#include "asterisk.h"
#include <sys/time.h>
#include <signal.h>
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dial.h"
#include "asterisk/pbx.h"
#include "asterisk/musiconhold.h"
#include "asterisk/app.h"
Go to the source code of this file.
Data Structures | |
struct | answer_exec_struct |
Structure for 'ANSWER_EXEC' option. More... | |
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. | |
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) |
Disable function for 'ANSWER_EXEC' option. | |
static void * | answer_exec_enable (void *data) |
Enable function for 'ANSWER_EXEC' option. | |
static void | answer_exec_run (struct ast_dial *dial, struct ast_dial_channel *dial_channel, char *app, char *args) |
Application execution function for 'ANSWER_EXEC' option. | |
ast_channel * | ast_dial_answered (struct ast_dial *dial) |
Return channel that answered. | |
ast_channel * | ast_dial_answered_steal (struct ast_dial *dial) |
Steal the channel that answered. | |
int | ast_dial_append (struct ast_dial *dial, const char *tech, const char *device) |
Append a channel. | |
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_global_timeout (struct ast_dial *dial, int timeout) |
Set the maximum time (globally) allowed for trying to ring phones. | |
void | ast_dial_set_state_callback (struct ast_dial *dial, ast_dial_state_callback callback) |
Set a callback for state changes. | |
void | ast_dial_set_timeout (struct ast_dial *dial, int num, int timeout) |
Set the maximum time (per channel) allowed for trying to ring the phone. | |
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 per dial structure. | |
static int | begin_dial_channel (struct ast_dial_channel *channel, struct ast_channel *chan) |
Helper function that does the beginning dialing per-appended channel. | |
static struct ast_dial_channel * | find_dial_channel (struct ast_dial *dial, int num) |
Helper function for finding a channel in a dial structure based on number. | |
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 int | handle_call_forward (struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_channel *chan) |
Helper function to handle channels that have been call forwarded. | |
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 int | handle_timeout_trip (struct ast_dial *dial, struct timeval start) |
Helper function to handle when a timeout occurs on dialing attempt. | |
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 int | music_disable (void *data) |
static void * | music_enable (void *data) |
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 |
#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 185 of file dial.c.
Referenced by handle_call_forward(), and 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 188 of file dial.c.
Referenced by monitor_dial().
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] |
Disable function for 'ANSWER_EXEC' option.
Definition at line 111 of file dial.c.
References answer_exec_struct::args, and ast_free.
00112 { 00113 struct answer_exec_struct *answer_exec = data; 00114 00115 /* Make sure we have a value */ 00116 if (!answer_exec) 00117 return -1; 00118 00119 /* If arguments are present, free them too */ 00120 if (answer_exec->args) 00121 ast_free(answer_exec->args); 00122 00123 /* This is simple - just free the structure */ 00124 ast_free(answer_exec); 00125 00126 return 0; 00127 }
static void* answer_exec_enable | ( | void * | data | ) | [static] |
Enable function for 'ANSWER_EXEC' option.
Definition at line 85 of file dial.c.
References app, args, ast_calloc, ast_copy_string(), ast_strdup, ast_strdupa, and ast_strlen_zero().
00086 { 00087 struct answer_exec_struct *answer_exec = NULL; 00088 char *app = ast_strdupa((char*)data), *args = NULL; 00089 00090 /* Not giving any data to this option is bad, mmmk? */ 00091 if (ast_strlen_zero(app)) 00092 return NULL; 00093 00094 /* Create new data structure */ 00095 if (!(answer_exec = ast_calloc(1, sizeof(*answer_exec)))) 00096 return NULL; 00097 00098 /* Parse out application and arguments */ 00099 if ((args = strchr(app, ','))) { 00100 *args++ = '\0'; 00101 answer_exec->args = ast_strdup(args); 00102 } 00103 00104 /* Copy application name */ 00105 ast_copy_string(answer_exec->app, app, sizeof(answer_exec->app)); 00106 00107 return answer_exec; 00108 }
static void answer_exec_run | ( | struct ast_dial * | dial, | |
struct ast_dial_channel * | dial_channel, | |||
char * | app, | |||
char * | args | |||
) | [static] |
Application execution function for 'ANSWER_EXEC' option.
Definition at line 145 of file dial.c.
References ast_hangup(), ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_STOP, ast_dial::lock, ast_dial_channel::owner, pbx_exec(), pbx_findapp(), and ast_dial::thread.
Referenced by monitor_dial().
00146 { 00147 struct ast_channel *chan = dial_channel->owner; 00148 struct ast_app *ast_app = pbx_findapp(app); 00149 00150 /* If the application was not found, return immediately */ 00151 if (!ast_app) 00152 return; 00153 00154 /* All is well... execute the application */ 00155 pbx_exec(chan, ast_app, args); 00156 00157 /* If another thread is not taking over hang up the channel */ 00158 ast_mutex_lock(&dial->lock); 00159 if (dial->thread != AST_PTHREADT_STOP) { 00160 ast_hangup(chan); 00161 dial_channel->owner = NULL; 00162 } 00163 ast_mutex_unlock(&dial->lock); 00164 00165 return; 00166 }
struct ast_channel* ast_dial_answered | ( | struct ast_dial * | dial | ) |
Return channel that answered.
dial | Dialing structure |
Definition at line 747 of file dial.c.
References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, and ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00748 { 00749 if (!dial) 00750 return NULL; 00751 00752 return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL); 00753 }
struct ast_channel* ast_dial_answered_steal | ( | struct ast_dial * | dial | ) |
Steal the channel that answered.
dial | Dialing structure |
Definition at line 759 of file dial.c.
References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, and ast_dial::state.
Referenced by do_notify().
00760 { 00761 struct ast_channel *chan = NULL; 00762 00763 if (!dial) 00764 return NULL; 00765 00766 if (dial->state == AST_DIAL_RESULT_ANSWERED) { 00767 chan = AST_LIST_FIRST(&dial->channels)->owner; 00768 AST_LIST_FIRST(&dial->channels)->owner = NULL; 00769 } 00770 00771 return chan; 00772 }
int ast_dial_append | ( | struct ast_dial * | dial, | |
const char * | tech, | |||
const char * | device | |||
) |
Append a channel.
Definition at line 222 of file dial.c.
References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_TAIL, ast_strdup, ast_dial::channels, ast_dial_channel::list, and ast_dial::num.
Referenced by dial_trunk(), do_notify(), and sla_ring_station().
00223 { 00224 struct ast_dial_channel *channel = NULL; 00225 00226 /* Make sure we have required arguments */ 00227 if (!dial || !tech || !device) 00228 return -1; 00229 00230 /* Allocate new memory for dialed channel structure */ 00231 if (!(channel = ast_calloc(1, sizeof(*channel)))) 00232 return -1; 00233 00234 /* Record technology and device for when we actually dial */ 00235 channel->tech = ast_strdup(tech); 00236 channel->device = ast_strdup(device); 00237 00238 /* Grab reference number from dial structure */ 00239 channel->num = ast_atomic_fetchadd_int(&dial->num, +1); 00240 00241 /* No timeout exists... yet */ 00242 channel->timeout = -1; 00243 00244 /* Insert into channels list */ 00245 AST_LIST_INSERT_TAIL(&dial->channels, channel, list); 00246 00247 return channel->num; 00248 }
struct ast_dial* ast_dial_create | ( | void | ) |
New dialing structure.
Definition at line 194 of file dial.c.
References ast_calloc, AST_LIST_HEAD_INIT, ast_mutex_init, and AST_PTHREADT_NULL.
Referenced by dial_trunk(), do_notify(), and sla_ring_station().
00195 { 00196 struct ast_dial *dial = NULL; 00197 00198 /* Allocate new memory for structure */ 00199 if (!(dial = ast_calloc(1, sizeof(*dial)))) 00200 return NULL; 00201 00202 /* Initialize list of channels */ 00203 AST_LIST_HEAD_INIT(&dial->channels); 00204 00205 /* Initialize thread to NULL */ 00206 dial->thread = AST_PTHREADT_NULL; 00207 00208 /* No timeout exists... yet */ 00209 dial->timeout = -1; 00210 dial->actual_timeout = -1; 00211 00212 /* Can't forget about the lock */ 00213 ast_mutex_init(&dial->lock); 00214 00215 return dial; 00216 }
int ast_dial_destroy | ( | struct ast_dial * | dial | ) |
Destroys a dialing structure.
dial | Dialing structure to free |
Definition at line 859 of file dial.c.
References AST_DIAL_OPTION_MAX, ast_free, ast_hangup(), AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, ast_dial::channels, ast_dial_channel::device, ast_dial_channel::list, option_types, ast_dial_channel::options, ast_dial_channel::owner, and ast_dial_channel::tech.
Referenced by dial_trunk(), do_notify(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00860 { 00861 int i = 0; 00862 struct ast_dial_channel *channel = NULL; 00863 00864 if (!dial) 00865 return -1; 00866 00867 /* Hangup and deallocate all the dialed channels */ 00868 AST_LIST_LOCK(&dial->channels); 00869 AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) { 00870 /* Disable any enabled options */ 00871 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00872 if (!channel->options[i]) 00873 continue; 00874 if (option_types[i].disable) 00875 option_types[i].disable(channel->options[i]); 00876 channel->options[i] = NULL; 00877 } 00878 /* Hang up channel if need be */ 00879 if (channel->owner) { 00880 ast_hangup(channel->owner); 00881 channel->owner = NULL; 00882 } 00883 /* Free structure */ 00884 ast_free(channel->tech); 00885 ast_free(channel->device); 00886 AST_LIST_REMOVE_CURRENT(list); 00887 ast_free(channel); 00888 } 00889 AST_LIST_TRAVERSE_SAFE_END; 00890 AST_LIST_UNLOCK(&dial->channels); 00891 00892 /* Disable any enabled options globally */ 00893 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) { 00894 if (!dial->options[i]) 00895 continue; 00896 if (option_types[i].disable) 00897 option_types[i].disable(dial->options[i]); 00898 dial->options[i] = NULL; 00899 } 00900 00901 /* Lock be gone! */ 00902 ast_mutex_destroy(&dial->lock); 00903 00904 /* Free structure */ 00905 ast_free(dial); 00906 00907 return 0; 00908 }
void ast_dial_hangup | ( | struct ast_dial * | dial | ) |
Hangup channels.
dial | Dialing structure |
Definition at line 835 of file dial.c.
References ast_hangup(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_dial::channels, ast_dial_channel::list, and ast_dial_channel::owner.
Referenced by ast_dial_run().
00836 { 00837 struct ast_dial_channel *channel = NULL; 00838 00839 if (!dial) 00840 return; 00841 00842 AST_LIST_LOCK(&dial->channels); 00843 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00844 if (channel->owner) { 00845 ast_hangup(channel->owner); 00846 channel->owner = NULL; 00847 } 00848 } 00849 AST_LIST_UNLOCK(&dial->channels); 00850 00851 return; 00852 }
enum ast_dial_result ast_dial_join | ( | struct ast_dial * | dial | ) |
Cancel async thread.
dial | Dialing structure |
Definition at line 787 of file dial.c.
References ast_channel_lock, ast_channel_unlock, AST_DIAL_RESULT_FAILED, AST_LIST_FIRST, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_dial::channels, ast_dial::lock, ast_dial::state, and ast_dial::thread.
Referenced by dial_trunk(), run_station(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().
00788 { 00789 pthread_t thread; 00790 00791 /* If the dial structure is not running in async, return failed */ 00792 if (dial->thread == AST_PTHREADT_NULL) 00793 return AST_DIAL_RESULT_FAILED; 00794 00795 /* Record thread */ 00796 thread = dial->thread; 00797 00798 /* Boom, commence locking */ 00799 ast_mutex_lock(&dial->lock); 00800 00801 /* Stop the thread */ 00802 dial->thread = AST_PTHREADT_STOP; 00803 00804 /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */ 00805 AST_LIST_LOCK(&dial->channels); 00806 if (AST_LIST_FIRST(&dial->channels)->is_running_app) { 00807 struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner; 00808 if (chan) { 00809 ast_channel_lock(chan); 00810 ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT); 00811 ast_channel_unlock(chan); 00812 } 00813 } else { 00814 /* Now we signal it with SIGURG so it will break out of it's waitfor */ 00815 pthread_kill(thread, SIGURG); 00816 } 00817 AST_LIST_UNLOCK(&dial->channels); 00818 00819 /* Yay done with it */ 00820 ast_mutex_unlock(&dial->lock); 00821 00822 /* Finally wait for the thread to exit */ 00823 pthread_join(thread, NULL); 00824 00825 /* Yay thread is all gone */ 00826 dial->thread = AST_PTHREADT_NULL; 00827 00828 return dial->state; 00829 }
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 1011 of file dial.c.
References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::disable, find_dial_channel(), option_types, and ast_dial_channel::options.
01012 { 01013 struct ast_dial_channel *channel = NULL; 01014 01015 /* Ensure we have required arguments */ 01016 if (!dial || AST_LIST_EMPTY(&dial->channels)) 01017 return -1; 01018 01019 if (!(channel = find_dial_channel(dial, num))) 01020 return -1; 01021 01022 /* If the option is not enabled, return failure */ 01023 if (!channel->options[option]) 01024 return -1; 01025 01026 /* Execute callback of option to disable it if it exists */ 01027 if (option_types[option].disable) 01028 option_types[option].disable(channel->options[option]); 01029 01030 /* Finally disable the option on the structure */ 01031 channel->options[option] = NULL; 01032 01033 return 0; 01034 }
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 959 of file dial.c.
References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::enable, find_dial_channel(), option_types, and ast_dial_channel::options.
00960 { 00961 struct ast_dial_channel *channel = NULL; 00962 00963 /* Ensure we have required arguments */ 00964 if (!dial || AST_LIST_EMPTY(&dial->channels)) 00965 return -1; 00966 00967 if (!(channel = find_dial_channel(dial, num))) 00968 return -1; 00969 00970 /* If the option is already enabled, return failure */ 00971 if (channel->options[option]) 00972 return -1; 00973 00974 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00975 if (option_types[option].enable) 00976 channel->options[option] = option_types[option].enable(data); 00977 else 00978 channel->options[option] = (void*)1; 00979 00980 return 0; 00981 }
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 988 of file dial.c.
References ast_option_types::disable, option_types, and ast_dial::options.
00989 { 00990 /* If the option is not enabled, return failure */ 00991 if (!dial->options[option]) { 00992 return -1; 00993 } 00994 00995 /* Execute callback of option to disable if it exists */ 00996 if (option_types[option].disable) 00997 option_types[option].disable(dial->options[option]); 00998 00999 /* Finally disable option on the structure */ 01000 dial->options[option] = NULL; 01001 01002 return 0; 01003 }
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 916 of file dial.c.
References ast_option_types::enable, option_types, and ast_dial::options.
Referenced by do_notify().
00917 { 00918 /* If the option is already enabled, return failure */ 00919 if (dial->options[option]) 00920 return -1; 00921 00922 /* Execute enable callback if it exists, if not simply make sure the value is set */ 00923 if (option_types[option].enable) 00924 dial->options[option] = option_types[option].enable(data); 00925 else 00926 dial->options[option] = (void*)1; 00927 00928 return 0; 00929 }
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 707 of file dial.c.
References ast_debug, ast_dial_hangup(), AST_DIAL_RESULT_FAILED, AST_DIAL_RESULT_INVALID, AST_DIAL_RESULT_TRYING, AST_LIST_EMPTY, ast_pthread_create, async_dial(), begin_dial(), ast_dial::channels, monitor_dial(), ast_dial::state, and ast_dial::thread.
Referenced by dial_trunk(), do_notify(), and sla_ring_station().
00708 { 00709 enum ast_dial_result res = AST_DIAL_RESULT_TRYING; 00710 00711 /* Ensure required arguments are passed */ 00712 if (!dial || (!chan && !async)) { 00713 ast_debug(1, "invalid #1\n"); 00714 return AST_DIAL_RESULT_INVALID; 00715 } 00716 00717 /* If there are no channels to dial we can't very well try to dial them */ 00718 if (AST_LIST_EMPTY(&dial->channels)) { 00719 ast_debug(1, "invalid #2\n"); 00720 return AST_DIAL_RESULT_INVALID; 00721 } 00722 00723 /* Dial each requested channel */ 00724 if (!begin_dial(dial, chan)) 00725 return AST_DIAL_RESULT_FAILED; 00726 00727 /* If we are running async spawn a thread and send it away... otherwise block here */ 00728 if (async) { 00729 dial->state = AST_DIAL_RESULT_TRYING; 00730 /* Try to create a thread */ 00731 if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) { 00732 /* Failed to create the thread - hangup all dialed channels and return failed */ 00733 ast_dial_hangup(dial); 00734 res = AST_DIAL_RESULT_FAILED; 00735 } 00736 } else { 00737 res = monitor_dial(dial, chan); 00738 } 00739 00740 return res; 00741 }
void ast_dial_set_global_timeout | ( | struct ast_dial * | dial, | |
int | timeout | |||
) |
Set the maximum time (globally) allowed for trying to ring phones.
dial | The dial structure to apply the time limit to | |
timeout | Maximum time allowed |
Definition at line 1046 of file dial.c.
References ast_dial::actual_timeout, and ast_dial::timeout.
Referenced by do_notify().
01047 { 01048 dial->timeout = timeout; 01049 01050 if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1)) 01051 dial->actual_timeout = dial->timeout; 01052 01053 return; 01054 }
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 1036 of file dial.c.
References ast_dial::state_callback.
Referenced by sla_ring_station().
01037 { 01038 dial->state_callback = callback; 01039 }
void ast_dial_set_timeout | ( | struct ast_dial * | dial, | |
int | num, | |||
int | timeout | |||
) |
Set the maximum time (per channel) allowed for trying to ring the phone.
dial | The dial structure the channel belongs to | |
num | Channel number to set timeout on | |
timeout | Maximum time allowed |
Definition at line 1062 of file dial.c.
References ast_dial::actual_timeout, find_dial_channel(), and ast_dial_channel::timeout.
01063 { 01064 struct ast_dial_channel *channel = NULL; 01065 01066 if (!(channel = find_dial_channel(dial, num))) 01067 return; 01068 01069 channel->timeout = timeout; 01070 01071 if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1)) 01072 dial->actual_timeout = channel->timeout; 01073 01074 return; 01075 }
enum ast_dial_result ast_dial_state | ( | struct ast_dial * | dial | ) |
Return state of dial.
dial | Dialing structure |
Definition at line 778 of file dial.c.
References ast_dial::state.
Referenced by dial_trunk(), and sla_handle_dial_state_event().
00779 { 00780 return dial->state; 00781 }
static void* async_dial | ( | void * | data | ) | [static] |
Dial async thread function.
Definition at line 693 of file dial.c.
References monitor_dial().
Referenced by ast_dial_run().
00694 { 00695 struct ast_dial *dial = data; 00696 00697 /* This is really really simple... we basically pass monitor_dial a NULL owner and it changes it's behavior */ 00698 monitor_dial(dial, NULL); 00699 00700 return NULL; 00701 }
static int begin_dial | ( | struct ast_dial * | dial, | |
struct ast_channel * | chan | |||
) | [static] |
Helper function that does the beginning dialing per dial structure.
Definition at line 304 of file dial.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, begin_dial_channel(), ast_dial::channels, and ast_dial_channel::list.
Referenced by ast_dial_run().
00305 { 00306 struct ast_dial_channel *channel = NULL; 00307 int success = 0; 00308 00309 /* Iterate through channel list, requesting and calling each one */ 00310 AST_LIST_LOCK(&dial->channels); 00311 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00312 success += begin_dial_channel(channel, chan); 00313 } 00314 AST_LIST_UNLOCK(&dial->channels); 00315 00316 /* If number of failures matches the number of channels, then this truly failed */ 00317 return success; 00318 }
static int begin_dial_channel | ( | struct ast_dial_channel * | channel, | |
struct ast_channel * | chan | |||
) | [static] |
Helper function that does the beginning dialing per-appended channel.
Definition at line 251 of file dial.c.
References accountcode, ast_channel::adsicpe, ast_channel::appl, ast_call(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_connected_line_copy_from_caller(), ast_copy_string(), AST_FORMAT_AUDIO_MASK, ast_hangup(), AST_MAX_EXTENSION, ast_party_redirecting_copy(), ast_poll_channel_add(), ast_request(), ast_string_field_set, ast_strlen_zero(), ast_verb, ast_dial_channel::cause, ast_channel::connected, ast_channel::data, ast_dial_channel::device, ast_channel::dialed, language, musicclass, ast_channel::musicclass, ast_channel::nativeformats, ast_dial_channel::owner, ast_channel::redirecting, ast_dial_channel::tech, ast_channel::transfercapability, ast_party_dialed::transit_network_select, and ast_channel::whentohangup.
Referenced by begin_dial(), and handle_call_forward().
00252 { 00253 char numsubst[AST_MAX_EXTENSION]; 00254 int res = 1; 00255 00256 /* Copy device string over */ 00257 ast_copy_string(numsubst, channel->device, sizeof(numsubst)); 00258 00259 /* If we fail to create our owner channel bail out */ 00260 if (!(channel->owner = ast_request(channel->tech, chan ? chan->nativeformats : AST_FORMAT_AUDIO_MASK, chan, numsubst, &channel->cause))) 00261 return -1; 00262 00263 channel->owner->appl = "AppDial2"; 00264 channel->owner->data = "(Outgoing Line)"; 00265 memset(&channel->owner->whentohangup, 0, sizeof(channel->owner->whentohangup)); 00266 00267 /* Inherit everything from he who spawned this dial */ 00268 if (chan) { 00269 ast_channel_inherit_variables(chan, channel->owner); 00270 ast_channel_datastore_inherit(chan, channel->owner); 00271 00272 /* Copy over callerid information */ 00273 ast_party_redirecting_copy(&channel->owner->redirecting, &chan->redirecting); 00274 00275 channel->owner->dialed.transit_network_select = chan->dialed.transit_network_select; 00276 00277 ast_connected_line_copy_from_caller(&channel->owner->connected, &chan->caller); 00278 00279 ast_string_field_set(channel->owner, language, chan->language); 00280 ast_string_field_set(channel->owner, accountcode, chan->accountcode); 00281 if (ast_strlen_zero(channel->owner->musicclass)) 00282 ast_string_field_set(channel->owner, musicclass, chan->musicclass); 00283 00284 channel->owner->adsicpe = chan->adsicpe; 00285 channel->owner->transfercapability = chan->transfercapability; 00286 } 00287 00288 /* Attempt to actually call this device */ 00289 if ((res = ast_call(channel->owner, numsubst, 0))) { 00290 res = 0; 00291 ast_hangup(channel->owner); 00292 channel->owner = NULL; 00293 } else { 00294 if (chan) 00295 ast_poll_channel_add(chan, channel->owner); 00296 res = 1; 00297 ast_verb(3, "Called %s\n", numsubst); 00298 } 00299 00300 return res; 00301 }
static struct ast_dial_channel* find_dial_channel | ( | struct ast_dial * | dial, | |
int | num | |||
) | [static] |
Helper function for finding a channel in a dial structure based on number.
Definition at line 933 of file dial.c.
References AST_LIST_LAST, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_dial::channels, ast_dial_channel::list, and ast_dial_channel::num.
Referenced by ast_dial_option_disable(), ast_dial_option_enable(), and ast_dial_set_timeout().
00934 { 00935 struct ast_dial_channel *channel = AST_LIST_LAST(&dial->channels); 00936 00937 /* We can try to predict programmer behavior, the last channel they added is probably the one they wanted to modify */ 00938 if (channel->num == num) 00939 return channel; 00940 00941 /* Hrm not at the end... looking through the list it is! */ 00942 AST_LIST_LOCK(&dial->channels); 00943 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00944 if (channel->num == num) 00945 break; 00946 } 00947 AST_LIST_UNLOCK(&dial->channels); 00948 00949 return channel; 00950 }
static struct ast_dial_channel* find_relative_dial_channel | ( | struct ast_dial * | dial, | |
struct ast_channel * | owner | |||
) | [static] |
Helper function that finds the dialed channel based on owner.
Definition at line 360 of file dial.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_dial::channels, ast_dial_channel::list, and ast_dial_channel::owner.
Referenced by monitor_dial().
00361 { 00362 struct ast_dial_channel *channel = NULL; 00363 00364 AST_LIST_LOCK(&dial->channels); 00365 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00366 if (channel->owner == owner) 00367 break; 00368 } 00369 AST_LIST_UNLOCK(&dial->channels); 00370 00371 return channel; 00372 }
static int handle_call_forward | ( | struct ast_dial * | dial, | |
struct ast_dial_channel * | channel, | |||
struct ast_channel * | chan | |||
) | [static] |
Helper function to handle channels that have been call forwarded.
Definition at line 321 of file dial.c.
References AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, ast_free, ast_hangup(), AST_LIST_UNLOCK, ast_strdup, ast_strdupa, begin_dial_channel(), ast_channel::call_forward, ast_dial::channels, ast_dial_channel::device, FIND_RELATIVE_OPTION, ast_dial_channel::owner, and ast_dial_channel::tech.
Referenced by monitor_dial().
00322 { 00323 struct ast_channel *original = channel->owner; 00324 char *tmp = ast_strdupa(channel->owner->call_forward); 00325 char *tech = "Local", *device = tmp, *stuff; 00326 00327 /* If call forwarding is disabled just drop the original channel and don't attempt to dial the new one */ 00328 if (FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_DISABLE_CALL_FORWARDING)) { 00329 ast_hangup(original); 00330 channel->owner = NULL; 00331 return 0; 00332 } 00333 00334 /* Figure out the new destination */ 00335 if ((stuff = strchr(tmp, '/'))) { 00336 *stuff++ = '\0'; 00337 tech = tmp; 00338 device = stuff; 00339 } 00340 00341 /* Drop old destination information */ 00342 ast_free(channel->tech); 00343 ast_free(channel->device); 00344 00345 /* Update the dial channel with the new destination information */ 00346 channel->tech = ast_strdup(tech); 00347 channel->device = ast_strdup(device); 00348 AST_LIST_UNLOCK(&dial->channels); 00349 00350 /* Finally give it a go... send it out into the world */ 00351 begin_dial_channel(channel, chan); 00352 00353 /* Drop the original channel */ 00354 ast_hangup(original); 00355 00356 return 0; 00357 }
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 383 of file dial.c.
References ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_FLASH, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_OFFHOOK, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_DIAL_OPTION_MUSIC, AST_DIAL_RESULT_ANSWERED, AST_DIAL_RESULT_PROCEEDING, AST_DIAL_RESULT_PROGRESS, AST_DIAL_RESULT_RINGING, AST_FRAME_CONTROL, ast_hangup(), ast_indicate(), ast_indicate_data(), AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_verb, ast_verbose, ast_dial::channels, ast_frame::data, ast_frame::datalen, ast_channel::exten, ast_frame::frametype, ast_frame_subclass::integer, ast_dial_channel::list, ast_channel::name, option_verbose, ast_dial::options, ast_dial_channel::owner, ast_frame::ptr, set_state(), ast_frame::subclass, and VERBOSE_PREFIX_3.
Referenced by monitor_dial(), and socket_read().
00384 { 00385 if (fr->frametype == AST_FRAME_CONTROL) { 00386 switch (fr->subclass.integer) { 00387 case AST_CONTROL_ANSWER: 00388 ast_verb(3, "%s answered %s\n", channel->owner->name, chan->name); 00389 AST_LIST_LOCK(&dial->channels); 00390 AST_LIST_REMOVE(&dial->channels, channel, list); 00391 AST_LIST_INSERT_HEAD(&dial->channels, channel, list); 00392 AST_LIST_UNLOCK(&dial->channels); 00393 set_state(dial, AST_DIAL_RESULT_ANSWERED); 00394 break; 00395 case AST_CONTROL_BUSY: 00396 ast_verb(3, "%s is busy\n", channel->owner->name); 00397 ast_hangup(channel->owner); 00398 channel->owner = NULL; 00399 break; 00400 case AST_CONTROL_CONGESTION: 00401 ast_verb(3, "%s is circuit-busy\n", channel->owner->name); 00402 ast_hangup(channel->owner); 00403 channel->owner = NULL; 00404 break; 00405 case AST_CONTROL_INCOMPLETE: 00406 ast_verb(3, "%s dialed Incomplete extension %s\n", channel->owner->name, channel->owner->exten); 00407 ast_indicate(chan, AST_CONTROL_INCOMPLETE); 00408 break; 00409 case AST_CONTROL_RINGING: 00410 ast_verb(3, "%s is ringing\n", channel->owner->name); 00411 if (!dial->options[AST_DIAL_OPTION_MUSIC]) 00412 ast_indicate(chan, AST_CONTROL_RINGING); 00413 set_state(dial, AST_DIAL_RESULT_RINGING); 00414 break; 00415 case AST_CONTROL_PROGRESS: 00416 ast_verb(3, "%s is making progress, passing it to %s\n", channel->owner->name, chan->name); 00417 ast_indicate(chan, AST_CONTROL_PROGRESS); 00418 set_state(dial, AST_DIAL_RESULT_PROGRESS); 00419 break; 00420 case AST_CONTROL_VIDUPDATE: 00421 ast_verb(3, "%s requested a video update, passing it to %s\n", channel->owner->name, chan->name); 00422 ast_indicate(chan, AST_CONTROL_VIDUPDATE); 00423 break; 00424 case AST_CONTROL_SRCUPDATE: 00425 if (option_verbose > 2) 00426 ast_verbose (VERBOSE_PREFIX_3 "%s requested a source update, passing it to %s\n", channel->owner->name, chan->name); 00427 ast_indicate(chan, AST_CONTROL_SRCUPDATE); 00428 break; 00429 case AST_CONTROL_CONNECTED_LINE: 00430 ast_verb(3, "%s connected line has changed, passing it to %s\n", channel->owner->name, chan->name); 00431 if (ast_channel_connected_line_macro(channel->owner, chan, fr, 1, 1)) { 00432 ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, fr->data.ptr, fr->datalen); 00433 } 00434 break; 00435 case AST_CONTROL_REDIRECTING: 00436 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", channel->owner->name, chan->name); 00437 if (ast_channel_redirecting_macro(channel->owner, chan, fr, 1, 1)) { 00438 ast_indicate_data(chan, AST_CONTROL_REDIRECTING, fr->data.ptr, fr->datalen); 00439 } 00440 break; 00441 case AST_CONTROL_PROCEEDING: 00442 ast_verb(3, "%s is proceeding, passing it to %s\n", channel->owner->name, chan->name); 00443 ast_indicate(chan, AST_CONTROL_PROCEEDING); 00444 set_state(dial, AST_DIAL_RESULT_PROCEEDING); 00445 break; 00446 case AST_CONTROL_HOLD: 00447 ast_verb(3, "Call on %s placed on hold\n", chan->name); 00448 ast_indicate(chan, AST_CONTROL_HOLD); 00449 break; 00450 case AST_CONTROL_UNHOLD: 00451 ast_verb(3, "Call on %s left from hold\n", chan->name); 00452 ast_indicate(chan, AST_CONTROL_UNHOLD); 00453 break; 00454 case AST_CONTROL_OFFHOOK: 00455 case AST_CONTROL_FLASH: 00456 break; 00457 case -1: 00458 /* Prod the channel */ 00459 ast_indicate(chan, -1); 00460 break; 00461 default: 00462 break; 00463 } 00464 } 00465 00466 return; 00467 }
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 470 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_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_verb, ast_dial::channels, ast_frame::frametype, ast_frame_subclass::integer, ast_dial_channel::list, ast_channel::name, ast_dial_channel::owner, set_state(), and ast_frame::subclass.
Referenced by monitor_dial().
00471 { 00472 /* If we have no owner we can only update the state of the dial structure, so only look at control frames */ 00473 if (fr->frametype != AST_FRAME_CONTROL) 00474 return; 00475 00476 switch (fr->subclass.integer) { 00477 case AST_CONTROL_ANSWER: 00478 ast_verb(3, "%s answered\n", channel->owner->name); 00479 AST_LIST_LOCK(&dial->channels); 00480 AST_LIST_REMOVE(&dial->channels, channel, list); 00481 AST_LIST_INSERT_HEAD(&dial->channels, channel, list); 00482 AST_LIST_UNLOCK(&dial->channels); 00483 set_state(dial, AST_DIAL_RESULT_ANSWERED); 00484 break; 00485 case AST_CONTROL_BUSY: 00486 ast_verb(3, "%s is busy\n", channel->owner->name); 00487 ast_hangup(channel->owner); 00488 channel->owner = NULL; 00489 break; 00490 case AST_CONTROL_CONGESTION: 00491 ast_verb(3, "%s is circuit-busy\n", channel->owner->name); 00492 ast_hangup(channel->owner); 00493 channel->owner = NULL; 00494 break; 00495 case AST_CONTROL_RINGING: 00496 ast_verb(3, "%s is ringing\n", channel->owner->name); 00497 set_state(dial, AST_DIAL_RESULT_RINGING); 00498 break; 00499 case AST_CONTROL_PROGRESS: 00500 ast_verb(3, "%s is making progress\n", channel->owner->name); 00501 set_state(dial, AST_DIAL_RESULT_PROGRESS); 00502 break; 00503 case AST_CONTROL_PROCEEDING: 00504 ast_verb(3, "%s is proceeding\n", channel->owner->name); 00505 set_state(dial, AST_DIAL_RESULT_PROCEEDING); 00506 break; 00507 default: 00508 break; 00509 } 00510 00511 return; 00512 }
static int handle_timeout_trip | ( | struct ast_dial * | dial, | |
struct timeval | start | |||
) | [static] |
Helper function to handle when a timeout occurs on dialing attempt.
Definition at line 515 of file dial.c.
References AST_DIAL_RESULT_TIMEOUT, ast_hangup(), AST_LIST_TRAVERSE, ast_tvdiff_ms(), ast_tvnow(), ast_dial::channels, ast_dial_channel::list, ast_dial_channel::owner, set_state(), ast_dial::state, ast_dial_channel::timeout, and ast_dial::timeout.
Referenced by monitor_dial().
00516 { 00517 struct ast_dial_channel *channel = NULL; 00518 int diff = ast_tvdiff_ms(ast_tvnow(), start), lowest_timeout = -1, new_timeout = -1; 00519 00520 /* If the global dial timeout tripped switch the state to timeout so our channel loop will drop every channel */ 00521 if (diff >= dial->timeout) { 00522 set_state(dial, AST_DIAL_RESULT_TIMEOUT); 00523 new_timeout = 0; 00524 } 00525 00526 /* Go through dropping out channels that have met their timeout */ 00527 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00528 if (dial->state == AST_DIAL_RESULT_TIMEOUT || diff >= channel->timeout) { 00529 ast_hangup(channel->owner); 00530 channel->owner = NULL; 00531 } else if ((lowest_timeout == -1) || (lowest_timeout > channel->timeout)) { 00532 lowest_timeout = channel->timeout; 00533 } 00534 } 00535 00536 /* Calculate the new timeout using the lowest timeout found */ 00537 if (lowest_timeout >= 0) 00538 new_timeout = lowest_timeout - diff; 00539 00540 return new_timeout; 00541 }
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 544 of file dial.c.
References ast_dial::actual_timeout, answer_exec_run(), answer_exec_struct::app, answer_exec_struct::args, AST_CONTROL_RINGING, AST_DIAL_OPTION_ANSWER_EXEC, AST_DIAL_OPTION_MUSIC, 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_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, AST_MAX_WATCHERS, ast_moh_start(), ast_moh_stop(), ast_poll_channel_del(), AST_PTHREADT_STOP, ast_read(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_tvnow(), ast_waitfor_n(), ast_channel::call_forward, ast_dial::channels, find_relative_dial_channel(), FIND_RELATIVE_OPTION, handle_call_forward(), handle_frame(), handle_frame_ownerless(), handle_timeout_trip(), IS_CALLER, ast_dial_channel::is_running_app, musicclass, ast_channel::musicclass, ast_dial::options, ast_dial_channel::owner, set_state(), ast_dial::state, and ast_dial::thread.
Referenced by ast_dial_run(), and async_dial().
00545 { 00546 int timeout = -1; 00547 struct ast_channel *cs[AST_MAX_WATCHERS], *who = NULL; 00548 struct ast_dial_channel *channel = NULL; 00549 struct answer_exec_struct *answer_exec = NULL; 00550 struct timeval start; 00551 00552 set_state(dial, AST_DIAL_RESULT_TRYING); 00553 00554 /* If the "always indicate ringing" option is set, change state to ringing and indicate to the owner if present */ 00555 if (dial->options[AST_DIAL_OPTION_RINGING]) { 00556 set_state(dial, AST_DIAL_RESULT_RINGING); 00557 if (chan) 00558 ast_indicate(chan, AST_CONTROL_RINGING); 00559 } else if (chan && dial->options[AST_DIAL_OPTION_MUSIC] && 00560 !ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) { 00561 char *original_moh = ast_strdupa(chan->musicclass); 00562 ast_indicate(chan, -1); 00563 ast_string_field_set(chan, musicclass, dial->options[AST_DIAL_OPTION_MUSIC]); 00564 ast_moh_start(chan, dial->options[AST_DIAL_OPTION_MUSIC], NULL); 00565 ast_string_field_set(chan, musicclass, original_moh); 00566 } 00567 00568 /* Record start time for timeout purposes */ 00569 start = ast_tvnow(); 00570 00571 /* We actually figured out the maximum timeout we can do as they were added, so we can directly access the info */ 00572 timeout = dial->actual_timeout; 00573 00574 /* Go into an infinite loop while we are trying */ 00575 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)) { 00576 int pos = 0, count = 0; 00577 struct ast_frame *fr = NULL; 00578 00579 /* Set up channel structure array */ 00580 pos = count = 0; 00581 if (chan) 00582 cs[pos++] = chan; 00583 00584 /* Add channels we are attempting to dial */ 00585 AST_LIST_LOCK(&dial->channels); 00586 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00587 if (channel->owner) { 00588 cs[pos++] = channel->owner; 00589 count++; 00590 } 00591 } 00592 AST_LIST_UNLOCK(&dial->channels); 00593 00594 /* If we have no outbound channels in progress, switch state to unanswered and stop */ 00595 if (!count) { 00596 set_state(dial, AST_DIAL_RESULT_UNANSWERED); 00597 break; 00598 } 00599 00600 /* Just to be safe... */ 00601 if (dial->thread == AST_PTHREADT_STOP) 00602 break; 00603 00604 /* Wait for frames from channels */ 00605 who = ast_waitfor_n(cs, pos, &timeout); 00606 00607 /* Check to see if our thread is being cancelled */ 00608 if (dial->thread == AST_PTHREADT_STOP) 00609 break; 00610 00611 /* If the timeout no longer exists OR if we got no channel it basically means the timeout was tripped, so handle it */ 00612 if (!timeout || !who) { 00613 timeout = handle_timeout_trip(dial, start); 00614 continue; 00615 } 00616 00617 /* Find relative dial channel */ 00618 if (!chan || !IS_CALLER(chan, who)) 00619 channel = find_relative_dial_channel(dial, who); 00620 00621 /* See if this channel has been forwarded elsewhere */ 00622 if (!ast_strlen_zero(who->call_forward)) { 00623 handle_call_forward(dial, channel, chan); 00624 continue; 00625 } 00626 00627 /* Attempt to read in a frame */ 00628 if (!(fr = ast_read(who))) { 00629 /* If this is the caller then we switch state to hangup and stop */ 00630 if (chan && IS_CALLER(chan, who)) { 00631 set_state(dial, AST_DIAL_RESULT_HANGUP); 00632 break; 00633 } 00634 if (chan) 00635 ast_poll_channel_del(chan, channel->owner); 00636 ast_hangup(who); 00637 channel->owner = NULL; 00638 continue; 00639 } 00640 00641 /* Process the frame */ 00642 if (chan) 00643 handle_frame(dial, channel, fr, chan); 00644 else 00645 handle_frame_ownerless(dial, channel, fr); 00646 00647 /* Free the received frame and start all over */ 00648 ast_frfree(fr); 00649 } 00650 00651 /* Do post-processing from loop */ 00652 if (dial->state == AST_DIAL_RESULT_ANSWERED) { 00653 /* Hangup everything except that which answered */ 00654 AST_LIST_LOCK(&dial->channels); 00655 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00656 if (!channel->owner || channel->owner == who) 00657 continue; 00658 if (chan) 00659 ast_poll_channel_del(chan, channel->owner); 00660 ast_hangup(channel->owner); 00661 channel->owner = NULL; 00662 } 00663 AST_LIST_UNLOCK(&dial->channels); 00664 /* If ANSWER_EXEC is enabled as an option, execute application on answered channel */ 00665 if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC))) { 00666 channel->is_running_app = 1; 00667 answer_exec_run(dial, channel, answer_exec->app, answer_exec->args); 00668 channel->is_running_app = 0; 00669 } 00670 00671 if (chan && dial->options[AST_DIAL_OPTION_MUSIC] && 00672 !ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) { 00673 ast_moh_stop(chan); 00674 } 00675 } else if (dial->state == AST_DIAL_RESULT_HANGUP) { 00676 /* Hangup everything */ 00677 AST_LIST_LOCK(&dial->channels); 00678 AST_LIST_TRAVERSE(&dial->channels, channel, list) { 00679 if (!channel->owner) 00680 continue; 00681 if (chan) 00682 ast_poll_channel_del(chan, channel->owner); 00683 ast_hangup(channel->owner); 00684 channel->owner = NULL; 00685 } 00686 AST_LIST_UNLOCK(&dial->channels); 00687 } 00688 00689 return dial->state; 00690 }
static int music_disable | ( | void * | data | ) | [static] |
static void* music_enable | ( | void * | data | ) | [static] |
Definition at line 129 of file dial.c.
References ast_strdup.
00130 { 00131 return ast_strdup(data); 00132 }
static void set_state | ( | struct ast_dial * | dial, | |
enum ast_dial_result | state | |||
) | [static] |
Definition at line 374 of file dial.c.
References ast_dial::state, and ast_dial::state_callback.
00375 { 00376 dial->state = state; 00377 00378 if (dial->state_callback) 00379 dial->state_callback(dial); 00380 }
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().