Wed Jan 8 2020 09:49:46

Asterisk developer's documentation


dial.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2007, Digium, Inc.
5  *
6  * Joshua Colp <jcolp@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Dialing API
22  *
23  * \author Joshua Colp <jcolp@digium.com>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 380853 $")
33 
34 #include <sys/time.h>
35 #include <signal.h>
36 
37 #include "asterisk/channel.h"
38 #include "asterisk/utils.h"
39 #include "asterisk/lock.h"
40 #include "asterisk/linkedlists.h"
41 #include "asterisk/dial.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/musiconhold.h"
44 #include "asterisk/app.h"
45 
46 /*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
47 struct ast_dial {
48  int num; /*!< Current number to give to next dialed channel */
49  int timeout; /*!< Maximum time allowed for dial attempts */
50  int actual_timeout; /*!< Actual timeout based on all factors (ie: channels) */
51  enum ast_dial_result state; /*!< Status of dial */
52  void *options[AST_DIAL_OPTION_MAX]; /*!< Global options */
53  ast_dial_state_callback state_callback; /*!< Status callback */
54  AST_LIST_HEAD(, ast_dial_channel) channels; /*!< Channels being dialed */
55  pthread_t thread; /*!< Thread (if running in async) */
56  ast_mutex_t lock; /*! Lock to protect the thread information above */
57 };
58 
59 /*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
61  int num; /*!< Unique number for dialed channel */
62  int timeout; /*!< Maximum time allowed for attempt */
63  char *tech; /*!< Technology being dialed */
64  char *device; /*!< Device being dialed */
65  void *options[AST_DIAL_OPTION_MAX]; /*!< Channel specific options */
66  int cause; /*!< Cause code in case of failure */
67  unsigned int is_running_app:1; /*!< Is this running an application? */
68  struct ast_channel *owner; /*!< Asterisk channel */
69  AST_LIST_ENTRY(ast_dial_channel) list; /*!< Linked list information */
70 };
71 
72 /*! \brief Typedef for dial option enable */
73 typedef void *(*ast_dial_option_cb_enable)(void *data);
74 
75 /*! \brief Typedef for dial option disable */
76 typedef int (*ast_dial_option_cb_disable)(void *data);
77 
78 /*! \brief Structure for 'ANSWER_EXEC' option */
80  char app[AST_MAX_APP]; /*!< Application name */
81  char *args; /*!< Application arguments */
82 };
83 
84 /*! \brief Enable function for 'ANSWER_EXEC' option */
85 static void *answer_exec_enable(void *data)
86 {
87  struct answer_exec_struct *answer_exec = NULL;
88  char *app = ast_strdupa((char*)data), *args = NULL;
89 
90  /* Not giving any data to this option is bad, mmmk? */
91  if (ast_strlen_zero(app))
92  return NULL;
93 
94  /* Create new data structure */
95  if (!(answer_exec = ast_calloc(1, sizeof(*answer_exec))))
96  return NULL;
97 
98  /* Parse out application and arguments */
99  if ((args = strchr(app, ','))) {
100  *args++ = '\0';
101  answer_exec->args = ast_strdup(args);
102  }
103 
104  /* Copy application name */
105  ast_copy_string(answer_exec->app, app, sizeof(answer_exec->app));
106 
107  return answer_exec;
108 }
109 
110 /*! \brief Disable function for 'ANSWER_EXEC' option */
111 static int answer_exec_disable(void *data)
112 {
113  struct answer_exec_struct *answer_exec = data;
114 
115  /* Make sure we have a value */
116  if (!answer_exec)
117  return -1;
118 
119  /* If arguments are present, free them too */
120  if (answer_exec->args)
121  ast_free(answer_exec->args);
122 
123  /* This is simple - just free the structure */
124  ast_free(answer_exec);
125 
126  return 0;
127 }
128 
129 static void *music_enable(void *data)
130 {
131  return ast_strdup(data);
132 }
133 
134 static int music_disable(void *data)
135 {
136  if (!data)
137  return -1;
138 
139  ast_free(data);
140 
141  return 0;
142 }
143 
144 /*! \brief Application execution function for 'ANSWER_EXEC' option */
145 static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial_channel, char *app, char *args)
146 {
147  struct ast_channel *chan = dial_channel->owner;
148  struct ast_app *ast_app = pbx_findapp(app);
149 
150  /* If the application was not found, return immediately */
151  if (!ast_app)
152  return;
153 
154  /* All is well... execute the application */
155  pbx_exec(chan, ast_app, args);
156 
157  /* If another thread is not taking over hang up the channel */
158  ast_mutex_lock(&dial->lock);
159  if (dial->thread != AST_PTHREADT_STOP) {
160  ast_hangup(chan);
161  dial_channel->owner = NULL;
162  }
163  ast_mutex_unlock(&dial->lock);
164 
165  return;
166 }
167 
169  enum ast_dial_option option;
172 };
173 
174 /*!
175  * \brief Map options to respective handlers (enable/disable).
176  *
177  * \note This list MUST be perfectly kept in order with enum
178  * ast_dial_option, or else madness will happen.
179  */
180 static const struct ast_option_types option_types[] = {
181  { AST_DIAL_OPTION_RINGING, NULL, NULL }, /*!< Always indicate ringing to caller */
182  { AST_DIAL_OPTION_ANSWER_EXEC, answer_exec_enable, answer_exec_disable }, /*!< Execute application upon answer in async mode */
183  { AST_DIAL_OPTION_MUSIC, music_enable, music_disable }, /*!< Play music to the caller instead of ringing */
184  { AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, NULL, NULL }, /*!< Disable call forwarding on channels */
185  { AST_DIAL_OPTION_MAX, NULL, NULL }, /*!< Terminator of list */
186 };
187 
188 /*! \brief Maximum number of channels we can watch at a time */
189 #define AST_MAX_WATCHERS 256
190 
191 /*! \brief Macro for finding the option structure to use on a dialed channel */
192 #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])
193 
194 /*! \brief Macro that determines whether a channel is the caller or not */
195 #define IS_CALLER(chan, owner) (chan == owner ? 1 : 0)
196 
197 /*! \brief New dialing structure
198  * \note Create a dialing structure
199  * \return Returns a calloc'd ast_dial structure, NULL on failure
200  */
202 {
203  struct ast_dial *dial = NULL;
204 
205  /* Allocate new memory for structure */
206  if (!(dial = ast_calloc(1, sizeof(*dial))))
207  return NULL;
208 
209  /* Initialize list of channels */
211 
212  /* Initialize thread to NULL */
213  dial->thread = AST_PTHREADT_NULL;
214 
215  /* No timeout exists... yet */
216  dial->timeout = -1;
217  dial->actual_timeout = -1;
218 
219  /* Can't forget about the lock */
220  ast_mutex_init(&dial->lock);
221 
222  return dial;
223 }
224 
225 /*! \brief Append a channel
226  * \note Appends a channel to a dialing structure
227  * \return Returns channel reference number on success, -1 on failure
228  */
229 int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device)
230 {
231  struct ast_dial_channel *channel = NULL;
232 
233  /* Make sure we have required arguments */
234  if (!dial || !tech || !device)
235  return -1;
236 
237  /* Allocate new memory for dialed channel structure */
238  if (!(channel = ast_calloc(1, sizeof(*channel))))
239  return -1;
240 
241  /* Record technology and device for when we actually dial */
242  channel->tech = ast_strdup(tech);
243  channel->device = ast_strdup(device);
244 
245  /* Grab reference number from dial structure */
246  channel->num = ast_atomic_fetchadd_int(&dial->num, +1);
247 
248  /* No timeout exists... yet */
249  channel->timeout = -1;
250 
251  /* Insert into channels list */
252  AST_LIST_INSERT_TAIL(&dial->channels, channel, list);
253 
254  return channel->num;
255 }
256 
257 /*! \brief Helper function that does the beginning dialing per-appended channel */
258 static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan)
259 {
260  char numsubst[AST_MAX_EXTENSION];
261  int res = 1;
262 
263  /* Copy device string over */
264  ast_copy_string(numsubst, channel->device, sizeof(numsubst));
265 
266  /* If we fail to create our owner channel bail out */
267  if (!(channel->owner = ast_request(channel->tech, chan ? chan->nativeformats : AST_FORMAT_AUDIO_MASK, chan, numsubst, &channel->cause)))
268  return -1;
269 
270  channel->owner->appl = "AppDial2";
271  channel->owner->data = "(Outgoing Line)";
272  memset(&channel->owner->whentohangup, 0, sizeof(channel->owner->whentohangup));
273 
274  /* Inherit everything from he who spawned this dial */
275  if (chan) {
276  ast_channel_inherit_variables(chan, channel->owner);
277  ast_channel_datastore_inherit(chan, channel->owner);
278 
279  /* Copy over callerid information */
281 
283 
285 
286  ast_string_field_set(channel->owner, language, chan->language);
288  if (ast_strlen_zero(channel->owner->musicclass))
290 
291  channel->owner->adsicpe = chan->adsicpe;
292  channel->owner->transfercapability = chan->transfercapability;
293  }
294 
295  /* Attempt to actually call this device */
296  if ((res = ast_call(channel->owner, numsubst, 0))) {
297  res = 0;
298  ast_hangup(channel->owner);
299  channel->owner = NULL;
300  } else {
301  if (chan)
302  ast_poll_channel_add(chan, channel->owner);
303  res = 1;
304  ast_verb(3, "Called %s\n", numsubst);
305  }
306 
307  return res;
308 }
309 
310 /*! \brief Helper function that does the beginning dialing per dial structure */
311 static int begin_dial(struct ast_dial *dial, struct ast_channel *chan)
312 {
313  struct ast_dial_channel *channel = NULL;
314  int success = 0;
315 
316  /* Iterate through channel list, requesting and calling each one */
317  AST_LIST_LOCK(&dial->channels);
318  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
319  success += begin_dial_channel(channel, chan);
320  }
321  AST_LIST_UNLOCK(&dial->channels);
322 
323  /* If number of failures matches the number of channels, then this truly failed */
324  return success;
325 }
326 
327 /*! \brief Helper function to handle channels that have been call forwarded */
328 static int handle_call_forward(struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_channel *chan)
329 {
330  struct ast_channel *original = channel->owner;
331  char *tmp = ast_strdupa(channel->owner->call_forward);
332  char *tech = "Local", *device = tmp, *stuff;
333 
334  /* If call forwarding is disabled just drop the original channel and don't attempt to dial the new one */
336  ast_hangup(original);
337  channel->owner = NULL;
338  return 0;
339  }
340 
341  /* Figure out the new destination */
342  if ((stuff = strchr(tmp, '/'))) {
343  *stuff++ = '\0';
344  tech = tmp;
345  device = stuff;
346  }
347 
348  /* Drop old destination information */
349  ast_free(channel->tech);
350  ast_free(channel->device);
351 
352  /* Update the dial channel with the new destination information */
353  channel->tech = ast_strdup(tech);
354  channel->device = ast_strdup(device);
355  AST_LIST_UNLOCK(&dial->channels);
356 
357  /* Finally give it a go... send it out into the world */
358  begin_dial_channel(channel, chan);
359 
360  /* Drop the original channel */
361  ast_hangup(original);
362 
363  return 0;
364 }
365 
366 /*! \brief Helper function that finds the dialed channel based on owner */
367 static struct ast_dial_channel *find_relative_dial_channel(struct ast_dial *dial, struct ast_channel *owner)
368 {
369  struct ast_dial_channel *channel = NULL;
370 
371  AST_LIST_LOCK(&dial->channels);
372  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
373  if (channel->owner == owner)
374  break;
375  }
376  AST_LIST_UNLOCK(&dial->channels);
377 
378  return channel;
379 }
380 
381 static void set_state(struct ast_dial *dial, enum ast_dial_result state)
382 {
383  dial->state = state;
384 
385  if (dial->state_callback)
386  dial->state_callback(dial);
387 }
388 
389 /*! \brief Helper function that handles control frames WITH owner */
390 static void handle_frame(struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_frame *fr, struct ast_channel *chan)
391 {
392  if (fr->frametype == AST_FRAME_CONTROL) {
393  switch (fr->subclass.integer) {
394  case AST_CONTROL_ANSWER:
395  ast_verb(3, "%s answered %s\n", channel->owner->name, chan->name);
396  AST_LIST_LOCK(&dial->channels);
397  AST_LIST_REMOVE(&dial->channels, channel, list);
398  AST_LIST_INSERT_HEAD(&dial->channels, channel, list);
399  AST_LIST_UNLOCK(&dial->channels);
401  break;
402  case AST_CONTROL_BUSY:
403  ast_verb(3, "%s is busy\n", channel->owner->name);
404  ast_hangup(channel->owner);
405  channel->owner = NULL;
406  break;
408  ast_verb(3, "%s is circuit-busy\n", channel->owner->name);
409  ast_hangup(channel->owner);
410  channel->owner = NULL;
411  break;
413  ast_verb(3, "%s dialed Incomplete extension %s\n", channel->owner->name, channel->owner->exten);
415  break;
416  case AST_CONTROL_RINGING:
417  ast_verb(3, "%s is ringing\n", channel->owner->name);
418  if (!dial->options[AST_DIAL_OPTION_MUSIC])
421  break;
423  ast_verb(3, "%s is making progress, passing it to %s\n", channel->owner->name, chan->name);
426  break;
428  ast_verb(3, "%s requested a video update, passing it to %s\n", channel->owner->name, chan->name);
430  break;
432  if (option_verbose > 2)
433  ast_verbose (VERBOSE_PREFIX_3 "%s requested a source update, passing it to %s\n", channel->owner->name, chan->name);
435  break;
437  ast_verb(3, "%s connected line has changed, passing it to %s\n", channel->owner->name, chan->name);
438  if (ast_channel_connected_line_macro(channel->owner, chan, fr, 1, 1)) {
440  }
441  break;
443  ast_verb(3, "%s redirecting info has changed, passing it to %s\n", channel->owner->name, chan->name);
444  if (ast_channel_redirecting_macro(channel->owner, chan, fr, 1, 1)) {
446  }
447  break;
449  ast_verb(3, "%s is proceeding, passing it to %s\n", channel->owner->name, chan->name);
452  break;
453  case AST_CONTROL_HOLD:
454  ast_verb(3, "Call on %s placed on hold\n", chan->name);
456  break;
457  case AST_CONTROL_UNHOLD:
458  ast_verb(3, "Call on %s left from hold\n", chan->name);
460  break;
461  case AST_CONTROL_OFFHOOK:
462  case AST_CONTROL_FLASH:
463  break;
464  case -1:
465  /* Prod the channel */
466  ast_indicate(chan, -1);
467  break;
468  default:
469  break;
470  }
471  }
472 
473  return;
474 }
475 
476 /*! \brief Helper function that handles control frames WITHOUT owner */
477 static void handle_frame_ownerless(struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_frame *fr)
478 {
479  /* If we have no owner we can only update the state of the dial structure, so only look at control frames */
480  if (fr->frametype != AST_FRAME_CONTROL)
481  return;
482 
483  switch (fr->subclass.integer) {
484  case AST_CONTROL_ANSWER:
485  ast_verb(3, "%s answered\n", channel->owner->name);
486  AST_LIST_LOCK(&dial->channels);
487  AST_LIST_REMOVE(&dial->channels, channel, list);
488  AST_LIST_INSERT_HEAD(&dial->channels, channel, list);
489  AST_LIST_UNLOCK(&dial->channels);
491  break;
492  case AST_CONTROL_BUSY:
493  ast_verb(3, "%s is busy\n", channel->owner->name);
494  ast_hangup(channel->owner);
495  channel->owner = NULL;
496  break;
498  ast_verb(3, "%s is circuit-busy\n", channel->owner->name);
499  ast_hangup(channel->owner);
500  channel->owner = NULL;
501  break;
502  case AST_CONTROL_RINGING:
503  ast_verb(3, "%s is ringing\n", channel->owner->name);
505  break;
507  ast_verb(3, "%s is making progress\n", channel->owner->name);
509  break;
511  ast_verb(3, "%s is proceeding\n", channel->owner->name);
513  break;
514  default:
515  break;
516  }
517 
518  return;
519 }
520 
521 /*! \brief Helper function to handle when a timeout occurs on dialing attempt */
522 static int handle_timeout_trip(struct ast_dial *dial, struct timeval start)
523 {
524  struct ast_dial_channel *channel = NULL;
525  int diff = ast_tvdiff_ms(ast_tvnow(), start), lowest_timeout = -1, new_timeout = -1;
526 
527  /* If the global dial timeout tripped switch the state to timeout so our channel loop will drop every channel */
528  if (diff >= dial->timeout) {
530  new_timeout = 0;
531  }
532 
533  /* Go through dropping out channels that have met their timeout */
534  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
535  if (dial->state == AST_DIAL_RESULT_TIMEOUT || diff >= channel->timeout) {
536  ast_hangup(channel->owner);
537  channel->owner = NULL;
538  } else if ((lowest_timeout == -1) || (lowest_timeout > channel->timeout)) {
539  lowest_timeout = channel->timeout;
540  }
541  }
542 
543  /* Calculate the new timeout using the lowest timeout found */
544  if (lowest_timeout >= 0)
545  new_timeout = lowest_timeout - diff;
546 
547  return new_timeout;
548 }
549 
550 /*! \brief Helper function that basically keeps tabs on dialing attempts */
551 static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_channel *chan)
552 {
553  int timeout = -1;
554  struct ast_channel *cs[AST_MAX_WATCHERS], *who = NULL;
555  struct ast_dial_channel *channel = NULL;
556  struct answer_exec_struct *answer_exec = NULL;
557  struct timeval start;
558 
560 
561  /* If the "always indicate ringing" option is set, change state to ringing and indicate to the owner if present */
562  if (dial->options[AST_DIAL_OPTION_RINGING]) {
564  if (chan)
566  } else if (chan && dial->options[AST_DIAL_OPTION_MUSIC] &&
568  char *original_moh = ast_strdupa(chan->musicclass);
569  ast_indicate(chan, -1);
571  ast_moh_start(chan, dial->options[AST_DIAL_OPTION_MUSIC], NULL);
572  ast_string_field_set(chan, musicclass, original_moh);
573  }
574 
575  /* Record start time for timeout purposes */
576  start = ast_tvnow();
577 
578  /* We actually figured out the maximum timeout we can do as they were added, so we can directly access the info */
579  timeout = dial->actual_timeout;
580 
581  /* Go into an infinite loop while we are trying */
582  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)) {
583  int pos = 0, count = 0;
584  struct ast_frame *fr = NULL;
585 
586  /* Set up channel structure array */
587  pos = count = 0;
588  if (chan)
589  cs[pos++] = chan;
590 
591  /* Add channels we are attempting to dial */
592  AST_LIST_LOCK(&dial->channels);
593  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
594  if (channel->owner) {
595  cs[pos++] = channel->owner;
596  count++;
597  }
598  }
599  AST_LIST_UNLOCK(&dial->channels);
600 
601  /* If we have no outbound channels in progress, switch state to unanswered and stop */
602  if (!count) {
604  break;
605  }
606 
607  /* Just to be safe... */
608  if (dial->thread == AST_PTHREADT_STOP)
609  break;
610 
611  /* Wait for frames from channels */
612  who = ast_waitfor_n(cs, pos, &timeout);
613 
614  /* Check to see if our thread is being cancelled */
615  if (dial->thread == AST_PTHREADT_STOP)
616  break;
617 
618  /* If the timeout no longer exists OR if we got no channel it basically means the timeout was tripped, so handle it */
619  if (!timeout || !who) {
620  timeout = handle_timeout_trip(dial, start);
621  continue;
622  }
623 
624  /* Find relative dial channel */
625  if (!chan || !IS_CALLER(chan, who))
626  channel = find_relative_dial_channel(dial, who);
627 
628  /* See if this channel has been forwarded elsewhere */
629  if (!ast_strlen_zero(who->call_forward)) {
630  handle_call_forward(dial, channel, chan);
631  continue;
632  }
633 
634  /* Attempt to read in a frame */
635  if (!(fr = ast_read(who))) {
636  /* If this is the caller then we switch state to hangup and stop */
637  if (chan && IS_CALLER(chan, who)) {
639  break;
640  }
641  if (chan)
642  ast_poll_channel_del(chan, channel->owner);
643  ast_hangup(who);
644  channel->owner = NULL;
645  continue;
646  }
647 
648  /* Process the frame */
649  if (chan)
650  handle_frame(dial, channel, fr, chan);
651  else
652  handle_frame_ownerless(dial, channel, fr);
653 
654  /* Free the received frame and start all over */
655  ast_frfree(fr);
656  }
657 
658  /* Do post-processing from loop */
659  if (dial->state == AST_DIAL_RESULT_ANSWERED) {
660  /* Hangup everything except that which answered */
661  AST_LIST_LOCK(&dial->channels);
662  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
663  if (!channel->owner || channel->owner == who)
664  continue;
665  if (chan)
666  ast_poll_channel_del(chan, channel->owner);
667  ast_hangup(channel->owner);
668  channel->owner = NULL;
669  }
670  AST_LIST_UNLOCK(&dial->channels);
671  /* If ANSWER_EXEC is enabled as an option, execute application on answered channel */
672  if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC))) {
673  channel->is_running_app = 1;
674  answer_exec_run(dial, channel, answer_exec->app, answer_exec->args);
675  channel->is_running_app = 0;
676  }
677 
678  if (chan && dial->options[AST_DIAL_OPTION_MUSIC] &&
680  ast_moh_stop(chan);
681  }
682  } else if (dial->state == AST_DIAL_RESULT_HANGUP) {
683  /* Hangup everything */
684  AST_LIST_LOCK(&dial->channels);
685  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
686  if (!channel->owner)
687  continue;
688  if (chan)
689  ast_poll_channel_del(chan, channel->owner);
690  ast_hangup(channel->owner);
691  channel->owner = NULL;
692  }
693  AST_LIST_UNLOCK(&dial->channels);
694  }
695 
696  return dial->state;
697 }
698 
699 /*! \brief Dial async thread function */
700 static void *async_dial(void *data)
701 {
702  struct ast_dial *dial = data;
703 
704  /* This is really really simple... we basically pass monitor_dial a NULL owner and it changes it's behavior */
705  monitor_dial(dial, NULL);
706 
707  return NULL;
708 }
709 
710 /*! \brief Execute dialing synchronously or asynchronously
711  * \note Dials channels in a dial structure.
712  * \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
713  */
714 enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async)
715 {
717 
718  /* Ensure required arguments are passed */
719  if (!dial || (!chan && !async)) {
720  ast_debug(1, "invalid #1\n");
722  }
723 
724  /* If there are no channels to dial we can't very well try to dial them */
725  if (AST_LIST_EMPTY(&dial->channels)) {
726  ast_debug(1, "invalid #2\n");
728  }
729 
730  /* Dial each requested channel */
731  if (!begin_dial(dial, chan))
732  return AST_DIAL_RESULT_FAILED;
733 
734  /* If we are running async spawn a thread and send it away... otherwise block here */
735  if (async) {
737  /* Try to create a thread */
738  if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
739  /* Failed to create the thread - hangup all dialed channels and return failed */
740  ast_dial_hangup(dial);
742  }
743  } else {
744  res = monitor_dial(dial, chan);
745  }
746 
747  return res;
748 }
749 
750 /*! \brief Return channel that answered
751  * \note Returns the Asterisk channel that answered
752  * \param dial Dialing structure
753  */
755 {
756  if (!dial)
757  return NULL;
758 
759  return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL);
760 }
761 
762 /*! \brief Steal the channel that answered
763  * \note Returns the Asterisk channel that answered and removes it from the dialing structure
764  * \param dial Dialing structure
765  */
767 {
768  struct ast_channel *chan = NULL;
769 
770  if (!dial)
771  return NULL;
772 
773  if (dial->state == AST_DIAL_RESULT_ANSWERED) {
774  chan = AST_LIST_FIRST(&dial->channels)->owner;
775  AST_LIST_FIRST(&dial->channels)->owner = NULL;
776  }
777 
778  return chan;
779 }
780 
781 /*! \brief Return state of dial
782  * \note Returns the state of the dial attempt
783  * \param dial Dialing structure
784  */
786 {
787  return dial->state;
788 }
789 
790 /*! \brief Cancel async thread
791  * \note Cancel a running async thread
792  * \param dial Dialing structure
793  */
795 {
796  pthread_t thread;
797 
798  /* If the dial structure is not running in async, return failed */
799  if (dial->thread == AST_PTHREADT_NULL)
800  return AST_DIAL_RESULT_FAILED;
801 
802  /* Record thread */
803  thread = dial->thread;
804 
805  /* Boom, commence locking */
806  ast_mutex_lock(&dial->lock);
807 
808  /* Stop the thread */
809  dial->thread = AST_PTHREADT_STOP;
810 
811  /* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
812  AST_LIST_LOCK(&dial->channels);
813  if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
814  struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
815  if (chan) {
816  ast_channel_lock(chan);
818  ast_channel_unlock(chan);
819  }
820  } else {
821  /* Now we signal it with SIGURG so it will break out of it's waitfor */
822  pthread_kill(thread, SIGURG);
823  }
824  AST_LIST_UNLOCK(&dial->channels);
825 
826  /* Yay done with it */
827  ast_mutex_unlock(&dial->lock);
828 
829  /* Finally wait for the thread to exit */
830  pthread_join(thread, NULL);
831 
832  /* Yay thread is all gone */
833  dial->thread = AST_PTHREADT_NULL;
834 
835  return dial->state;
836 }
837 
838 /*! \brief Hangup channels
839  * \note Hangup all active channels
840  * \param dial Dialing structure
841  */
842 void ast_dial_hangup(struct ast_dial *dial)
843 {
844  struct ast_dial_channel *channel = NULL;
845 
846  if (!dial)
847  return;
848 
849  AST_LIST_LOCK(&dial->channels);
850  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
851  if (channel->owner) {
852  ast_hangup(channel->owner);
853  channel->owner = NULL;
854  }
855  }
856  AST_LIST_UNLOCK(&dial->channels);
857 
858  return;
859 }
860 
861 /*! \brief Destroys a dialing structure
862  * \note Destroys (free's) the given ast_dial structure
863  * \param dial Dialing structure to free
864  * \return Returns 0 on success, -1 on failure
865  */
866 int ast_dial_destroy(struct ast_dial *dial)
867 {
868  int i = 0;
869  struct ast_dial_channel *channel = NULL;
870 
871  if (!dial)
872  return -1;
873 
874  /* Hangup and deallocate all the dialed channels */
875  AST_LIST_LOCK(&dial->channels);
876  AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) {
877  /* Disable any enabled options */
878  for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
879  if (!channel->options[i])
880  continue;
881  if (option_types[i].disable)
882  option_types[i].disable(channel->options[i]);
883  channel->options[i] = NULL;
884  }
885  /* Hang up channel if need be */
886  if (channel->owner) {
887  ast_hangup(channel->owner);
888  channel->owner = NULL;
889  }
890  /* Free structure */
891  ast_free(channel->tech);
892  ast_free(channel->device);
894  ast_free(channel);
895  }
897  AST_LIST_UNLOCK(&dial->channels);
898 
899  /* Disable any enabled options globally */
900  for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
901  if (!dial->options[i])
902  continue;
903  if (option_types[i].disable)
904  option_types[i].disable(dial->options[i]);
905  dial->options[i] = NULL;
906  }
907 
908  /* Lock be gone! */
909  ast_mutex_destroy(&dial->lock);
910 
911  /* Free structure */
912  ast_free(dial);
913 
914  return 0;
915 }
916 
917 /*! \brief Enables an option globally
918  * \param dial Dial structure to enable option on
919  * \param option Option to enable
920  * \param data Data to pass to this option (not always needed)
921  * \return Returns 0 on success, -1 on failure
922  */
923 int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data)
924 {
925  /* If the option is already enabled, return failure */
926  if (dial->options[option])
927  return -1;
928 
929  /* Execute enable callback if it exists, if not simply make sure the value is set */
930  if (option_types[option].enable)
931  dial->options[option] = option_types[option].enable(data);
932  else
933  dial->options[option] = (void*)1;
934 
935  return 0;
936 }
937 
938 /*! \brief Helper function for finding a channel in a dial structure based on number
939  */
940 static struct ast_dial_channel *find_dial_channel(struct ast_dial *dial, int num)
941 {
942  struct ast_dial_channel *channel = AST_LIST_LAST(&dial->channels);
943 
944  /* We can try to predict programmer behavior, the last channel they added is probably the one they wanted to modify */
945  if (channel->num == num)
946  return channel;
947 
948  /* Hrm not at the end... looking through the list it is! */
949  AST_LIST_LOCK(&dial->channels);
950  AST_LIST_TRAVERSE(&dial->channels, channel, list) {
951  if (channel->num == num)
952  break;
953  }
954  AST_LIST_UNLOCK(&dial->channels);
955 
956  return channel;
957 }
958 
959 /*! \brief Enables an option per channel
960  * \param dial Dial structure
961  * \param num Channel number to enable option on
962  * \param option Option to enable
963  * \param data Data to pass to this option (not always needed)
964  * \return Returns 0 on success, -1 on failure
965  */
966 int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data)
967 {
968  struct ast_dial_channel *channel = NULL;
969 
970  /* Ensure we have required arguments */
971  if (!dial || AST_LIST_EMPTY(&dial->channels))
972  return -1;
973 
974  if (!(channel = find_dial_channel(dial, num)))
975  return -1;
976 
977  /* If the option is already enabled, return failure */
978  if (channel->options[option])
979  return -1;
980 
981  /* Execute enable callback if it exists, if not simply make sure the value is set */
982  if (option_types[option].enable)
983  channel->options[option] = option_types[option].enable(data);
984  else
985  channel->options[option] = (void*)1;
986 
987  return 0;
988 }
989 
990 /*! \brief Disables an option globally
991  * \param dial Dial structure to disable option on
992  * \param option Option to disable
993  * \return Returns 0 on success, -1 on failure
994  */
996 {
997  /* If the option is not enabled, return failure */
998  if (!dial->options[option]) {
999  return -1;
1000  }
1001 
1002  /* Execute callback of option to disable if it exists */
1003  if (option_types[option].disable)
1004  option_types[option].disable(dial->options[option]);
1005 
1006  /* Finally disable option on the structure */
1007  dial->options[option] = NULL;
1008 
1009  return 0;
1010 }
1011 
1012 /*! \brief Disables an option per channel
1013  * \param dial Dial structure
1014  * \param num Channel number to disable option on
1015  * \param option Option to disable
1016  * \return Returns 0 on success, -1 on failure
1017  */
1018 int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option)
1019 {
1020  struct ast_dial_channel *channel = NULL;
1021 
1022  /* Ensure we have required arguments */
1023  if (!dial || AST_LIST_EMPTY(&dial->channels))
1024  return -1;
1025 
1026  if (!(channel = find_dial_channel(dial, num)))
1027  return -1;
1028 
1029  /* If the option is not enabled, return failure */
1030  if (!channel->options[option])
1031  return -1;
1032 
1033  /* Execute callback of option to disable it if it exists */
1034  if (option_types[option].disable)
1035  option_types[option].disable(channel->options[option]);
1036 
1037  /* Finally disable the option on the structure */
1038  channel->options[option] = NULL;
1039 
1040  return 0;
1041 }
1042 
1044 {
1045  dial->state_callback = callback;
1046 }
1047 
1048 /*! \brief Set the maximum time (globally) allowed for trying to ring phones
1049  * \param dial The dial structure to apply the time limit to
1050  * \param timeout Maximum time allowed
1051  * \return nothing
1052  */
1053 void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout)
1054 {
1055  dial->timeout = timeout;
1056 
1057  if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1))
1058  dial->actual_timeout = dial->timeout;
1059 
1060  return;
1061 }
1062 
1063 /*! \brief Set the maximum time (per channel) allowed for trying to ring the phone
1064  * \param dial The dial structure the channel belongs to
1065  * \param num Channel number to set timeout on
1066  * \param timeout Maximum time allowed
1067  * \return nothing
1068  */
1069 void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout)
1070 {
1071  struct ast_dial_channel *channel = NULL;
1072 
1073  if (!(channel = find_dial_channel(dial, num)))
1074  return;
1075 
1076  channel->timeout = timeout;
1077 
1078  if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1))
1079  dial->actual_timeout = channel->timeout;
1080 
1081  return;
1082 }
char * args
Definition: dial.c:81
static char musicclass[MAX_MUSICCLASS]
Definition: chan_mgcp.c:155
struct ast_channel * ast_waitfor_n(struct ast_channel **chan, int n, int *ms)
Waits for input on a group of channels Wait for input on an array of channels for a given # of millis...
Definition: channel.c:3534
union ast_frame_subclass subclass
Definition: frame.h:146
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_iax2.c:383
static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial_channel, char *app, char *args)
Application execution function for &#39;ANSWER_EXEC&#39; option.
Definition: dial.c:145
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
Music on hold handling.
int ast_dial_destroy(struct ast_dial *dial)
Destroys a dialing structure.
Definition: dial.c:866
static void set_state(struct ast_dial *dial, enum ast_dial_result state)
Definition: dial.c:381
struct ast_party_connected_line connected
Channel Connected Line ID information.
Definition: channel.h:811
static int begin_dial(struct ast_dial *dial, struct ast_channel *chan)
Helper function that does the beginning dialing per dial structure.
Definition: dial.c:311
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data)
Enables an option globally.
Definition: dial.c:923
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1)
Definition: channel.c:2665
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
unsigned int is_running_app
Definition: dial.c:67
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:172
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: pbx.c:1537
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx.c:1497
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.
Definition: dial.c:477
Main dialing structure. Contains global options, channels being dialed, and more! ...
Definition: dial.c:47
#define ast_strdup(a)
Definition: astmm.h:109
struct ast_dial::@252 channels
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.
Definition: dial.c:367
void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout)
Set the maximum time (globally) allowed for trying to ring phones.
Definition: dial.c:1053
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
void * ptr
Definition: frame.h:160
void ast_dial_hangup(struct ast_dial *dial)
Hangup channels.
Definition: dial.c:842
enum ast_dial_result state
Definition: dial.c:51
#define VERBOSE_PREFIX_3
Definition: logger.h:43
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device)
Append a channel.
Definition: dial.c:229
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4383
static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan)
Helper function that does the beginning dialing per-appended channel.
Definition: dial.c:258
struct ast_party_redirecting redirecting
Redirecting/Diversion information.
Definition: channel.h:814
int option_verbose
Definition: asterisk.c:181
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4447
Dialing API.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define FIND_RELATIVE_OPTION(dial, dial_channel, ast_dial_option)
Macro for finding the option structure to use on a dialed channel.
Definition: dial.c:192
#define ast_mutex_lock(a)
Definition: lock.h:155
unsigned short transfercapability
Definition: channel.h:863
format_t nativeformats
Definition: channel.h:852
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame)
Run a connected line interception macro and update a channel&#39;s connected line information.
Definition: channel.c:9618
const char * data
Definition: channel.h:755
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:841
enum ast_channel_adsicpe adsicpe
Definition: channel.h:844
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:8051
#define AST_MAX_WATCHERS
Maximum number of channels we can watch at a time.
Definition: dial.c:189
#define ast_verb(level,...)
Definition: logger.h:243
const char * appl
Definition: channel.h:754
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
Definition: lock.h:603
Utility functions.
pthread_t thread
Definition: dial.c:55
int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data)
Enables an option per channel.
Definition: dial.c:966
void *(* ast_dial_option_cb_enable)(void *data)
Typedef for dial option enable.
Definition: dial.c:73
void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
Set a callback for state changes.
Definition: dial.c:1043
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2573
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:52
ast_dial_result
List of return codes for dial run API calls.
Definition: dial.h:48
static const char app[]
Definition: app_adsiprog.c:49
General Asterisk PBX channel definitions.
enum ast_dial_result ast_dial_join(struct ast_dial *dial)
Cancel async thread.
Definition: dial.c:794
int num
Definition: dial.c:48
#define AST_PTHREADT_NULL
Definition: lock.h:65
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_MAX_EXTENSION
Definition: channel.h:135
int datalen
Definition: frame.h:148
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
int(* ast_dial_option_cb_disable)(void *data)
Typedef for dial option disable.
Definition: dial.c:76
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2746
char * tech
Definition: dial.c:63
A set of macros to manage forward-linked lists.
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:108
int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option)
Disables an option globally.
Definition: dial.c:995
ast_dial_option
List of options that are applicable either globally or per dialed channel.
Definition: dial.h:39
enum ast_dial_result ast_dial_state(struct ast_dial *dial)
Return state of dial.
Definition: dial.c:785
Core PBX routines and definitions.
enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async)
Execute dialing synchronously or asynchronously.
Definition: dial.c:714
struct ast_party_dialed dialed
Dialed/Called information.
Definition: channel.h:797
static void * music_enable(void *data)
Definition: dial.c:129
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
void * options[AST_DIAL_OPTION_MAX]
Definition: dial.c:65
struct ast_channel * owner
Definition: dial.c:68
ast_dial_option_cb_enable enable
Definition: dial.c:170
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
static int answer_exec_disable(void *data)
Disable function for &#39;ANSWER_EXEC&#39; option.
Definition: dial.c:111
#define AST_MAX_APP
Definition: pbx.h:39
static struct @350 args
ast_mutex_t lock
Definition: dial.c:54
const ast_string_field call_forward
Definition: channel.h:787
static int music_disable(void *data)
Definition: dial.c:134
const ast_string_field name
Definition: channel.h:787
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:8040
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
struct ast_channel * ast_dial_answered(struct ast_dial *dial)
Return channel that answered.
Definition: dial.c:754
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
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.
Definition: dial.c:328
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
static void * async_dial(void *data)
Dial async thread function.
Definition: dial.c:700
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6241
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
Definition: linkedlists.h:611
#define ast_free(a)
Definition: astmm.h:97
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:418
struct ast_dial * ast_dial_create(void)
New dialing structure.
Definition: dial.c:201
static void * answer_exec_enable(void *data)
Enable function for &#39;ANSWER_EXEC&#39; option.
Definition: dial.c:85
#define AST_FORMAT_AUDIO_MASK
Definition: frame.h:274
struct ast_dial_channel::@253 list
int ast_call(struct ast_channel *chan, char *addr, int timeout)
Make a call.
Definition: channel.c:5761
Structure for &#39;ANSWER_EXEC&#39; option.
Definition: dial.c:79
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:551
static struct ast_option_types option_types[]
Map options to respective handlers (enable/disable).
Definition: dial.c:180
struct ast_channel * ast_dial_answered_steal(struct ast_dial *dial)
Steal the channel that answered.
Definition: dial.c:766
void(* ast_dial_state_callback)(struct ast_dial *)
Definition: dial.h:36
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.
Definition: dial.c:390
void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1)
Definition: channel.c:2688
int transit_network_select
Transit Network Select.
Definition: channel.h:347
ast_dial_state_callback state_callback
Definition: dial.c:53
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:940
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8443
ast_app: A registered application
Definition: pbx.c:971
int timeout
Definition: dial.c:49
#define AST_PTHREADT_STOP
Definition: lock.h:66
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
const ast_string_field musicclass
Definition: channel.h:787
const ast_string_field accountcode
Definition: channel.h:787
Data structure associated with a single frame of data.
Definition: frame.h:142
ast_dial_option_cb_disable disable
Definition: dial.c:171
struct timeval whentohangup
Definition: channel.h:789
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
enum ast_frame_type frametype
Definition: frame.h:144
int actual_timeout
Definition: dial.c:50
#define ast_mutex_init(pmutex)
Definition: lock.h:152
#define ast_frfree(fr)
Definition: frame.h:583
char app[AST_MAX_APP]
Definition: dial.c:80
int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option)
Disables an option per channel.
Definition: dial.c:1018
#define ast_mutex_destroy(a)
Definition: lock.h:154
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.
Definition: dial.c:1069
#define IS_CALLER(chan, owner)
Macro that determines whether a channel is the caller or not.
Definition: dial.c:195
struct ast_channel * ast_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *status)
Requests a channel.
Definition: channel.c:5695
union ast_frame::@172 data
char * device
Definition: dial.c:64
const ast_string_field language
Definition: channel.h:787
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2367
Structure for mutex and tracking information.
Definition: lock.h:121
static int handle_timeout_trip(struct ast_dial *dial, struct timeval start)
Helper function to handle when a timeout occurs on dialing attempt.
Definition: dial.c:522
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
int timeout
Definition: dial.c:62
int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame)
Run a redirecting interception macro and update a channel&#39;s redirecting information.
Definition: channel.c:9663
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:60
#define ast_mutex_unlock(a)
Definition: lock.h:156
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344