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>
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38 #include <sys/signal.h>
40 #include <netinet/in.h>
42 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
43 #include "asterisk/lock.h"
44 #include "asterisk/file.h"
45 #include "asterisk/channel.h"
46 #include "asterisk/pbx.h"
47 #include "asterisk/module.h"
48 #include "asterisk/translate.h"
49 #include "asterisk/say.h"
50 #include "asterisk/config.h"
51 #include "asterisk/features.h"
52 #include "asterisk/musiconhold.h"
53 #include "asterisk/callerid.h"
54 #include "asterisk/utils.h"
55 #include "asterisk/app.h"
56 #include "asterisk/causes.h"
57 #include "asterisk/rtp_engine.h"
58 #include "asterisk/cdr.h"
59 #include "asterisk/manager.h"
60 #include "asterisk/privacy.h"
61 #include "asterisk/stringfields.h"
62 #include "asterisk/global_datastores.h"
63 #include "asterisk/dsp.h"
64 #include "asterisk/cel.h"
65 #include "asterisk/aoc.h"
66 #include "asterisk/ccss.h"
67 #include "asterisk/indications.h"
70 <application name="Dial" language="en_US">
72 Attempt to connect to another device or endpoint and bridge the call.
75 <parameter name="Technology/Resource" required="true" argsep="&">
76 <argument name="Technology/Resource" required="true">
77 <para>Specification of the device(s) to dial. These must be in the format of
78 <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
79 represents a particular channel driver, and <replaceable>Resource</replaceable>
80 represents a resource available to that particular channel driver.</para>
82 <argument name="Technology2/Resource2" required="false" multiple="true">
83 <para>Optional extra devices to dial in parallel</para>
84 <para>If you need more then one enter them as
85 Technology2/Resource2&Technology3/Resourse3&.....</para>
88 <parameter name="timeout" required="false">
89 <para>Specifies the number of seconds we attempt to dial the specified devices</para>
90 <para>If not specified, this defaults to 136 years.</para>
92 <parameter name="options" required="false">
95 <argument name="x" required="true">
96 <para>The file to play to the called party</para>
98 <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
101 <para>Immediately answer the calling channel when the called channel answers in
102 all cases. Normally, the calling channel is answered when the called channel
103 answers, but when options such as A() and M() are used, the calling channel is
104 not answered until all actions on the called channel (such as playing an
105 announcement) are completed. This option can be used to answer the calling
106 channel before doing anything on the called channel. You will rarely need to use
107 this option, the default behavior is adequate in most cases.</para>
110 <para>Reset the call detail record (CDR) for this call.</para>
113 <para>If the Dial() application cancels this call, always set the flag to tell the channel
114 driver that the call is answered elsewhere.</para>
117 <para>Allow the calling user to dial a 1 digit extension while waiting for
118 a call to be answered. Exit to that extension if it exists in the
119 current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
122 <option name="D" argsep=":">
123 <argument name="called" />
124 <argument name="calling" />
125 <argument name="progress" />
126 <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
127 party has answered, but before the call gets bridged. The
128 <replaceable>called</replaceable> DTMF string is sent to the called party, and the
129 <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
130 can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
131 immediately after receiving a PROGRESS message.</para>
134 <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
137 <argument name="x" required="false" />
138 <para>If <replaceable>x</replaceable> is not provided, force the callerid of the <emphasis>calling</emphasis>
139 channel to be set as the extension associated with the channel using a dialplan <literal>hint</literal>.
140 For example, some PSTNs do not allow CallerID to be set to anything
141 other than the number assigned to the caller. If <replaceable>x</replaceable> is provided, though, then
142 this option behaves quite differently. Any outgoing channel created will have its connected party information
143 set to <replaceable>x</replaceable></para>
145 <option name="F" argsep="^">
146 <argument name="context" required="false" />
147 <argument name="exten" required="false" />
148 <argument name="priority" required="true" />
149 <para>When the caller hangs up, transfer the called party
150 to the specified destination and continue execution at that location.</para>
153 <para>Proceed with dialplan execution at the next priority in the current extension if the
154 source channel hangs up.</para>
157 <para>Proceed with dialplan execution at the next priority in the current extension if the
158 destination channel hangs up.</para>
160 <option name="G" argsep="^">
161 <argument name="context" required="false" />
162 <argument name="exten" required="false" />
163 <argument name="priority" required="true" />
164 <para>If the call is answered, transfer the calling party to
165 the specified <replaceable>priority</replaceable> and the called party to the specified
166 <replaceable>priority</replaceable> plus one.</para>
168 <para>You cannot use any additional action post answer options in conjunction with this option.</para>
172 <para>Allow the called party to hang up by sending the <literal>*</literal> DTMF digit.</para>
175 <para>Allow the calling party to hang up by hitting the <literal>*</literal> DTMF digit.</para>
178 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
181 <para>Asterisk will ignore any connected line update requests or redirecting party update
182 requests it may receiveon this dial attempt.</para>
185 <para>Allow the called party to enable parking of the call by sending
186 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
189 <para>Allow the calling party to enable parking of the call by sending
190 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
192 <option name="L" argsep=":">
193 <argument name="x" required="true">
194 <para>Maximum call time, in milliseconds</para>
197 <para>Warning time, in milliseconds</para>
200 <para>Repeat time, in milliseconds</para>
202 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
203 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
204 <para>This option is affected by the following variables:</para>
206 <variable name="LIMIT_PLAYAUDIO_CALLER">
207 <value name="yes" default="true" />
209 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
211 <variable name="LIMIT_PLAYAUDIO_CALLEE">
213 <value name="no" default="true"/>
214 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
216 <variable name="LIMIT_TIMEOUT_FILE">
217 <value name="filename"/>
218 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
219 If not set, the time remaining will be announced.</para>
221 <variable name="LIMIT_CONNECT_FILE">
222 <value name="filename"/>
223 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
224 If not set, the time remaining will be announced.</para>
226 <variable name="LIMIT_WARNING_FILE">
227 <value name="filename"/>
228 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
229 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
234 <argument name="class" required="false"/>
235 <para>Provide hold music to the calling party until a requested
236 channel answers. A specific music on hold <replaceable>class</replaceable>
237 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
239 <option name="M" argsep="^">
240 <argument name="macro" required="true">
241 <para>Name of the macro that should be executed.</para>
243 <argument name="arg" multiple="true">
244 <para>Macro arguments</para>
246 <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
247 before connecting to the calling channel. Arguments can be specified to the Macro
248 using <literal>^</literal> as a delimiter. The macro can set the variable
249 <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
250 finished executing:</para>
252 <variable name="MACRO_RESULT">
253 <para>If set, this action will be taken after the macro finished executing.</para>
255 Hangup both legs of the call
257 <value name="CONGESTION">
258 Behave as if line congestion was encountered
261 Behave as if a busy signal was encountered
263 <value name="CONTINUE">
264 Hangup the called party and allow the calling party to continue dialplan execution at the next priority
266 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
267 <value name="GOTO:<context>^<exten>^<priority>">
268 Transfer the call to the specified destination.
273 <para>You cannot use any additional action post answer options in conjunction
274 with this option. Also, pbx services are not run on the peer (called) channel,
275 so you will not be able to set timeouts via the TIMEOUT() function in this macro.</para>
277 <warning><para>Be aware of the limitations that macros have, specifically with regards to use of
278 the <literal>WaitExten</literal> application. For more information, see the documentation for
279 Macro()</para></warning>
282 <argument name="delete">
283 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
284 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
286 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
287 always be deleted.</para>
289 <para>This option is a modifier for the call screening/privacy mode. (See the
290 <literal>p</literal> and <literal>P</literal> options.) It specifies
291 that no introductions are to be saved in the <directory>priv-callerintros</directory>
295 <para>This option is a modifier for the call screening/privacy mode. It specifies
296 that if Caller*ID is present, do not screen the call.</para>
299 <para>Specify that the Caller*ID that was present on the <emphasis>calling</emphasis> channel
300 be set as the Caller*ID on the <emphasis>called</emphasis> channel. This was the
301 behavior of Asterisk 1.0 and earlier.</para>
304 <argument name="mode">
305 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
306 the originator hanging up will cause the phone to ring back immediately.</para>
307 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
308 flashes the trunk, it will ring their phone back.</para>
310 <para>Enables <emphasis>operator services</emphasis> mode. This option only
311 works when bridging a DAHDI channel to another DAHDI channel
312 only. if specified on non-DAHDI interfaces, it will be ignored.
313 When the destination answers (presumably an operator services
314 station), the originator no longer has control of their line.
315 They may hang up, but the switch will not release their line
316 until the destination party (the operator) hangs up.</para>
319 <para>This option enables screening mode. This is basically Privacy mode
320 without memory.</para>
323 <argument name="x" />
324 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
325 it is provided. The current extension is used if a database family/key is not specified.</para>
328 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
329 party until the called channel has answered.</para>
330 <argument name="tone" required="false">
331 <para>Indicate progress to calling party. Send audio 'tone' from indications.conf</para>
335 <argument name="x" required="true" />
336 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
337 answered the call.</para>
340 <argument name="x" required="true" />
341 <para>Force the outgoing callerid tag parameter to be set to the string <replaceable>x</replaceable></para>
344 <para>Allow the called party to transfer the calling party by sending the
345 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
346 transfers initiated by other methods.</para>
349 <para>Allow the calling party to transfer the called party by sending the
350 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
351 transfers initiated by other methods.</para>
353 <option name="U" argsep="^">
354 <argument name="x" required="true">
355 <para>Name of the subroutine to execute via Gosub</para>
357 <argument name="arg" multiple="true" required="false">
358 <para>Arguments for the Gosub routine</para>
360 <para>Execute via Gosub the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
361 to the calling channel. Arguments can be specified to the Gosub
362 using <literal>^</literal> as a delimiter. The Gosub routine can set the variable
363 <variable>GOSUB_RESULT</variable> to specify the following actions after the Gosub returns.</para>
365 <variable name="GOSUB_RESULT">
367 Hangup both legs of the call.
369 <value name="CONGESTION">
370 Behave as if line congestion was encountered.
373 Behave as if a busy signal was encountered.
375 <value name="CONTINUE">
376 Hangup the called party and allow the calling party
377 to continue dialplan execution at the next priority.
379 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
380 <value name="GOTO:<context>^<exten>^<priority>">
381 Transfer the call to the specified priority. Optionally, an extension, or
382 extension and priority can be specified.
387 <para>You cannot use any additional action post answer options in conjunction
388 with this option. Also, pbx services are not run on the peer (called) channel,
389 so you will not be able to set timeouts via the TIMEOUT() function in this routine.</para>
393 <argument name = "x" required="true">
394 <para>Force the outgoing callerid presentation indicator parameter to be set
395 to one of the values passed in <replaceable>x</replaceable>:
396 <literal>allowed_not_screened</literal>
397 <literal>allowed_passed_screen</literal>
398 <literal>allowed_failed_screen</literal>
399 <literal>allowed</literal>
400 <literal>prohib_not_screened</literal>
401 <literal>prohib_passed_screen</literal>
402 <literal>prohib_failed_screen</literal>
403 <literal>prohib</literal>
404 <literal>unavailable</literal></para>
408 <para>Allow the called party to enable recording of the call by sending
409 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
412 <para>Allow the calling party to enable recording of the call by sending
413 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
416 <para>Allow the called party to enable recording of the call by sending
417 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
420 <para>Allow the calling party to enable recording of the call by sending
421 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
424 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
428 <parameter name="URL">
429 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
433 <para>This application will place calls to one or more specified channels. As soon
434 as one of the requested channels answers, the originating channel will be
435 answered, if it has not already been answered. These two channels will then
436 be active in a bridged call. All other channels that were requested will then
439 <para>Unless there is a timeout specified, the Dial application will wait
440 indefinitely until one of the called channels answers, the user hangs up, or
441 if all of the called channels are busy or unavailable. Dialplan executing will
442 continue if no requested channels can be called, or if the timeout expires.
443 This application will report normal termination if the originating channel
444 hangs up, or if the call is bridged and either of the parties in the bridge
445 ends the call.</para>
446 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
447 application will be put into that group (as in Set(GROUP()=...).
448 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
449 application will be put into that group (as in Set(GROUP()=...). Unlike OUTBOUND_GROUP,
450 however, the variable will be unset after use.</para>
452 <para>This application sets the following channel variables:</para>
454 <variable name="DIALEDTIME">
455 <para>This is the time from dialing a channel until when it is disconnected.</para>
457 <variable name="ANSWEREDTIME">
458 <para>This is the amount of time for actual call.</para>
460 <variable name="DIALSTATUS">
461 <para>This is the status of the call</para>
462 <value name="CHANUNAVAIL" />
463 <value name="CONGESTION" />
464 <value name="NOANSWER" />
465 <value name="BUSY" />
466 <value name="ANSWER" />
467 <value name="CANCEL" />
468 <value name="DONTCALL">
469 For the Privacy and Screening Modes.
470 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
472 <value name="TORTURE">
473 For the Privacy and Screening Modes.
474 Will be set if the called party chooses to send the calling party to the 'torture' script.
476 <value name="INVALIDARGS" />
481 <application name="RetryDial" language="en_US">
483 Place a call, retrying on failure allowing an optional exit extension.
486 <parameter name="announce" required="true">
487 <para>Filename of sound that will be played when no channel can be reached</para>
489 <parameter name="sleep" required="true">
490 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
492 <parameter name="retries" required="true">
493 <para>Number of retries</para>
494 <para>When this is reached flow will continue at the next priority in the dialplan</para>
496 <parameter name="dialargs" required="true">
497 <para>Same format as arguments provided to the Dial application</para>
501 <para>This application will attempt to place a call using the normal Dial application.
502 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
503 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
504 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
505 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
506 While waiting to retry a call, a 1 digit extension may be dialed. If that
507 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
508 one, The call will jump to that extension immediately.
509 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
510 to the Dial application.</para>
515 static const char app[] = "Dial";
516 static const char rapp[] = "RetryDial";
519 OPT_ANNOUNCE = (1 << 0),
520 OPT_RESETCDR = (1 << 1),
521 OPT_DTMF_EXIT = (1 << 2),
522 OPT_SENDDTMF = (1 << 3),
523 OPT_FORCECLID = (1 << 4),
524 OPT_GO_ON = (1 << 5),
525 OPT_CALLEE_HANGUP = (1 << 6),
526 OPT_CALLER_HANGUP = (1 << 7),
527 OPT_ORIGINAL_CLID = (1 << 8),
528 OPT_DURATION_LIMIT = (1 << 9),
529 OPT_MUSICBACK = (1 << 10),
530 OPT_CALLEE_MACRO = (1 << 11),
531 OPT_SCREEN_NOINTRO = (1 << 12),
532 OPT_SCREEN_NOCALLERID = (1 << 13),
533 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
534 OPT_SCREENING = (1 << 15),
535 OPT_PRIVACY = (1 << 16),
536 OPT_RINGBACK = (1 << 17),
537 OPT_DURATION_STOP = (1 << 18),
538 OPT_CALLEE_TRANSFER = (1 << 19),
539 OPT_CALLER_TRANSFER = (1 << 20),
540 OPT_CALLEE_MONITOR = (1 << 21),
541 OPT_CALLER_MONITOR = (1 << 22),
542 OPT_GOTO = (1 << 23),
543 OPT_OPERMODE = (1 << 24),
544 OPT_CALLEE_PARK = (1 << 25),
545 OPT_CALLER_PARK = (1 << 26),
546 OPT_IGNORE_FORWARDING = (1 << 27),
547 OPT_CALLEE_GOSUB = (1 << 28),
548 OPT_CALLEE_MIXMONITOR = (1 << 29),
549 OPT_CALLER_MIXMONITOR = (1 << 30),
550 OPT_CALLER_ANSWER = (1 << 31),
553 #define DIAL_STILLGOING (1 << 31)
554 #define DIAL_NOFORWARDHTML ((uint64_t)1 << 32) /* flags are now 64 bits, so keep it up! */
555 #define DIAL_CALLERID_ABSENT ((uint64_t)1 << 33) /* TRUE if caller id is not available for connected line. */
556 #define OPT_CANCEL_ELSEWHERE ((uint64_t)1 << 34)
557 #define OPT_PEER_H ((uint64_t)1 << 35)
558 #define OPT_CALLEE_GO_ON ((uint64_t)1 << 36)
559 #define OPT_CANCEL_TIMEOUT ((uint64_t)1 << 37)
560 #define OPT_FORCE_CID_TAG ((uint64_t)1 << 38)
561 #define OPT_FORCE_CID_PRES ((uint64_t)1 << 39)
564 OPT_ARG_ANNOUNCE = 0,
567 OPT_ARG_DURATION_LIMIT,
569 OPT_ARG_CALLEE_MACRO,
571 OPT_ARG_CALLEE_GOSUB,
572 OPT_ARG_CALLEE_GO_ON,
574 OPT_ARG_DURATION_STOP,
576 OPT_ARG_SCREEN_NOINTRO,
578 OPT_ARG_FORCE_CID_TAG,
579 OPT_ARG_FORCE_CID_PRES,
580 /* note: this entry _MUST_ be the last one in the enum */
584 AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
585 AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
586 AST_APP_OPTION('a', OPT_CALLER_ANSWER),
587 AST_APP_OPTION('C', OPT_RESETCDR),
588 AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
589 AST_APP_OPTION('d', OPT_DTMF_EXIT),
590 AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
591 AST_APP_OPTION('e', OPT_PEER_H),
592 AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
593 AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
594 AST_APP_OPTION('g', OPT_GO_ON),
595 AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
596 AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
597 AST_APP_OPTION('H', OPT_CALLER_HANGUP),
598 AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
599 AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
600 AST_APP_OPTION('k', OPT_CALLEE_PARK),
601 AST_APP_OPTION('K', OPT_CALLER_PARK),
602 AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
603 AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
604 AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
605 AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
606 AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
607 AST_APP_OPTION('o', OPT_ORIGINAL_CLID),
608 AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
609 AST_APP_OPTION('p', OPT_SCREENING),
610 AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
611 AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
612 AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
613 AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG),
614 AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES),
615 AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
616 AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
617 AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
618 AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
619 AST_APP_OPTION('W', OPT_CALLER_MONITOR),
620 AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
621 AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
622 AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
625 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
626 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
627 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
628 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
629 !chan->audiohooks && !peer->audiohooks)
632 * The list of active channels
635 struct chanlist *next;
636 struct ast_channel *chan;
638 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
639 struct ast_party_connected_line connected;
640 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
641 unsigned int pending_connected_update:1;
642 struct ast_aoc_decoded *aoc_s_rate_list;
645 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode);
647 static void chanlist_free(struct chanlist *outgoing)
649 ast_party_connected_line_free(&outgoing->connected);
650 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
654 static void hanguptree(struct chanlist *outgoing, struct ast_channel *exception, int answered_elsewhere)
656 /* Hang up a tree of stuff */
659 /* Hangup any existing lines we have open */
660 if (outgoing->chan && (outgoing->chan != exception)) {
661 if (answered_elsewhere) {
662 /* The flag is used for local channel inheritance and stuff */
663 ast_set_flag(outgoing->chan, AST_FLAG_ANSWERED_ELSEWHERE);
664 /* This is for the channel drivers */
665 outgoing->chan->hangupcause = AST_CAUSE_ANSWERED_ELSEWHERE;
667 ast_hangup(outgoing->chan);
670 outgoing = outgoing->next;
675 #define AST_MAX_WATCHERS 256
678 * argument to handle_cause() and other functions.
681 struct ast_channel *chan;
687 static void handle_cause(int cause, struct cause_args *num)
689 struct ast_cdr *cdr = num->chan->cdr;
698 case AST_CAUSE_CONGESTION:
704 case AST_CAUSE_NO_ROUTE_DESTINATION:
705 case AST_CAUSE_UNREGISTERED:
711 case AST_CAUSE_NO_ANSWER:
713 ast_cdr_noanswer(cdr);
716 case AST_CAUSE_NORMAL_CLEARING:
725 /*! \brief free the buffer if allocated, and set the pointer to the second arg */
726 #define S_REPLACE(s, new_val) \
732 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
734 char rexten[2] = { exten, '\0' };
737 if (!ast_goto_if_exists(chan, context, rexten, pri))
740 if (!ast_goto_if_exists(chan, chan->context, rexten, pri))
742 else if (!ast_strlen_zero(chan->macrocontext)) {
743 if (!ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
750 /* do not call with chan lock held */
751 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
756 ast_channel_lock(chan);
757 context = ast_strdupa(S_OR(chan->macrocontext, chan->context));
758 exten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
759 ast_channel_unlock(chan);
761 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
764 static void senddialevent(struct ast_channel *src, struct ast_channel *dst, const char *dialstring)
766 struct ast_channel *chans[] = { src, dst };
767 ast_manager_event_multichan(EVENT_FLAG_CALL, "Dial", 2, chans,
768 "SubEvent: Begin\r\n"
770 "Destination: %s\r\n"
771 "CallerIDNum: %s\r\n"
772 "CallerIDName: %s\r\n"
774 "DestUniqueID: %s\r\n"
775 "Dialstring: %s\r\n",
776 src->name, dst->name, S_OR(src->cid.cid_num, "<unknown>"),
777 S_OR(src->cid.cid_name, "<unknown>"), src->uniqueid,
778 dst->uniqueid, dialstring ? dialstring : "");
781 static void senddialendevent(struct ast_channel *src, const char *dialstatus)
783 ast_manager_event(src, EVENT_FLAG_CALL, "Dial",
787 "DialStatus: %s\r\n",
788 src->name, src->uniqueid, dialstatus);
792 * helper function for wait_for_answer()
794 * XXX this code is highly suspicious, as it essentially overwrites
795 * the outgoing channel without properly deleting it.
797 * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
799 static void do_forward(struct chanlist *o,
800 struct cause_args *num, struct ast_flags64 *peerflags, int single, int *to)
803 struct ast_channel *original = o->chan;
804 struct ast_channel *c = o->chan; /* the winner */
805 struct ast_channel *in = num->chan; /* the input channel */
810 ast_copy_string(tmpchan, c->call_forward, sizeof(tmpchan));
811 if ((stuff = strchr(tmpchan, '/'))) {
815 const char *forward_context;
817 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
818 if (ast_strlen_zero(forward_context)) {
819 forward_context = NULL;
821 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", c->call_forward, forward_context ? forward_context : c->context);
822 ast_channel_unlock(c);
827 ast_cel_report_event(in, AST_CEL_FORWARD, NULL, c->call_forward, NULL);
829 /* Before processing channel, go ahead and check for forwarding */
830 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
831 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
832 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
833 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
835 cause = AST_CAUSE_BUSY;
837 /* Setup parameters */
838 c = o->chan = ast_request(tech, in->nativeformats, in, stuff, &cause);
841 ast_channel_make_compatible(o->chan, in);
842 ast_channel_inherit_variables(in, o->chan);
843 ast_channel_datastore_inherit(in, o->chan);
844 /* When a call is forwarded, we don't want to track new interfaces
845 * dialed for CC purposes. Setting the done flag will ensure that
846 * any Dial operations that happen later won't record CC interfaces.
848 ast_ignore_cc(o->chan);
849 ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", o->chan->name);
851 ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
854 ast_clear_flag64(o, DIAL_STILLGOING);
855 handle_cause(cause, num);
856 ast_hangup(original);
858 if (single && CAN_EARLY_BRIDGE(peerflags, c, in)) {
859 ast_rtp_instance_early_bridge_make_compatible(c, in);
862 ast_channel_set_redirecting(c, &original->redirecting);
864 while (ast_channel_trylock(in)) {
865 CHANNEL_DEADLOCK_AVOIDANCE(c);
867 if (ast_strlen_zero(c->redirecting.from.number)) {
869 * The call was not previously redirected so it is
870 * now redirected from this number.
872 S_REPLACE(c->redirecting.from.number,
873 ast_strdup(S_OR(in->macroexten, in->exten)));
876 c->cid.cid_tns = in->cid.cid_tns;
878 if (ast_test_flag64(o, OPT_FORCECLID)) {
879 S_REPLACE(c->cid.cid_num, ast_strdup(S_OR(in->macroexten, in->exten)));
880 S_REPLACE(c->cid.cid_name, NULL);
881 ast_string_field_set(c, accountcode, c->accountcode);
883 ast_party_caller_copy(&c->cid, &in->cid);
884 ast_string_field_set(c, accountcode, in->accountcode);
886 ast_party_connected_line_copy(&c->connected, &original->connected);
888 c->data = "(Outgoing Line)";
890 * We must unlock c before calling ast_channel_redirecting_macro, because
891 * we put c into autoservice there. That is pretty much a guaranteed
892 * deadlock. This is why the handling of c's lock may seem a bit unusual
895 ast_channel_unlock(c);
896 if (ast_channel_redirecting_macro(c, in, &c->redirecting, 1, 0)) {
897 while (ast_channel_trylock(c)) {
898 CHANNEL_DEADLOCK_AVOIDANCE(in);
900 ast_channel_update_redirecting(in, &c->redirecting);
901 ast_channel_unlock(c);
904 ast_clear_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE);
905 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
909 ast_channel_unlock(in);
911 if (ast_call(c, tmpchan, 0)) {
912 ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
913 ast_clear_flag64(o, DIAL_STILLGOING);
914 ast_hangup(original);
920 while (ast_channel_trylock(in)) {
921 CHANNEL_DEADLOCK_AVOIDANCE(c);
923 senddialevent(in, c, stuff);
924 if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
925 char cidname[AST_MAX_EXTENSION] = "";
926 const char *tmpexten;
927 tmpexten = ast_strdupa(S_OR(in->macroexten, in->exten));
928 ast_channel_unlock(in);
929 ast_channel_unlock(c);
930 ast_set_callerid(c, tmpexten, get_cid_name(cidname, sizeof(cidname), in), NULL);
932 ast_channel_unlock(in);
933 ast_channel_unlock(c);
935 /* Hangup the original channel now, in case we needed it */
936 ast_hangup(original);
939 ast_indicate(in, -1);
944 /* argument used for some functions. */
945 struct privacy_args {
949 char privintro[1024];
953 static struct ast_channel *wait_for_answer(struct ast_channel *in,
954 struct chanlist *outgoing, int *to, struct ast_flags64 *peerflags,
956 struct privacy_args *pa,
957 const struct cause_args *num_in, int *result, char *dtmf_progress,
960 struct cause_args num = *num_in;
961 int prestart = num.busy + num.congestion + num.nochan;
963 struct ast_channel *peer = NULL;
964 /* single is set if only one destination is enabled */
965 int single = outgoing && !outgoing->next;
967 struct chanlist *epollo;
969 struct ast_party_connected_line connected_caller;
970 struct ast_str *featurecode = ast_str_alloca(FEATURE_MAX_LEN + 1);
971 int cc_recall_core_id;
973 int cc_frame_received = 0;
976 ast_party_connected_line_init(&connected_caller);
978 /* Turn off hold music, etc */
979 if (!ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK)) {
980 ast_deactivate_generator(in);
981 /* If we are calling a single channel, and not providing ringback or music, */
982 /* then, make them compatible for in-band tone purpose */
983 ast_channel_make_compatible(outgoing->chan, in);
986 if (!ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE) && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
987 ast_channel_lock(outgoing->chan);
988 ast_connected_line_copy_from_caller(&connected_caller, &outgoing->chan->cid);
989 ast_channel_unlock(outgoing->chan);
990 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
991 ast_channel_update_connected_line(in, &connected_caller);
992 ast_party_connected_line_free(&connected_caller);
996 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
999 for (epollo = outgoing; epollo; epollo = epollo->next)
1000 ast_poll_channel_add(in, epollo->chan);
1003 while (*to && !peer) {
1005 int pos = 0; /* how many channels do we handle */
1006 int numlines = prestart;
1007 struct ast_channel *winner;
1008 struct ast_channel *watchers[AST_MAX_WATCHERS];
1010 watchers[pos++] = in;
1011 for (o = outgoing; o; o = o->next) {
1012 /* Keep track of important channels */
1013 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1014 watchers[pos++] = o->chan;
1017 if (pos == 1) { /* only the input channel is available */
1018 if (numlines == (num.busy + num.congestion + num.nochan)) {
1019 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1021 strcpy(pa->status, "BUSY");
1022 else if (num.congestion)
1023 strcpy(pa->status, "CONGESTION");
1024 else if (num.nochan)
1025 strcpy(pa->status, "CHANUNAVAIL");
1027 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1031 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1035 winner = ast_waitfor_n(watchers, pos, to);
1036 for (o = outgoing; o; o = o->next) {
1037 struct ast_frame *f;
1038 struct ast_channel *c = o->chan;
1042 if (ast_test_flag64(o, DIAL_STILLGOING) && c->_state == AST_STATE_UP) {
1044 ast_verb(3, "%s answered %s\n", c->name, in->name);
1045 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1046 if (o->pending_connected_update) {
1047 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1048 ast_channel_update_connected_line(in, &o->connected);
1050 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1051 ast_channel_lock(c);
1052 ast_connected_line_copy_from_caller(&connected_caller, &c->cid);
1053 ast_channel_unlock(c);
1054 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1055 ast_channel_update_connected_line(in, &connected_caller);
1056 ast_party_connected_line_free(&connected_caller);
1059 if (o->aoc_s_rate_list) {
1060 size_t encoded_size;
1061 struct ast_aoc_encoded *encoded;
1062 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1063 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1064 ast_aoc_destroy_encoded(encoded);
1068 ast_copy_flags64(peerflags, o,
1069 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1070 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1071 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1072 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1073 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1074 DIAL_NOFORWARDHTML);
1075 ast_string_field_set(c, dialcontext, "");
1076 ast_copy_string(c->exten, "", sizeof(c->exten));
1082 /* here, o->chan == c == winner */
1083 if (!ast_strlen_zero(c->call_forward)) {
1084 pa->sentringing = 0;
1085 if (!ignore_cc && (f = ast_read(c))) {
1086 if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
1087 /* This channel is forwarding the call, and is capable of CC, so
1088 * be sure to add the new device interface to the list
1090 ast_handle_cc_control_frame(in, c, f->data.ptr);
1094 do_forward(o, &num, peerflags, single, to);
1097 f = ast_read(winner);
1099 in->hangupcause = c->hangupcause;
1101 ast_poll_channel_del(in, c);
1105 ast_clear_flag64(o, DIAL_STILLGOING);
1106 handle_cause(in->hangupcause, &num);
1109 if (f->frametype == AST_FRAME_CONTROL) {
1110 switch (f->subclass.integer) {
1111 case AST_CONTROL_ANSWER:
1112 /* This is our guy if someone answered. */
1114 ast_verb(3, "%s answered %s\n", c->name, in->name);
1115 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1116 if (o->pending_connected_update) {
1117 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1118 ast_channel_update_connected_line(in, &o->connected);
1120 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1121 ast_channel_lock(c);
1122 ast_connected_line_copy_from_caller(&connected_caller, &c->cid);
1123 ast_channel_unlock(c);
1124 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1125 ast_channel_update_connected_line(in, &connected_caller);
1126 ast_party_connected_line_free(&connected_caller);
1129 if (o->aoc_s_rate_list) {
1130 size_t encoded_size;
1131 struct ast_aoc_encoded *encoded;
1132 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1133 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1134 ast_aoc_destroy_encoded(encoded);
1139 peer->cdr->answer = ast_tvnow();
1140 peer->cdr->disposition = AST_CDR_ANSWERED;
1142 ast_copy_flags64(peerflags, o,
1143 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1144 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1145 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1146 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1147 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1148 DIAL_NOFORWARDHTML);
1149 ast_string_field_set(c, dialcontext, "");
1150 ast_copy_string(c->exten, "", sizeof(c->exten));
1151 if (CAN_EARLY_BRIDGE(peerflags, in, peer))
1152 /* Setup early bridge if appropriate */
1153 ast_channel_early_bridge(in, peer);
1155 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1156 in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
1157 c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
1159 case AST_CONTROL_BUSY:
1160 ast_verb(3, "%s is busy\n", c->name);
1161 in->hangupcause = c->hangupcause;
1164 ast_clear_flag64(o, DIAL_STILLGOING);
1165 handle_cause(AST_CAUSE_BUSY, &num);
1167 case AST_CONTROL_CONGESTION:
1168 ast_verb(3, "%s is circuit-busy\n", c->name);
1169 in->hangupcause = c->hangupcause;
1172 ast_clear_flag64(o, DIAL_STILLGOING);
1173 handle_cause(AST_CAUSE_CONGESTION, &num);
1175 case AST_CONTROL_RINGING:
1176 /* This is a tricky area to get right when using a native
1177 * CC agent. The reason is that we do the best we can to send only a
1178 * single ringing notification to the caller.
1180 * Call completion complicates the logic used here. CCNR is typically
1181 * offered during a ringing message. Let's say that party A calls
1182 * parties B, C, and D. B and C do not support CC requests, but D
1183 * does. If we were to receive a ringing notification from B before
1184 * the others, then we would end up sending a ringing message to
1185 * A with no CCNR offer present.
1187 * The approach that we have taken is that if we receive a ringing
1188 * response from a party and no CCNR offer is present, we need to
1189 * wait. Specifically, we need to wait until either a) a called party
1190 * offers CCNR in its ringing response or b) all called parties have
1191 * responded in some way to our call and none offers CCNR.
1193 * The drawback to this is that if one of the parties has a delayed
1194 * response or, god forbid, one just plain doesn't respond to our
1195 * outgoing call, then this will result in a significant delay between
1196 * when the caller places the call and hears ringback.
1198 * Note also that if CC is disabled for this call, then it is perfectly
1199 * fine for ringing frames to get sent through.
1202 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1203 ast_verb(3, "%s is ringing\n", c->name);
1204 /* Setup early media if appropriate */
1205 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1206 ast_channel_early_bridge(in, c);
1207 if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
1208 ast_indicate(in, AST_CONTROL_RINGING);
1213 case AST_CONTROL_PROGRESS:
1214 ast_verb(3, "%s is making progress passing it to %s\n", c->name, in->name);
1215 /* Setup early media if appropriate */
1216 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1217 ast_channel_early_bridge(in, c);
1218 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1219 if (single || (!single && !pa->sentringing)) {
1220 ast_indicate(in, AST_CONTROL_PROGRESS);
1222 if(!ast_strlen_zero(dtmf_progress)) {
1223 ast_verb(3, "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n", dtmf_progress);
1224 ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1227 case AST_CONTROL_VIDUPDATE:
1228 ast_verb(3, "%s requested a video update, passing it to %s\n", c->name, in->name);
1229 ast_indicate(in, AST_CONTROL_VIDUPDATE);
1231 case AST_CONTROL_SRCUPDATE:
1232 ast_verb(3, "%s requested a source update, passing it to %s\n", c->name, in->name);
1233 ast_indicate(in, AST_CONTROL_SRCUPDATE);
1235 case AST_CONTROL_CONNECTED_LINE:
1236 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1237 ast_verb(3, "Connected line update to %s prevented.\n", in->name);
1238 } else if (!single) {
1239 struct ast_party_connected_line connected;
1240 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", c->name, in->name);
1241 ast_party_connected_line_set_init(&connected, &o->connected);
1242 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
1243 ast_party_connected_line_set(&o->connected, &connected);
1244 ast_party_connected_line_free(&connected);
1245 o->pending_connected_update = 1;
1247 if (ast_channel_connected_line_macro(c, in, f, 1, 1)) {
1248 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
1252 case AST_CONTROL_AOC:
1254 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1255 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1256 ast_aoc_destroy_decoded(o->aoc_s_rate_list);
1257 o->aoc_s_rate_list = decoded;
1259 ast_aoc_destroy_decoded(decoded);
1263 case AST_CONTROL_REDIRECTING:
1264 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1265 ast_verb(3, "Redirecting update to %s prevented.\n", in->name);
1267 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", c->name, in->name);
1268 if (ast_channel_redirecting_macro(c, in, f, 1, 1)) {
1269 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
1271 pa->sentringing = 0;
1274 case AST_CONTROL_PROCEEDING:
1275 ast_verb(3, "%s is proceeding passing it to %s\n", c->name, in->name);
1276 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1277 ast_channel_early_bridge(in, c);
1278 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1279 ast_indicate(in, AST_CONTROL_PROCEEDING);
1281 case AST_CONTROL_HOLD:
1282 ast_verb(3, "Call on %s placed on hold\n", c->name);
1283 ast_indicate(in, AST_CONTROL_HOLD);
1285 case AST_CONTROL_UNHOLD:
1286 ast_verb(3, "Call on %s left from hold\n", c->name);
1287 ast_indicate(in, AST_CONTROL_UNHOLD);
1289 case AST_CONTROL_OFFHOOK:
1290 case AST_CONTROL_FLASH:
1291 /* Ignore going off hook and flash */
1293 case AST_CONTROL_CC:
1295 ast_handle_cc_control_frame(in, c, f->data.ptr);
1296 cc_frame_received = 1;
1300 if (!ast_test_flag64(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
1301 ast_verb(3, "%s stopped sounds\n", c->name);
1302 ast_indicate(in, -1);
1303 pa->sentringing = 0;
1307 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1309 } else if (single) {
1310 switch (f->frametype) {
1311 case AST_FRAME_VOICE:
1312 case AST_FRAME_IMAGE:
1313 case AST_FRAME_TEXT:
1314 if (ast_write(in, f)) {
1315 ast_log(LOG_WARNING, "Unable to write frame\n");
1318 case AST_FRAME_HTML:
1319 if (!ast_test_flag64(outgoing, DIAL_NOFORWARDHTML) && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1320 ast_log(LOG_WARNING, "Unable to send URL\n");
1330 struct ast_frame *f = ast_read(in);
1332 if (f && (f->frametype != AST_FRAME_VOICE))
1333 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1334 else if (!f || (f->frametype != AST_FRAME_VOICE))
1335 printf("Hangup received on %s\n", in->name);
1337 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1340 strcpy(pa->status, "CANCEL");
1341 ast_cdr_noanswer(in->cdr);
1343 if (f->data.uint32) {
1344 in->hangupcause = f->data.uint32;
1349 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1354 /* now f is guaranteed non-NULL */
1355 if (f->frametype == AST_FRAME_DTMF) {
1356 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1357 const char *context;
1358 ast_channel_lock(in);
1359 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1360 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1361 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1363 ast_cdr_noanswer(in->cdr);
1364 *result = f->subclass.integer;
1365 strcpy(pa->status, "CANCEL");
1367 ast_channel_unlock(in);
1369 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1373 ast_channel_unlock(in);
1376 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1377 detect_disconnect(in, f->subclass.integer, featurecode)) {
1378 ast_verb(3, "User requested call disconnect.\n");
1380 strcpy(pa->status, "CANCEL");
1381 ast_cdr_noanswer(in->cdr);
1384 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1390 /* Forward HTML stuff */
1391 if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML))
1392 if (ast_channel_sendhtml(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1)
1393 ast_log(LOG_WARNING, "Unable to send URL\n");
1395 if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF_BEGIN) || (f->frametype == AST_FRAME_DTMF_END))) {
1396 if (ast_write(outgoing->chan, f))
1397 ast_log(LOG_WARNING, "Unable to forward voice or dtmf\n");
1399 if (single && (f->frametype == AST_FRAME_CONTROL)) {
1400 if ((f->subclass.integer == AST_CONTROL_HOLD) ||
1401 (f->subclass.integer == AST_CONTROL_UNHOLD) ||
1402 (f->subclass.integer == AST_CONTROL_VIDUPDATE) ||
1403 (f->subclass.integer == AST_CONTROL_SRCUPDATE) ||
1404 (f->subclass.integer == AST_CONTROL_REDIRECTING)) {
1405 ast_verb(3, "%s requested special control %d, passing it to %s\n", in->name, f->subclass.integer, outgoing->chan->name);
1406 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
1407 } else if (f->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
1408 if (ast_channel_connected_line_macro(in, outgoing->chan, f, 0, 1)) {
1409 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
1411 } else if (f->subclass.integer == AST_CONTROL_REDIRECTING) {
1412 if (ast_channel_redirecting_macro(in, outgoing->chan, f, 0, 1)) {
1413 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
1420 ast_verb(3, "Nobody picked up in %d ms\n", orig);
1421 if (!*to || ast_check_hangup(in))
1422 ast_cdr_noanswer(in->cdr);
1426 for (epollo = outgoing; epollo; epollo = epollo->next) {
1428 ast_poll_channel_del(in, epollo->chan);
1433 ast_cc_completed(in, "Recall completed!");
1438 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode)
1440 struct ast_flags features = { AST_FEATURE_DISCONNECT }; /* only concerned with disconnect feature */
1441 struct ast_call_feature feature = { 0, };
1444 ast_str_append(&featurecode, 1, "%c", code);
1446 res = ast_feature_detect(chan, &features, ast_str_buffer(featurecode), &feature);
1448 if (res != AST_FEATURE_RETURN_STOREDIGITS) {
1449 ast_str_reset(featurecode);
1451 if (feature.feature_mask & AST_FEATURE_DISCONNECT) {
1458 static void replace_macro_delimiter(char *s)
1465 /* returns true if there is a valid privacy reply */
1466 static int valid_priv_reply(struct ast_flags64 *opts, int res)
1470 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1472 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1477 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1478 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1484 /* Get the user's intro, store it in priv-callerintros/$CID,
1485 unless it is already there-- this should be done before the
1486 call is actually dialed */
1488 /* all ring indications and moh for the caller has been halted as soon as the
1489 target extension was picked up. We are going to have to kill some
1490 time and make the caller believe the peer hasn't picked up yet */
1492 if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
1493 char *original_moh = ast_strdupa(chan->musicclass);
1494 ast_indicate(chan, -1);
1495 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
1496 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1497 ast_string_field_set(chan, musicclass, original_moh);
1498 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1499 ast_indicate(chan, AST_CONTROL_RINGING);
1503 /* Start autoservice on the other chan ?? */
1504 res2 = ast_autoservice_start(chan);
1505 /* Now Stream the File */
1506 for (loopcount = 0; loopcount < 3; loopcount++) {
1507 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1509 if (!res2) /* on timeout, play the message again */
1510 res2 = ast_play_and_wait(peer, "priv-callpending");
1511 if (!valid_priv_reply(opts, res2))
1513 /* priv-callpending script:
1514 "I have a caller waiting, who introduces themselves as:"
1517 res2 = ast_play_and_wait(peer, pa->privintro);
1518 if (!valid_priv_reply(opts, res2))
1520 /* now get input from the called party, as to their choice */
1522 /* XXX can we have both, or they are mutually exclusive ? */
1523 if (ast_test_flag64(opts, OPT_PRIVACY))
1524 res2 = ast_play_and_wait(peer, "priv-callee-options");
1525 if (ast_test_flag64(opts, OPT_SCREENING))
1526 res2 = ast_play_and_wait(peer, "screen-callee-options");
1528 /*! \page DialPrivacy Dial Privacy scripts
1529 \par priv-callee-options script:
1530 "Dial 1 if you wish this caller to reach you directly in the future,
1531 and immediately connect to their incoming call
1532 Dial 2 if you wish to send this caller to voicemail now and
1534 Dial 3 to send this caller to the torture menus, now and forevermore.
1535 Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
1536 Dial 5 to allow this caller to come straight thru to you in the future,
1537 but right now, just this once, send them to voicemail."
1538 \par screen-callee-options script:
1539 "Dial 1 if you wish to immediately connect to the incoming call
1540 Dial 2 if you wish to send this caller to voicemail.
1541 Dial 3 to send this caller to the torture menus.
1542 Dial 4 to send this caller to a simple "go away" menu.
1544 if (valid_priv_reply(opts, res2))
1546 /* invalid option */
1547 res2 = ast_play_and_wait(peer, "vm-sorry");
1550 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
1552 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1553 ast_indicate(chan, -1);
1554 pa->sentringing = 0;
1556 ast_autoservice_stop(chan);
1557 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
1558 /* map keypresses to various things, the index is res2 - '1' */
1559 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
1560 static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
1562 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
1563 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
1564 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
1570 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1573 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1576 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1579 /* XXX should we set status to DENY ? */
1580 if (ast_test_flag64(opts, OPT_PRIVACY))
1582 /* if not privacy, then 5 is the same as "default" case */
1583 default: /* bad input or -1 if failure to start autoservice */
1584 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
1585 /* well, there seems basically two choices. Just patch the caller thru immediately,
1586 or,... put 'em thru to voicemail. */
1587 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
1588 ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
1589 /* XXX should we set status to DENY ? */
1590 /* XXX what about the privacy flags ? */
1594 if (res2 == '1') { /* the only case where we actually connect */
1595 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
1596 just clog things up, and it's not useful information, not being tied to a CID */
1597 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
1598 ast_filedelete(pa->privintro, NULL);
1599 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1600 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1602 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1604 return 0; /* the good exit path */
1606 ast_hangup(peer); /* hang up on the callee -- he didn't want to talk anyway! */
1611 /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
1612 static int setup_privacy_args(struct privacy_args *pa,
1613 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
1618 int silencethreshold;
1620 if (!ast_strlen_zero(chan->cid.cid_num)) {
1621 l = ast_strdupa(chan->cid.cid_num);
1622 ast_shrink_phone_number(l);
1623 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
1624 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
1625 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
1627 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
1628 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1633 tnam = ast_strdupa(chan->name);
1634 /* clean the channel name so slashes don't try to end up in disk file name */
1635 for (tn2 = tnam; *tn2; tn2++) {
1636 if (*tn2 == '/') /* any other chars to be afraid of? */
1639 ast_verb(3, "Privacy-- callerid is empty\n");
1641 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", chan->exten, tnam);
1643 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1646 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
1648 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
1649 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
1650 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
1651 pa->privdb_val = AST_PRIVACY_ALLOW;
1652 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
1653 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
1656 if (pa->privdb_val == AST_PRIVACY_DENY) {
1657 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
1658 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1660 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
1661 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1662 return 0; /* Is this right? */
1663 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
1664 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1665 return 0; /* is this right??? */
1666 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
1667 /* Get the user's intro, store it in priv-callerintros/$CID,
1668 unless it is already there-- this should be done before the
1669 call is actually dialed */
1671 /* make sure the priv-callerintros dir actually exists */
1672 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
1673 if ((res = ast_mkdir(pa->privintro, 0755))) {
1674 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
1678 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
1679 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
1680 /* the DELUX version of this code would allow this caller the
1681 option to hear and retape their previously recorded intro.
1684 int duration; /* for feedback from play_and_wait */
1685 /* the file doesn't exist yet. Let the caller submit his
1686 vocal intro for posterity */
1687 /* priv-recordintro script:
1689 "At the tone, please say your name:"
1692 silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
1694 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "gsm", &duration, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
1695 /* don't think we'll need a lock removed, we took care of
1696 conflicts by naming the pa.privintro file */
1698 /* Delete the file regardless since they hung up during recording */
1699 ast_filedelete(pa->privintro, NULL);
1700 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1701 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1703 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1706 if (!ast_streamfile(chan, "vm-dialout", chan->language) )
1707 ast_waitstream(chan, "");
1710 return 1; /* success */
1713 static void end_bridge_callback(void *data)
1717 struct ast_channel *chan = data;
1725 ast_channel_lock(chan);
1726 if (chan->cdr->answer.tv_sec) {
1727 snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->answer.tv_sec);
1728 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
1731 if (chan->cdr->start.tv_sec) {
1732 snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->start.tv_sec);
1733 pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
1735 ast_channel_unlock(chan);
1738 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
1739 bconfig->end_bridge_callback_data = originator;
1742 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
1744 struct ast_tone_zone_sound *ts = NULL;
1746 const char *str = data;
1748 if (ast_strlen_zero(str)) {
1749 ast_debug(1,"Nothing to play\n");
1753 ts = ast_get_indication_tone(chan->zone, str);
1755 if (ts && ts->data[0]) {
1756 res = ast_playtones_start(chan, 0, ts->data, 0);
1762 ts = ast_tone_zone_sound_unref(ts);
1766 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
1772 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
1774 int res = -1; /* default: error */
1775 char *rest, *cur; /* scan the list of destinations */
1776 struct chanlist *outgoing = NULL; /* list of destinations */
1777 struct ast_channel *peer;
1778 int to; /* timeout */
1779 struct cause_args num = { chan, 0, 0, 0 };
1782 char *cid_num = NULL, *cid_name = NULL, *cid_tag = NULL, *cid_pres = NULL;
1784 struct ast_bridge_config config = { { 0, } };
1785 struct timeval calldurationlimit = { 0, };
1786 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
1787 struct privacy_args pa = {
1790 .status = "INVALIDARGS",
1792 int sentringing = 0, moh = 0;
1793 const char *outbound_group = NULL;
1797 int delprivintro = 0;
1798 AST_DECLARE_APP_ARGS(args,
1800 AST_APP_ARG(timeout);
1801 AST_APP_ARG(options);
1804 struct ast_flags64 opts = { 0, };
1805 char *opt_args[OPT_ARG_ARRAY_SIZE];
1806 struct ast_datastore *datastore = NULL;
1807 int fulldial = 0, num_dialed = 0;
1809 char device_name[AST_CHANNEL_NAME];
1811 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
1812 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
1813 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
1814 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
1815 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
1816 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
1818 if (ast_strlen_zero(data)) {
1819 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1820 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1824 parse = ast_strdupa(data);
1826 AST_STANDARD_APP_ARGS(args, parse);
1828 if (!ast_strlen_zero(args.options) &&
1829 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
1830 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1834 if (ast_strlen_zero(args.peers)) {
1835 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1836 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1840 if (ast_cc_call_init(chan, &ignore_cc)) {
1844 if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
1845 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
1847 if (delprivintro < 0 || delprivintro > 1) {
1848 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
1853 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
1854 opt_args[OPT_ARG_RINGBACK] = NULL;
1857 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
1858 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
1859 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
1862 if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
1863 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
1864 if (!calldurationlimit.tv_sec) {
1865 ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
1866 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1869 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
1872 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
1873 dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
1874 dtmfcalled = strsep(&dtmf_progress, ":");
1875 dtmfcalling = strsep(&dtmf_progress, ":");
1878 if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
1879 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
1883 if (ast_test_flag64(&opts, OPT_FORCECLID) && !ast_strlen_zero(opt_args[OPT_ARG_FORCECLID]))
1884 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &cid_name, &cid_num);
1885 if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG) && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG]))
1886 cid_tag = ast_strdupa(opt_args[OPT_ARG_FORCE_CID_TAG]);
1887 if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES) && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES]))
1888 cid_pres = ast_strdupa(opt_args[OPT_ARG_FORCE_CID_PRES]);
1889 if (ast_test_flag64(&opts, OPT_RESETCDR) && chan->cdr)
1890 ast_cdr_reset(chan->cdr, NULL);
1891 if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
1892 opt_args[OPT_ARG_PRIVACY] = ast_strdupa(chan->exten);
1894 if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
1895 res = setup_privacy_args(&pa, &opts, opt_args, chan);
1898 res = -1; /* reset default */
1901 if (ast_test_flag64(&opts, OPT_DTMF_EXIT) || ast_test_flag64(&opts, OPT_CALLER_HANGUP)) {
1902 __ast_answer(chan, 0, 0);
1908 /* If a channel group has been specified, get it for use when we create peer channels */
1910 ast_channel_lock(chan);
1911 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
1912 outbound_group = ast_strdupa(outbound_group);
1913 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
1914 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
1915 outbound_group = ast_strdupa(outbound_group);
1917 ast_channel_unlock(chan);
1918 ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_IGNORE_CONNECTEDLINE |
1919 OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
1921 /* loop through the list of dial destinations */
1923 while ((cur = strsep(&rest, "&")) ) {
1924 struct chanlist *tmp;
1925 struct ast_channel *tc; /* channel for this destination */
1926 /* Get a technology/[device:]number pair */
1928 char *interface = ast_strdupa(number);
1929 char *tech = strsep(&number, "/");
1930 /* find if we already dialed this interface */
1931 struct ast_dialed_interface *di;
1932 AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
1935 ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
1938 if (!(tmp = ast_calloc(1, sizeof(*tmp))))
1941 ast_copy_flags64(tmp, &opts,
1942 OPT_CANCEL_ELSEWHERE |
1943 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1944 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1945 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1946 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1947 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1948 OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
1949 ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
1951 ast_copy_string(numsubst, number, sizeof(numsubst));
1952 /* Request the peer */
1954 ast_channel_lock(chan);
1955 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL);
1957 * Seed the chanlist's connected line information with previously
1958 * acquired connected line info from the incoming channel. The
1959 * previously acquired connected line info could have been set
1960 * through the CONNECTED_LINE dialplan function.
1962 ast_party_connected_line_copy(&tmp->connected, &chan->connected);
1963 ast_channel_unlock(chan);
1966 dialed_interfaces = datastore->data;
1968 if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) {
1969 ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n");
1974 datastore->inheritance = DATASTORE_INHERIT_FOREVER;
1976 if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
1977 ast_datastore_free(datastore);
1982 datastore->data = dialed_interfaces;
1983 AST_LIST_HEAD_INIT(dialed_interfaces);
1985 ast_channel_lock(chan);
1986 ast_channel_datastore_add(chan, datastore);
1987 ast_channel_unlock(chan);
1990 AST_LIST_LOCK(dialed_interfaces);
1991 AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
1992 if (!strcasecmp(di->interface, interface)) {
1993 ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n",
1998 AST_LIST_UNLOCK(dialed_interfaces);
2006 /* It is always ok to dial a Local interface. We only keep track of
2007 * which "real" interfaces have been dialed. The Local channel will
2008 * inherit this list so that if it ends up dialing a real interface,
2009 * it won't call one that has already been called. */
2010 if (strcasecmp(tech, "Local")) {
2011 if (!(di = ast_calloc(1, sizeof(*di) + strlen(interface)))) {
2012 AST_LIST_UNLOCK(dialed_interfaces);
2016 strcpy(di->interface, interface);
2018 AST_LIST_LOCK(dialed_interfaces);
2019 AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
2020 AST_LIST_UNLOCK(dialed_interfaces);
2023 tc = ast_request(tech, chan->nativeformats, chan, numsubst, &cause);
2025 /* If we can't, just go on to the next call */
2026 ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
2027 tech, cause, ast_cause2str(cause));
2028 handle_cause(cause, &num);
2029 if (!rest) /* we are on the last destination */
2030 chan->hangupcause = cause;
2032 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2033 if (!ast_cc_callback(chan, tech, numsubst, ast_cc_busy_interface)) {
2034 ast_cc_extension_monitor_add_dialstring(chan, interface, "");
2039 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2041 ast_cc_extension_monitor_add_dialstring(chan, interface, device_name);
2043 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
2045 ast_channel_lock(tc);
2046 while (ast_channel_trylock(chan)) {
2047 CHANNEL_DEADLOCK_AVOIDANCE(tc);
2049 /* Setup outgoing SDP to match incoming one */
2050 if (!outgoing && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2051 ast_rtp_instance_early_bridge_make_compatible(tc, chan);
2054 /* Inherit specially named variables from parent channel */
2055 ast_channel_inherit_variables(chan, tc);
2056 ast_channel_datastore_inherit(chan, tc);
2058 tc->appl = "AppDial";
2059 tc->data = "(Outgoing Line)";
2060 memset(&tc->whentohangup, 0, sizeof(tc->whentohangup));
2062 /* If the new channel has no callerid, try to guess what it should be */
2063 if (ast_strlen_zero(tc->cid.cid_num)) {
2064 if (!ast_strlen_zero(chan->connected.id.number)) {
2065 ast_set_callerid(tc, chan->connected.id.number, chan->connected.id.name, chan->connected.ani);
2066 } else if (!ast_strlen_zero(chan->cid.cid_dnid)) {
2067 ast_set_callerid(tc, chan->cid.cid_dnid, NULL, NULL);
2068 } else if (!ast_strlen_zero(S_OR(chan->macroexten, chan->exten))) {
2069 ast_set_callerid(tc, S_OR(chan->macroexten, chan->exten), NULL, NULL);
2071 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2074 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2075 struct ast_party_connected_line connected;
2078 ast_party_connected_line_set_init(&connected, &tmp->chan->connected);
2079 connected.id.number = cid_num;
2080 connected.id.name = cid_name;
2081 connected.id.tag = cid_tag;
2083 pres = ast_parse_caller_presentation(cid_pres);
2085 connected.id.number_presentation = pres;
2088 connected.id.number_presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
2090 ast_channel_set_connected_line(tmp->chan, &connected);
2092 ast_connected_line_copy_from_caller(&tc->connected, &chan->cid);
2095 ast_party_redirecting_copy(&tc->redirecting, &chan->redirecting);
2097 tc->cid.cid_tns = chan->cid.cid_tns;
2099 if (!ast_strlen_zero(chan->accountcode)) {
2100 ast_string_field_set(tc, peeraccount, chan->accountcode);
2102 if (ast_strlen_zero(tc->musicclass))
2103 ast_string_field_set(tc, musicclass, chan->musicclass);
2105 /* Pass ADSI CPE and transfer capability */
2106 tc->adsicpe = chan->adsicpe;
2107 tc->transfercapability = chan->transfercapability;
2109 /* If we have an outbound group, set this peer channel to it */
2111 ast_app_group_set_channel(tc, outbound_group);
2112 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2113 if (ast_test_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE))
2114 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
2116 /* Check if we're forced by configuration */
2117 if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
2118 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
2121 /* Inherit context and extension */
2122 ast_string_field_set(tc, dialcontext, ast_strlen_zero(chan->macrocontext) ? chan->context : chan->macrocontext);
2123 if (!ast_strlen_zero(chan->macroexten))
2124 ast_copy_string(tc->exten, chan->macroexten, sizeof(tc->exten));
2126 ast_copy_string(tc->exten, chan->exten, sizeof(tc->exten));
2128 ast_channel_unlock(tc);
2129 res = ast_call(tc, numsubst, 0); /* Place the call, but don't wait on the answer */
2131 /* Save the info in cdr's that we called them */
2133 ast_cdr_setdestchan(chan->cdr, tc->name);
2135 /* check the results of ast_call */
2137 /* Again, keep going even if there's an error */
2138 ast_debug(1, "ast call on peer returned %d\n", res);
2139 ast_verb(3, "Couldn't call %s\n", numsubst);
2140 if (tc->hangupcause) {
2141 chan->hangupcause = tc->hangupcause;
2143 ast_channel_unlock(chan);
2144 ast_cc_call_failed(chan, tc, interface);
2150 const char *tmpexten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
2151 senddialevent(chan, tc, numsubst);
2152 ast_verb(3, "Called %s\n", numsubst);
2153 ast_channel_unlock(chan);
2154 if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2155 char cidname[AST_MAX_EXTENSION];
2156 ast_set_callerid(tc, tmpexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
2159 /* Put them in the list of outgoing thingies... We're ready now.
2160 XXX If we're forcibly removed, these outgoing calls won't get
2162 ast_set_flag64(tmp, DIAL_STILLGOING);
2164 tmp->next = outgoing;
2166 /* If this line is up, don't try anybody else */
2167 if (outgoing->chan->_state == AST_STATE_UP)
2171 if (ast_strlen_zero(args.timeout)) {
2174 to = atoi(args.timeout);
2178 ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2184 strcpy(pa.status, "CHANUNAVAIL");
2185 if (fulldial == num_dialed) {
2190 /* Our status will at least be NOANSWER */
2191 strcpy(pa.status, "NOANSWER");
2192 if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
2194 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2195 char *original_moh = ast_strdupa(chan->musicclass);
2196 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
2197 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2198 ast_string_field_set(chan, musicclass, original_moh);
2200 ast_moh_start(chan, NULL, NULL);
2202 ast_indicate(chan, AST_CONTROL_PROGRESS);
2203 } else if (ast_test_flag64(outgoing, OPT_RINGBACK)) {
2204 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2205 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2206 ast_indicate(chan, AST_CONTROL_RINGING);
2209 ast_indicate(chan, AST_CONTROL_PROGRESS);
2212 ast_indicate(chan, AST_CONTROL_RINGING);
2218 peer = wait_for_answer(chan, outgoing, &to, peerflags, opt_args, &pa, &num, &result, dtmf_progress, ignore_cc);
2220 /* The ast_channel_datastore_remove() function could fail here if the
2221 * datastore was moved to another channel during a masquerade. If this is
2222 * the case, don't free the datastore here because later, when the channel
2223 * to which the datastore was moved hangs up, it will attempt to free this
2224 * datastore again, causing a crash
2226 if (!ast_channel_datastore_remove(chan, datastore))
2227 ast_datastore_free(datastore);
2231 } else if (to) { /* Musta gotten hung up */
2233 } else { /* Nobody answered, next please? */
2237 /* SIP, in particular, sends back this error code to indicate an
2238 * overlap dialled number needs more digits. */
2239 if (chan->hangupcause == AST_CAUSE_INVALID_NUMBER_FORMAT) {
2240 res = AST_PBX_INCOMPLETE;
2243 /* almost done, although the 'else' block is 400 lines */
2247 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER))
2250 strcpy(pa.status, "ANSWER");
2251 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2252 /* Ah ha! Someone answered within the desired timeframe. Of course after this
2253 we will always return with -1 so that it is hung up properly after the
2255 hanguptree(outgoing, peer, 1);
2257 /* If appropriate, log that we have a destination channel and set the answer time */
2259 ast_cdr_setdestchan(chan->cdr, peer->name);
2260 ast_cdr_setanswer(chan->cdr, peer->cdr->answer);
2263 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", peer->name);
2265 ast_channel_lock(peer);
2266 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
2269 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
2270 ast_channel_unlock(peer);
2272 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
2273 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
2274 ast_channel_sendurl( peer, args.url );
2276 if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
2277 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
2282 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
2286 struct ast_channel *chans[2];
2287 struct ast_channel *active_chan;
2292 /* we need to stream the announcment while monitoring the caller for a hangup */
2294 /* stream the file */
2295 res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
2298 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
2301 ast_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
2302 while (peer->stream) {
2305 ms = ast_sched_wait(peer->sched);
2307 if (ms < 0 && !peer->timingfunc) {
2308 ast_stopstream(peer);
2314 active_chan = ast_waitfor_n(chans, 2, &ms);
2316 struct ast_frame *fr = ast_read(active_chan);
2322 switch(fr->frametype) {
2323 case AST_FRAME_DTMF_END:
2324 digit = fr->subclass.integer;
2325 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
2326 ast_stopstream(peer);
2327 res = ast_senddigit(chan, digit, 0);
2330 case AST_FRAME_CONTROL:
2331 switch (fr->subclass.integer) {
2332 case AST_CONTROL_HANGUP:
2342 /* Ignore all others */
2347 ast_sched_runq(peer->sched);
2349 ast_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
2352 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
2353 /* chan and peer are going into the PBX, they both
2354 * should probably get CDR records. */
2355 ast_clear_flag(chan->cdr, AST_CDR_FLAG_DIALED);
2356 ast_clear_flag(peer->cdr, AST_CDR_FLAG_DIALED);
2358 replace_macro_delimiter(opt_args[OPT_ARG_GOTO]);
2359 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
2360 /* peer goes to the same context and extension as chan, so just copy info from chan*/
2361 ast_copy_string(peer->context, chan->context, sizeof(peer->context));
2362 ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
2363 peer->priority = chan->priority + 2;
2364 ast_pbx_start(peer);
2365 hanguptree(outgoing, NULL, ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0);
2372 if (ast_test_flag64(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
2373 struct ast_app *theapp;
2374 const char *macro_result;
2376 res = ast_autoservice_start(chan);
2378 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
2382 theapp = pbx_findapp("Macro");
2384 if (theapp && !res) { /* XXX why check res here ? */
2385 /* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
2386 ast_copy_string(peer->context, chan->context, sizeof(peer->context));
2387 ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
2389 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
2390 res = pbx_exec(peer, theapp, opt_args[OPT_ARG_CALLEE_MACRO]);
2391 ast_debug(1, "Macro exited with status %d\n", res);
2394 ast_log(LOG_ERROR, "Could not find application Macro\n");
2398 if (ast_autoservice_stop(chan) < 0) {
2402 ast_channel_lock(peer);
2404 if (!res && (macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
2405 char *macro_transfer_dest;
2407 if (!strcasecmp(macro_result, "BUSY")) {
2408 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
2409 ast_set_flag64(peerflags, OPT_GO_ON);
2411 } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
2412 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
2413 ast_set_flag64(peerflags, OPT_GO_ON);
2415 } else if (!strcasecmp(macro_result, "CONTINUE")) {
2416 /* hangup peer and keep chan alive assuming the macro has changed
2417 the context / exten / priority or perhaps
2418 the next priority in the current exten is desired.
2420 ast_set_flag64(peerflags, OPT_GO_ON);
2422 } else if (!strcasecmp(macro_result, "ABORT")) {
2423 /* Hangup both ends unless the caller has the g flag */
2425 } else if (!strncasecmp(macro_result, "GOTO:", 5) && (macro_transfer_dest = ast_strdupa(macro_result + 5))) {
2427 /* perform a transfer to a new extension */
2428 if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
2429 replace_macro_delimiter(macro_transfer_dest);
2430 if (!ast_parseable_goto(chan, macro_transfer_dest))
2431 ast_set_flag64(peerflags, OPT_GO_ON);
2436 ast_channel_unlock(peer);
2439 if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
2440 struct ast_app *theapp;
2441 const char *gosub_result;
2442 char *gosub_args, *gosub_argstart;
2445 res9 = ast_autoservice_start(chan);
2447 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
2451 theapp = pbx_findapp("Gosub");
2453 if (theapp && !res9) {
2454 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
2456 /* Set where we came from */
2457 ast_copy_string(peer->context, "app_dial_gosub_virtual_context", sizeof(peer->context));
2458 ast_copy_string(peer->exten, "s", sizeof(peer->exten));
2461 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
2462 if (gosub_argstart) {
2463 *gosub_argstart = 0;
2464 if (asprintf(&gosub_args, "%s,s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], gosub_argstart + 1) < 0) {
2465 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
2468 *gosub_argstart = ',';
2470 if (asprintf(&gosub_args, "%s,s,1", opt_args[OPT_ARG_CALLEE_GOSUB]) < 0) {
2471 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
2477 res9 = pbx_exec(peer, theapp, gosub_args);
2479 struct ast_pbx_args args;
2480 /* A struct initializer fails to compile for this case ... */
2481 memset(&args, 0, sizeof(args));
2482 args.no_hangup_chan = 1;
2483 ast_pbx_run_args(peer, &args);
2485 ast_free(gosub_args);
2486 ast_debug(1, "Gosub exited with status %d\n", res9);
2488 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
2492 ast_log(LOG_ERROR, "Could not find application Gosub\n");
2496 if (ast_autoservice_stop(chan) < 0) {
2497 ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n");
2501 ast_channel_lock(peer);
2503 if (!res9 && (gosub_result = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
2504 char *gosub_transfer_dest;
2505 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
2507 /* Inherit return value from the peer, so it can be used in the master */
2509 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
2512 if (!strcasecmp(gosub_result, "BUSY")) {
2513 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
2514 ast_set_flag64(peerflags, OPT_GO_ON);
2516 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
2517 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
2518 ast_set_flag64(peerflags, OPT_GO_ON);
2520 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
2521 /* hangup peer and keep chan alive assuming the macro has changed
2522 the context / exten / priority or perhaps
2523 the next priority in the current exten is desired.
2525 ast_set_flag64(peerflags, OPT_GO_ON);
2527 } else if (!strcasecmp(gosub_result, "ABORT")) {
2528 /* Hangup both ends unless the caller has the g flag */
2530 } else if (!strncasecmp(gosub_result, "GOTO:", 5) && (gosub_transfer_dest = ast_strdupa(gosub_result + 5))) {