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