Asterisk - The Open Source Telephony Project  18.5.0
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. More...
 
struct ast_channelast_dial_answered_steal (struct ast_dial *dial)
 Steal the channel that answered. More...
 
int ast_dial_append (struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
 Append a channel. More...
 
int ast_dial_append_channel (struct ast_dial *dial, struct ast_channel *chan)
 Append a channel using an actual channel object. More...
 
struct ast_dialast_dial_create (void)
 New dialing structure. More...
 
int ast_dial_destroy (struct ast_dial *dial)
 Destroys a dialing structure. More...
 
struct ast_channelast_dial_get_channel (struct ast_dial *dial, int num)
 Get the dialing channel, if prerun has been executed. More...
 
void * ast_dial_get_user_data (struct ast_dial *dial)
 Return the user data on a dial structure. More...
 
void ast_dial_hangup (struct ast_dial *dial)
 Hangup channels. More...
 
enum ast_dial_result ast_dial_join (struct ast_dial *dial)
 Cancel async thread. More...
 
int ast_dial_option_disable (struct ast_dial *dial, int num, enum ast_dial_option option)
 Disables an option per channel. More...
 
int ast_dial_option_enable (struct ast_dial *dial, int num, enum ast_dial_option option, void *data)
 Enables an option per channel. More...
 
int ast_dial_option_global_disable (struct ast_dial *dial, enum ast_dial_option option)
 Disables an option globally. More...
 
int ast_dial_option_global_enable (struct ast_dial *dial, enum ast_dial_option option, void *data)
 Enables an option globally. More...
 
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. More...
 
int ast_dial_reason (struct ast_dial *dial, int num)
 Get the reason an outgoing channel has failed. More...
 
enum ast_dial_result ast_dial_run (struct ast_dial *dial, struct ast_channel *chan, int async)
 Execute dialing synchronously or asynchronously. More...
 
void ast_dial_set_global_timeout (struct ast_dial *dial, int timeout)
 Set the maximum time (globally) allowed for trying to ring phones. More...
 
void ast_dial_set_state_callback (struct ast_dial *dial, ast_dial_state_callback callback)
 Set a callback for state changes. More...
 
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. More...
 
void ast_dial_set_user_data (struct ast_dial *dial, void *user_data)
 Set user data on a dial structure. More...
 
enum ast_dial_result ast_dial_state (struct ast_dial *dial)
 Return state of dial. More...
 
const char * ast_hangup_cause_to_dial_status (int hangup_cause)
 Convert a hangup cause to a publishable dial status. More...
 

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_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 };

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 981 of file dial.c.

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().

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

◆ 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 993 of file dial.c.

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().

994 {
995  struct ast_channel *chan = NULL;
996 
997  if (!dial)
998  return NULL;
999 
1000  if (dial->state == AST_DIAL_RESULT_ANSWERED) {
1001  chan = AST_LIST_FIRST(&dial->channels)->owner;
1002  AST_LIST_FIRST(&dial->channels)->owner = NULL;
1003  }
1004 
1005  return chan;
1006 }
Main Channel structure associated with a channel.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
enum ast_dial_result state
Definition: dial.c:52
#define NULL
Definition: resample.c:96
struct ast_dial::@381 channels

◆ 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 282 of file dial.c.

References ast_calloc, dial_append_common(), and NULL.

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

283 {
284  struct ast_dial_channel *channel = NULL;
285 
286  /* Make sure we have required arguments */
287  if (!dial || !tech || !device)
288  return -1;
289 
290  /* Allocate new memory for dialed channel structure */
291  if (!(channel = ast_calloc(1, sizeof(*channel))))
292  return -1;
293 
294  return dial_append_common(dial, channel, tech, device, assignedids);
295 }
Definition: muted.c:95
#define NULL
Definition: resample.c:96
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:249
char * tech
Definition: dial.c:66
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
char * device
Definition: dial.c:67
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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 297 of file dial.c.

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.

298 {
299  struct ast_dial_channel *channel;
300  char *tech;
301  char *device;
302  char *dash;
303 
304  if (!dial || !chan) {
305  return -1;
306  }
307 
308  channel = ast_calloc(1, sizeof(*channel));
309  if (!channel) {
310  return -1;
311  }
312  channel->owner = chan;
313 
314  tech = ast_strdupa(ast_channel_name(chan));
315 
316  device = strchr(tech, '/');
317  if (!device) {
318  ast_free(channel);
319  return -1;
320  }
321  *device++ = '\0';
322 
323  dash = strrchr(device, '-');
324  if (dash) {
325  *dash = '\0';
326  }
327 
328  return dial_append_common(dial, channel, tech, device, NULL);
329 }
Definition: muted.c:95
#define NULL
Definition: resample.c:96
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:249
char * tech
Definition: dial.c:66
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
struct ast_channel * owner
Definition: dial.c:73
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
const char * ast_channel_name(const struct ast_channel *chan)
char * device
Definition: dial.c:67
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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 225 of file dial.c.

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().

226 {
227  struct ast_dial *dial = NULL;
228 
229  /* Allocate new memory for structure */
230  if (!(dial = ast_calloc(1, sizeof(*dial))))
231  return NULL;
232 
233  /* Initialize list of channels */
235 
236  /* Initialize thread to NULL */
237  dial->thread = AST_PTHREADT_NULL;
238 
239  /* No timeout exists... yet */
240  dial->timeout = -1;
241  dial->actual_timeout = -1;
242 
243  /* Can't forget about the lock */
244  ast_mutex_init(&dial->lock);
245 
246  return dial;
247 }
Main dialing structure. Contains global options, channels being dialed, and more! ...
Definition: dial.c:48
#define NULL
Definition: resample.c:96
pthread_t thread
Definition: dial.c:57
#define AST_PTHREADT_NULL
Definition: lock.h:66
ast_mutex_t lock
Definition: dial.c:56
struct ast_dial::@381 channels
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
Definition: linkedlists.h:625
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
int timeout
Definition: dial.c:50
int actual_timeout
Definition: dial.c:51
#define ast_mutex_init(pmutex)
Definition: lock.h:184

◆ 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
Returns
Returns 0 on success, -1 on failure
Note
Destroys (free's) the given ast_dial structure
Parameters
dialDialing structure to free
Returns
Returns 0 on success, -1 on failure

Definition at line 1091 of file dial.c.

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, 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().

1092 {
1093  int i = 0;
1094  struct ast_dial_channel *channel = NULL;
1095 
1096  if (!dial)
1097  return -1;
1098 
1099  /* Hangup and deallocate all the dialed channels */
1100  AST_LIST_LOCK(&dial->channels);
1101  AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) {
1102  /* Disable any enabled options */
1103  for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
1104  if (!channel->options[i])
1105  continue;
1106  if (option_types[i].disable)
1107  option_types[i].disable(channel->options[i]);
1108  channel->options[i] = NULL;
1109  }
1110 
1111  /* Hang up channel if need be */
1112  ast_hangup(channel->owner);
1113  channel->owner = NULL;
1114 
1115  /* Free structure */
1116  ast_free(channel->tech);
1117  ast_free(channel->device);
1118  ast_free(channel->assignedid1);
1119  ast_free(channel->assignedid2);
1120 
1122  ast_free(channel);
1123  }
1125  AST_LIST_UNLOCK(&dial->channels);
1126 
1127  /* Disable any enabled options globally */
1128  for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
1129  if (!dial->options[i])
1130  continue;
1131  if (option_types[i].disable)
1132  option_types[i].disable(dial->options[i]);
1133  dial->options[i] = NULL;
1134  }
1135 
1136  /* Lock be gone! */
1137  ast_mutex_destroy(&dial->lock);
1138 
1139  /* Free structure */
1140  ast_free(dial);
1141 
1142  return 0;
1143 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
char * assignedid2
Definition: dial.c:72
Definition: muted.c:95
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
struct ast_dial_channel::@382 list
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:53
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
char * tech
Definition: dial.c:66
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:68
struct ast_channel * owner
Definition: dial.c:73
ast_mutex_t lock
Definition: dial.c:56
struct ast_dial::@381 channels
#define ast_free(a)
Definition: astmm.h:182
static const struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition: dial.c:201
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
ast_dial_option_cb_disable disable
Definition: dial.c:192
char * assignedid1
Definition: dial.c:71
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define ast_mutex_destroy(a)
Definition: lock.h:186
char * device
Definition: dial.c:67
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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 1282 of file dial.c.

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

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

1283 {
1284  struct ast_dial_channel *channel;
1285 
1286  if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
1287  return NULL;
1288  }
1289 
1290  return channel->owner;
1291 }
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
Definition: muted.c:95
#define NULL
Definition: resample.c:96
struct ast_channel * owner
Definition: dial.c:73
struct ast_dial::@381 channels
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:1168
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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
Returns
A pointer to the user data

Definition at line 1303 of file dial.c.

References ast_dial::user_data.

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

1304 {
1305  return dial->user_data;
1306 }
void * user_data
Definition: dial.c:55

◆ ast_dial_hangup()

void ast_dial_hangup ( struct ast_dial dial)

Hangup channels.

Note
Hangup all active channels
Parameters
dialDialing structure

Definition at line 1069 of file dial.c.

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().

1070 {
1071  struct ast_dial_channel *channel = NULL;
1072 
1073  if (!dial)
1074  return;
1075 
1076  AST_LIST_LOCK(&dial->channels);
1077  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
1078  ast_hangup(channel->owner);
1079  channel->owner = NULL;
1080  }
1081  AST_LIST_UNLOCK(&dial->channels);
1082 
1083  return;
1084 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: muted.c:95
#define NULL
Definition: resample.c:96
struct ast_dial_channel::@382 list
struct ast_channel * owner
Definition: dial.c:73
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct ast_dial::@381 channels
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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 1021 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, NULL, ast_dial::state, 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().

1022 {
1023  pthread_t thread;
1024 
1025  /* If the dial structure is not running in async, return failed */
1026  if (dial->thread == AST_PTHREADT_NULL)
1027  return AST_DIAL_RESULT_FAILED;
1028 
1029  /* Record thread */
1030  thread = dial->thread;
1031 
1032  /* Boom, commence locking */
1033  ast_mutex_lock(&dial->lock);
1034 
1035  /* Stop the thread */
1036  dial->thread = AST_PTHREADT_STOP;
1037 
1038  /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
1039  AST_LIST_LOCK(&dial->channels);
1040  if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
1041  struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
1042  if (chan) {
1043  ast_channel_lock(chan);
1045  ast_channel_unlock(chan);
1046  }
1047  } else {
1048  /* Now we signal it with SIGURG so it will break out of it's waitfor */
1049  pthread_kill(thread, SIGURG);
1050  }
1051  AST_LIST_UNLOCK(&dial->channels);
1052 
1053  /* Yay done with it */
1054  ast_mutex_unlock(&dial->lock);
1055 
1056  /* Finally wait for the thread to exit */
1057  pthread_join(thread, NULL);
1058 
1059  /* Yay thread is all gone */
1060  dial->thread = AST_PTHREADT_NULL;
1061 
1062  return dial->state;
1063 }
pthread_t thread
Definition: app_meetme.c:1089
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
enum ast_dial_result state
Definition: dial.c:52
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
pthread_t thread
Definition: dial.c:57
#define AST_PTHREADT_NULL
Definition: lock.h:66
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2476
ast_mutex_t lock
Definition: dial.c:56
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_dial::@381 channels
#define AST_PTHREADT_STOP
Definition: lock.h:67
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ 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
Returns
Returns 0 on success, -1 on failure

Definition at line 1246 of file dial.c.

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

1247 {
1248  struct ast_dial_channel *channel = NULL;
1249 
1250  /* Ensure we have required arguments */
1251  if (!dial || AST_LIST_EMPTY(&dial->channels))
1252  return -1;
1253 
1254  if (!(channel = find_dial_channel(dial, num)))
1255  return -1;
1256 
1257  /* If the option is not enabled, return failure */
1258  if (!channel->options[option])
1259  return -1;
1260 
1261  /* Execute callback of option to disable it if it exists */
1262  if (option_types[option].disable)
1263  option_types[option].disable(channel->options[option]);
1264 
1265  /* Finally disable the option on the structure */
1266  channel->options[option] = NULL;
1267 
1268  return 0;
1269 }
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
Definition: muted.c:95
#define NULL
Definition: resample.c:96
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:68
struct ast_dial::@381 channels
static const struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition: dial.c:201
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:1168
ast_dial_option_cb_disable disable
Definition: dial.c:192
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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)
Returns
Returns 0 on success, -1 on failure

Definition at line 1194 of file dial.c.

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

1195 {
1196  struct ast_dial_channel *channel = NULL;
1197 
1198  /* Ensure we have required arguments */
1199  if (!dial || AST_LIST_EMPTY(&dial->channels))
1200  return -1;
1201 
1202  if (!(channel = find_dial_channel(dial, num)))
1203  return -1;
1204 
1205  /* If the option is already enabled, return failure */
1206  if (channel->options[option])
1207  return -1;
1208 
1209  /* Execute enable callback if it exists, if not simply make sure the value is set */
1210  if (option_types[option].enable)
1211  channel->options[option] = option_types[option].enable(data);
1212  else
1213  channel->options[option] = (void*)1;
1214 
1215  return 0;
1216 }
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
Definition: muted.c:95
#define NULL
Definition: resample.c:96
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:68
ast_dial_option_cb_enable enable
Definition: dial.c:191
struct ast_dial::@381 channels
static const struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition: dial.c:201
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:1168
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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
Returns
Returns 0 on success, -1 on failure

Definition at line 1223 of file dial.c.

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

1224 {
1225  /* If the option is not enabled, return failure */
1226  if (!dial->options[option]) {
1227  return -1;
1228  }
1229 
1230  /* Execute callback of option to disable if it exists */
1231  if (option_types[option].disable)
1232  option_types[option].disable(dial->options[option]);
1233 
1234  /* Finally disable option on the structure */
1235  dial->options[option] = NULL;
1236 
1237  return 0;
1238 }
#define NULL
Definition: resample.c:96
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:53
static const struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition: dial.c:201
ast_dial_option_cb_disable disable
Definition: dial.c:192

◆ 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)
Returns
Returns 0 on success, -1 on failure

Definition at line 1151 of file dial.c.

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

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

1152 {
1153  /* If the option is already enabled, return failure */
1154  if (dial->options[option])
1155  return -1;
1156 
1157  /* Execute enable callback if it exists, if not simply make sure the value is set */
1158  if (option_types[option].enable)
1159  dial->options[option] = option_types[option].enable(data);
1160  else
1161  dial->options[option] = (void*)1;
1162 
1163  return 0;
1164 }
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:53
ast_dial_option_cb_enable enable
Definition: dial.c:191
static const struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition: dial.c:201

◆ 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 0 success

Definition at line 433 of file dial.c.

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().

434 {
435  struct ast_dial_channel *channel;
436  int res = -1;
437  char *predial_string = dial->options[AST_DIAL_OPTION_PREDIAL];
438 
439  AST_LIST_LOCK(&dial->channels);
440  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
441  if ((res = begin_dial_prerun(channel, chan, cap, predial_string))) {
442  break;
443  }
444  }
445  AST_LIST_UNLOCK(&dial->channels);
446 
447  return res;
448 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: muted.c:95
struct ast_dial_channel::@382 list
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:53
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct ast_dial::@381 channels
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:332
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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 1271 of file dial.c.

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

Referenced by pbx_outgoing_attempt().

1272 {
1273  struct ast_dial_channel *channel;
1274 
1275  if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
1276  return -1;
1277  }
1278 
1279  return channel->cause;
1280 }
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
Definition: muted.c:95
struct ast_dial::@381 channels
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:1168
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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 939 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, 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().

940 {
942 
943  /* Ensure required arguments are passed */
944  if (!dial) {
945  ast_debug(1, "invalid #1\n");
947  }
948 
949  /* If there are no channels to dial we can't very well try to dial them */
950  if (AST_LIST_EMPTY(&dial->channels)) {
951  ast_debug(1, "invalid #2\n");
953  }
954 
955  /* Dial each requested channel */
956  if (!begin_dial(dial, chan, async))
957  return AST_DIAL_RESULT_FAILED;
958 
959  /* If we are running async spawn a thread and send it away... otherwise block here */
960  if (async) {
961  /* reference be released at dial destruction if it isn't NULL */
964  /* Try to create a thread */
965  if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
966  /* Failed to create the thread - hangup all dialed channels and return failed */
967  ast_dial_hangup(dial);
969  }
970  } else {
971  res = monitor_dial(dial, chan);
972  }
973 
974  return res;
975 }
void ast_dial_hangup(struct ast_dial *dial)
Hangup channels.
Definition: dial.c:1069
enum ast_dial_result state
Definition: dial.c:52
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:483
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
ast_callid callid
Definition: dial.c:58
#define NULL
Definition: resample.c:96
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:1962
pthread_t thread
Definition: dial.c:57
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
ast_dial_result
List of return codes for dial run API calls.
Definition: dial.h:54
static void * async_dial(void *data)
Dial async thread function.
Definition: dial.c:922
struct ast_dial::@381 channels
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:559
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:770

◆ 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
Returns
nothing
Parameters
dialThe dial structure to apply the time limit to
timeoutMaximum time allowed
Returns
nothing

Definition at line 1313 of file dial.c.

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

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

1314 {
1315  dial->timeout = timeout;
1316 
1317  if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1))
1318  dial->actual_timeout = dial->timeout;
1319 
1320  return;
1321 }
static int timeout
Definition: cdr_mysql.c:86
int timeout
Definition: dial.c:50
int actual_timeout
Definition: dial.c:51

◆ 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
Returns
nothing

Definition at line 1293 of file dial.c.

References ast_dial::state_callback.

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

1294 {
1295  dial->state_callback = callback;
1296 }
ast_dial_state_callback state_callback
Definition: dial.c:54

◆ 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
Returns
nothing
Parameters
dialThe dial structure the channel belongs to
numChannel number to set timeout on
timeoutMaximum time allowed
Returns
nothing

Definition at line 1329 of file dial.c.

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

1330 {
1331  struct ast_dial_channel *channel = NULL;
1332 
1333  if (!(channel = find_dial_channel(dial, num)))
1334  return;
1335 
1336  channel->timeout = timeout;
1337 
1338  if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1))
1339  dial->actual_timeout = channel->timeout;
1340 
1341  return;
1342 }
static int timeout
Definition: cdr_mysql.c:86
Definition: muted.c:95
#define NULL
Definition: resample.c:96
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:1168
int actual_timeout
Definition: dial.c:51
int timeout
Definition: dial.c:65
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63

◆ 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
Returns
nothing

Definition at line 1298 of file dial.c.

References ast_dial::user_data.

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

1299 {
1300  dial->user_data = user_data;
1301 }
void * user_data
Definition: dial.c:55

◆ 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 1012 of file dial.c.

References ast_dial::state.

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

1013 {
1014  return dial->state;
1015 }
enum ast_dial_result state
Definition: dial.c:52

◆ 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 753 of file dial.c.

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().

754 {
755  switch(hangup_cause) {
756  case AST_CAUSE_BUSY:
757  return "BUSY";
759  return "CONGESTION";
762  return "CHANUNAVAIL";
763  case AST_CAUSE_NO_ANSWER:
764  default:
765  return "NOANSWER";
766  }
767 }
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
#define AST_CAUSE_UNREGISTERED
Definition: causes.h:153
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:99
#define AST_CAUSE_BUSY
Definition: causes.h:148
#define AST_CAUSE_CONGESTION
Definition: causes.h:152