2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2012, 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 <support_level>core</support_level>
35 ASTERISK_REGISTER_FILE()
38 #include <sys/signal.h>
40 #include <netinet/in.h>
42 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
43 #include "asterisk/lock.h"
44 #include "asterisk/file.h"
45 #include "asterisk/channel.h"
46 #include "asterisk/pbx.h"
47 #include "asterisk/module.h"
48 #include "asterisk/translate.h"
49 #include "asterisk/say.h"
50 #include "asterisk/config.h"
51 #include "asterisk/features.h"
52 #include "asterisk/musiconhold.h"
53 #include "asterisk/callerid.h"
54 #include "asterisk/utils.h"
55 #include "asterisk/app.h"
56 #include "asterisk/causes.h"
57 #include "asterisk/rtp_engine.h"
58 #include "asterisk/manager.h"
59 #include "asterisk/privacy.h"
60 #include "asterisk/stringfields.h"
61 #include "asterisk/dsp.h"
62 #include "asterisk/aoc.h"
63 #include "asterisk/ccss.h"
64 #include "asterisk/indications.h"
65 #include "asterisk/framehook.h"
66 #include "asterisk/dial.h"
67 #include "asterisk/stasis_channels.h"
68 #include "asterisk/bridge_after.h"
69 #include "asterisk/features_config.h"
70 #include "asterisk/max_forwards.h"
73 <application name="Dial" language="en_US">
75 Attempt to connect to another device or endpoint and bridge the call.
78 <parameter name="Technology/Resource" required="true" argsep="&">
79 <argument name="Technology/Resource" required="true">
80 <para>Specification of the device(s) to dial. These must be in the format of
81 <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
82 represents a particular channel driver, and <replaceable>Resource</replaceable>
83 represents a resource available to that particular channel driver.</para>
85 <argument name="Technology2/Resource2" required="false" multiple="true">
86 <para>Optional extra devices to dial in parallel</para>
87 <para>If you need more then one enter them as
88 Technology2/Resource2&Technology3/Resourse3&.....</para>
91 <parameter name="timeout" required="false">
92 <para>Specifies the number of seconds we attempt to dial the specified devices</para>
93 <para>If not specified, this defaults to 136 years.</para>
95 <parameter name="options" required="false">
98 <argument name="x" required="true">
99 <para>The file to play to the called party</para>
101 <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
104 <para>Immediately answer the calling channel when the called channel answers in
105 all cases. Normally, the calling channel is answered when the called channel
106 answers, but when options such as A() and M() are used, the calling channel is
107 not answered until all actions on the called channel (such as playing an
108 announcement) are completed. This option can be used to answer the calling
109 channel before doing anything on the called channel. You will rarely need to use
110 this option, the default behavior is adequate in most cases.</para>
112 <option name="b" argsep="^">
113 <para>Before initiating an outgoing call, Gosub to the specified
114 location using the newly created channel. The Gosub will be
115 executed for each destination channel.</para>
116 <argument name="context" required="false" />
117 <argument name="exten" required="false" />
118 <argument name="priority" required="true" hasparams="optional" argsep="^">
119 <argument name="arg1" multiple="true" required="true" />
120 <argument name="argN" />
123 <option name="B" argsep="^">
124 <para>Before initiating the outgoing call(s), Gosub to the specified
125 location using the current channel.</para>
126 <argument name="context" required="false" />
127 <argument name="exten" required="false" />
128 <argument name="priority" required="true" hasparams="optional" argsep="^">
129 <argument name="arg1" multiple="true" required="true" />
130 <argument name="argN" />
134 <para>Reset the call detail record (CDR) for this call.</para>
137 <para>If the Dial() application cancels this call, always set HANGUPCAUSE to 'answered elsewhere'</para>
140 <para>Allow the calling user to dial a 1 digit extension while waiting for
141 a call to be answered. Exit to that extension if it exists in the
142 current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
145 <para>Many SIP and ISDN phones cannot send DTMF digits until the call is
146 connected. If you wish to use this option with these phones, you
147 can use the <literal>Answer</literal> application before dialing.</para>
150 <option name="D" argsep=":">
151 <argument name="called" />
152 <argument name="calling" />
153 <argument name="progress" />
154 <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
155 party has answered, but before the call gets bridged. The
156 <replaceable>called</replaceable> DTMF string is sent to the called party, and the
157 <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
158 can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
159 to the called party immediately after receiving a PROGRESS message.</para>
160 <para>See SendDTMF for valid digits.</para>
163 <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
166 <argument name="x" required="false" />
167 <para>If <replaceable>x</replaceable> is not provided, force the CallerID sent on a call-forward or
168 deflection to the dialplan extension of this Dial() using a dialplan <literal>hint</literal>.
169 For example, some PSTNs do not allow CallerID to be set to anything
170 other than the numbers assigned to you.
171 If <replaceable>x</replaceable> is provided, force the CallerID sent to <replaceable>x</replaceable>.</para>
173 <option name="F" argsep="^">
174 <argument name="context" required="false" />
175 <argument name="exten" required="false" />
176 <argument name="priority" required="true" />
177 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party
178 to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
180 <para>Any channel variables you want the called channel to inherit from the caller channel must be
181 prefixed with one or two underbars ('_').</para>
185 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party to the next priority of the current extension
186 and <emphasis>start</emphasis> execution at that location.</para>
188 <para>Any channel variables you want the called channel to inherit from the caller channel must be
189 prefixed with one or two underbars ('_').</para>
192 <para>Using this option from a Macro() or GoSub() might not make sense as there would be no return points.</para>
196 <para>Proceed with dialplan execution at the next priority in the current extension if the
197 destination channel hangs up.</para>
199 <option name="G" argsep="^">
200 <argument name="context" required="false" />
201 <argument name="exten" required="false" />
202 <argument name="priority" required="true" />
203 <para>If the call is answered, transfer the calling party to
204 the specified <replaceable>priority</replaceable> and the called party to the specified
205 <replaceable>priority</replaceable> plus one.</para>
207 <para>You cannot use any additional action post answer options in conjunction with this option.</para>
211 <para>Allow the called party to hang up by sending the DTMF sequence
212 defined for disconnect in <filename>features.conf</filename>.</para>
215 <para>Allow the calling party to hang up by sending the DTMF sequence
216 defined for disconnect in <filename>features.conf</filename>.</para>
218 <para>Many SIP and ISDN phones cannot send DTMF digits until the call is
219 connected. If you wish to allow DTMF disconnect before the dialed
220 party answers with these phones, you can use the <literal>Answer</literal>
221 application before dialing.</para>
225 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
228 <para>Asterisk will ignore any connected line update requests or any redirecting party
229 update requests it may receive on this dial attempt.</para>
232 <para>Allow the called party to enable parking of the call by sending
233 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
236 <para>Allow the calling party to enable parking of the call by sending
237 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
239 <option name="L" argsep=":">
240 <argument name="x" required="true">
241 <para>Maximum call time, in milliseconds</para>
244 <para>Warning time, in milliseconds</para>
247 <para>Repeat time, in milliseconds</para>
249 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
250 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
251 <para>This option is affected by the following variables:</para>
253 <variable name="LIMIT_PLAYAUDIO_CALLER">
254 <value name="yes" default="true" />
256 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
258 <variable name="LIMIT_PLAYAUDIO_CALLEE">
260 <value name="no" default="true"/>
261 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
263 <variable name="LIMIT_TIMEOUT_FILE">
264 <value name="filename"/>
265 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
266 If not set, the time remaining will be announced.</para>
268 <variable name="LIMIT_CONNECT_FILE">
269 <value name="filename"/>
270 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
271 If not set, the time remaining will be announced.</para>
273 <variable name="LIMIT_WARNING_FILE">
274 <value name="filename"/>
275 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
276 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
281 <argument name="class" required="false"/>
282 <para>Provide hold music to the calling party until a requested
283 channel answers. A specific music on hold <replaceable>class</replaceable>
284 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
286 <option name="M" argsep="^">
287 <argument name="macro" required="true">
288 <para>Name of the macro that should be executed.</para>
290 <argument name="arg" multiple="true">
291 <para>Macro arguments</para>
293 <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
294 before connecting to the calling channel. Arguments can be specified to the Macro
295 using <literal>^</literal> as a delimiter. The macro can set the variable
296 <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
297 finished executing:</para>
299 <variable name="MACRO_RESULT">
300 <para>If set, this action will be taken after the macro finished executing.</para>
302 Hangup both legs of the call
304 <value name="CONGESTION">
305 Behave as if line congestion was encountered
308 Behave as if a busy signal was encountered
310 <value name="CONTINUE">
311 Hangup the called party and allow the calling party to continue dialplan execution at the next priority
313 <value name="GOTO:[[<context>^]<exten>^]<priority>">
314 Transfer the call to the specified destination.
319 <para>You cannot use any additional action post answer options in conjunction
320 with this option. Also, pbx services are run on the peer (called) channel,
321 so you will not be able to set timeouts via the TIMEOUT() function in this macro.</para>
323 <warning><para>Be aware of the limitations that macros have, specifically with regards to use of
324 the <literal>WaitExten</literal> application. For more information, see the documentation for
325 Macro()</para></warning>
328 <argument name="delete">
329 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
330 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
332 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
333 always be deleted.</para>
335 <para>This option is a modifier for the call screening/privacy mode. (See the
336 <literal>p</literal> and <literal>P</literal> options.) It specifies
337 that no introductions are to be saved in the <directory>priv-callerintros</directory>
341 <para>This option is a modifier for the call screening/privacy mode. It specifies
342 that if Caller*ID is present, do not screen the call.</para>
345 <argument name="x" required="false" />
346 <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
347 <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
348 This was the behavior of Asterisk 1.0 and earlier.
349 If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
350 Note that o(${CALLERID(all)}) is similar to option o without the parameter.</para>
353 <argument name="mode">
354 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
355 the originator hanging up will cause the phone to ring back immediately.</para>
356 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
357 flashes the trunk, it will ring their phone back.</para>
359 <para>Enables <emphasis>operator services</emphasis> mode. This option only
360 works when bridging a DAHDI channel to another DAHDI channel
361 only. if specified on non-DAHDI interfaces, it will be ignored.
362 When the destination answers (presumably an operator services
363 station), the originator no longer has control of their line.
364 They may hang up, but the switch will not release their line
365 until the destination party (the operator) hangs up.</para>
368 <para>This option enables screening mode. This is basically Privacy mode
369 without memory.</para>
372 <argument name="x" />
373 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
374 it is provided. The current extension is used if a database family/key is not specified.</para>
377 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
378 party until the called channel has answered.</para>
379 <argument name="tone" required="false">
380 <para>Indicate progress to calling party. Send audio 'tone' from the indications.conf tonezone currently in use.</para>
384 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing.
385 Allow interruption of the ringback if early media is received on the channel.</para>
388 <argument name="x" required="true" />
389 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
390 answered the call.</para>
393 <argument name="x" required="true" />
394 <para>Force the outgoing callerid tag parameter to be set to the string <replaceable>x</replaceable>.</para>
395 <para>Works with the f option.</para>
398 <para>Allow the called party to transfer the calling party by sending the
399 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
400 transfers initiated by other methods.</para>
403 <para>Allow the calling party to transfer the called party by sending the
404 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
405 transfers initiated by other methods.</para>
407 <option name="U" argsep="^">
408 <argument name="x" required="true">
409 <para>Name of the subroutine to execute via Gosub</para>
411 <argument name="arg" multiple="true" required="false">
412 <para>Arguments for the Gosub routine</para>
414 <para>Execute via Gosub the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
415 to the calling channel. Arguments can be specified to the Gosub
416 using <literal>^</literal> as a delimiter. The Gosub routine can set the variable
417 <variable>GOSUB_RESULT</variable> to specify the following actions after the Gosub returns.</para>
419 <variable name="GOSUB_RESULT">
421 Hangup both legs of the call.
423 <value name="CONGESTION">
424 Behave as if line congestion was encountered.
427 Behave as if a busy signal was encountered.
429 <value name="CONTINUE">
430 Hangup the called party and allow the calling party
431 to continue dialplan execution at the next priority.
433 <value name="GOTO:[[<context>^]<exten>^]<priority>">
434 Transfer the call to the specified destination.
439 <para>You cannot use any additional action post answer options in conjunction
440 with this option. Also, pbx services are run on the peer (called) channel,
441 so you will not be able to set timeouts via the TIMEOUT() function in this routine.</para>
445 <argument name = "x" required="true">
446 <para>Force the outgoing callerid presentation indicator parameter to be set
447 to one of the values passed in <replaceable>x</replaceable>:
448 <literal>allowed_not_screened</literal>
449 <literal>allowed_passed_screen</literal>
450 <literal>allowed_failed_screen</literal>
451 <literal>allowed</literal>
452 <literal>prohib_not_screened</literal>
453 <literal>prohib_passed_screen</literal>
454 <literal>prohib_failed_screen</literal>
455 <literal>prohib</literal>
456 <literal>unavailable</literal></para>
458 <para>Works with the f option.</para>
461 <para>Allow the called party to enable recording of the call by sending
462 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
465 <para>Allow the calling party to enable recording of the call by sending
466 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
469 <para>Allow the called party to enable recording of the call by sending
470 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
473 <para>Allow the calling party to enable recording of the call by sending
474 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
477 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
481 <parameter name="URL">
482 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
486 <para>This application will place calls to one or more specified channels. As soon
487 as one of the requested channels answers, the originating channel will be
488 answered, if it has not already been answered. These two channels will then
489 be active in a bridged call. All other channels that were requested will then
492 <para>Unless there is a timeout specified, the Dial application will wait
493 indefinitely until one of the called channels answers, the user hangs up, or
494 if all of the called channels are busy or unavailable. Dialplan executing will
495 continue if no requested channels can be called, or if the timeout expires.
496 This application will report normal termination if the originating channel
497 hangs up, or if the call is bridged and either of the parties in the bridge
498 ends the call.</para>
499 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
500 application will be put into that group (as in Set(GROUP()=...).
501 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
502 application will be put into that group (as in Set(GROUP()=...). Unlike <variable>OUTBOUND_GROUP</variable>,
503 however, the variable will be unset after use.</para>
505 <para>This application sets the following channel variables:</para>
507 <variable name="DIALEDTIME">
508 <para>This is the time from dialing a channel until when it is disconnected.</para>
510 <variable name="ANSWEREDTIME">
511 <para>This is the amount of time for actual call.</para>
513 <variable name="DIALSTATUS">
514 <para>This is the status of the call</para>
515 <value name="CHANUNAVAIL" />
516 <value name="CONGESTION" />
517 <value name="NOANSWER" />
518 <value name="BUSY" />
519 <value name="ANSWER" />
520 <value name="CANCEL" />
521 <value name="DONTCALL">
522 For the Privacy and Screening Modes.
523 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
525 <value name="TORTURE">
526 For the Privacy and Screening Modes.
527 Will be set if the called party chooses to send the calling party to the 'torture' script.
529 <value name="INVALIDARGS" />
534 <application name="RetryDial" language="en_US">
536 Place a call, retrying on failure allowing an optional exit extension.
539 <parameter name="announce" required="true">
540 <para>Filename of sound that will be played when no channel can be reached</para>
542 <parameter name="sleep" required="true">
543 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
545 <parameter name="retries" required="true">
546 <para>Number of retries</para>
547 <para>When this is reached flow will continue at the next priority in the dialplan</para>
549 <parameter name="dialargs" required="true">
550 <para>Same format as arguments provided to the Dial application</para>
554 <para>This application will attempt to place a call using the normal Dial application.
555 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
556 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
557 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
558 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
559 While waiting to retry a call, a 1 digit extension may be dialed. If that
560 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
561 one, The call will jump to that extension immediately.
562 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
563 to the Dial application.</para>
568 static const char app[] = "Dial";
569 static const char rapp[] = "RetryDial";
572 OPT_ANNOUNCE = (1 << 0),
573 OPT_RESETCDR = (1 << 1),
574 OPT_DTMF_EXIT = (1 << 2),
575 OPT_SENDDTMF = (1 << 3),
576 OPT_FORCECLID = (1 << 4),
577 OPT_GO_ON = (1 << 5),
578 OPT_CALLEE_HANGUP = (1 << 6),
579 OPT_CALLER_HANGUP = (1 << 7),
580 OPT_ORIGINAL_CLID = (1 << 8),
581 OPT_DURATION_LIMIT = (1 << 9),
582 OPT_MUSICBACK = (1 << 10),
583 OPT_CALLEE_MACRO = (1 << 11),
584 OPT_SCREEN_NOINTRO = (1 << 12),
585 OPT_SCREEN_NOCALLERID = (1 << 13),
586 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
587 OPT_SCREENING = (1 << 15),
588 OPT_PRIVACY = (1 << 16),
589 OPT_RINGBACK = (1 << 17),
590 OPT_DURATION_STOP = (1 << 18),
591 OPT_CALLEE_TRANSFER = (1 << 19),
592 OPT_CALLER_TRANSFER = (1 << 20),
593 OPT_CALLEE_MONITOR = (1 << 21),
594 OPT_CALLER_MONITOR = (1 << 22),
595 OPT_GOTO = (1 << 23),
596 OPT_OPERMODE = (1 << 24),
597 OPT_CALLEE_PARK = (1 << 25),
598 OPT_CALLER_PARK = (1 << 26),
599 OPT_IGNORE_FORWARDING = (1 << 27),
600 OPT_CALLEE_GOSUB = (1 << 28),
601 OPT_CALLEE_MIXMONITOR = (1 << 29),
602 OPT_CALLER_MIXMONITOR = (1 << 30),
605 /* flags are now 64 bits, so keep it up! */
606 #define DIAL_STILLGOING (1LLU << 31)
607 #define DIAL_NOFORWARDHTML (1LLU << 32)
608 #define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
609 #define OPT_CANCEL_ELSEWHERE (1LLU << 34)
610 #define OPT_PEER_H (1LLU << 35)
611 #define OPT_CALLEE_GO_ON (1LLU << 36)
612 #define OPT_CANCEL_TIMEOUT (1LLU << 37)
613 #define OPT_FORCE_CID_TAG (1LLU << 38)
614 #define OPT_FORCE_CID_PRES (1LLU << 39)
615 #define OPT_CALLER_ANSWER (1LLU << 40)
616 #define OPT_PREDIAL_CALLEE (1LLU << 41)
617 #define OPT_PREDIAL_CALLER (1LLU << 42)
618 #define OPT_RING_WITH_EARLY_MEDIA (1LLU << 43)
621 OPT_ARG_ANNOUNCE = 0,
624 OPT_ARG_DURATION_LIMIT,
626 OPT_ARG_CALLEE_MACRO,
628 OPT_ARG_CALLEE_GOSUB,
629 OPT_ARG_CALLEE_GO_ON,
631 OPT_ARG_DURATION_STOP,
633 OPT_ARG_SCREEN_NOINTRO,
634 OPT_ARG_ORIGINAL_CLID,
636 OPT_ARG_FORCE_CID_TAG,
637 OPT_ARG_FORCE_CID_PRES,
638 OPT_ARG_PREDIAL_CALLEE,
639 OPT_ARG_PREDIAL_CALLER,
640 /* note: this entry _MUST_ be the last one in the enum */
644 AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
645 AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
646 AST_APP_OPTION('a', OPT_CALLER_ANSWER),
647 AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
648 AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
649 AST_APP_OPTION('C', OPT_RESETCDR),
650 AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
651 AST_APP_OPTION('d', OPT_DTMF_EXIT),
652 AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
653 AST_APP_OPTION('e', OPT_PEER_H),
654 AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
655 AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
656 AST_APP_OPTION('g', OPT_GO_ON),
657 AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
658 AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
659 AST_APP_OPTION('H', OPT_CALLER_HANGUP),
660 AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
661 AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
662 AST_APP_OPTION('k', OPT_CALLEE_PARK),
663 AST_APP_OPTION('K', OPT_CALLER_PARK),
664 AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
665 AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
666 AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
667 AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
668 AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
669 AST_APP_OPTION_ARG('o', OPT_ORIGINAL_CLID, OPT_ARG_ORIGINAL_CLID),
670 AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
671 AST_APP_OPTION('p', OPT_SCREENING),
672 AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
673 AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
674 AST_APP_OPTION('R', OPT_RING_WITH_EARLY_MEDIA),
675 AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
676 AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG),
677 AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
678 AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
679 AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES),
680 AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
681 AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
682 AST_APP_OPTION('W', OPT_CALLER_MONITOR),
683 AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
684 AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
685 AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
688 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
689 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
690 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
691 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
692 !ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \
693 ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer)))
696 * The list of active channels
699 AST_LIST_ENTRY(chanlist) node;
700 struct ast_channel *chan;
701 /*! Channel interface dialing string (is tech/number). (Stored in stuff[]) */
702 const char *interface;
703 /*! Channel technology name. (Stored in stuff[]) */
705 /*! Channel device addressing. (Stored in stuff[]) */
707 /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
708 char *orig_chan_name;
710 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
711 struct ast_party_connected_line connected;
712 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
713 unsigned int pending_connected_update:1;
714 struct ast_aoc_decoded *aoc_s_rate_list;
715 /*! The interface, tech, and number strings are stuffed here. */
719 AST_LIST_HEAD_NOLOCK(dial_head, chanlist);
721 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode);
723 static void chanlist_free(struct chanlist *outgoing)
725 ast_party_connected_line_free(&outgoing->connected);
726 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
727 ast_free(outgoing->orig_chan_name);
731 static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int answered_elsewhere)
733 /* Hang up a tree of stuff */
734 struct chanlist *outgoing;
736 while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
737 /* Hangup any existing lines we have open */
738 if (outgoing->chan && (outgoing->chan != exception)) {
739 if (answered_elsewhere) {
740 /* This is for the channel drivers */
741 ast_channel_hangupcause_set(outgoing->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
743 ast_hangup(outgoing->chan);
745 chanlist_free(outgoing);
749 #define AST_MAX_WATCHERS 256
752 * argument to handle_cause() and other functions.
755 struct ast_channel *chan;
761 static void handle_cause(int cause, struct cause_args *num)
767 case AST_CAUSE_CONGESTION:
770 case AST_CAUSE_NO_ROUTE_DESTINATION:
771 case AST_CAUSE_UNREGISTERED:
774 case AST_CAUSE_NO_ANSWER:
775 case AST_CAUSE_NORMAL_CLEARING:
783 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
785 char rexten[2] = { exten, '\0' };
788 if (!ast_goto_if_exists(chan, context, rexten, pri))
791 if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
793 else if (!ast_strlen_zero(ast_channel_macrocontext(chan))) {
794 if (!ast_goto_if_exists(chan, ast_channel_macrocontext(chan), rexten, pri))
801 /* do not call with chan lock held */
802 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
807 ast_channel_lock(chan);
808 context = ast_strdupa(S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)));
809 exten = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
810 ast_channel_unlock(chan);
812 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
816 * helper function for wait_for_answer()
818 * \param o Outgoing call channel list.
819 * \param num Incoming call channel cause accumulation
820 * \param peerflags Dial option flags
821 * \param single TRUE if there is only one outgoing call.
822 * \param caller_entertained TRUE if the caller is being entertained by MOH or ringback.
823 * \param to Remaining call timeout time.
824 * \param forced_clid OPT_FORCECLID caller id to send
825 * \param stored_clid Caller id representing the called party if needed
827 * XXX this code is highly suspicious, as it essentially overwrites
828 * the outgoing channel without properly deleting it.
830 * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
832 static void do_forward(struct chanlist *o, struct cause_args *num,
833 struct ast_flags64 *peerflags, int single, int caller_entertained, int *to,
834 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
837 struct ast_channel *original = o->chan;
838 struct ast_channel *c = o->chan; /* the winner */
839 struct ast_channel *in = num->chan; /* the input channel */
843 struct ast_party_caller caller;
845 ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
846 if ((stuff = strchr(tmpchan, '/'))) {
850 const char *forward_context;
852 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
853 if (ast_strlen_zero(forward_context)) {
854 forward_context = NULL;
856 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
857 ast_channel_unlock(c);
861 if (!strcasecmp(tech, "Local")) {
863 * Drop the connected line update block for local channels since
864 * this is going to run dialplan and the user can change his
865 * mind about what connected line information he wants to send.
867 ast_clear_flag64(o, OPT_IGNORE_CONNECTEDLINE);
870 /* Before processing channel, go ahead and check for forwarding */
871 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
872 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
873 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
874 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
876 cause = AST_CAUSE_BUSY;
878 struct ast_format_cap *nativeformats;
880 ast_channel_lock(in);
881 nativeformats = ao2_bump(ast_channel_nativeformats(in));
882 ast_channel_unlock(in);
884 /* Setup parameters */
885 c = o->chan = ast_request(tech, nativeformats, NULL, in, stuff, &cause);
887 ao2_cleanup(nativeformats);
890 if (single && !caller_entertained) {
891 ast_channel_make_compatible(in, o->chan);
893 ast_channel_lock_both(in, o->chan);
894 ast_channel_inherit_variables(in, o->chan);
895 ast_channel_datastore_inherit(in, o->chan);
896 ast_max_forwards_decrement(o->chan);
897 ast_channel_unlock(in);
898 ast_channel_unlock(o->chan);
899 /* When a call is forwarded, we don't want to track new interfaces
900 * dialed for CC purposes. Setting the done flag will ensure that
901 * any Dial operations that happen later won't record CC interfaces.
903 ast_ignore_cc(o->chan);
904 ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", ast_channel_name(o->chan));
907 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
911 ast_channel_publish_dial(in, original, stuff, "BUSY");
912 ast_clear_flag64(o, DIAL_STILLGOING);
913 handle_cause(cause, num);
914 ast_hangup(original);
916 ast_channel_lock_both(c, original);
917 ast_party_redirecting_copy(ast_channel_redirecting(c),
918 ast_channel_redirecting(original));
919 ast_channel_unlock(c);
920 ast_channel_unlock(original);
922 ast_channel_lock_both(c, in);
924 if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
925 ast_rtp_instance_early_bridge_make_compatible(c, in);
928 if (!ast_channel_redirecting(c)->from.number.valid
929 || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
931 * The call was not previously redirected so it is
932 * now redirected from this number.
934 ast_party_number_free(&ast_channel_redirecting(c)->from.number);
935 ast_party_number_init(&ast_channel_redirecting(c)->from.number);
936 ast_channel_redirecting(c)->from.number.valid = 1;
937 ast_channel_redirecting(c)->from.number.str =
938 ast_strdup(S_OR(ast_channel_macroexten(in), ast_channel_exten(in)));
941 ast_channel_dialed(c)->transit_network_select = ast_channel_dialed(in)->transit_network_select;
943 /* Determine CallerID to store in outgoing channel. */
944 ast_party_caller_set_init(&caller, ast_channel_caller(c));
945 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
946 caller.id = *stored_clid;
947 ast_channel_set_caller_event(c, &caller, NULL);
948 ast_set_flag64(o, DIAL_CALLERID_ABSENT);
949 } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
950 ast_channel_caller(c)->id.number.str, NULL))) {
952 * The new channel has no preset CallerID number by the channel
953 * driver. Use the dialplan extension and hint name.
955 caller.id = *stored_clid;
956 ast_channel_set_caller_event(c, &caller, NULL);
957 ast_set_flag64(o, DIAL_CALLERID_ABSENT);
959 ast_clear_flag64(o, DIAL_CALLERID_ABSENT);
962 /* Determine CallerID for outgoing channel to send. */
963 if (ast_test_flag64(o, OPT_FORCECLID)) {
964 struct ast_party_connected_line connected;
966 ast_party_connected_line_init(&connected);
967 connected.id = *forced_clid;
968 ast_party_connected_line_copy(ast_channel_connected(c), &connected);
970 ast_connected_line_copy_from_caller(ast_channel_connected(c), ast_channel_caller(in));
973 ast_channel_req_accountcodes(c, in, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
975 ast_channel_appl_set(c, "AppDial");
976 ast_channel_data_set(c, "(Outgoing Line)");
977 ast_channel_publish_snapshot(c);
979 ast_channel_unlock(in);
980 if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
981 struct ast_party_redirecting redirecting;
984 * Redirecting updates to the caller make sense only on single
987 * We must unlock c before calling
988 * ast_channel_redirecting_macro, because we put c into
989 * autoservice there. That is pretty much a guaranteed
990 * deadlock. This is why the handling of c's lock may seem a
993 ast_party_redirecting_init(&redirecting);
994 ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(c));
995 ast_channel_unlock(c);
996 if (ast_channel_redirecting_sub(c, in, &redirecting, 0) &&
997 ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
998 ast_channel_update_redirecting(in, &redirecting, NULL);
1000 ast_party_redirecting_free(&redirecting);
1002 ast_channel_unlock(c);
1005 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1009 if (ast_call(c, stuff, 0)) {
1010 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1012 ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1013 ast_clear_flag64(o, DIAL_STILLGOING);
1014 ast_hangup(original);
1019 ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1020 ast_channel_call_forward(original));
1022 ast_channel_publish_dial(in, c, stuff, NULL);
1024 /* Hangup the original channel now, in case we needed it */
1025 ast_hangup(original);
1027 if (single && !caller_entertained) {
1028 ast_indicate(in, -1);
1033 /* argument used for some functions. */
1034 struct privacy_args {
1038 char privintro[1024];
1042 static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
1044 struct chanlist *outgoing;
1045 AST_LIST_TRAVERSE(out_chans, outgoing, node) {
1046 if (!outgoing->chan || outgoing->chan == exception) {
1049 ast_channel_publish_dial(in, outgoing->chan, NULL, status);
1055 * \brief Update connected line on chan from peer.
1058 * \param chan Channel to get connected line updated.
1059 * \param peer Channel providing connected line information.
1060 * \param is_caller Non-zero if chan is the calling channel.
1064 static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
1066 struct ast_party_connected_line connected_caller;
1068 ast_party_connected_line_init(&connected_caller);
1070 ast_channel_lock(peer);
1071 ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(peer));
1072 ast_channel_unlock(peer);
1073 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1074 if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)
1075 && ast_channel_connected_line_macro(peer, chan, &connected_caller, is_caller, 0)) {
1076 ast_channel_update_connected_line(chan, &connected_caller, NULL);
1078 ast_party_connected_line_free(&connected_caller);
1081 static struct ast_channel *wait_for_answer(struct ast_channel *in,
1082 struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags,
1084 struct privacy_args *pa,
1085 const struct cause_args *num_in, int *result, char *dtmf_progress,
1086 const int ignore_cc,
1087 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
1089 struct cause_args num = *num_in;
1090 int prestart = num.busy + num.congestion + num.nochan;
1092 struct ast_channel *peer = NULL;
1094 struct chanlist *epollo;
1096 struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
1097 /* single is set if only one destination is enabled */
1098 int single = outgoing && !AST_LIST_NEXT(outgoing, node);
1099 int caller_entertained = outgoing
1100 && ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
1101 struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
1102 int cc_recall_core_id;
1104 int cc_frame_received = 0;
1105 int num_ringing = 0;
1106 struct timeval start = ast_tvnow();
1109 /* Turn off hold music, etc */
1110 if (!caller_entertained) {
1111 ast_deactivate_generator(in);
1112 /* If we are calling a single channel, and not providing ringback or music, */
1113 /* then, make them compatible for in-band tone purpose */
1114 if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
1115 /* If these channels can not be made compatible,
1116 * there is no point in continuing. The bridge
1117 * will just fail if it gets that far.
1120 strcpy(pa->status, "CONGESTION");
1121 ast_channel_publish_dial(in, outgoing->chan, NULL, pa->status);
1126 if (!ast_test_flag64(outgoing, OPT_IGNORE_CONNECTEDLINE)
1127 && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
1128 update_connected_line_from_peer(in, outgoing->chan, 1);
1132 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1135 AST_LIST_TRAVERSE(out_chans, epollo, node) {
1136 ast_poll_channel_add(in, epollo->chan);
1140 while ((*to = ast_remaining_ms(start, orig)) && !peer) {
1142 int pos = 0; /* how many channels do we handle */
1143 int numlines = prestart;
1144 struct ast_channel *winner;
1145 struct ast_channel *watchers[AST_MAX_WATCHERS];
1147 watchers[pos++] = in;
1148 AST_LIST_TRAVERSE(out_chans, o, node) {
1149 /* Keep track of important channels */
1150 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1151 watchers[pos++] = o->chan;
1154 if (pos == 1) { /* only the input channel is available */
1155 if (numlines == (num.busy + num.congestion + num.nochan)) {
1156 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1158 strcpy(pa->status, "BUSY");
1159 else if (num.congestion)
1160 strcpy(pa->status, "CONGESTION");
1161 else if (num.nochan)
1162 strcpy(pa->status, "CHANUNAVAIL");
1164 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1168 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1172 winner = ast_waitfor_n(watchers, pos, to);
1173 AST_LIST_TRAVERSE(out_chans, o, node) {
1174 struct ast_frame *f;
1175 struct ast_channel *c = o->chan;
1179 if (ast_test_flag64(o, DIAL_STILLGOING) && ast_channel_state(c) == AST_STATE_UP) {
1181 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1182 if (o->orig_chan_name
1183 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1185 * The channel name changed so we must generate COLP update.
1186 * Likely because a call pickup channel masqueraded in.
1188 update_connected_line_from_peer(in, c, 1);
1189 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1190 if (o->pending_connected_update) {
1191 if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
1192 ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1193 ast_channel_update_connected_line(in, &o->connected, NULL);
1195 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1196 update_connected_line_from_peer(in, c, 1);
1199 if (o->aoc_s_rate_list) {
1200 size_t encoded_size;
1201 struct ast_aoc_encoded *encoded;
1202 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1203 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1204 ast_aoc_destroy_encoded(encoded);
1208 ast_copy_flags64(peerflags, o,
1209 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1210 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1211 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1212 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1213 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1214 DIAL_NOFORWARDHTML);
1215 ast_channel_dialcontext_set(c, "");
1216 ast_channel_exten_set(c, "");
1222 /* here, o->chan == c == winner */
1223 if (!ast_strlen_zero(ast_channel_call_forward(c))) {
1224 pa->sentringing = 0;
1225 if (!ignore_cc && (f = ast_read(c))) {
1226 if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
1227 /* This channel is forwarding the call, and is capable of CC, so
1228 * be sure to add the new device interface to the list
1230 ast_handle_cc_control_frame(in, c, f->data.ptr);
1235 if (o->pending_connected_update) {
1237 * Re-seed the chanlist's connected line information with
1238 * previously acquired connected line info from the incoming
1239 * channel. The previously acquired connected line info could
1240 * have been set through the CONNECTED_LINE dialplan function.
1242 o->pending_connected_update = 0;
1243 ast_channel_lock(in);
1244 ast_party_connected_line_copy(&o->connected, ast_channel_connected(in));
1245 ast_channel_unlock(in);
1248 do_forward(o, &num, peerflags, single, caller_entertained, &orig,
1249 forced_clid, stored_clid);
1252 ast_free(o->orig_chan_name);
1253 o->orig_chan_name = ast_strdup(ast_channel_name(o->chan));
1255 && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)
1256 && !ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1257 update_connected_line_from_peer(in, o->chan, 1);
1262 f = ast_read(winner);
1264 ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
1266 ast_poll_channel_del(in, c);
1268 ast_channel_publish_dial(in, c, NULL, ast_hangup_cause_to_dial_status(ast_channel_hangupcause(c)));
1271 ast_clear_flag64(o, DIAL_STILLGOING);
1272 handle_cause(ast_channel_hangupcause(in), &num);
1275 switch (f->frametype) {
1276 case AST_FRAME_CONTROL:
1277 switch (f->subclass.integer) {
1278 case AST_CONTROL_ANSWER:
1279 /* This is our guy if someone answered. */
1281 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1282 if (o->orig_chan_name
1283 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1285 * The channel name changed so we must generate COLP update.
1286 * Likely because a call pickup channel masqueraded in.
1288 update_connected_line_from_peer(in, c, 1);
1289 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1290 if (o->pending_connected_update) {
1291 if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
1292 ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1293 ast_channel_update_connected_line(in, &o->connected, NULL);
1295 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1296 update_connected_line_from_peer(in, c, 1);
1299 if (o->aoc_s_rate_list) {
1300 size_t encoded_size;
1301 struct ast_aoc_encoded *encoded;
1302 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1303 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1304 ast_aoc_destroy_encoded(encoded);
1308 /* Inform everyone else that they've been canceled.
1309 * The dial end event for the peer will be sent out after
1310 * other Dial options have been handled.
1312 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1313 ast_copy_flags64(peerflags, o,
1314 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1315 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1316 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1317 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1318 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1319 DIAL_NOFORWARDHTML);
1320 ast_channel_dialcontext_set(c, "");
1321 ast_channel_exten_set(c, "");
1322 if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
1323 /* Setup early bridge if appropriate */
1324 ast_channel_early_bridge(in, peer);
1327 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1328 ast_channel_hangupcause_set(in, AST_CAUSE_NORMAL_CLEARING);
1329 ast_channel_hangupcause_set(c, AST_CAUSE_NORMAL_CLEARING);
1331 case AST_CONTROL_BUSY:
1332 ast_verb(3, "%s is busy\n", ast_channel_name(c));
1333 ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
1334 ast_channel_publish_dial(in, c, NULL, "BUSY");
1337 ast_clear_flag64(o, DIAL_STILLGOING);
1338 handle_cause(AST_CAUSE_BUSY, &num);
1340 case AST_CONTROL_CONGESTION:
1341 ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1342 ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
1343 ast_channel_publish_dial(in, c, NULL, "CONGESTION");
1346 ast_clear_flag64(o, DIAL_STILLGOING);
1347 handle_cause(AST_CAUSE_CONGESTION, &num);
1349 case AST_CONTROL_RINGING:
1350 /* This is a tricky area to get right when using a native
1351 * CC agent. The reason is that we do the best we can to send only a
1352 * single ringing notification to the caller.
1354 * Call completion complicates the logic used here. CCNR is typically
1355 * offered during a ringing message. Let's say that party A calls
1356 * parties B, C, and D. B and C do not support CC requests, but D
1357 * does. If we were to receive a ringing notification from B before
1358 * the others, then we would end up sending a ringing message to
1359 * A with no CCNR offer present.
1361 * The approach that we have taken is that if we receive a ringing
1362 * response from a party and no CCNR offer is present, we need to
1363 * wait. Specifically, we need to wait until either a) a called party
1364 * offers CCNR in its ringing response or b) all called parties have
1365 * responded in some way to our call and none offers CCNR.
1367 * The drawback to this is that if one of the parties has a delayed
1368 * response or, god forbid, one just plain doesn't respond to our
1369 * outgoing call, then this will result in a significant delay between
1370 * when the caller places the call and hears ringback.
1372 * Note also that if CC is disabled for this call, then it is perfectly
1373 * fine for ringing frames to get sent through.
1376 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1377 ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1378 /* Setup early media if appropriate */
1379 if (single && !caller_entertained
1380 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1381 ast_channel_early_bridge(in, c);
1383 if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
1384 ast_indicate(in, AST_CONTROL_RINGING);
1389 case AST_CONTROL_PROGRESS:
1390 ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1391 /* Setup early media if appropriate */
1392 if (single && !caller_entertained
1393 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1394 ast_channel_early_bridge(in, c);
1396 if (!ast_test_flag64(outgoing, OPT_RINGBACK)) {
1397 if (single || (!single && !pa->sentringing)) {
1398 ast_indicate(in, AST_CONTROL_PROGRESS);
1401 if (!ast_strlen_zero(dtmf_progress)) {
1403 "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n",
1405 ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1408 case AST_CONTROL_VIDUPDATE:
1409 case AST_CONTROL_SRCUPDATE:
1410 case AST_CONTROL_SRCCHANGE:
1411 if (!single || caller_entertained) {
1414 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1415 ast_channel_name(c), f->subclass.integer, ast_channel_name(in));
1416 ast_indicate(in, f->subclass.integer);
1418 case AST_CONTROL_CONNECTED_LINE:
1419 if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1420 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1424 struct ast_party_connected_line connected;
1426 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
1427 ast_channel_name(c), ast_channel_name(in));
1428 ast_party_connected_line_set_init(&connected, &o->connected);
1429 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
1430 ast_party_connected_line_set(&o->connected, &connected, NULL);
1431 ast_party_connected_line_free(&connected);
1432 o->pending_connected_update = 1;
1435 if (ast_channel_connected_line_sub(c, in, f, 1) &&
1436 ast_channel_connected_line_macro(c, in, f, 1, 1)) {
1437 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
1440 case AST_CONTROL_AOC:
1442 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1443 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1444 ast_aoc_destroy_decoded(o->aoc_s_rate_list);
1445 o->aoc_s_rate_list = decoded;
1447 ast_aoc_destroy_decoded(decoded);
1451 case AST_CONTROL_REDIRECTING:
1454 * Redirecting updates to the caller make sense only on single
1459 if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1460 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1463 ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
1464 ast_channel_name(c), ast_channel_name(in));
1465 if (ast_channel_redirecting_sub(c, in, f, 1) &&
1466 ast_channel_redirecting_macro(c, in, f, 1, 1)) {
1467 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
1469 pa->sentringing = 0;
1471 case AST_CONTROL_PROCEEDING:
1472 ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1473 if (single && !caller_entertained
1474 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1475 ast_channel_early_bridge(in, c);
1477 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1478 ast_indicate(in, AST_CONTROL_PROCEEDING);
1480 case AST_CONTROL_HOLD:
1481 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1482 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1483 ast_indicate_data(in, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
1485 case AST_CONTROL_UNHOLD:
1486 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1487 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1488 ast_indicate(in, AST_CONTROL_UNHOLD);
1490 case AST_CONTROL_OFFHOOK:
1491 case AST_CONTROL_FLASH:
1492 /* Ignore going off hook and flash */
1494 case AST_CONTROL_CC:
1496 ast_handle_cc_control_frame(in, c, f->data.ptr);
1497 cc_frame_received = 1;
1500 case AST_CONTROL_PVT_CAUSE_CODE:
1501 ast_indicate_data(in, AST_CONTROL_PVT_CAUSE_CODE, f->data.ptr, f->datalen);
1504 if (single && !caller_entertained) {
1505 ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1506 ast_indicate(in, -1);
1507 pa->sentringing = 0;
1511 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1515 case AST_FRAME_VOICE:
1516 case AST_FRAME_IMAGE:
1517 if (caller_entertained) {
1521 case AST_FRAME_TEXT:
1522 if (single && ast_write(in, f)) {
1523 ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
1527 case AST_FRAME_HTML:
1528 if (single && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)
1529 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1530 ast_log(LOG_WARNING, "Unable to send URL\n");
1539 struct ast_frame *f = ast_read(in);
1541 if (f && (f->frametype != AST_FRAME_VOICE))
1542 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1543 else if (!f || (f->frametype != AST_FRAME_VOICE))
1544 printf("Hangup received on %s\n", in->name);
1546 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1549 strcpy(pa->status, "CANCEL");
1550 publish_dial_end_event(in, out_chans, NULL, pa->status);
1552 if (f->data.uint32) {
1553 ast_channel_hangupcause_set(in, f->data.uint32);
1558 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1563 /* now f is guaranteed non-NULL */
1564 if (f->frametype == AST_FRAME_DTMF) {
1565 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1566 const char *context;
1567 ast_channel_lock(in);
1568 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1569 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1570 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1572 *result = f->subclass.integer;
1573 strcpy(pa->status, "CANCEL");
1574 publish_dial_end_event(in, out_chans, NULL, pa->status);
1576 ast_channel_unlock(in);
1578 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1582 ast_channel_unlock(in);
1585 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1586 detect_disconnect(in, f->subclass.integer, &featurecode)) {
1587 ast_verb(3, "User requested call disconnect.\n");
1589 strcpy(pa->status, "CANCEL");
1590 publish_dial_end_event(in, out_chans, NULL, pa->status);
1593 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1599 /* Send the frame from the in channel to all outgoing channels. */
1600 AST_LIST_TRAVERSE(out_chans, o, node) {
1601 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1602 /* This outgoing channel has died so don't send the frame to it. */
1605 switch (f->frametype) {
1606 case AST_FRAME_HTML:
1607 /* Forward HTML stuff */
1608 if (!ast_test_flag64(o, DIAL_NOFORWARDHTML)
1609 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1610 ast_log(LOG_WARNING, "Unable to send URL\n");
1613 case AST_FRAME_VOICE:
1614 case AST_FRAME_IMAGE:
1615 if (!single || caller_entertained) {
1617 * We are calling multiple parties or caller is being
1618 * entertained and has thus not been made compatible.
1619 * No need to check any other called parties.
1624 case AST_FRAME_TEXT:
1625 case AST_FRAME_DTMF_BEGIN:
1626 case AST_FRAME_DTMF_END:
1627 if (ast_write(o->chan, f)) {
1628 ast_log(LOG_WARNING, "Unable to forward frametype: %u\n",
1632 case AST_FRAME_CONTROL:
1633 switch (f->subclass.integer) {
1634 case AST_CONTROL_HOLD:
1635 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1636 ast_indicate_data(o->chan, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
1638 case AST_CONTROL_UNHOLD:
1639 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1640 ast_indicate(o->chan, AST_CONTROL_UNHOLD);
1642 case AST_CONTROL_VIDUPDATE:
1643 case AST_CONTROL_SRCUPDATE:
1644 case AST_CONTROL_SRCCHANGE:
1645 if (!single || caller_entertained) {
1647 * We are calling multiple parties or caller is being
1648 * entertained and has thus not been made compatible.
1649 * No need to check any other called parties.
1653 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1654 ast_channel_name(in), f->subclass.integer, ast_channel_name(o->chan));
1655 ast_indicate(o->chan, f->subclass.integer);
1657 case AST_CONTROL_CONNECTED_LINE:
1658 if (ast_channel_connected_line_sub(in, o->chan, f, 1) &&
1659 ast_channel_connected_line_macro(in, o->chan, f, 0, 1)) {
1660 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1663 case AST_CONTROL_REDIRECTING:
1664 if (ast_channel_redirecting_sub(in, o->chan, f, 1) &&
1665 ast_channel_redirecting_macro(in, o->chan, f, 0, 1)) {
1666 ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
1670 /* We are not going to do anything with this frame. */
1675 /* We are not going to do anything with this frame. */
1684 if (!*to || ast_check_hangup(in)) {
1685 ast_verb(3, "Nobody picked up in %d ms\n", orig);
1686 publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
1690 AST_LIST_TRAVERSE(out_chans, epollo, node) {
1692 ast_poll_channel_del(in, epollo->chan);
1697 ast_cc_completed(in, "Recall completed!");
1702 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
1704 char disconnect_code[AST_FEATURE_MAX_LEN];
1707 ast_str_append(featurecode, 1, "%c", code);
1709 res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
1711 ast_str_reset(*featurecode);
1715 if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
1716 /* Could be a partial match, anyway */
1717 if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
1718 ast_str_reset(*featurecode);
1723 if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
1724 ast_str_reset(*featurecode);
1731 /* returns true if there is a valid privacy reply */
1732 static int valid_priv_reply(struct ast_flags64 *opts, int res)
1736 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1738 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1743 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1744 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1750 /* Get the user's intro, store it in priv-callerintros/$CID,
1751 unless it is already there-- this should be done before the
1752 call is actually dialed */
1754 /* all ring indications and moh for the caller has been halted as soon as the
1755 target extension was picked up. We are going to have to kill some
1756 time and make the caller believe the peer hasn't picked up yet */
1758 if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
1759 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
1760 ast_indicate(chan, -1);
1761 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
1762 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1763 ast_channel_musicclass_set(chan, original_moh);
1764 } else if (ast_test_flag64(opts, OPT_RINGBACK) || ast_test_flag64(opts, OPT_RING_WITH_EARLY_MEDIA)) {
1765 ast_indicate(chan, AST_CONTROL_RINGING);
1769 /* Start autoservice on the other chan ?? */
1770 res2 = ast_autoservice_start(chan);
1771 /* Now Stream the File */
1772 for (loopcount = 0; loopcount < 3; loopcount++) {
1773 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1775 if (!res2) /* on timeout, play the message again */
1776 res2 = ast_play_and_wait(peer, "priv-callpending");
1777 if (!valid_priv_reply(opts, res2))
1779 /* priv-callpending script:
1780 "I have a caller waiting, who introduces themselves as:"
1783 res2 = ast_play_and_wait(peer, pa->privintro);
1784 if (!valid_priv_reply(opts, res2))
1786 /* now get input from the called party, as to their choice */
1788 /* XXX can we have both, or they are mutually exclusive ? */
1789 if (ast_test_flag64(opts, OPT_PRIVACY))
1790 res2 = ast_play_and_wait(peer, "priv-callee-options");
1791 if (ast_test_flag64(opts, OPT_SCREENING))
1792 res2 = ast_play_and_wait(peer, "screen-callee-options");
1795 /*! \page DialPrivacy Dial Privacy scripts
1796 * \par priv-callee-options script:
1797 * \li Dial 1 if you wish this caller to reach you directly in the future,
1798 * and immediately connect to their incoming call.
1799 * \li Dial 2 if you wish to send this caller to voicemail now and forevermore.
1800 * \li Dial 3 to send this caller to the torture menus, now and forevermore.
1801 * \li Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
1802 * \li Dial 5 to allow this caller to come straight thru to you in the future,
1803 * but right now, just this once, send them to voicemail.
1805 * \par screen-callee-options script:
1806 * \li Dial 1 if you wish to immediately connect to the incoming call
1807 * \li Dial 2 if you wish to send this caller to voicemail.
1808 * \li Dial 3 to send this caller to the torture menus.
1809 * \li Dial 4 to send this caller to a simple "go away" menu.
1811 if (valid_priv_reply(opts, res2))
1813 /* invalid option */
1814 res2 = ast_play_and_wait(peer, "vm-sorry");
1817 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
1819 } else if (ast_test_flag64(opts, OPT_RINGBACK) || ast_test_flag64(opts, OPT_RING_WITH_EARLY_MEDIA)) {
1820 ast_indicate(chan, -1);
1821 pa->sentringing = 0;
1823 ast_autoservice_stop(chan);
1824 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
1825 /* map keypresses to various things, the index is res2 - '1' */
1826 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
1827 static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
1829 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
1830 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
1831 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
1837 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1840 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1843 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1846 /* XXX should we set status to DENY ? */
1847 if (ast_test_flag64(opts, OPT_PRIVACY))
1849 /* if not privacy, then 5 is the same as "default" case */
1850 default: /* bad input or -1 if failure to start autoservice */
1851 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
1852 /* well, there seems basically two choices. Just patch the caller thru immediately,
1853 or,... put 'em thru to voicemail. */
1854 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
1855 ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
1856 /* XXX should we set status to DENY ? */
1857 /* XXX what about the privacy flags ? */
1861 if (res2 == '1') { /* the only case where we actually connect */
1862 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
1863 just clog things up, and it's not useful information, not being tied to a CID */
1864 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
1865 ast_filedelete(pa->privintro, NULL);
1866 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1867 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1869 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1871 return 0; /* the good exit path */
1873 /* hang up on the callee -- he didn't want to talk anyway! */
1874 ast_autoservice_chan_hangup_peer(chan, peer);
1879 /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
1880 static int setup_privacy_args(struct privacy_args *pa,
1881 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
1887 if (ast_channel_caller(chan)->id.number.valid
1888 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
1889 l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
1890 ast_shrink_phone_number(l);
1891 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
1892 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
1893 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
1895 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
1896 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1901 tnam = ast_strdupa(ast_channel_name(chan));
1902 /* clean the channel name so slashes don't try to end up in disk file name */
1903 for (tn2 = tnam; *tn2; tn2++) {
1904 if (*tn2 == '/') /* any other chars to be afraid of? */
1907 ast_verb(3, "Privacy-- callerid is empty\n");
1909 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
1911 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1914 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
1916 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
1917 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
1918 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
1919 pa->privdb_val = AST_PRIVACY_ALLOW;
1920 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
1921 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
1924 if (pa->privdb_val == AST_PRIVACY_DENY) {
1925 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
1926 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1928 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
1929 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1930 return 0; /* Is this right? */
1931 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
1932 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1933 return 0; /* is this right??? */
1934 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
1935 /* Get the user's intro, store it in priv-callerintros/$CID,
1936 unless it is already there-- this should be done before the
1937 call is actually dialed */
1939 /* make sure the priv-callerintros dir actually exists */
1940 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
1941 if ((res = ast_mkdir(pa->privintro, 0755))) {
1942 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
1946 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
1947 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
1948 /* the DELUX version of this code would allow this caller the
1949 option to hear and retape their previously recorded intro.
1952 int duration; /* for feedback from play_and_wait */
1953 /* the file doesn't exist yet. Let the caller submit his
1954 vocal intro for posterity */
1955 /* priv-recordintro script:
1957 "At the tone, please say your name:"
1960 int silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
1962 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 */
1963 /* don't think we'll need a lock removed, we took care of
1964 conflicts by naming the pa.privintro file */
1966 /* Delete the file regardless since they hung up during recording */
1967 ast_filedelete(pa->privintro, NULL);
1968 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1969 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1971 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1974 if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
1975 ast_waitstream(chan, "");
1978 return 1; /* success */
1981 static void end_bridge_callback(void *data)
1985 struct ast_channel *chan = data;
1989 ast_channel_lock(chan);
1990 ast_channel_stage_snapshot(chan);
1991 snprintf(buf, sizeof(buf), "%d", ast_channel_get_up_time(chan));
1992 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
1993 snprintf(buf, sizeof(buf), "%d", ast_channel_get_duration(chan));
1994 pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
1995 ast_channel_stage_snapshot_done(chan);
1996 ast_channel_unlock(chan);
1999 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
2000 bconfig->end_bridge_callback_data = originator;
2003 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
2005 struct ast_tone_zone_sound *ts = NULL;
2007 const char *str = data;
2009 if (ast_strlen_zero(str)) {
2010 ast_debug(1,"Nothing to play\n");
2014 ts = ast_get_indication_tone(ast_channel_zone(chan), str);
2016 if (ts && ts->data[0]) {
2017 res = ast_playtones_start(chan, 0, ts->data, 0);
2023 ts = ast_tone_zone_sound_unref(ts);
2027 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
2035 * \brief Setup the after bridge goto location on the peer.
2038 * \param chan Calling channel for bridge.
2039 * \param peer Peer channel for bridge.
2040 * \param opts Dialing option flags.
2041 * \param opt_args Dialing option argument strings.
2045 static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
2047 const char *context;
2048 const char *extension;
2051 if (ast_test_flag64(opts, OPT_PEER_H)) {
2052 ast_channel_lock(chan);
2053 context = ast_strdupa(ast_channel_context(chan));
2054 ast_channel_unlock(chan);
2055 ast_bridge_set_after_h(peer, context);
2056 } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
2057 ast_channel_lock(chan);
2058 context = ast_strdupa(ast_channel_context(chan));
2059 extension = ast_strdupa(ast_channel_exten(chan));
2060 priority = ast_channel_priority(chan);
2061 ast_channel_unlock(chan);
2062 ast_bridge_set_after_go_on(peer, context, extension, priority,
2063 opt_args[OPT_ARG_CALLEE_GO_ON]);
2067 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
2069 int res = -1; /* default: error */
2070 char *rest, *cur; /* scan the list of destinations */
2071 struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2072 struct chanlist *outgoing;
2073 struct chanlist *tmp;
2074 struct ast_channel *peer;
2075 int to; /* timeout */
2076 struct cause_args num = { chan, 0, 0, 0 };
2079 struct ast_bridge_config config = { { 0, } };
2080 struct timeval calldurationlimit = { 0, };
2081 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
2082 struct privacy_args pa = {
2085 .status = "INVALIDARGS",
2087 int sentringing = 0, moh = 0;
2088 const char *outbound_group = NULL;
2092 int delprivintro = 0;
2093 AST_DECLARE_APP_ARGS(args,
2095 AST_APP_ARG(timeout);
2096 AST_APP_ARG(options);
2099 struct ast_flags64 opts = { 0, };
2100 char *opt_args[OPT_ARG_ARRAY_SIZE];
2101 int fulldial = 0, num_dialed = 0;
2103 char device_name[AST_CHANNEL_NAME];
2104 char forced_clid_name[AST_MAX_EXTENSION];
2105 char stored_clid_name[AST_MAX_EXTENSION];
2106 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2108 * \brief Forced CallerID party information to send.
2109 * \note This will not have any malloced strings so do not free it.
2111 struct ast_party_id forced_clid;
2113 * \brief Stored CallerID information if needed.
2115 * \note If OPT_ORIGINAL_CLID set then this is the o option
2116 * CallerID. Otherwise it is the dialplan extension and hint
2119 * \note This will not have any malloced strings so do not free it.
2121 struct ast_party_id stored_clid;
2123 * \brief CallerID party information to store.
2124 * \note This will not have any malloced strings so do not free it.
2126 struct ast_party_caller caller;
2129 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2130 ast_channel_lock(chan);
2131 ast_channel_stage_snapshot(chan);
2132 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2133 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2134 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2135 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2136 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2137 ast_channel_stage_snapshot_done(chan);
2138 max_forwards = ast_max_forwards_get(chan);
2139 ast_channel_unlock(chan);
2141 if (max_forwards <= 0) {
2142 ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2143 ast_channel_name(chan));
2144 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2148 if (ast_strlen_zero(data)) {
2149 ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
2150 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2154 parse = ast_strdupa(data);
2156 AST_STANDARD_APP_ARGS(args, parse);
2158 if (!ast_strlen_zero(args.options) &&
2159 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2160 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2164 if (ast_strlen_zero(args.peers)) {
2165 ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
2166 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2170 if (ast_cc_call_init(chan, &ignore_cc)) {
2174 if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
2175 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2177 if (delprivintro < 0 || delprivintro > 1) {
2178 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2183 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2184 opt_args[OPT_ARG_RINGBACK] = NULL;
2187 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2188 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2189 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2192 if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
2193 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2194 if (!calldurationlimit.tv_sec) {
2195 ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
2196 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2199 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2202 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2203 dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
2204 dtmfcalled = strsep(&dtmf_progress, ":");
2205 dtmfcalling = strsep(&dtmf_progress, ":");
2208 if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
2209 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2213 /* Setup the forced CallerID information to send if used. */
2214 ast_party_id_init(&forced_clid);
2215 force_forwards_only = 0;
2216 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2217 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2218 ast_channel_lock(chan);
2219 forced_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
2220 ast_channel_unlock(chan);
2221 forced_clid_name[0] = '\0';
2222 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2223 sizeof(forced_clid_name), chan);
2224 force_forwards_only = 1;
2226 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2227 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2228 &forced_clid.number.str);
2230 if (!ast_strlen_zero(forced_clid.name.str)) {
2231 forced_clid.name.valid = 1;
2233 if (!ast_strlen_zero(forced_clid.number.str)) {
2234 forced_clid.number.valid = 1;
2237 if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG)
2238 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2239 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2241 forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
2242 if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES)
2243 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2246 pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
2248 forced_clid.number.presentation = pres;
2252 /* Setup the stored CallerID information if needed. */
2253 ast_party_id_init(&stored_clid);
2254 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2255 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2256 ast_channel_lock(chan);
2257 ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2258 if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2259 stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2261 if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2262 stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2264 if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2265 stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2267 if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2268 stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2270 ast_channel_unlock(chan);
2272 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2273 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2274 &stored_clid.number.str);
2275 if (!ast_strlen_zero(stored_clid.name.str)) {
2276 stored_clid.name.valid = 1;
2278 if (!ast_strlen_zero(stored_clid.number.str)) {
2279 stored_clid.number.valid = 1;
2284 * In case the new channel has no preset CallerID number by the
2285 * channel driver, setup the dialplan extension and hint name.
2287 stored_clid_name[0] = '\0';
2288 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2289 sizeof(stored_clid_name), chan);
2290 if (ast_strlen_zero(stored_clid.name.str)) {
2291 stored_clid.name.str = NULL;
2293 stored_clid.name.valid = 1;
2295 ast_channel_lock(chan);
2296 stored_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
2297 stored_clid.number.valid = 1;
2298 ast_channel_unlock(chan);
2301 if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2302 ast_cdr_reset(ast_channel_name(chan), 0);
2304 if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
2305 opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan));
2307 if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
2308 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2311 res = -1; /* reset default */
2317 /* If a channel group has been specified, get it for use when we create peer channels */
2319 ast_channel_lock(chan);
2320 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2321 outbound_group = ast_strdupa(outbound_group);
2322 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2323 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2324 outbound_group = ast_strdupa(outbound_group);
2326 ast_channel_unlock(chan);
2328 /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2329 ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID
2330 | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_CANCEL_TIMEOUT
2331 | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
2333 /* PREDIAL: Run gosub on the caller's channel */
2334 if (ast_test_flag64(&opts, OPT_PREDIAL_CALLER)
2335 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2336 ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
2337 ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2340 /* loop through the list of dial destinations */
2342 while ((cur = strsep(&rest, "&")) ) {
2343 struct ast_channel *tc; /* channel for this destination */
2344 /* Get a technology/resource pair */
2346 char *tech = strsep(&number, "/");
2349 struct ast_format_cap *nativeformats;
2352 if (ast_strlen_zero(number)) {
2353 ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2357 tech_len = strlen(tech) + 1;
2358 number_len = strlen(number) + 1;
2359 tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2364 /* Save tech, number, and interface. */
2370 cur[tech_len - 1] = '/';
2371 tmp->interface = cur;
2373 strcpy(cur, number);
2377 /* Set per outgoing call leg options. */
2378 ast_copy_flags64(tmp, &opts,
2379 OPT_CANCEL_ELSEWHERE |
2380 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
2381 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
2382 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
2383 OPT_CALLEE_PARK | OPT_CALLER_PARK |
2384 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
2385 OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID | OPT_IGNORE_CONNECTEDLINE |
2386 OPT_RING_WITH_EARLY_MEDIA);
2387 ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
2390 /* Request the peer */
2392 ast_channel_lock(chan);
2394 * Seed the chanlist's connected line information with previously
2395 * acquired connected line info from the incoming channel. The
2396 * previously acquired connected line info could have been set
2397 * through the CONNECTED_LINE dialplan function.
2399 ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan));
2401 nativeformats = ao2_bump(ast_channel_nativeformats(chan));
2403 ast_channel_unlock(chan);
2405 tc = ast_request(tmp->tech, nativeformats, NULL, chan, tmp->number, &cause);
2407 ao2_cleanup(nativeformats);
2410 /* If we can't, just go on to the next call */
2411 ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
2412 tmp->tech, cause, ast_cause2str(cause));
2413 handle_cause(cause, &num);
2415 /* we are on the last destination */
2416 ast_channel_hangupcause_set(chan, cause);
2418 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2419 if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2420 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, "");
2427 ast_channel_lock(tc);
2428 ast_channel_stage_snapshot(tc);
2429 ast_channel_unlock(tc);
2431 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2433 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2436 ast_channel_lock_both(tc, chan);
2437 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2439 /* Setup outgoing SDP to match incoming one */
2440 if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2441 /* We are on the only destination. */
2442 ast_rtp_instance_early_bridge_make_compatible(tc, chan);
2445 /* Inherit specially named variables from parent channel */
2446 ast_channel_inherit_variables(chan, tc);
2447 ast_channel_datastore_inherit(chan, tc);
2448 ast_max_forwards_decrement(tc);
2450 ast_channel_appl_set(tc, "AppDial");
2451 ast_channel_data_set(tc, "(Outgoing Line)");
2452 ast_channel_publish_snapshot(tc);
2454 memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2456 /* Determine CallerID to store in outgoing channel. */
2457 ast_party_caller_set_init(&caller, ast_channel_caller(tc));
2458 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2459 caller.id = stored_clid;
2460 ast_channel_set_caller_event(tc, &caller, NULL);
2461 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2462 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2463 ast_channel_caller(tc)->id.number.str, NULL))) {
2465 * The new channel has no preset CallerID number by the channel
2466 * driver. Use the dialplan extension and hint name.
2468 caller.id = stored_clid;
2469 if (!caller.id.name.valid
2470 && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2471 ast_channel_connected(chan)->id.name.str, NULL))) {
2473 * No hint name available. We have a connected name supplied by
2474 * the dialplan we can use instead.
2476 caller.id.name.valid = 1;
2477 caller.id.name = ast_channel_connected(chan)->id.name;
2479 ast_channel_set_caller_event(tc, &caller, NULL);
2480 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2481 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2483 /* The new channel has no preset CallerID name by the channel driver. */
2484 if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2485 ast_channel_connected(chan)->id.name.str, NULL))) {
2487 * We have a connected name supplied by the dialplan we can
2490 caller.id.name.valid = 1;
2491 caller.id.name = ast_channel_connected(chan)->id.name;
2492 ast_channel_set_caller_event(tc, &caller, NULL);
2496 /* Determine CallerID for outgoing channel to send. */
2497 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2498 struct ast_party_connected_line connected;
2500 ast_party_connected_line_set_init(&connected, ast_channel_connected(tc));
2501 connected.id = forced_clid;
2502 ast_channel_set_connected_line(tc, &connected, NULL);
2504 ast_connected_line_copy_from_caller(ast_channel_connected(tc), ast_channel_caller(chan));
2507 ast_party_redirecting_copy(ast_channel_redirecting(tc), ast_channel_redirecting(chan));
2509 ast_channel_dialed(tc)->transit_network_select = ast_channel_dialed(chan)->transit_network_select;
2511 ast_channel_req_accountcodes(tc, chan, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
2512 if (ast_strlen_zero(ast_channel_musicclass(tc))) {
2513 ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2516 /* Pass ADSI CPE and transfer capability */
2517 ast_channel_adsicpe_set(tc, ast_channel_adsicpe(chan));
2518 ast_channel_transfercapability_set(tc, ast_channel_transfercapability(chan));
2520 /* If we have an outbound group, set this peer channel to it */
2522 ast_app_group_set_channel(tc, outbound_group);
2523 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2524 if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE)
2525 ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
2527 /* Check if we're forced by configuration */
2528 if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
2529 ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
2532 /* Inherit context and extension */
2533 ast_channel_dialcontext_set(tc, ast_strlen_zero(ast_channel_macrocontext(chan)) ? ast_channel_context(chan) : ast_channel_macrocontext(chan));
2534 if (!ast_strlen_zero(ast_channel_macroexten(chan)))
2535 ast_channel_exten_set(tc, ast_channel_macroexten(chan));
2537 ast_channel_exten_set(tc, ast_channel_exten(chan));
2539 ast_channel_stage_snapshot_done(tc);
2541 /* Save the original channel name to detect call pickup masquerading in. */