Asterisk - The Open Source Telephony Project GIT-master-4f2b068
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
dial.h File Reference

Dialing API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* ast_dial_state_callback) (struct ast_dial *)
 

Enumerations

enum  ast_dial_option {
  AST_DIAL_OPTION_RINGING , AST_DIAL_OPTION_ANSWER_EXEC , AST_DIAL_OPTION_MUSIC , AST_DIAL_OPTION_DISABLE_CALL_FORWARDING ,
  AST_DIAL_OPTION_PREDIAL , AST_DIAL_OPTION_DIAL_REPLACES_SELF , AST_DIAL_OPTION_SELF_DESTROY , AST_DIAL_OPTION_MAX
}
 List of options that are applicable either globally or per dialed channel. More...
 
enum  ast_dial_result {
  AST_DIAL_RESULT_INVALID , AST_DIAL_RESULT_FAILED , AST_DIAL_RESULT_TRYING , AST_DIAL_RESULT_RINGING ,
  AST_DIAL_RESULT_PROGRESS , AST_DIAL_RESULT_PROCEEDING , AST_DIAL_RESULT_ANSWERED , AST_DIAL_RESULT_TIMEOUT ,
  AST_DIAL_RESULT_HANGUP , AST_DIAL_RESULT_UNANSWERED
}
 List of return codes for dial run API calls. More...
 

Functions

struct ast_channelast_dial_answered (struct ast_dial *dial)
 Return channel that answered.
 
struct ast_channelast_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, const struct ast_assigned_ids *assignedids)
 Append a channel.
 
int ast_dial_append_channel (struct ast_dial *dial, struct ast_channel *chan)
 Append a channel using an actual channel object.
 
struct ast_dialast_dial_create (void)
 New dialing structure.
 
int ast_dial_destroy (struct ast_dial *dial)
 Destroys a dialing structure.
 
struct ast_channelast_dial_get_channel (struct ast_dial *dial, int num)
 Get the dialing channel, if prerun has been executed.
 
void * ast_dial_get_user_data (struct ast_dial *dial)
 Return the user data on a dial 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.
 
int ast_dial_prerun (struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap)
 Request all appended channels, but do not dial.
 
int ast_dial_reason (struct ast_dial *dial, int num)
 Get the reason an outgoing channel has failed.
 
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.
 
void ast_dial_set_user_data (struct ast_dial *dial, void *user_data)
 Set user data on a dial structure.
 
enum ast_dial_result ast_dial_state (struct ast_dial *dial)
 Return state of dial.
 
const char * ast_hangup_cause_to_dial_status (int hangup_cause)
 Convert a hangup cause to a publishable dial status.
 

Detailed Description

Dialing API.

Definition in file dial.h.

Typedef Documentation

◆ ast_dial_state_callback

typedef void(* ast_dial_state_callback) (struct ast_dial *)

Definition at line 39 of file dial.h.

Enumeration Type Documentation

◆ ast_dial_option

List of options that are applicable either globally or per dialed channel.

Enumerator
AST_DIAL_OPTION_RINGING 

Always indicate ringing to caller

AST_DIAL_OPTION_ANSWER_EXEC 

Execute application upon answer in async mode

AST_DIAL_OPTION_MUSIC 

Play music on hold instead of ringing to the calling channel

AST_DIAL_OPTION_DISABLE_CALL_FORWARDING 

Disable call forwarding on channels

AST_DIAL_OPTION_PREDIAL 

Execute a predial subroutine before dialing

AST_DIAL_OPTION_DIAL_REPLACES_SELF 

The dial operation is a replacement for the requester

AST_DIAL_OPTION_SELF_DESTROY 

Destroy self at end of ast_dial_run

AST_DIAL_OPTION_MAX 

End terminator – must always remain last

Definition at line 42 of file dial.h.

42 {
43 AST_DIAL_OPTION_RINGING, /*!< Always indicate ringing to caller */
44 AST_DIAL_OPTION_ANSWER_EXEC, /*!< Execute application upon answer in async mode */
45 AST_DIAL_OPTION_MUSIC, /*!< Play music on hold instead of ringing to the calling channel */
46 AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, /*!< Disable call forwarding on channels */
47 AST_DIAL_OPTION_PREDIAL, /*!< Execute a predial subroutine before dialing */
48 AST_DIAL_OPTION_DIAL_REPLACES_SELF, /*!< The dial operation is a replacement for the requester */
49 AST_DIAL_OPTION_SELF_DESTROY, /*!< Destroy self at end of ast_dial_run */
50 AST_DIAL_OPTION_MAX, /*!< End terminator -- must always remain last */
51};
@ AST_DIAL_OPTION_DIAL_REPLACES_SELF
Definition dial.h:48
@ AST_DIAL_OPTION_ANSWER_EXEC
Definition dial.h:44
@ AST_DIAL_OPTION_RINGING
Definition dial.h:43
@ AST_DIAL_OPTION_MUSIC
Definition dial.h:45
@ AST_DIAL_OPTION_PREDIAL
Definition dial.h:47
@ AST_DIAL_OPTION_DISABLE_CALL_FORWARDING
Definition dial.h:46
@ AST_DIAL_OPTION_SELF_DESTROY
Definition dial.h:49
@ AST_DIAL_OPTION_MAX
Definition dial.h:50

◆ ast_dial_result

List of return codes for dial run API calls.

Enumerator
AST_DIAL_RESULT_INVALID 

Invalid options were passed to run function

AST_DIAL_RESULT_FAILED 

Attempts to dial failed before reaching critical state

AST_DIAL_RESULT_TRYING 

Currently trying to dial

AST_DIAL_RESULT_RINGING 

Dial is presently ringing

AST_DIAL_RESULT_PROGRESS 

Dial is presently progressing

AST_DIAL_RESULT_PROCEEDING 

Dial is presently proceeding

AST_DIAL_RESULT_ANSWERED 

A channel was answered

AST_DIAL_RESULT_TIMEOUT 

Timeout was tripped, nobody answered

AST_DIAL_RESULT_HANGUP 

Caller hung up

AST_DIAL_RESULT_UNANSWERED 

Nobody answered

Definition at line 54 of file dial.h.

54 {
55 AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */
56 AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */
57 AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */
58 AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */
59 AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */
60 AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */
61 AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */
62 AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */
63 AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */
64 AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */
65};
@ AST_DIAL_RESULT_FAILED
Definition dial.h:56
@ AST_DIAL_RESULT_HANGUP
Definition dial.h:63
@ AST_DIAL_RESULT_INVALID
Definition dial.h:55
@ AST_DIAL_RESULT_ANSWERED
Definition dial.h:61
@ AST_DIAL_RESULT_TIMEOUT
Definition dial.h:62
@ AST_DIAL_RESULT_TRYING
Definition dial.h:57
@ AST_DIAL_RESULT_PROGRESS
Definition dial.h:59
@ AST_DIAL_RESULT_RINGING
Definition dial.h:58
@ AST_DIAL_RESULT_PROCEEDING
Definition dial.h:60
@ AST_DIAL_RESULT_UNANSWERED
Definition dial.h:64

Function Documentation

◆ ast_dial_answered()

struct ast_channel * ast_dial_answered ( struct ast_dial dial)

Return channel that answered.

Note
Returns the Asterisk channel that answered
Parameters
dialDialing structure

Definition at line 980 of file dial.c.

981{
982 if (!dial)
983 return NULL;
984
985 return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL);
986}
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define NULL
Definition resample.c:96
enum ast_dial_result state
Definition dial.c:52
struct ast_dial::@369 channels

References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, NULL, and ast_dial::state.

Referenced by ari_originate_dial(), dial_trunk(), page_state_callback(), and sla_handle_dial_state_event().

◆ ast_dial_answered_steal()

struct ast_channel * ast_dial_answered_steal ( struct ast_dial dial)

Steal the channel that answered.

Note
Returns the Asterisk channel that answered and removes it from the dialing structure
Parameters
dialDialing structure

Definition at line 992 of file dial.c.

993{
994 struct ast_channel *chan = NULL;
995
996 if (!dial)
997 return NULL;
998
999 if (dial->state == AST_DIAL_RESULT_ANSWERED) {
1000 chan = AST_LIST_FIRST(&dial->channels)->owner;
1001 AST_LIST_FIRST(&dial->channels)->owner = NULL;
1002 }
1003
1004 return chan;
1005}
Main Channel structure associated with a channel.

References AST_DIAL_RESULT_ANSWERED, AST_LIST_FIRST, ast_dial::channels, NULL, and ast_dial::state.

Referenced by ari_originate_dial(), do_notify(), pbx_outgoing_exec(), and recall_callback().

◆ ast_dial_append()

int ast_dial_append ( struct ast_dial dial,
const char *  tech,
const char *  device,
const struct ast_assigned_ids assignedids 
)

Append a channel.

Note
Appends a channel to a dialing structure
Returns
Returns channel reference number on success, -1 on failure

Definition at line 280 of file dial.c.

281{
282 struct ast_dial_channel *channel = NULL;
283
284 /* Make sure we have required arguments */
285 if (!dial || !tech || !device)
286 return -1;
287
288 /* Allocate new memory for dialed channel structure */
289 if (!(channel = ast_calloc(1, sizeof(*channel))))
290 return -1;
291
292 return dial_append_common(dial, channel, tech, device, assignedids);
293}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
static int dial_append_common(struct ast_dial *dial, struct ast_dial_channel *channel, const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
Definition dial.c:247
Dialing channel structure. Contains per-channel dialing options, asterisk channel,...
Definition dial.c:63
char * tech
Definition dial.c:66
char * device
Definition dial.c:67

References ast_calloc, ast_dial_channel::device, dial_append_common(), NULL, and ast_dial_channel::tech.

Referenced by ari_channels_handle_originate_with_id(), dial_trunk(), do_notify(), page_exec(), pbx_outgoing_attempt(), recalling_enter(), and sla_ring_station().

◆ ast_dial_append_channel()

int ast_dial_append_channel ( struct ast_dial dial,
struct ast_channel chan 
)

Append a channel using an actual channel object.

Parameters
dialThe ast_dial to add the channel to
chanThe channel to add to the dial
Return values
-1Failure
non-zeroThe position of the channel in the list of dialed channels
Note
The chan ref is stolen with a successful return.

Definition at line 295 of file dial.c.

296{
297 struct ast_dial_channel *channel;
298 char *tech;
299 char *device;
300 char *dash;
301
302 if (!dial || !chan) {
303 return -1;
304 }
305
306 channel = ast_calloc(1, sizeof(*channel));
307 if (!channel) {
308 return -1;
309 }
310 channel->owner = chan;
311
313
314 device = strchr(tech, '/');
315 if (!device) {
316 ast_free(channel);
317 return -1;
318 }
319 *device++ = '\0';
320
321 dash = strrchr(device, '-');
322 if (dash) {
323 *dash = '\0';
324 }
325
326 return dial_append_common(dial, channel, tech, device, NULL);
327}
#define ast_free(a)
Definition astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel * owner
Definition dial.c:73

References ast_calloc, ast_channel_name(), ast_free, ast_strdupa, ast_dial_channel::device, dial_append_common(), NULL, ast_dial_channel::owner, and ast_dial_channel::tech.

◆ ast_dial_create()

struct ast_dial * ast_dial_create ( void  )

New dialing structure.

Note
Create a dialing structure
Returns
Returns a calloc'd ast_dial structure, NULL on failure

Definition at line 223 of file dial.c.

224{
225 struct ast_dial *dial = NULL;
226
227 /* Allocate new memory for structure */
228 if (!(dial = ast_calloc(1, sizeof(*dial))))
229 return NULL;
230
231 /* Initialize list of channels */
233
234 /* Initialize thread to NULL */
236
237 /* No timeout exists... yet */
238 dial->timeout = -1;
239 dial->actual_timeout = -1;
240
241 /* Can't forget about the lock */
242 ast_mutex_init(&dial->lock);
243
244 return dial;
245}
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
#define AST_PTHREADT_NULL
Definition lock.h:73
#define ast_mutex_init(pmutex)
Definition lock.h:193
Main dialing structure. Contains global options, channels being dialed, and more!
Definition dial.c:48
pthread_t thread
Definition dial.c:57
int timeout
Definition dial.c:50
ast_mutex_t lock
Definition dial.c:56
int actual_timeout
Definition dial.c:51

References ast_dial::actual_timeout, ast_calloc, AST_LIST_HEAD_INIT, ast_mutex_init, AST_PTHREADT_NULL, ast_dial::channels, ast_dial::lock, NULL, ast_dial::thread, and ast_dial::timeout.

Referenced by ari_channels_handle_originate_with_id(), dial_trunk(), do_notify(), page_exec(), pbx_outgoing_attempt(), recalling_enter(), and sla_ring_station().

◆ ast_dial_destroy()

int ast_dial_destroy ( struct ast_dial dial)

Destroys a dialing structure.

Note
Cancels dialing and destroys (free's) the given ast_dial structure
Parameters
dialDialing structure to free
Return values
0on success
-1on failure

Definition at line 1094 of file dial.c.

1095{
1096 int i = 0;
1097 struct ast_dial_channel *channel = NULL;
1098
1099 if (!dial)
1100 return -1;
1101
1102 /* Hangup and deallocate all the dialed channels */
1103 AST_LIST_LOCK(&dial->channels);
1104 AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) {
1105 /* Disable any enabled options */
1106 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
1107 if (!channel->options[i])
1108 continue;
1109 if (option_types[i].disable)
1110 option_types[i].disable(channel->options[i]);
1111 channel->options[i] = NULL;
1112 }
1113
1114 /* Hang up channel if need be */
1115 ast_hangup(channel->owner);
1116 channel->owner = NULL;
1117
1118 /* Free structure */
1119 ast_free(channel->tech);
1120 ast_free(channel->device);
1121 ast_free(channel->assignedid1);
1122 ast_free(channel->assignedid2);
1123
1125 ast_free(channel);
1126 }
1128 AST_LIST_UNLOCK(&dial->channels);
1129
1130 /* Disable any enabled options globally */
1131 for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
1132 if (!dial->options[i])
1133 continue;
1134 if (option_types[i].disable)
1135 option_types[i].disable(dial->options[i]);
1136 dial->options[i] = NULL;
1137 }
1138
1139 /* Lock be gone! */
1140 ast_mutex_destroy(&dial->lock);
1141
1142 /* Free structure */
1143 ast_free(dial);
1144
1145 return 0;
1146}
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2538
static const struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition dial.c:199
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_LOCK(head)
Locks a list.
Definition linkedlists.h:40
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
#define ast_mutex_destroy(a)
Definition lock.h:195
struct ast_dial_channel::@370 list
char * assignedid2
Definition dial.c:72
void * options[AST_DIAL_OPTION_MAX]
Definition dial.c:68
char * assignedid1
Definition dial.c:71
void * options[AST_DIAL_OPTION_MAX]
Definition dial.c:53
ast_dial_option_cb_disable disable
Definition dial.c:190

References ast_dial_channel::assignedid1, ast_dial_channel::assignedid2, AST_DIAL_OPTION_MAX, ast_free, ast_hangup(), AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_mutex_destroy, ast_dial::channels, ast_dial_channel::device, ast_option_types::disable, ast_dial_channel::list, ast_dial::lock, NULL, option_types, ast_dial::options, ast_dial_channel::options, ast_dial_channel::owner, and ast_dial_channel::tech.

Referenced by ari_channels_handle_originate_with_id(), ari_originate_dial(), dial_trunk(), do_notify(), monitor_dial(), page_exec(), pbx_outgoing_destroy(), recalling_exit(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().

◆ ast_dial_get_channel()

struct ast_channel * ast_dial_get_channel ( struct ast_dial dial,
int  num 
)

Get the dialing channel, if prerun has been executed.

Parameters
dialDial structure
numChannel number to get channel of
Returns
Pointer to channel, without reference

Definition at line 1261 of file dial.c.

1262{
1263 struct ast_dial_channel *channel;
1264
1265 if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
1266 return NULL;
1267 }
1268
1269 return channel->owner;
1270}
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.
Definition dial.c:1165
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.

References AST_LIST_EMPTY, ast_dial::channels, find_dial_channel(), NULL, ast_dial_channel::num, and ast_dial_channel::owner.

Referenced by ari_channels_handle_originate_with_id(), pbx_outgoing_attempt(), pbx_outgoing_state_callback(), and recalling_enter().

◆ ast_dial_get_user_data()

void * ast_dial_get_user_data ( struct ast_dial dial)

Return the user data on a dial structure.

Parameters
dialThe dial structure

Definition at line 1282 of file dial.c.

1283{
1284 return dial->user_data;
1285}
void * user_data
Definition dial.c:55

References ast_dial::user_data.

Referenced by ari_originate_dial(), page_state_callback(), and recall_callback().

◆ ast_dial_hangup()

void ast_dial_hangup ( struct ast_dial dial)

Hangup channels.

Note
Hangup all active channels
Parameters
dialDialing structure

Definition at line 1077 of file dial.c.

1078{
1079 struct ast_dial_channel *channel = NULL;
1080
1081 if (!dial)
1082 return;
1083
1084 AST_LIST_LOCK(&dial->channels);
1085 AST_LIST_TRAVERSE(&dial->channels, channel, list) {
1086 ast_hangup(channel->owner);
1087 channel->owner = NULL;
1088 }
1089 AST_LIST_UNLOCK(&dial->channels);
1090
1091 return;
1092}
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.

References ast_hangup(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_dial::channels, ast_dial_channel::list, NULL, and ast_dial_channel::owner.

Referenced by ast_dial_run(), and page_exec().

◆ ast_dial_join()

enum ast_dial_result ast_dial_join ( struct ast_dial dial)

Cancel async thread.

Note
Cancel a running async thread
Parameters
dialDialing structure

Definition at line 1020 of file dial.c.

1021{
1022 pthread_t thread;
1023
1024 /* If the dial structure is not running in async, return failed */
1025 if (dial->thread == AST_PTHREADT_NULL)
1027
1028 /* Record thread */
1029 thread = dial->thread;
1030
1031 /* Boom, commence locking */
1032 ast_mutex_lock(&dial->lock);
1033
1034 /* Stop the thread */
1035 dial->thread = AST_PTHREADT_STOP;
1036
1037 /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
1038 AST_LIST_LOCK(&dial->channels);
1039 if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
1040 struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
1041 if (chan) {
1042 ast_channel_lock(chan);
1044 ast_channel_unlock(chan);
1045 }
1046 } else {
1047 struct ast_dial_channel *channel = NULL;
1048
1049 /* Now we signal it with SIGURG so it will break out of it's waitfor */
1050 pthread_kill(thread, SIGURG);
1051
1052 /* pthread_kill may not be enough, if outgoing channel has already got an answer (no more in waitfor) but is not yet running an application. Force soft hangup. */
1053 AST_LIST_TRAVERSE(&dial->channels, channel, list) {
1054 if (channel->owner) {
1056 }
1057 }
1058 }
1059 AST_LIST_UNLOCK(&dial->channels);
1060
1061 /* Yay done with it */
1062 ast_mutex_unlock(&dial->lock);
1063
1064 /* Finally wait for the thread to exit */
1065 pthread_join(thread, NULL);
1066
1067 /* Yay thread is all gone */
1068 dial->thread = AST_PTHREADT_NULL;
1069
1070 return dial->state;
1071}
pthread_t thread
Definition app_sla.c:335
#define ast_channel_lock(chan)
Definition channel.h:2982
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition channel.c:2461
@ AST_SOFTHANGUP_EXPLICIT
Definition channel.h:1168
#define ast_channel_unlock(chan)
Definition channel.h:2983
#define AST_PTHREADT_STOP
Definition lock.h:74
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196

References ast_channel_lock, ast_channel_unlock, AST_DIAL_RESULT_FAILED, AST_LIST_FIRST, AST_LIST_LOCK, AST_LIST_TRAVERSE, 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_channel::list, ast_dial::lock, NULL, ast_dial_channel::owner, ast_dial::state, thread, and ast_dial::thread.

Referenced by dial_trunk(), page_exec(), recalling_exit(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_ring_station(), and sla_stop_ringing_station().

◆ ast_dial_option_disable()

int ast_dial_option_disable ( struct ast_dial dial,
int  num,
enum ast_dial_option  option 
)

Disables an option per channel.

Parameters
dialDial structure
numChannel number to disable option on
optionOption to disable
Return values
0on success
-1on failure

Definition at line 1225 of file dial.c.

1226{
1227 struct ast_dial_channel *channel = NULL;
1228
1229 /* Ensure we have required arguments */
1230 if (!dial || AST_LIST_EMPTY(&dial->channels))
1231 return -1;
1232
1233 if (!(channel = find_dial_channel(dial, num)))
1234 return -1;
1235
1236 /* If the option is not enabled, return failure */
1237 if (!channel->options[option])
1238 return -1;
1239
1240 /* Execute callback of option to disable it if it exists */
1241 if (option_types[option].disable)
1242 option_types[option].disable(channel->options[option]);
1243
1244 /* Finally disable the option on the structure */
1245 channel->options[option] = NULL;
1246
1247 return 0;
1248}

References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::disable, find_dial_channel(), NULL, ast_dial_channel::num, option_types, and ast_dial_channel::options.

◆ ast_dial_option_enable()

int ast_dial_option_enable ( struct ast_dial dial,
int  num,
enum ast_dial_option  option,
void *  data 
)

Enables an option per channel.

Parameters
dialDial structure
numChannel number to enable option on
optionOption to enable
dataData to pass to this option (not always needed)
Return values
0on success
-1on failure

Definition at line 1184 of file dial.c.

1185{
1186 struct ast_dial_channel *channel = NULL;
1187
1188 /* Ensure we have required arguments */
1189 if (!dial || AST_LIST_EMPTY(&dial->channels))
1190 return -1;
1191
1192 if (!(channel = find_dial_channel(dial, num)))
1193 return -1;
1194
1195 /* If the option is already enabled, return failure */
1196 if (channel->options[option])
1197 return -1;
1198
1199 /* Execute enable callback if it exists, if not simply make sure the value is set */
1200 if (option_types[option].enable)
1201 channel->options[option] = option_types[option].enable(data);
1202 else
1203 channel->options[option] = (void*)1;
1204
1205 return 0;
1206}
ast_dial_option_cb_enable enable
Definition dial.c:189

References AST_LIST_EMPTY, ast_dial::channels, ast_option_types::enable, find_dial_channel(), NULL, ast_dial_channel::num, option_types, and ast_dial_channel::options.

◆ ast_dial_option_global_disable()

int ast_dial_option_global_disable ( struct ast_dial dial,
enum ast_dial_option  option 
)

Disables an option globally.

Parameters
dialDial structure to disable option on
optionOption to disable
Return values
0on success
-1on failure

Definition at line 1208 of file dial.c.

1209{
1210 /* If the option is not enabled, return failure */
1211 if (!dial->options[option]) {
1212 return -1;
1213 }
1214
1215 /* Execute callback of option to disable if it exists */
1216 if (option_types[option].disable)
1217 option_types[option].disable(dial->options[option]);
1218
1219 /* Finally disable option on the structure */
1220 dial->options[option] = NULL;
1221
1222 return 0;
1223}

References ast_option_types::disable, NULL, option_types, and ast_dial::options.

◆ ast_dial_option_global_enable()

int ast_dial_option_global_enable ( struct ast_dial dial,
enum ast_dial_option  option,
void *  data 
)

Enables an option globally.

Parameters
dialDial structure to enable option on
optionOption to enable
dataData to pass to this option (not always needed)
Return values
0on success
-1on failure

Definition at line 1148 of file dial.c.

1149{
1150 /* If the option is already enabled, return failure */
1151 if (dial->options[option])
1152 return -1;
1153
1154 /* Execute enable callback if it exists, if not simply make sure the value is set */
1155 if (option_types[option].enable)
1156 dial->options[option] = option_types[option].enable(data);
1157 else
1158 dial->options[option] = (void*)1;
1159
1160 return 0;
1161}

References ast_option_types::enable, option_types, and ast_dial::options.

Referenced by do_notify(), page_exec(), and pbx_outgoing_attempt().

◆ ast_dial_prerun()

int ast_dial_prerun ( struct ast_dial dial,
struct ast_channel chan,
struct ast_format_cap cap 
)

Request all appended channels, but do not dial.

Parameters
dialDialing structure
chanOptional dialing channel
capOptional requested capabilities
Return values
-1failure
0success

Definition at line 431 of file dial.c.

432{
433 struct ast_dial_channel *channel;
434 int res = -1;
435 char *predial_string = dial->options[AST_DIAL_OPTION_PREDIAL];
436
437 AST_LIST_LOCK(&dial->channels);
438 AST_LIST_TRAVERSE(&dial->channels, channel, list) {
439 if ((res = begin_dial_prerun(channel, chan, cap, predial_string))) {
440 break;
441 }
442 }
444
445 return res;
446}
static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channel *chan, struct ast_format_cap *cap, const char *predial_string)
Helper function that requests all channels.
Definition dial.c:330

References AST_DIAL_OPTION_PREDIAL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, begin_dial_prerun(), ast_dial::channels, ast_dial_channel::list, and ast_dial::options.

Referenced by ari_channels_handle_originate_with_id(), pbx_outgoing_attempt(), and recalling_enter().

◆ ast_dial_reason()

int ast_dial_reason ( struct ast_dial dial,
int  num 
)

Get the reason an outgoing channel has failed.

Parameters
dialDial structure
numChannel number to get the reason from
Returns
Numerical cause code

Definition at line 1250 of file dial.c.

1251{
1252 struct ast_dial_channel *channel;
1253
1254 if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
1255 return -1;
1256 }
1257
1258 return channel->cause;
1259}

References AST_LIST_EMPTY, ast_dial_channel::cause, ast_dial::channels, find_dial_channel(), and ast_dial_channel::num.

Referenced by pbx_outgoing_attempt().

◆ ast_dial_run()

enum ast_dial_result ast_dial_run ( struct ast_dial dial,
struct ast_channel chan,
int  async 
)

Execute dialing synchronously or asynchronously.

Note
Dials channels in a dial structure.
Returns
Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).

Definition at line 938 of file dial.c.

939{
941
942 /* Ensure required arguments are passed */
943 if (!dial) {
944 ast_debug(1, "invalid #1\n");
946 }
947
948 /* If there are no channels to dial we can't very well try to dial them */
949 if (AST_LIST_EMPTY(&dial->channels)) {
950 ast_debug(1, "invalid #2\n");
952 }
953
954 /* Dial each requested channel */
955 if (!begin_dial(dial, chan, async))
957
958 /* If we are running async spawn a thread and send it away... otherwise block here */
959 if (async) {
960 /* reference be released at dial destruction if it isn't NULL */
963 /* Try to create a thread */
964 if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
965 /* Failed to create the thread - hangup all dialed channels and return failed */
966 ast_dial_hangup(dial);
968 }
969 } else {
970 res = monitor_dial(dial, chan);
971 }
972
973 return res;
974}
static void * async_dial(void *data)
Dial async thread function.
Definition dial.c:921
void ast_dial_hangup(struct ast_dial *dial)
Hangup channels.
Definition dial.c:1077
static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_channel *chan)
Helper function that basically keeps tabs on dialing attempts.
Definition dial.c:769
static int begin_dial(struct ast_dial *dial, struct ast_channel *chan, int async)
Helper function that does the beginning dialing per dial structure.
Definition dial.c:481
ast_dial_result
List of return codes for dial run API calls.
Definition dial.h:54
#define ast_debug(level,...)
Log a DEBUG message.
ast_callid ast_read_threadstorage_callid(void)
extracts the callid from the thread
Definition logger.c:2268
ast_callid callid
Definition dial.c:58
#define ast_pthread_create(a, b, c, d)
Definition utils.h:624

References ast_debug, ast_dial_hangup(), AST_DIAL_RESULT_FAILED, AST_DIAL_RESULT_INVALID, AST_DIAL_RESULT_TRYING, AST_LIST_EMPTY, ast_pthread_create, ast_read_threadstorage_callid(), async_dial(), begin_dial(), ast_dial::callid, ast_dial::channels, monitor_dial(), NULL, ast_dial::state, and ast_dial::thread.

Referenced by ari_originate_dial(), dial_trunk(), do_notify(), page_exec(), pbx_outgoing_exec(), recalling_enter(), and sla_ring_station().

◆ ast_dial_set_global_timeout()

void ast_dial_set_global_timeout ( struct ast_dial dial,
int  timeout 
)

Set the maximum time (globally) allowed for trying to ring phones.

Parameters
dialThe dial structure to apply the time limit to
timeoutMaximum time allowed in milliseconds

Definition at line 1287 of file dial.c.

1288{
1289 dial->timeout = timeout;
1290
1291 if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1))
1292 dial->actual_timeout = dial->timeout;
1293
1294 return;
1295}

References ast_dial::actual_timeout, ast_dial::timeout, and ast_dial_channel::timeout.

Referenced by ari_channels_handle_originate_with_id(), do_notify(), page_exec(), and pbx_outgoing_attempt().

◆ ast_dial_set_state_callback()

void ast_dial_set_state_callback ( struct ast_dial dial,
ast_dial_state_callback  callback 
)

Set a callback for state changes.

Parameters
dialThe dial structure to watch for state changes
callbackthe callback

Definition at line 1272 of file dial.c.

1273{
1274 dial->state_callback = callback;
1275}
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags, int rdlock)
ast_dial_state_callback state_callback
Definition dial.c:54

References callback(), and ast_dial::state_callback.

Referenced by page_exec(), pbx_outgoing_attempt(), recalling_enter(), and sla_ring_station().

◆ ast_dial_set_timeout()

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.

Parameters
dialThe dial structure the channel belongs to
numChannel number to set timeout on
timeoutMaximum time allowed in milliseconds

Definition at line 1297 of file dial.c.

1298{
1299 struct ast_dial_channel *channel = NULL;
1300
1301 if (!(channel = find_dial_channel(dial, num)))
1302 return;
1303
1304 channel->timeout = timeout;
1305
1306 if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1))
1307 dial->actual_timeout = channel->timeout;
1308
1309 return;
1310}

References ast_dial::actual_timeout, find_dial_channel(), NULL, ast_dial_channel::num, and ast_dial_channel::timeout.

◆ ast_dial_set_user_data()

void ast_dial_set_user_data ( struct ast_dial dial,
void *  user_data 
)

Set user data on a dial structure.

Parameters
dialThe dial structure to set a user data pointer on
user_dataThe user data pointer

Definition at line 1277 of file dial.c.

1278{
1279 dial->user_data = user_data;
1280}

References ast_dial::user_data.

Referenced by ari_channels_handle_originate_with_id(), page_exec(), and recalling_enter().

◆ ast_dial_state()

enum ast_dial_result ast_dial_state ( struct ast_dial dial)

Return state of dial.

Note
Returns the state of the dial attempt
Parameters
dialDialing structure

Definition at line 1011 of file dial.c.

1012{
1013 return dial->state;
1014}

References ast_dial::state.

Referenced by dial_trunk(), page_state_callback(), pbx_outgoing_state_callback(), recall_callback(), and sla_handle_dial_state_event().

◆ ast_hangup_cause_to_dial_status()

const char * ast_hangup_cause_to_dial_status ( int  hangup_cause)

Convert a hangup cause to a publishable dial status.

Since
12

Definition at line 752 of file dial.c.

753{
754 switch(hangup_cause) {
755 case AST_CAUSE_BUSY:
756 return "BUSY";
758 return "CONGESTION";
761 return "CHANUNAVAIL";
763 default:
764 return "NOANSWER";
765 }
766}
#define AST_CAUSE_CONGESTION
Definition causes.h:153
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition causes.h:100
#define AST_CAUSE_UNREGISTERED
Definition causes.h:154
#define AST_CAUSE_BUSY
Definition causes.h:149
#define AST_CAUSE_NO_ANSWER
Definition causes.h:109

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, and AST_CAUSE_UNREGISTERED.

Referenced by monitor_dial(), try_calling(), and wait_for_answer().