2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2008, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
21 * \brief dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 <depend>chan_local</depend>
30 <support_level>core</support_level>
36 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
39 #include <sys/signal.h>
41 #include <netinet/in.h>
43 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
44 #include "asterisk/lock.h"
45 #include "asterisk/file.h"
46 #include "asterisk/channel.h"
47 #include "asterisk/pbx.h"
48 #include "asterisk/module.h"
49 #include "asterisk/translate.h"
50 #include "asterisk/say.h"
51 #include "asterisk/config.h"
52 #include "asterisk/features.h"
53 #include "asterisk/musiconhold.h"
54 #include "asterisk/callerid.h"
55 #include "asterisk/utils.h"
56 #include "asterisk/app.h"
57 #include "asterisk/causes.h"
58 #include "asterisk/rtp_engine.h"
59 #include "asterisk/cdr.h"
60 #include "asterisk/manager.h"
61 #include "asterisk/privacy.h"
62 #include "asterisk/stringfields.h"
63 #include "asterisk/global_datastores.h"
64 #include "asterisk/dsp.h"
65 #include "asterisk/cel.h"
66 #include "asterisk/aoc.h"
67 #include "asterisk/ccss.h"
68 #include "asterisk/indications.h"
69 #include "asterisk/framehook.h"
72 <application name="Dial" language="en_US">
74 Attempt to connect to another device or endpoint and bridge the call.
77 <parameter name="Technology/Resource" required="true" argsep="&">
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>
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 then one enter them as
87 Technology2/Resource2&Technology3/Resourse3&.....</para>
90 <parameter name="timeout" required="false">
91 <para>Specifies the number of seconds we attempt to dial the specified devices</para>
92 <para>If not specified, this defaults to 136 years.</para>
94 <parameter name="options" required="false">
97 <argument name="x" required="true">
98 <para>The file to play to the called party</para>
100 <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
103 <para>Immediately answer the calling channel when the called channel answers in
104 all cases. Normally, the calling channel is answered when the called channel
105 answers, but when options such as A() and M() are used, the calling channel is
106 not answered until all actions on the called channel (such as playing an
107 announcement) are completed. This option can be used to answer the calling
108 channel before doing anything on the called channel. You will rarely need to use
109 this option, the default behavior is adequate in most cases.</para>
112 <para>Reset the call detail record (CDR) for this call.</para>
115 <para>If the Dial() application cancels this call, always set the flag to tell the channel
116 driver that the call is answered elsewhere.</para>
119 <para>Allow the calling user to dial a 1 digit extension while waiting for
120 a call to be answered. Exit to that extension if it exists in the
121 current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
124 <para>Many SIP and ISDN phones cannot send DTMF digits until the call is
125 connected. If you wish to use this option with these phones, you
126 can use the <literal>Answer</literal> application before dialing.</para>
129 <option name="D" argsep=":">
130 <argument name="called" />
131 <argument name="calling" />
132 <argument name="progress" />
133 <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
134 party has answered, but before the call gets bridged. The
135 <replaceable>called</replaceable> DTMF string is sent to the called party, and the
136 <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
137 can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
138 immediately after receiving a PROGRESS message.</para>
141 <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
144 <argument name="x" required="false" />
145 <para>If <replaceable>x</replaceable> is not provided, force the CallerID sent on a call-forward or
146 deflection to the dialplan extension of this Dial() using a dialplan <literal>hint</literal>.
147 For example, some PSTNs do not allow CallerID to be set to anything
148 other than the numbers assigned to you.
149 If <replaceable>x</replaceable> is provided, force the CallerID sent to <replaceable>x</replaceable>.</para>
151 <option name="F" argsep="^">
152 <argument name="context" required="false" />
153 <argument name="exten" required="false" />
154 <argument name="priority" required="true" />
155 <para>When the caller hangs up, transfer the called party
156 to the specified destination and continue execution at that location.</para>
159 <para>Proceed with dialplan execution at the next priority in the current extension if the
160 source channel hangs up.</para>
163 <para>Proceed with dialplan execution at the next priority in the current extension if the
164 destination channel hangs up.</para>
166 <option name="G" argsep="^">
167 <argument name="context" required="false" />
168 <argument name="exten" required="false" />
169 <argument name="priority" required="true" />
170 <para>If the call is answered, transfer the calling party to
171 the specified <replaceable>priority</replaceable> and the called party to the specified
172 <replaceable>priority</replaceable> plus one.</para>
174 <para>You cannot use any additional action post answer options in conjunction with this option.</para>
178 <para>Allow the called party to hang up by sending the DTMF sequence
179 defined for disconnect in <filename>features.conf</filename>.</para>
182 <para>Allow the calling party to hang up by sending the DTMF sequence
183 defined for disconnect in <filename>features.conf</filename>.</para>
185 <para>Many SIP and ISDN phones cannot send DTMF digits until the call is
186 connected. If you wish to allow DTMF disconnect before the dialed
187 party answers with these phones, you can use the <literal>Answer</literal>
188 application before dialing.</para>
192 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
195 <para>Asterisk will ignore any connected line update requests or redirecting party update
196 requests it may receiveon this dial attempt.</para>
199 <para>Allow the called party to enable parking of the call by sending
200 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
203 <para>Allow the calling party to enable parking of the call by sending
204 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
206 <option name="L" argsep=":">
207 <argument name="x" required="true">
208 <para>Maximum call time, in milliseconds</para>
211 <para>Warning time, in milliseconds</para>
214 <para>Repeat time, in milliseconds</para>
216 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
217 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
218 <para>This option is affected by the following variables:</para>
220 <variable name="LIMIT_PLAYAUDIO_CALLER">
221 <value name="yes" default="true" />
223 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
225 <variable name="LIMIT_PLAYAUDIO_CALLEE">
227 <value name="no" default="true"/>
228 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
230 <variable name="LIMIT_TIMEOUT_FILE">
231 <value name="filename"/>
232 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
233 If not set, the time remaining will be announced.</para>
235 <variable name="LIMIT_CONNECT_FILE">
236 <value name="filename"/>
237 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
238 If not set, the time remaining will be announced.</para>
240 <variable name="LIMIT_WARNING_FILE">
241 <value name="filename"/>
242 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
243 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
248 <argument name="class" required="false"/>
249 <para>Provide hold music to the calling party until a requested
250 channel answers. A specific music on hold <replaceable>class</replaceable>
251 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
253 <option name="M" argsep="^">
254 <argument name="macro" required="true">
255 <para>Name of the macro that should be executed.</para>
257 <argument name="arg" multiple="true">
258 <para>Macro arguments</para>
260 <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
261 before connecting to the calling channel. Arguments can be specified to the Macro
262 using <literal>^</literal> as a delimiter. The macro can set the variable
263 <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
264 finished executing:</para>
266 <variable name="MACRO_RESULT">
267 <para>If set, this action will be taken after the macro finished executing.</para>
269 Hangup both legs of the call
271 <value name="CONGESTION">
272 Behave as if line congestion was encountered
275 Behave as if a busy signal was encountered
277 <value name="CONTINUE">
278 Hangup the called party and allow the calling party to continue dialplan execution at the next priority
280 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
281 <value name="GOTO:<context>^<exten>^<priority>">
282 Transfer the call to the specified destination.
287 <para>You cannot use any additional action post answer options in conjunction
288 with this option. Also, pbx services are not run on the peer (called) channel,
289 so you will not be able to set timeouts via the TIMEOUT() function in this macro.</para>
291 <warning><para>Be aware of the limitations that macros have, specifically with regards to use of
292 the <literal>WaitExten</literal> application. For more information, see the documentation for
293 Macro()</para></warning>
296 <argument name="delete">
297 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
298 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
300 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
301 always be deleted.</para>
303 <para>This option is a modifier for the call screening/privacy mode. (See the
304 <literal>p</literal> and <literal>P</literal> options.) It specifies
305 that no introductions are to be saved in the <directory>priv-callerintros</directory>
309 <para>This option is a modifier for the call screening/privacy mode. It specifies
310 that if Caller*ID is present, do not screen the call.</para>
313 <argument name="x" required="false" />
314 <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
315 <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
316 This was the behavior of Asterisk 1.0 and earlier.
317 If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
318 Note that o(${CALLERID(all)}) is similar to option o without the parameter.</para>
321 <argument name="mode">
322 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
323 the originator hanging up will cause the phone to ring back immediately.</para>
324 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
325 flashes the trunk, it will ring their phone back.</para>
327 <para>Enables <emphasis>operator services</emphasis> mode. This option only
328 works when bridging a DAHDI channel to another DAHDI channel
329 only. if specified on non-DAHDI interfaces, it will be ignored.
330 When the destination answers (presumably an operator services
331 station), the originator no longer has control of their line.
332 They may hang up, but the switch will not release their line
333 until the destination party (the operator) hangs up.</para>
336 <para>This option enables screening mode. This is basically Privacy mode
337 without memory.</para>
340 <argument name="x" />
341 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
342 it is provided. The current extension is used if a database family/key is not specified.</para>
345 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
346 party until the called channel has answered.</para>
347 <argument name="tone" required="false">
348 <para>Indicate progress to calling party. Send audio 'tone' from indications.conf</para>
352 <argument name="x" required="true" />
353 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
354 answered the call.</para>
357 <argument name="x" required="true" />
358 <para>Force the outgoing callerid tag parameter to be set to the string <replaceable>x</replaceable>.</para>
359 <para>Works with the f option.</para>
362 <para>Allow the called party to transfer the calling party by sending the
363 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
364 transfers initiated by other methods.</para>
367 <para>Allow the calling party to transfer the called party by sending the
368 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
369 transfers initiated by other methods.</para>
371 <option name="U" argsep="^">
372 <argument name="x" required="true">
373 <para>Name of the subroutine to execute via Gosub</para>
375 <argument name="arg" multiple="true" required="false">
376 <para>Arguments for the Gosub routine</para>
378 <para>Execute via Gosub the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
379 to the calling channel. Arguments can be specified to the Gosub
380 using <literal>^</literal> as a delimiter. The Gosub routine can set the variable
381 <variable>GOSUB_RESULT</variable> to specify the following actions after the Gosub returns.</para>
383 <variable name="GOSUB_RESULT">
385 Hangup both legs of the call.
387 <value name="CONGESTION">
388 Behave as if line congestion was encountered.
391 Behave as if a busy signal was encountered.
393 <value name="CONTINUE">
394 Hangup the called party and allow the calling party
395 to continue dialplan execution at the next priority.
397 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
398 <value name="GOTO:<context>^<exten>^<priority>">
399 Transfer the call to the specified priority. Optionally, an extension, or
400 extension and priority can be specified.
405 <para>You cannot use any additional action post answer options in conjunction
406 with this option. Also, pbx services are not run on the peer (called) channel,
407 so you will not be able to set timeouts via the TIMEOUT() function in this routine.</para>
411 <argument name = "x" required="true">
412 <para>Force the outgoing callerid presentation indicator parameter to be set
413 to one of the values passed in <replaceable>x</replaceable>:
414 <literal>allowed_not_screened</literal>
415 <literal>allowed_passed_screen</literal>
416 <literal>allowed_failed_screen</literal>
417 <literal>allowed</literal>
418 <literal>prohib_not_screened</literal>
419 <literal>prohib_passed_screen</literal>
420 <literal>prohib_failed_screen</literal>
421 <literal>prohib</literal>
422 <literal>unavailable</literal></para>
424 <para>Works with the f option.</para>
427 <para>Allow the called party to enable recording of the call by sending
428 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
431 <para>Allow the calling party to enable recording of the call by sending
432 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
435 <para>Allow the called party to enable recording of the call by sending
436 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
439 <para>Allow the calling party to enable recording of the call by sending
440 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
443 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
447 <parameter name="URL">
448 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
452 <para>This application will place calls to one or more specified channels. As soon
453 as one of the requested channels answers, the originating channel will be
454 answered, if it has not already been answered. These two channels will then
455 be active in a bridged call. All other channels that were requested will then
458 <para>Unless there is a timeout specified, the Dial application will wait
459 indefinitely until one of the called channels answers, the user hangs up, or
460 if all of the called channels are busy or unavailable. Dialplan executing will
461 continue if no requested channels can be called, or if the timeout expires.
462 This application will report normal termination if the originating channel
463 hangs up, or if the call is bridged and either of the parties in the bridge
464 ends the call.</para>
465 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
466 application will be put into that group (as in Set(GROUP()=...).
467 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
468 application will be put into that group (as in Set(GROUP()=...). Unlike OUTBOUND_GROUP,
469 however, the variable will be unset after use.</para>
471 <para>This application sets the following channel variables:</para>
473 <variable name="DIALEDTIME">
474 <para>This is the time from dialing a channel until when it is disconnected.</para>
476 <variable name="ANSWEREDTIME">
477 <para>This is the amount of time for actual call.</para>
479 <variable name="DIALSTATUS">
480 <para>This is the status of the call</para>
481 <value name="CHANUNAVAIL" />
482 <value name="CONGESTION" />
483 <value name="NOANSWER" />
484 <value name="BUSY" />
485 <value name="ANSWER" />
486 <value name="CANCEL" />
487 <value name="DONTCALL">
488 For the Privacy and Screening Modes.
489 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
491 <value name="TORTURE">
492 For the Privacy and Screening Modes.
493 Will be set if the called party chooses to send the calling party to the 'torture' script.
495 <value name="INVALIDARGS" />
500 <application name="RetryDial" language="en_US">
502 Place a call, retrying on failure allowing an optional exit extension.
505 <parameter name="announce" required="true">
506 <para>Filename of sound that will be played when no channel can be reached</para>
508 <parameter name="sleep" required="true">
509 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
511 <parameter name="retries" required="true">
512 <para>Number of retries</para>
513 <para>When this is reached flow will continue at the next priority in the dialplan</para>
515 <parameter name="dialargs" required="true">
516 <para>Same format as arguments provided to the Dial application</para>
520 <para>This application will attempt to place a call using the normal Dial application.
521 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
522 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
523 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
524 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
525 While waiting to retry a call, a 1 digit extension may be dialed. If that
526 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
527 one, The call will jump to that extension immediately.
528 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
529 to the Dial application.</para>
534 static const char app[] = "Dial";
535 static const char rapp[] = "RetryDial";
538 OPT_ANNOUNCE = (1 << 0),
539 OPT_RESETCDR = (1 << 1),
540 OPT_DTMF_EXIT = (1 << 2),
541 OPT_SENDDTMF = (1 << 3),
542 OPT_FORCECLID = (1 << 4),
543 OPT_GO_ON = (1 << 5),
544 OPT_CALLEE_HANGUP = (1 << 6),
545 OPT_CALLER_HANGUP = (1 << 7),
546 OPT_ORIGINAL_CLID = (1 << 8),
547 OPT_DURATION_LIMIT = (1 << 9),
548 OPT_MUSICBACK = (1 << 10),
549 OPT_CALLEE_MACRO = (1 << 11),
550 OPT_SCREEN_NOINTRO = (1 << 12),
551 OPT_SCREEN_NOCALLERID = (1 << 13),
552 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
553 OPT_SCREENING = (1 << 15),
554 OPT_PRIVACY = (1 << 16),
555 OPT_RINGBACK = (1 << 17),
556 OPT_DURATION_STOP = (1 << 18),
557 OPT_CALLEE_TRANSFER = (1 << 19),
558 OPT_CALLER_TRANSFER = (1 << 20),
559 OPT_CALLEE_MONITOR = (1 << 21),
560 OPT_CALLER_MONITOR = (1 << 22),
561 OPT_GOTO = (1 << 23),
562 OPT_OPERMODE = (1 << 24),
563 OPT_CALLEE_PARK = (1 << 25),
564 OPT_CALLER_PARK = (1 << 26),
565 OPT_IGNORE_FORWARDING = (1 << 27),
566 OPT_CALLEE_GOSUB = (1 << 28),
567 OPT_CALLEE_MIXMONITOR = (1 << 29),
568 OPT_CALLER_MIXMONITOR = (1 << 30),
571 /* flags are now 64 bits, so keep it up! */
572 #define DIAL_STILLGOING (1LLU << 31)
573 #define DIAL_NOFORWARDHTML (1LLU << 32)
574 #define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
575 #define OPT_CANCEL_ELSEWHERE (1LLU << 34)
576 #define OPT_PEER_H (1LLU << 35)
577 #define OPT_CALLEE_GO_ON (1LLU << 36)
578 #define OPT_CANCEL_TIMEOUT (1LLU << 37)
579 #define OPT_FORCE_CID_TAG (1LLU << 38)
580 #define OPT_FORCE_CID_PRES (1LLU << 39)
581 #define OPT_CALLER_ANSWER (1LLU << 40)
584 OPT_ARG_ANNOUNCE = 0,
587 OPT_ARG_DURATION_LIMIT,
589 OPT_ARG_CALLEE_MACRO,
591 OPT_ARG_CALLEE_GOSUB,
592 OPT_ARG_CALLEE_GO_ON,
594 OPT_ARG_DURATION_STOP,
596 OPT_ARG_SCREEN_NOINTRO,
597 OPT_ARG_ORIGINAL_CLID,
599 OPT_ARG_FORCE_CID_TAG,
600 OPT_ARG_FORCE_CID_PRES,
601 /* note: this entry _MUST_ be the last one in the enum */
605 AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
606 AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
607 AST_APP_OPTION('a', OPT_CALLER_ANSWER),
608 AST_APP_OPTION('C', OPT_RESETCDR),
609 AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
610 AST_APP_OPTION('d', OPT_DTMF_EXIT),
611 AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
612 AST_APP_OPTION('e', OPT_PEER_H),
613 AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
614 AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
615 AST_APP_OPTION('g', OPT_GO_ON),
616 AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
617 AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
618 AST_APP_OPTION('H', OPT_CALLER_HANGUP),
619 AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
620 AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
621 AST_APP_OPTION('k', OPT_CALLEE_PARK),
622 AST_APP_OPTION('K', OPT_CALLER_PARK),
623 AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
624 AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
625 AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
626 AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
627 AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
628 AST_APP_OPTION_ARG('o', OPT_ORIGINAL_CLID, OPT_ARG_ORIGINAL_CLID),
629 AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
630 AST_APP_OPTION('p', OPT_SCREENING),
631 AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
632 AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
633 AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
634 AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG),
635 AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES),
636 AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
637 AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
638 AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
639 AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
640 AST_APP_OPTION('W', OPT_CALLER_MONITOR),
641 AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
642 AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
643 AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
646 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
647 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
648 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
649 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
650 !chan->audiohooks && !peer->audiohooks && \
651 ast_framehook_list_is_empty(chan->framehooks) && ast_framehook_list_is_empty(peer->framehooks))
654 * The list of active channels
657 struct chanlist *next;
658 struct ast_channel *chan;
660 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
661 struct ast_party_connected_line connected;
662 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
663 unsigned int pending_connected_update:1;
664 struct ast_aoc_decoded *aoc_s_rate_list;
667 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode);
669 static void chanlist_free(struct chanlist *outgoing)
671 ast_party_connected_line_free(&outgoing->connected);
672 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
676 static void hanguptree(struct chanlist *outgoing, struct ast_channel *exception, int answered_elsewhere)
678 /* Hang up a tree of stuff */
681 /* Hangup any existing lines we have open */
682 if (outgoing->chan && (outgoing->chan != exception)) {
683 if (answered_elsewhere) {
684 /* The flag is used for local channel inheritance and stuff */
685 ast_set_flag(outgoing->chan, AST_FLAG_ANSWERED_ELSEWHERE);
686 /* This is for the channel drivers */
687 outgoing->chan->hangupcause = AST_CAUSE_ANSWERED_ELSEWHERE;
689 ast_hangup(outgoing->chan);
692 outgoing = outgoing->next;
697 #define AST_MAX_WATCHERS 256
700 * argument to handle_cause() and other functions.
703 struct ast_channel *chan;
709 static void handle_cause(int cause, struct cause_args *num)
711 struct ast_cdr *cdr = num->chan->cdr;
720 case AST_CAUSE_CONGESTION:
726 case AST_CAUSE_NO_ROUTE_DESTINATION:
727 case AST_CAUSE_UNREGISTERED:
733 case AST_CAUSE_NO_ANSWER:
735 ast_cdr_noanswer(cdr);
738 case AST_CAUSE_NORMAL_CLEARING:
747 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
749 char rexten[2] = { exten, '\0' };
752 if (!ast_goto_if_exists(chan, context, rexten, pri))
755 if (!ast_goto_if_exists(chan, chan->context, rexten, pri))
757 else if (!ast_strlen_zero(chan->macrocontext)) {
758 if (!ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
765 /* do not call with chan lock held */
766 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
771 ast_channel_lock(chan);
772 context = ast_strdupa(S_OR(chan->macrocontext, chan->context));
773 exten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
774 ast_channel_unlock(chan);
776 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
779 static void senddialevent(struct ast_channel *src, struct ast_channel *dst, const char *dialstring)
781 struct ast_channel *chans[] = { src, dst };
782 ast_manager_event_multichan(EVENT_FLAG_CALL, "Dial", 2, chans,
783 "SubEvent: Begin\r\n"
785 "Destination: %s\r\n"
786 "CallerIDNum: %s\r\n"
787 "CallerIDName: %s\r\n"
788 "ConnectedLineNum: %s\r\n"
789 "ConnectedLineName: %s\r\n"
791 "DestUniqueID: %s\r\n"
792 "Dialstring: %s\r\n",
793 src->name, dst->name,
794 S_COR(src->caller.id.number.valid, src->caller.id.number.str, "<unknown>"),
795 S_COR(src->caller.id.name.valid, src->caller.id.name.str, "<unknown>"),
796 S_COR(src->connected.id.number.valid, src->connected.id.number.str, "<unknown>"),
797 S_COR(src->connected.id.name.valid, src->connected.id.name.str, "<unknown>"),
798 src->uniqueid, dst->uniqueid,
799 dialstring ? dialstring : "");
802 static void senddialendevent(struct ast_channel *src, const char *dialstatus)
804 ast_manager_event(src, EVENT_FLAG_CALL, "Dial",
808 "DialStatus: %s\r\n",
809 src->name, src->uniqueid, dialstatus);
813 * helper function for wait_for_answer()
815 * XXX this code is highly suspicious, as it essentially overwrites
816 * the outgoing channel without properly deleting it.
818 * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
820 static void do_forward(struct chanlist *o,
821 struct cause_args *num, struct ast_flags64 *peerflags, int single, int *to,
822 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
825 struct ast_channel *original = o->chan;
826 struct ast_channel *c = o->chan; /* the winner */
827 struct ast_channel *in = num->chan; /* the input channel */
831 struct ast_party_caller caller;
833 ast_copy_string(tmpchan, c->call_forward, sizeof(tmpchan));
834 if ((stuff = strchr(tmpchan, '/'))) {
838 const char *forward_context;
840 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
841 if (ast_strlen_zero(forward_context)) {
842 forward_context = NULL;
844 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", c->call_forward, forward_context ? forward_context : c->context);
845 ast_channel_unlock(c);
850 ast_cel_report_event(in, AST_CEL_FORWARD, NULL, c->call_forward, NULL);
852 /* Before processing channel, go ahead and check for forwarding */
853 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
854 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
855 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
856 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
858 cause = AST_CAUSE_BUSY;
860 /* Setup parameters */
861 c = o->chan = ast_request(tech, in->nativeformats, in, stuff, &cause);
864 ast_channel_make_compatible(o->chan, in);
865 ast_channel_inherit_variables(in, o->chan);
866 ast_channel_datastore_inherit(in, o->chan);
867 /* When a call is forwarded, we don't want to track new interfaces
868 * dialed for CC purposes. Setting the done flag will ensure that
869 * any Dial operations that happen later won't record CC interfaces.
871 ast_ignore_cc(o->chan);
872 ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", o->chan->name);
875 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
879 ast_clear_flag64(o, DIAL_STILLGOING);
880 handle_cause(cause, num);
881 ast_hangup(original);
883 struct ast_party_redirecting redirecting;
885 if (single && CAN_EARLY_BRIDGE(peerflags, c, in)) {
886 ast_rtp_instance_early_bridge_make_compatible(c, in);
889 ast_channel_set_redirecting(c, &original->redirecting, NULL);
891 while (ast_channel_trylock(in)) {
892 CHANNEL_DEADLOCK_AVOIDANCE(c);
894 if (!c->redirecting.from.number.valid
895 || ast_strlen_zero(c->redirecting.from.number.str)) {
897 * The call was not previously redirected so it is
898 * now redirected from this number.
900 ast_party_number_free(&c->redirecting.from.number);
901 ast_party_number_init(&c->redirecting.from.number);
902 c->redirecting.from.number.valid = 1;
903 c->redirecting.from.number.str =
904 ast_strdup(S_OR(in->macroexten, in->exten));
907 c->dialed.transit_network_select = in->dialed.transit_network_select;
909 /* Determine CallerID to store in outgoing channel. */
910 ast_party_caller_set_init(&caller, &c->caller);
911 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
912 caller.id = *stored_clid;
913 ast_channel_set_caller_event(c, &caller, NULL);
914 } else if (ast_strlen_zero(S_COR(c->caller.id.number.valid,
915 c->caller.id.number.str, NULL))) {
917 * The new channel has no preset CallerID number by the channel
918 * driver. Use the dialplan extension and hint name.
920 caller.id = *stored_clid;
921 ast_channel_set_caller_event(c, &caller, NULL);
924 /* Determine CallerID for outgoing channel to send. */
925 if (ast_test_flag64(o, OPT_FORCECLID)) {
926 struct ast_party_connected_line connected;
928 ast_party_connected_line_init(&connected);
929 connected.id = *forced_clid;
930 ast_party_connected_line_copy(&c->connected, &connected);
932 ast_connected_line_copy_from_caller(&c->connected, &in->caller);
935 ast_string_field_set(c, accountcode, in->accountcode);
938 c->data = "(Outgoing Line)";
940 * We must unlock c before calling ast_channel_redirecting_macro, because
941 * we put c into autoservice there. That is pretty much a guaranteed
942 * deadlock. This is why the handling of c's lock may seem a bit unusual
945 ast_party_redirecting_init(&redirecting);
946 ast_party_redirecting_copy(&redirecting, &c->redirecting);
947 ast_channel_unlock(c);
948 if (ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
949 ast_channel_update_redirecting(in, &redirecting, NULL);
951 ast_party_redirecting_free(&redirecting);
952 ast_channel_unlock(in);
954 ast_clear_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE);
955 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
959 if (ast_call(c, stuff, 0)) {
960 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
962 ast_clear_flag64(o, DIAL_STILLGOING);
963 ast_hangup(original);
969 while (ast_channel_trylock(in)) {
970 CHANNEL_DEADLOCK_AVOIDANCE(c);
972 senddialevent(in, c, stuff);
973 ast_channel_unlock(in);
974 ast_channel_unlock(c);
975 /* Hangup the original channel now, in case we needed it */
976 ast_hangup(original);
979 ast_indicate(in, -1);
984 /* argument used for some functions. */
985 struct privacy_args {
989 char privintro[1024];
993 static struct ast_channel *wait_for_answer(struct ast_channel *in,
994 struct chanlist *outgoing, int *to, struct ast_flags64 *peerflags,
996 struct privacy_args *pa,
997 const struct cause_args *num_in, int *result, char *dtmf_progress,
999 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
1001 struct cause_args num = *num_in;
1002 int prestart = num.busy + num.congestion + num.nochan;
1004 struct ast_channel *peer = NULL;
1005 /* single is set if only one destination is enabled */
1006 int single = outgoing && !outgoing->next;
1008 struct chanlist *epollo;
1010 struct ast_party_connected_line connected_caller;
1011 struct ast_str *featurecode = ast_str_alloca(FEATURE_MAX_LEN + 1);
1012 int cc_recall_core_id;
1014 int cc_frame_received = 0;
1015 int num_ringing = 0;
1017 ast_party_connected_line_init(&connected_caller);
1019 /* Turn off hold music, etc */
1020 if (!ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK)) {
1021 ast_deactivate_generator(in);
1022 /* If we are calling a single channel, and not providing ringback or music, */
1023 /* then, make them compatible for in-band tone purpose */
1024 if (ast_channel_make_compatible(outgoing->chan, in) < 0) {
1025 /* If these channels can not be made compatible,
1026 * there is no point in continuing. The bridge
1027 * will just fail if it gets that far.
1030 strcpy(pa->status, "CONGESTION");
1031 ast_cdr_failed(in->cdr);
1036 if (!ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE) && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
1037 ast_channel_lock(outgoing->chan);
1038 ast_connected_line_copy_from_caller(&connected_caller, &outgoing->chan->caller);
1039 ast_channel_unlock(outgoing->chan);
1040 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1041 ast_channel_update_connected_line(in, &connected_caller, NULL);
1042 ast_party_connected_line_free(&connected_caller);
1046 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1049 for (epollo = outgoing; epollo; epollo = epollo->next)
1050 ast_poll_channel_add(in, epollo->chan);
1053 while (*to && !peer) {
1055 int pos = 0; /* how many channels do we handle */
1056 int numlines = prestart;
1057 struct ast_channel *winner;
1058 struct ast_channel *watchers[AST_MAX_WATCHERS];
1060 watchers[pos++] = in;
1061 for (o = outgoing; o; o = o->next) {
1062 /* Keep track of important channels */
1063 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1064 watchers[pos++] = o->chan;
1067 if (pos == 1) { /* only the input channel is available */
1068 if (numlines == (num.busy + num.congestion + num.nochan)) {
1069 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1071 strcpy(pa->status, "BUSY");
1072 else if (num.congestion)
1073 strcpy(pa->status, "CONGESTION");
1074 else if (num.nochan)
1075 strcpy(pa->status, "CHANUNAVAIL");
1077 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1081 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1085 winner = ast_waitfor_n(watchers, pos, to);
1086 for (o = outgoing; o; o = o->next) {
1087 struct ast_frame *f;
1088 struct ast_channel *c = o->chan;
1092 if (ast_test_flag64(o, DIAL_STILLGOING) && c->_state == AST_STATE_UP) {
1094 ast_verb(3, "%s answered %s\n", c->name, in->name);
1095 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1096 if (o->pending_connected_update) {
1097 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1098 ast_channel_update_connected_line(in, &o->connected, NULL);
1100 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1101 ast_channel_lock(c);
1102 ast_connected_line_copy_from_caller(&connected_caller, &c->caller);
1103 ast_channel_unlock(c);
1104 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1105 ast_channel_update_connected_line(in, &connected_caller, NULL);
1106 ast_party_connected_line_free(&connected_caller);
1109 if (o->aoc_s_rate_list) {
1110 size_t encoded_size;
1111 struct ast_aoc_encoded *encoded;
1112 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1113 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1114 ast_aoc_destroy_encoded(encoded);
1118 ast_copy_flags64(peerflags, o,
1119 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1120 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1121 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1122 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1123 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1124 DIAL_NOFORWARDHTML);
1125 ast_string_field_set(c, dialcontext, "");
1126 ast_copy_string(c->exten, "", sizeof(c->exten));
1132 /* here, o->chan == c == winner */
1133 if (!ast_strlen_zero(c->call_forward)) {
1134 pa->sentringing = 0;
1135 if (!ignore_cc && (f = ast_read(c))) {
1136 if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
1137 /* This channel is forwarding the call, and is capable of CC, so
1138 * be sure to add the new device interface to the list
1140 ast_handle_cc_control_frame(in, c, f->data.ptr);
1144 do_forward(o, &num, peerflags, single, to, forced_clid, stored_clid);
1147 f = ast_read(winner);
1149 in->hangupcause = c->hangupcause;
1151 ast_poll_channel_del(in, c);
1155 ast_clear_flag64(o, DIAL_STILLGOING);
1156 handle_cause(in->hangupcause, &num);
1159 if (f->frametype == AST_FRAME_CONTROL) {
1160 switch (f->subclass.integer) {
1161 case AST_CONTROL_ANSWER:
1162 /* This is our guy if someone answered. */
1164 ast_verb(3, "%s answered %s\n", c->name, in->name);
1165 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1166 if (o->pending_connected_update) {
1167 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1168 ast_channel_update_connected_line(in, &o->connected, NULL);
1170 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1171 ast_channel_lock(c);
1172 ast_connected_line_copy_from_caller(&connected_caller, &c->caller);
1173 ast_channel_unlock(c);
1174 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1175 ast_channel_update_connected_line(in, &connected_caller, NULL);
1176 ast_party_connected_line_free(&connected_caller);
1179 if (o->aoc_s_rate_list) {
1180 size_t encoded_size;
1181 struct ast_aoc_encoded *encoded;
1182 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1183 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1184 ast_aoc_destroy_encoded(encoded);
1189 peer->cdr->answer = ast_tvnow();
1190 peer->cdr->disposition = AST_CDR_ANSWERED;
1192 ast_copy_flags64(peerflags, o,
1193 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1194 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1195 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1196 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1197 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1198 DIAL_NOFORWARDHTML);
1199 ast_string_field_set(c, dialcontext, "");
1200 ast_copy_string(c->exten, "", sizeof(c->exten));
1201 if (CAN_EARLY_BRIDGE(peerflags, in, peer))
1202 /* Setup early bridge if appropriate */
1203 ast_channel_early_bridge(in, peer);
1205 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1206 in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
1207 c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
1209 case AST_CONTROL_BUSY:
1210 ast_verb(3, "%s is busy\n", c->name);
1211 in->hangupcause = c->hangupcause;
1214 ast_clear_flag64(o, DIAL_STILLGOING);
1215 handle_cause(AST_CAUSE_BUSY, &num);
1217 case AST_CONTROL_CONGESTION:
1218 ast_verb(3, "%s is circuit-busy\n", c->name);
1219 in->hangupcause = c->hangupcause;
1222 ast_clear_flag64(o, DIAL_STILLGOING);
1223 handle_cause(AST_CAUSE_CONGESTION, &num);
1225 case AST_CONTROL_RINGING:
1226 /* This is a tricky area to get right when using a native
1227 * CC agent. The reason is that we do the best we can to send only a
1228 * single ringing notification to the caller.
1230 * Call completion complicates the logic used here. CCNR is typically
1231 * offered during a ringing message. Let's say that party A calls
1232 * parties B, C, and D. B and C do not support CC requests, but D
1233 * does. If we were to receive a ringing notification from B before
1234 * the others, then we would end up sending a ringing message to
1235 * A with no CCNR offer present.
1237 * The approach that we have taken is that if we receive a ringing
1238 * response from a party and no CCNR offer is present, we need to
1239 * wait. Specifically, we need to wait until either a) a called party
1240 * offers CCNR in its ringing response or b) all called parties have
1241 * responded in some way to our call and none offers CCNR.
1243 * The drawback to this is that if one of the parties has a delayed
1244 * response or, god forbid, one just plain doesn't respond to our
1245 * outgoing call, then this will result in a significant delay between
1246 * when the caller places the call and hears ringback.
1248 * Note also that if CC is disabled for this call, then it is perfectly
1249 * fine for ringing frames to get sent through.
1252 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1253 ast_verb(3, "%s is ringing\n", c->name);
1254 /* Setup early media if appropriate */
1255 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1256 ast_channel_early_bridge(in, c);
1257 if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
1258 ast_indicate(in, AST_CONTROL_RINGING);
1263 case AST_CONTROL_PROGRESS:
1264 ast_verb(3, "%s is making progress passing it to %s\n", c->name, in->name);
1265 /* Setup early media if appropriate */
1266 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1267 ast_channel_early_bridge(in, c);
1268 if (!ast_test_flag64(outgoing, OPT_RINGBACK)) {
1269 if (single || (!single && !pa->sentringing)) {
1270 ast_indicate(in, AST_CONTROL_PROGRESS);
1273 if (!ast_strlen_zero(dtmf_progress)) {
1275 "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n",
1277 ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1280 case AST_CONTROL_VIDUPDATE:
1281 ast_verb(3, "%s requested a video update, passing it to %s\n", c->name, in->name);
1282 ast_indicate(in, AST_CONTROL_VIDUPDATE);
1284 case AST_CONTROL_SRCUPDATE:
1285 ast_verb(3, "%s requested a source update, passing it to %s\n", c->name, in->name);
1286 ast_indicate(in, AST_CONTROL_SRCUPDATE);
1288 case AST_CONTROL_CONNECTED_LINE:
1289 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1290 ast_verb(3, "Connected line update to %s prevented.\n", in->name);
1291 } else if (!single) {
1292 struct ast_party_connected_line connected;
1293 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", c->name, in->name);
1294 ast_party_connected_line_set_init(&connected, &o->connected);
1295 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
1296 ast_party_connected_line_set(&o->connected, &connected, NULL);
1297 ast_party_connected_line_free(&connected);
1298 o->pending_connected_update = 1;
1300 if (ast_channel_connected_line_macro(c, in, f, 1, 1)) {
1301 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
1305 case AST_CONTROL_AOC:
1307 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1308 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1309 ast_aoc_destroy_decoded(o->aoc_s_rate_list);
1310 o->aoc_s_rate_list = decoded;
1312 ast_aoc_destroy_decoded(decoded);
1316 case AST_CONTROL_REDIRECTING:
1317 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1318 ast_verb(3, "Redirecting update to %s prevented.\n", in->name);
1319 } else if (single) {
1320 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", c->name, in->name);
1321 if (ast_channel_redirecting_macro(c, in, f, 1, 1)) {
1322 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
1324 pa->sentringing = 0;
1327 case AST_CONTROL_PROCEEDING:
1328 ast_verb(3, "%s is proceeding passing it to %s\n", c->name, in->name);
1329 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1330 ast_channel_early_bridge(in, c);
1331 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1332 ast_indicate(in, AST_CONTROL_PROCEEDING);
1334 case AST_CONTROL_HOLD:
1335 ast_verb(3, "Call on %s placed on hold\n", c->name);
1336 ast_indicate(in, AST_CONTROL_HOLD);
1338 case AST_CONTROL_UNHOLD:
1339 ast_verb(3, "Call on %s left from hold\n", c->name);
1340 ast_indicate(in, AST_CONTROL_UNHOLD);
1342 case AST_CONTROL_OFFHOOK:
1343 case AST_CONTROL_FLASH:
1344 /* Ignore going off hook and flash */
1346 case AST_CONTROL_CC:
1348 ast_handle_cc_control_frame(in, c, f->data.ptr);
1349 cc_frame_received = 1;
1353 if (!ast_test_flag64(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
1354 ast_verb(3, "%s stopped sounds\n", c->name);
1355 ast_indicate(in, -1);
1356 pa->sentringing = 0;
1360 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1362 } else if (single) {
1363 switch (f->frametype) {
1364 case AST_FRAME_VOICE:
1365 case AST_FRAME_IMAGE:
1366 case AST_FRAME_TEXT:
1367 if (!ast_test_flag64(outgoing, OPT_RINGBACK | OPT_MUSICBACK) && ast_write(in, f)) {
1368 ast_log(LOG_WARNING, "Unable to write frametype: %d\n",
1372 case AST_FRAME_HTML:
1373 if (!ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)
1374 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1375 ast_log(LOG_WARNING, "Unable to send URL\n");
1385 struct ast_frame *f = ast_read(in);
1387 if (f && (f->frametype != AST_FRAME_VOICE))
1388 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1389 else if (!f || (f->frametype != AST_FRAME_VOICE))
1390 printf("Hangup received on %s\n", in->name);
1392 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1395 strcpy(pa->status, "CANCEL");
1396 ast_cdr_noanswer(in->cdr);
1398 if (f->data.uint32) {
1399 in->hangupcause = f->data.uint32;
1404 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1409 /* now f is guaranteed non-NULL */
1410 if (f->frametype == AST_FRAME_DTMF) {
1411 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1412 const char *context;
1413 ast_channel_lock(in);
1414 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1415 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1416 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1418 ast_cdr_noanswer(in->cdr);
1419 *result = f->subclass.integer;
1420 strcpy(pa->status, "CANCEL");
1422 ast_channel_unlock(in);
1424 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1428 ast_channel_unlock(in);
1431 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1432 detect_disconnect(in, f->subclass.integer, featurecode)) {
1433 ast_verb(3, "User requested call disconnect.\n");
1435 strcpy(pa->status, "CANCEL");
1436 ast_cdr_noanswer(in->cdr);
1439 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1445 /* Send the frame from the in channel to all outgoing channels. */
1446 for (o = outgoing; o; o = o->next) {
1447 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1448 /* This outgoing channel has died so don't send the frame to it. */
1451 switch (f->frametype) {
1452 case AST_FRAME_HTML:
1453 /* Forward HTML stuff */
1454 if (!ast_test_flag64(o, DIAL_NOFORWARDHTML)
1455 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1456 ast_log(LOG_WARNING, "Unable to send URL\n");
1459 case AST_FRAME_VOICE:
1460 case AST_FRAME_IMAGE:
1461 case AST_FRAME_TEXT:
1462 case AST_FRAME_DTMF_BEGIN:
1463 case AST_FRAME_DTMF_END:
1464 if (ast_write(o->chan, f)) {
1465 ast_log(LOG_WARNING, "Unable to forward frametype: %d\n",
1469 case AST_FRAME_CONTROL:
1470 switch (f->subclass.integer) {
1471 case AST_CONTROL_HOLD:
1472 case AST_CONTROL_UNHOLD:
1473 case AST_CONTROL_VIDUPDATE:
1474 case AST_CONTROL_SRCUPDATE:
1475 ast_verb(3, "%s requested special control %d, passing it to %s\n",
1476 in->name, f->subclass.integer, o->chan->name);
1477 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1479 case AST_CONTROL_CONNECTED_LINE:
1480 if (ast_channel_connected_line_macro(in, o->chan, f, 0, 1)) {
1481 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1484 case AST_CONTROL_REDIRECTING:
1485 if (ast_channel_redirecting_macro(in, o->chan, f, 0, 1)) {
1486 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1500 ast_verb(3, "Nobody picked up in %d ms\n", orig);
1501 if (!*to || ast_check_hangup(in))
1502 ast_cdr_noanswer(in->cdr);
1506 for (epollo = outgoing; epollo; epollo = epollo->next) {
1508 ast_poll_channel_del(in, epollo->chan);
1513 ast_cc_completed(in, "Recall completed!");
1518 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode)
1520 struct ast_flags features = { AST_FEATURE_DISCONNECT }; /* only concerned with disconnect feature */
1521 struct ast_call_feature feature = { 0, };
1524 ast_str_append(&featurecode, 1, "%c", code);
1526 res = ast_feature_detect(chan, &features, ast_str_buffer(featurecode), &feature);
1528 if (res != AST_FEATURE_RETURN_STOREDIGITS) {
1529 ast_str_reset(featurecode);
1531 if (feature.feature_mask & AST_FEATURE_DISCONNECT) {
1538 static void replace_macro_delimiter(char *s)
1545 /* returns true if there is a valid privacy reply */
1546 static int valid_priv_reply(struct ast_flags64 *opts, int res)
1550 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1552 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1557 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1558 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1564 /* Get the user's intro, store it in priv-callerintros/$CID,
1565 unless it is already there-- this should be done before the
1566 call is actually dialed */
1568 /* all ring indications and moh for the caller has been halted as soon as the
1569 target extension was picked up. We are going to have to kill some
1570 time and make the caller believe the peer hasn't picked up yet */
1572 if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
1573 char *original_moh = ast_strdupa(chan->musicclass);
1574 ast_indicate(chan, -1);
1575 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
1576 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1577 ast_string_field_set(chan, musicclass, original_moh);
1578 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1579 ast_indicate(chan, AST_CONTROL_RINGING);
1583 /* Start autoservice on the other chan ?? */
1584 res2 = ast_autoservice_start(chan);
1585 /* Now Stream the File */
1586 for (loopcount = 0; loopcount < 3; loopcount++) {
1587 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1589 if (!res2) /* on timeout, play the message again */
1590 res2 = ast_play_and_wait(peer, "priv-callpending");
1591 if (!valid_priv_reply(opts, res2))
1593 /* priv-callpending script:
1594 "I have a caller waiting, who introduces themselves as:"
1597 res2 = ast_play_and_wait(peer, pa->privintro);
1598 if (!valid_priv_reply(opts, res2))
1600 /* now get input from the called party, as to their choice */
1602 /* XXX can we have both, or they are mutually exclusive ? */
1603 if (ast_test_flag64(opts, OPT_PRIVACY))
1604 res2 = ast_play_and_wait(peer, "priv-callee-options");
1605 if (ast_test_flag64(opts, OPT_SCREENING))
1606 res2 = ast_play_and_wait(peer, "screen-callee-options");
1608 /*! \page DialPrivacy Dial Privacy scripts
1609 \par priv-callee-options script:
1610 "Dial 1 if you wish this caller to reach you directly in the future,
1611 and immediately connect to their incoming call
1612 Dial 2 if you wish to send this caller to voicemail now and
1614 Dial 3 to send this caller to the torture menus, now and forevermore.
1615 Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
1616 Dial 5 to allow this caller to come straight thru to you in the future,
1617 but right now, just this once, send them to voicemail."
1618 \par screen-callee-options script:
1619 "Dial 1 if you wish to immediately connect to the incoming call
1620 Dial 2 if you wish to send this caller to voicemail.
1621 Dial 3 to send this caller to the torture menus.
1622 Dial 4 to send this caller to a simple "go away" menu.
1624 if (valid_priv_reply(opts, res2))
1626 /* invalid option */
1627 res2 = ast_play_and_wait(peer, "vm-sorry");
1630 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
1632 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1633 ast_indicate(chan, -1);
1634 pa->sentringing = 0;
1636 ast_autoservice_stop(chan);
1637 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
1638 /* map keypresses to various things, the index is res2 - '1' */
1639 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
1640 static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
1642 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
1643 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
1644 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
1650 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1653 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1656 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1659 /* XXX should we set status to DENY ? */
1660 if (ast_test_flag64(opts, OPT_PRIVACY))
1662 /* if not privacy, then 5 is the same as "default" case */
1663 default: /* bad input or -1 if failure to start autoservice */
1664 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
1665 /* well, there seems basically two choices. Just patch the caller thru immediately,
1666 or,... put 'em thru to voicemail. */
1667 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
1668 ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
1669 /* XXX should we set status to DENY ? */
1670 /* XXX what about the privacy flags ? */
1674 if (res2 == '1') { /* the only case where we actually connect */
1675 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
1676 just clog things up, and it's not useful information, not being tied to a CID */
1677 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
1678 ast_filedelete(pa->privintro, NULL);
1679 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1680 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1682 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1684 return 0; /* the good exit path */
1686 ast_hangup(peer); /* hang up on the callee -- he didn't want to talk anyway! */
1691 /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
1692 static int setup_privacy_args(struct privacy_args *pa,
1693 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
1698 int silencethreshold;
1700 if (chan->caller.id.number.valid
1701 && !ast_strlen_zero(chan->caller.id.number.str)) {
1702 l = ast_strdupa(chan->caller.id.number.str);
1703 ast_shrink_phone_number(l);
1704 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
1705 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
1706 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
1708 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
1709 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1714 tnam = ast_strdupa(chan->name);
1715 /* clean the channel name so slashes don't try to end up in disk file name */
1716 for (tn2 = tnam; *tn2; tn2++) {
1717 if (*tn2 == '/') /* any other chars to be afraid of? */
1720 ast_verb(3, "Privacy-- callerid is empty\n");
1722 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", chan->exten, tnam);
1724 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1727 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
1729 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
1730 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
1731 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
1732 pa->privdb_val = AST_PRIVACY_ALLOW;
1733 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
1734 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
1737 if (pa->privdb_val == AST_PRIVACY_DENY) {
1738 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
1739 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1741 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
1742 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1743 return 0; /* Is this right? */
1744 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
1745 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1746 return 0; /* is this right??? */
1747 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
1748 /* Get the user's intro, store it in priv-callerintros/$CID,
1749 unless it is already there-- this should be done before the
1750 call is actually dialed */
1752 /* make sure the priv-callerintros dir actually exists */
1753 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
1754 if ((res = ast_mkdir(pa->privintro, 0755))) {
1755 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
1759 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
1760 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
1761 /* the DELUX version of this code would allow this caller the
1762 option to hear and retape their previously recorded intro.
1765 int duration; /* for feedback from play_and_wait */
1766 /* the file doesn't exist yet. Let the caller submit his
1767 vocal intro for posterity */
1768 /* priv-recordintro script:
1770 "At the tone, please say your name:"
1773 silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
1775 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
1776 /* don't think we'll need a lock removed, we took care of
1777 conflicts by naming the pa.privintro file */
1779 /* Delete the file regardless since they hung up during recording */
1780 ast_filedelete(pa->privintro, NULL);
1781 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1782 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1784 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1787 if (!ast_streamfile(chan, "vm-dialout", chan->language) )
1788 ast_waitstream(chan, "");
1791 return 1; /* success */
1794 static void end_bridge_callback(void *data)
1798 struct ast_channel *chan = data;
1806 ast_channel_lock(chan);
1807 if (chan->cdr->answer.tv_sec) {
1808 snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->answer.tv_sec);
1809 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
1812 if (chan->cdr->start.tv_sec) {
1813 snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->start.tv_sec);
1814 pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
1816 ast_channel_unlock(chan);
1819 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
1820 bconfig->end_bridge_callback_data = originator;
1823 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
1825 struct ast_tone_zone_sound *ts = NULL;
1827 const char *str = data;
1829 if (ast_strlen_zero(str)) {
1830 ast_debug(1,"Nothing to play\n");
1834 ts = ast_get_indication_tone(chan->zone, str);
1836 if (ts && ts->data[0]) {
1837 res = ast_playtones_start(chan, 0, ts->data, 0);
1843 ts = ast_tone_zone_sound_unref(ts);
1847 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
1853 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
1855 int res = -1; /* default: error */
1856 char *rest, *cur; /* scan the list of destinations */
1857 struct chanlist *outgoing = NULL; /* list of destinations */
1858 struct ast_channel *peer;
1859 int to; /* timeout */
1860 struct cause_args num = { chan, 0, 0, 0 };
1864 struct ast_bridge_config config = { { 0, } };
1865 struct timeval calldurationlimit = { 0, };
1866 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
1867 struct privacy_args pa = {
1870 .status = "INVALIDARGS",
1872 int sentringing = 0, moh = 0;
1873 const char *outbound_group = NULL;
1877 int delprivintro = 0;
1878 AST_DECLARE_APP_ARGS(args,
1880 AST_APP_ARG(timeout);
1881 AST_APP_ARG(options);
1884 struct ast_flags64 opts = { 0, };
1885 char *opt_args[OPT_ARG_ARRAY_SIZE];
1886 struct ast_datastore *datastore = NULL;
1887 int fulldial = 0, num_dialed = 0;
1889 char device_name[AST_CHANNEL_NAME];
1890 char forced_clid_name[AST_MAX_EXTENSION];
1891 char stored_clid_name[AST_MAX_EXTENSION];
1892 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
1894 * \brief Forced CallerID party information to send.
1895 * \note This will not have any malloced strings so do not free it.
1897 struct ast_party_id forced_clid;
1899 * \brief Stored CallerID information if needed.
1901 * \note If OPT_ORIGINAL_CLID set then this is the o option
1902 * CallerID. Otherwise it is the dialplan extension and hint
1905 * \note This will not have any malloced strings so do not free it.
1907 struct ast_party_id stored_clid;
1909 * \brief CallerID party information to store.
1910 * \note This will not have any malloced strings so do not free it.
1912 struct ast_party_caller caller;
1914 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
1915 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
1916 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
1917 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
1918 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
1919 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
1921 if (ast_strlen_zero(data)) {
1922 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1923 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1927 parse = ast_strdupa(data);
1929 AST_STANDARD_APP_ARGS(args, parse);
1931 if (!ast_strlen_zero(args.options) &&
1932 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
1933 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1937 if (ast_strlen_zero(args.peers)) {
1938 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1939 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1943 if (ast_cc_call_init(chan, &ignore_cc)) {
1947 if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
1948 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
1950 if (delprivintro < 0 || delprivintro > 1) {
1951 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
1956 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
1957 opt_args[OPT_ARG_RINGBACK] = NULL;
1960 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
1961 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
1962 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
1965 if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
1966 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
1967 if (!calldurationlimit.tv_sec) {
1968 ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
1969 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1972 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
1975 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
1976 dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
1977 dtmfcalled = strsep(&dtmf_progress, ":");
1978 dtmfcalling = strsep(&dtmf_progress, ":");
1981 if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
1982 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
1986 /* Setup the forced CallerID information to send if used. */
1987 ast_party_id_init(&forced_clid);
1988 force_forwards_only = 0;
1989 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
1990 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
1991 ast_channel_lock(chan);
1992 forced_clid.number.str = ast_strdupa(S_OR(chan->macroexten, chan->exten));
1993 ast_channel_unlock(chan);
1994 forced_clid_name[0] = '\0';
1995 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
1996 sizeof(forced_clid_name), chan);
1997 force_forwards_only = 1;
1999 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2000 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2001 &forced_clid.number.str);
2003 if (!ast_strlen_zero(forced_clid.name.str)) {
2004 forced_clid.name.valid = 1;
2006 if (!ast_strlen_zero(forced_clid.number.str)) {
2007 forced_clid.number.valid = 1;
2010 if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG)
2011 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2012 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2014 forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
2015 if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES)
2016 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2019 pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
2021 forced_clid.number.presentation = pres;
2025 /* Setup the stored CallerID information if needed. */
2026 ast_party_id_init(&stored_clid);
2027 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2028 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2029 ast_channel_lock(chan);
2030 ast_party_id_set_init(&stored_clid, &chan->caller.id);
2031 if (!ast_strlen_zero(chan->caller.id.name.str)) {
2032 stored_clid.name.str = ast_strdupa(chan->caller.id.name.str);
2034 if (!ast_strlen_zero(chan->caller.id.number.str)) {
2035 stored_clid.number.str = ast_strdupa(chan->caller.id.number.str);
2037 if (!ast_strlen_zero(chan->caller.id.subaddress.str)) {
2038 stored_clid.subaddress.str = ast_strdupa(chan->caller.id.subaddress.str);
2040 if (!ast_strlen_zero(chan->caller.id.tag)) {
2041 stored_clid.tag = ast_strdupa(chan->caller.id.tag);
2043 ast_channel_unlock(chan);
2045 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2046 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2047 &stored_clid.number.str);
2048 if (!ast_strlen_zero(stored_clid.name.str)) {
2049 stored_clid.name.valid = 1;
2051 if (!ast_strlen_zero(stored_clid.number.str)) {
2052 stored_clid.number.valid = 1;
2057 * In case the new channel has no preset CallerID number by the
2058 * channel driver, setup the dialplan extension and hint name.
2060 stored_clid_name[0] = '\0';
2061 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2062 sizeof(stored_clid_name), chan);
2063 if (ast_strlen_zero(stored_clid.name.str)) {
2064 stored_clid.name.str = NULL;
2066 stored_clid.name.valid = 1;
2068 ast_channel_lock(chan);
2069 stored_clid.number.str = ast_strdupa(S_OR(chan->macroexten, chan->exten));
2070 stored_clid.number.valid = 1;
2071 ast_channel_unlock(chan);
2074 if (ast_test_flag64(&opts, OPT_RESETCDR) && chan->cdr)
2075 ast_cdr_reset(chan->cdr, NULL);
2076 if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
2077 opt_args[OPT_ARG_PRIVACY] = ast_strdupa(chan->exten);
2079 if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
2080 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2083 res = -1; /* reset default */
2089 /* If a channel group has been specified, get it for use when we create peer channels */
2091 ast_channel_lock(chan);
2092 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2093 outbound_group = ast_strdupa(outbound_group);
2094 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2095 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2096 outbound_group = ast_strdupa(outbound_group);
2098 ast_channel_unlock(chan);
2099 ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_IGNORE_CONNECTEDLINE |
2100 OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
2102 /* loop through the list of dial destinations */
2104 while ((cur = strsep(&rest, "&")) ) {
2105 struct chanlist *tmp;
2106 struct ast_channel *tc; /* channel for this destination */
2107 /* Get a technology/[device:]number pair */
2109 char *interface = ast_strdupa(number);
2110 char *tech = strsep(&number, "/");
2111 /* find if we already dialed this interface */
2112 struct ast_dialed_interface *di;
2113 AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
2115 if (ast_strlen_zero(number)) {
2116 ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
2119 if (!(tmp = ast_calloc(1, sizeof(*tmp))))
2122 ast_copy_flags64(tmp, &opts,
2123 OPT_CANCEL_ELSEWHERE |
2124 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
2125 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
2126 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
2127 OPT_CALLEE_PARK | OPT_CALLER_PARK |
2128 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
2129 OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
2130 ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
2132 ast_copy_string(numsubst, number, sizeof(numsubst));
2133 /* Request the peer */
2135 ast_channel_lock(chan);
2136 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL);
2138 * Seed the chanlist's connected line information with previously
2139 * acquired connected line info from the incoming channel. The
2140 * previously acquired connected line info could have been set
2141 * through the CONNECTED_LINE dialplan function.
2143 ast_party_connected_line_copy(&tmp->connected, &chan->connected);
2144 ast_channel_unlock(chan);
2147 dialed_interfaces = datastore->data;
2149 if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) {
2150 ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n");
2155 datastore->inheritance = DATASTORE_INHERIT_FOREVER;
2157 if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
2158 ast_datastore_free(datastore);
2163 datastore->data = dialed_interfaces;
2164 AST_LIST_HEAD_INIT(dialed_interfaces);
2166 ast_channel_lock(chan);
2167 ast_channel_datastore_add(chan, datastore);
2168 ast_channel_unlock(chan);
2171 AST_LIST_LOCK(dialed_interfaces);
2172 AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
2173 if (!strcasecmp(di->interface, interface)) {
2174 ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n",
2179 AST_LIST_UNLOCK(dialed_interfaces);
2187 /* It is always ok to dial a Local interface. We only keep track of
2188 * which "real" interfaces have been dialed. The Local channel will
2189 * inherit this list so that if it ends up dialing a real interface,
2190 * it won't call one that has already been called. */
2191 if (strcasecmp(tech, "Local")) {
2192 if (!(di = ast_calloc(1, sizeof(*di) + strlen(interface)))) {
2193 AST_LIST_UNLOCK(dialed_interfaces);
2197 strcpy(di->interface, interface);
2199 AST_LIST_LOCK(dialed_interfaces);
2200 AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
2201 AST_LIST_UNLOCK(dialed_interfaces);
2204 tc = ast_request(tech, chan->nativeformats, chan, numsubst, &cause);
2206 /* If we can't, just go on to the next call */
2207 ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
2208 tech, cause, ast_cause2str(cause));
2209 handle_cause(cause, &num);
2210 if (!rest) /* we are on the last destination */
2211 chan->hangupcause = cause;
2213 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2214 if (!ast_cc_callback(chan, tech, numsubst, ast_cc_busy_interface)) {
2215 ast_cc_extension_monitor_add_dialstring(chan, interface, "");
2220 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2222 ast_cc_extension_monitor_add_dialstring(chan, interface, device_name);
2224 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
2226 ast_channel_lock(tc);
2227 while (ast_channel_trylock(chan)) {
2228 CHANNEL_DEADLOCK_AVOIDANCE(tc);
2230 /* Setup outgoing SDP to match incoming one */
2231 if (!outgoing && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2232 ast_rtp_instance_early_bridge_make_compatible(tc, chan);
2235 /* Inherit specially named variables from parent channel */
2236 ast_channel_inherit_variables(chan, tc);
2237 ast_channel_datastore_inherit(chan, tc);
2239 tc->appl = "AppDial";
2240 tc->data = "(Outgoing Line)";
2241 memset(&tc->whentohangup, 0, sizeof(tc->whentohangup));
2243 /* Determine CallerID to store in outgoing channel. */
2244 ast_party_caller_set_init(&caller, &tc->caller);
2245 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2246 caller.id = stored_clid;
2247 ast_channel_set_caller_event(tc, &caller, NULL);
2248 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2249 } else if (ast_strlen_zero(S_COR(tc->caller.id.number.valid,
2250 tc->caller.id.number.str, NULL))) {
2252 * The new channel has no preset CallerID number by the channel
2253 * driver. Use the dialplan extension and hint name.
2255 caller.id = stored_clid;
2256 if (!caller.id.name.valid
2257 && !ast_strlen_zero(S_COR(chan->connected.id.name.valid,
2258 chan->connected.id.name.str, NULL))) {
2260 * No hint name available. We have a connected name supplied by
2261 * the dialplan we can use instead.
2263 caller.id.name.valid = 1;
2264 caller.id.name = chan->connected.id.name;
2266 ast_channel_set_caller_event(tc, &caller, NULL);
2267 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2268 } else if (ast_strlen_zero(S_COR(tc->caller.id.name.valid, tc->caller.id.name.str,
2270 /* The new channel has no preset CallerID name by the channel driver. */
2271 if (!ast_strlen_zero(S_COR(chan->connected.id.name.valid,
2272 chan->connected.id.name.str, NULL))) {
2274 * We have a connected name supplied by the dialplan we can
2277 caller.id.name.valid = 1;
2278 caller.id.name = chan->connected.id.name;
2279 ast_channel_set_caller_event(tc, &caller, NULL);
2283 /* Determine CallerID for outgoing channel to send. */
2284 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2285 struct ast_party_connected_line connected;
2287 ast_party_connected_line_set_init(&connected, &tc->connected);
2288 connected.id = forced_clid;
2289 ast_channel_set_connected_line(tc, &connected, NULL);
2291 ast_connected_line_copy_from_caller(&tc->connected, &chan->caller);
2294 ast_party_redirecting_copy(&tc->redirecting, &chan->redirecting);
2296 tc->dialed.transit_network_select = chan->dialed.transit_network_select;
2298 if (!ast_strlen_zero(chan->accountcode)) {
2299 ast_string_field_set(tc, peeraccount, chan->accountcode);
2301 if (ast_strlen_zero(tc->musicclass))
2302 ast_string_field_set(tc, musicclass, chan->musicclass);
2304 /* Pass ADSI CPE and transfer capability */
2305 tc->adsicpe = chan->adsicpe;
2306 tc->transfercapability = chan->transfercapability;
2308 /* If we have an outbound group, set this peer channel to it */
2310 ast_app_group_set_channel(tc, outbound_group);
2311 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2312 if (ast_test_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE))
2313 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
2315 /* Check if we're forced by configuration */
2316 if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
2317 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
2320 /* Inherit context and extension */
2321 ast_string_field_set(tc, dialcontext, ast_strlen_zero(chan->macrocontext) ? chan->context : chan->macrocontext);
2322 if (!ast_strlen_zero(chan->macroexten))
2323 ast_copy_string(tc->exten, chan->macroexten, sizeof(tc->exten));
2325 ast_copy_string(tc->exten, chan->exten, sizeof(tc->exten));
2327 ast_channel_unlock(tc);
2328 res = ast_call(tc, numsubst, 0); /* Place the call, but don't wait on the answer */
2330 /* Save the info in cdr's that we called them */
2332 ast_cdr_setdestchan(chan->cdr, tc->name);
2334 /* check the results of ast_call */
2336 /* Again, keep going even if there's an error */
2337 ast_debug(1, "ast call on peer returned %d\n", res);
2338 ast_verb(3, "Couldn't call %s/%s\n", tech, numsubst);
2339 if (tc->hangupcause) {
2340 chan->hangupcause = tc->hangupcause;
2342 ast_channel_unlock(chan);
2343 ast_cc_call_failed(chan, tc, interface);
2349 senddialevent(chan, tc, numsubst);
2350 ast_verb(3, "Called %s/%s\n", tech, numsubst);
2351 ast_channel_unlock(chan);
2353 /* Put them in the list of outgoing thingies... We're ready now.
2354 XXX If we're forcibly removed, these outgoing calls won't get
2356 ast_set_flag64(tmp, DIAL_STILLGOING);
2358 tmp->next = outgoing;
2360 /* If this line is up, don't try anybody else */
2361 if (outgoing->chan->_state == AST_STATE_UP)
2365 if (ast_strlen_zero(args.timeout)) {
2368 to = atoi(args.timeout);
2372 ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2378 strcpy(pa.status, "CHANUNAVAIL");
2379 if (fulldial == num_dialed) {
2384 /* Our status will at least be NOANSWER */
2385 strcpy(pa.status, "NOANSWER");
2386 if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
2388 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2389 char *original_moh = ast_strdupa(chan->musicclass);
2390 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
2391 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2392 ast_string_field_set(chan, musicclass, original_moh);
2394 ast_moh_start(chan, NULL, NULL);
2396 ast_indicate(chan, AST_CONTROL_PROGRESS);
2397 } else if (ast_test_flag64(outgoing, OPT_RINGBACK)) {
2398 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2399 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2400 ast_indicate(chan, AST_CONTROL_RINGING);
2403 ast_indicate(chan, AST_CONTROL_PROGRESS);
2406 ast_indicate(chan, AST_CONTROL_RINGING);
2412 peer = wait_for_answer(chan, outgoing, &to, peerflags, opt_args, &pa, &num, &result,
2413 dtmf_progress, ignore_cc, &forced_clid, &stored_clid);
2415 /* The ast_channel_datastore_remove() function could fail here if the
2416 * datastore was moved to another channel during a masquerade. If this is
2417 * the case, don't free the datastore here because later, when the channel
2418 * to which the datastore was moved hangs up, it will attempt to free this
2419 * datastore again, causing a crash
2421 ast_channel_lock(chan);
2422 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL); /* make sure we weren't cleaned up already */
2423 if (datastore && !ast_channel_datastore_remove(chan, datastore)) {
2424 ast_datastore_free(datastore);
2426 ast_channel_unlock(chan);
2430 } else if (to) { /* Musta gotten hung up */
2432 } else { /* Nobody answered, next please? */
2438 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER))
2441 strcpy(pa.status, "ANSWER");
2442 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2443 /* Ah ha! Someone answered within the desired timeframe. Of course after this
2444 we will always return with -1 so that it is hung up properly after the
2446 hanguptree(outgoing, peer, 1);
2448 /* If appropriate, log that we have a destination channel and set the answer time */
2450 ast_cdr_setdestchan(chan->cdr, peer->name);
2451 ast_cdr_setanswer(chan->cdr, peer->cdr->answer);
2454 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", peer->name);
2456 ast_channel_lock(peer);
2457 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
2460 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
2461 ast_channel_unlock(peer);
2463 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
2464 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
2465 ast_channel_sendurl( peer, args.url );
2467 if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
2468 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
2473 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
2477 struct ast_channel *chans[2];
2478 struct ast_channel *active_chan;
2483 /* we need to stream the announcment while monitoring the caller for a hangup */
2485 /* stream the file */
2486 res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
2489 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
2492 ast_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
2493 while (peer->stream) {
2496 ms = ast_sched_wait(peer->sched);
2498 if (ms < 0 && !peer->timingfunc) {
2499 ast_stopstream(peer);
2505 active_chan = ast_waitfor_n(chans, 2, &ms);
2507 struct ast_frame *fr = ast_read(active_chan);
2513 switch(fr->frametype) {
2514 case AST_FRAME_DTMF_END:
2515 digit = fr->subclass.integer;
2516 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
2517 ast_stopstream(peer);
2518 res = ast_senddigit(chan, digit, 0);
2521 case AST_FRAME_CONTROL:
2522 switch (fr->subclass.integer) {
2523 case AST_CONTROL_HANGUP:
2533 /* Ignore all others */
2538 ast_sched_runq(peer->sched);
2540 ast_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
2543 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
2544 /* chan and peer are going into the PBX, they both
2545 * should probably get CDR records. */