#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dial.h"
#include "asterisk/pbx.h"
Go to the source code of this file.
Data Structures | |
struct | answer_exec_struct |
struct | ast_dial |
Main dialing structure. Contains global options, channels being dialed, and more! More... | |
struct | ast_dial_channel |
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! More... | |
struct | ast_option_types |
Options structure - maps options to respective handlers (enable/disable). This list MUST be perfectly kept in order, or else madness will happen. More... | |
Defines | |
#define | AST_MAX_WATCHERS 256 |
Maximum number of channels we can watch at a time. | |
#define | FIND_RELATIVE_OPTION(dial, dial_channel, ast_dial_option) (dial_channel->options[ast_dial_option] ? dial_channel->options[ast_dial_option] : dial->options[ast_dial_option]) |
Macro for finding the option structure to use on a dialed channel. | |
#define | IS_CALLER(chan, owner) (chan == owner ? 1 : 0) |
Macro that determines whether a channel is the caller or not. | |
#define | S_REPLACE(s, new_val) |
Typedefs | |
typedef int(* | ast_dial_option_cb_disable )(void *data) |
Typedef for dial option disable. | |
typedef void *(* | ast_dial_option_cb_enable )(void *data) |
Typedef for dial option enable. | |
Functions | |
static int | answer_exec_disable (void *data) |
static void * | answer_exec_enable (void *data) |
static void | answer_exec_run (struct ast_channel *chan, char *app, char *args) |
struct ast_channel * | ast_dial_answered (struct ast_dial *dial) |
Return channel that answered. | |
int | ast_dial_append (struct ast_dial *dial, const char *tech, const char *device) |
Append a channel. | |
struct ast_dial * | ast_dial_create (void) |
New dialing structure. | |
int | ast_dial_destroy (struct ast_dial *dial) |
Destroys a dialing structure. | |
void | ast_dial_hangup (struct ast_dial *dial) |
Hangup channels. | |
enum ast_dial_result | ast_dial_join (struct ast_dial *dial) |
Cancel async thread. | |
int | ast_dial_option_disable (struct ast_dial *dial, int num, enum ast_dial_option option) |
Disables an option per channel. | |
int | ast_dial_option_enable (struct ast_dial *dial, int num, enum ast_dial_option option, void *data) |
Enables an option per channel. | |
int | ast_dial_option_global_disable (struct ast_dial *dial, enum ast_dial_option option) |
Disables an option globally. | |
int | ast_dial_option_global_enable (struct ast_dial *dial, enum ast_dial_option option, void *data) |
Enables an option globally. | |
enum ast_dial_result | ast_dial_run (struct ast_dial *dial, struct ast_channel *chan, int async) |
Execute dialing synchronously or asynchronously. | |
void | ast_dial_set_state_callback (struct ast_dial *dial, ast_dial_state_callback callback) |
Set a callback for state changes. | |
enum ast_dial_result | ast_dial_state (struct ast_dial *dial) |
Return state of dial. | |
static void * | async_dial (void *data) |
Dial async thread function. | |
static int | begin_dial (struct ast_dial *dial, struct ast_channel *chan) |
Helper function that does the beginning dialing. | |
static struct ast_dial_channel * | find_relative_dial_channel (struct ast_dial *dial, struct ast_channel *owner) |
Helper function that finds the dialed channel based on owner. | |
static void | handle_frame (struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_frame *fr, struct ast_channel *chan) |
Helper function that handles control frames WITH owner. | |
static void | handle_frame_ownerless (struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_frame *fr) |
Helper function that handles control frames WITHOUT owner. | |
static enum ast_dial_result | monitor_dial (struct ast_dial *dial, struct ast_channel *chan) |
Helper function that basically keeps tabs on dialing attempts. | |
static void | set_state (struct ast_dial *dial, enum ast_dial_result state) |
Variables | |
static struct ast_option_types | option_types [] |
Options structure - maps options to respective handlers (enable/disable). This list MUST be perfectly kept in order, or else madness will happen. |
Definition in file dial.c.
#define AST_MAX_WATCHERS 256 |
Maximum number of channels we can watch at a time.
Definition at line 160 of file dial.c.
Referenced by monitor_dial(), and wait_for_answer().
#define FIND_RELATIVE_OPTION | ( | dial, | |||
dial_channel, | |||||
ast_dial_option | ) | (dial_channel->options[ast_dial_option] ? dial_channel->options[ast_dial_option] : dial->options[ast_dial_option]) |
Macro for finding the option structure to use on a dialed channel.
Definition at line 163 of file dial.c.
Referenced by monitor_dial().
#define IS_CALLER | ( | chan, | |||
owner | ) | (chan == owner ? 1 : 0) |
Macro that determines whether a channel is the caller or not.
Definition at line 166 of file dial.c.
Referenced by monitor_dial().
#define S_REPLACE | ( | s, | |||
new_val | ) |
typedef int(* ast_dial_option_cb_disable)(void *data) |
typedef void*(* ast_dial_option_cb_enable)(void *data) |
static int answer_exec_disable | ( | void * | data | ) | [static] |
Definition at line 107 of file dial.c.
References answer_exec_struct::args, and free.
00108 { 00109 struct answer_exec_struct *answer_exec = data; 00110 00111 /* Make sure we have a value */ 00112 if (!answer_exec) 00113 return -1; 00114 00115 /* If arguments are present, free them too */ 00116 if (answer_exec->args) 00117 free(answer_exec->args); 00118 00119 /* This is simple - just free the structure */ 00120 free(answer_exec); 00121 00122 return 0; 00123 }
static void* answer_exec_enable | ( | void * | data | ) | [static] |
Definition at line 81 of file dial.c.
References answer_exec_struct::app, app, answer_exec_struct::args, ast_calloc, ast_strdup, ast_strdupa, and ast_strlen_zero().
00082 { 00083 struct answer_exec_struct *answer_exec = NULL; 00084 char *app = ast_strdupa((char*)data), *args = NULL; 00085 00086 /* Not giving any data to this option is bad, mmmk? */ 00087 if (ast_strlen_zero(app)) 00088 return NULL; 00089 00090 /* Create new data structure */ 00091 if (!(answer_exec = ast_calloc(1, sizeof(*answer_exec)))) 00092 return NULL; 00093 00094 /* Parse out application and arguments */ 00095 if ((args = strchr(app, '|'))) { 00096 *args++ = '\0'; 00097 answer_exec->args = ast_strdup(args); 00098 } 00099 00100 /* Copy application name */ 00101 ast_copy_string(answer_exec->app, app, sizeof(answer_exec->app)); 00102 00103 return answer_exec; 00104 }
static void answer_exec_run | ( | struct ast_channel * | chan, | |
char * | app, | |||
char * | args | |||
) | [static] |
Definition at line 126 of file dial.c.
References pbx_exec(), and pbx_findapp().
Referenced by monitor_dial().
00127 { 00128 struct ast_app *ast_app = pbx_findapp(app); 00129 00130 /* If the application was not found, return immediately */ 00131 if (!ast_app) 00132 return; 00133 00134 /* All is well... execute the application */ 00135 pbx_exec(chan, ast_app, args); 00136 00137 return; 00138 }
struct ast_channel* ast_dial_answered | ( | struct ast_dial * | dial | ) | [read] |
Return channel that answered.
dial | Dialing structure |
Definition at line 583 of file dial.c.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00584 { 00585 if (!dial) 00586 return NULL; 00587 00588 return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL); 00589 }
int ast_dial_append | ( | struct ast_dial * | dial, | |
const char * | tech, | |||
const char * | device | |||
) |
Append a channel.
Definition at line 193 of file dial.c.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00194 { 00195 struct ast_dial_channel *channel = NULL; 00196 00197 /* Make sure we have required arguments */ 00198 if (!dial || !tech || !device) 00199 return -1; 00200 00201 /* Allocate new memory for dialed channel structure */ 00202 if (!(channel = ast_calloc(1, sizeof(*channel)))) 00203 return -1; 00204 00205 /* Record technology and device for when we actually dial */ 00206 channel->tech = tech; 00207 channel->device = device; 00208 00209 /* Grab reference number from dial structure */ 00210 channel->num = ast_atomic_fetchadd_int(&dial->num, +1); 00211 00212 /* Insert into channels list */ 00213 AST_LIST_INSERT_TAIL(&dial->channels, channel, list); 00214 00215 return channel->num; 00216 }
struct ast_dial* ast_dial_create | ( | void | ) | [read] |
New dialing structure.
Definition at line 172 of file dial.c.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00173 { 00174 struct ast_dial *dial = NULL; 00175 00176 /* Allocate new memory for structure */ 00177 if (!(dial = ast_calloc(1, sizeof(*dial)))) 00178 return NULL; 00179 00180 /* Initialize list of channels */ 00181 AST_LIST_HEAD_INIT_NOLOCK(&dial->channels); 00182 00183 /* Initialize thread to NULL */ 00184 dial->thread = AST_PTHREADT_NULL; 00185 00186 return dial; 00187 }
int ast_dial_destroy | ( | struct ast_dial * | dial | ) |
Destroys a dialing structure.
dial | Dialing structure to free |
Definition at line 656 of file dial.c.
Referenced by dial_trunk(), page_exec(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00657 { 00658 int i = 0; 00659 struct ast_dial_channel *channel = NULL; 00660 00661 if (!dial) 00662 return -1; 00663 00664 /* Hangup and deallocate all the dialed channels */ 00665 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00666 /* Disable any enabled options */ 00667 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00668 if (!channel->options[i]) 00669 continue; 00670 if (option_types[i].disable) 00671 option_types[i].disable(channel->options[i]); 00672 channel->options[i] = NULL; 00673 } 00674 /* Hang up channel if need be */ 00675 if (channel->owner) { 00676 ast_hangup(channel->owner); 00677 channel->owner = NULL; 00678 } 00679 /* Free structure */ 00680 free(channel); 00681 } 00682 00683 /* Disable any enabled options globally */ 00684 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00685 if (!dial->options[i]) 00686 continue; 00687 if (option_types[i].disable) 00688 option_types[i].disable(dial->options[i]); 00689 dial->options[i] = NULL; 00690 } 00691 00692 /* Free structure */ 00693 free(dial); 00694 00695 return 0; 00696 }
void ast_dial_hangup | ( | struct ast_dial * | dial | ) |
Hangup channels.
dial | Dialing structure |
Definition at line 634 of file dial.c.
Referenced by ast_dial_run(), and page_exec().
00635 { 00636 struct ast_dial_channel *channel = NULL; 00637 00638 if (!dial) 00639 return; 00640 00641 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00642 if (channel->owner) { 00643 ast_hangup(channel->owner); 00644 channel->owner = NULL; 00645 } 00646 } 00647 00648 return; 00649 }
enum ast_dial_result ast_dial_join | ( | struct ast_dial * | dial | ) |
Cancel async thread.
dial | Dialing structure |
Definition at line 604 of file dial.c.
Referenced by dial_trunk(), page_exec(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00605 { 00606 pthread_t thread; 00607 00608 /* If the dial structure is not running in async, return failed */ 00609 if (dial->thread == AST_PTHREADT_NULL) 00610 return AST_DIAL_RESULT_FAILED; 00611 00612 /* Record thread */ 00613 thread = dial->thread; 00614 00615 /* Stop the thread */ 00616 dial->thread = AST_PTHREADT_STOP; 00617 00618 /* Now we signal it with SIGURG so it will break out of it's waitfor */ 00619 pthread_kill(thread, SIGURG); 00620 00621 /* Finally wait for the thread to exit */ 00622 pthread_join(thread, NULL); 00623 00624 /* Yay thread is all gone */ 00625 dial->thread = AST_PTHREADT_NULL; 00626 00627 return dial->state; 00628 }
int ast_dial_option_disable | ( | struct ast_dial * | dial, | |
int | num, | |||
enum ast_dial_option | option | |||
) |
Disables an option per channel.
dial | Dial structure | |
num | Channel number to disable option on | |
option | Option to disable |
Definition at line 788 of file dial.c.
00789 { 00790 struct ast_dial_channel *channel = NULL; 00791 00792 /* Ensure we have required arguments */ 00793 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00794 return -1; 00795 00796 /* Look for channel, we can sort of cheat and predict things - the last channel in the list will probably be what they want */ 00797 if (AST_LIST_LAST(&dial->channels)->num != num) { 00798 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00799 if (channel->num == num) 00800 break; 00801 } 00802 } else { 00803 channel = AST_LIST_LAST(&dial->channels); 00804 } 00805 00806 /* If none found, return failure */ 00807 if (!channel) 00808 return -1; 00809 00810 /* If the option is not enabled, return failure */ 00811 if (!channel->options[option]) 00812 return -1; 00813 00814 /* Execute callback of option to disable it if it exists */ 00815 if (option_types[option].disable) 00816 option_types[option].disable(channel->options[option]); 00817 00818 /* Finally disable the option on the structure */ 00819 channel->options[option] = NULL; 00820 00821 return 0; 00822 }
int ast_dial_option_enable | ( | struct ast_dial * | dial, | |
int | num, | |||
enum ast_dial_option | option, | |||
void * | data | |||
) |
Enables an option per channel.
dial | Dial structure | |
num | Channel number to enable option on | |
option | Option to enable | |
data | Data to pass to this option (not always needed) |
Definition at line 726 of file dial.c.
00727 { 00728 struct ast_dial_channel *channel = NULL; 00729 00730 /* Ensure we have required arguments */ 00731 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00732 return -1; 00733 00734 /* Look for channel, we can sort of cheat and predict things - the last channel in the list will probably be what they want */ 00735 if (AST_LIST_LAST(&dial->channels)->num != num) { 00736 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00737 if (channel->num == num) 00738 break; 00739 } 00740 } else { 00741 channel = AST_LIST_LAST(&dial->channels); 00742 } 00743 00744 /* If none found, return failure */ 00745 if (!channel) 00746 return -1; 00747 00748 /* If the option is already enabled, return failure */ 00749 if (channel->options[option]) 00750 return -1; 00751 00752 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00753 if (option_types[option].enable) 00754 channel->options[option] = option_types[option].enable(data); 00755 else 00756 channel->options[option] = (void*)1; 00757 00758 return 0; 00759 }
int ast_dial_option_global_disable | ( | struct ast_dial * | dial, | |
enum ast_dial_option | option | |||
) |
Disables an option globally.
dial | Dial structure to disable option on | |
option | Option to disable |
Definition at line 766 of file dial.c.
00767 { 00768 /* If the option is not enabled, return failure */ 00769 if (!dial->options[option]) 00770 return -1; 00771 00772 /* Execute callback of option to disable if it exists */ 00773 if (option_types[option].disable) 00774 option_types[option].disable(dial->options[option]); 00775 00776 /* Finally disable option on the structure */ 00777 dial->options[option] = NULL; 00778 00779 return 0; 00780 }
int ast_dial_option_global_enable | ( | struct ast_dial * | dial, | |
enum ast_dial_option | option, | |||
void * | data | |||
) |
Enables an option globally.
dial | Dial structure to enable option on | |
option | Option to enable | |
data | Data to pass to this option (not always needed) |
Definition at line 704 of file dial.c.
Referenced by page_exec().
00705 { 00706 /* If the option is already enabled, return failure */ 00707 if (dial->options[option]) 00708 return -1; 00709 00710 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00711 if (option_types[option].enable) 00712 dial->options[option] = option_types[option].enable(data); 00713 else 00714 dial->options[option] = (void*)1; 00715 00716 return 0; 00717 }
enum ast_dial_result ast_dial_run | ( | struct ast_dial * | dial, | |
struct ast_channel * | chan, | |||
int | async | |||
) |
Execute dialing synchronously or asynchronously.
Definition at line 543 of file dial.c.
Referenced by dial_trunk(), page_exec(), and sla_ring_station().
00544 { 00545 enum ast_dial_result res = AST_DIAL_RESULT_TRYING; 00546 00547 /* Ensure required arguments are passed */ 00548 if (!dial || (!chan && !async)) { 00549 ast_log(LOG_DEBUG, "invalid #1\n"); 00550 return AST_DIAL_RESULT_INVALID; 00551 } 00552 00553 /* If there are no channels to dial we can't very well try to dial them */ 00554 if (AST_LIST_EMPTY(&dial->channels)) { 00555 ast_log(LOG_DEBUG, "invalid #2\n"); 00556 return AST_DIAL_RESULT_INVALID; 00557 } 00558 00559 /* Dial each requested channel */ 00560 if (!begin_dial(dial, chan)) 00561 return AST_DIAL_RESULT_FAILED; 00562 00563 /* If we are running async spawn a thread and send it away... otherwise block here */ 00564 if (async) { 00565 dial->state = AST_DIAL_RESULT_TRYING; 00566 /* Try to create a thread */ 00567 if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) { 00568 /* Failed to create the thread - hangup all dialed channels and return failed */ 00569 ast_dial_hangup(dial); 00570 res = AST_DIAL_RESULT_FAILED; 00571 } 00572 } else { 00573 res = monitor_dial(dial, chan); 00574 } 00575 00576 return res; 00577 }
void ast_dial_set_state_callback | ( | struct ast_dial * | dial, | |
ast_dial_state_callback | callback | |||
) |
Set a callback for state changes.
dial | The dial structure to watch for state changes | |
callback | the callback |
Definition at line 824 of file dial.c.
Referenced by sla_ring_station().
00825 { 00826 dial->state_callback = callback; 00827 }
enum ast_dial_result ast_dial_state | ( | struct ast_dial * | dial | ) |
Return state of dial.
dial | Dialing structure |
Definition at line 595 of file dial.c.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00596 { 00597 return dial->state; 00598 }
static void* async_dial | ( | void * | data | ) | [static] |
Dial async thread function.
Definition at line 529 of file dial.c.
References monitor_dial().
Referenced by ast_dial_run().
00530 { 00531 struct ast_dial *dial = data; 00532 00533 /* This is really really simple... we basically pass monitor_dial a NULL owner and it changes it's behavior */ 00534 monitor_dial(dial, NULL); 00535 00536 return NULL; 00537 }
static int begin_dial | ( | struct ast_dial * | dial, | |
struct ast_channel * | chan | |||
) | [static] |
Helper function that does the beginning dialing.
Definition at line 219 of file dial.c.
References accountcode, ast_channel::adsicpe, ast_channel::appl, ast_call(), ast_channel_inherit_variables(), AST_FORMAT_AUDIO_MASK, ast_hangup(), AST_LIST_TRAVERSE, AST_MAX_EXTENSION, ast_request(), ast_strdup, ast_string_field_set, ast_strlen_zero(), ast_verbose(), ast_dial_channel::cause, ast_channel::cdrflags, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_tns, ast_callerid::cid_ton, ast_channel::data, ast_dial_channel::device, language, musicclass, ast_channel::nativeformats, option_verbose, ast_dial_channel::owner, S_REPLACE, ast_dial_channel::tech, ast_channel::transfercapability, VERBOSE_PREFIX_3, and ast_channel::whentohangup.
Referenced by ast_dial_run().
00220 { 00221 struct ast_dial_channel *channel = NULL; 00222 int success = 0, res = 0; 00223 00224 /* Iterate through channel list, requesting and calling each one */ 00225 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00226 char numsubst[AST_MAX_EXTENSION]; 00227 00228 /* Copy device string over */ 00229 ast_copy_string(numsubst, channel->device, sizeof(numsubst)); 00230 00231 /* Request that the channel be created */ 00232 if (!(channel->owner = ast_request(channel->tech, 00233 chan ? chan->nativeformats : AST_FORMAT_AUDIO_MASK, numsubst, &channel->cause))) { 00234 continue; 00235 } 00236 00237 channel->owner->appl = "AppDial2"; 00238 channel->owner->data = "(Outgoing Line)"; 00239 channel->owner->whentohangup = 0; 00240 00241 /* Inherit everything from he who spawned this Dial */ 00242 if (chan) { 00243 ast_channel_inherit_variables(chan, channel->owner); 00244 00245 /* Copy over callerid information */ 00246 S_REPLACE(channel->owner->cid.cid_num, ast_strdup(chan->cid.cid_num)); 00247 S_REPLACE(channel->owner->cid.cid_name, ast_strdup(chan->cid.cid_name)); 00248 S_REPLACE(channel->owner->cid.cid_ani, ast_strdup(chan->cid.cid_ani)); 00249 S_REPLACE(channel->owner->cid.cid_rdnis, ast_strdup(chan->cid.cid_rdnis)); 00250 00251 ast_string_field_set(channel->owner, language, chan->language); 00252 ast_string_field_set(channel->owner, accountcode, chan->accountcode); 00253 channel->owner->cdrflags = chan->cdrflags; 00254 if (ast_strlen_zero(channel->owner->musicclass)) 00255 ast_string_field_set(channel->owner, musicclass, chan->musicclass); 00256 00257 channel->owner->cid.cid_pres = chan->cid.cid_pres; 00258 channel->owner->cid.cid_ton = chan->cid.cid_ton; 00259 channel->owner->cid.cid_tns = chan->cid.cid_tns; 00260 channel->owner->adsicpe = chan->adsicpe; 00261 channel->owner->transfercapability = chan->transfercapability; 00262 } 00263 00264 /* Actually call the device */ 00265 if ((res = ast_call(channel->owner, numsubst, 0))) { 00266 ast_hangup(channel->owner); 00267 channel->owner = NULL; 00268 } else { 00269 success++; 00270 if (option_verbose > 2) 00271 ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", numsubst); 00272 } 00273 } 00274 00275 /* If number of failures matches the number of channels, then this truly failed */ 00276 return success; 00277 }
static struct ast_dial_channel* find_relative_dial_channel | ( | struct ast_dial * | dial, | |
struct ast_channel * | owner | |||
) | [static, read] |
Helper function that finds the dialed channel based on owner.
Definition at line 280 of file dial.c.
References AST_LIST_TRAVERSE, and ast_dial_channel::owner.
Referenced by monitor_dial().
00281 { 00282 struct ast_dial_channel *channel = NULL; 00283 00284 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00285 if (channel->owner == owner) 00286 break; 00287 } 00288 00289 return channel; 00290 }
static void handle_frame | ( | struct ast_dial * | dial, | |
struct ast_dial_channel * | channel, | |||
struct ast_frame * | fr, | |||
struct ast_channel * | chan | |||
) | [static] |
Helper function that handles control frames WITH owner.
Definition at line 301 of file dial.c.
References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_DIAL_RESULT_ANSWERED, AST_DIAL_RESULT_PROCEEDING, AST_DIAL_RESULT_PROGRESS, AST_DIAL_RESULT_RINGING, AST_FRAME_CONTROL, ast_hangup(), ast_indicate(), AST_LIST_INSERT_HEAD, AST_LIST_REMOVE, ast_verbose(), ast_frame::frametype, option_verbose, ast_dial_channel::owner, set_state(), ast_frame::subclass, and VERBOSE_PREFIX_3.
Referenced by monitor_dial(), and socket_read().
00302 { 00303 if (fr->frametype == AST_FRAME_CONTROL) { 00304 switch (fr->subclass) { 00305 case AST_CONTROL_ANSWER: 00306 if (option_verbose > 2) 00307 ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", channel->owner->name, chan->name); 00308 AST_LIST_REMOVE(&dial->channels, channel, list); 00309 AST_LIST_INSERT_HEAD(&dial->channels, channel, list); 00310 set_state(dial, AST_DIAL_RESULT_ANSWERED); 00311 break; 00312 case AST_CONTROL_BUSY: 00313 if (option_verbose > 2) 00314 ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", channel->owner->name); 00315 ast_hangup(channel->owner); 00316 channel->owner = NULL; 00317 break; 00318 case AST_CONTROL_CONGESTION: 00319 if (option_verbose > 2) 00320 ast_verbose(VERBOSE_PREFIX_3 "%s is circuit-busy\n", channel->owner->name); 00321 ast_hangup(channel->owner); 00322 channel->owner = NULL; 00323 break; 00324 case AST_CONTROL_RINGING: 00325 if (option_verbose > 2) 00326 ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", channel->owner->name); 00327 ast_indicate(chan, AST_CONTROL_RINGING); 00328 set_state(dial, AST_DIAL_RESULT_RINGING); 00329 break; 00330 case AST_CONTROL_PROGRESS: 00331 if (option_verbose > 2) 00332 ast_verbose (VERBOSE_PREFIX_3 "%s is making progress, passing it to %s\n", channel->owner->name, chan->name); 00333 ast_indicate(chan, AST_CONTROL_PROGRESS); 00334 set_state(dial, AST_DIAL_RESULT_PROGRESS); 00335 break; 00336 case AST_CONTROL_VIDUPDATE: 00337 if (option_verbose > 2) 00338 ast_verbose (VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", channel->owner->name, chan->name); 00339 ast_indicate(chan, AST_CONTROL_VIDUPDATE); 00340 break; 00341 case AST_CONTROL_PROCEEDING: 00342 if (option_verbose > 2) 00343 ast_verbose (VERBOSE_PREFIX_3 "%s is proceeding, passing it to %s\n", channel->owner->name, chan->name); 00344 ast_indicate(chan, AST_CONTROL_PROCEEDING); 00345 set_state(dial, AST_DIAL_RESULT_PROCEEDING); 00346 break; 00347 case AST_CONTROL_HOLD: 00348 if (option_verbose > 2) 00349 ast_verbose(VERBOSE_PREFIX_3 "Call on %s placed on hold\n", chan->name); 00350 ast_indicate(chan, AST_CONTROL_HOLD); 00351 break; 00352 case AST_CONTROL_UNHOLD: 00353 if (option_verbose > 2) 00354 ast_verbose(VERBOSE_PREFIX_3 "Call on %s left from hold\n", chan->name); 00355 ast_indicate(chan, AST_CONTROL_UNHOLD); 00356 break; 00357 case AST_CONTROL_OFFHOOK: 00358 case AST_CONTROL_FLASH: 00359 break; 00360 case -1: 00361 /* Prod the channel */ 00362 ast_indicate(chan, -1); 00363 break; 00364 default: 00365 break; 00366 } 00367 } 00368 00369 return; 00370 }
static void handle_frame_ownerless | ( | struct ast_dial * | dial, | |
struct ast_dial_channel * | channel, | |||
struct ast_frame * | fr | |||
) | [static] |
Helper function that handles control frames WITHOUT owner.
Definition at line 373 of file dial.c.
References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_DIAL_RESULT_ANSWERED, AST_DIAL_RESULT_PROCEEDING, AST_DIAL_RESULT_PROGRESS, AST_DIAL_RESULT_RINGING, AST_FRAME_CONTROL, ast_hangup(), AST_LIST_INSERT_HEAD, AST_LIST_REMOVE, ast_verbose(), ast_frame::frametype, option_verbose, ast_dial_channel::owner, set_state(), ast_frame::subclass, and VERBOSE_PREFIX_3.
Referenced by monitor_dial().
00374 { 00375 /* If we have no owner we can only update the state of the dial structure, so only look at control frames */ 00376 if (fr->frametype != AST_FRAME_CONTROL) 00377 return; 00378 00379 switch (fr->subclass) { 00380 case AST_CONTROL_ANSWER: 00381 if (option_verbose > 2) 00382 ast_verbose( VERBOSE_PREFIX_3 "%s answered\n", channel->owner->name); 00383 AST_LIST_REMOVE(&dial->channels, channel, list); 00384 AST_LIST_INSERT_HEAD(&dial->channels, channel, list); 00385 set_state(dial, AST_DIAL_RESULT_ANSWERED); 00386 break; 00387 case AST_CONTROL_BUSY: 00388 if (option_verbose > 2) 00389 ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", channel->owner->name); 00390 ast_hangup(channel->owner); 00391 channel->owner = NULL; 00392 break; 00393 case AST_CONTROL_CONGESTION: 00394 if (option_verbose > 2) 00395 ast_verbose(VERBOSE_PREFIX_3 "%s is circuit-busy\n", channel->owner->name); 00396 ast_hangup(channel->owner); 00397 channel->owner = NULL; 00398 break; 00399 case AST_CONTROL_RINGING: 00400 if (option_verbose > 2) 00401 ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", channel->owner->name); 00402 set_state(dial, AST_DIAL_RESULT_RINGING); 00403 break; 00404 case AST_CONTROL_PROGRESS: 00405 if (option_verbose > 2) 00406 ast_verbose (VERBOSE_PREFIX_3 "%s is making progress\n", channel->owner->name); 00407 set_state(dial, AST_DIAL_RESULT_PROGRESS); 00408 break; 00409 case AST_CONTROL_PROCEEDING: 00410 if (option_verbose > 2) 00411 ast_verbose (VERBOSE_PREFIX_3 "%s is proceeding\n", channel->owner->name); 00412 set_state(dial, AST_DIAL_RESULT_PROCEEDING); 00413 break; 00414 default: 00415 break; 00416 } 00417 00418 return; 00419 }
static enum ast_dial_result monitor_dial | ( | struct ast_dial * | dial, | |
struct ast_channel * | chan | |||
) | [static] |
Helper function that basically keeps tabs on dialing attempts.
Definition at line 422 of file dial.c.
References answer_exec_run(), answer_exec_struct::app, answer_exec_struct::args, AST_CONTROL_RINGING, AST_DIAL_OPTION_ANSWER_EXEC, AST_DIAL_OPTION_RINGING, AST_DIAL_RESULT_ANSWERED, AST_DIAL_RESULT_HANGUP, AST_DIAL_RESULT_RINGING, AST_DIAL_RESULT_TIMEOUT, AST_DIAL_RESULT_TRYING, AST_DIAL_RESULT_UNANSWERED, ast_frfree(), ast_hangup(), ast_indicate(), AST_LIST_TRAVERSE, AST_MAX_WATCHERS, AST_PTHREADT_STOP, ast_read(), ast_waitfor_n(), find_relative_dial_channel(), FIND_RELATIVE_OPTION, handle_frame(), handle_frame_ownerless(), IS_CALLER, ast_dial::options, ast_dial_channel::owner, set_state(), and ast_dial::state.
Referenced by ast_dial_run(), and async_dial().
00423 { 00424 int timeout = -1, count = 0; 00425 struct ast_channel *cs[AST_MAX_WATCHERS], *who = NULL; 00426 struct ast_dial_channel *channel = NULL; 00427 struct answer_exec_struct *answer_exec = NULL; 00428 00429 set_state(dial, AST_DIAL_RESULT_TRYING); 00430 00431 /* If the "always indicate ringing" option is set, change state to ringing and indicate to the owner if present */ 00432 if (dial->options[AST_DIAL_OPTION_RINGING]) { 00433 set_state(dial, AST_DIAL_RESULT_RINGING); 00434 if (chan) 00435 ast_indicate(chan, AST_CONTROL_RINGING); 00436 } 00437 00438 /* Go into an infinite loop while we are trying */ 00439 while ((dial->state != AST_DIAL_RESULT_UNANSWERED) && (dial->state != AST_DIAL_RESULT_ANSWERED) && (dial->state != AST_DIAL_RESULT_HANGUP) && (dial->state != AST_DIAL_RESULT_TIMEOUT)) { 00440 int pos = 0; 00441 struct ast_frame *fr = NULL; 00442 00443 /* Set up channel structure array */ 00444 pos = count = 0; 00445 if (chan) 00446 cs[pos++] = chan; 00447 00448 /* Add channels we are attempting to dial */ 00449 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00450 if (channel->owner) { 00451 cs[pos++] = channel->owner; 00452 count++; 00453 } 00454 } 00455 00456 /* If we have no outbound channels in progress, switch state to unanswered and stop */ 00457 if (!count) { 00458 set_state(dial, AST_DIAL_RESULT_UNANSWERED); 00459 break; 00460 } 00461 00462 /* Just to be safe... */ 00463 if (dial->thread == AST_PTHREADT_STOP) 00464 break; 00465 00466 /* Wait for frames from channels */ 00467 who = ast_waitfor_n(cs, pos, &timeout); 00468 00469 /* Check to see if our thread is being cancelled */ 00470 if (dial->thread == AST_PTHREADT_STOP) 00471 break; 00472 00473 /* If we are not being cancelled and we have no channel, then timeout was tripped */ 00474 if (!who) 00475 continue; 00476 00477 /* Find relative dial channel */ 00478 if (!chan || !IS_CALLER(chan, who)) 00479 channel = find_relative_dial_channel(dial, who); 00480 00481 /* Attempt to read in a frame */ 00482 if (!(fr = ast_read(who))) { 00483 /* If this is the caller then we switch state to hangup and stop */ 00484 if (chan && IS_CALLER(chan, who)) { 00485 set_state(dial, AST_DIAL_RESULT_HANGUP); 00486 break; 00487 } 00488 ast_hangup(who); 00489 channel->owner = NULL; 00490 continue; 00491 } 00492 00493 /* Process the frame */ 00494 if (chan) 00495 handle_frame(dial, channel, fr, chan); 00496 else 00497 handle_frame_ownerless(dial, channel, fr); 00498 00499 /* Free the received frame and start all over */ 00500 ast_frfree(fr); 00501 } 00502 00503 /* Do post-processing from loop */ 00504 if (dial->state == AST_DIAL_RESULT_ANSWERED) { 00505 /* Hangup everything except that which answered */ 00506 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00507 if (!channel->owner || channel->owner == who) 00508 continue; 00509 ast_hangup(channel->owner); 00510 channel->owner = NULL; 00511 } 00512 /* If ANSWER_EXEC is enabled as an option, execute application on answered channel */ 00513 if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC))) 00514 answer_exec_run(who, answer_exec->app, answer_exec->args); 00515 } else if (dial->state == AST_DIAL_RESULT_HANGUP) { 00516 /* Hangup everything */ 00517 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00518 if (!channel->owner) 00519 continue; 00520 ast_hangup(channel->owner); 00521 channel->owner = NULL; 00522 } 00523 } 00524 00525 return dial->state; 00526 }
static void set_state | ( | struct ast_dial * | dial, | |
enum ast_dial_result | state | |||
) | [static] |
Definition at line 292 of file dial.c.
References ast_dial::state, and ast_dial::state_callback.
Referenced by handle_frame(), handle_frame_ownerless(), and monitor_dial().
00293 { 00294 dial->state = state; 00295 00296 if (dial->state_callback) 00297 dial->state_callback(dial); 00298 }
struct ast_option_types option_types[] [static] |
Options structure - maps options to respective handlers (enable/disable). This list MUST be perfectly kept in order, or else madness will happen.
Referenced by ast_dial_destroy(), ast_dial_option_disable(), ast_dial_option_enable(), ast_dial_option_global_disable(), and ast_dial_option_global_enable().