Asterisk - The Open Source Telephony Project  GIT-master-44aef04
app_dial.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2012, Digium, Inc.
5  *
6  * Mark Spencer <markster@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 dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <support_level>core</support_level>
30  ***/
31 
32 
33 #include "asterisk.h"
34 
35 #include <sys/time.h>
36 #include <signal.h>
37 #include <sys/stat.h>
38 #include <netinet/in.h>
39 
40 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
41 #include "asterisk/lock.h"
42 #include "asterisk/file.h"
43 #include "asterisk/channel.h"
44 #include "asterisk/pbx.h"
45 #include "asterisk/module.h"
46 #include "asterisk/translate.h"
47 #include "asterisk/say.h"
48 #include "asterisk/config.h"
49 #include "asterisk/features.h"
50 #include "asterisk/musiconhold.h"
51 #include "asterisk/callerid.h"
52 #include "asterisk/utils.h"
53 #include "asterisk/app.h"
54 #include "asterisk/causes.h"
55 #include "asterisk/rtp_engine.h"
56 #include "asterisk/manager.h"
57 #include "asterisk/privacy.h"
58 #include "asterisk/stringfields.h"
59 #include "asterisk/dsp.h"
60 #include "asterisk/aoc.h"
61 #include "asterisk/ccss.h"
62 #include "asterisk/indications.h"
63 #include "asterisk/framehook.h"
64 #include "asterisk/dial.h"
66 #include "asterisk/bridge_after.h"
68 #include "asterisk/max_forwards.h"
69 #include "asterisk/stream.h"
70 
71 /*** DOCUMENTATION
72  <application name="Dial" language="en_US">
73  <synopsis>
74  Attempt to connect to another device or endpoint and bridge the call.
75  </synopsis>
76  <syntax>
77  <parameter name="Technology/Resource" required="false" argsep="&amp;">
78  <argument name="Technology/Resource" required="true">
79  <para>Specification of the device(s) to dial. These must be in the format of
80  <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
81  represents a particular channel driver, and <replaceable>Resource</replaceable>
82  represents a resource available to that particular channel driver.</para>
83  </argument>
84  <argument name="Technology2/Resource2" required="false" multiple="true">
85  <para>Optional extra devices to dial in parallel</para>
86  <para>If you need more than one enter them as
87  Technology2/Resource2&amp;Technology3/Resource3&amp;.....</para>
88  </argument>
89  </parameter>
90  <parameter name="timeout" required="false">
91  <para>Specifies the number of seconds we attempt to dial the specified devices.</para>
92  <para>If not specified, this defaults to 136 years.</para>
93  </parameter>
94  <parameter name="options" required="false">
95  <optionlist>
96  <option name="A">
97  <argument name="x" required="true">
98  <para>The file to play to the called party</para>
99  </argument>
100  <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
101  </option>
102  <option name="a">
103  <para>Immediately answer the calling channel when the called channel answers in
104  all cases. Normally, the calling channel is answered when the called channel
105  answers, but when options such as <literal>A()</literal> and
106  <literal>M()</literal> are used, the calling channel is
107  not answered until all actions on the called channel (such as playing an
108  announcement) are completed. This option can be used to answer the calling
109  channel before doing anything on the called channel. You will rarely need to use
110  this option, the default behavior is adequate in most cases.</para>
111  </option>
112  <option name="b" argsep="^">
113  <para>Before initiating an outgoing call, <literal>Gosub</literal> to the specified
114  location using the newly created channel. The <literal>Gosub</literal> will be
115  executed for each destination channel.</para>
116  <argument name="context" required="false" />
117  <argument name="exten" required="false" />
118  <argument name="priority" required="true" hasparams="optional" argsep="^">
119  <argument name="arg1" multiple="true" required="true" />
120  <argument name="argN" />
121  </argument>
122  </option>
123  <option name="B" argsep="^">
124  <para>Before initiating the outgoing call(s), <literal>Gosub</literal> to the
125  specified location using the current channel.</para>
126  <argument name="context" required="false" />
127  <argument name="exten" required="false" />
128  <argument name="priority" required="true" hasparams="optional" argsep="^">
129  <argument name="arg1" multiple="true" required="true" />
130  <argument name="argN" />
131  </argument>
132  </option>
133  <option name="C">
134  <para>Reset the call detail record (CDR) for this call.</para>
135  </option>
136  <option name="c">
137  <para>If the Dial() application cancels this call, always set
138  <variable>HANGUPCAUSE</variable> to 'answered elsewhere'</para>
139  </option>
140  <option name="d">
141  <para>Allow the calling user to dial a 1 digit extension while waiting for
142  a call to be answered. Exit to that extension if it exists in the
143  current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
144  if it exists.</para>
145  <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
146  connected. If you wish to use this option with these phones, you
147  can use the <literal>Answer</literal> application before dialing.</para>
148  </option>
149  <option name="D" argsep=":">
150  <argument name="called" />
151  <argument name="calling" />
152  <argument name="progress" />
153  <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
154  party has answered, but before the call gets bridged. The
155  <replaceable>called</replaceable> DTMF string is sent to the called party, and the
156  <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
157  can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
158  to the called party immediately after receiving a <literal>PROGRESS</literal> message.</para>
159  <para>See <literal>SendDTMF</literal> for valid digits.</para>
160  </option>
161  <option name="e">
162  <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
163  </option>
164  <option name="f">
165  <argument name="x" required="false" />
166  <para>If <replaceable>x</replaceable> is not provided, force the CallerID sent on a call-forward or
167  deflection to the dialplan extension of this <literal>Dial()</literal> using a dialplan <literal>hint</literal>.
168  For example, some PSTNs do not allow CallerID to be set to anything
169  other than the numbers assigned to you.
170  If <replaceable>x</replaceable> is provided, force the CallerID sent to <replaceable>x</replaceable>.</para>
171  </option>
172  <option name="F" argsep="^">
173  <argument name="context" required="false" />
174  <argument name="exten" required="false" />
175  <argument name="priority" required="true" />
176  <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party
177  to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
178  <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
179  prefixed with one or two underbars ('_').</para>
180  </option>
181  <option name="F">
182  <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party to the next priority of the current extension
183  and <emphasis>start</emphasis> execution at that location.</para>
184  <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
185  prefixed with one or two underbars ('_').</para>
186  <para>NOTE: Using this option from a Macro() or GoSub() might not make sense as there would be no return points.</para>
187  </option>
188  <option name="g">
189  <para>Proceed with dialplan execution at the next priority in the current extension if the
190  destination channel hangs up.</para>
191  </option>
192  <option name="G" argsep="^">
193  <argument name="context" required="false" />
194  <argument name="exten" required="false" />
195  <argument name="priority" required="true" />
196  <para>If the call is answered, transfer the calling party to
197  the specified <replaceable>priority</replaceable> and the called party to the specified
198  <replaceable>priority</replaceable> plus one.</para>
199  <para>NOTE: You cannot use any additional action post answer options in conjunction with this option.</para>
200  </option>
201  <option name="h">
202  <para>Allow the called party to hang up by sending the DTMF sequence
203  defined for disconnect in <filename>features.conf</filename>.</para>
204  </option>
205  <option name="H">
206  <para>Allow the calling party to hang up by sending the DTMF sequence
207  defined for disconnect in <filename>features.conf</filename>.</para>
208  <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
209  connected. If you wish to allow DTMF disconnect before the dialed
210  party answers with these phones, you can use the <literal>Answer</literal>
211  application before dialing.</para>
212  </option>
213  <option name="i">
214  <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
215  </option>
216  <option name="I">
217  <para>Asterisk will ignore any connected line update requests or any redirecting party
218  update requests it may receive on this dial attempt.</para>
219  </option>
220  <option name="k">
221  <para>Allow the called party to enable parking of the call by sending
222  the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
223  </option>
224  <option name="K">
225  <para>Allow the calling party to enable parking of the call by sending
226  the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
227  </option>
228  <option name="L" argsep=":">
229  <argument name="x" required="true">
230  <para>Maximum call time, in milliseconds</para>
231  </argument>
232  <argument name="y">
233  <para>Warning time, in milliseconds</para>
234  </argument>
235  <argument name="z">
236  <para>Repeat time, in milliseconds</para>
237  </argument>
238  <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
239  left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
240  <para>This option is affected by the following variables:</para>
241  <variablelist>
242  <variable name="LIMIT_PLAYAUDIO_CALLER">
243  <value name="yes" default="true" />
244  <value name="no" />
245  <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
246  </variable>
247  <variable name="LIMIT_PLAYAUDIO_CALLEE">
248  <value name="yes" />
249  <value name="no" default="true"/>
250  <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
251  </variable>
252  <variable name="LIMIT_TIMEOUT_FILE">
253  <value name="filename"/>
254  <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
255  If not set, the time remaining will be announced.</para>
256  </variable>
257  <variable name="LIMIT_CONNECT_FILE">
258  <value name="filename"/>
259  <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
260  If not set, the time remaining will be announced.</para>
261  </variable>
262  <variable name="LIMIT_WARNING_FILE">
263  <value name="filename"/>
264  <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
265  a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
266  </variable>
267  </variablelist>
268  </option>
269  <option name="m">
270  <argument name="class" required="false"/>
271  <para>Provide hold music to the calling party until a requested
272  channel answers. A specific music on hold <replaceable>class</replaceable>
273  (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
274  </option>
275  <option name="M" argsep="^">
276  <argument name="macro" required="true">
277  <para>Name of the macro that should be executed.</para>
278  </argument>
279  <argument name="arg" multiple="true">
280  <para>Macro arguments</para>
281  </argument>
282  <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
283  before connecting to the calling channel. Arguments can be specified to the Macro
284  using <literal>^</literal> as a delimiter. The macro can set the variable
285  <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
286  finished executing:</para>
287  <variablelist>
288  <variable name="MACRO_RESULT">
289  <para>If set, this action will be taken after the macro finished executing.</para>
290  <value name="ABORT">
291  Hangup both legs of the call
292  </value>
293  <value name="CONGESTION">
294  Behave as if line congestion was encountered
295  </value>
296  <value name="BUSY">
297  Behave as if a busy signal was encountered
298  </value>
299  <value name="CONTINUE">
300  Hangup the called party and allow the calling party to continue dialplan execution at the next priority
301  </value>
302  <value name="GOTO:[[&lt;context&gt;^]&lt;exten&gt;^]&lt;priority&gt;">
303  Transfer the call to the specified destination.
304  </value>
305  </variable>
306  </variablelist>
307  <para>NOTE: You cannot use any additional action post answer options in conjunction
308  with this option. Also, pbx services are run on the peer (called) channel,
309  so you will not be able to set timeouts via the <literal>TIMEOUT()</literal> function in this macro.</para>
310  <para>WARNING: Be aware of the limitations that macros have, specifically with regards to use of
311  the <literal>WaitExten</literal> application. For more information, see the documentation for
312  <literal>Macro()</literal>.</para>
313  <para>NOTE: Macros are deprecated, GoSub should be used instead,
314  see the <literal>U</literal> option.</para>
315  </option>
316  <option name="n">
317  <argument name="delete">
318  <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
319  the recorded introduction will not be deleted if the caller hangs up while the remote party has not
320  yet answered.</para>
321  <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
322  always be deleted.</para>
323  </argument>
324  <para>This option is a modifier for the call screening/privacy mode. (See the
325  <literal>p</literal> and <literal>P</literal> options.) It specifies
326  that no introductions are to be saved in the <directory>priv-callerintros</directory>
327  directory.</para>
328  </option>
329  <option name="N">
330  <para>This option is a modifier for the call screening/privacy mode. It specifies
331  that if CallerID is present, do not screen the call.</para>
332  </option>
333  <option name="o">
334  <argument name="x" required="false" />
335  <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
336  <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
337  This was the behavior of Asterisk 1.0 and earlier.
338  If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
339  Note that <literal>o(${CALLERID(all)})</literal> is similar to option <literal>o</literal> without the parameter.</para>
340  </option>
341  <option name="O">
342  <argument name="mode">
343  <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
344  the originator hanging up will cause the phone to ring back immediately.</para>
345  <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
346  flashes the trunk, it will ring their phone back.</para>
347  </argument>
348  <para>Enables <emphasis>operator services</emphasis> mode. This option only
349  works when bridging a DAHDI channel to another DAHDI channel
350  only. if specified on non-DAHDI interfaces, it will be ignored.
351  When the destination answers (presumably an operator services
352  station), the originator no longer has control of their line.
353  They may hang up, but the switch will not release their line
354  until the destination party (the operator) hangs up.</para>
355  </option>
356  <option name="p">
357  <para>This option enables screening mode. This is basically Privacy mode
358  without memory.</para>
359  </option>
360  <option name="P">
361  <argument name="x" />
362  <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
363  it is provided. The current extension is used if a database family/key is not specified.</para>
364  </option>
365  <option name="Q">
366  <argument name="cause" required="true"/>
367  <para>Specify the Q.850/Q.931 <replaceable>cause</replaceable> to send on
368  unanswered channels when another channel answers the call.
369  As with <literal>Hangup()</literal>, <replaceable>cause</replaceable>
370  can be a numeric cause code or a name such as
371  <literal>NO_ANSWER</literal>,
372  <literal>USER_BUSY</literal>,
373  <literal>CALL_REJECTED</literal> or
374  <literal>ANSWERED_ELSEWHERE</literal> (the default if Q isn't specified).
375  You can also specify <literal>0</literal> or <literal>NONE</literal>
376  to send no cause. See the <filename>causes.h</filename> file for the
377  full list of valid causes and names.
378  </para>
379  <para>NOTE: chan_sip does not support setting the cause on a CANCEL to anything
380  other than ANSWERED_ELSEWHERE.</para>
381  </option>
382  <option name="r">
383  <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
384  party until the called channel has answered.</para>
385  <argument name="tone" required="false">
386  <para>Indicate progress to calling party. Send audio 'tone' from the <filename>indications.conf</filename> tonezone currently in use.</para>
387  </argument>
388  </option>
389  <option name="R">
390  <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing.
391  Allow interruption of the ringback if early media is received on the channel.</para>
392  </option>
393  <option name="S">
394  <argument name="x" required="true" />
395  <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
396  answered the call.</para>
397  </option>
398  <option name="s">
399  <argument name="x" required="true" />
400  <para>Force the outgoing CallerID tag parameter to be set to the string <replaceable>x</replaceable>.</para>
401  <para>Works with the <literal>f</literal> option.</para>
402  </option>
403  <option name="t">
404  <para>Allow the called party to transfer the calling party by sending the
405  DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
406  transfers initiated by other methods.</para>
407  </option>
408  <option name="T">
409  <para>Allow the calling party to transfer the called party by sending the
410  DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
411  transfers initiated by other methods.</para>
412  </option>
413  <option name="U" argsep="^">
414  <argument name="x" required="true">
415  <para>Name of the subroutine context to execute via <literal>Gosub</literal>.
416  The subroutine execution starts in the named context at the s exten and priority 1.</para>
417  </argument>
418  <argument name="arg" multiple="true" required="false">
419  <para>Arguments for the <literal>Gosub</literal> routine</para>
420  </argument>
421  <para>Execute via <literal>Gosub</literal> the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
422  to the calling channel. Arguments can be specified to the <literal>Gosub</literal>
423  using <literal>^</literal> as a delimiter. The <literal>Gosub</literal> routine can set the variable
424  <variable>GOSUB_RESULT</variable> to specify the following actions after the <literal>Gosub</literal> returns.</para>
425  <variablelist>
426  <variable name="GOSUB_RESULT">
427  <value name="ABORT">
428  Hangup both legs of the call.
429  </value>
430  <value name="CONGESTION">
431  Behave as if line congestion was encountered.
432  </value>
433  <value name="BUSY">
434  Behave as if a busy signal was encountered.
435  </value>
436  <value name="CONTINUE">
437  Hangup the called party and allow the calling party
438  to continue dialplan execution at the next priority.
439  </value>
440  <value name="GOTO:[[&lt;context&gt;^]&lt;exten&gt;^]&lt;priority&gt;">
441  Transfer the call to the specified destination.
442  </value>
443  </variable>
444  </variablelist>
445  <para>NOTE: You cannot use any additional action post answer options in conjunction
446  with this option. Also, pbx services are run on the <emphasis>called</emphasis> channel,
447  so you will not be able to set timeouts via the <literal>TIMEOUT()</literal> function in this routine.</para>
448  </option>
449  <option name="u">
450  <argument name = "x" required="true">
451  <para>Force the outgoing callerid presentation indicator parameter to be set
452  to one of the values passed in <replaceable>x</replaceable>:
453  <literal>allowed_not_screened</literal>
454  <literal>allowed_passed_screen</literal>
455  <literal>allowed_failed_screen</literal>
456  <literal>allowed</literal>
457  <literal>prohib_not_screened</literal>
458  <literal>prohib_passed_screen</literal>
459  <literal>prohib_failed_screen</literal>
460  <literal>prohib</literal>
461  <literal>unavailable</literal></para>
462  </argument>
463  <para>Works with the <literal>f</literal> option.</para>
464  </option>
465  <option name="w">
466  <para>Allow the called party to enable recording of the call by sending
467  the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
468  </option>
469  <option name="W">
470  <para>Allow the calling party to enable recording of the call by sending
471  the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
472  </option>
473  <option name="x">
474  <para>Allow the called party to enable recording of the call by sending
475  the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
476  </option>
477  <option name="X">
478  <para>Allow the calling party to enable recording of the call by sending
479  the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
480  </option>
481  <option name="z">
482  <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
483  </option>
484  </optionlist>
485  </parameter>
486  <parameter name="URL">
487  <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
488  </parameter>
489  </syntax>
490  <description>
491  <para>This application will place calls to one or more specified channels. As soon
492  as one of the requested channels answers, the originating channel will be
493  answered, if it has not already been answered. These two channels will then
494  be active in a bridged call. All other channels that were requested will then
495  be hung up.</para>
496 
497  <para>Unless there is a timeout specified, the Dial application will wait
498  indefinitely until one of the called channels answers, the user hangs up, or
499  if all of the called channels are busy or unavailable. Dialplan execution will
500  continue if no requested channels can be called, or if the timeout expires.
501  This application will report normal termination if the originating channel
502  hangs up, or if the call is bridged and either of the parties in the bridge
503  ends the call.</para>
504  <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
505  application will be put into that group (as in <literal>Set(GROUP()=...</literal>).
506  If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
507  application will be put into that group (as in <literal>Set(GROUP()=...</literal>). Unlike <variable>OUTBOUND_GROUP</variable>,
508  however, the variable will be unset after use.</para>
509 
510  <example title="Dial with 30 second timeout">
511  same => n,Dial(PJSIP/alice,30)
512  </example>
513  <example title="Parallel dial with 45 second timeout">
514  same => n,Dial(PJSIP/alice&amp;PJIP/bob,45)
515  </example>
516  <example title="Dial with 'g' continuation option">
517  same => n,Dial(PJSIP/alice,,g)
518  same => n,Log(NOTICE, Alice call result: ${DIALSTATUS})
519  </example>
520  <example title="Dial with transfer/recording features for calling party">
521  same => n,Dial(PJSIP/alice,,TX)
522  </example>
523  <example title="Dial with call length limit">
524  same => n,Dial(PJSIP/alice,,L(60000:30000:10000))
525  </example>
526  <example title="Dial alice and bob and send NO_ANSWER to bob instead of ANSWERED_ELSEWHERE when alice answers">
527  same => n,Dial(PJSIP/alice&amp;PJSIP/bob,,Q(NO_ANSWER))
528  </example>
529  <example title="Dial with pre-dial subroutines">
530  [default]
531 
532  exten => callee_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
533  same => n,Log(NOTICE, I'm called on channel ${CHANNEL} prior to it starting the dial attempt)
534  same => n,Return()
535 
536  exten => called_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
537  same => n,Log(NOTICE, I'm called on outbound channel ${CHANNEL} prior to it being used to dial someone)
538  same => n,Return()
539 
540  exten => _X.,1,NoOp()
541  same => n,Dial(PJSIP/alice,,b(default^called_channel^1(my_gosub_arg1^my_gosub_arg2))B(default^callee_channel^1(my_gosub_arg1^my_gosub_arg2)))
542  same => n,Hangup()
543  </example>
544  <example title="Dial with post-answer subroutine executed on outbound channel">
545  [my_gosub_routine]
546 
547  exten => s,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
548  same => n,Playback(hello)
549  same => n,Return()
550 
551  [default]
552 
553  exten => _X.,1,NoOp()
554  same => n,Dial(PJSIP/alice,,U(my_gosub_routine^my_gosub_arg1^my_gosub_arg2))
555  same => n,Hangup()
556  </example>
557  <example title="Dial into ConfBridge using 'G' option">
558  same => n,Dial(PJSIP/alice,,G(jump_to_here))
559  same => n(jump_to_here),Goto(confbridge)
560  same => n,Goto(confbridge)
561  same => n(confbridge),ConfBridge(${EXTEN})
562  </example>
563  <para>This application sets the following channel variables:</para>
564  <variablelist>
565  <variable name="DIALEDTIME">
566  <para>This is the time from dialing a channel until when it is disconnected.</para>
567  </variable>
568  <variable name="DIALEDTIME_MS">
569  <para>This is the milliseconds version of the DIALEDTIME variable.</para>
570  </variable>
571  <variable name="ANSWEREDTIME">
572  <para>This is the amount of time for actual call.</para>
573  </variable>
574  <variable name="ANSWEREDTIME_MS">
575  <para>This is the milliseconds version of the ANSWEREDTIME variable.</para>
576  </variable>
577  <variable name="RINGTIME">
578  <para>This is the time from creating the channel to the first RINGING event received. Empty if there was no ring.</para>
579  </variable>
580  <variable name="RINGTIME_MS">
581  <para>This is the milliseconds version of the RINGTIME variable.</para>
582  </variable>
583  <variable name="PROGRESSTIME">
584  <para>This is the time from creating the channel to the first PROGRESS event received. Empty if there was no such event.</para>
585  </variable>
586  <variable name="PROGRESSTIME_MS">
587  <para>This is the milliseconds version of the PROGRESSTIME variable.</para>
588  </variable>
589  <variable name="DIALEDPEERNAME">
590  <para>The name of the outbound channel that answered the call.</para>
591  </variable>
592  <variable name="DIALEDPEERNUMBER">
593  <para>The number that was dialed for the answered outbound channel.</para>
594  </variable>
595  <variable name="FORWARDERNAME">
596  <para>If a call forward occurred, the name of the forwarded channel.</para>
597  </variable>
598  <variable name="DIALSTATUS">
599  <para>This is the status of the call</para>
600  <value name="CHANUNAVAIL" />
601  <value name="CONGESTION" />
602  <value name="NOANSWER" />
603  <value name="BUSY" />
604  <value name="ANSWER" />
605  <value name="CANCEL" />
606  <value name="DONTCALL">
607  For the Privacy and Screening Modes.
608  Will be set if the called party chooses to send the calling party to the 'Go Away' script.
609  </value>
610  <value name="TORTURE">
611  For the Privacy and Screening Modes.
612  Will be set if the called party chooses to send the calling party to the 'torture' script.
613  </value>
614  <value name="INVALIDARGS" />
615  </variable>
616  </variablelist>
617  </description>
618  <see-also>
619  <ref type="application">RetryDial</ref>
620  <ref type="application">SendDTMF</ref>
621  <ref type="application">Gosub</ref>
622  <ref type="application">Macro</ref>
623  </see-also>
624  </application>
625  <application name="RetryDial" language="en_US">
626  <synopsis>
627  Place a call, retrying on failure allowing an optional exit extension.
628  </synopsis>
629  <syntax>
630  <parameter name="announce" required="true">
631  <para>Filename of sound that will be played when no channel can be reached</para>
632  </parameter>
633  <parameter name="sleep" required="true">
634  <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
635  </parameter>
636  <parameter name="retries" required="true">
637  <para>Number of retries</para>
638  <para>When this is reached flow will continue at the next priority in the dialplan</para>
639  </parameter>
640  <parameter name="dialargs" required="true">
641  <para>Same format as arguments provided to the Dial application</para>
642  </parameter>
643  </syntax>
644  <description>
645  <para>This application will attempt to place a call using the normal Dial application.
646  If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
647  Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
648  After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
649  If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
650  While waiting to retry a call, a 1 digit extension may be dialed. If that
651  extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
652  one, The call will jump to that extension immediately.
653  The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
654  to the Dial application.</para>
655  </description>
656  <see-also>
657  <ref type="application">Dial</ref>
658  </see-also>
659  </application>
660  ***/
661 
662 static const char app[] = "Dial";
663 static const char rapp[] = "RetryDial";
664 
665 enum {
666  OPT_ANNOUNCE = (1 << 0),
667  OPT_RESETCDR = (1 << 1),
668  OPT_DTMF_EXIT = (1 << 2),
669  OPT_SENDDTMF = (1 << 3),
670  OPT_FORCECLID = (1 << 4),
671  OPT_GO_ON = (1 << 5),
672  OPT_CALLEE_HANGUP = (1 << 6),
673  OPT_CALLER_HANGUP = (1 << 7),
674  OPT_ORIGINAL_CLID = (1 << 8),
675  OPT_DURATION_LIMIT = (1 << 9),
676  OPT_MUSICBACK = (1 << 10),
677  OPT_CALLEE_MACRO = (1 << 11),
678  OPT_SCREEN_NOINTRO = (1 << 12),
681  OPT_SCREENING = (1 << 15),
682  OPT_PRIVACY = (1 << 16),
683  OPT_RINGBACK = (1 << 17),
684  OPT_DURATION_STOP = (1 << 18),
685  OPT_CALLEE_TRANSFER = (1 << 19),
686  OPT_CALLER_TRANSFER = (1 << 20),
687  OPT_CALLEE_MONITOR = (1 << 21),
688  OPT_CALLER_MONITOR = (1 << 22),
689  OPT_GOTO = (1 << 23),
690  OPT_OPERMODE = (1 << 24),
691  OPT_CALLEE_PARK = (1 << 25),
692  OPT_CALLER_PARK = (1 << 26),
694  OPT_CALLEE_GOSUB = (1 << 28),
697 };
698 
699 /* flags are now 64 bits, so keep it up! */
700 #define DIAL_STILLGOING (1LLU << 31)
701 #define DIAL_NOFORWARDHTML (1LLU << 32)
702 #define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
703 #define OPT_CANCEL_ELSEWHERE (1LLU << 34)
704 #define OPT_PEER_H (1LLU << 35)
705 #define OPT_CALLEE_GO_ON (1LLU << 36)
706 #define OPT_CANCEL_TIMEOUT (1LLU << 37)
707 #define OPT_FORCE_CID_TAG (1LLU << 38)
708 #define OPT_FORCE_CID_PRES (1LLU << 39)
709 #define OPT_CALLER_ANSWER (1LLU << 40)
710 #define OPT_PREDIAL_CALLEE (1LLU << 41)
711 #define OPT_PREDIAL_CALLER (1LLU << 42)
712 #define OPT_RING_WITH_EARLY_MEDIA (1LLU << 43)
713 #define OPT_HANGUPCAUSE (1LLU << 44)
714 
715 enum {
736  /* note: this entry _MUST_ be the last one in the enum */
738 };
739 
784 
785 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
786  OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
787  OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
788  OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
789  !ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \
790  ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer)))
791 
792 /*
793  * The list of active channels
794  */
795 struct chanlist {
797  struct ast_channel *chan;
798  /*! Channel interface dialing string (is tech/number). (Stored in stuff[]) */
799  const char *interface;
800  /*! Channel technology name. (Stored in stuff[]) */
801  const char *tech;
802  /*! Channel device addressing. (Stored in stuff[]) */
803  const char *number;
804  /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
806  uint64_t flags;
807  /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
809  /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
810  unsigned int pending_connected_update:1;
812  /*! The interface, tech, and number strings are stuffed here. */
813  char stuff[0];
814 };
815 
817 
818 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode);
819 
820 static void chanlist_free(struct chanlist *outgoing)
821 {
824  ast_free(outgoing->orig_chan_name);
825  ast_free(outgoing);
826 }
827 
828 static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
829 {
830  /* Hang up a tree of stuff */
831  struct chanlist *outgoing;
832 
833  while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
834  /* Hangup any existing lines we have open */
835  if (outgoing->chan && (outgoing->chan != exception)) {
836  if (hangupcause >= 0) {
837  /* This is for the channel drivers */
838  ast_channel_hangupcause_set(outgoing->chan, hangupcause);
839  }
840  ast_hangup(outgoing->chan);
841  }
842  chanlist_free(outgoing);
843  }
844 }
845 
846 #define AST_MAX_WATCHERS 256
847 
848 /*
849  * argument to handle_cause() and other functions.
850  */
851 struct cause_args {
852  struct ast_channel *chan;
853  int busy;
855  int nochan;
856 };
857 
858 static void handle_cause(int cause, struct cause_args *num)
859 {
860  switch(cause) {
861  case AST_CAUSE_BUSY:
862  num->busy++;
863  break;
865  num->congestion++;
866  break;
869  num->nochan++;
870  break;
871  case AST_CAUSE_NO_ANSWER:
873  break;
874  default:
875  num->nochan++;
876  break;
877  }
878 }
879 
880 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
881 {
882  char rexten[2] = { exten, '\0' };
883 
884  if (context) {
885  if (!ast_goto_if_exists(chan, context, rexten, pri))
886  return 1;
887  } else {
888  if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
889  return 1;
890  else if (!ast_strlen_zero(ast_channel_macrocontext(chan))) {
891  if (!ast_goto_if_exists(chan, ast_channel_macrocontext(chan), rexten, pri))
892  return 1;
893  }
894  }
895  return 0;
896 }
897 
898 /* do not call with chan lock held */
899 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
900 {
901  const char *context;
902  const char *exten;
903 
904  ast_channel_lock(chan);
907  ast_channel_unlock(chan);
908 
909  return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
910 }
911 
912 /*!
913  * helper function for wait_for_answer()
914  *
915  * \param o Outgoing call channel list.
916  * \param num Incoming call channel cause accumulation
917  * \param peerflags Dial option flags
918  * \param single TRUE if there is only one outgoing call.
919  * \param caller_entertained TRUE if the caller is being entertained by MOH or ringback.
920  * \param to Remaining call timeout time.
921  * \param forced_clid OPT_FORCECLID caller id to send
922  * \param stored_clid Caller id representing the called party if needed
923  *
924  * XXX this code is highly suspicious, as it essentially overwrites
925  * the outgoing channel without properly deleting it.
926  *
927  * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
928  */
929 static void do_forward(struct chanlist *o, struct cause_args *num,
930  struct ast_flags64 *peerflags, int single, int caller_entertained, int *to,
931  struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
932 {
933  char tmpchan[256];
934  char forwarder[AST_CHANNEL_NAME];
935  struct ast_channel *original = o->chan;
936  struct ast_channel *c = o->chan; /* the winner */
937  struct ast_channel *in = num->chan; /* the input channel */
938  char *stuff;
939  char *tech;
940  int cause;
941  struct ast_party_caller caller;
942 
943  ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
944  ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
945  if ((stuff = strchr(tmpchan, '/'))) {
946  *stuff++ = '\0';
947  tech = tmpchan;
948  } else {
949  const char *forward_context;
950  ast_channel_lock(c);
951  forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
952  if (ast_strlen_zero(forward_context)) {
953  forward_context = NULL;
954  }
955  snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
957  stuff = tmpchan;
958  tech = "Local";
959  }
960  if (!strcasecmp(tech, "Local")) {
961  /*
962  * Drop the connected line update block for local channels since
963  * this is going to run dialplan and the user can change his
964  * mind about what connected line information he wants to send.
965  */
967  }
968 
969  /* Before processing channel, go ahead and check for forwarding */
970  ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
971  /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
972  if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
973  ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
974  ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
975  ast_channel_call_forward(original));
976  c = o->chan = NULL;
977  cause = AST_CAUSE_BUSY;
978  } else {
979  struct ast_stream_topology *topology;
980 
981  ast_channel_lock(in);
983  ast_channel_unlock(in);
984 
985  /* Setup parameters */
986  c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
987 
988  ast_stream_topology_free(topology);
989 
990  if (c) {
991  if (single && !caller_entertained) {
993  }
994  ast_channel_lock_both(in, o->chan);
997  pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
999  ast_channel_unlock(in);
1001  /* When a call is forwarded, we don't want to track new interfaces
1002  * dialed for CC purposes. Setting the done flag will ensure that
1003  * any Dial operations that happen later won't record CC interfaces.
1004  */
1005  ast_ignore_cc(o->chan);
1006  ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",
1007  ast_channel_name(o->chan));
1008  } else
1010  "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
1011  tech, stuff, cause);
1012  }
1013  if (!c) {
1014  ast_channel_publish_dial(in, original, stuff, "BUSY");
1016  handle_cause(cause, num);
1017  ast_hangup(original);
1018  } else {
1019  ast_channel_lock_both(c, original);
1021  ast_channel_redirecting(original));
1022  ast_channel_unlock(c);
1023  ast_channel_unlock(original);
1024 
1025  ast_channel_lock_both(c, in);
1026 
1027  if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
1029  }
1030 
1031  if (!ast_channel_redirecting(c)->from.number.valid
1032  || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
1033  /*
1034  * The call was not previously redirected so it is
1035  * now redirected from this number.
1036  */
1042  }
1043 
1045 
1046  /* Determine CallerID to store in outgoing channel. */
1048  if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1049  caller.id = *stored_clid;
1050  ast_channel_set_caller_event(c, &caller, NULL);
1052  } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
1053  ast_channel_caller(c)->id.number.str, NULL))) {
1054  /*
1055  * The new channel has no preset CallerID number by the channel
1056  * driver. Use the dialplan extension and hint name.
1057  */
1058  caller.id = *stored_clid;
1059  ast_channel_set_caller_event(c, &caller, NULL);
1061  } else {
1063  }
1064 
1065  /* Determine CallerID for outgoing channel to send. */
1066  if (ast_test_flag64(o, OPT_FORCECLID)) {
1067  struct ast_party_connected_line connected;
1068 
1069  ast_party_connected_line_init(&connected);
1070  connected.id = *forced_clid;
1072  } else {
1074  }
1075 
1077 
1078  ast_channel_appl_set(c, "AppDial");
1079  ast_channel_data_set(c, "(Outgoing Line)");
1081 
1082  ast_channel_unlock(in);
1083  if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1084  struct ast_party_redirecting redirecting;
1085 
1086  /*
1087  * Redirecting updates to the caller make sense only on single
1088  * calls.
1089  *
1090  * We must unlock c before calling
1091  * ast_channel_redirecting_macro, because we put c into
1092  * autoservice there. That is pretty much a guaranteed
1093  * deadlock. This is why the handling of c's lock may seem a
1094  * bit unusual here.
1095  */
1096  ast_party_redirecting_init(&redirecting);
1098  ast_channel_unlock(c);
1099  if (ast_channel_redirecting_sub(c, in, &redirecting, 0) &&
1100  ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
1101  ast_channel_update_redirecting(in, &redirecting, NULL);
1102  }
1103  ast_party_redirecting_free(&redirecting);
1104  } else {
1105  ast_channel_unlock(c);
1106  }
1107 
1108  if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1109  *to = -1;
1110  }
1111 
1112  if (ast_call(c, stuff, 0)) {
1113  ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1114  tech, stuff);
1115  ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1117  ast_hangup(original);
1118  ast_hangup(c);
1119  c = o->chan = NULL;
1120  num->nochan++;
1121  } else {
1122  ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1123  ast_channel_call_forward(original));
1124 
1125  ast_channel_publish_dial(in, c, stuff, NULL);
1126 
1127  /* Hangup the original channel now, in case we needed it */
1128  ast_hangup(original);
1129  }
1130  if (single && !caller_entertained) {
1131  ast_indicate(in, -1);
1132  }
1133  }
1134 }
1135 
1136 /* argument used for some functions. */
1140  char privcid[256];
1141  char privintro[1024];
1142  char status[256];
1143 };
1144 
1145 static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
1146 {
1147  struct chanlist *outgoing;
1148  AST_LIST_TRAVERSE(out_chans, outgoing, node) {
1149  if (!outgoing->chan || outgoing->chan == exception) {
1150  continue;
1151  }
1152  ast_channel_publish_dial(in, outgoing->chan, NULL, status);
1153  }
1154 }
1155 
1156 /*!
1157  * \internal
1158  * \brief Update connected line on chan from peer.
1159  * \since 13.6.0
1160  *
1161  * \param chan Channel to get connected line updated.
1162  * \param peer Channel providing connected line information.
1163  * \param is_caller Non-zero if chan is the calling channel.
1164  *
1165  * \return Nothing
1166  */
1167 static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
1168 {
1169  struct ast_party_connected_line connected_caller;
1170 
1171  ast_party_connected_line_init(&connected_caller);
1172 
1173  ast_channel_lock(peer);
1174  ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(peer));
1175  ast_channel_unlock(peer);
1177  if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)
1178  && ast_channel_connected_line_macro(peer, chan, &connected_caller, is_caller, 0)) {
1179  ast_channel_update_connected_line(chan, &connected_caller, NULL);
1180  }
1181  ast_party_connected_line_free(&connected_caller);
1182 }
1183 
1184 /*!
1185  * \internal
1186  * \pre chan is locked
1187  */
1188 static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
1189 {
1190  char buf[32];
1191  char full_var_name[128];
1192 
1193  snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000);
1194  pbx_builtin_setvar_helper(chan, var_base, buf);
1195 
1196  snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base);
1197  snprintf(buf, sizeof(buf), "%" PRId64, duration);
1198  pbx_builtin_setvar_helper(chan, full_var_name, buf);
1199 }
1200 
1202  struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags,
1203  char *opt_args[],
1204  struct privacy_args *pa,
1205  const struct cause_args *num_in, int *result, char *dtmf_progress,
1206  const int ignore_cc,
1207  struct ast_party_id *forced_clid, struct ast_party_id *stored_clid,
1208  struct ast_bridge_config *config)
1209 {
1210  struct cause_args num = *num_in;
1211  int prestart = num.busy + num.congestion + num.nochan;
1212  int orig = *to;
1213  struct ast_channel *peer = NULL;
1214  struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
1215  /* single is set if only one destination is enabled */
1216  int single = outgoing && !AST_LIST_NEXT(outgoing, node);
1217  int caller_entertained = outgoing
1218  && ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
1219  struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
1220  int cc_recall_core_id;
1221  int is_cc_recall;
1222  int cc_frame_received = 0;
1223  int num_ringing = 0;
1224  int sent_ring = 0;
1225  int sent_progress = 0;
1226  struct timeval start = ast_tvnow();
1227  SCOPE_ENTER(3, "%s\n", ast_channel_name(in));
1228 
1229  if (single) {
1230  /* Turn off hold music, etc */
1231  if (!caller_entertained) {
1233  /* If we are calling a single channel, and not providing ringback or music, */
1234  /* then, make them compatible for in-band tone purpose */
1235  if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
1236  /* If these channels can not be made compatible,
1237  * there is no point in continuing. The bridge
1238  * will just fail if it gets that far.
1239  */
1240  *to = -1;
1241  strcpy(pa->status, "CONGESTION");
1242  ast_channel_publish_dial(in, outgoing->chan, NULL, pa->status);
1243  SCOPE_EXIT_RTN_VALUE(NULL, "%s: can't be made compat with %s\n",
1244  ast_channel_name(in), ast_channel_name(outgoing->chan));
1245  }
1246  }
1247 
1249  && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
1250  update_connected_line_from_peer(in, outgoing->chan, 1);
1251  }
1252  }
1253 
1254  is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1255 
1256  while ((*to = ast_remaining_ms(start, orig)) && !peer) {
1257  struct chanlist *o;
1258  int pos = 0; /* how many channels do we handle */
1259  int numlines = prestart;
1260  struct ast_channel *winner;
1261  struct ast_channel *watchers[AST_MAX_WATCHERS];
1262 
1263  watchers[pos++] = in;
1264  AST_LIST_TRAVERSE(out_chans, o, node) {
1265  /* Keep track of important channels */
1266  if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1267  watchers[pos++] = o->chan;
1268  numlines++;
1269  }
1270  if (pos == 1) { /* only the input channel is available */
1271  if (numlines == (num.busy + num.congestion + num.nochan)) {
1272  ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1273  if (num.busy)
1274  strcpy(pa->status, "BUSY");
1275  else if (num.congestion)
1276  strcpy(pa->status, "CONGESTION");
1277  else if (num.nochan)
1278  strcpy(pa->status, "CHANUNAVAIL");
1279  } else {
1280  ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1281  }
1282  *to = 0;
1283  if (is_cc_recall) {
1284  ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1285  }
1286  SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outging channels available\n", ast_channel_name(in));
1287  }
1288  winner = ast_waitfor_n(watchers, pos, to);
1289  AST_LIST_TRAVERSE(out_chans, o, node) {
1290  struct ast_frame *f;
1291  struct ast_channel *c = o->chan;
1292 
1293  if (c == NULL)
1294  continue;
1296  if (!peer) {
1297  ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1298  if (o->orig_chan_name
1299  && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1300  /*
1301  * The channel name changed so we must generate COLP update.
1302  * Likely because a call pickup channel masqueraded in.
1303  */
1305  } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1306  if (o->pending_connected_update) {
1307  if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
1308  ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1310  }
1311  } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1313  }
1314  }
1315  if (o->aoc_s_rate_list) {
1316  size_t encoded_size;
1317  struct ast_aoc_encoded *encoded;
1318  if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1319  ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1320  ast_aoc_destroy_encoded(encoded);
1321  }
1322  }
1323  peer = c;
1324  publish_dial_end_event(in, out_chans, peer, "CANCEL");
1325  ast_copy_flags64(peerflags, o,
1332  ast_channel_dialcontext_set(c, "");
1333  ast_channel_exten_set(c, "");
1334  }
1335  continue;
1336  }
1337  if (c != winner)
1338  continue;
1339  /* here, o->chan == c == winner */
1341  pa->sentringing = 0;
1342  if (!ignore_cc && (f = ast_read(c))) {
1344  /* This channel is forwarding the call, and is capable of CC, so
1345  * be sure to add the new device interface to the list
1346  */
1348  }
1349  ast_frfree(f);
1350  }
1351 
1352  if (o->pending_connected_update) {
1353  /*
1354  * Re-seed the chanlist's connected line information with
1355  * previously acquired connected line info from the incoming
1356  * channel. The previously acquired connected line info could
1357  * have been set through the CONNECTED_LINE dialplan function.
1358  */
1359  o->pending_connected_update = 0;
1360  ast_channel_lock(in);
1362  ast_channel_unlock(in);
1363  }
1364 
1365  do_forward(o, &num, peerflags, single, caller_entertained, &orig,
1366  forced_clid, stored_clid);
1367 
1368  if (o->chan) {
1371  if (single
1375  }
1376  }
1377  continue;
1378  }
1379  f = ast_read(winner);
1380  if (!f) {
1383  ast_hangup(c);
1384  c = o->chan = NULL;
1387  continue;
1388  }
1389  switch (f->frametype) {
1390  case AST_FRAME_CONTROL:
1391  switch (f->subclass.integer) {
1392  case AST_CONTROL_ANSWER:
1393  /* This is our guy if someone answered. */
1394  if (!peer) {
1395  ast_trace(-1, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1396  ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1397  if (o->orig_chan_name
1398  && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1399  /*
1400  * The channel name changed so we must generate COLP update.
1401  * Likely because a call pickup channel masqueraded in.
1402  */
1404  } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1405  if (o->pending_connected_update) {
1406  if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
1407  ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1409  }
1410  } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1412  }
1413  }
1414  if (o->aoc_s_rate_list) {
1415  size_t encoded_size;
1416  struct ast_aoc_encoded *encoded;
1417  if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1418  ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1419  ast_aoc_destroy_encoded(encoded);
1420  }
1421  }
1422  peer = c;
1423  /* Answer can optionally include a topology */
1424  if (f->subclass.topology) {
1425  /*
1426  * We need to bump the refcount on the topology to prevent it
1427  * from being cleaned up when the frame is cleaned up.
1428  */
1429  config->answer_topology = ao2_bump(f->subclass.topology);
1430  ast_trace(-1, "%s Found topology in frame: %p %p %s\n",
1431  ast_channel_name(peer), f, config->answer_topology,
1432  ast_str_tmp(256, ast_stream_topology_to_str(config->answer_topology, &STR_TMP)));
1433  }
1434 
1435  /* Inform everyone else that they've been canceled.
1436  * The dial end event for the peer will be sent out after
1437  * other Dial options have been handled.
1438  */
1439  publish_dial_end_event(in, out_chans, peer, "CANCEL");
1440  ast_copy_flags64(peerflags, o,
1447  ast_channel_dialcontext_set(c, "");
1448  ast_channel_exten_set(c, "");
1449  if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
1450  /* Setup early bridge if appropriate */
1451  ast_channel_early_bridge(in, peer);
1452  }
1453  }
1454  /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1457  break;
1458  case AST_CONTROL_BUSY:
1459  ast_verb(3, "%s is busy\n", ast_channel_name(c));
1461  ast_channel_publish_dial(in, c, NULL, "BUSY");
1462  ast_hangup(c);
1463  c = o->chan = NULL;
1466  break;
1468  ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1470  ast_channel_publish_dial(in, c, NULL, "CONGESTION");
1471  ast_hangup(c);
1472  c = o->chan = NULL;
1475  break;
1476  case AST_CONTROL_RINGING:
1477  /* This is a tricky area to get right when using a native
1478  * CC agent. The reason is that we do the best we can to send only a
1479  * single ringing notification to the caller.
1480  *
1481  * Call completion complicates the logic used here. CCNR is typically
1482  * offered during a ringing message. Let's say that party A calls
1483  * parties B, C, and D. B and C do not support CC requests, but D
1484  * does. If we were to receive a ringing notification from B before
1485  * the others, then we would end up sending a ringing message to
1486  * A with no CCNR offer present.
1487  *
1488  * The approach that we have taken is that if we receive a ringing
1489  * response from a party and no CCNR offer is present, we need to
1490  * wait. Specifically, we need to wait until either a) a called party
1491  * offers CCNR in its ringing response or b) all called parties have
1492  * responded in some way to our call and none offers CCNR.
1493  *
1494  * The drawback to this is that if one of the parties has a delayed
1495  * response or, god forbid, one just plain doesn't respond to our
1496  * outgoing call, then this will result in a significant delay between
1497  * when the caller places the call and hears ringback.
1498  *
1499  * Note also that if CC is disabled for this call, then it is perfectly
1500  * fine for ringing frames to get sent through.
1501  */
1502  ++num_ringing;
1503  if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1504  ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1505  /* Setup early media if appropriate */
1506  if (single && !caller_entertained
1507  && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1508  ast_channel_early_bridge(in, c);
1509  }
1510  if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
1512  pa->sentringing++;
1513  }
1514  if (!sent_ring) {
1515  struct timeval now, then;
1516  int64_t diff;
1517 
1518  now = ast_tvnow();
1519 
1520  ast_channel_lock(in);
1522 
1523  then = ast_channel_creationtime(c);
1524  diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1525  set_duration_var(in, "RINGTIME", diff);
1526 
1528  ast_channel_unlock(in);
1529  sent_ring = 1;
1530  }
1531  }
1532  ast_channel_publish_dial(in, c, NULL, "RINGING");
1533  break;
1534  case AST_CONTROL_PROGRESS:
1535  ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1536  /* Setup early media if appropriate */
1537  if (single && !caller_entertained
1538  && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1539  ast_channel_early_bridge(in, c);
1540  }
1541  if (!ast_test_flag64(outgoing, OPT_RINGBACK)) {
1542  if (single || (!single && !pa->sentringing)) {
1544  }
1545  }
1546  if (!sent_progress) {
1547  struct timeval now, then;
1548  int64_t diff;
1549 
1550  now = ast_tvnow();
1551 
1552  ast_channel_lock(in);
1554 
1555  then = ast_channel_creationtime(c);
1556  diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1557  set_duration_var(in, "PROGRESSTIME", diff);
1558 
1560  ast_channel_unlock(in);
1561  sent_progress = 1;
1562 
1563  if (!ast_strlen_zero(dtmf_progress)) {
1564  ast_verb(3,
1565  "Sending DTMF '%s' to the called party as result of "
1566  "receiving a PROGRESS message.\n",
1567  dtmf_progress);
1568  ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1569  }
1570  }
1571  ast_channel_publish_dial(in, c, NULL, "PROGRESS");
1572  break;
1573  case AST_CONTROL_VIDUPDATE:
1574  case AST_CONTROL_SRCUPDATE:
1575  case AST_CONTROL_SRCCHANGE:
1576  if (!single || caller_entertained) {
1577  break;
1578  }
1579  ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1581  ast_indicate(in, f->subclass.integer);
1582  break;
1585  ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1586  break;
1587  }
1588  if (!single) {
1589  struct ast_party_connected_line connected;
1590 
1591  ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
1594  ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
1595  ast_party_connected_line_set(&o->connected, &connected, NULL);
1596  ast_party_connected_line_free(&connected);
1597  o->pending_connected_update = 1;
1598  break;
1599  }
1600  if (ast_channel_connected_line_sub(c, in, f, 1) &&
1601  ast_channel_connected_line_macro(c, in, f, 1, 1)) {
1603  }
1604  break;
1605  case AST_CONTROL_AOC:
1606  {
1607  struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1608  if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1610  o->aoc_s_rate_list = decoded;
1611  } else {
1612  ast_aoc_destroy_decoded(decoded);
1613  }
1614  }
1615  break;
1617  if (!single) {
1618  /*
1619  * Redirecting updates to the caller make sense only on single
1620  * calls.
1621  */
1622  break;
1623  }
1625  ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1626  break;
1627  }
1628  ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
1630  if (ast_channel_redirecting_sub(c, in, f, 1) &&
1631  ast_channel_redirecting_macro(c, in, f, 1, 1)) {
1633  }
1634  pa->sentringing = 0;
1635  break;
1637  ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1638  if (single && !caller_entertained
1639  && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1640  ast_channel_early_bridge(in, c);
1641  }
1642  if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1644  ast_channel_publish_dial(in, c, NULL, "PROCEEDING");
1645  break;
1646  case AST_CONTROL_HOLD:
1647  /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1648  ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1650  break;
1651  case AST_CONTROL_UNHOLD:
1652  /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1653  ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1655  break;
1656  case AST_CONTROL_OFFHOOK:
1657  case AST_CONTROL_FLASH:
1658  /* Ignore going off hook and flash */
1659  break;
1660  case AST_CONTROL_CC:
1661  if (!ignore_cc) {
1663  cc_frame_received = 1;
1664  }
1665  break;
1668  break;
1669  case -1:
1670  if (single && !caller_entertained) {
1671  ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1672  ast_indicate(in, -1);
1673  pa->sentringing = 0;
1674  }
1675  break;
1676  default:
1677  ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1678  break;
1679  }
1680  break;
1681  case AST_FRAME_VIDEO:
1682  case AST_FRAME_VOICE:
1683  case AST_FRAME_IMAGE:
1684  if (caller_entertained) {
1685  break;
1686  }
1687  /* Fall through */
1688  case AST_FRAME_TEXT:
1689  if (single && ast_write(in, f)) {
1690  ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
1691  f->frametype);
1692  }
1693  break;
1694  case AST_FRAME_HTML:
1695  if (single && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)
1696  && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1697  ast_log(LOG_WARNING, "Unable to send URL\n");
1698  }
1699  break;
1700  default:
1701  break;
1702  }
1703  ast_frfree(f);
1704  } /* end for */
1705  if (winner == in) {
1706  struct ast_frame *f = ast_read(in);
1707 #if 0
1708  if (f && (f->frametype != AST_FRAME_VOICE))
1709  printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1710  else if (!f || (f->frametype != AST_FRAME_VOICE))
1711  printf("Hangup received on %s\n", in->name);
1712 #endif
1713  if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1714  /* Got hung up */
1715  *to = -1;
1716  strcpy(pa->status, "CANCEL");
1717  publish_dial_end_event(in, out_chans, NULL, pa->status);
1718  if (f) {
1719  if (f->data.uint32) {
1721  }
1722  ast_frfree(f);
1723  }
1724  if (is_cc_recall) {
1725  ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1726  }
1727  SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller hung up\n", ast_channel_name(in));
1728  }
1729 
1730  /* now f is guaranteed non-NULL */
1731  if (f->frametype == AST_FRAME_DTMF) {
1732  if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1733  const char *context;
1734  ast_channel_lock(in);
1735  context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1736  if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1737  ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1738  *to = 0;
1739  *result = f->subclass.integer;
1740  strcpy(pa->status, "CANCEL");
1741  publish_dial_end_event(in, out_chans, NULL, pa->status);
1742  ast_frfree(f);
1743  ast_channel_unlock(in);
1744  if (is_cc_recall) {
1745  ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1746  }
1747  SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller pressed %c to end call\n",
1749  }
1750  ast_channel_unlock(in);
1751  }
1752 
1753  if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1754  detect_disconnect(in, f->subclass.integer, &featurecode)) {
1755  ast_verb(3, "User requested call disconnect.\n");
1756  *to = 0;
1757  strcpy(pa->status, "CANCEL");
1758  publish_dial_end_event(in, out_chans, NULL, pa->status);
1759  ast_frfree(f);
1760  if (is_cc_recall) {
1761  ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1762  }
1763  SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller requested disconnect\n",
1764  ast_channel_name(in));
1765  }
1766  }
1767 
1768  /* Send the frame from the in channel to all outgoing channels. */
1769  AST_LIST_TRAVERSE(out_chans, o, node) {
1770  if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1771  /* This outgoing channel has died so don't send the frame to it. */
1772  continue;
1773  }
1774  switch (f->frametype) {
1775  case AST_FRAME_HTML:
1776  /* Forward HTML stuff */
1778  && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1779  ast_log(LOG_WARNING, "Unable to send URL\n");
1780  }
1781  break;
1782  case AST_FRAME_VIDEO:
1783  case AST_FRAME_VOICE:
1784  case AST_FRAME_IMAGE:
1785  if (!single || caller_entertained) {
1786  /*
1787  * We are calling multiple parties or caller is being
1788  * entertained and has thus not been made compatible.
1789  * No need to check any other called parties.
1790  */
1791  goto skip_frame;
1792  }
1793  /* Fall through */
1794  case AST_FRAME_TEXT:
1795  case AST_FRAME_DTMF_BEGIN:
1796  case AST_FRAME_DTMF_END:
1797  if (ast_write(o->chan, f)) {
1798  ast_log(LOG_WARNING, "Unable to forward frametype: %u\n",
1799  f->frametype);
1800  }
1801  break;
1802  case AST_FRAME_CONTROL:
1803  switch (f->subclass.integer) {
1804  case AST_CONTROL_HOLD:
1805  ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1807  break;
1808  case AST_CONTROL_UNHOLD:
1809  ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1811  break;
1812  case AST_CONTROL_VIDUPDATE:
1813  case AST_CONTROL_SRCUPDATE:
1814  case AST_CONTROL_SRCCHANGE:
1815  if (!single || caller_entertained) {
1816  /*
1817  * We are calling multiple parties or caller is being
1818  * entertained and has thus not been made compatible.
1819  * No need to check any other called parties.
1820  */
1821  goto skip_frame;
1822  }
1823  ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1826  break;
1829  ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
1830  break;
1831  }
1832  if (ast_channel_connected_line_sub(in, o->chan, f, 1) &&
1833  ast_channel_connected_line_macro(in, o->chan, f, 0, 1)) {
1835  }
1836  break;
1839  ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
1840  break;
1841  }
1842  if (ast_channel_redirecting_sub(in, o->chan, f, 1) &&
1843  ast_channel_redirecting_macro(in, o->chan, f, 0, 1)) {
1845  }
1846  break;
1847  default:
1848  /* We are not going to do anything with this frame. */
1849  goto skip_frame;
1850  }
1851  break;
1852  default:
1853  /* We are not going to do anything with this frame. */
1854  goto skip_frame;
1855  }
1856  }
1857 skip_frame:;
1858  ast_frfree(f);
1859  }
1860  }
1861 
1862  if (!*to || ast_check_hangup(in)) {
1863  ast_verb(3, "Nobody picked up in %d ms\n", orig);
1864  publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
1865  }
1866 
1867  if (is_cc_recall) {
1868  ast_cc_completed(in, "Recall completed!");
1869  }
1870  SCOPE_EXIT_RTN_VALUE(peer, "%s: %s%s\n", ast_channel_name(in),
1871  peer ? "Answered by " : "No answer", peer ? ast_channel_name(peer) : "");
1872 }
1873 
1874 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
1875 {
1876  char disconnect_code[AST_FEATURE_MAX_LEN];
1877  int res;
1878 
1879  ast_str_append(featurecode, 1, "%c", code);
1880 
1881  res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
1882  if (res) {
1883  ast_str_reset(*featurecode);
1884  return 0;
1885  }
1886 
1887  if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
1888  /* Could be a partial match, anyway */
1889  if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
1890  ast_str_reset(*featurecode);
1891  }
1892  return 0;
1893  }
1894 
1895  if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
1896  ast_str_reset(*featurecode);
1897  return 0;
1898  }
1899 
1900  return 1;
1901 }
1902 
1903 /* returns true if there is a valid privacy reply */
1904 static int valid_priv_reply(struct ast_flags64 *opts, int res)
1905 {
1906  if (res < '1')
1907  return 0;
1908  if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1909  return 1;
1910  if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1911  return 1;
1912  return 0;
1913 }
1914 
1915 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1916  struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1917 {
1918 
1919  int res2;
1920  int loopcount = 0;
1921 
1922  /* Get the user's intro, store it in priv-callerintros/$CID,
1923  unless it is already there-- this should be done before the
1924  call is actually dialed */
1925 
1926  /* all ring indications and moh for the caller has been halted as soon as the
1927  target extension was picked up. We are going to have to kill some
1928  time and make the caller believe the peer hasn't picked up yet */
1929 
1930  if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
1931  char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
1932  ast_indicate(chan, -1);
1933  ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
1934  ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1935  ast_channel_musicclass_set(chan, original_moh);
1938  pa->sentringing++;
1939  }
1940 
1941  /* Start autoservice on the other chan ?? */
1942  res2 = ast_autoservice_start(chan);
1943  /* Now Stream the File */
1944  for (loopcount = 0; loopcount < 3; loopcount++) {
1945  if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1946  break;
1947  if (!res2) /* on timeout, play the message again */
1948  res2 = ast_play_and_wait(peer, "priv-callpending");
1949  if (!valid_priv_reply(opts, res2))
1950  res2 = 0;
1951  /* priv-callpending script:
1952  "I have a caller waiting, who introduces themselves as:"
1953  */
1954  if (!res2)
1955  res2 = ast_play_and_wait(peer, pa->privintro);
1956  if (!valid_priv_reply(opts, res2))
1957  res2 = 0;
1958  /* now get input from the called party, as to their choice */
1959  if (!res2) {
1960  /* XXX can we have both, or they are mutually exclusive ? */
1961  if (ast_test_flag64(opts, OPT_PRIVACY))
1962  res2 = ast_play_and_wait(peer, "priv-callee-options");
1963  if (ast_test_flag64(opts, OPT_SCREENING))
1964  res2 = ast_play_and_wait(peer, "screen-callee-options");
1965  }
1966 
1967  /*! \page DialPrivacy Dial Privacy scripts
1968  * \par priv-callee-options script:
1969  * \li Dial 1 if you wish this caller to reach you directly in the future,
1970  * and immediately connect to their incoming call.
1971  * \li Dial 2 if you wish to send this caller to voicemail now and forevermore.
1972  * \li Dial 3 to send this caller to the torture menus, now and forevermore.
1973  * \li Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
1974  * \li Dial 5 to allow this caller to come straight thru to you in the future,
1975  * but right now, just this once, send them to voicemail.
1976  *
1977  * \par screen-callee-options script:
1978  * \li Dial 1 if you wish to immediately connect to the incoming call
1979  * \li Dial 2 if you wish to send this caller to voicemail.
1980  * \li Dial 3 to send this caller to the torture menus.
1981  * \li Dial 4 to send this caller to a simple "go away" menu.
1982  */
1983  if (valid_priv_reply(opts, res2))
1984  break;
1985  /* invalid option */
1986  res2 = ast_play_and_wait(peer, "vm-sorry");
1987  }
1988 
1989  if (ast_test_flag64(opts, OPT_MUSICBACK)) {
1990  ast_moh_stop(chan);
1992  ast_indicate(chan, -1);
1993  pa->sentringing = 0;
1994  }
1995  ast_autoservice_stop(chan);
1996  if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
1997  /* map keypresses to various things, the index is res2 - '1' */
1998  static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
2000  int i = res2 - '1';
2001  ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
2002  opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
2003  ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
2004  }
2005  switch (res2) {
2006  case '1':
2007  break;
2008  case '2':
2009  ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2010  break;
2011  case '3':
2012  ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2013  break;
2014  case '4':
2015  ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2016  break;
2017  case '5':
2018  if (ast_test_flag64(opts, OPT_PRIVACY)) {
2019  ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2020  break;
2021  }
2022  /* if not privacy, then 5 is the same as "default" case */
2023  default: /* bad input or -1 if failure to start autoservice */
2024  /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
2025  /* well, there seems basically two choices. Just patch the caller thru immediately,
2026  or,... put 'em thru to voicemail. */
2027  /* since the callee may have hung up, let's do the voicemail thing, no database decision */
2028  ast_verb(3, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
2029  /* XXX should we set status to DENY ? */
2030  /* XXX what about the privacy flags ? */
2031  break;
2032  }
2033 
2034  if (res2 == '1') { /* the only case where we actually connect */
2035  /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
2036  just clog things up, and it's not useful information, not being tied to a CID */
2037  if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
2039  if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2040  ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2041  else
2042  ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2043  }
2044  return 0; /* the good exit path */
2045  } else {
2046  return -1;
2047  }
2048 }
2049 
2050 /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
2051 static int setup_privacy_args(struct privacy_args *pa,
2052  struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
2053 {
2054  char callerid[60];
2055  int res;
2056  char *l;
2057 
2058  if (ast_channel_caller(chan)->id.number.valid
2059  && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2060  l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2062  if (ast_test_flag64(opts, OPT_PRIVACY) ) {
2063  ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
2064  pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
2065  } else {
2066  ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
2068  }
2069  } else {
2070  char *tnam, *tn2;
2071 
2072  tnam = ast_strdupa(ast_channel_name(chan));
2073  /* clean the channel name so slashes don't try to end up in disk file name */
2074  for (tn2 = tnam; *tn2; tn2++) {
2075  if (*tn2 == '/') /* any other chars to be afraid of? */
2076  *tn2 = '=';
2077  }
2078  ast_verb(3, "Privacy-- callerid is empty\n");
2079 
2080  snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
2081  l = callerid;
2083  }
2084 
2085  ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
2086 
2087  if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
2088  /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
2089  ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
2091  } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
2092  ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
2093  }
2094 
2095  if (pa->privdb_val == AST_PRIVACY_DENY) {
2096  ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
2097  ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2098  return 0;
2099  } else if (pa->privdb_val == AST_PRIVACY_KILL) {
2100  ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2101  return 0; /* Is this right? */
2102  } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
2103  ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2104  return 0; /* is this right??? */
2105  } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
2106  /* Get the user's intro, store it in priv-callerintros/$CID,
2107  unless it is already there-- this should be done before the
2108  call is actually dialed */
2109 
2110  /* make sure the priv-callerintros dir actually exists */
2111  snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
2112  if ((res = ast_mkdir(pa->privintro, 0755))) {
2113  ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
2114  return -1;
2115  }
2116 
2117  snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
2118  if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
2119  /* the DELUX version of this code would allow this caller the
2120  option to hear and retape their previously recorded intro.
2121  */
2122  } else {
2123  int duration; /* for feedback from play_and_wait */
2124  /* the file doesn't exist yet. Let the caller submit his
2125  vocal intro for posterity */
2126  /* priv-recordintro script:
2127 
2128  "At the tone, please say your name:"
2129 
2130  */
2132  ast_answer(chan);
2133  res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
2134  /* don't think we'll need a lock removed, we took care of
2135  conflicts by naming the pa.privintro file */
2136  if (res == -1) {
2137  /* Delete the file regardless since they hung up during recording */
2139  if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2140  ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2141  else
2142  ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2143  return -1;
2144  }
2145  if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
2146  ast_waitstream(chan, "");
2147  }
2148  }
2149  return 1; /* success */
2150 }
2151 
2152 static void end_bridge_callback(void *data)
2153 {
2154  struct ast_channel *chan = data;
2155 
2156  ast_channel_lock(chan);
2158  set_duration_var(chan, "ANSWEREDTIME", ast_channel_get_up_time_ms(chan));
2159  set_duration_var(chan, "DIALEDTIME", ast_channel_get_duration_ms(chan));
2161  ast_channel_unlock(chan);
2162 }
2163 
2164 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
2165  bconfig->end_bridge_callback_data = originator;
2166 }
2167 
2168 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
2169 {
2170  struct ast_tone_zone_sound *ts = NULL;
2171  int res;
2172  const char *str = data;
2173 
2174  if (ast_strlen_zero(str)) {
2175  ast_debug(1,"Nothing to play\n");
2176  return -1;
2177  }
2178 
2179  ts = ast_get_indication_tone(ast_channel_zone(chan), str);
2180 
2181  if (ts && ts->data[0]) {
2182  res = ast_playtones_start(chan, 0, ts->data, 0);
2183  } else {
2184  res = -1;
2185  }
2186 
2187  if (ts) {
2188  ts = ast_tone_zone_sound_unref(ts);
2189  }
2190 
2191  if (res) {
2192  ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
2193  }
2194 
2195  return res;
2196 }
2197 
2198 /*!
2199  * \internal
2200  * \brief Setup the after bridge goto location on the peer.
2201  * \since 12.0.0
2202  *
2203  * \param chan Calling channel for bridge.
2204  * \param peer Peer channel for bridge.
2205  * \param opts Dialing option flags.
2206  * \param opt_args Dialing option argument strings.
2207  *
2208  * \return Nothing
2209  */
2210 static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
2211 {
2212  const char *context;
2213  const char *extension;
2214  int priority;
2215 
2216  if (ast_test_flag64(opts, OPT_PEER_H)) {
2217  ast_channel_lock(chan);
2218  context = ast_strdupa(ast_channel_context(chan));
2219  ast_channel_unlock(chan);
2220  ast_bridge_set_after_h(peer, context);
2221  } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
2222  ast_channel_lock(chan);
2223  context = ast_strdupa(ast_channel_context(chan));
2224  extension = ast_strdupa(ast_channel_exten(chan));
2225  priority = ast_channel_priority(chan);
2226  ast_channel_unlock(chan);
2227  ast_bridge_set_after_go_on(peer, context, extension, priority,
2228  opt_args[OPT_ARG_CALLEE_GO_ON]);
2229  }
2230 }
2231 
2232 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
2233 {
2234  int res = -1; /* default: error */
2235  char *rest, *cur; /* scan the list of destinations */
2236  struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2237  struct chanlist *outgoing;
2238  struct chanlist *tmp;
2239  struct ast_channel *peer = NULL;
2240  int to; /* timeout */
2241  struct cause_args num = { chan, 0, 0, 0 };
2242  int cause;
2243 
2244  struct ast_bridge_config config = { { 0, } };
2245  struct timeval calldurationlimit = { 0, };
2246  char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
2247  struct privacy_args pa = {
2248  .sentringing = 0,
2249  .privdb_val = 0,
2250  .status = "INVALIDARGS",
2251  };
2252  int sentringing = 0, moh = 0;
2253  const char *outbound_group = NULL;
2254  int result = 0;
2255  char *parse;
2256  int opermode = 0;
2257  int delprivintro = 0;
2259  AST_APP_ARG(peers);
2262  AST_APP_ARG(url);
2263  );
2264  struct ast_flags64 opts = { 0, };
2265  char *opt_args[OPT_ARG_ARRAY_SIZE];
2266  int fulldial = 0, num_dialed = 0;
2267  int ignore_cc = 0;
2268  char device_name[AST_CHANNEL_NAME];
2269  char forced_clid_name[AST_MAX_EXTENSION];
2270  char stored_clid_name[AST_MAX_EXTENSION];
2271  int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2272  /*!
2273  * \brief Forced CallerID party information to send.
2274  * \note This will not have any malloced strings so do not free it.
2275  */
2276  struct ast_party_id forced_clid;
2277  /*!
2278  * \brief Stored CallerID information if needed.
2279  *
2280  * \note If OPT_ORIGINAL_CLID set then this is the o option
2281  * CallerID. Otherwise it is the dialplan extension and hint
2282  * name.
2283  *
2284  * \note This will not have any malloced strings so do not free it.
2285  */
2286  struct ast_party_id stored_clid;
2287  /*!
2288  * \brief CallerID party information to store.
2289  * \note This will not have any malloced strings so do not free it.
2290  */
2291  struct ast_party_caller caller;
2292  int max_forwards;
2293  SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data);
2294 
2295  /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2296  ast_channel_lock(chan);
2298  pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2299  pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2300  pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2301  pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2302  pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");
2303  pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2304  pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");
2305  pbx_builtin_setvar_helper(chan, "RINGTIME", "");
2306  pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");
2307  pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");
2308  pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");
2310  max_forwards = ast_max_forwards_get(chan);
2311  ast_channel_unlock(chan);
2312 
2313  if (max_forwards <= 0) {
2314  ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2315  ast_channel_name(chan));
2316  pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2317  SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan));
2318  }
2319 
2320  if (ast_check_hangup_locked(chan)) {
2321  /*
2322  * Caller hung up before we could dial. If dial is executed
2323  * within an AGI then the AGI has likely eaten all queued
2324  * frames before executing the dial in DeadAGI mode. With
2325  * the caller hung up and no pending frames from the caller's
2326  * read queue, dial would not know that the call has hung up
2327  * until a called channel answers. It is rather annoying to
2328  * whoever just answered the non-existent call.
2329  *
2330  * Dial should not continue execution in DeadAGI mode, hangup
2331  * handlers, or the h exten.
2332  */
2333  ast_verb(3, "Caller hung up before dial.\n");
2334  pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
2335  SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan));
2336  }
2337 
2338  parse = ast_strdupa(data ?: "");
2339 
2340  AST_STANDARD_APP_ARGS(args, parse);
2341 
2342  if (!ast_strlen_zero(args.options) &&
2343  ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2344  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2345  goto done;
2346  }
2347 
2348  if (ast_cc_call_init(chan, &ignore_cc)) {
2349  goto done;
2350  }
2351 
2353  delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2354 
2355  if (delprivintro < 0 || delprivintro > 1) {
2356  ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2357  delprivintro = 0;
2358  }
2359  }
2360 
2361  if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2362  opt_args[OPT_ARG_RINGBACK] = NULL;
2363  }
2364 
2365  if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2366  opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2367  ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2368  }
2369 
2371  calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2372  if (!calldurationlimit.tv_sec) {
2373  ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);
2374  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2375  goto done;
2376  }
2377  ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2378  }
2379 
2380  if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2381  dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
2382  dtmfcalled = strsep(&dtmf_progress, ":");
2383  dtmfcalling = strsep(&dtmf_progress, ":");
2384  }
2385 
2387  if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2388  goto done;
2389  }
2390 
2391  /* Setup the forced CallerID information to send if used. */
2392  ast_party_id_init(&forced_clid);
2393  force_forwards_only = 0;
2394  if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2395  if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2396  ast_channel_lock(chan);
2397  forced_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
2398  ast_channel_unlock(chan);
2399  forced_clid_name[0] = '\0';
2400  forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2401  sizeof(forced_clid_name), chan);
2402  force_forwards_only = 1;
2403  } else {
2404  /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2405  ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2406  &forced_clid.number.str);
2407  }
2408  if (!ast_strlen_zero(forced_clid.name.str)) {
2409  forced_clid.name.valid = 1;
2410  }
2411  if (!ast_strlen_zero(forced_clid.number.str)) {
2412  forced_clid.number.valid = 1;
2413  }
2414  }
2416  && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2417  forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2418  }
2421  && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2422  int pres;
2423 
2424  pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
2425  if (0 <= pres) {
2426  forced_clid.number.presentation = pres;
2427  }
2428  }
2429 
2430  /* Setup the stored CallerID information if needed. */
2431  ast_party_id_init(&stored_clid);
2432  if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2433  if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2434  ast_channel_lock(chan);
2435  ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2436  if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2437  stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2438  }
2439  if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2440  stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2441  }
2442  if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2443  stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2444  }
2445  if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2446  stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2447  }
2448  ast_channel_unlock(chan);
2449  } else {
2450  /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2451  ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2452  &stored_clid.number.str);
2453  if (!ast_strlen_zero(stored_clid.name.str)) {
2454  stored_clid.name.valid = 1;
2455  }
2456  if (!ast_strlen_zero(stored_clid.number.str)) {
2457  stored_clid.number.valid = 1;
2458  }
2459  }
2460  } else {
2461  /*
2462  * In case the new channel has no preset CallerID number by the
2463  * channel driver, setup the dialplan extension and hint name.
2464  */
2465  stored_clid_name[0] = '\0';
2466  stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2467  sizeof(stored_clid_name), chan);
2468  if (ast_strlen_zero(stored_clid.name.str)) {
2469  stored_clid.name.str = NULL;
2470  } else {
2471  stored_clid.name.valid = 1;
2472  }
2473  ast_channel_lock(chan);
2474  stored_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
2475  stored_clid.number.valid = 1;
2476  ast_channel_unlock(chan);
2477  }
2478 
2479  if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2480  ast_cdr_reset(ast_channel_name(chan), 0);
2481  }
2482  if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
2483  opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan));
2484 
2485  if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
2486  res = setup_privacy_args(&pa, &opts, opt_args, chan);
2487  if (res <= 0)
2488  goto out;
2489  res = -1; /* reset default */
2490  }
2491 
2492  if (continue_exec)
2493  *continue_exec = 0;
2494 
2495  /* If a channel group has been specified, get it for use when we create peer channels */
2496 
2497  ast_channel_lock(chan);
2498  if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2499  outbound_group = ast_strdupa(outbound_group);
2500  pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2501  } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2502  outbound_group = ast_strdupa(outbound_group);
2503  }
2504  ast_channel_unlock(chan);
2505 
2506  /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2510 
2511  /* PREDIAL: Run gosub on the caller's channel */
2513  && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2514  ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
2515  ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2516  }
2517 
2518  /* loop through the list of dial destinations */
2519  rest = args.peers;
2520  while ((cur = strsep(&rest, "&"))) {
2521  struct ast_channel *tc; /* channel for this destination */
2522  char *number;
2523  char *tech;
2524  size_t tech_len;
2525  size_t number_len;
2526  struct ast_stream_topology *topology;
2527 
2528  cur = ast_strip(cur);
2529  if (ast_strlen_zero(cur)) {
2530  /* No tech/resource in this position. */
2531  continue;
2532  }
2533 
2534  /* Get a technology/resource pair */
2535  number = cur;
2536  tech = strsep(&number, "/");
2537 
2538  num_dialed++;
2539  if (ast_strlen_zero(number)) {
2540  ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2541  goto out;
2542  }
2543 
2544  tech_len = strlen(tech) + 1;
2545  number_len = strlen(number) + 1;
2546  tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2547  if (!tmp) {
2548  goto out;
2549  }
2550 
2551  /* Save tech, number, and interface. */
2552  cur = tmp->stuff;
2553  strcpy(cur, tech);
2554  tmp->tech = cur;
2555  cur += tech_len;
2556  strcpy(cur, tech);
2557  cur[tech_len - 1] = '/';
2558  tmp->interface = cur;
2559  cur += tech_len;
2560  strcpy(cur, number);
2561  tmp->number = cur;
2562 
2563  if (opts.flags) {
2564  /* Set per outgoing call leg options. */
2565  ast_copy_flags64(tmp, &opts,
2575  }
2576 
2577  /* Request the peer */
2578 
2579  ast_channel_lock(chan);
2580  /*
2581  * Seed the chanlist's connected line information with previously
2582  * acquired connected line info from the incoming channel. The
2583  * previously acquired connected line info could have been set
2584  * through the CONNECTED_LINE dialplan function.
2585  */
2587 
2589 
2590  ast_channel_unlock(chan);
2591 
2592  tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
2593 
2594  ast_stream_topology_free(topology);
2595 
2596  if (!tc) {
2597  /* If we can't, just go on to the next call */
2598  ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
2599  tmp->tech, cause, ast_cause2str(cause));
2600  handle_cause(cause, &num);
2601  if (!rest) {
2602  /* we are on the last destination */
2603  ast_channel_hangupcause_set(chan, cause);
2604  }
2605  if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2606  if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2608  }
2609  }
2610  chanlist_free(tmp);
2611  continue;
2612  }
2613 
2614  ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2615  if (!ignore_cc) {
2616  ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2617  }
2618 
2619  ast_channel_lock_both(tc, chan);
2621 
2622  pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2623 
2624  /* Setup outgoing SDP to match incoming one */
2625  if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2626  /* We are on the only destination. */
2628  }
2629 
2630  /* Inherit specially named variables from parent channel */
2634 
2635  ast_channel_appl_set(tc, "AppDial");
2636  ast_channel_data_set(tc, "(Outgoing Line)");
2637 
2638  memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2639 
2640  /* Determine CallerID to store in outgoing channel. */
2642  if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2643  caller.id = stored_clid;
2644  ast_channel_set_caller_event(tc, &caller, NULL);
2646  } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2647  ast_channel_caller(tc)->id.number.str, NULL))) {
2648  /*
2649  * The new channel has no preset CallerID number by the channel
2650  * driver. Use the dialplan extension and hint name.
2651  */
2652  caller.id = stored_clid;
2653  if (!caller.id.name.valid
2654  && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2655  ast_channel_connected(chan)->id.name.str, NULL))) {
2656  /*
2657  * No hint name available. We have a connected name supplied by
2658  * the dialplan we can use instead.
2659  */
2660  caller.id.name.valid = 1;
2661  caller.id.name = ast_channel_connected(chan)->id.name;
2662  }
2663  ast_channel_set_caller_event(tc, &caller, NULL);
2665  } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2666  NULL))) {
2667  /* The new channel has no preset CallerID name by the channel driver. */
2668  if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2669  ast_channel_connected(chan)->id.name.str, NULL))) {
2670  /*
2671  * We have a connected name supplied by the dialplan we can
2672  * use instead.
2673  */
2674  caller.id.name.valid = 1;
2675  caller.id.name = ast_channel_connected(chan)->id.name;
2676  ast_channel_set_caller_event(tc, &caller, NULL);
2677  }
2678  }
2679 
2680  /* Determine CallerID for outgoing channel to send. */
2681  if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2682  struct ast_party_connected_line connected;
2683 
2685  connected.id = forced_clid;
2686  ast_channel_set_connected_line(tc, &connected, NULL);
2687  } else {
2689  }
2690 
2692 
2694 
2697  ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2698  }
2699 
2700  /* Pass ADSI CPE and transfer capability */
2703 
2704  /* If we have an outbound group, set this peer channel to it */
2705  if (outbound_group)
2706  ast_app_group_set_channel(tc, outbound_group);
2707  /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2710 
2711  /* Check if we're forced by configuration */
2714 
2715 
2716  /* Inherit context and extension */
2717  ast_channel_dialcontext_set(tc, ast_strlen_zero(ast_channel_macrocontext(chan)) ? ast_channel_context(chan) : ast_channel_macrocontext(chan));
2720  else
2722 
2724 
2725  /* Save the original channel name to detect call pickup masquerading in. */
2727 
2728  ast_channel_unlock(tc);
2729  ast_channel_unlock(chan);
2730 
2731  /* Put channel in the list of outgoing thingies. */
2732  tmp->chan = tc;
2733  AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
2734  }
2735 
2736  if (AST_LIST_EMPTY(&out_chans)) {
2737  ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");
2738  if (continue_exec) {
2739  /* There is no point in having RetryDial try again */
2740  *continue_exec = 1;
2741  }
2742  strcpy(pa.status, "CHANUNAVAIL");
2743  res = 0;
2744  goto out;
2745  }
2746 
2747  /*
2748  * PREDIAL: Run gosub on all of the callee channels
2749  *
2750  * We run the callee predial before ast_call() in case the user
2751  * wishes to do something on the newly created channels before
2752  * the channel does anything important.
2753  *
2754  * Inside the target gosub we will be able to do something with
2755  * the newly created channel name ie: now the calling channel
2756  * can know what channel will be used to call the destination
2757  * ex: now we will know that SIP/abc-123 is calling SIP/def-124
2758  */
2761  && !AST_LIST_EMPTY(&out_chans)) {
2762  const char *predial_callee;
2763 
2764  ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
2765  predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
2766  if (predial_callee) {
2767  ast_autoservice_start(chan);
2768  AST_LIST_TRAVERSE(&out_chans, tmp, node) {
2769  ast_pre_call(tmp->chan, predial_callee);
2770  }
2771  ast_autoservice_stop(chan);
2772  ast_free((char *) predial_callee);
2773  }
2774  }
2775 
2776  /* Start all outgoing calls */
2777  AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
2778  res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
2779  ast_channel_lock(chan);
2780 
2781  /* check the results of ast_call */
2782  if (res) {
2783  /* Again, keep going even if there's an error */
2784  ast_debug(1, "ast call on peer returned %d\n", res);
2785  ast_verb(3, "Couldn't call %s\n", tmp->interface);
2786  if (ast_channel_hangupcause(tmp->chan)) {
2788  }
2789  ast_channel_unlock(chan);
2790  ast_cc_call_failed(chan, tmp->chan, tmp->interface);
2791  ast_hangup(tmp->chan);
2792  tmp->chan = NULL;
2794  chanlist_free(tmp);
2795  continue;
2796  }
2797 
2798  ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
2799  ast_channel_unlock(chan);
2800 
2801  ast_verb(3, "Called %s\n", tmp->interface);
2803 
2804  /* If this line is up, don't try anybody else */
2805  if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
2806  break;
2807  }
2808  }
2810 
2811  if (ast_strlen_zero(args.timeout)) {
2812  to = -1;
2813  } else {
2814  to = atoi(args.timeout);
2815  if (to > 0)
2816  to *= 1000;
2817  else {
2818  ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2819  to = -1;
2820  }
2821  }
2822 
2823  outgoing = AST_LIST_FIRST(&out_chans);
2824  if (!outgoing) {
2825  strcpy(pa.status, "CHANUNAVAIL");
2826  if (fulldial == num_dialed) {
2827  res = -1;
2828  goto out;
2829  }
2830  } else {
2831  /* Our status will at least be NOANSWER */
2832  strcpy(pa.status, "NOANSWER");
2833  if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
2834  moh = 1;
2835  if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2836  char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2837  ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2838  ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2839  ast_channel_musicclass_set(chan, original_moh);
2840  } else {
2841  ast_moh_start(chan, NULL, NULL);
2842  }
2844  } else if (ast_test_flag64(outgoing, OPT_RINGBACK) || ast_test_flag64(outgoing, OPT_RING_WITH_EARLY_MEDIA)) {
2845  if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2846  if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2848  sentringing++;
2849  } else {
2851  }
2852  } else {
2854  sentringing++;
2855  }
2856  }
2857  }
2858 
2859  peer = wait_for_answer(chan, &out_chans, &to, peerflags, opt_args, &pa, &num, &result,
2860  dtmf_progress, ignore_cc, &forced_clid, &stored_clid, &config);
2861 
2862  if (!peer) {
2863  if (result) {
2864  res = result;
2865  } else if (to) { /* Musta gotten hung up */
2866  res = -1;
2867  } else { /* Nobody answered, next please? */
2868  res = 0;
2869  }
2870  } else {
2871  const char *number;
2872  const char *name;
2873  int dial_end_raised = 0;
2874  int cause = -1;
2875 
2876  if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
2877  ast_answer(chan);
2878  }
2879 
2880  /* Ah ha! Someone answered within the desired timeframe. Of course after this
2881  we will always return with -1 so that it is hung up properly after the
2882  conversation. */
2883 
2884  if (ast_test_flag64(&opts, OPT_HANGUPCAUSE)
2885  && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
2886  cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
2887  if (cause <= 0) {
2888  if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
2889  cause = 0;
2890  } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
2891  || cause < 0) {
2892  ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
2893  opt_args[OPT_ARG_HANGUPCAUSE]);
2894  cause = -1;
2895  }
2896  }
2897  }
2898  hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
2899 
2900  /* If appropriate, log that we have a destination channel and set the answer time */
2901 
2902  ast_channel_lock(peer);
2903  name = ast_strdupa(ast_channel_name(peer));
2904 
2905  number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
2906  if (ast_strlen_zero(number)) {
2907  number = NULL;
2908  } else {
2909  number = ast_strdupa(number);
2910  }
2911  ast_channel_unlock(peer);
2912 
2913  ast_channel_lock(chan);
2915 
2916  strcpy(pa.status, "ANSWER");
2917  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2918 
2919  pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
2920  pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
2921 
2923  ast_channel_unlock(chan);
2924 
2925  if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
2926  ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
2927  ast_channel_sendurl( peer, args.url );
2928  }
2930  if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
2931  ast_channel_publish_dial(chan, peer, NULL, pa.status);
2932  /* hang up on the callee -- he didn't want to talk anyway! */
2934  res = 0;
2935  goto out;
2936  }
2937  }
2938  if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
2939  res = 0;
2940  } else {
2941  int digit = 0;
2942  struct ast_channel *chans[2];
2943  struct ast_channel *active_chan;
2944 
2945  chans[0] = chan;
2946  chans[1] = peer;
2947 
2948  /* we need to stream the announcement to the called party when the OPT_ARG_ANNOUNCE (-A) is setted */
2949 
2950  /* stream the file */
2951  res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
2952  if (res) {
2953  res = 0;
2954  ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
2955  }
2956 
2958  while (ast_channel_stream(peer)) {
2959  int ms;
2960 
2961  ms = ast_sched_wait(ast_channel_sched(peer));
2962 
2963  if (ms < 0 && !ast_channel_timingfunc(peer)) {
2964  ast_stopstream(peer);
2965  break;
2966  }
2967  if (ms < 0)
2968  ms = 1000;
2969 
2970  active_chan = ast_waitfor_n(chans, 2, &ms);
2971  if (active_chan) {
2972  struct ast_channel *other_chan;
2973  struct ast_frame *fr = ast_read(active_chan);
2974 
2975  if (!fr) {
2977  res = -1;
2978  goto done;
2979  }
2980  switch (fr->frametype) {
2981  case AST_FRAME_DTMF_END:
2982  digit = fr->subclass.integer;
2983  if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
2984  ast_stopstream(peer);
2985  res = ast_senddigit(chan, digit, 0);
2986  }
2987  break;
2988  case AST_FRAME_CONTROL:
2989  switch (fr->subclass.integer) {
2990  case AST_CONTROL_HANGUP:
2991  ast_frfree(fr);
2993  res = -1;
2994  goto done;
2996  /* Pass COLP update to the other channel. */
2997  if (active_chan == chan) {
2998  other_chan = peer;
2999  } else {
3000  other_chan = chan;
3001  }
3002  if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)
3003  && ast_channel_connected_line_macro(active_chan,
3004  other_chan, fr, other_chan == chan, 1)) {
3005  ast_indicate_data(other_chan, fr->subclass.integer,
3006  fr->data.ptr, fr->datalen);
3007  }
3008  break;
3009  default:
3010  break;
3011  }
3012  break;
3013  default:
3014  /* Ignore all others */
3015  break;
3016  }
3017  ast_frfree(fr);
3018  }
3020  }
3022  }
3023 
3024  if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
3025  /* chan and peer are going into the PBX; as such neither are considered
3026  * outgoing channels any longer */
3028 
3029  ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
3030  ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
3031  /* peer goes to the same context and extension as chan, so just copy info from chan*/
3032  ast_channel_lock(peer);
3039  ast_channel_unlock(peer);
3040  if (ast_pbx_start(peer)) {
3042  }
3043  if (continue_exec)
3044  *continue_exec = 1;
3045  res = 0;
3046  ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3047  goto done;
3048  }
3049 
3051  const char *macro_result_peer;
3052  int macro_res;
3053 
3054  /* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
3055  ast_channel_lock_both(chan, peer);
3058  ast_channel_unlock(peer);
3059  ast_channel_unlock(chan);
3060  ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
3061  macro_res = ast_app_exec_macro(chan, peer, opt_args[OPT_ARG_CALLEE_MACRO]);
3062 
3063  ast_channel_lock(peer);
3064 
3065  if (!macro_res && (macro_result_peer = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
3066  char *macro_result = ast_strdupa(macro_result_peer);
3067  char *macro_transfer_dest;
3068 
3069  ast_channel_unlock(peer);
3070 
3071  if (!strcasecmp(macro_result, "BUSY")) {
3072  ast_copy_string(pa.status, macro_result, sizeof(pa.status));
3073  ast_set_flag64(peerflags, OPT_GO_ON);
3074  macro_res = -1;
3075  } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
3076  ast_copy_string(pa.status, macro_result, sizeof(pa.status));
3077  ast_set_flag64(peerflags, OPT_GO_ON);
3078  macro_res = -1;
3079  } else if (!strcasecmp(macro_result, "CONTINUE")) {
3080  /* hangup peer and keep chan alive assuming the macro has changed
3081  the context / exten / priority or perhaps
3082  the next priority in the current exten is desired.
3083  */
3084  ast_set_flag64(peerflags, OPT_GO_ON);
3085  macro_res = -1;
3086  } else if (!strcasecmp(macro_result, "ABORT")) {
3087  /* Hangup both ends unless the caller has the g flag */
3088  macro_res = -1;
3089  } else if (!strncasecmp(macro_result, "GOTO:", 5)) {
3090  macro_transfer_dest = macro_result + 5;
3091  macro_res = -1;
3092  /* perform a transfer to a new extension */
3093  if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
3094  ast_replace_subargument_delimiter(macro_transfer_dest);
3095  }
3096  if (!ast_parseable_goto(chan, macro_transfer_dest)) {
3097  ast_set_flag64(peerflags, OPT_GO_ON);
3098  }
3099  }
3100  if (macro_res && !dial_end_raised) {
3101  ast_channel_publish_dial(chan, peer, NULL, macro_result);
3102  dial_end_raised = 1;
3103  }
3104  } else {
3105  ast_channel_unlock(peer);
3106  }
3107  res = macro_res;
3108  }
3109 
3111  const char *gosub_result_peer;
3112  char *gosub_argstart;
3113  char *gosub_args = NULL;
3114  int gosub_res = -1;
3115 
3116  ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
3117  gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
3118  if (gosub_argstart) {
3119  const char *what_is_s = "s";
3120  *gosub_argstart = 0;
3121  if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
3122  ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
3123  what_is_s = "~~s~~";
3124  }
3125  if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
3126  gosub_args = NULL;
3127  }
3128  *gosub_argstart = ',';
3129  } else {
3130  const char *what_is_s = "s";
3131  if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
3132  ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
3133  what_is_s = "~~s~~";
3134  }
3135  if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
3136  gosub_args = NULL;
3137  }
3138  }
3139  if (gosub_args) {
3140  gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
3141  ast_free(gosub_args);
3142  } else {
3143  ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
3144  }
3145 
3146  ast_channel_lock_both(chan, peer);
3147 
3148  if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
3149  char *gosub_transfer_dest;
3150  char *gosub_result = ast_strdupa(gosub_result_peer);
3151  const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
3152 
3153  /* Inherit return value from the peer, so it can be used in the master */
3154  if (gosub_retval) {
3155  pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
3156  }
3157 
3158  ast_channel_unlock(peer);
3159  ast_channel_unlock(chan);
3160 
3161  if (!strcasecmp(gosub_result, "BUSY")) {
3162  ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3163  ast_set_flag64(peerflags, OPT_GO_ON);
3164  gosub_res = -1;
3165  } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
3166  ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3167  ast_set_flag64(peerflags, OPT_GO_ON);
3168  gosub_res = -1;
3169  } else if (!strcasecmp(gosub_result, "CONTINUE")) {
3170  /* Hangup peer and continue with the next extension priority. */
3171  ast_set_flag64(peerflags, OPT_GO_ON);
3172  gosub_res = -1;
3173  } else if (!strcasecmp(gosub_result, "ABORT")) {
3174  /* Hangup both ends unless the caller has the g flag */
3175  gosub_res = -1;
3176  } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
3177  gosub_transfer_dest = gosub_result + 5;
3178  gosub_res = -1;
3179  /* perform a transfer to a new extension */
3180  if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
3181  ast_replace_subargument_delimiter(gosub_transfer_dest);
3182  }
3183  if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
3184  ast_set_flag64(peerflags, OPT_GO_ON);
3185  }
3186  }
3187  if (gosub_res) {
3188  res = gosub_res;
3189  if (!dial_end_raised) {
3190  ast_channel_publish_dial(chan, peer, NULL, gosub_result);
3191  dial_end_raised = 1;
3192  }
3193  }
3194  } else {
3195  ast_channel_unlock(peer);
3196  ast_channel_unlock(chan);
3197  }
3198  }
3199 
3200  if (!res) {
3201 
3202  /* None of the Dial options changed our status; inform
3203  * everyone that this channel answered
3204  */
3205  if (!dial_end_raised) {
3206  ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3207  dial_end_raised = 1;
3208  }
3209 
3210  if (!ast_tvzero(calldurationlimit)) {
3211  struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
3212  ast_channel_lock(peer);
3213  ast_channel_whentohangup_set(peer, &whentohangup);
3214  ast_channel_unlock(peer);
3215  }
3216  if (!ast_strlen_zero(dtmfcalled)) {
3217  ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
3218  res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
3219  }
3220  if (!ast_strlen_zero(dtmfcalling)) {
3221  ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
3222  res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
3223  }
3224  }
3225 
3226  if (res) { /* some error */
3227  if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
3229  }
3230  setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3231  if (ast_bridge_setup_after_goto(peer)
3232  || ast_pbx_start(peer)) {
3234  }
3235  res = -1;
3236  } else {
3237  if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
3239  if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
3241  if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
3243  if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
3245  if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
3247  if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
3249  if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
3251  if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
3253  if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
3255  if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
3257 
3259  config.end_bridge_callback_data = chan;
3261 
3262  if (moh) {
3263  moh = 0;
3264  ast_moh_stop(chan);
3265  } else if (sentringing) {
3266  sentringing = 0;
3267  ast_indicate(chan, -1);
3268  }
3269  /* Be sure no generators are left on it and reset the visible indication */
3272  /* Make sure channels are compatible */
3273  res = ast_channel_make_compatible(chan, peer);
3274  if (res < 0) {
3275  ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", ast_channel_name(chan), ast_channel_name(peer));
3277  res = -1;
3278  goto done;
3279  }
3280  if (opermode) {
3281  struct oprmode oprmode;
3282 
3283  oprmode.peer = peer;
3284  oprmode.mode = opermode;
3285 
3286  ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
3287  }
3288  setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3289 
3290  res = ast_bridge_call(chan, peer, &config);
3291  }
3292  }
3293 out:
3294  if (moh) {
3295  moh = 0;
3296  ast_moh_stop(chan);
3297  } else if (sentringing) {
3298  sentringing = 0;
3299  ast_indicate(chan, -1);
3300  }
3301 
3302  if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3304  if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3305  ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
3306  } else {
3307  ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
3308  }
3309  }
3310 
3312  /* forward 'answered elsewhere' if we received it */
3313  hanguptree(&out_chans, NULL,
3317  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3318  ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
3319 
3320  if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
3321  if (!ast_tvzero(calldurationlimit))
3322  memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
3323  res = 0;
3324  }
3325 
3326 done:
3327  if (config.answer_topology) {
3328  ast_trace(2, "%s Cleaning up topology: %p %s\n",
3329  peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology,
3330  ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP)));
3331 
3332  /*
3333  * At this point, the channel driver that answered should have bumped the
3334  * topology refcount for itself. Here we're cleaning up the reference we added
3335  * in wait_for_answer().
3336  */
3338  }
3339  if (config.warning_sound) {
3340  ast_free((char *)config.warning_sound);
3341  }
3342  if (config.end_sound) {
3343  ast_free((char *)config.end_sound);
3344  }
3345  if (config.start_sound) {
3346  ast_free((char *)config.start_sound);
3347  }
3348  ast_ignore_cc(chan);
3349  SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan));
3350 }
3351 
3352 static int dial_exec(struct ast_channel *chan, const char *data)
3353 {
3354  struct ast_flags64 peerflags;
3355 
3356  memset(&peerflags, 0, sizeof(peerflags));
3357 
3358  return dial_exec_full(chan, data, &peerflags, NULL);
3359 }
3360 
3361 static int retrydial_exec(struct ast_channel *chan, const char *data)
3362 {
3363  char *parse;
3364  const char *context = NULL;
3365  int sleepms = 0, loops = 0, res = -1;
3366  struct ast_flags64 peerflags = { 0, };
3368  AST_APP_ARG(announce);
3369  AST_APP_ARG(sleep);
3370  AST_APP_ARG(retries);
3371  AST_APP_ARG(dialdata);
3372  );
3373 
3374  if (ast_strlen_zero(data)) {
3375  ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
3376  return -1;
3377  }
3378 
3379  parse = ast_strdupa(data);
3380  AST_STANDARD_APP_ARGS(args, parse);
3381 
3382  if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
3383  sleepms *= 1000;
3384 
3385  if (!ast_strlen_zero(args.retries)) {
3386  loops = atoi(args.retries);
3387  }
3388 
3389  if (!args.dialdata) {
3390  ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
3391  goto done;
3392  }
3393 
3394  if (sleepms < 1000)
3395  sleepms = 10000;
3396 
3397  if (!loops)
3398  loops = -1; /* run forever */
3399 
3400  ast_channel_lock(chan);
3401  context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
3402  context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
3403  ast_channel_unlock(chan);
3404 
3405  res = 0;
3406  while (loops) {
3407  int continue_exec;
3408 
3409  ast_channel_data_set(chan, "Retrying");
3411  ast_moh_stop(chan);
3412 
3413  res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
3414  if (continue_exec)
3415  break;
3416 
3417  if (res == 0) {
3418  if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
3419  if (!ast_strlen_zero(args.announce)) {
3420  if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3421  if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3423  } else
3424  ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3425  }
3426  if (!res && sleepms) {
3428  ast_moh_start(chan, NULL, NULL);
3429  res = ast_waitfordigit(chan, sleepms);
3430  }
3431  } else {
3432  if (!ast_strlen_zero(args.announce)) {
3433  if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3434  if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3435  res = ast_waitstream(chan, "");
3436  } else
3437  ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3438  }
3439  if (sleepms) {
3441  ast_moh_start(chan, NULL, NULL);
3442  if (!res)
3443  res = ast_waitfordigit(chan, sleepms);
3444  }
3445  }
3446  }
3447 
3448  if (res < 0 || res == AST_PBX_INCOMPLETE) {
3449  break;
3450  } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
3451  if (onedigit_goto(chan, context, (char) res, 1)) {
3452  res = 0;
3453  break;
3454  }
3455  }
3456  loops--;
3457  }
3458  if (loops == 0)
3459  res = 0;
3460  else if (res == 1)
3461  res = 0;
3462 
3464  ast_moh_stop(chan);
3465  done:
3466  return res;
3467 }
3468 
3469 static int unload_module(void)
3470 {
3471  int res;
3472 
3475 
3476  return res;
3477 }
3478 
3479 static int load_module(void)
3480 {
3481  int res;
3482 
3485 
3486  return res;
3487 }
3488 
3489 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Dialing Application",
3490  .support_level = AST_MODULE_SUPPORT_CORE,
3491  .load = load_module,
3492  .unload = unload_module,
3493  .requires = "ccss",
3494 );
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
Definition: main/app.c:904
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:3152
#define OPT_FORCE_CID_PRES
Definition: app_dial.c:708
static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
Definition: app_dial.c:1874
int sentringing
Definition: app_dial.c:1138
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels together (early)
Definition: channel.c:7411
Information needed to identify an endpoint in a call.
Definition: channel.h:339
Tone Indication Support.
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2008
int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
Definition: pbx.c:4141
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2902
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
Definition: test_heap.c:38
Music on hold handling.
#define OPT_CALLEE_GO_ON
Definition: app_dial.c:705
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
Definition: max_forwards.c:121
char * str
Subscriber phone number (Malloced)
Definition: channel.h:292
int64_t ast_channel_get_duration_ms(struct ast_channel *chan)
Obtain how long it&#39;s been, in milliseconds, since the channel was created.
Definition: channel.c:2815
#define OPT_RING_WITH_EARLY_MEDIA
Definition: app_dial.c:712
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1250
char stuff[0]
Definition: app_dial.c:813
#define AST_PRIVACY_ALLOW
Definition: privacy.h:31
Asterisk locking-related definitions:
char privintro[1024]
Definition: app_dial.c:1141
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int frame)
Run a connected line interception macro and update a channel&#39;s connected line information.
Definition: channel.c:10328
void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
char privcid[256]
Definition: app_dial.c:1140
#define ast_copy_flags64(dest, src, flagz)
Definition: utils.h:141
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name...
Definition: channel.c:7371
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
Definition: app_dial.c:880
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
int ast_cc_failed(int core_id, const char *const debug,...)
Indicate failure has occurred.
Definition: ccss.c:3879
unsigned int pending_connected_update
Definition: app_dial.c:810
#define OPT_CANCEL_ELSEWHERE
Definition: app_dial.c:703
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
struct ast_flags features_callee
Definition: channel.h:1079
const char * tech
Definition: app_dial.c:801
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition: channel.h:296
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
char * config
Definition: conf2ael.c:66
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
Definition: sched.c:755
struct ast_stream_topology * answer_topology
Definition: channel.h:1100
struct ast_party_id id
Connected party ID.
Definition: channel.h:459
#define AST_DIGIT_ANY
Definition: file.h:48
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:351
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation...
Definition: channel.c:2031
#define ast_test_flag(p, flag)
Definition: utils.h:63
Support for translation of data formats. translate.c.
#define BEGIN_OPTIONS
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4291
struct ast_party_name name
Subscriber name.
Definition: channel.h:341
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: channel.h:528
void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
static int unload_module(void)
Definition: app_dial.c:3469
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
#define OPT_PREDIAL_CALLEE
Definition: app_dial.c:710
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Indicate that the redirecting id has changed.
Definition: channel.c:10272
int64_t ast_channel_get_up_time_ms(struct ast_channel *chan)
Obtain how long it has been since the channel was answered in ms.
Definition: channel.c:2830
Convenient Signal Processing routines.
int congestion
Definition: app_dial.c:854
int ast_privacy_check(char *dest, char *cid)
Definition: privacy.c:46
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition: channel.c:6619
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:455
#define AST_OPTION_OPRMODE
#define LOG_WARNING
Definition: logger.h:274
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:4712
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
union ast_frame::@257 data
#define AST_MAX_WATCHERS
Definition: app_dial.c:846
void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Indicate that the connected line information has changed.
Definition: channel.c:9082
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
static int timeout
Definition: cdr_mysql.c:86
static void end_bridge_callback(void *data)
Definition: app_dial.c:2152
static int tmp()
Definition: bt_open.c:389
Persistant data storage (akin to *doze registry)
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6452
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:108
uint64_t flags
Definition: app_dial.c:806
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Definition: channel.c:11128
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4271
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:307
#define ast_trace(level,...)
Definition: logger.h:881
ast_channel_state
ast_channel states
Definition: channelstate.h:35
struct chanlist::@18 node
char * str
Subscriber name (Malloced)
Definition: channel.h:265
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:4667
Dialing API.
int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
Bridge a call, optionally allowing redirection.
Definition: features.c:716
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define DIAL_STILLGOING
Definition: app_dial.c:700
const char * ast_hangup_cause_to_dial_status(int hangup_cause)
Convert a hangup cause to a publishable dial status.
Definition: dial.c:753
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ast_set_flag64(p, flag)
Definition: utils.h:127
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
static struct test_val c
#define ast_str_alloca(init_len)
Definition: strings.h:800
static int retrydial_exec(struct ast_channel *chan, const char *data)
Definition: app_dial.c:3361
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition: channel.c:2058
const char * str
Definition: app_jack.c:147
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
const char * args
char * str
Malloced subaddress string.
Definition: channel.h:314
#define NULL
Definition: resample.c:96
const char * data
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4918
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
Definition: file.c:1098
#define AST_FRAME_DTMF
#define OPT_CANCEL_TIMEOUT
Definition: app_dial.c:706
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7421
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition: utils.h:204
static int priority
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7775
const char * ast_channel_call_forward(const struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
#define ast_verb(level,...)
Definition: logger.h:455
void ast_bridge_set_after_h(struct ast_channel *chan, const char *context)
Set channel to run the h exten after the bridge.
Definition: bridge_after.c:631
int ast_cc_is_recall(struct ast_channel *chan, int *core_id, const char *const monitor_type)
Decide if a call to a particular channel is a CC recall.
Definition: ccss.c:3438
void ast_handle_cc_control_frame(struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data)
Properly react to a CC control frame.
Definition: ccss.c:2316
static void handle_cause(int cause, struct cause_args *num)
Definition: app_dial.c:858
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
Media Stream API.
void ast_cc_call_failed(struct ast_channel *incoming, struct ast_channel *outgoing, const char *const dialstring)
Make CCBS available in the case that ast_call fails.
Definition: ccss.c:4199
#define CAN_EARLY_BRIDGE(flags, chan, peer)
Definition: app_dial.c:785
Utility functions.
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
const char * start_sound
Definition: channel.h:1089
static struct ast_channel * wait_for_answer(struct ast_channel *in, struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags, char *opt_args[], struct privacy_args *pa, const struct cause_args *num_in, int *result, char *dtmf_progress, const int ignore_cc, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid, struct ast_bridge_config *config)
Definition: app_dial.c:1201
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
int ast_cc_completed(struct ast_channel *chan, const char *const debug,...)
Indicate recall has been acknowledged.
Definition: ccss.c:3842
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
int done
Definition: test_amihooks.c:48
#define DIAL_CALLERID_ABSENT
Definition: app_dial.c:702
Number structure.
Definition: app_followme.c:154
#define ao2_bump(obj)
Definition: astobj2.h:491
struct ast_party_id id
Caller party ID.
Definition: channel.h:421
Configuration File Parser.
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2359
static int setup_privacy_args(struct privacy_args *pa, struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
returns 1 if successful, 0 or <0 if the caller should &#39;goto out&#39;
Definition: app_dial.c:2051
#define ast_str_tmp(init_len, __expr)
Definition: strings.h:1136
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
void ast_replace_subargument_delimiter(char *s)
Replace &#39;^&#39; in a string with &#39;,&#39;.
Definition: main/utils.c:1966
static int dial_exec(struct ast_channel *chan, const char *data)
Definition: app_dial.c:3352
#define ast_log
Definition: astobj2.c:42
void ast_cc_extension_monitor_add_dialstring(struct ast_channel *incoming, const char *const dialstring, const char *const device_name)
Add a child dialstring to an extension monitor.
Definition: ccss.c:2005
const char * interface
Definition: app_dial.c:799
static const char * get_cid_name(char *name, int namelen, struct ast_channel *chan)
Definition: app_dial.c:899
Generic Advice of Charge encode and decode routines.
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition: channel.c:6716
const char * ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf)
Get a string representing the topology for debugging/display purposes.
Definition: stream.c:936
struct ast_aoc_decoded * ast_aoc_decode(struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
decodes an encoded aoc payload.
Definition: aoc.c:449
General Asterisk PBX channel definitions.
FILE * in
Definition: utils/frame.c:33
static int valid_priv_reply(struct ast_flags64 *opts, int res)
Definition: app_dial.c:1904
Asterisk file paths, configured in asterisk.conf.
#define AST_PRIVACY_KILL
Definition: privacy.h:32
struct ast_channel * chan
Definition: app_dial.c:797
#define OPT_PREDIAL_CALLER
Definition: app_dial.c:711
#define OPT_HANGUPCAUSE
Definition: app_dial.c:713
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
struct ast_aoc_encoded * ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
encodes a decoded aoc structure so it can be passed on the wire
Definition: aoc.c:650
#define OPT_FORCE_CID_TAG
Definition: app_dial.c:707
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition: causes.h:113
static int silencethreshold
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:8859
#define AST_MAX_EXTENSION
Definition: channel.h:135
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
Run a redirecting interception subroutine and update a channel&#39;s redirecting information.
Definition: channel.c:10477
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1630
bridge configuration
Definition: channel.h:1077
void * end_bridge_callback_data
Definition: channel.h:1092
Caller Party information.
Definition: channel.h:419
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
const char * end_sound
Definition: channel.h:1088
structure to hold extensions
int ast_play_and_wait(struct ast_channel *chan, const char *fn)
Play a stream and wait for a digit, returning the digit that was pressed.
Definition: main/app.c:1393
static int dial_handle_playtones(struct ast_channel *chan, const char *data)
Definition: app_dial.c:2168
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:85
void(* end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition: channel.h:1096
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition: cdr.c:3598
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:227
List of channel drivers.
Definition: app_dial.c:795
struct ast_channel * ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel (specifying stream topology)
Definition: channel.c:6348
#define DIAL_NOFORWARDHTML
Definition: app_dial.c:701
int nochan
Definition: app_dial.c:855
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
#define OPT_PEER_H
Definition: app_dial.c:704
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4179
int ast_app_exec_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_args)
Run a macro on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:273
int ast_pre_call(struct ast_channel *chan, const char *sub_args)
Execute a Gosub call on the channel before a call is placed.
Definition: channel.c:6435
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6425
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
const char * ast_channel_exten(const struct ast_channel *chan)
Core PBX routines and definitions.
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
Definition: callerid.c:1143
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:2834
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:1677
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:441
struct ast_party_connected_line connected
Definition: app_dial.c:808
struct ast_flags features_caller
Definition: channel.h:1078
int ast_cc_callback(struct ast_channel *inbound, const char *const tech, const char *const dest, ast_cc_callback_fn callback)
Run a callback for potential matching destinations.
Definition: ccss.c:4244
uint64_t flags
Definition: utils.h:205
static const char app[]
Definition: app_dial.c:662
int ast_cc_call_init(struct ast_channel *chan, int *ignore_cc)
Start the CC process on a call.
Definition: ccss.c:2409
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define AST_PBX_INCOMPLETE
Definition: pbx.h:51
struct ast_party_subaddress subaddress
Subscriber subaddress.
Definition: channel.h:345
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
Parse connected line indication frame data.
Definition: channel.c:8774
#define OPT_CALLER_ANSWER
Definition: app_dial.c:709
struct ast_sched_context * ast_channel_sched(const struct ast_channel *chan)
#define LOG_ERROR
Definition: logger.h:285
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
Initialize the given caller structure using the given guide for a set update operation.
Definition: channel.c:1985
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
Definition: channel.c:11121
int privdb_val
Definition: app_dial.c:1139
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:1904
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame)
Run a connected line interception subroutine and update a channel&#39;s connected line information...
Definition: channel.c:10432
Channel datastore data for max forwards.
Definition: max_forwards.c:29
const char * number
Definition: app_dial.c:803
void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
Set the connected line information based on another connected line source.
Definition: channel.c:2040
ast_channel_adsicpe
Definition: channel.h:869
Description of a tone.
Definition: indications.h:35
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:455
int ast_get_builtin_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a builtin feature.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
Connected Line/Party information.
Definition: channel.h:457
int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence_ms, const char *path)
Record a file based on input from a channel. Use default accept and cancel DTMF. This function will p...
Definition: main/app.c:1920
const ast_string_field name
void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide)
Initialize the given party id structure using the given guide for a set update operation.
Definition: channel.c:1766
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
struct ast_channel * chan
Definition: app_dial.c:852
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:7765
static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
Definition: app_dial.c:2210
struct timeval ast_channel_creationtime(struct ast_channel *chan)
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition: channel.h:523
#define LOG_NOTICE
Definition: logger.h:263
int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition: pbx.c:8793
void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen)
Sends HTML on given channel Send HTML or URL on link.
Definition: channel.c:6624
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
#define ast_strlen_zero(a)
Definition: muted.c:73
int ast_channel_sendurl(struct ast_channel *channel, const char *url)
Sends a URL on a given link Send URL on link.
Definition: channel.c:6631
#define ast_channel_unlock(chan)
Definition: channel.h:2903
int ast_privacy_set(char *dest, char *cid, int status)
Definition: privacy.c:82
const char * ast_cause2str(int state) attribute_pure
Gives the string form of a given cause code.
Definition: channel.c:608
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
static const char name[]
Definition: cdr_mysql.c:74
#define AST_CAUSE_UNREGISTERED
Definition: causes.h:153
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:6765
int source
Information about the source of an update.
Definition: channel.h:483
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define AST_CHANNEL_NAME
Definition: channel.h:172
Call Completion Supplementary Services API.
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2534
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
#define SCOPE_ENTER(level,...)
Definition: logger.h:890
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5088
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition: aoc.c:313
static const struct ast_app_option dial_exec_options[128]
Definition: app_dial.c:783
static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
Definition: app_dial.c:1188
void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer)
Put chan into autoservice while hanging up peer.
Definition: autoservice.c:342
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition: channel.c:1743
#define ast_set2_flag64(p, value, flag)
Definition: utils.h:151
#define AST_PRIVACY_UNKNOWN
Definition: privacy.h:34
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
Definition: linkedlists.h:251
#define ast_clear_flag64(p, flag)
Definition: utils.h:134
#define ast_clear_flag(p, flag)
Definition: utils.h:77
struct ast_channel * peer
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
#define AST_PRIVACY_DENY
Definition: privacy.h:30
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
Definition: stream.c:667
void ast_cc_busy_interface(struct ast_channel *inbound, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, void *private_data)
Callback made from ast_cc_callback for certain channel types.
Definition: ccss.c:4232
Definition: astman.c:88
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3170
void(* end_bridge_callback)(void *)
Definition: channel.h:1091
#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN
Definition: callerid.h:332
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2909
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
Definition: logger.h:909
FrameHook Architecture.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
void ast_ignore_cc(struct ast_channel *chan)
Mark the channel to ignore further CC activity.
Definition: ccss.c:3720
char * tag
User-set "tag".
Definition: channel.h:355
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2888
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
int transit_network_select
Transit Network Select.
Definition: channel.h:398
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition: channel.c:2165
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2017
char * strsep(char **str, const char *delims)
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:99
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
Definition: max_forwards.c:135
FILE * out
Definition: utils/frame.c:33
int busy
Definition: app_dial.c:853
After Bridge Execution API.
int ast_channel_hangupcause(const struct ast_channel *chan)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
static void chanlist_free(struct chanlist *outgoing)
Definition: app_dial.c:820
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
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:8282
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
const char * ast_channel_name(const struct ast_channel *chan)
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition: channel.c:2108
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1775
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition: file.c:1086
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
#define END_OPTIONS
static int load_module(void)
Definition: app_dial.c:3479
#define ast_frfree(fr)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2800
static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
Definition: app_dial.c:1145
static PGresult * result
Definition: cel_pgsql.c:88
#define AST_FEATURE_MAX_LEN
#define AST_CAUSE_BUSY
Definition: causes.h:148
static const char rapp[]
Definition: app_dial.c:663
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Definition: sched.c:431
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
Get a device name given its channel structure.
Definition: channel.c:10590
static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
Definition: app_dial.c:2232
Data structure associated with a single frame of data.
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:370
Internal Asterisk hangup causes.
const char * ast_channel_language(const struct ast_channel *chan)
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:302
Definition: aoc.h:64
const char * ast_channel_context(const struct ast_channel *chan)
void ast_bridge_set_after_go_on(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *parseable_goto)
Set channel to go on in the dialplan after the bridge.
Definition: bridge_after.c:636
const char * data
Description of a tone.
Definition: indications.h:52
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
get the message type, AOC-D, AOC-E, or AOC Request
Definition: aoc.c:892
static void do_forward(struct chanlist *o, struct cause_args *num, struct ast_flags64 *peerflags, int single, int caller_entertained, int *to, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
Definition: app_dial.c:929
static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
Definition: app_dial.c:1167
#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
int ast_str2cause(const char *name) attribute_pure
Convert the string form of a cause code to a number.
Definition: channel.c:621
const char * warning_sound
Definition: channel.h:1087
static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition: app_dial.c:2164
char status[256]
Definition: app_dial.c:1142
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:280
static struct test_options options
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
Call Parking and Pickup API Includes code and algorithms from the Zapata library. ...
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
const char * ast_channel_macrocontext(const struct ast_channel *chan)
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:947
struct ast_aoc_decoded * aoc_s_rate_list
Definition: app_dial.c:811
static char url[512]
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src)
Make two channels compatible for early bridging.
Definition: rtp_engine.c:2251
Pluggable RTP Architecture.
static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
Definition: app_dial.c:828
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:1959
struct ast_stream_topology * topology
Asterisk module definitions.
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
int ast_bridge_setup_after_goto(struct ast_channel *chan)
Setup any after bridge goto location to begin execution.
Definition: bridge_after.c:447
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Set the connected line information in the Asterisk channel.
Definition: channel.c:8297
#define AST_CAUSE_CONGESTION
Definition: causes.h:152
const char * ast_channel_macroexten(const struct ast_channel *chan)
void ast_channel_data_set(struct ast_channel *chan, const char *value)
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
Set the group for a channel, splitting the provided data into group and category, if specified...
Definition: main/app.c:1959
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:187
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
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:2121
const char * ast_channel_musicclass(const struct ast_channel *chan)
jack_status_t status
Definition: app_jack.c:146
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:10380
#define AST_APP_ARG(name)
Define an application argument.
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2102
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008
int ast_bridge_timelimit(struct ast_channel *chan, struct ast_bridge_config *config, char *parse, struct timeval *calldurationlimit)
parse L option and read associated channel variables to set warning, warning frequency, and timelimit
Definition: features.c:886
char * orig_chan_name
Definition: app_dial.c:805
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343
#define ast_test_flag64(p, flag)
Definition: utils.h:120