2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2008, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 <depend>chan_local</depend>
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38 #include <sys/signal.h>
40 #include <netinet/in.h>
42 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
43 #include "asterisk/lock.h"
44 #include "asterisk/file.h"
45 #include "asterisk/channel.h"
46 #include "asterisk/pbx.h"
47 #include "asterisk/module.h"
48 #include "asterisk/translate.h"
49 #include "asterisk/say.h"
50 #include "asterisk/config.h"
51 #include "asterisk/features.h"
52 #include "asterisk/musiconhold.h"
53 #include "asterisk/callerid.h"
54 #include "asterisk/utils.h"
55 #include "asterisk/app.h"
56 #include "asterisk/causes.h"
57 #include "asterisk/rtp_engine.h"
58 #include "asterisk/cdr.h"
59 #include "asterisk/manager.h"
60 #include "asterisk/privacy.h"
61 #include "asterisk/stringfields.h"
62 #include "asterisk/global_datastores.h"
63 #include "asterisk/dsp.h"
64 #include "asterisk/cel.h"
65 #include "asterisk/indications.h"
68 <application name="Dial" language="en_US">
70 Attempt to connect to another device or endpoint and bridge the call.
73 <parameter name="Technology/Resource" required="true" argsep="&">
74 <argument name="Technology/Resource" required="true">
75 <para>Specification of the device(s) to dial. These must be in the format of
76 <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
77 represents a particular channel driver, and <replaceable>Resource</replaceable>
78 represents a resource available to that particular channel driver.</para>
80 <argument name="Technology2/Resource2" required="false" multiple="true">
81 <para>Optional extra devices to dial in parallel</para>
82 <para>If you need more then one enter them as
83 Technology2/Resource2&Technology3/Resourse3&.....</para>
86 <parameter name="timeout" required="false">
87 <para>Specifies the number of seconds we attempt to dial the specified devices</para>
88 <para>If not specified, this defaults to 136 years.</para>
90 <parameter name="options" required="false">
93 <argument name="x" required="true">
94 <para>The file to play to the called party</para>
96 <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
99 <para>Immediately answer the calling channel when the called channel answers in
100 all cases. Normally, the calling channel is answered when the called channel
101 answers, but when options such as A() and M() are used, the calling channel is
102 not answered until all actions on the called channel (such as playing an
103 announcement) are completed. This option can be used to answer the calling
104 channel before doing anything on the called channel. You will rarely need to use
105 this option, the default behavior is adequate in most cases.</para>
108 <para>Reset the call detail record (CDR) for this call.</para>
111 <para>If the Dial() application cancels this call, always set the flag to tell the channel
112 driver that the call is answered elsewhere.</para>
115 <para>Allow the calling user to dial a 1 digit extension while waiting for
116 a call to be answered. Exit to that extension if it exists in the
117 current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
120 <option name="D" argsep=":">
121 <argument name="called" />
122 <argument name="calling" />
123 <argument name="progress" />
124 <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
125 party has answered, but before the call gets bridged. The
126 <replaceable>called</replaceable> DTMF string is sent to the called party, and the
127 <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
128 can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
129 immediately after receiving a PROGRESS message.</para>
132 <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
135 <para>Force the callerid of the <emphasis>calling</emphasis> channel to be set as the
136 extension associated with the channel using a dialplan <literal>hint</literal>.
137 For example, some PSTNs do not allow CallerID to be set to anything
138 other than the number assigned to the caller.</para>
140 <option name="F" argsep="^">
141 <argument name="context" required="false" />
142 <argument name="exten" required="false" />
143 <argument name="priority" required="true" />
144 <para>When the caller hangs up, transfer the called party
145 to the specified destination and continue execution at that location.</para>
148 <para>Proceed with dialplan execution at the next priority in the current extension if the
149 source channel hangs up.</para>
152 <para>Proceed with dialplan execution at the next priority in the current extension if the
153 destination channel hangs up.</para>
155 <option name="G" argsep="^">
156 <argument name="context" required="false" />
157 <argument name="exten" required="false" />
158 <argument name="priority" required="true" />
159 <para>If the call is answered, transfer the calling party to
160 the specified <replaceable>priority</replaceable> and the called party to the specified
161 <replaceable>priority</replaceable> plus one.</para>
163 <para>You cannot use any additional action post answer options in conjunction with this option.</para>
167 <para>Allow the called party to hang up by sending the <literal>*</literal> DTMF digit.</para>
170 <para>Allow the calling party to hang up by hitting the <literal>*</literal> DTMF digit.</para>
173 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
176 <para>Asterisk will ignore any connected line update requests or redirecting party update
177 requests it may receiveon this dial attempt.</para>
180 <para>Allow the called party to enable parking of the call by sending
181 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
184 <para>Allow the calling party to enable parking of the call by sending
185 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
187 <option name="L" argsep=":">
188 <argument name="x" required="true">
189 <para>Maximum call time, in milliseconds</para>
192 <para>Warning time, in milliseconds</para>
195 <para>Repeat time, in milliseconds</para>
197 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
198 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
199 <para>This option is affected by the following variables:</para>
201 <variable name="LIMIT_PLAYAUDIO_CALLER">
202 <value name="yes" default="true" />
204 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
206 <variable name="LIMIT_PLAYAUDIO_CALLEE">
208 <value name="no" default="true"/>
209 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
211 <variable name="LIMIT_TIMEOUT_FILE">
212 <value name="filename"/>
213 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
214 If not set, the time remaining will be announced.</para>
216 <variable name="LIMIT_CONNECT_FILE">
217 <value name="filename"/>
218 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
219 If not set, the time remaining will be announced.</para>
221 <variable name="LIMIT_WARNING_FILE">
222 <value name="filename"/>
223 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
224 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
229 <argument name="class" required="false"/>
230 <para>Provide hold music to the calling party until a requested
231 channel answers. A specific music on hold <replaceable>class</replaceable>
232 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
234 <option name="M" argsep="^">
235 <argument name="macro" required="true">
236 <para>Name of the macro that should be executed.</para>
238 <argument name="arg" multiple="true">
239 <para>Macro arguments</para>
241 <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
242 before connecting to the calling channel. Arguments can be specified to the Macro
243 using <literal>^</literal> as a delimiter. The macro can set the variable
244 <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
245 finished executing:</para>
247 <variable name="MACRO_RESULT">
248 <para>If set, this action will be taken after the macro finished executing.</para>
250 Hangup both legs of the call
252 <value name="CONGESTION">
253 Behave as if line congestion was encountered
256 Behave as if a busy signal was encountered
258 <value name="CONTINUE">
259 Hangup the called party and allow the calling party to continue dialplan execution at the next priority
261 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
262 <value name="GOTO:<context>^<exten>^<priority>">
263 Transfer the call to the specified destination.
268 <para>You cannot use any additional action post answer options in conjunction
269 with this option. Also, pbx services are not run on the peer (called) channel,
270 so you will not be able to set timeouts via the TIMEOUT() function in this macro.</para>
272 <warning><para>Be aware of the limitations that macros have, specifically with regards to use of
273 the <literal>WaitExten</literal> application. For more information, see the documentation for
274 Macro()</para></warning>
277 <argument name="delete">
278 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
279 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
281 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
282 always be deleted.</para>
284 <para>This option is a modifier for the call screening/privacy mode. (See the
285 <literal>p</literal> and <literal>P</literal> options.) It specifies
286 that no introductions are to be saved in the <directory>priv-callerintros</directory>
290 <para>This option is a modifier for the call screening/privacy mode. It specifies
291 that if Caller*ID is present, do not screen the call.</para>
294 <para>Specify that the Caller*ID that was present on the <emphasis>calling</emphasis> channel
295 be set as the Caller*ID on the <emphasis>called</emphasis> channel. This was the
296 behavior of Asterisk 1.0 and earlier.</para>
299 <argument name="mode">
300 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
301 the originator hanging up will cause the phone to ring back immediately.</para>
302 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
303 flashes the trunk, it will ring their phone back.</para>
305 <para>Enables <emphasis>operator services</emphasis> mode. This option only
306 works when bridging a DAHDI channel to another DAHDI channel
307 only. if specified on non-DAHDI interfaces, it will be ignored.
308 When the destination answers (presumably an operator services
309 station), the originator no longer has control of their line.
310 They may hang up, but the switch will not release their line
311 until the destination party (the operator) hangs up.</para>
314 <para>This option enables screening mode. This is basically Privacy mode
315 without memory.</para>
318 <argument name="x" />
319 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
320 it is provided. The current extension is used if a database family/key is not specified.</para>
323 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
324 party until the called channel has answered.</para>
325 <argument name="tone" required="false">
326 <para>Indicate progress to calling party. Send audio 'tone' from indications.conf</para>
330 <argument name="x" required="true" />
331 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
332 answered the call.</para>
335 <para>Allow the called party to transfer the calling party by sending the
336 DTMF sequence defined in <filename>features.conf</filename>.</para>
339 <para>Allow the calling party to transfer the called party by sending the
340 DTMF sequence defined in <filename>features.conf</filename>.</para>
342 <option name="U" argsep="^">
343 <argument name="x" required="true">
344 <para>Name of the subroutine to execute via Gosub</para>
346 <argument name="arg" multiple="true" required="false">
347 <para>Arguments for the Gosub routine</para>
349 <para>Execute via Gosub the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
350 to the calling channel. Arguments can be specified to the Gosub
351 using <literal>^</literal> as a delimiter. The Gosub routine can set the variable
352 <variable>GOSUB_RESULT</variable> to specify the following actions after the Gosub returns.</para>
354 <variable name="GOSUB_RESULT">
356 Hangup both legs of the call.
358 <value name="CONGESTION">
359 Behave as if line congestion was encountered.
362 Behave as if a busy signal was encountered.
364 <value name="CONTINUE">
365 Hangup the called party and allow the calling party
366 to continue dialplan execution at the next priority.
368 <!-- TODO: Fix this syntax up, once we've figured out how to specify the GOTO syntax -->
369 <value name="GOTO:<context>^<exten>^<priority>">
370 Transfer the call to the specified priority. Optionally, an extension, or
371 extension and priority can be specified.
376 <para>You cannot use any additional action post answer options in conjunction
377 with this option. Also, pbx services are not run on the peer (called) channel,
378 so you will not be able to set timeouts via the TIMEOUT() function in this routine.</para>
382 <para>Allow the called party to enable recording of the call by sending
383 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
386 <para>Allow the calling party to enable recording of the call by sending
387 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
390 <para>Allow the called party to enable recording of the call by sending
391 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
394 <para>Allow the calling party to enable recording of the call by sending
395 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
398 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
402 <parameter name="URL">
403 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
407 <para>This application will place calls to one or more specified channels. As soon
408 as one of the requested channels answers, the originating channel will be
409 answered, if it has not already been answered. These two channels will then
410 be active in a bridged call. All other channels that were requested will then
413 <para>Unless there is a timeout specified, the Dial application will wait
414 indefinitely until one of the called channels answers, the user hangs up, or
415 if all of the called channels are busy or unavailable. Dialplan executing will
416 continue if no requested channels can be called, or if the timeout expires.
417 This application will report normal termination if the originating channel
418 hangs up, or if the call is bridged and either of the parties in the bridge
419 ends the call.</para>
420 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
421 application will be put into that group (as in Set(GROUP()=...).
422 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
423 application will be put into that group (as in Set(GROUP()=...). Unlike OUTBOUND_GROUP,
424 however, the variable will be unset after use.</para>
426 <para>This application sets the following channel variables:</para>
428 <variable name="DIALEDTIME">
429 <para>This is the time from dialing a channel until when it is disconnected.</para>
431 <variable name="ANSWEREDTIME">
432 <para>This is the amount of time for actual call.</para>
434 <variable name="DIALSTATUS">
435 <para>This is the status of the call</para>
436 <value name="CHANUNAVAIL" />
437 <value name="CONGESTION" />
438 <value name="NOANSWER" />
439 <value name="BUSY" />
440 <value name="ANSWER" />
441 <value name="CANCEL" />
442 <value name="DONTCALL">
443 For the Privacy and Screening Modes.
444 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
446 <value name="TORTURE">
447 For the Privacy and Screening Modes.
448 Will be set if the called party chooses to send the calling party to the 'torture' script.
450 <value name="INVALIDARGS" />
455 <application name="RetryDial" language="en_US">
457 Place a call, retrying on failure allowing an optional exit extension.
460 <parameter name="announce" required="true">
461 <para>Filename of sound that will be played when no channel can be reached</para>
463 <parameter name="sleep" required="true">
464 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
466 <parameter name="retries" required="true">
467 <para>Number of retries</para>
468 <para>When this is reached flow will continue at the next priority in the dialplan</para>
470 <parameter name="dialargs" required="true">
471 <para>Same format as arguments provided to the Dial application</para>
475 <para>This application will attempt to place a call using the normal Dial application.
476 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
477 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
478 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
479 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
480 While waiting to retry a call, a 1 digit extension may be dialed. If that
481 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
482 one, The call will jump to that extension immediately.
483 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
484 to the Dial application.</para>
489 static const char app[] = "Dial";
490 static const char rapp[] = "RetryDial";
493 OPT_ANNOUNCE = (1 << 0),
494 OPT_RESETCDR = (1 << 1),
495 OPT_DTMF_EXIT = (1 << 2),
496 OPT_SENDDTMF = (1 << 3),
497 OPT_FORCECLID = (1 << 4),
498 OPT_GO_ON = (1 << 5),
499 OPT_CALLEE_HANGUP = (1 << 6),
500 OPT_CALLER_HANGUP = (1 << 7),
501 OPT_ORIGINAL_CLID = (1 << 8),
502 OPT_DURATION_LIMIT = (1 << 9),
503 OPT_MUSICBACK = (1 << 10),
504 OPT_CALLEE_MACRO = (1 << 11),
505 OPT_SCREEN_NOINTRO = (1 << 12),
506 OPT_SCREEN_NOCALLERID = (1 << 13),
507 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
508 OPT_SCREENING = (1 << 15),
509 OPT_PRIVACY = (1 << 16),
510 OPT_RINGBACK = (1 << 17),
511 OPT_DURATION_STOP = (1 << 18),
512 OPT_CALLEE_TRANSFER = (1 << 19),
513 OPT_CALLER_TRANSFER = (1 << 20),
514 OPT_CALLEE_MONITOR = (1 << 21),
515 OPT_CALLER_MONITOR = (1 << 22),
516 OPT_GOTO = (1 << 23),
517 OPT_OPERMODE = (1 << 24),
518 OPT_CALLEE_PARK = (1 << 25),
519 OPT_CALLER_PARK = (1 << 26),
520 OPT_IGNORE_FORWARDING = (1 << 27),
521 OPT_CALLEE_GOSUB = (1 << 28),
522 OPT_CALLEE_MIXMONITOR = (1 << 29),
523 OPT_CALLER_MIXMONITOR = (1 << 30),
524 OPT_CALLER_ANSWER = (1 << 31),
527 #define DIAL_STILLGOING (1 << 31)
528 #define DIAL_NOFORWARDHTML ((uint64_t)1 << 32) /* flags are now 64 bits, so keep it up! */
529 #define DIAL_NOCONNECTEDLINE ((uint64_t)1 << 33)
530 #define OPT_CANCEL_ELSEWHERE ((uint64_t)1 << 34)
531 #define OPT_PEER_H ((uint64_t)1 << 35)
532 #define OPT_CALLEE_GO_ON ((uint64_t)1 << 36)
533 #define OPT_CANCEL_TIMEOUT ((uint64_t)1 << 37)
536 OPT_ARG_ANNOUNCE = 0,
539 OPT_ARG_DURATION_LIMIT,
541 OPT_ARG_CALLEE_MACRO,
543 OPT_ARG_CALLEE_GOSUB,
544 OPT_ARG_CALLEE_GO_ON,
546 OPT_ARG_DURATION_STOP,
548 OPT_ARG_SCREEN_NOINTRO,
549 /* note: this entry _MUST_ be the last one in the enum */
553 AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
554 AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
555 AST_APP_OPTION('a', OPT_CALLER_ANSWER),
556 AST_APP_OPTION('C', OPT_RESETCDR),
557 AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
558 AST_APP_OPTION('d', OPT_DTMF_EXIT),
559 AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
560 AST_APP_OPTION('e', OPT_PEER_H),
561 AST_APP_OPTION('f', OPT_FORCECLID),
562 AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
563 AST_APP_OPTION('g', OPT_GO_ON),
564 AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
565 AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
566 AST_APP_OPTION('H', OPT_CALLER_HANGUP),
567 AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
568 AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
569 AST_APP_OPTION('k', OPT_CALLEE_PARK),
570 AST_APP_OPTION('K', OPT_CALLER_PARK),
571 AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
572 AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
573 AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
574 AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
575 AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
576 AST_APP_OPTION('o', OPT_ORIGINAL_CLID),
577 AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
578 AST_APP_OPTION('p', OPT_SCREENING),
579 AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
580 AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
581 AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
582 AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
583 AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
584 AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
585 AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
586 AST_APP_OPTION('W', OPT_CALLER_MONITOR),
587 AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
588 AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
589 AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
592 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
593 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
594 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
595 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
596 !chan->audiohooks && !peer->audiohooks)
599 * The list of active channels
602 struct chanlist *next;
603 struct ast_channel *chan;
605 struct ast_party_connected_line connected;
608 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode);
610 static void chanlist_free(struct chanlist *outgoing)
612 ast_party_connected_line_free(&outgoing->connected);
616 static void hanguptree(struct chanlist *outgoing, struct ast_channel *exception, int answered_elsewhere)
618 /* Hang up a tree of stuff */
621 /* Hangup any existing lines we have open */
622 if (outgoing->chan && (outgoing->chan != exception)) {
623 if (answered_elsewhere) {
624 /* The flag is used for local channel inheritance and stuff */
625 ast_set_flag(outgoing->chan, AST_FLAG_ANSWERED_ELSEWHERE);
626 /* This is for the channel drivers */
627 outgoing->chan->hangupcause = AST_CAUSE_ANSWERED_ELSEWHERE;
629 ast_party_connected_line_free(&outgoing->connected);
630 ast_hangup(outgoing->chan);
633 outgoing = outgoing->next;
638 #define AST_MAX_WATCHERS 256
641 * argument to handle_cause() and other functions.
644 struct ast_channel *chan;
650 static void handle_cause(int cause, struct cause_args *num)
652 struct ast_cdr *cdr = num->chan->cdr;
661 case AST_CAUSE_CONGESTION:
667 case AST_CAUSE_NO_ROUTE_DESTINATION:
668 case AST_CAUSE_UNREGISTERED:
674 case AST_CAUSE_NO_ANSWER:
676 ast_cdr_noanswer(cdr);
679 case AST_CAUSE_NORMAL_CLEARING:
688 /* free the buffer if allocated, and set the pointer to the second arg */
689 #define S_REPLACE(s, new_val) \
696 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
698 char rexten[2] = { exten, '\0' };
701 if (!ast_goto_if_exists(chan, context, rexten, pri))
704 if (!ast_goto_if_exists(chan, chan->context, rexten, pri))
706 else if (!ast_strlen_zero(chan->macrocontext)) {
707 if (!ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
714 /* do not call with chan lock held */
715 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
720 ast_channel_lock(chan);
721 context = ast_strdupa(S_OR(chan->macrocontext, chan->context));
722 exten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
723 ast_channel_unlock(chan);
725 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
728 static void senddialevent(struct ast_channel *src, struct ast_channel *dst, const char *dialstring)
730 struct ast_channel *chans[] = { src, dst };
731 ast_manager_event_multichan(EVENT_FLAG_CALL, "Dial", 2, chans,
732 "SubEvent: Begin\r\n"
734 "Destination: %s\r\n"
735 "CallerIDNum: %s\r\n"
736 "CallerIDName: %s\r\n"
738 "DestUniqueID: %s\r\n"
739 "Dialstring: %s\r\n",
740 src->name, dst->name, S_OR(src->cid.cid_num, "<unknown>"),
741 S_OR(src->cid.cid_name, "<unknown>"), src->uniqueid,
742 dst->uniqueid, dialstring ? dialstring : "");
745 static void senddialendevent(struct ast_channel *src, const char *dialstatus)
747 ast_manager_event(src, EVENT_FLAG_CALL, "Dial",
751 "DialStatus: %s\r\n",
752 src->name, src->uniqueid, dialstatus);
756 * helper function for wait_for_answer()
758 * XXX this code is highly suspicious, as it essentially overwrites
759 * the outgoing channel without properly deleting it.
761 * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
763 static void do_forward(struct chanlist *o,
764 struct cause_args *num, struct ast_flags64 *peerflags, int single, int *to)
767 struct ast_channel *original = o->chan;
768 struct ast_channel *c = o->chan; /* the winner */
769 struct ast_channel *in = num->chan; /* the input channel */
770 struct ast_party_redirecting *apr = &o->chan->redirecting;
771 struct ast_party_connected_line *apc = &o->chan->connected;
776 ast_copy_string(tmpchan, c->call_forward, sizeof(tmpchan));
777 if ((stuff = strchr(tmpchan, '/'))) {
781 const char *forward_context;
783 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
784 if (ast_strlen_zero(forward_context)) {
785 forward_context = NULL;
787 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", c->call_forward, forward_context ? forward_context : c->context);
788 ast_channel_unlock(c);
793 ast_cel_report_event(in, AST_CEL_FORWARD, NULL, c->call_forward, NULL);
795 /* Before processing channel, go ahead and check for forwarding */
796 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
797 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
798 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
799 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
801 cause = AST_CAUSE_BUSY;
803 /* Setup parameters */
804 c = o->chan = ast_request(tech, in->nativeformats, in, stuff, &cause);
807 ast_channel_make_compatible(o->chan, in);
808 ast_channel_inherit_variables(in, o->chan);
809 ast_channel_datastore_inherit(in, o->chan);
811 ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
814 ast_clear_flag64(o, DIAL_STILLGOING);
815 handle_cause(cause, num);
816 ast_hangup(original);
818 if (single && CAN_EARLY_BRIDGE(peerflags, c, in)) {
819 ast_rtp_instance_early_bridge_make_compatible(c, in);
822 c->cdrflags = in->cdrflags;
824 ast_channel_set_redirecting(c, apr);
826 while (ast_channel_trylock(in)) {
827 CHANNEL_DEADLOCK_AVOIDANCE(c);
829 S_REPLACE(c->cid.cid_rdnis, ast_strdup(S_OR(original->cid.cid_rdnis, S_OR(in->macroexten, in->exten))));
831 c->cid.cid_tns = in->cid.cid_tns;
833 if (ast_test_flag64(o, OPT_FORCECLID)) {
834 S_REPLACE(c->cid.cid_num, ast_strdupa(S_OR(in->macroexten, in->exten)));
835 S_REPLACE(c->cid.cid_name, NULL);
836 ast_string_field_set(c, accountcode, c->accountcode);
838 ast_party_caller_copy(&c->cid, &in->cid);
839 ast_string_field_set(c, accountcode, in->accountcode);
841 ast_party_connected_line_copy(&c->connected, apc);
843 S_REPLACE(in->cid.cid_rdnis, ast_strdup(c->cid.cid_rdnis));
844 ast_channel_update_redirecting(in, apr);
846 ast_clear_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE);
847 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
851 ast_channel_unlock(in);
852 ast_channel_unlock(c);
854 if (ast_call(c, tmpchan, 0)) {
855 ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
856 ast_clear_flag64(o, DIAL_STILLGOING);
857 ast_hangup(original);
863 while (ast_channel_trylock(in)) {
864 CHANNEL_DEADLOCK_AVOIDANCE(c);
866 senddialevent(in, c, stuff);
867 if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
868 char cidname[AST_MAX_EXTENSION] = "";
869 const char *tmpexten;
870 tmpexten = ast_strdupa(S_OR(in->macroexten, in->exten));
871 ast_channel_unlock(in);
872 ast_channel_unlock(c);
873 ast_set_callerid(c, tmpexten, get_cid_name(cidname, sizeof(cidname), in), NULL);
875 ast_channel_unlock(in);
876 ast_channel_unlock(c);
878 /* Hangup the original channel now, in case we needed it */
879 ast_hangup(original);
882 ast_indicate(in, -1);
887 /* argument used for some functions. */
888 struct privacy_args {
892 char privintro[1024];
896 static struct ast_channel *wait_for_answer(struct ast_channel *in,
897 struct chanlist *outgoing, int *to, struct ast_flags64 *peerflags,
899 struct privacy_args *pa,
900 const struct cause_args *num_in, int *result, char *dtmf_progress)
902 struct cause_args num = *num_in;
903 int prestart = num.busy + num.congestion + num.nochan;
905 struct ast_channel *peer = NULL;
906 /* single is set if only one destination is enabled */
907 int single = outgoing && !outgoing->next;
909 struct chanlist *epollo;
911 struct ast_party_connected_line connected_caller;
912 struct ast_str *featurecode = ast_str_alloca(FEATURE_MAX_LEN + 1);
914 ast_party_connected_line_init(&connected_caller);
916 /* Turn off hold music, etc */
917 if (!ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK)) {
918 ast_deactivate_generator(in);
919 /* If we are calling a single channel, and not providing ringback or music, */
920 /* then, make them compatible for in-band tone purpose */
921 ast_channel_make_compatible(outgoing->chan, in);
924 if (!ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE) && !ast_test_flag64(outgoing, DIAL_NOCONNECTEDLINE)) {
925 ast_channel_lock(outgoing->chan);
926 ast_connected_line_copy_from_caller(&connected_caller, &outgoing->chan->cid);
927 ast_channel_unlock(outgoing->chan);
928 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
929 ast_channel_update_connected_line(in, &connected_caller);
930 ast_party_connected_line_free(&connected_caller);
935 for (epollo = outgoing; epollo; epollo = epollo->next)
936 ast_poll_channel_add(in, epollo->chan);
939 while (*to && !peer) {
941 int pos = 0; /* how many channels do we handle */
942 int numlines = prestart;
943 struct ast_channel *winner;
944 struct ast_channel *watchers[AST_MAX_WATCHERS];
946 watchers[pos++] = in;
947 for (o = outgoing; o; o = o->next) {
948 /* Keep track of important channels */
949 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
950 watchers[pos++] = o->chan;
953 if (pos == 1) { /* only the input channel is available */
954 if (numlines == (num.busy + num.congestion + num.nochan)) {
955 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
957 strcpy(pa->status, "BUSY");
958 else if (num.congestion)
959 strcpy(pa->status, "CONGESTION");
961 strcpy(pa->status, "CHANUNAVAIL");
963 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
968 winner = ast_waitfor_n(watchers, pos, to);
969 for (o = outgoing; o; o = o->next) {
971 struct ast_channel *c = o->chan;
975 if (ast_test_flag64(o, DIAL_STILLGOING) && c->_state == AST_STATE_UP) {
977 ast_verb(3, "%s answered %s\n", c->name, in->name);
978 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
979 if (o->connected.id.number) {
980 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
981 ast_channel_update_connected_line(in, &o->connected);
983 } else if (!ast_test_flag64(o, DIAL_NOCONNECTEDLINE)) {
985 ast_connected_line_copy_from_caller(&connected_caller, &c->cid);
986 ast_channel_unlock(c);
987 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
988 ast_channel_update_connected_line(in, &connected_caller);
989 ast_party_connected_line_free(&connected_caller);
993 ast_copy_flags64(peerflags, o,
994 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
995 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
996 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
997 OPT_CALLEE_PARK | OPT_CALLER_PARK |
998 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1000 ast_string_field_set(c, dialcontext, "");
1001 ast_copy_string(c->exten, "", sizeof(c->exten));
1007 /* here, o->chan == c == winner */
1008 if (!ast_strlen_zero(c->call_forward)) {
1009 pa->sentringing = 0;
1010 do_forward(o, &num, peerflags, single, to);
1013 f = ast_read(winner);
1015 in->hangupcause = c->hangupcause;
1017 ast_poll_channel_del(in, c);
1021 ast_clear_flag64(o, DIAL_STILLGOING);
1022 handle_cause(in->hangupcause, &num);
1025 if (f->frametype == AST_FRAME_CONTROL) {
1026 switch (f->subclass.integer) {
1027 case AST_CONTROL_ANSWER:
1028 /* This is our guy if someone answered. */
1030 ast_verb(3, "%s answered %s\n", c->name, in->name);
1031 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1032 if (o->connected.id.number) {
1033 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
1034 ast_channel_update_connected_line(in, &o->connected);
1036 } else if (!ast_test_flag64(o, DIAL_NOCONNECTEDLINE)) {
1037 ast_channel_lock(c);
1038 ast_connected_line_copy_from_caller(&connected_caller, &c->cid);
1039 ast_channel_unlock(c);
1040 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1041 ast_channel_update_connected_line(in, &connected_caller);
1042 ast_party_connected_line_free(&connected_caller);
1047 peer->cdr->answer = ast_tvnow();
1048 peer->cdr->disposition = AST_CDR_ANSWERED;
1050 ast_copy_flags64(peerflags, o,
1051 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1052 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1053 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1054 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1055 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1056 DIAL_NOFORWARDHTML);
1057 ast_string_field_set(c, dialcontext, "");
1058 ast_copy_string(c->exten, "", sizeof(c->exten));
1059 if (CAN_EARLY_BRIDGE(peerflags, in, peer))
1060 /* Setup early bridge if appropriate */
1061 ast_channel_early_bridge(in, peer);
1063 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1064 in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
1065 c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
1067 case AST_CONTROL_BUSY:
1068 ast_verb(3, "%s is busy\n", c->name);
1069 in->hangupcause = c->hangupcause;
1072 ast_clear_flag64(o, DIAL_STILLGOING);
1073 handle_cause(AST_CAUSE_BUSY, &num);
1075 case AST_CONTROL_CONGESTION:
1076 ast_verb(3, "%s is circuit-busy\n", c->name);
1077 in->hangupcause = c->hangupcause;
1080 ast_clear_flag64(o, DIAL_STILLGOING);
1081 handle_cause(AST_CAUSE_CONGESTION, &num);
1083 case AST_CONTROL_RINGING:
1084 ast_verb(3, "%s is ringing\n", c->name);
1085 /* Setup early media if appropriate */
1086 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1087 ast_channel_early_bridge(in, c);
1088 if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
1089 ast_indicate(in, AST_CONTROL_RINGING);
1093 case AST_CONTROL_PROGRESS:
1094 ast_verb(3, "%s is making progress passing it to %s\n", c->name, in->name);
1095 /* Setup early media if appropriate */
1096 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1097 ast_channel_early_bridge(in, c);
1098 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1099 if (single || (!single && !pa->sentringing)) {
1100 ast_indicate(in, AST_CONTROL_PROGRESS);
1102 if(!ast_strlen_zero(dtmf_progress)) {
1103 ast_verb(3, "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n", dtmf_progress);
1104 ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1107 case AST_CONTROL_VIDUPDATE:
1108 ast_verb(3, "%s requested a video update, passing it to %s\n", c->name, in->name);
1109 ast_indicate(in, AST_CONTROL_VIDUPDATE);
1111 case AST_CONTROL_SRCUPDATE:
1112 ast_verb(3, "%s requested a source update, passing it to %s\n", c->name, in->name);
1113 ast_indicate(in, AST_CONTROL_SRCUPDATE);
1115 case AST_CONTROL_CONNECTED_LINE:
1116 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1117 ast_verb(3, "Connected line update to %s prevented.\n", in->name);
1118 } else if (!single) {
1119 struct ast_party_connected_line connected;
1120 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", c->name, in->name);
1121 ast_party_connected_line_set_init(&connected, &o->connected);
1122 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
1123 ast_party_connected_line_set(&o->connected, &connected);
1124 ast_party_connected_line_free(&connected);
1126 if (ast_channel_connected_line_macro(c, in, f, 1, 1)) {
1127 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
1131 case AST_CONTROL_REDIRECTING:
1132 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
1133 ast_verb(3, "Redirecting update to %s prevented.\n", in->name);
1135 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", c->name, in->name);
1136 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
1137 pa->sentringing = 0;
1140 case AST_CONTROL_PROCEEDING:
1141 ast_verb(3, "%s is proceeding passing it to %s\n", c->name, in->name);
1142 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
1143 ast_channel_early_bridge(in, c);
1144 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
1145 ast_indicate(in, AST_CONTROL_PROCEEDING);
1147 case AST_CONTROL_HOLD:
1148 ast_verb(3, "Call on %s placed on hold\n", c->name);
1149 ast_indicate(in, AST_CONTROL_HOLD);
1151 case AST_CONTROL_UNHOLD:
1152 ast_verb(3, "Call on %s left from hold\n", c->name);
1153 ast_indicate(in, AST_CONTROL_UNHOLD);
1155 case AST_CONTROL_OFFHOOK:
1156 case AST_CONTROL_FLASH:
1157 /* Ignore going off hook and flash */
1160 if (!ast_test_flag64(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
1161 ast_verb(3, "%s stopped sounds\n", c->name);
1162 ast_indicate(in, -1);
1163 pa->sentringing = 0;
1167 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1169 } else if (single) {
1170 switch (f->frametype) {
1171 case AST_FRAME_VOICE:
1172 case AST_FRAME_IMAGE:
1173 case AST_FRAME_TEXT:
1174 if (ast_write(in, f)) {
1175 ast_log(LOG_WARNING, "Unable to write frame\n");
1178 case AST_FRAME_HTML:
1179 if (!ast_test_flag64(outgoing, DIAL_NOFORWARDHTML) && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1180 ast_log(LOG_WARNING, "Unable to send URL\n");
1190 struct ast_frame *f = ast_read(in);
1192 if (f && (f->frametype != AST_FRAME_VOICE))
1193 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1194 else if (!f || (f->frametype != AST_FRAME_VOICE))
1195 printf("Hangup received on %s\n", in->name);
1197 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1200 strcpy(pa->status, "CANCEL");
1201 ast_cdr_noanswer(in->cdr);
1203 if (f->data.uint32) {
1204 in->hangupcause = f->data.uint32;
1211 /* now f is guaranteed non-NULL */
1212 if (f->frametype == AST_FRAME_DTMF) {
1213 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1214 const char *context;
1215 ast_channel_lock(in);
1216 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1217 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1218 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1220 ast_cdr_noanswer(in->cdr);
1221 *result = f->subclass.integer;
1222 strcpy(pa->status, "CANCEL");
1224 ast_channel_unlock(in);
1227 ast_channel_unlock(in);
1230 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1231 detect_disconnect(in, f->subclass.integer, featurecode)) {
1232 ast_verb(3, "User requested call disconnect.\n");
1234 strcpy(pa->status, "CANCEL");
1235 ast_cdr_noanswer(in->cdr);
1241 /* Forward HTML stuff */
1242 if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML))
1243 if (ast_channel_sendhtml(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1)
1244 ast_log(LOG_WARNING, "Unable to send URL\n");
1246 if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF_BEGIN) || (f->frametype == AST_FRAME_DTMF_END))) {
1247 if (ast_write(outgoing->chan, f))
1248 ast_log(LOG_WARNING, "Unable to forward voice or dtmf\n");
1250 if (single && (f->frametype == AST_FRAME_CONTROL)) {
1251 if ((f->subclass.integer == AST_CONTROL_HOLD) ||
1252 (f->subclass.integer == AST_CONTROL_UNHOLD) ||
1253 (f->subclass.integer == AST_CONTROL_VIDUPDATE) ||
1254 (f->subclass.integer == AST_CONTROL_SRCUPDATE) ||
1255 (f->subclass.integer == AST_CONTROL_REDIRECTING)) {
1256 ast_verb(3, "%s requested special control %d, passing it to %s\n", in->name, f->subclass.integer, outgoing->chan->name);
1257 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
1258 } else if (f->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
1259 if (ast_channel_connected_line_macro(in, outgoing->chan, f, 0, 1)) {
1260 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
1267 ast_verb(3, "Nobody picked up in %d ms\n", orig);
1268 if (!*to || ast_check_hangup(in))
1269 ast_cdr_noanswer(in->cdr);
1273 for (epollo = outgoing; epollo; epollo = epollo->next) {
1275 ast_poll_channel_del(in, epollo->chan);
1282 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode)
1284 struct ast_flags features = { AST_FEATURE_DISCONNECT }; /* only concerned with disconnect feature */
1285 struct ast_call_feature feature = { 0, };
1288 ast_str_append(&featurecode, 1, "%c", code);
1290 res = ast_feature_detect(chan, &features, ast_str_buffer(featurecode), &feature);
1292 if (res != AST_FEATURE_RETURN_STOREDIGITS) {
1293 ast_str_reset(featurecode);
1295 if (feature.feature_mask & AST_FEATURE_DISCONNECT) {
1302 static void replace_macro_delimiter(char *s)
1309 /* returns true if there is a valid privacy reply */
1310 static int valid_priv_reply(struct ast_flags64 *opts, int res)
1314 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1316 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1321 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1322 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1328 /* Get the user's intro, store it in priv-callerintros/$CID,
1329 unless it is already there-- this should be done before the
1330 call is actually dialed */
1332 /* all ring indications and moh for the caller has been halted as soon as the
1333 target extension was picked up. We are going to have to kill some
1334 time and make the caller believe the peer hasn't picked up yet */
1336 if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
1337 char *original_moh = ast_strdupa(chan->musicclass);
1338 ast_indicate(chan, -1);
1339 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
1340 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1341 ast_string_field_set(chan, musicclass, original_moh);
1342 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1343 ast_indicate(chan, AST_CONTROL_RINGING);
1347 /* Start autoservice on the other chan ?? */
1348 res2 = ast_autoservice_start(chan);
1349 /* Now Stream the File */
1350 for (loopcount = 0; loopcount < 3; loopcount++) {
1351 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1353 if (!res2) /* on timeout, play the message again */
1354 res2 = ast_play_and_wait(peer, "priv-callpending");
1355 if (!valid_priv_reply(opts, res2))
1357 /* priv-callpending script:
1358 "I have a caller waiting, who introduces themselves as:"
1361 res2 = ast_play_and_wait(peer, pa->privintro);
1362 if (!valid_priv_reply(opts, res2))
1364 /* now get input from the called party, as to their choice */
1366 /* XXX can we have both, or they are mutually exclusive ? */
1367 if (ast_test_flag64(opts, OPT_PRIVACY))
1368 res2 = ast_play_and_wait(peer, "priv-callee-options");
1369 if (ast_test_flag64(opts, OPT_SCREENING))
1370 res2 = ast_play_and_wait(peer, "screen-callee-options");
1372 /*! \page DialPrivacy Dial Privacy scripts
1373 \par priv-callee-options script:
1374 "Dial 1 if you wish this caller to reach you directly in the future,
1375 and immediately connect to their incoming call
1376 Dial 2 if you wish to send this caller to voicemail now and
1378 Dial 3 to send this caller to the torture menus, now and forevermore.
1379 Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
1380 Dial 5 to allow this caller to come straight thru to you in the future,
1381 but right now, just this once, send them to voicemail."
1382 \par screen-callee-options script:
1383 "Dial 1 if you wish to immediately connect to the incoming call
1384 Dial 2 if you wish to send this caller to voicemail.
1385 Dial 3 to send this caller to the torture menus.
1386 Dial 4 to send this caller to a simple "go away" menu.
1388 if (valid_priv_reply(opts, res2))
1390 /* invalid option */
1391 res2 = ast_play_and_wait(peer, "vm-sorry");
1394 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
1396 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
1397 ast_indicate(chan, -1);
1398 pa->sentringing = 0;
1400 ast_autoservice_stop(chan);
1401 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
1402 /* map keypresses to various things, the index is res2 - '1' */
1403 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
1404 static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
1406 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
1407 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
1408 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
1414 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1417 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1420 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1423 /* XXX should we set status to DENY ? */
1424 if (ast_test_flag64(opts, OPT_PRIVACY))
1426 /* if not privacy, then 5 is the same as "default" case */
1427 default: /* bad input or -1 if failure to start autoservice */
1428 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
1429 /* well, there seems basically two choices. Just patch the caller thru immediately,
1430 or,... put 'em thru to voicemail. */
1431 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
1432 ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
1433 /* XXX should we set status to DENY ? */
1434 /* XXX what about the privacy flags ? */
1438 if (res2 == '1') { /* the only case where we actually connect */
1439 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
1440 just clog things up, and it's not useful information, not being tied to a CID */
1441 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
1442 ast_filedelete(pa->privintro, NULL);
1443 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1444 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1446 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1448 return 0; /* the good exit path */
1450 ast_hangup(peer); /* hang up on the callee -- he didn't want to talk anyway! */
1455 /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
1456 static int setup_privacy_args(struct privacy_args *pa,
1457 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
1462 int silencethreshold;
1464 if (!ast_strlen_zero(chan->cid.cid_num)) {
1465 l = ast_strdupa(chan->cid.cid_num);
1466 ast_shrink_phone_number(l);
1467 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
1468 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
1469 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
1471 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
1472 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1477 tnam = ast_strdupa(chan->name);
1478 /* clean the channel name so slashes don't try to end up in disk file name */
1479 for (tn2 = tnam; *tn2; tn2++) {
1480 if (*tn2 == '/') /* any other chars to be afraid of? */
1483 ast_verb(3, "Privacy-- callerid is empty\n");
1485 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", chan->exten, tnam);
1487 pa->privdb_val = AST_PRIVACY_UNKNOWN;
1490 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
1492 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
1493 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
1494 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
1495 pa->privdb_val = AST_PRIVACY_ALLOW;
1496 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
1497 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
1500 if (pa->privdb_val == AST_PRIVACY_DENY) {
1501 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
1502 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
1504 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
1505 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
1506 return 0; /* Is this right? */
1507 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
1508 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
1509 return 0; /* is this right??? */
1510 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
1511 /* Get the user's intro, store it in priv-callerintros/$CID,
1512 unless it is already there-- this should be done before the
1513 call is actually dialed */
1515 /* make sure the priv-callerintros dir actually exists */
1516 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
1517 if ((res = ast_mkdir(pa->privintro, 0755))) {
1518 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
1522 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
1523 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
1524 /* the DELUX version of this code would allow this caller the
1525 option to hear and retape their previously recorded intro.
1528 int duration; /* for feedback from play_and_wait */
1529 /* the file doesn't exist yet. Let the caller submit his
1530 vocal intro for posterity */
1531 /* priv-recordintro script:
1533 "At the tone, please say your name:"
1536 silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
1538 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "gsm", &duration, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
1539 /* don't think we'll need a lock removed, we took care of
1540 conflicts by naming the pa.privintro file */
1542 /* Delete the file regardless since they hung up during recording */
1543 ast_filedelete(pa->privintro, NULL);
1544 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
1545 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
1547 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
1550 if (!ast_streamfile(chan, "vm-dialout", chan->language) )
1551 ast_waitstream(chan, "");
1554 return 1; /* success */
1557 static void end_bridge_callback(void *data)
1561 struct ast_channel *chan = data;
1569 ast_channel_lock(chan);
1570 if (chan->cdr->answer.tv_sec) {
1571 snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->answer.tv_sec);
1572 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
1575 if (chan->cdr->start.tv_sec) {
1576 snprintf(buf, sizeof(buf), "%ld", end - chan->cdr->start.tv_sec);
1577 pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
1579 ast_channel_unlock(chan);
1582 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
1583 bconfig->end_bridge_callback_data = originator;
1586 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
1588 struct ast_tone_zone_sound *ts = NULL;
1590 const char *str = data;
1592 if (ast_strlen_zero(str)) {
1593 ast_debug(1,"Nothing to play\n");
1597 ts = ast_get_indication_tone(chan->zone, str);
1599 if (ts && ts->data[0]) {
1600 res = ast_playtones_start(chan, 0, ts->data, 0);
1606 ts = ast_tone_zone_sound_unref(ts);
1610 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
1616 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
1618 int res = -1; /* default: error */
1619 char *rest, *cur; /* scan the list of destinations */
1620 struct chanlist *outgoing = NULL; /* list of destinations */
1621 struct ast_channel *peer;
1622 int to; /* timeout */
1623 struct cause_args num = { chan, 0, 0, 0 };
1626 char cidname[AST_MAX_EXTENSION] = "";
1628 struct ast_bridge_config config = { { 0, } };
1629 struct timeval calldurationlimit = { 0, };
1630 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
1631 struct privacy_args pa = {
1634 .status = "INVALIDARGS",
1636 int sentringing = 0, moh = 0;
1637 const char *outbound_group = NULL;
1641 int delprivintro = 0;
1642 AST_DECLARE_APP_ARGS(args,
1644 AST_APP_ARG(timeout);
1645 AST_APP_ARG(options);
1648 struct ast_flags64 opts = { 0, };
1649 char *opt_args[OPT_ARG_ARRAY_SIZE];
1650 struct ast_datastore *datastore = NULL;
1651 int fulldial = 0, num_dialed = 0;
1653 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
1654 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
1655 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
1656 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
1657 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
1658 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
1660 if (ast_strlen_zero(data)) {
1661 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1662 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1666 parse = ast_strdupa(data);
1668 AST_STANDARD_APP_ARGS(args, parse);
1670 if (!ast_strlen_zero(args.options) &&
1671 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
1672 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1676 if (ast_strlen_zero(args.peers)) {
1677 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
1678 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1682 if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
1683 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
1685 if (delprivintro < 0 || delprivintro > 1) {
1686 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
1691 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
1692 opt_args[OPT_ARG_RINGBACK] = NULL;
1695 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
1696 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
1697 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
1700 if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
1701 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
1702 if (!calldurationlimit.tv_sec) {
1703 ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
1704 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
1707 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
1710 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
1711 dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
1712 dtmfcalled = strsep(&dtmf_progress, ":");
1713 dtmfcalling = strsep(&dtmf_progress, ":");
1716 if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
1717 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
1721 if (ast_test_flag64(&opts, OPT_RESETCDR) && chan->cdr)
1722 ast_cdr_reset(chan->cdr, NULL);
1723 if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
1724 opt_args[OPT_ARG_PRIVACY] = ast_strdupa(chan->exten);
1726 if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
1727 res = setup_privacy_args(&pa, &opts, opt_args, chan);
1730 res = -1; /* reset default */
1733 if (ast_test_flag64(&opts, OPT_DTMF_EXIT) || ast_test_flag64(&opts, OPT_CALLER_HANGUP)) {
1734 __ast_answer(chan, 0, 0);
1740 /* If a channel group has been specified, get it for use when we create peer channels */
1742 ast_channel_lock(chan);
1743 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
1744 outbound_group = ast_strdupa(outbound_group);
1745 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
1746 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
1747 outbound_group = ast_strdupa(outbound_group);
1749 ast_channel_unlock(chan);
1750 ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_IGNORE_CONNECTEDLINE |
1751 OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB);
1753 /* loop through the list of dial destinations */
1755 while ((cur = strsep(&rest, "&")) ) {
1756 struct chanlist *tmp;
1757 struct ast_channel *tc; /* channel for this destination */
1758 /* Get a technology/[device:]number pair */
1760 char *interface = ast_strdupa(number);
1761 char *tech = strsep(&number, "/");
1762 /* find if we already dialed this interface */
1763 struct ast_dialed_interface *di;
1764 AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
1767 ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
1770 if (!(tmp = ast_calloc(1, sizeof(*tmp))))
1773 ast_copy_flags64(tmp, &opts,
1774 OPT_CANCEL_ELSEWHERE |
1775 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
1776 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
1777 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
1778 OPT_CALLEE_PARK | OPT_CALLER_PARK |
1779 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
1780 OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
1781 ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
1783 ast_copy_string(numsubst, number, sizeof(numsubst));
1784 /* Request the peer */
1786 ast_channel_lock(chan);
1787 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL);
1788 /* If the incoming channel has previously had connected line information
1789 * set on it (perhaps through the CONNECTED_LINE dialplan function) then
1790 * seed the calllist's connected line information with this previously
1793 if (chan->connected.id.number) {
1794 ast_party_connected_line_copy(&tmp->connected, &chan->connected);
1796 ast_channel_unlock(chan);
1799 dialed_interfaces = datastore->data;
1801 if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) {
1802 ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n");
1807 datastore->inheritance = DATASTORE_INHERIT_FOREVER;
1809 if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
1810 ast_datastore_free(datastore);
1815 datastore->data = dialed_interfaces;
1816 AST_LIST_HEAD_INIT(dialed_interfaces);
1818 ast_channel_lock(chan);
1819 ast_channel_datastore_add(chan, datastore);
1820 ast_channel_unlock(chan);
1823 AST_LIST_LOCK(dialed_interfaces);
1824 AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
1825 if (!strcasecmp(di->interface, interface)) {
1826 ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n",
1831 AST_LIST_UNLOCK(dialed_interfaces);
1839 /* It is always ok to dial a Local interface. We only keep track of
1840 * which "real" interfaces have been dialed. The Local channel will
1841 * inherit this list so that if it ends up dialing a real interface,
1842 * it won't call one that has already been called. */
1843 if (strcasecmp(tech, "Local")) {
1844 if (!(di = ast_calloc(1, sizeof(*di) + strlen(interface)))) {
1845 AST_LIST_UNLOCK(dialed_interfaces);
1849 strcpy(di->interface, interface);
1851 AST_LIST_LOCK(dialed_interfaces);
1852 AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
1853 AST_LIST_UNLOCK(dialed_interfaces);
1856 tc = ast_request(tech, chan->nativeformats, chan, numsubst, &cause);
1858 /* If we can't, just go on to the next call */
1859 ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
1860 tech, cause, ast_cause2str(cause));
1861 handle_cause(cause, &num);
1862 if (!rest) /* we are on the last destination */
1863 chan->hangupcause = cause;
1867 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
1869 ast_channel_lock(tc);
1870 while (ast_channel_trylock(chan)) {
1871 CHANNEL_DEADLOCK_AVOIDANCE(tc);
1873 /* Setup outgoing SDP to match incoming one */
1874 if (!outgoing && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
1875 ast_rtp_instance_early_bridge_make_compatible(tc, chan);
1878 /* Inherit specially named variables from parent channel */
1879 ast_channel_inherit_variables(chan, tc);
1880 ast_channel_datastore_inherit(chan, tc);
1882 tc->appl = "AppDial";
1883 tc->data = "(Outgoing Line)";
1884 memset(&tc->whentohangup, 0, sizeof(tc->whentohangup));
1886 /* If the new channel has no callerid, try to guess what it should be */
1887 if (ast_strlen_zero(tc->cid.cid_num)) {
1888 if (!ast_strlen_zero(chan->connected.id.number)) {
1889 ast_set_callerid(tc, chan->connected.id.number, chan->connected.id.name, chan->connected.ani);
1890 } else if (!ast_strlen_zero(chan->cid.cid_dnid)) {
1891 ast_set_callerid(tc, chan->cid.cid_dnid, NULL, NULL);
1892 } else if (!ast_strlen_zero(S_OR(chan->macroexten, chan->exten))) {
1893 ast_set_callerid(tc, S_OR(chan->macroexten, chan->exten), NULL, NULL);
1895 ast_set_flag64(tmp, DIAL_NOCONNECTEDLINE);
1898 ast_connected_line_copy_from_caller(&tc->connected, &chan->cid);
1900 S_REPLACE(tc->cid.cid_rdnis, ast_strdup(chan->cid.cid_rdnis));
1901 ast_party_redirecting_copy(&tc->redirecting, &chan->redirecting);
1903 tc->cid.cid_tns = chan->cid.cid_tns;
1905 if (!ast_strlen_zero(chan->accountcode)) {
1906 ast_string_field_set(tc, peeraccount, chan->accountcode);
1908 tc->cdrflags = chan->cdrflags;
1909 if (ast_strlen_zero(tc->musicclass))
1910 ast_string_field_set(tc, musicclass, chan->musicclass);
1912 /* Pass ADSI CPE and transfer capability */
1913 tc->adsicpe = chan->adsicpe;
1914 tc->transfercapability = chan->transfercapability;
1916 /* If we have an outbound group, set this peer channel to it */
1918 ast_app_group_set_channel(tc, outbound_group);
1919 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
1920 if (ast_test_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE))
1921 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
1923 /* Check if we're forced by configuration */
1924 if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
1925 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
1928 /* Inherit context and extension */
1929 ast_string_field_set(tc, dialcontext, ast_strlen_zero(chan->macrocontext) ? chan->context : chan->macrocontext);
1930 if (!ast_strlen_zero(chan->macroexten))
1931 ast_copy_string(tc->exten, chan->macroexten, sizeof(tc->exten));
1933 ast_copy_string(tc->exten, chan->exten, sizeof(tc->exten));
1935 ast_channel_unlock(tc);
1936 res = ast_call(tc, numsubst, 0); /* Place the call, but don't wait on the answer */
1938 /* Save the info in cdr's that we called them */
1940 ast_cdr_setdestchan(chan->cdr, tc->name);
1942 /* check the results of ast_call */
1944 /* Again, keep going even if there's an error */
1945 ast_debug(1, "ast call on peer returned %d\n", res);
1946 ast_verb(3, "Couldn't call %s\n", numsubst);
1947 if (tc->hangupcause) {
1948 chan->hangupcause = tc->hangupcause;
1950 ast_channel_unlock(chan);
1956 const char *tmpexten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
1957 senddialevent(chan, tc, numsubst);
1958 ast_verb(3, "Called %s\n", numsubst);
1959 ast_channel_unlock(chan);
1960 if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1961 ast_set_callerid(tc, tmpexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
1964 /* Put them in the list of outgoing thingies... We're ready now.
1965 XXX If we're forcibly removed, these outgoing calls won't get
1967 ast_set_flag64(tmp, DIAL_STILLGOING);
1969 tmp->next = outgoing;
1971 /* If this line is up, don't try anybody else */
1972 if (outgoing->chan->_state == AST_STATE_UP)
1976 if (ast_strlen_zero(args.timeout)) {
1979 to = atoi(args.timeout);
1983 ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
1989 strcpy(pa.status, "CHANUNAVAIL");
1990 if (fulldial == num_dialed) {
1995 /* Our status will at least be NOANSWER */
1996 strcpy(pa.status, "NOANSWER");
1997 if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
1999 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2000 char *original_moh = ast_strdupa(chan->musicclass);
2001 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
2002 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2003 ast_string_field_set(chan, musicclass, original_moh);
2005 ast_moh_start(chan, NULL, NULL);
2007 ast_indicate(chan, AST_CONTROL_PROGRESS);
2008 } else if (ast_test_flag64(outgoing, OPT_RINGBACK)) {
2009 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2010 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2011 ast_indicate(chan, AST_CONTROL_RINGING);
2014 ast_indicate(chan, AST_CONTROL_PROGRESS);
2017 ast_indicate(chan, AST_CONTROL_RINGING);
2023 peer = wait_for_answer(chan, outgoing, &to, peerflags, opt_args, &pa, &num, &result, dtmf_progress);
2025 /* The ast_channel_datastore_remove() function could fail here if the
2026 * datastore was moved to another channel during a masquerade. If this is
2027 * the case, don't free the datastore here because later, when the channel
2028 * to which the datastore was moved hangs up, it will attempt to free this
2029 * datastore again, causing a crash
2031 if (!ast_channel_datastore_remove(chan, datastore))
2032 ast_datastore_free(datastore);
2036 } else if (to) { /* Musta gotten hung up */
2038 } else { /* Nobody answered, next please? */
2042 /* SIP, in particular, sends back this error code to indicate an
2043 * overlap dialled number needs more digits. */
2044 if (chan->hangupcause == AST_CAUSE_INVALID_NUMBER_FORMAT) {
2045 res = AST_PBX_INCOMPLETE;
2048 /* almost done, although the 'else' block is 400 lines */
2052 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER))
2055 strcpy(pa.status, "ANSWER");
2056 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2057 /* Ah ha! Someone answered within the desired timeframe. Of course after this
2058 we will always return with -1 so that it is hung up properly after the
2060 hanguptree(outgoing, peer, 1);
2062 /* If appropriate, log that we have a destination channel and set the answer time */
2064 ast_cdr_setdestchan(chan->cdr, peer->name);
2065 ast_cdr_setanswer(chan->cdr, peer->cdr->answer);
2068 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", peer->name);
2070 ast_channel_lock(peer);
2071 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
2074 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
2075 ast_channel_unlock(peer);
2077 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
2078 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
2079 ast_channel_sendurl( peer, args.url );
2081 if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
2082 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
2087 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
2091 struct ast_channel *chans[2];
2092 struct ast_channel *active_chan;
2097 /* we need to stream the announcment while monitoring the caller for a hangup */
2099 /* stream the file */
2100 res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
2103 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
2106 ast_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
2107 while (peer->stream) {
2110 ms = ast_sched_wait(peer->sched);
2112 if (ms < 0 && !peer->timingfunc) {
2113 ast_stopstream(peer);
2119 active_chan = ast_waitfor_n(chans, 2, &ms);
2121 struct ast_frame *fr = ast_read(active_chan);
2127 switch(fr->frametype) {
2128 case AST_FRAME_DTMF_END:
2129 digit = fr->subclass.integer;
2130 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
2131 ast_stopstream(peer);
2132 res = ast_senddigit(chan, digit, 0);
2135 case AST_FRAME_CONTROL:
2136 switch (fr->subclass.integer) {
2137 case AST_CONTROL_HANGUP:
2147 /* Ignore all others */
2152 ast_sched_runq(peer->sched);
2154 ast_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
2157 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
2158 replace_macro_delimiter(opt_args[OPT_ARG_GOTO]);
2159 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
2160 /* peer goes to the same context and extension as chan, so just copy info from chan*/
2161 ast_copy_string(peer->context, chan->context, sizeof(peer->context));
2162 ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
2163 peer->priority = chan->priority + 2;
2164 ast_pbx_start(peer);
2165 hanguptree(outgoing, NULL, ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0);
2172 if (ast_test_flag64(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
2173 struct ast_app *theapp;
2174 const char *macro_result;
2176 res = ast_autoservice_start(chan);
2178 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
2182 theapp = pbx_findapp("Macro");
2184 if (theapp && !res) { /* XXX why check res here ? */
2185 /* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
2186 ast_copy_string(peer->context, chan->context, sizeof(peer->context));
2187 ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
2189 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
2190 res = pbx_exec(peer, theapp, opt_args[OPT_ARG_CALLEE_MACRO]);
2191 ast_debug(1, "Macro exited with status %d\n", res);
2194 ast_log(LOG_ERROR, "Could not find application Macro\n");
2198 if (ast_autoservice_stop(chan) < 0) {
2202 ast_channel_lock(peer);
2204 if (!res && (macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
2205 char *macro_transfer_dest;
2207 if (!strcasecmp(macro_result, "BUSY")) {
2208 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
2209 ast_set_flag64(peerflags, OPT_GO_ON);
2211 } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
2212 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
2213 ast_set_flag64(peerflags, OPT_GO_ON);
2215 } else if (!strcasecmp(macro_result, "CONTINUE")) {
2216 /* hangup peer and keep chan alive assuming the macro has changed
2217 the context / exten / priority or perhaps
2218 the next priority in the current exten is desired.
2220 ast_set_flag64(peerflags, OPT_GO_ON);
2222 } else if (!strcasecmp(macro_result, "ABORT")) {
2223 /* Hangup both ends unless the caller has the g flag */
2225 } else if (!strncasecmp(macro_result, "GOTO:", 5) && (macro_transfer_dest = ast_strdupa(macro_result + 5))) {
2227 /* perform a transfer to a new extension */
2228 if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
2229 replace_macro_delimiter(macro_transfer_dest);
2230 if (!ast_parseable_goto(chan, macro_transfer_dest))
2231 ast_set_flag64(peerflags, OPT_GO_ON);
2236 ast_channel_unlock(peer);
2239 if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
2240 struct ast_app *theapp;
2241 const char *gosub_result;
2242 char *gosub_args, *gosub_argstart;
2245 res9 = ast_autoservice_start(chan);
2247 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
2251 theapp = pbx_findapp("Gosub");
2253 if (theapp && !res9) {
2254 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
2256 /* Set where we came from */
2257 ast_copy_string(peer->context, "app_dial_gosub_virtual_context", sizeof(peer->context));
2258 ast_copy_string(peer->exten, "s", sizeof(peer->exten));
2261 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
2262 if (gosub_argstart) {
2263 *gosub_argstart = 0;
2264 if (asprintf(&gosub_args, "%s,s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], gosub_argstart + 1) < 0) {
2265 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
2268 *gosub_argstart = ',';
2270 if (asprintf(&gosub_args, "%s,s,1", opt_args[OPT_ARG_CALLEE_GOSUB]) < 0) {
2271 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
2277 res9 = pbx_exec(peer, theapp, gosub_args);
2279 struct ast_pbx_args args;
2280 /* A struct initializer fails to compile for this case ... */
2281 memset(&args, 0, sizeof(args));
2282 args.no_hangup_chan = 1;
2283 ast_pbx_run_args(peer, &args);
2285 ast_free(gosub_args);
2286 ast_debug(1, "Gosub exited with status %d\n", res9);
2288 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
2292 ast_log(LOG_ERROR, "Could not find application Gosub\n");
2296 if (ast_autoservice_stop(chan) < 0) {
2297 ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n");
2301 ast_channel_lock(peer);
2303 if (!res9 && (gosub_result = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
2304 char *gosub_transfer_dest;
2306 if (!strcasecmp(gosub_result, "BUSY")) {
2307 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
2308 ast_set_flag64(peerflags, OPT_GO_ON);
2310 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
2311 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
2312 ast_set_flag64(peerflags, OPT_GO_ON);
2314 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
2315 /* hangup peer and keep chan alive assuming the macro has changed
2316 the context / exten / priority or perhaps
2317 the next priority in the current exten is desired.
2319 ast_set_flag64(peerflags, OPT_GO_ON);
2321 } else if (!strcasecmp(gosub_result, "ABORT")) {
2322 /* Hangup both ends unless the caller has the g flag */
2324 } else if (!strncasecmp(gosub_result, "GOTO:", 5) && (gosub_transfer_dest = ast_strdupa(gosub_result + 5))) {
2326 /* perform a transfer to a new extension */
2327 if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
2328 replace_macro_delimiter(gosub_transfer_dest);
2329 if (!ast_parseable_goto(chan, gosub_transfer_dest))
2330 ast_set_flag64(peerflags, OPT_GO_ON);
2335 ast_channel_unlock(peer);
2339 if (!ast_tvzero(calldurationlimit)) {
2340 struct timeval whentohangup = calldurationlimit;
2341 peer->whentohangup = ast_tvadd(ast_tvnow(), whentohangup);
2343 if (!ast_strlen_zero(dtmfcalled)) {
2344 ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
2345 res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
2347 if (!ast_strlen_zero(dtmfcalling)) {
2348 ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
2349 res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
2353 if (res) { /* some error */
2356 if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
2357 ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
2358 if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
2359 ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
2360 if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
2361 ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
2362 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
2363 ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
2364 if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
2365 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
2366 if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
2367 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
2368 if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
2369 ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
2370 if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
2371 ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
2372 if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
2373 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
2374 if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
2375 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
2376 if (ast_test_flag64(peerflags, OPT_GO_ON))
2377 ast_set_flag(&(config.features_caller), AST_FEATURE_NO_H_EXTEN);
2379 config.end_bridge_callback = end_bridge_callback;
2380 config.end_bridge_callback_data = chan;
2381 config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
2386 } else if (sentringing) {
2388 ast_indicate(chan, -1);
2390 /* Be sure no generators are left on it */
2391 ast_deactivate_generator(chan);
2392 /* Make sure channels are compatible */
2393 res = ast_channel_make_compatible(chan, peer);
2395 ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", chan->name, peer->name);
2401 struct oprmode oprmode;
2403 oprmode.peer = peer;
2404 oprmode.mode = opermode;
2406 ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
2408 res = ast_bridge_call(chan, peer, &config);
2411 strcpy(peer->context, chan->context);
2413 if (ast_test_flag64(&opts, OPT_PEER_H) && ast_exists_extension(peer, peer->context, "h", 1, peer->cid.cid_num)) {
2418 strcpy(peer->exten, "h");
2420 autoloopflag = ast_test_flag(peer, AST_FLAG_IN_AUTOLOOP); /* save value to restore at the end */
2421 ast_set_flag(peer, AST_FLAG_IN_AUTOLOOP);
2423 while ((res9 = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num, &found, 1)) == 0)
2426 if (found && res9) {
2427 /* Something bad happened, or a hangup has been requested. */
2428 ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
2429 ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
2431 ast_set2_flag(peer, autoloopflag, AST_FLAG_IN_AUTOLOOP); /* set it back the way it was */
2433 if (!ast_check_hangup(peer) && ast_test_flag64(&opts, OPT_CALLEE_GO_ON)) {
2434 if(!ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GO_ON])) {
2435 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_GO_ON]);
2436 ast_parseable_goto(peer, opt_args[OPT_ARG_CALLEE_GO_ON]);
2439 res = ast_goto_if_exists(peer, chan->context, chan->exten, (chan->priority) + 1);
2440 if (res == AST_PBX_GOTO_FAILED) {
2445 ast_pbx_start(peer);
2447 if (!ast_check_hangup(chan))
2448 chan->hangupcause = peer->hangupcause;
2456 } else if (sentringing) {
2458 ast_indicate(chan, -1);
2461 if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
2462 ast_filedelete(pa.privintro, NULL);
2463 if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
2464 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
2466 ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
2470 ast_channel_early_bridge(chan, NULL);
2471 hanguptree(outgoing, NULL, 0); /* In this case, there's no answer anywhere */
2472 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2473 senddialendevent(chan, pa.status);
2474 ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
2476 if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
2477 if (!ast_tvzero(calldurationlimit))
2478 memset(&chan->whentohangup, 0, sizeof(chan->whentohangup));
2483 if (config.warning_sound) {
2484 ast_free((char *)config.warning_sound);
2486 if (config.end_sound) {
2487 ast_free((char *)config.end_sound);
2489 if (config.start_sound) {
2490 ast_free((char *)config.start_sound);
2495 static int dial_exec(struct ast_channel *chan, const char *data)
2497 struct ast_flags64 peerflags;
2499 memset(&peerflags, 0, sizeof(peerflags));
2501 return dial_exec_full(chan, data, &peerflags, NULL);
2504 static int retrydial_exec(struct ast_channel *chan, const char *data)
2507 const char *context = NULL;
2508 int sleepms = 0, loops = 0, res = -1;
2509 struct ast_flags64 peerflags = { 0, };
2510 AST_DECLARE_APP_ARGS(args,
2511 AST_APP_ARG(announce);
2513 AST_APP_ARG(retries);
2514 AST_APP_ARG(dialdata);
2517 if (ast_strlen_zero(data)) {
2518 ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
2522 parse = ast_strdupa(data);
2523 AST_STANDARD_APP_ARGS(args, parse);
2525 if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
2528 if (!ast_strlen_zero(args.retries)) {
2529 loops = atoi(args.retries);
2532 if (!args.dialdata) {
2533 ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
2541 loops = -1; /* run forever */
2543 ast_channel_lock(chan);
2544 context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
2545 context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
2546 ast_channel_unlock(chan);
2552 chan->data = "Retrying";
2553 if (ast_test_flag(chan, AST_FLAG_MOH))
2556 res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
2561 if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
2562 if (!ast_strlen_zero(args.announce)) {
2563 if (ast_fileexists(args.announce, NULL, chan->language) > 0) {
2564 if (!(res = ast_streamfile(chan, args.announce, chan->language)))
2565 ast_waitstream(chan, AST_DIGIT_ANY);
2567 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
2569 if (!res && sleepms) {
2570 if (!ast_test_flag(chan, AST_FLAG_MOH))
2571 ast_moh_start(chan, NULL, NULL);
2572 res = ast_waitfordigit(chan, sleepms);
2575 if (!ast_strlen_zero(args.announce)) {
2576 if (ast_fileexists(args.announce, NULL, chan->language) > 0) {
2577 if (!(res = ast_streamfile(chan, args.announce, chan->language)))
2578 res = ast_waitstream(chan, "");
2580 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);