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 <emphasis>called</emphasis> party
156 to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
158 <para>Any channel variables you want the called channel to inherit from the caller channel must be
159 prefixed with one or two underbars ('_').</para>
163 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party to the next priority of the current extension
164 and <emphasis>start</emphasis> execution at that location.</para>
166 <para>Any channel variables you want the called channel to inherit from the caller channel must be
167 prefixed with one or two underbars ('_').</para>
170 <para>Using this option from a Macro() or GoSub() might not make sense as there would be no return points.</para>
174 <para>Proceed with dialplan execution at the next priority in the current extension if the
175 destination channel hangs up.</para>
177 <option name="G" argsep="^">
178 <argument name="context" required="false" />
179 <argument name="exten" required="false" />
180 <argument name="priority" required="true" />
181 <para>If the call is answered, transfer the calling party to
182 the specified <replaceable>priority</replaceable> and the called party to the specified
183 <replaceable>priority</replaceable> plus one.</para>
185 <para>You cannot use any additional action post answer options in conjunction with this option.</para>
189 <para>Allow the called party to hang up by sending the DTMF sequence
190 defined for disconnect in <filename>features.conf</filename>.</para>
193 <para>Allow the calling party to hang up by sending the DTMF sequence
194 defined for disconnect in <filename>features.conf</filename>.</para>
196 <para>Many SIP and ISDN phones cannot send DTMF digits until the call is
197 connected. If you wish to allow DTMF disconnect before the dialed
198 party answers with these phones, you can use the <literal>Answer</literal>
199 application before dialing.</para>
203 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
206 <para>Asterisk will ignore any connected line update requests or any redirecting party
207 update requests it may receive on this dial attempt.</para>
210 <para>Allow the called party to enable parking of the call by sending
211 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
214 <para>Allow the calling party to enable parking of the call by sending
215 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
217 <option name="L" argsep=":">
218 <argument name="x" required="true">
219 <para>Maximum call time, in milliseconds</para>
222 <para>Warning time, in milliseconds</para>
225 <para>Repeat time, in milliseconds</para>
227 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
228 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
229 <para>This option is affected by the following variables:</para>
231 <variable name="LIMIT_PLAYAUDIO_CALLER">
232 <value name="yes" default="true" />
234 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
236 <variable name="LIMIT_PLAYAUDIO_CALLEE">
238 <value name="no" default="true"/>
239 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
241 <variable name="LIMIT_TIMEOUT_FILE">
242 <value name="filename"/>
243 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
244 If not set, the time remaining will be announced.</para>
246 <variable name="LIMIT_CONNECT_FILE">
247 <value name="filename"/>
248 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
249 If not set, the time remaining will be announced.</para>
251 <variable name="LIMIT_WARNING_FILE">
252 <value name="filename"/>
253 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
254 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
259 <argument name="class" required="false"/>
260 <para>Provide hold music to the calling party until a requested
261 channel answers. A specific music on hold <replaceable>class</replaceable>
262 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
264 <option name="M" argsep="^">
265 <argument name="macro" required="true">
266 <para>Name of the macro that should be executed.</para>
268 <argument name="arg" multiple="true">
269 <para>Macro arguments</para>
271 <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
272 before connecting to the calling channel. Arguments can be specified to the Macro
273 using <literal>^</literal> as a delimiter. The macro can set the variable
274 <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
275 finished executing:</para>
277 <variable name="MACRO_RESULT">
278 <para>If set, this action will be taken after the macro finished executing.</para>
280 Hangup both legs of the call
282 <value name="CONGESTION">
283 Behave as if line congestion was encountered
286 Behave as if a busy signal was encountered
288 <value name="CONTINUE">
289 Hangup the called party and allow the calling party to continue dialplan execution at the next priority
291 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
292 <value name="GOTO:<context>^<exten>^<priority>">
293 Transfer the call to the specified destination.
298 <para>You cannot use any additional action post answer options in conjunction
299 with this option. Also, pbx services are not run on the peer (called) channel,
300 so you will not be able to set timeouts via the TIMEOUT() function in this macro.</para>
302 <warning><para>Be aware of the limitations that macros have, specifically with regards to use of
303 the <literal>WaitExten</literal> application. For more information, see the documentation for
304 Macro()</para></warning>
307 <argument name="delete">
308 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
309 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
311 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
312 always be deleted.</para>
314 <para>This option is a modifier for the call screening/privacy mode. (See the
315 <literal>p</literal> and <literal>P</literal> options.) It specifies
316 that no introductions are to be saved in the <directory>priv-callerintros</directory>
320 <para>This option is a modifier for the call screening/privacy mode. It specifies
321 that if Caller*ID is present, do not screen the call.</para>
324 <argument name="x" required="false" />
325 <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
326 <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
327 This was the behavior of Asterisk 1.0 and earlier.
328 If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
329 Note that o(${CALLERID(all)}) is similar to option o without the parameter.</para>
332 <argument name="mode">
333 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
334 the originator hanging up will cause the phone to ring back immediately.</para>
335 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
336 flashes the trunk, it will ring their phone back.</para>
338 <para>Enables <emphasis>operator services</emphasis> mode. This option only
339 works when bridging a DAHDI channel to another DAHDI channel
340 only. if specified on non-DAHDI interfaces, it will be ignored.
341 When the destination answers (presumably an operator services
342 station), the originator no longer has control of their line.
343 They may hang up, but the switch will not release their line
344 until the destination party (the operator) hangs up.</para>
347 <para>This option enables screening mode. This is basically Privacy mode
348 without memory.</para>
351 <argument name="x" />
352 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
353 it is provided. The current extension is used if a database family/key is not specified.</para>
356 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
357 party until the called channel has answered.</para>
358 <argument name="tone" required="false">
359 <para>Indicate progress to calling party. Send audio 'tone' from indications.conf</para>
363 <argument name="x" required="true" />
364 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
365 answered the call.</para>
368 <argument name="x" required="true" />
369 <para>Force the outgoing callerid tag parameter to be set to the string <replaceable>x</replaceable>.</para>
370 <para>Works with the f option.</para>
373 <para>Allow the called party to transfer the calling party by sending the
374 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
375 transfers initiated by other methods.</para>
378 <para>Allow the calling party to transfer the called party by sending the
379 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
380 transfers initiated by other methods.</para>
382 <option name="U" argsep="^">
383 <argument name="x" required="true">
384 <para>Name of the subroutine to execute via Gosub</para>
386 <argument name="arg" multiple="true" required="false">
387 <para>Arguments for the Gosub routine</para>
389 <para>Execute via Gosub the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
390 to the calling channel. Arguments can be specified to the Gosub
391 using <literal>^</literal> as a delimiter. The Gosub routine can set the variable
392 <variable>GOSUB_RESULT</variable> to specify the following actions after the Gosub returns.</para>
394 <variable name="GOSUB_RESULT">
396 Hangup both legs of the call.
398 <value name="CONGESTION">
399 Behave as if line congestion was encountered.
402 Behave as if a busy signal was encountered.
404 <value name="CONTINUE">
405 Hangup the called party and allow the calling party
406 to continue dialplan execution at the next priority.
408 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
409 <value name="GOTO:<context>^<exten>^<priority>">
410 Transfer the call to the specified priority. Optionally, an extension, or
411 extension and priority can be specified.
416 <para>You cannot use any additional action post answer options in conjunction
417 with this option. Also, pbx services are not run on the peer (called) channel,
418 so you will not be able to set timeouts via the TIMEOUT() function in this routine.</para>
422 <argument name = "x" required="true">
423 <para>Force the outgoing callerid presentation indicator parameter to be set
424 to one of the values passed in <replaceable>x</replaceable>:
425 <literal>allowed_not_screened</literal>
426 <literal>allowed_passed_screen</literal>
427 <literal>allowed_failed_screen</literal>
428 <literal>allowed</literal>
429 <literal>prohib_not_screened</literal>
430 <literal>prohib_passed_screen</literal>
431 <literal>prohib_failed_screen</literal>
432 <literal>prohib</literal>
433 <literal>unavailable</literal></para>
435 <para>Works with the f option.</para>
438 <para>Allow the called party to enable recording of the call by sending
439 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
442 <para>Allow the calling party to enable recording of the call by sending
443 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
446 <para>Allow the called party to enable recording of the call by sending
447 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
450 <para>Allow the calling party to enable recording of the call by sending
451 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
454 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
458 <parameter name="URL">
459 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
463 <para>This application will place calls to one or more specified channels. As soon
464 as one of the requested channels answers, the originating channel will be
465 answered, if it has not already been answered. These two channels will then
466 be active in a bridged call. All other channels that were requested will then
469 <para>Unless there is a timeout specified, the Dial application will wait
470 indefinitely until one of the called channels answers, the user hangs up, or
471 if all of the called channels are busy or unavailable. Dialplan executing will
472 continue if no requested channels can be called, or if the timeout expires.
473 This application will report normal termination if the originating channel
474 hangs up, or if the call is bridged and either of the parties in the bridge
475 ends the call.</para>
476 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
477 application will be put into that group (as in Set(GROUP()=...).
478 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
479 application will be put into that group (as in Set(GROUP()=...). Unlike <variable>OUTBOUND_GROUP</variable>,
480 however, the variable will be unset after use.</para>
482 <para>This application sets the following channel variables:</para>
484 <variable name="DIALEDTIME">
485 <para>This is the time from dialing a channel until when it is disconnected.</para>
487 <variable name="ANSWEREDTIME">
488 <para>This is the amount of time for actual call.</para>
490 <variable name="DIALSTATUS">
491 <para>This is the status of the call</para>
492 <value name="CHANUNAVAIL" />
493 <value name="CONGESTION" />
494 <value name="NOANSWER" />
495 <value name="BUSY" />
496 <value name="ANSWER" />
497 <value name="CANCEL" />
498 <value name="DONTCALL">
499 For the Privacy and Screening Modes.
500 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
502 <value name="TORTURE">
503 For the Privacy and Screening Modes.
504 Will be set if the called party chooses to send the calling party to the 'torture' script.
506 <value name="INVALIDARGS" />
511 <application name="RetryDial" language="en_US">
513 Place a call, retrying on failure allowing an optional exit extension.
516 <parameter name="announce" required="true">
517 <para>Filename of sound that will be played when no channel can be reached</para>
519 <parameter name="sleep" required="true">
520 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
522 <parameter name="retries" required="true">
523 <para>Number of retries</para>
524 <para>When this is reached flow will continue at the next priority in the dialplan</para>
526 <parameter name="dialargs" required="true">
527 <para>Same format as arguments provided to the Dial application</para>
531 <para>This application will attempt to place a call using the normal Dial application.
532 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
533 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
534 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
535 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
536 While waiting to retry a call, a 1 digit extension may be dialed. If that
537 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
538 one, The call will jump to that extension immediately.
539 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
540 to the Dial application.</para>
545 static const char app[] = "Dial";
546 static const char rapp[] = "RetryDial";
549 OPT_ANNOUNCE = (1 << 0),
550 OPT_RESETCDR = (1 << 1),
551 OPT_DTMF_EXIT = (1 << 2),
552 OPT_SENDDTMF = (1 << 3),
553 OPT_FORCECLID = (1 << 4),
554 OPT_GO_ON = (1 << 5),
555 OPT_CALLEE_HANGUP = (1 << 6),
556 OPT_CALLER_HANGUP = (1 << 7),
557 OPT_ORIGINAL_CLID = (1 << 8),
558 OPT_DURATION_LIMIT = (1 << 9),
559 OPT_MUSICBACK = (1 << 10),
560 OPT_CALLEE_MACRO = (1 << 11),
561 OPT_SCREEN_NOINTRO = (1 << 12),
562 OPT_SCREEN_NOCALLERID = (1 << 13),
563 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
564 OPT_SCREENING = (1 << 15),
565 OPT_PRIVACY = (1 << 16),
566 OPT_RINGBACK = (1 << 17),
567 OPT_DURATION_STOP = (1 << 18),
568 OPT_CALLEE_TRANSFER = (1 << 19),
569 OPT_CALLER_TRANSFER = (1 << 20),
570 OPT_CALLEE_MONITOR = (1 << 21),
571 OPT_CALLER_MONITOR = (1 << 22),
572 OPT_GOTO = (1 << 23),
573 OPT_OPERMODE = (1 << 24),
574 OPT_CALLEE_PARK = (1 << 25),
575 OPT_CALLER_PARK = (1 << 26),
576 OPT_IGNORE_FORWARDING = (1 << 27),
577 OPT_CALLEE_GOSUB = (1 << 28),
578 OPT_CALLEE_MIXMONITOR = (1 << 29),
579 OPT_CALLER_MIXMONITOR = (1 << 30),
582 /* flags are now 64 bits, so keep it up! */
583 #define DIAL_STILLGOING (1LLU << 31)
584 #define DIAL_NOFORWARDHTML (1LLU << 32)
585 #define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
586 #define OPT_CANCEL_ELSEWHERE (1LLU << 34)
587 #define OPT_PEER_H (1LLU << 35)
588 #define OPT_CALLEE_GO_ON (1LLU << 36)
589 #define OPT_CANCEL_TIMEOUT (1LLU << 37)
590 #define OPT_FORCE_CID_TAG (1LLU << 38)
591 #define OPT_FORCE_CID_PRES (1LLU << 39)
592 #define OPT_CALLER_ANSWER (1LLU << 40)
595 OPT_ARG_ANNOUNCE = 0,
598 OPT_ARG_DURATION_LIMIT,
600 OPT_ARG_CALLEE_MACRO,
602 OPT_ARG_CALLEE_GOSUB,
603 OPT_ARG_CALLEE_GO_ON,
605 OPT_ARG_DURATION_STOP,
607 OPT_ARG_SCREEN_NOINTRO,
608 OPT_ARG_ORIGINAL_CLID,
610 OPT_ARG_FORCE_CID_TAG,
611 OPT_ARG_FORCE_CID_PRES,
612 /* note: this entry _MUST_ be the last one in the enum */
616 AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
617 AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
618 AST_APP_OPTION('a', OPT_CALLER_ANSWER),
619 AST_APP_OPTION('C', OPT_RESETCDR),
620 AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
621 AST_APP_OPTION('d', OPT_DTMF_EXIT),
622 AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
623 AST_APP_OPTION('e', OPT_PEER_H),
624 AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
625 AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
626 AST_APP_OPTION('g', OPT_GO_ON),
627 AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
628 AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
629 AST_APP_OPTION('H', OPT_CALLER_HANGUP),
630 AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
631 AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
632 AST_APP_OPTION('k', OPT_CALLEE_PARK),
633 AST_APP_OPTION('K', OPT_CALLER_PARK),
634 AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
635 AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
636 AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
637 AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
638 AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
639 AST_APP_OPTION_ARG('o', OPT_ORIGINAL_CLID, OPT_ARG_ORIGINAL_CLID),
640 AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
641 AST_APP_OPTION('p', OPT_SCREENING),
642 AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
643 AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
644 AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
645 AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG),
646 AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES),
647 AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
648 AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
649 AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
650 AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
651 AST_APP_OPTION('W', OPT_CALLER_MONITOR),
652 AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
653 AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
654 AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
657 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
658 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
659 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
660 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
661 !ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \
662 ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer)))
665 * The list of active channels
668 struct chanlist *next;
669 struct ast_channel *chan;
671 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
672 struct ast_party_connected_line connected;
673 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
674 unsigned int pending_connected_update:1;
675 struct ast_aoc_decoded *aoc_s_rate_list;
678 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode);
680 static void chanlist_free(struct chanlist *outgoing)
682 ast_party_connected_line_free(&outgoing->connected);
683 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
687 static void hanguptree(struct chanlist *outgoing, struct ast_channel *exception, int answered_elsewhere)
689 /* Hang up a tree of stuff */
692 /* Hangup any existing lines we have open */
693 if (outgoing->chan && (outgoing->chan != exception)) {
694 if (answered_elsewhere) {
695 /* The flag is used for local channel inheritance and stuff */
696 ast_set_flag(ast_channel_flags(outgoing->chan), AST_FLAG_ANSWERED_ELSEWHERE);
697 /* This is for the channel drivers */
698 ast_channel_hangupcause_set(outgoing->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
700 ast_hangup(outgoing->chan);
703 outgoing = outgoing->next;
708 #define AST_MAX_WATCHERS 256
711 * argument to handle_cause() and other functions.
714 struct ast_channel *chan;
720 static void handle_cause(int cause, struct cause_args *num)
722 struct ast_cdr *cdr = ast_channel_cdr(num->chan);
731 case AST_CAUSE_CONGESTION:
737 case AST_CAUSE_NO_ROUTE_DESTINATION:
738 case AST_CAUSE_UNREGISTERED:
744 case AST_CAUSE_NO_ANSWER:
746 ast_cdr_noanswer(cdr);
749 case AST_CAUSE_NORMAL_CLEARING:
758 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
760 char rexten[2] = { exten, '\0' };
763 if (!ast_goto_if_exists(chan, context, rexten, pri))
766 if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
768 else if (!ast_strlen_zero(ast_channel_macrocontext(chan))) {
769 if (!ast_goto_if_exists(chan, ast_channel_macrocontext(chan), rexten, pri))
776 /* do not call with chan lock held */
777 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
782 ast_channel_lock(chan);
783 context = ast_strdupa(S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)));
784 exten = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
785 ast_channel_unlock(chan);
787 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
790 static void senddialevent(struct ast_channel *src, struct ast_channel *dst, const char *dialstring)
792 struct ast_channel *chans[] = { src, dst };
793 ast_manager_event_multichan(EVENT_FLAG_CALL, "Dial", 2, chans,
794 "SubEvent: Begin\r\n"
796 "Destination: %s\r\n"
797 "CallerIDNum: %s\r\n"
798 "CallerIDName: %s\r\n"
799 "ConnectedLineNum: %s\r\n"
800 "ConnectedLineName: %s\r\n"
802 "DestUniqueID: %s\r\n"
803 "Dialstring: %s\r\n",
804 ast_channel_name(src), ast_channel_name(dst),
805 S_COR(ast_channel_caller(src)->id.number.valid, ast_channel_caller(src)->id.number.str, "<unknown>"),
806 S_COR(ast_channel_caller(src)->id.name.valid, ast_channel_caller(src)->id.name.str, "<unknown>"),
807 S_COR(ast_channel_connected(src)->id.number.valid, ast_channel_connected(src)->id.number.str, "<unknown>"),
808 S_COR(ast_channel_connected(src)->id.name.valid, ast_channel_connected(src)->id.name.str, "<unknown>"),
809 ast_channel_uniqueid(src), ast_channel_uniqueid(dst),
810 dialstring ? dialstring : "");
813 static void senddialendevent(struct ast_channel *src, const char *dialstatus)
815 ast_manager_event(src, EVENT_FLAG_CALL, "Dial",
819 "DialStatus: %s\r\n",
820 ast_channel_name(src), ast_channel_uniqueid(src), dialstatus);
824 * helper function for wait_for_answer()
826 * \param o Outgoing call channel list.
827 * \param num Incoming call channel cause accumulation
828 * \param peerflags Dial option flags
829 * \param single_caller_bored From wait_for_answer: single && !caller_entertained
830 * \param to Remaining call timeout time.
831 * \param forced_clid OPT_FORCECLID caller id to send
832 * \param stored_clid Caller id representing the called party if needed
834 * XXX this code is highly suspicious, as it essentially overwrites
835 * the outgoing channel without properly deleting it.
837 * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
839 static void do_forward(struct chanlist *o,
840 struct cause_args *num, struct ast_flags64 *peerflags, int single_caller_bored, int *to,
841 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
844 struct ast_channel *original = o->chan;
845 struct ast_channel *c = o->chan; /* the winner */
846 struct ast_channel *in = num->chan; /* the input channel */
850 struct ast_party_caller caller;
852 ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
853 if ((stuff = strchr(tmpchan, '/'))) {
857 const char *forward_context;
859 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
860 if (ast_strlen_zero(forward_context)) {
861 forward_context = NULL;
863 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
864 ast_channel_unlock(c);
869 ast_cel_report_event(in, AST_CEL_FORWARD, NULL, ast_channel_call_forward(c), NULL);
871 /* Before processing channel, go ahead and check for forwarding */
872 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
873 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
874 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
875 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
877 cause = AST_CAUSE_BUSY;
879 /* Setup parameters */
880 c = o->chan = ast_request(tech, ast_channel_nativeformats(in), in, stuff, &cause);
882 if (single_caller_bored) {
883 ast_channel_make_compatible(o->chan, in);
885 ast_channel_inherit_variables(in, o->chan);
886 ast_channel_datastore_inherit(in, o->chan);
887 /* When a call is forwarded, we don't want to track new interfaces
888 * dialed for CC purposes. Setting the done flag will ensure that
889 * any Dial operations that happen later won't record CC interfaces.
891 ast_ignore_cc(o->chan);
892 ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", ast_channel_name(o->chan));
895 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
899 ast_clear_flag64(o, DIAL_STILLGOING);
900 handle_cause(cause, num);
901 ast_hangup(original);
903 struct ast_party_redirecting redirecting;
905 if (single_caller_bored && CAN_EARLY_BRIDGE(peerflags, c, in)) {
906 ast_rtp_instance_early_bridge_make_compatible(c, in);
909 ast_channel_set_redirecting(c, ast_channel_redirecting(original), NULL);
911 while (ast_channel_trylock(in)) {
912 CHANNEL_DEADLOCK_AVOIDANCE(c);
914 if (!ast_channel_redirecting(c)->from.number.valid
915 || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
917 * The call was not previously redirected so it is
918 * now redirected from this number.
920 ast_party_number_free(&ast_channel_redirecting(c)->from.number);
921 ast_party_number_init(&ast_channel_redirecting(c)->from.number);
922 ast_channel_redirecting(c)->from.number.valid = 1;
923 ast_channel_redirecting(c)->from.number.str =
924 ast_strdup(S_OR(ast_channel_macroexten(in), ast_channel_exten(in)));
927 ast_channel_dialed(c)->transit_network_select = ast_channel_dialed(in)->transit_network_select;
929 /* Determine CallerID to store in outgoing channel. */
930 ast_party_caller_set_init(&caller, ast_channel_caller(c));
931 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
932 caller.id = *stored_clid;
933 ast_channel_set_caller_event(c, &caller, NULL);
934 } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
935 ast_channel_caller(c)->id.number.str, NULL))) {
937 * The new channel has no preset CallerID number by the channel
938 * driver. Use the dialplan extension and hint name.
940 caller.id = *stored_clid;
941 ast_channel_set_caller_event(c, &caller, NULL);
944 /* Determine CallerID for outgoing channel to send. */
945 if (ast_test_flag64(o, OPT_FORCECLID)) {
946 struct ast_party_connected_line connected;
948 ast_party_connected_line_init(&connected);
949 connected.id = *forced_clid;
950 ast_party_connected_line_copy(ast_channel_connected(c), &connected);
952 ast_connected_line_copy_from_caller(ast_channel_connected(c), ast_channel_caller(in));
955 ast_channel_accountcode_set(c, ast_channel_accountcode(in));
957 ast_channel_appl_set(c, "AppDial");
958 ast_channel_data_set(c, "(Outgoing Line)");
960 * We must unlock c before calling ast_channel_redirecting_macro, because
961 * we put c into autoservice there. That is pretty much a guaranteed
962 * deadlock. This is why the handling of c's lock may seem a bit unusual
965 ast_party_redirecting_init(&redirecting);
966 ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(c));
967 ast_channel_unlock(c);
968 if (ast_channel_redirecting_sub(c, in, &redirecting, 0) &&
969 ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
970 ast_channel_update_redirecting(in, &redirecting, NULL);
972 ast_party_redirecting_free(&redirecting);
973 ast_channel_unlock(in);
975 ast_clear_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE);
976 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
980 if (ast_call(c, stuff, 0)) {
981 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
983 ast_clear_flag64(o, DIAL_STILLGOING);
984 ast_hangup(original);
990 while (ast_channel_trylock(in)) {
991 CHANNEL_DEADLOCK_AVOIDANCE(c);
993 senddialevent(in, c, stuff);
994 ast_channel_unlock(in);
995 ast_channel_unlock(c);
996 /* Hangup the original channel now, in case we needed it */
997 ast_hangup(original);
999 if (single_caller_bored) {
1000 ast_indicate(in, -1);
1005 /* argument used for some functions. */
1006 struct privacy_args {
1010 char privintro[1024];
1014 static struct ast_channel *wait_for_answer(struct ast_channel *in,
1015 struct chanlist *outgoing, int *to, struct ast_flags64 *peerflags,
1017 struct privacy_args *pa,
1018 const struct cause_args *num_in, int *result, char *dtmf_progress,
1019 const int ignore_cc,
1020 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
1022 struct cause_args num = *num_in;
1023 int prestart = num.busy + num.congestion + num.nochan;
1025 struct ast_channel *peer = NULL;
1026 /* single is set if only one destination is enabled */
1027 int single = outgoing && !outgoing->next;
1028 int caller_entertained = outgoing
1029 && ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
1031 struct chanlist *epollo;
1033 struct ast_party_connected_line connected_caller;
1034 struct ast_str *featurecode = ast_str_alloca(FEATURE_MAX_LEN + 1);
1035 int cc_recall_core_id;
1037 int cc_frame_received = 0;
1038 int num_ringing = 0;
1040 ast_party_connected_line_init(&connected_caller);
1042 /* Turn off hold music, etc */
1043 if (!caller_entertained) {
1044 ast_deactivate_generator(in);
1045 /* If we are calling a single channel, and not providing ringback or music, */
1046 /* then, make them compatible for in-band tone purpose */
1047 if (ast_channel_make_compatible(outgoing->chan, in) < 0) {
1048 /* If these channels can not be made compatible,
1049 * there is no point in continuing. The bridge
1050 * will just fail if it gets that far.
1053 strcpy(pa->status, "CONGESTION");
1054 ast_cdr_failed(ast_channel_cdr(in));
1059 if (!ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE) && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
1060 ast_channel_lock(outgoing->chan);
1061 ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(outgoing->chan));
1062 ast_channel_unlock(outgoing->chan);
1063 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1064 if (ast_channel_connected_line_sub(outgoing->chan, in, &connected_caller, 0) &&
1065 ast_channel_connected_line_macro(outgoing->chan, in, &connected_caller, 1, 0)) {
1066 ast_channel_update_connected_line(in, &connected_caller, NULL);
1068 ast_party_connected_line_free(&connected_caller);
1072 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1075 for (epollo = outgoing; epollo; epollo = epollo->next)
1076 ast_poll_channel_add(in, epollo->chan);
1079 while (*to && !peer) {
1081 int pos = 0; /* how many channels do we handle */
1082 int numlines = prestart;
1083 struct ast_channel *winner;
1084 struct ast_channel *watchers[AST_MAX_WATCHERS];
1086 watchers[pos++] = in;
1087 for (o = outgoing; o; o = o->next) {
1088 /* Keep track of important channels */
1089 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1090 watchers[pos++] = o->chan;
1093 if (pos == 1) { /* only the input channel is available */
1094 if (numlines == (num.busy + num.congestion + num.nochan)) {
1095 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1097 strcpy(pa->status, "BUSY");
1098 else if (num.congestion)
1099 strcpy(pa->status, "CONGESTION");
1100 else if (num.nochan)
1101 strcpy(pa->status, "CHANUNAVAIL");
1103 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1107 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1111 winner = ast_waitfor_n(watchers, pos, to);
1112 for (o = outgoing; o; o = o->next) {
1113 struct ast_frame *f;
1114 struct ast_channel *c = o->chan;
1118 if (ast_test_flag64(o, DIAL_STILLGOING) && ast_channel_state(c) == AST_STATE_UP) {
1120 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1121 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1122 if (o->pending_connected_update) {
1123 if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
1124 ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1125 ast_channel_update_connected_line(in, &o->connected, NULL);
1127 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1128 ast_channel_lock(c);
1129 ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(c));
1130 ast_channel_unlock(c);
1131 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1132 if (ast_channel_connected_line_sub(c, in, &connected_caller, 0) &&
1133 ast_channel_connected_line_macro(c, in, &connected_caller, 1, 0)) {
1134 ast_channel_update_connected_line(in, &connected_caller, NULL);
1136 ast_party_connected_line_free(&connected_caller);
1139 if (o->aoc_s_rate_list) {
1140 size_t encoded_size;
1141 struct ast_aoc_encoded *encoded;
1142 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1143 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1144 ast_aoc_destroy_encoded(encoded);
1148 ast_copy_flags64(peerflags, o,
1149 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1150 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1151 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1152 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1153 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1154 DIAL_NOFORWARDHTML);
1155 ast_channel_dialcontext_set(c, "");
1156 ast_channel_exten_set(c, "");
1162 /* here, o->chan == c == winner */
1163 if (!ast_strlen_zero(ast_channel_call_forward(c))) {
1164 pa->sentringing = 0;
1165 if (!ignore_cc && (f = ast_read(c))) {
1166 if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
1167 /* This channel is forwarding the call, and is capable of CC, so
1168 * be sure to add the new device interface to the list
1170 ast_handle_cc_control_frame(in, c, f->data.ptr);
1174 do_forward(o, &num, peerflags, single && !caller_entertained, to,
1175 forced_clid, stored_clid);
1178 f = ast_read(winner);
1180 ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
1182 ast_poll_channel_del(in, c);
1186 ast_clear_flag64(o, DIAL_STILLGOING);
1187 handle_cause(ast_channel_hangupcause(in), &num);
1190 switch (f->frametype) {
1191 case AST_FRAME_CONTROL:
1192 switch (f->subclass.integer) {
1193 case AST_CONTROL_ANSWER:
1194 /* This is our guy if someone answered. */
1196 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1197 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1198 if (o->pending_connected_update) {
1199 if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
1200 ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1201 ast_channel_update_connected_line(in, &o->connected, NULL);
1203 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1204 ast_channel_lock(c);
1205 ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(c));
1206 ast_channel_unlock(c);
1207 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1208 if (ast_channel_connected_line_sub(c, in, &connected_caller, 0) &&
1209 ast_channel_connected_line_macro(c, in, &connected_caller, 1, 0)) {
1210 ast_channel_update_connected_line(in, &connected_caller, NULL);
1212 ast_party_connected_line_free(&connected_caller);
1215 if (o->aoc_s_rate_list) {
1216 size_t encoded_size;
1217 struct ast_aoc_encoded *encoded;
1218 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1219 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1220 ast_aoc_destroy_encoded(encoded);
1224 if (ast_channel_cdr(peer)) {
1225 ast_channel_cdr(peer)->answer = ast_tvnow();
1226 ast_channel_cdr(peer)->disposition = AST_CDR_ANSWERED;
1228 ast_copy_flags64(peerflags, o,
1229 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1230 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1231 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1232 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1233 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1234 DIAL_NOFORWARDHTML);
1235 ast_channel_dialcontext_set(c, "");
1236 ast_channel_exten_set(c, "");
1237 if (CAN_EARLY_BRIDGE(peerflags, in, peer))
1238 /* Setup early bridge if appropriate */
1239 ast_channel_early_bridge(in, peer);
1241 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1242 ast_channel_hangupcause_set(in, AST_CAUSE_NORMAL_CLEARING);
1243 ast_channel_hangupcause_set(c, AST_CAUSE_NORMAL_CLEARING);
1245 case AST_CONTROL_BUSY:
1246 ast_verb(3, "%s is busy\n", ast_channel_name(c));
1247 ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
1250 ast_clear_flag64(o, DIAL_STILLGOING);
1251 handle_cause(AST_CAUSE_BUSY, &num);
1253 case AST_CONTROL_CONGESTION:
1254 ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1255 ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
1258 ast_clear_flag64(o, DIAL_STILLGOING);
1259 handle_cause(AST_CAUSE_CONGESTION, &num);
1261 case AST_CONTROL_RINGING:
1262 /* This is a tricky area to get right when using a native
1263 * CC agent. The reason is that we do the best we can to send only a
1264 * single ringing notification to the caller.
1266 * Call completion complicates the logic used here. CCNR is typically
1267 * offered during a ringing message. Let's say that party A calls
1268 * parties B, C, and D. B and C do not support CC requests, but D
1269 * does. If we were to receive a ringing notification from B before
1270 * the others, then we would end up sending a ringing message to
1271 * A with no CCNR offer present.
1273 * The approach that we have taken is that if we receive a ringing
1274 * response from a party and no CCNR offer is present, we need to
1275 * wait. Specifically, we need to wait until either a) a called party
1276 * offers CCNR in its ringing response or b) all called parties have
1277 * responded in some way to our call and none offers CCNR.
1279 * The drawback to this is that if one of the parties has a delayed
1280 * response or, god forbid, one just plain doesn't respond to our
1281 * outgoing call, then this will result in a significant delay between
1282 * when the caller places the call and hears ringback.
1284 * Note also that if CC is disabled for this call, then it is perfectly
1285 * fine for ringing frames to get sent through.
1288 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1289 ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1290 /* Setup early media if appropriate */
1291 if (single && !caller_entertained
1292 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1293 ast_channel_early_bridge(in, c);
1295 if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
1296 ast_indicate(in, AST_CONTROL_RINGING);
1301 case AST_CONTROL_PROGRESS:
1302 ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1303 /* Setup early media if appropriate */
1304 if (single && !caller_entertained
1305 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1306 ast_channel_early_bridge(in, c);
1308 if (!ast_test_flag64(outgoing, OPT_RINGBACK)) {
1309 if (single || (!single && !pa->sentringing)) {
1310 ast_indicate(in, AST_CONTROL_PROGRESS);
1313 if (!ast_strlen_zero(dtmf_progress)) {
1315 "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n",
1317 ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1320 case AST_CONTROL_VIDUPDATE:
1321 case AST_CONTROL_SRCUPDATE:
1322 case AST_CONTROL_SRCCHANGE:
1323 if (!single || caller_entertained) {
1326 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1327 ast_channel_name(c), f->subclass.integer, ast_channel_name(in));
1328 ast_indicate(in, f->subclass.integer);
1330 case AST_CONTROL_CONNECTED_LINE:
1331 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1332 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1333 } else if (!single) {
1334 struct ast_party_connected_line connected;
1335 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", ast_channel_name(c), ast_channel_name(in));
1336 ast_party_connected_line_set_init(&connected, &o->connected);
1337 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
1338 ast_party_connected_line_set(&o->connected, &connected, NULL);
1339 ast_party_connected_line_free(&connected);
1340 o->pending_connected_update = 1;
1342 if (ast_channel_connected_line_sub(c, in, f, 1) &&
1343 ast_channel_connected_line_macro(c, in, f, 1, 1)) {
1344 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
1348 case AST_CONTROL_AOC:
1350 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1351 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1352 ast_aoc_destroy_decoded(o->aoc_s_rate_list);
1353 o->aoc_s_rate_list = decoded;
1355 ast_aoc_destroy_decoded(decoded);
1359 case AST_CONTROL_REDIRECTING:
1360 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1361 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1362 } else if (single) {
1363 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1364 if (ast_channel_redirecting_sub(c, in, f, 1) &&
1365 ast_channel_redirecting_macro(c, in, f, 1, 1)) {
1366 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
1368 pa->sentringing = 0;
1371 case AST_CONTROL_PROCEEDING:
1372 ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1373 if (single && !caller_entertained
1374 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1375 ast_channel_early_bridge(in, c);
1377 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1378 ast_indicate(in, AST_CONTROL_PROCEEDING);
1380 case AST_CONTROL_HOLD:
1381 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1382 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1383 ast_indicate_data(in, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
1385 case AST_CONTROL_UNHOLD:
1386 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1387 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1388 ast_indicate(in, AST_CONTROL_UNHOLD);
1390 case AST_CONTROL_OFFHOOK:
1391 case AST_CONTROL_FLASH:
1392 /* Ignore going off hook and flash */
1394 case AST_CONTROL_CC:
1396 ast_handle_cc_control_frame(in, c, f->data.ptr);
1397 cc_frame_received = 1;
1401 if (single && !caller_entertained) {
1402 ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1403 ast_indicate(in, -1);
1404 pa->sentringing = 0;
1408 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1412 case AST_FRAME_VOICE:
1413 case AST_FRAME_IMAGE:
1414 if (caller_entertained) {
1418 case AST_FRAME_TEXT:
1419 if (single && ast_write(in, f)) {
1420 ast_log(LOG_WARNING, "Unable to write frametype: %d\n",
1424 case AST_FRAME_HTML:
1425 if (single && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)
1426 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1427 ast_log(LOG_WARNING, "Unable to send URL\n");
1436 struct ast_frame *f = ast_read(in);
1438 if (f && (f->frametype != AST_FRAME_VOICE))
1439 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1440 else if (!f || (f->frametype != AST_FRAME_VOICE))
1441 printf("Hangup received on %s\n", in->name);
1443 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1446 strcpy(pa->status, "CANCEL");
1447 ast_cdr_noanswer(ast_channel_cdr(in));
1449 if (f->data.uint32) {
1450 ast_channel_hangupcause_set(in, f->data.uint32);
1455 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1460 /* now f is guaranteed non-NULL */
1461 if (f->frametype == AST_FRAME_DTMF) {
1462 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1463 const char *context;
1464 ast_channel_lock(in);
1465 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1466 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1467 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1469 ast_cdr_noanswer(ast_channel_cdr(in));
1470 *result = f->subclass.integer;
1471 strcpy(pa->status, "CANCEL");
1473 ast_channel_unlock(in);
1475 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1479 ast_channel_unlock(in);
1482 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1483 detect_disconnect(in, f->subclass.integer, featurecode)) {
1484 ast_verb(3, "User requested call disconnect.\n");
1486 strcpy(pa->status, "CANCEL");
1487 ast_cdr_noanswer(ast_channel_cdr(in));
1490 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1496 /* Send the frame from the in channel to all outgoing channels. */
1497 for (o = outgoing; o; o = o->next) {
1498 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1499 /* This outgoing channel has died so don't send the frame to it. */
1502 switch (f->frametype) {
1503 case AST_FRAME_HTML:
1504 /* Forward HTML stuff */
1505 if (!ast_test_flag64(o, DIAL_NOFORWARDHTML)
1506 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1507 ast_log(LOG_WARNING, "Unable to send URL\n");
1510 case AST_FRAME_VOICE:
1511 case AST_FRAME_IMAGE:
1512 if (!single || caller_entertained) {
1514 * We are calling multiple parties or caller is being
1515 * entertained and has thus not been made compatible.
1516 * No need to check any other called parties.
1521 case AST_FRAME_TEXT:
1522 case AST_FRAME_DTMF_BEGIN:
1523 case AST_FRAME_DTMF_END:
1524 if (ast_write(o->chan, f)) {
1525 ast_log(LOG_WARNING, "Unable to forward frametype: %d\n",
1529 case AST_FRAME_CONTROL:
1530 switch (f->subclass.integer) {
1531 case AST_CONTROL_HOLD:
1532 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1533 ast_indicate_data(o->chan, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
1535 case AST_CONTROL_UNHOLD:
1536 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1537 ast_indicate(o->chan, AST_CONTROL_UNHOLD);
1539 case AST_CONTROL_VIDUPDATE:
1540 case AST_CONTROL_SRCUPDATE:
1541 case AST_CONTROL_SRCCHANGE:
1542 if (!single || caller_entertained) {
1544 * We are calling multiple parties or caller is being
1545 * entertained and has thus not been made compatible.
1546 * No need to check any other called parties.
1550 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1551 ast_channel_name(in), f->subclass.integer, ast_channel_name(o->chan));
1552 ast_indicate(o->chan, f->subclass.integer);
1554 case AST_CONTROL_CONNECTED_LINE:
1555 if (ast_channel_connected_line_sub(in, o->chan, f, 1) &&
1556 ast_channel_connected_line_macro(in, o->chan, f, 0, 1)) {
1557 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1560 case AST_CONTROL_REDIRECTING:
1561 if (ast_channel_redirecting_sub(in, o->chan, f, 1) &&
1562 ast_channel_redirecting_macro(in, o->chan, f, 0, 1)) {
1563 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1567 /* We are not going to do anything with this frame. */
1572 /* We are not going to do anything with this frame. */
1580 ast_verb(3, "Nobody picked up in %d ms\n", orig);
1581 if (!*to || ast_check_hangup(in))
1582 ast_cdr_noanswer(ast_channel_cdr(in));
1586 for (epollo = outgoing; epollo; epollo = epollo->next) {
1588 ast_poll_channel_del(in, epollo->chan);
1593 ast_cc_completed(in, "Recall completed!");
1598 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode)
1600 struct ast_flags features = { AST_FEATURE_DISCONNECT }; /* only concerned with disconnect feature */
1601 struct ast_call_feature feature = { 0, };
1604 ast_str_append(&featurecode, 1, "%c", code);
1606 res = ast_feature_detect(chan, &features, ast_str_buffer(featurecode), &feature);
1608 if (res != AST_FEATURE_RETURN_STOREDIGITS) {
1609 ast_str_reset(featurecode);
1611 if (feature.feature_mask & AST_FEATURE_DISCONNECT) {
1618 /* returns true if there is a valid privacy reply */
1619 static int valid_priv_reply(struct ast_flags64 *opts, int res)
1623 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1625 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1630 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1631 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1637 /* Get the user's intro, store it in priv-callerintros/$CID,
1638 unless it is already there-- this should be done before the
1639 call is actually dialed */
1641 /* all ring indications and moh for the caller has been halted as soon as the
1642 target extension was picked up. We are going to have to kill some
1643 time and make the caller believe the peer hasn't picked up yet */
1645 if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
1646 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
1647 ast_indicate(chan, -1);
1648 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
1649 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1650 ast_channel_musicclass_set(chan, original_moh);
1651 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1652 ast_indicate(chan, AST_CONTROL_RINGING);
1656 /* Start autoservice on the other chan ?? */
1657 res2 = ast_autoservice_start(chan);
1658 /* Now Stream the File */
1659 for (loopcount = 0; loopcount < 3; loopcount++) {
1660 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1662 if (!res2) /* on timeout, play the message again */
1663 res2 = ast_play_and_wait(peer, "priv-callpending");
1664 if (!valid_priv_reply(opts, res2))
1666 /* priv-callpending script:
1667 "I have a caller waiting, who introduces themselves as:"
1670 res2 = ast_play_and_wait(peer, pa->privintro);
1671 if (!valid_priv_reply(opts, res2))
1673 /* now get input from the called party, as to their choice */
1675 /* XXX can we have both, or they are mutually exclusive ? */
1676 if (ast_test_flag64(opts, OPT_PRIVACY))
1677 res2 = ast_play_and_wait(peer, "priv-callee-options");
1678 if (ast_test_flag64(opts, OPT_SCREENING))
1679 res2 = ast_play_and_wait(peer, "screen-callee-options");
1681 /*! \page DialPrivacy Dial Privacy scripts
1682 \par priv-callee-options script:
1683 "Dial 1 if you wish this caller to reach you directly in the future,
1684 and immediately connect to their incoming call
1685 Dial 2 if you wish to send this caller to voicemail now and
1687 Dial 3 to send this caller to the torture menus, now and forevermore.
1688 Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
1689 Dial 5 to allow this caller to come straight thru to you in the future,
1690 but right now, just this once, send them to voicemail."
1691 \par screen-callee-options script:
1692 "Dial 1 if you wish to immediately connect to the incoming call
1693 Dial 2 if you wish to send this caller to voicemail.
1694 Dial 3 to send this caller to the torture menus.
1695 Dial 4 to send this caller to a simple "go away" menu.
1697 if (valid_priv_reply(opts, res2))
1699 /* invalid option */
1700 res2 = ast_play_and_wait(peer, "vm-sorry");
1703 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
1705 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1706 ast_indicate(chan, -1);
1707 pa->sentringing = 0;
1709 ast_autoservice_stop(chan);
1710 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
1711 /* map keypresses to various things, the index is res2 - '1' */
1712 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
1713 static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
1715 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
1716 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
1717 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
1723 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1726 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1729 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1732 /* XXX should we set status to DENY ? */
1733 if (ast_test_flag64(opts, OPT_PRIVACY))
1735 /* if not privacy, then 5 is the same as "default" case */
1736 default: /* bad input or -1 if failure to start autoservice */
1737 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
1738 /* well, there seems basically two choices. Just patch the caller thru immediately,
1739 or,... put 'em thru to voicemail. */
1740 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
1741 ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
1742 /* XXX should we set status to DENY ? */
1743 /* XXX what about the privacy flags ? */
1747 if (res2 == '1') { /* the only case where we actually connect */
1748 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
1749 just clog things up, and it's not useful information, not being tied to a CID */
1750 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
1751 ast_filedelete(pa->privintro, NULL);
1752 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1753 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1755 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1757 return 0; /* the good exit path */
1759 ast_hangup(peer); /* hang up on the callee -- he didn't want to talk anyway! */
1764 /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
1765 static int setup_privacy_args(struct privacy_args *pa,
1766 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
1772 if (ast_channel_caller(chan)->id.number.valid
1773 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
1774 l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
1775 ast_shrink_phone_number(l);
1776 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
1777 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
1778 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
1780 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
1781 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1786 tnam = ast_strdupa(ast_channel_name(chan));
1787 /* clean the channel name so slashes don't try to end up in disk file name */
1788 for (tn2 = tnam; *tn2; tn2++) {
1789 if (*tn2 == '/') /* any other chars to be afraid of? */
1792 ast_verb(3, "Privacy-- callerid is empty\n");
1794 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
1796 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1799 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
1801 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
1802 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
1803 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
1804 pa->privdb_val = AST_PRIVACY_ALLOW;
1805 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
1806 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
1809 if (pa->privdb_val == AST_PRIVACY_DENY) {
1810 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
1811 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1813 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
1814 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1815 return 0; /* Is this right? */
1816 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
1817 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1818 return 0; /* is this right??? */
1819 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
1820 /* Get the user's intro, store it in priv-callerintros/$CID,
1821 unless it is already there-- this should be done before the
1822 call is actually dialed */
1824 /* make sure the priv-callerintros dir actually exists */
1825 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
1826 if ((res = ast_mkdir(pa->privintro, 0755))) {
1827 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
1831 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
1832 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
1833 /* the DELUX version of this code would allow this caller the
1834 option to hear and retape their previously recorded intro.
1837 int duration; /* for feedback from play_and_wait */
1838 /* the file doesn't exist yet. Let the caller submit his
1839 vocal intro for posterity */
1840 /* priv-recordintro script:
1842 "At the tone, please say your name:"
1845 int silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
1847 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
1848 /* don't think we'll need a lock removed, we took care of
1849 conflicts by naming the pa.privintro file */
1851 /* Delete the file regardless since they hung up during recording */
1852 ast_filedelete(pa->privintro, NULL);
1853 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1854 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1856 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1859 if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
1860 ast_waitstream(chan, "");
1863 return 1; /* success */
1866 static void end_bridge_callback(void *data)
1870 struct ast_channel *chan = data;
1872 if (!ast_channel_cdr(chan)) {
1878 ast_channel_lock(chan);
1879 if (ast_channel_cdr(chan)->answer.tv_sec) {
1880 snprintf(buf, sizeof(buf), "%ld", (long) end - ast_channel_cdr(chan)->answer.tv_sec);
1881 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
1884 if (ast_channel_cdr(chan)->start.tv_sec) {
1885 snprintf(buf, sizeof(buf), "%ld", (long) end - ast_channel_cdr(chan)->start.tv_sec);
1886 pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
1888 ast_channel_unlock(chan);
1891 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
1892 bconfig->end_bridge_callback_data = originator;
1895 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
1897 struct ast_tone_zone_sound *ts = NULL;
1899 const char *str = data;
1901 if (ast_strlen_zero(str)) {
1902 ast_debug(1,"Nothing to play\n");
1906 ts = ast_get_indication_tone(ast_channel_zone(chan), str);
1908 if (ts && ts->data[0]) {
1909 res = ast_playtones_start(chan, 0, ts->data, 0);
1915 ts = ast_tone_zone_sound_unref(ts);
1919 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
1925 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
1927 int res = -1; /* default: error */
1928 char *rest, *cur; /* scan the list of destinations */
1929 struct chanlist *outgoing = NULL; /* list of destinations */
1930 struct ast_channel *peer;
1931 int to; /* timeout */
1932 struct cause_args num = { chan, 0, 0, 0 };
1936 struct ast_bridge_config config = { { 0, } };
1937 struct timeval calldurationlimit = { 0, };
1938 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
1939 struct privacy_args pa = {
1942 .status = "INVALIDARGS",
1944 int sentringing = 0, moh = 0;
1945 const char *outbound_group = NULL;
1949 int delprivintro = 0;
1950 AST_DECLARE_APP_ARGS(args,
1952 AST_APP_ARG(timeout);
1953 AST_APP_ARG(options);
1956 struct ast_flags64 opts = { 0, };
1957 char *opt_args[OPT_ARG_ARRAY_SIZE];
1958 struct ast_datastore *datastore = NULL;
1959 int fulldial = 0, num_dialed = 0;
1961 char device_name[AST_CHANNEL_NAME];
1962 char forced_clid_name[AST_MAX_EXTENSION];
1963 char stored_clid_name[AST_MAX_EXTENSION];
1964 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
1966 * \brief Forced CallerID party information to send.
1967 * \note This will not have any malloced strings so do not free it.
1969 struct ast_party_id forced_clid;
1971 * \brief Stored CallerID information if needed.
1973 * \note If OPT_ORIGINAL_CLID set then this is the o option
1974 * CallerID. Otherwise it is the dialplan extension and hint
1977 * \note This will not have any malloced strings so do not free it.
1979 struct ast_party_id stored_clid;
1981 * \brief CallerID party information to store.
1982 * \note This will not have any malloced strings so do not free it.
1984 struct ast_party_caller caller;
1986 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
1987 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
1988 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
1989 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
1990 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
1991 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
1993 if (ast_strlen_zero(data)) {
1994 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1995 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1999 parse = ast_strdupa(data);
2001 AST_STANDARD_APP_ARGS(args, parse);
2003 if (!ast_strlen_zero(args.options) &&
2004 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2005 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2009 if (ast_strlen_zero(args.peers)) {
2010 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
2011 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2015 if (ast_cc_call_init(chan, &ignore_cc)) {
2019 if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
2020 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2022 if (delprivintro < 0 || delprivintro > 1) {
2023 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2028 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2029 opt_args[OPT_ARG_RINGBACK] = NULL;
2032 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2033 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2034 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2037 if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
2038 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2039 if (!calldurationlimit.tv_sec) {
2040 ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
2041 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2044 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2047 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2048 dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
2049 dtmfcalled = strsep(&dtmf_progress, ":");
2050 dtmfcalling = strsep(&dtmf_progress, ":");
2053 if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
2054 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2058 /* Setup the forced CallerID information to send if used. */
2059 ast_party_id_init(&forced_clid);
2060 force_forwards_only = 0;
2061 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2062 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2063 ast_channel_lock(chan);
2064 forced_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
2065 ast_channel_unlock(chan);
2066 forced_clid_name[0] = '\0';
2067 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2068 sizeof(forced_clid_name), chan);
2069 force_forwards_only = 1;
2071 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2072 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2073 &forced_clid.number.str);
2075 if (!ast_strlen_zero(forced_clid.name.str)) {
2076 forced_clid.name.valid = 1;
2078 if (!ast_strlen_zero(forced_clid.number.str)) {
2079 forced_clid.number.valid = 1;
2082 if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG)
2083 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2084 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2086 forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
2087 if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES)
2088 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2091 pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
2093 forced_clid.number.presentation = pres;
2097 /* Setup the stored CallerID information if needed. */
2098 ast_party_id_init(&stored_clid);
2099 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2100 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2101 ast_channel_lock(chan);
2102 ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2103 if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2104 stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2106 if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2107 stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2109 if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2110 stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2112 if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2113 stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2115 ast_channel_unlock(chan);
2117 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2118 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2119 &stored_clid.number.str);
2120 if (!ast_strlen_zero(stored_clid.name.str)) {
2121 stored_clid.name.valid = 1;
2123 if (!ast_strlen_zero(stored_clid.number.str)) {
2124 stored_clid.number.valid = 1;
2129 * In case the new channel has no preset CallerID number by the
2130 * channel driver, setup the dialplan extension and hint name.
2132 stored_clid_name[0] = '\0';
2133 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2134 sizeof(stored_clid_name), chan);
2135 if (ast_strlen_zero(stored_clid.name.str)) {
2136 stored_clid.name.str = NULL;
2138 stored_clid.name.valid = 1;
2140 ast_channel_lock(chan);
2141 stored_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
2142 stored_clid.number.valid = 1;
2143 ast_channel_unlock(chan);
2146 if (ast_test_flag64(&opts, OPT_RESETCDR) && ast_channel_cdr(chan))
2147 ast_cdr_reset(ast_channel_cdr(chan), NULL);
2148 if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
2149 opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan));
2151 if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
2152 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2155 res = -1; /* reset default */
2161 /* If a channel group has been specified, get it for use when we create peer channels */
2163 ast_channel_lock(chan);
2164 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2165 outbound_group = ast_strdupa(outbound_group);
2166 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2167 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2168 outbound_group = ast_strdupa(outbound_group);
2170 ast_channel_unlock(chan);
2171 ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_IGNORE_CONNECTEDLINE |
2172 OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
2174 /* loop through the list of dial destinations */
2176 while ((cur = strsep(&rest, "&")) ) {
2177 struct chanlist *tmp;
2178 struct ast_channel *tc; /* channel for this destination */
2179 /* Get a technology/[device:]number pair */
2181 char *interface = ast_strdupa(number);
2182 char *tech = strsep(&number, "/");
2183 /* find if we already dialed this interface */
2184 struct ast_dialed_interface *di;
2185 AST_LIST_HEAD(,ast_dialed_interface) *dialed_interfaces;
2187 if (ast_strlen_zero(number)) {
2188 ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
2191 if (!(tmp = ast_calloc(1, sizeof(*tmp))))
2194 ast_copy_flags64(tmp, &opts,
2195 OPT_CANCEL_ELSEWHERE |
2196 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
2197 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
2198 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
2199 OPT_CALLEE_PARK | OPT_CALLER_PARK |
2200 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
2201 OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
2202 ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
2204 ast_copy_string(numsubst, number, sizeof(numsubst));
2205 /* Request the peer */
2207 ast_channel_lock(chan);
2208 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL);
2210 * Seed the chanlist's connected line information with previously
2211 * acquired connected line info from the incoming channel. The
2212 * previously acquired connected line info could have been set
2213 * through the CONNECTED_LINE dialplan function.
2215 ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan));
2216 ast_channel_unlock(chan);
2219 dialed_interfaces = datastore->data;
2221 if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) {
2222 ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n");
2227 datastore->inheritance = DATASTORE_INHERIT_FOREVER;
2229 if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
2230 ast_datastore_free(datastore);
2235 datastore->data = dialed_interfaces;
2236 AST_LIST_HEAD_INIT(dialed_interfaces);
2238 ast_channel_lock(chan);
2239 ast_channel_datastore_add(chan, datastore);
2240 ast_channel_unlock(chan);
2243 AST_LIST_LOCK(dialed_interfaces);
2244 AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
2245 if (!strcasecmp(di->interface, interface)) {
2246 ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n",
2251 AST_LIST_UNLOCK(dialed_interfaces);
2259 /* It is always ok to dial a Local interface. We only keep track of
2260 * which "real" interfaces have been dialed. The Local channel will
2261 * inherit this list so that if it ends up dialing a real interface,
2262 * it won't call one that has already been called. */
2263 if (strcasecmp(tech, "Local")) {
2264 if (!(di = ast_calloc(1, sizeof(*di) + strlen(interface)))) {
2265 AST_LIST_UNLOCK(dialed_interfaces);
2269 strcpy(di->interface, interface);
2271 AST_LIST_LOCK(dialed_interfaces);
2272 AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
2273 AST_LIST_UNLOCK(dialed_interfaces);
2276 tc = ast_request(tech, ast_channel_nativeformats(chan), chan, numsubst, &cause);
2278 /* If we can't, just go on to the next call */
2279 ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
2280 tech, cause, ast_cause2str(cause));
2281 handle_cause(cause, &num);
2282 if (!rest) /* we are on the last destination */
2283 ast_channel_hangupcause_set(chan, cause);
2285 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2286 if (!ast_cc_callback(chan, tech, numsubst, ast_cc_busy_interface)) {
2287 ast_cc_extension_monitor_add_dialstring(chan, interface, "");
2292 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2294 ast_cc_extension_monitor_add_dialstring(chan, interface, device_name);
2296 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
2298 ast_channel_lock(tc);
2299 while (ast_channel_trylock(chan)) {
2300 CHANNEL_DEADLOCK_AVOIDANCE(tc);
2302 /* Setup outgoing SDP to match incoming one */
2303 if (!outgoing && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2304 ast_rtp_instance_early_bridge_make_compatible(tc, chan);
2307 /* Inherit specially named variables from parent channel */
2308 ast_channel_inherit_variables(chan, tc);
2309 ast_channel_datastore_inherit(chan, tc);
2311 ast_channel_appl_set(tc, "AppDial");
2312 ast_channel_data_set(tc, "(Outgoing Line)");
2313 memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2315 /* Determine CallerID to store in outgoing channel. */
2316 ast_party_caller_set_init(&caller, ast_channel_caller(tc));
2317 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2318 caller.id = stored_clid;
2319 ast_channel_set_caller_event(tc, &caller, NULL);
2320 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2321 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2322 ast_channel_caller(tc)->id.number.str, NULL))) {
2324 * The new channel has no preset CallerID number by the channel
2325 * driver. Use the dialplan extension and hint name.
2327 caller.id = stored_clid;
2328 if (!caller.id.name.valid
2329 && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2330 ast_channel_connected(chan)->id.name.str, NULL))) {
2332 * No hint name available. We have a connected name supplied by
2333 * the dialplan we can use instead.
2335 caller.id.name.valid = 1;
2336 caller.id.name = ast_channel_connected(chan)->id.name;
2338 ast_channel_set_caller_event(tc, &caller, NULL);
2339 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2340 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2342 /* The new channel has no preset CallerID name by the channel driver. */
2343 if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2344 ast_channel_connected(chan)->id.name.str, NULL))) {
2346 * We have a connected name supplied by the dialplan we can
2349 caller.id.name.valid = 1;
2350 caller.id.name = ast_channel_connected(chan)->id.name;
2351 ast_channel_set_caller_event(tc, &caller, NULL);
2355 /* Determine CallerID for outgoing channel to send. */
2356 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2357 struct ast_party_connected_line connected;
2359 ast_party_connected_line_set_init(&connected, ast_channel_connected(tc));
2360 connected.id = forced_clid;
2361 ast_channel_set_connected_line(tc, &connected, NULL);
2363 ast_connected_line_copy_from_caller(ast_channel_connected(tc), ast_channel_caller(chan));
2366 ast_party_redirecting_copy(ast_channel_redirecting(tc), ast_channel_redirecting(chan));
2368 ast_channel_dialed(tc)->transit_network_select = ast_channel_dialed(chan)->transit_network_select;
2370 if (!ast_strlen_zero(ast_channel_accountcode(chan))) {
2371 ast_channel_accountcode_set(tc, ast_channel_accountcode(chan));
2373 if (ast_strlen_zero(ast_channel_musicclass(tc))) {
2374 ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2377 /* Pass ADSI CPE and transfer capability */
2378 ast_channel_adsicpe_set(tc, ast_channel_adsicpe(chan));
2379 ast_channel_transfercapability_set(tc, ast_channel_transfercapability(chan));
2381 /* If we have an outbound group, set this peer channel to it */
2383 ast_app_group_set_channel(tc, outbound_group);
2384 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2385 if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE))
2386 ast_set_flag(ast_channel_flags(tc), AST_FLAG_ANSWERED_ELSEWHERE);
2388 /* Check if we're forced by configuration */
2389 if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
2390 ast_set_flag(ast_channel_flags(tc), AST_FLAG_ANSWERED_ELSEWHERE);
2393 /* Inherit context and extension */
2394 ast_channel_dialcontext_set(tc, ast_strlen_zero(ast_channel_macrocontext(chan)) ? ast_channel_context(chan) : ast_channel_macrocontext(chan));
2395 if (!ast_strlen_zero(ast_channel_macroexten(chan)))
2396 ast_channel_exten_set(tc, ast_channel_macroexten(chan));
2398 ast_channel_exten_set(tc, ast_channel_exten(chan));
2400 ast_channel_unlock(tc);
2401 ast_channel_unlock(chan);
2402 res = ast_call(tc, numsubst, 0); /* Place the call, but don't wait on the answer */
2403 ast_channel_lock(chan);
2405 /* Save the info in cdr's that we called them */
2406 if (ast_channel_cdr(chan))
2407 ast_cdr_setdestchan(ast_channel_cdr(chan), ast_channel_name(tc));
2409 /* check the results of ast_call */
2411 /* Again, keep going even if there's an error */
2412 ast_debug(1, "ast call on peer returned %d\n", res);
2413 ast_verb(3, "Couldn't call %s/%s\n", tech, numsubst);
2414 if (ast_channel_hangupcause(tc)) {
2415 ast_channel_hangupcause_set(chan, ast_channel_hangupcause(tc));
2417 ast_channel_unlock(chan);
2418 ast_cc_call_failed(chan, tc, interface);
2424 senddialevent(chan, tc, numsubst);
2425 ast_verb(3, "Called %s/%s\n", tech, numsubst);
2426 ast_channel_unlock(chan);
2428 /* Put them in the list of outgoing thingies... We're ready now.
2429 XXX If we're forcibly removed, these outgoing calls won't get
2431 ast_set_flag64(tmp, DIAL_STILLGOING);
2433 tmp->next = outgoing;
2435 /* If this line is up, don't try anybody else */
2436 if (ast_channel_state(outgoing->chan) == AST_STATE_UP)
2440 if (ast_strlen_zero(args.timeout)) {
2443 to = atoi(args.timeout);
2447 ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2453 strcpy(pa.status, "CHANUNAVAIL");
2454 if (fulldial == num_dialed) {
2459 /* Our status will at least be NOANSWER */
2460 strcpy(pa.status, "NOANSWER");
2461 if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
2463 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2464 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2465 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2466 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2467 ast_channel_musicclass_set(chan, original_moh);
2469 ast_moh_start(chan, NULL, NULL);
2471 ast_indicate(chan, AST_CONTROL_PROGRESS);
2472 } else if (ast_test_flag64(outgoing, OPT_RINGBACK)) {
2473 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2474 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2475 ast_indicate(chan, AST_CONTROL_RINGING);
2478 ast_indicate(chan, AST_CONTROL_PROGRESS);
2481 ast_indicate(chan, AST_CONTROL_RINGING);
2487 peer = wait_for_answer(chan, outgoing, &to, peerflags, opt_args, &pa, &num, &result,
2488 dtmf_progress, ignore_cc, &forced_clid, &stored_clid);
2490 /* The ast_channel_datastore_remove() function could fail here if the
2491 * datastore was moved to another channel during a masquerade. If this is
2492 * the case, don't free the datastore here because later, when the channel
2493 * to which the datastore was moved hangs up, it will attempt to free this
2494 * datastore again, causing a crash
2496 ast_channel_lock(chan);
2497 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL); /* make sure we weren't cleaned up already */
2498 if (datastore && !ast_channel_datastore_remove(chan, datastore)) {
2499 ast_datastore_free(datastore);
2501 ast_channel_unlock(chan);
2505 } else if (to) { /* Musta gotten hung up */
2507 } else { /* Nobody answered, next please? */
2513 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER))
2516 strcpy(pa.status, "ANSWER");
2517 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2518 /* Ah ha! Someone answered within the desired timeframe. Of course after this
2519 we will always return with -1 so that it is hung up properly after the
2521 hanguptree(outgoing, peer, 1);
2523 /* If appropriate, log that we have a destination channel and set the answer time */
2524 if (ast_channel_cdr(chan)) {
2525 ast_cdr_setdestchan(ast_channel_cdr(chan), ast_channel_name(peer));
2526 ast_cdr_setanswer(ast_channel_cdr(chan), ast_channel_cdr(peer)->answer);
2528 if (ast_channel_name(peer))
2529 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", ast_channel_name(peer));
2531 ast_channel_lock(peer);
2532 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
2535 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
2536 ast_channel_unlock(peer);
2538 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
2539 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
2540 ast_channel_sendurl( peer, args.url );
2542 if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
2543 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
2548 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
2552 struct ast_channel *chans[2];
2553 struct ast_channel *active_chan;
2558 /* we need to stream the announcment while monitoring the caller for a hangup */
2560 /* stream the file */
2561 res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
2564 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
2567 ast_set_flag(ast_channel_flags(peer), AST_FLAG_END_DTMF_ONLY);
2568 while (ast_channel_stream(peer)) {
2571 ms = ast_sched_wait(ast_channel_sched(peer));
2573 if (ms < 0 && !ast_channel_timingfunc(peer)) {
2574 ast_stopstream(peer);
2580 active_chan = ast_waitfor_n(chans, 2, &ms);
2582 struct ast_frame *fr = ast_read(active_chan);
2588 switch(fr->frametype) {
2589 case AST_FRAME_DTMF_END:
2590 digit = fr->subclass.integer;
2591 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
2592 ast_stopstream(peer);
2593 res = ast_senddigit(chan, digit, 0);
2596 case AST_FRAME_CONTROL:
2597 switch (fr->subclass.integer) {
2598 case AST_CONTROL_HANGUP:
2608 /* Ignore all others */
2613 ast_sched_runq(ast_channel_sched(peer));
2615 ast_clear_flag(ast_channel_flags(peer), AST_FLAG_END_DTMF_ONLY);
2618 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
2619 /* chan and peer are going into the PBX, they both
2620 * should probably get CDR records. */
2621 ast_clear_flag(ast_channel_cdr(chan), AST_CDR_FLAG_DIALED);
2622 ast_clear_flag(ast_channel_cdr(peer), AST_CDR_FLAG_DIALED);
2624 ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
2625 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
2626 /* peer goes to the same context and extension as chan, so just copy info from chan*/
2627 ast_channel_context_set(peer, ast_channel_context(chan));
2628 ast_channel_exten_set(peer, ast_channel_exten(chan));
2629 ast_channel_priority_set(peer, ast_channel_priority(chan) + 2);
2630 ast_pbx_start(peer);
2631 hanguptree(outgoing, NULL, ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0);
2638 if (ast_test_flag64(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
2639 struct ast_app *theapp;
2640 const char *macro_result;
2642 res = ast_autoservice_start(chan);
2644 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
2648 theapp = pbx_findapp("Macro");
2650 if (theapp && !res) { /* XXX why check res here ? */
2651 /* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
2652 ast_channel_context_set(peer, ast_channel_context(chan));
2653 ast_channel_exten_set(peer, ast_channel_exten(chan));
2655 ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
2656 res = pbx_exec(peer, theapp, opt_args[OPT_ARG_CALLEE_MACRO]);
2657 ast_debug(1, "Macro exited with status %d\n", res);
2660 ast_log(LOG_ERROR, "Could not find application Macro\n");
2664 if (ast_autoservice_stop(chan) < 0) {
2668 ast_channel_lock(peer);
2670 if (!res && (macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
2671 char *macro_transfer_dest;
2673 if (!strcasecmp(macro_result, "BUSY")) {
2674 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
2675 ast_set_flag64(peerflags, OPT_GO_ON);
2677 } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
2678 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
2679 ast_set_flag64(peerflags, OPT_GO_ON);
2681 } else if (!strcasecmp(macro_result, "CONTINUE")) {
2682 /* hangup peer and keep chan alive assuming the macro has changed
2683 the context / exten / priority or perhaps
2684 the next priority in the current exten is desired.
2686 ast_set_flag64(peerflags, OPT_GO_ON);
2688 } else if (!strcasecmp(macro_result, "ABORT")) {
2689 /* Hangup both ends unless the caller has the g flag */
2691 } else if (!strncasecmp(macro_result, "GOTO:", 5) && (macro_transfer_dest = ast_strdupa(macro_result + 5))) {
2693 /* perform a transfer to a new extension */
2694 if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
2695 ast_replace_subargument_delimiter(macro_transfer_dest);
2696 if (!ast_parseable_goto(chan, macro_transfer_dest))
2697 ast_set_flag64(peerflags, OPT_GO_ON);
2702 ast_channel_unlock(peer);
2705 if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
2706 struct ast_app *theapp;
2707 const char *gosub_result;
2708 char *gosub_args, *gosub_argstart;
2711 res9 = ast_autoservice_start(chan);
2713 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
2717 theapp = pbx_findapp("Gosub");
2719 if (theapp && !res9) {
2720 ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
2722 /* Set where we came from */
2723 ast_channel_context_set(peer, "app_dial_gosub_virtual_context");
2724 ast_channel_exten_set(peer, "s");
2725 ast_channel_priority_set(peer, 0);
2727 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
2728 if (gosub_argstart) {
2729 const char *what_is_s = "s";
2730 *gosub_argstart = 0;
2731 if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
2732 ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
2733 what_is_s = "~~s~~";
2735 if (asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
2736 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
2739 *gosub_argstart = ',';
2741 const char *what_is_s = "s";
2742 if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
2743 ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
2744 what_is_s = "~~s~~";
2746 if (asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
2747 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
2753 res9 = pbx_exec(peer, theapp, gosub_args);
2755 struct ast_pbx_args pbx_args;
2756 /* A struct initializer fails to compile for this case ... */
2757 memset(&pbx_args, 0, sizeof(pbx_args));
2758 pbx_args.no_hangup_chan = 1;
2759 ast_pbx_run_args(peer, &pbx_args);
2761 ast_free(gosub_args);
2762 ast_debug(1, "Gosub exited with status %d\n", res9);
2764 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
2768 ast_log(LOG_ERROR, "Could not find application Gosub\n");
2772 if (ast_autoservice_stop(chan) < 0) {
2773 ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n");
2777 ast_channel_lock(peer);
2779 if (!res9 && (gosub_result = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
2780 char *gosub_transfer_dest;
2781 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
2783 /* Inherit return value from the peer, so it can be used in the master */
2785 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
2788 if (!strcasecmp(gosub_result, "BUSY")) {
2789 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
2790 ast_set_flag64(peerflags, OPT_GO_ON);
2792 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
2793 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
2794 ast_set_flag64(peerflags, OPT_GO_ON);
2796 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
2797 /* hangup peer and keep chan alive assuming the macro has changed
2798 the context / exten / priority or perhaps
2799 the next priority in the current exten is desired.
2801 ast_set_flag64(peerflags, OPT_GO_ON);
2803 } else if (!strcasecmp(gosub_result, "ABORT")) {
2804 /* Hangup both ends unless the caller has the g flag */