Asterisk - The Open Source Telephony Project GIT-master-91e368c
app_dial.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2012, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
22 *
23 * \author Mark Spencer <markster@digium.com>
24 *
25 * \ingroup applications
26 */
27
28/*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32
33#include "asterisk.h"
34
35#include <sys/time.h>
36#include <signal.h>
37#include <sys/stat.h>
38#include <netinet/in.h>
39
40#include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
41#include "asterisk/lock.h"
42#include "asterisk/file.h"
43#include "asterisk/channel.h"
44#include "asterisk/pbx.h"
45#include "asterisk/module.h"
46#include "asterisk/translate.h"
47#include "asterisk/say.h"
48#include "asterisk/config.h"
49#include "asterisk/features.h"
51#include "asterisk/callerid.h"
52#include "asterisk/utils.h"
53#include "asterisk/app.h"
54#include "asterisk/causes.h"
55#include "asterisk/rtp_engine.h"
56#include "asterisk/manager.h"
57#include "asterisk/privacy.h"
59#include "asterisk/dsp.h"
60#include "asterisk/aoc.h"
61#include "asterisk/ccss.h"
63#include "asterisk/framehook.h"
64#include "asterisk/dial.h"
69#include "asterisk/stream.h"
70
71/*** DOCUMENTATION
72 <application name="Dial" language="en_US">
73 <synopsis>
74 Attempt to connect to another device or endpoint and bridge the call.
75 </synopsis>
76 <syntax>
77 <parameter name="Technology/Resource" required="false" argsep="&amp;">
78 <argument name="Technology/Resource" required="true">
79 <para>Specification of the device(s) to dial. These must be in the format of
80 <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
81 represents a particular channel driver, and <replaceable>Resource</replaceable>
82 represents a resource available to that particular channel driver.</para>
83 </argument>
84 <argument name="Technology2/Resource2" required="false" multiple="true">
85 <para>Optional extra devices to dial in parallel</para>
86 <para>If you need more than one enter them as
87 Technology2/Resource2&amp;Technology3/Resource3&amp;.....</para>
88 </argument>
89 <xi:include xpointer="xpointer(/docs/info[@name='Dial_Resource'])" />
90 </parameter>
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>
94 </parameter>
95 <parameter name="options" required="false">
96 <optionlist>
97 <option name="A" argsep=":">
98 <argument name="x">
99 <para>The file to play to the called party</para>
100 </argument>
101 <argument name="y">
102 <para>The file to play to the calling party</para>
103 </argument>
104 <para>Play an announcement to the called and/or calling parties, where <replaceable>x</replaceable>
105 is the prompt to be played to the called party and <replaceable>y</replaceable> is the prompt
106 to be played to the caller. The files may be different and will be played to each party
107 simultaneously.</para>
108 </option>
109 <option name="a">
110 <para>Immediately answer the calling channel when the called channel answers in
111 all cases. Normally, the calling channel is answered when the called channel
112 answers, but when options such as <literal>A()</literal> and
113 <literal>M()</literal> are used, the calling channel is
114 not answered until all actions on the called channel (such as playing an
115 announcement) are completed. This option can be used to answer the calling
116 channel before doing anything on the called channel. You will rarely need to use
117 this option, the default behavior is adequate in most cases.</para>
118 </option>
119 <option name="b" argsep="^">
120 <para>Before initiating an outgoing call, <literal>Gosub</literal> to the specified
121 location using the newly created channel. The <literal>Gosub</literal> will be
122 executed for each destination channel.</para>
123 <argument name="context" required="false" />
124 <argument name="exten" required="false" />
125 <argument name="priority" required="true" hasparams="optional" argsep="^">
126 <argument name="arg1" multiple="true" required="true" />
127 <argument name="argN" />
128 </argument>
129 </option>
130 <option name="B" argsep="^">
131 <para>Before initiating the outgoing call(s), <literal>Gosub</literal> to the
132 specified location using the current channel.</para>
133 <argument name="context" required="false" />
134 <argument name="exten" required="false" />
135 <argument name="priority" required="true" hasparams="optional" argsep="^">
136 <argument name="arg1" multiple="true" required="true" />
137 <argument name="argN" />
138 </argument>
139 </option>
140 <option name="C">
141 <para>Reset the call detail record (CDR) for this call.</para>
142 </option>
143 <option name="c">
144 <para>If the Dial() application cancels this call, always set
145 <variable>HANGUPCAUSE</variable> to 'answered elsewhere'</para>
146 </option>
147 <option name="d">
148 <para>Allow the calling user to dial a 1 digit extension while waiting for
149 a call to be answered. Exit to that extension if it exists in the
150 current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
151 if it exists.</para>
152 <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
153 connected. If you wish to use this option with these phones, you
154 can use the <literal>Answer</literal> application before dialing.</para>
155 </option>
156 <option name="D" argsep=":">
157 <argument name="called" />
158 <argument name="calling" />
159 <argument name="progress" />
160 <argument name="mfprogress" />
161 <argument name="mfwink" />
162 <argument name="sfprogress" />
163 <argument name="sfwink" />
164 <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
165 party has answered, but before the call gets bridged. The
166 <replaceable>called</replaceable> DTMF string is sent to the called party, and the
167 <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
168 can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
169 to the called party immediately after receiving a <literal>PROGRESS</literal> message.</para>
170 <para>See <literal>SendDTMF</literal> for valid digits.</para>
171 <para>If <replaceable>mfprogress</replaceable> is specified, its MF is sent
172 to the called party immediately after receiving a <literal>PROGRESS</literal> message.
173 If <replaceable>mfwink</replaceable> is specified, its MF is sent
174 to the called party immediately after receiving a <literal>WINK</literal> message.</para>
175 <para>See <literal>SendMF</literal> for valid digits.</para>
176 <para>If <replaceable>sfprogress</replaceable> is specified, its SF is sent
177 to the called party immediately after receiving a <literal>PROGRESS</literal> message.
178 If <replaceable>sfwink</replaceable> is specified, its SF is sent
179 to the called party immediately after receiving a <literal>WINK</literal> message.</para>
180 <para>See <literal>SendSF</literal> for valid digits.</para>
181 </option>
182 <option name="E">
183 <para>Enable echoing of sent MF or SF digits back to caller (e.g. "hearpulsing").
184 Used in conjunction with the D option.</para>
185 </option>
186 <option name="e">
187 <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
188 </option>
189 <option name="f">
190 <argument name="x" required="false" />
191 <para>If <replaceable>x</replaceable> is not provided, force the CallerID sent on a call-forward or
192 deflection to the dialplan extension of this <literal>Dial()</literal> using a dialplan <literal>hint</literal>.
193 For example, some PSTNs do not allow CallerID to be set to anything
194 other than the numbers assigned to you.
195 If <replaceable>x</replaceable> is provided, force the CallerID sent to <replaceable>x</replaceable>.</para>
196 </option>
197 <option name="F" argsep="^">
198 <argument name="context" required="false" />
199 <argument name="exten" required="false" />
200 <argument name="priority" required="true" />
201 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party
202 to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
203 <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
204 prefixed with one or two underbars ('_').</para>
205 </option>
206 <option name="F">
207 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party to the next priority of the current extension
208 and <emphasis>start</emphasis> execution at that location.</para>
209 <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
210 prefixed with one or two underbars ('_').</para>
211 <para>NOTE: Using this option from a GoSub() might not make sense as there would be no return points.</para>
212 </option>
213 <option name="g">
214 <para>Proceed with dialplan execution at the next priority in the current extension if the
215 destination channel hangs up.</para>
216 </option>
217 <option name="G" argsep="^">
218 <argument name="context" required="false" />
219 <argument name="exten" required="false" />
220 <argument name="priority" required="true" />
221 <para>If the call is answered, transfer the calling party to
222 the specified <replaceable>priority</replaceable> and the called party to the specified
223 <replaceable>priority</replaceable> plus one.</para>
224 <para>NOTE: You cannot use any additional action post answer options in conjunction with this option.</para>
225 </option>
226 <option name="h">
227 <para>Allow the called party to hang up by sending the DTMF sequence
228 defined for disconnect in <filename>features.conf</filename>.</para>
229 </option>
230 <option name="H">
231 <para>Allow the calling party to hang up by sending the DTMF sequence
232 defined for disconnect in <filename>features.conf</filename>.</para>
233 <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
234 connected. If you wish to allow DTMF disconnect before the dialed
235 party answers with these phones, you can use the <literal>Answer</literal>
236 application before dialing.</para>
237 </option>
238 <option name="i">
239 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
240 </option>
241 <option name="I">
242 <para>Asterisk will ignore any connected line update requests or any redirecting party
243 update requests it may receive on this dial attempt.</para>
244 </option>
245 <option name="k">
246 <para>Allow the called party to enable parking of the call by sending
247 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
248 </option>
249 <option name="K">
250 <para>Allow the calling party to enable parking of the call by sending
251 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
252 </option>
253 <option name="L" argsep=":">
254 <argument name="x" required="true">
255 <para>Maximum call time, in milliseconds</para>
256 </argument>
257 <argument name="y">
258 <para>Warning time, in milliseconds</para>
259 </argument>
260 <argument name="z">
261 <para>Repeat time, in milliseconds</para>
262 </argument>
263 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
264 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
265 <para>This option is affected by the following variables:</para>
266 <variablelist>
267 <variable name="LIMIT_PLAYAUDIO_CALLER">
268 <value name="yes" default="true" />
269 <value name="no" />
270 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
271 </variable>
272 <variable name="LIMIT_PLAYAUDIO_CALLEE">
273 <value name="yes" />
274 <value name="no" default="true"/>
275 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
276 </variable>
277 <variable name="LIMIT_TIMEOUT_FILE">
278 <value name="filename"/>
279 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
280 If not set, the time remaining will be announced.</para>
281 </variable>
282 <variable name="LIMIT_CONNECT_FILE">
283 <value name="filename"/>
284 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
285 If not set, the time remaining will be announced.</para>
286 </variable>
287 <variable name="LIMIT_WARNING_FILE">
288 <value name="filename"/>
289 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
290 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
291 </variable>
292 </variablelist>
293 </option>
294 <option name="m">
295 <argument name="class" required="false"/>
296 <para>Provide hold music to the calling party until a requested
297 channel answers. A specific music on hold <replaceable>class</replaceable>
298 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
299 </option>
300 <option name="n">
301 <argument name="delete">
302 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
303 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
304 yet answered.</para>
305 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
306 always be deleted.</para>
307 </argument>
308 <para>This option is a modifier for the call screening/privacy mode. (See the
309 <literal>p</literal> and <literal>P</literal> options.) It specifies
310 that no introductions are to be saved in the <directory>priv-callerintros</directory>
311 directory.</para>
312 </option>
313 <option name="N">
314 <para>This option is a modifier for the call screening/privacy mode. It specifies
315 that if CallerID is present, do not screen the call.</para>
316 </option>
317 <option name="o">
318 <argument name="x" required="false" />
319 <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
320 <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
321 This was the behavior of Asterisk 1.0 and earlier.
322 If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
323 Note that <literal>o(${CALLERID(all)})</literal> is similar to option <literal>o</literal> without the parameter.</para>
324 </option>
325 <option name="O">
326 <argument name="mode">
327 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
328 the originator hanging up will cause the phone to ring back immediately.</para>
329 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
330 flashes the trunk, it will ring their phone back.</para>
331 </argument>
332 <para>Enables <emphasis>operator services</emphasis> mode. This option only
333 works when bridging a DAHDI channel to another DAHDI channel
334 only. If specified on non-DAHDI interfaces, it will be ignored.
335 When the destination answers (presumably an operator services
336 station), the originator no longer has control of their line.
337 They may hang up, but the switch will not release their line
338 until the destination party (the operator) hangs up.</para>
339 </option>
340 <option name="p">
341 <para>This option enables screening mode. This is basically Privacy mode
342 without memory.</para>
343 </option>
344 <option name="P">
345 <argument name="x" />
346 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
347 it is provided. The current extension is used if a database family/key is not specified.</para>
348 </option>
349 <option name="Q">
350 <argument name="cause" required="true"/>
351 <para>Specify the Q.850/Q.931 <replaceable>cause</replaceable> to send on
352 unanswered channels when another channel answers the call.
353 As with <literal>Hangup()</literal>, <replaceable>cause</replaceable>
354 can be a numeric cause code or a name such as
355 <literal>NO_ANSWER</literal>,
356 <literal>USER_BUSY</literal>,
357 <literal>CALL_REJECTED</literal> or
358 <literal>ANSWERED_ELSEWHERE</literal> (the default if Q isn't specified).
359 You can also specify <literal>0</literal> or <literal>NONE</literal>
360 to send no cause. See the <filename>causes.h</filename> file for the
361 full list of valid causes and names.
362 </para>
363 </option>
364 <option name="r">
365 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
366 party until the called channel has answered.</para>
367 <argument name="tone" required="false">
368 <para>Indicate progress to calling party. Send audio 'tone' from the <filename>indications.conf</filename> tonezone currently in use.</para>
369 </argument>
370 </option>
371 <option name="R">
372 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing.
373 Allow interruption of the ringback if early media is received on the channel.</para>
374 </option>
375 <option name="S">
376 <argument name="x" required="true" />
377 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
378 answered the call.</para>
379 </option>
380 <option name="s">
381 <argument name="x" required="true" />
382 <para>Force the outgoing CallerID tag parameter to be set to the string <replaceable>x</replaceable>.</para>
383 <para>Works with the <literal>f</literal> option.</para>
384 </option>
385 <option name="t">
386 <para>Allow the called party to transfer the calling party by sending the
387 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
388 transfers initiated by other methods.</para>
389 </option>
390 <option name="T">
391 <para>Allow the calling party to transfer the called party by sending the
392 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
393 transfers initiated by other methods.</para>
394 </option>
395 <option name="U" argsep="^">
396 <argument name="x" required="true">
397 <para>Name of the subroutine context to execute via <literal>Gosub</literal>.
398 The subroutine execution starts in the named context at the s exten and priority 1.</para>
399 </argument>
400 <argument name="arg" multiple="true" required="false">
401 <para>Arguments for the <literal>Gosub</literal> routine</para>
402 </argument>
403 <para>Execute via <literal>Gosub</literal> the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
404 to the calling channel. Arguments can be specified to the <literal>Gosub</literal>
405 using <literal>^</literal> as a delimiter. The <literal>Gosub</literal> routine can set the variable
406 <variable>GOSUB_RESULT</variable> to specify the following actions after the <literal>Gosub</literal> returns.</para>
407 <variablelist>
408 <variable name="GOSUB_RESULT">
409 <value name="ABORT">
410 Hangup both legs of the call.
411 </value>
412 <value name="CONGESTION">
413 Behave as if line congestion was encountered.
414 </value>
415 <value name="BUSY">
416 Behave as if a busy signal was encountered.
417 </value>
418 <value name="CONTINUE">
419 Hangup the called party and allow the calling party
420 to continue dialplan execution at the next priority.
421 </value>
422 <value name="GOTO:[[&lt;context&gt;^]&lt;exten&gt;^]&lt;priority&gt;">
423 Transfer the call to the specified destination.
424 </value>
425 </variable>
426 </variablelist>
427 <para>NOTE: You cannot use any additional action post answer options in conjunction
428 with this option. Also, pbx services are run on the <emphasis>called</emphasis> channel,
429 so you will not be able to set timeouts via the <literal>TIMEOUT()</literal> function in this routine.</para>
430 </option>
431 <option name="u">
432 <argument name = "x" required="true">
433 <para>Force the outgoing callerid presentation indicator parameter to be set
434 to one of the values passed in <replaceable>x</replaceable>:
435 <literal>allowed_not_screened</literal>
436 <literal>allowed_passed_screen</literal>
437 <literal>allowed_failed_screen</literal>
438 <literal>allowed</literal>
439 <literal>prohib_not_screened</literal>
440 <literal>prohib_passed_screen</literal>
441 <literal>prohib_failed_screen</literal>
442 <literal>prohib</literal>
443 <literal>unavailable</literal></para>
444 </argument>
445 <para>Works with the <literal>f</literal> option.</para>
446 </option>
447 <option name="w">
448 <para>Allow the called party to enable recording of the call by sending
449 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
450 </option>
451 <option name="W">
452 <para>Allow the calling party to enable recording of the call by sending
453 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
454 </option>
455 <option name="x">
456 <para>Allow the called party to enable recording of the call by sending
457 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
458 </option>
459 <option name="X">
460 <para>Allow the calling party to enable recording of the call by sending
461 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
462 </option>
463 <option name="z">
464 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
465 </option>
466 </optionlist>
467 </parameter>
468 <parameter name="URL">
469 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
470 </parameter>
471 </syntax>
472 <description>
473 <para>This application will place calls to one or more specified channels. As soon
474 as one of the requested channels answers, the originating channel will be
475 answered, if it has not already been answered. These two channels will then
476 be active in a bridged call. All other channels that were requested will then
477 be hung up.</para>
478 <para>Unless there is a timeout specified, the Dial application will wait
479 indefinitely until one of the called channels answers, the user hangs up, or
480 if all of the called channels are busy or unavailable. Dialplan execution will
481 continue if no requested channels can be called, or if the timeout expires.
482 This application will report normal termination if the originating channel
483 hangs up, or if the call is bridged and either of the parties in the bridge
484 ends the call.</para>
485 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
486 application will be put into that group (as in <literal>Set(GROUP()=...</literal>).
487 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
488 application will be put into that group (as in <literal>Set(GROUP()=...</literal>). Unlike <variable>OUTBOUND_GROUP</variable>,
489 however, the variable will be unset after use.</para>
490 <example title="Dial with 30 second timeout">
491 same => n,Dial(PJSIP/alice,30)
492 </example>
493 <example title="Parallel dial with 45 second timeout">
494 same => n,Dial(PJSIP/alice&amp;PJIP/bob,45)
495 </example>
496 <example title="Dial with 'g' continuation option">
497 same => n,Dial(PJSIP/alice,,g)
498 same => n,Log(NOTICE, Alice call result: ${DIALSTATUS})
499 </example>
500 <example title="Dial with transfer/recording features for calling party">
501 same => n,Dial(PJSIP/alice,,TX)
502 </example>
503 <example title="Dial with call length limit">
504 same => n,Dial(PJSIP/alice,,L(60000:30000:10000))
505 </example>
506 <example title="Dial alice and bob and send NO_ANSWER to bob instead of ANSWERED_ELSEWHERE when alice answers">
507 same => n,Dial(PJSIP/alice&amp;PJSIP/bob,,Q(NO_ANSWER))
508 </example>
509 <example title="Dial with pre-dial subroutines">
510 [default]
511 exten => callee_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
512 same => n,Log(NOTICE, I'm called on channel ${CHANNEL} prior to it starting the dial attempt)
513 same => n,Return()
514 exten => called_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
515 same => n,Log(NOTICE, I'm called on outbound channel ${CHANNEL} prior to it being used to dial someone)
516 same => n,Return()
517 exten => _X.,1,NoOp()
518 same => n,Dial(PJSIP/alice,,b(default^called_channel^1(my_gosub_arg1^my_gosub_arg2))B(default^callee_channel^1(my_gosub_arg1^my_gosub_arg2)))
519 same => n,Hangup()
520 </example>
521 <example title="Dial with post-answer subroutine executed on outbound channel">
522 [my_gosub_routine]
523 exten => s,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
524 same => n,Playback(hello)
525 same => n,Return()
526 [default]
527 exten => _X.,1,NoOp()
528 same => n,Dial(PJSIP/alice,,U(my_gosub_routine^my_gosub_arg1^my_gosub_arg2))
529 same => n,Hangup()
530 </example>
531 <example title="Dial into ConfBridge using 'G' option">
532 same => n,Dial(PJSIP/alice,,G(jump_to_here))
533 same => n(jump_to_here),Goto(confbridge)
534 same => n,Goto(confbridge)
535 same => n(confbridge),ConfBridge(${EXTEN})
536 </example>
537 <para>This application sets the following channel variables:</para>
538 <variablelist>
539 <variable name="DIALEDTIME">
540 <para>This is the time from dialing a channel until when it is disconnected.</para>
541 </variable>
542 <variable name="DIALEDTIME_MS">
543 <para>This is the milliseconds version of the DIALEDTIME variable.</para>
544 </variable>
545 <variable name="ANSWEREDTIME">
546 <para>This is the amount of time for actual call.</para>
547 </variable>
548 <variable name="ANSWEREDTIME_MS">
549 <para>This is the milliseconds version of the ANSWEREDTIME variable.</para>
550 </variable>
551 <variable name="RINGTIME">
552 <para>This is the time from creating the channel to the first RINGING event received. Empty if there was no ring.</para>
553 </variable>
554 <variable name="RINGTIME_MS">
555 <para>This is the milliseconds version of the RINGTIME variable.</para>
556 </variable>
557 <variable name="PROGRESSTIME">
558 <para>This is the time from creating the channel to the first PROGRESS event received. Empty if there was no such event.</para>
559 </variable>
560 <variable name="PROGRESSTIME_MS">
561 <para>This is the milliseconds version of the PROGRESSTIME variable.</para>
562 </variable>
563 <variable name="DIALEDPEERNAME">
564 <para>The name of the outbound channel that answered the call.</para>
565 </variable>
566 <variable name="DIALEDPEERNUMBER">
567 <para>The number that was dialed for the answered outbound channel.</para>
568 </variable>
569 <variable name="FORWARDERNAME">
570 <para>If a call forward occurred, the name of the forwarded channel.</para>
571 </variable>
572 <variable name="DIALSTATUS">
573 <para>This is the status of the call</para>
574 <value name="CHANUNAVAIL">
575 Either the dialed peer exists but is not currently reachable, e.g.
576 endpoint is not registered, or an attempt was made to call a
577 nonexistent location, e.g. nonexistent DNS hostname.
578 </value>
579 <value name="CONGESTION">
580 Channel or switching congestion occured when routing the call.
581 This can occur if there is a slow or no response from the remote end.
582 </value>
583 <value name="NOANSWER">
584 Called party did not answer.
585 </value>
586 <value name="BUSY">
587 The called party was busy or indicated a busy status.
588 Note that some SIP devices will respond with 486 Busy if their Do Not Disturb
589 modes are active. In this case, you can use DEVICE_STATUS to check if the
590 endpoint is actually in use, if needed.
591 </value>
592 <value name="ANSWER">
593 The call was answered.
594 Any other result implicitly indicates the call was not answered.
595 </value>
596 <value name="CANCEL">
597 Dial was cancelled before call was answered or reached some other terminating event.
598 </value>
599 <value name="DONTCALL">
600 For the Privacy and Screening Modes.
601 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
602 </value>
603 <value name="TORTURE">
604 For the Privacy and Screening Modes.
605 Will be set if the called party chooses to send the calling party to the 'torture' script.
606 </value>
607 <value name="INVALIDARGS">
608 Dial failed due to invalid syntax.
609 </value>
610 </variable>
611 </variablelist>
612 </description>
613 <see-also>
614 <ref type="application">RetryDial</ref>
615 <ref type="application">SendDTMF</ref>
616 <ref type="application">Gosub</ref>
617 </see-also>
618 </application>
619 <application name="RetryDial" language="en_US">
620 <synopsis>
621 Place a call, retrying on failure allowing an optional exit extension.
622 </synopsis>
623 <syntax>
624 <parameter name="announce" required="true">
625 <para>Filename of sound that will be played when no channel can be reached</para>
626 </parameter>
627 <parameter name="sleep" required="true">
628 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
629 </parameter>
630 <parameter name="retries" required="true">
631 <para>Number of retries</para>
632 <para>When this is reached flow will continue at the next priority in the dialplan</para>
633 </parameter>
634 <parameter name="dialargs" required="true">
635 <para>Same format as arguments provided to the Dial application</para>
636 </parameter>
637 </syntax>
638 <description>
639 <para>This application will attempt to place a call using the normal Dial application.
640 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
641 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
642 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
643 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
644 While waiting to retry a call, a 1 digit extension may be dialed. If that
645 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
646 one, The call will jump to that extension immediately.
647 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
648 to the Dial application.</para>
649 </description>
650 <see-also>
651 <ref type="application">Dial</ref>
652 </see-also>
653 </application>
654 ***/
655
656static const char app[] = "Dial";
657static const char rapp[] = "RetryDial";
658
659enum {
660 OPT_ANNOUNCE = (1 << 0),
661 OPT_RESETCDR = (1 << 1),
662 OPT_DTMF_EXIT = (1 << 2),
663 OPT_SENDDTMF = (1 << 3),
664 OPT_FORCECLID = (1 << 4),
665 OPT_GO_ON = (1 << 5),
670 OPT_MUSICBACK = (1 << 10),
674 OPT_SCREENING = (1 << 15),
675 OPT_PRIVACY = (1 << 16),
676 OPT_RINGBACK = (1 << 17),
677 OPT_DURATION_STOP = (1 << 18),
682 OPT_GOTO = (1 << 23),
683 OPT_OPERMODE = (1 << 24),
684 OPT_CALLEE_PARK = (1 << 25),
685 OPT_CALLER_PARK = (1 << 26),
687 OPT_CALLEE_GOSUB = (1 << 28),
690};
691
692/* flags are now 64 bits, so keep it up! */
693#define DIAL_STILLGOING (1LLU << 31)
694#define DIAL_NOFORWARDHTML (1LLU << 32)
695#define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
696#define OPT_CANCEL_ELSEWHERE (1LLU << 34)
697#define OPT_PEER_H (1LLU << 35)
698#define OPT_CALLEE_GO_ON (1LLU << 36)
699#define OPT_CANCEL_TIMEOUT (1LLU << 37)
700#define OPT_FORCE_CID_TAG (1LLU << 38)
701#define OPT_FORCE_CID_PRES (1LLU << 39)
702#define OPT_CALLER_ANSWER (1LLU << 40)
703#define OPT_PREDIAL_CALLEE (1LLU << 41)
704#define OPT_PREDIAL_CALLER (1LLU << 42)
705#define OPT_RING_WITH_EARLY_MEDIA (1LLU << 43)
706#define OPT_HANGUPCAUSE (1LLU << 44)
707#define OPT_HEARPULSING (1LLU << 45)
708
709enum {
729 /* note: this entry _MUST_ be the last one in the enum */
732
777
778#define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
779 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
780 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
781 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_GOSUB) && \
782 !ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \
783 ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer)))
784
785/*
786 * The list of active channels
787 */
788struct chanlist {
791 /*! Channel interface dialing string (is tech/number). (Stored in stuff[]) */
792 const char *interface;
793 /*! Channel technology name. (Stored in stuff[]) */
794 const char *tech;
795 /*! Channel device addressing. (Stored in stuff[]) */
796 const char *number;
797 /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
799 uint64_t flags;
800 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
802 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
805 /*! The interface, tech, and number strings are stuffed here. */
806 char stuff[0];
807};
808
810
811static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode);
812
813static void chanlist_free(struct chanlist *outgoing)
814{
816 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
817 ast_free(outgoing->orig_chan_name);
819}
820
821static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
822{
823 /* Hang up a tree of stuff */
824 struct chanlist *outgoing;
825
826 while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
827 /* Hangup any existing lines we have open */
828 if (outgoing->chan && (outgoing->chan != exception)) {
829 if (hangupcause >= 0) {
830 /* This is for the channel drivers */
831 ast_channel_hangupcause_set(outgoing->chan, hangupcause);
832 }
833 ast_hangup(outgoing->chan);
834 }
836 }
837}
838
839#define AST_MAX_WATCHERS 256
840
841/*
842 * argument to handle_cause() and other functions.
843 */
846 int busy;
849};
850
851static void handle_cause(int cause, struct cause_args *num)
852{
853 switch(cause) {
854 case AST_CAUSE_BUSY:
855 num->busy++;
856 break;
858 num->congestion++;
859 break;
862 num->nochan++;
863 break;
866 break;
867 default:
868 num->nochan++;
869 break;
870 }
871}
872
873static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
874{
875 char rexten[2] = { exten, '\0' };
876
877 if (context) {
878 if (!ast_goto_if_exists(chan, context, rexten, pri))
879 return 1;
880 } else {
881 if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
882 return 1;
883 }
884 return 0;
885}
886
887/* do not call with chan lock held */
888static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
889{
890 const char *context;
891 const char *exten;
892
893 ast_channel_lock(chan);
896 ast_channel_unlock(chan);
897
898 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
899}
900
901/*!
902 * helper function for wait_for_answer()
903 *
904 * \param o Outgoing call channel list.
905 * \param num Incoming call channel cause accumulation
906 * \param peerflags Dial option flags
907 * \param single TRUE if there is only one outgoing call.
908 * \param caller_entertained TRUE if the caller is being entertained by MOH or ringback.
909 * \param to Remaining call timeout time.
910 * \param forced_clid OPT_FORCECLID caller id to send
911 * \param stored_clid Caller id representing the called party if needed
912 *
913 * XXX this code is highly suspicious, as it essentially overwrites
914 * the outgoing channel without properly deleting it.
915 *
916 * \todo eventually this function should be integrated into and replaced by ast_call_forward()
917 */
918static void do_forward(struct chanlist *o, struct cause_args *num,
919 struct ast_flags64 *peerflags, int single, int caller_entertained, int *to,
920 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
921{
922 char tmpchan[256];
923 char forwarder[AST_CHANNEL_NAME];
924 struct ast_channel *original = o->chan;
925 struct ast_channel *c = o->chan; /* the winner */
926 struct ast_channel *in = num->chan; /* the input channel */
927 char *stuff;
928 char *tech;
929 int cause;
930 struct ast_party_caller caller;
931
932 ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
933 ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
934 if ((stuff = strchr(tmpchan, '/'))) {
935 *stuff++ = '\0';
936 tech = tmpchan;
937 } else {
938 const char *forward_context;
940 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
941 if (ast_strlen_zero(forward_context)) {
942 forward_context = NULL;
943 }
944 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
946 stuff = tmpchan;
947 tech = "Local";
948 }
949 if (!strcasecmp(tech, "Local")) {
950 /*
951 * Drop the connected line update block for local channels since
952 * this is going to run dialplan and the user can change his
953 * mind about what connected line information he wants to send.
954 */
956 }
957
958 /* Before processing channel, go ahead and check for forwarding */
959 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
960 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
961 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
962 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
963 ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
964 ast_channel_call_forward(original));
965 c = o->chan = NULL;
966 cause = AST_CAUSE_BUSY;
967 } else {
968 struct ast_stream_topology *topology;
969
973
974 /* Setup parameters */
975 c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
976
977 ast_stream_topology_free(topology);
978
979 if (c) {
980 if (single && !caller_entertained) {
982 }
986 pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
990 /* When a call is forwarded, we don't want to track new interfaces
991 * dialed for CC purposes. Setting the done flag will ensure that
992 * any Dial operations that happen later won't record CC interfaces.
993 */
995 ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",
997 } else
999 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
1000 tech, stuff, cause);
1001 }
1002 if (!c) {
1003 ast_channel_publish_dial(in, original, stuff, "BUSY");
1005 handle_cause(cause, num);
1006 ast_hangup(original);
1007 } else {
1008 ast_channel_lock_both(c, original);
1010 ast_channel_redirecting(original));
1012 ast_channel_unlock(original);
1013
1015
1016 if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
1018 }
1019
1020 if (!ast_channel_redirecting(c)->from.number.valid
1021 || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
1022 /*
1023 * The call was not previously redirected so it is
1024 * now redirected from this number.
1025 */
1031 }
1032
1034
1035 /* Determine CallerID to store in outgoing channel. */
1037 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1038 caller.id = *stored_clid;
1041 } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
1042 ast_channel_caller(c)->id.number.str, NULL))) {
1043 /*
1044 * The new channel has no preset CallerID number by the channel
1045 * driver. Use the dialplan extension and hint name.
1046 */
1047 caller.id = *stored_clid;
1050 } else {
1052 }
1053
1054 /* Determine CallerID for outgoing channel to send. */
1057
1059 connected.id = *forced_clid;
1061 } else {
1063 }
1064
1066
1067 ast_channel_appl_set(c, "AppDial");
1068 ast_channel_data_set(c, "(Outgoing Line)");
1070
1072 if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1073 struct ast_party_redirecting redirecting;
1074
1075 /*
1076 * Redirecting updates to the caller make sense only on single
1077 * calls.
1078 *
1079 * Need to re-evalute if unlocking is still required here as macro is gone
1080 */
1081 ast_party_redirecting_init(&redirecting);
1084 if (ast_channel_redirecting_sub(c, in, &redirecting, 0)) {
1085 ast_channel_update_redirecting(in, &redirecting, NULL);
1086 }
1087 ast_party_redirecting_free(&redirecting);
1088 } else {
1090 }
1091
1092 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1093 *to = -1;
1094 }
1095
1096 if (ast_call(c, stuff, 0)) {
1097 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1098 tech, stuff);
1099 ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1101 ast_hangup(original);
1102 ast_hangup(c);
1103 c = o->chan = NULL;
1104 num->nochan++;
1105 } else {
1106 ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1107 ast_channel_call_forward(original));
1108
1110
1111 /* Hangup the original channel now, in case we needed it */
1112 ast_hangup(original);
1113 }
1114 if (single && !caller_entertained) {
1115 ast_indicate(in, -1);
1116 }
1117 }
1118}
1119
1120/* argument used for some functions. */
1124 char privcid[256];
1125 char privintro[1024];
1126 char status[256];
1128};
1129
1130static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
1131{
1132 struct chanlist *outgoing;
1133 AST_LIST_TRAVERSE(out_chans, outgoing, node) {
1134 if (!outgoing->chan || outgoing->chan == exception) {
1135 continue;
1136 }
1138 }
1139}
1140
1141/*!
1142 * \internal
1143 * \brief Update connected line on chan from peer.
1144 * \since 13.6.0
1145 *
1146 * \param chan Channel to get connected line updated.
1147 * \param peer Channel providing connected line information.
1148 * \param is_caller Non-zero if chan is the calling channel.
1149 */
1150static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
1151{
1152 struct ast_party_connected_line connected_caller;
1153
1154 ast_party_connected_line_init(&connected_caller);
1155
1156 ast_channel_lock(peer);
1158 ast_channel_unlock(peer);
1160 if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)) {
1161 ast_channel_update_connected_line(chan, &connected_caller, NULL);
1162 }
1163 ast_party_connected_line_free(&connected_caller);
1164}
1165
1166/*!
1167 * \internal
1168 * \pre chan is locked
1169 */
1170static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
1171{
1172 char buf[32];
1173 char full_var_name[128];
1174
1175 snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000);
1176 pbx_builtin_setvar_helper(chan, var_base, buf);
1177
1178 snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base);
1179 snprintf(buf, sizeof(buf), "%" PRId64, duration);
1180 pbx_builtin_setvar_helper(chan, full_var_name, buf);
1181}
1182
1184 struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags,
1185 char *opt_args[],
1186 struct privacy_args *pa,
1187 const struct cause_args *num_in, int *result, char *dtmf_progress,
1188 char *mf_progress, char *mf_wink,
1189 char *sf_progress, char *sf_wink,
1190 const int hearpulsing,
1191 const int ignore_cc,
1192 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid,
1193 struct ast_bridge_config *config)
1194{
1195 struct cause_args num = *num_in;
1196 int prestart = num.busy + num.congestion + num.nochan;
1197 int orig = *to;
1198 struct ast_channel *peer = NULL;
1199 struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
1200 /* single is set if only one destination is enabled */
1201 int single = outgoing && !AST_LIST_NEXT(outgoing, node);
1202 int caller_entertained = outgoing
1204 struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
1205 int cc_recall_core_id;
1206 int is_cc_recall;
1207 int cc_frame_received = 0;
1208 int num_ringing = 0;
1209 int sent_ring = 0;
1210 int sent_progress = 0, sent_wink = 0;
1211 struct timeval start = ast_tvnow();
1212 SCOPE_ENTER(3, "%s\n", ast_channel_name(in));
1213
1214 if (single) {
1215 /* Turn off hold music, etc */
1216 if (!caller_entertained) {
1218 /* If we are calling a single channel, and not providing ringback or music, */
1219 /* then, make them compatible for in-band tone purpose */
1220 if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
1221 /* If these channels can not be made compatible,
1222 * there is no point in continuing. The bridge
1223 * will just fail if it gets that far.
1224 */
1225 *to = -1;
1226 strcpy(pa->status, "CONGESTION");
1228 SCOPE_EXIT_RTN_VALUE(NULL, "%s: can't be made compat with %s\n",
1230 }
1231 }
1232
1236 }
1237 }
1238
1239 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1240
1241 while ((*to = ast_remaining_ms(start, orig)) && !peer) {
1242 struct chanlist *o;
1243 int pos = 0; /* how many channels do we handle */
1244 int numlines = prestart;
1245 struct ast_channel *winner;
1246 struct ast_channel *watchers[AST_MAX_WATCHERS];
1247
1248 watchers[pos++] = in;
1249 AST_LIST_TRAVERSE(out_chans, o, node) {
1250 /* Keep track of important channels */
1251 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1252 watchers[pos++] = o->chan;
1253 numlines++;
1254 }
1255 if (pos == 1) { /* only the input channel is available */
1256 if (numlines == (num.busy + num.congestion + num.nochan)) {
1257 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1258 if (num.busy)
1259 strcpy(pa->status, "BUSY");
1260 else if (num.congestion)
1261 strcpy(pa->status, "CONGESTION");
1262 else if (num.nochan)
1263 strcpy(pa->status, "CHANUNAVAIL");
1264 } else {
1265 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1266 }
1267 *to = 0;
1268 if (is_cc_recall) {
1269 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1270 }
1271 SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outgoing channels available\n", ast_channel_name(in));
1272 }
1273 winner = ast_waitfor_n(watchers, pos, to);
1274 AST_LIST_TRAVERSE(out_chans, o, node) {
1275 int res = 0;
1276 struct ast_frame *f;
1277 struct ast_channel *c = o->chan;
1278
1279 if (c == NULL)
1280 continue;
1282 if (!peer) {
1283 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1284 if (o->orig_chan_name
1285 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1286 /*
1287 * The channel name changed so we must generate COLP update.
1288 * Likely because a call pickup channel masqueraded in.
1289 */
1291 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1292 if (o->pending_connected_update) {
1295 }
1296 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1298 }
1299 }
1300 if (o->aoc_s_rate_list) {
1301 size_t encoded_size;
1302 struct ast_aoc_encoded *encoded;
1303 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1304 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1305 ast_aoc_destroy_encoded(encoded);
1306 }
1307 }
1308 peer = c;
1309 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1310 ast_copy_flags64(peerflags, o,
1317 ast_channel_dialcontext_set(c, "");
1319 }
1320 continue;
1321 }
1322 if (c != winner)
1323 continue;
1324 /* here, o->chan == c == winner */
1326 pa->sentringing = 0;
1327 if (!ignore_cc && (f = ast_read(c))) {
1329 /* This channel is forwarding the call, and is capable of CC, so
1330 * be sure to add the new device interface to the list
1331 */
1333 }
1334 ast_frfree(f);
1335 }
1336
1337 if (o->pending_connected_update) {
1338 /*
1339 * Re-seed the chanlist's connected line information with
1340 * previously acquired connected line info from the incoming
1341 * channel. The previously acquired connected line info could
1342 * have been set through the CONNECTED_LINE dialplan function.
1343 */
1348 }
1349
1350 do_forward(o, &num, peerflags, single, caller_entertained, &orig,
1351 forced_clid, stored_clid);
1352
1353 if (o->chan) {
1356 if (single
1360 }
1361 }
1362 continue;
1363 }
1364 f = ast_read(winner);
1365 if (!f) {
1368 ast_hangup(c);
1369 c = o->chan = NULL;
1372 continue;
1373 }
1374 switch (f->frametype) {
1375 case AST_FRAME_CONTROL:
1376 switch (f->subclass.integer) {
1377 case AST_CONTROL_ANSWER:
1378 /* This is our guy if someone answered. */
1379 if (!peer) {
1380 ast_trace(-1, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1381 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1382 if (o->orig_chan_name
1383 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1384 /*
1385 * The channel name changed so we must generate COLP update.
1386 * Likely because a call pickup channel masqueraded in.
1387 */
1389 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1390 if (o->pending_connected_update) {
1393 }
1394 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1396 }
1397 }
1398 if (o->aoc_s_rate_list) {
1399 size_t encoded_size;
1400 struct ast_aoc_encoded *encoded;
1401 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1402 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1403 ast_aoc_destroy_encoded(encoded);
1404 }
1405 }
1406 peer = c;
1407 /* Answer can optionally include a topology */
1408 if (f->subclass.topology) {
1409 /*
1410 * We need to bump the refcount on the topology to prevent it
1411 * from being cleaned up when the frame is cleaned up.
1412 */
1413 config->answer_topology = ao2_bump(f->subclass.topology);
1414 ast_trace(-1, "%s Found topology in frame: %p %p %s\n",
1415 ast_channel_name(peer), f, config->answer_topology,
1416 ast_str_tmp(256, ast_stream_topology_to_str(config->answer_topology, &STR_TMP)));
1417 }
1418
1419 /* Inform everyone else that they've been canceled.
1420 * The dial end event for the peer will be sent out after
1421 * other Dial options have been handled.
1422 */
1423 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1424 ast_copy_flags64(peerflags, o,
1431 ast_channel_dialcontext_set(c, "");
1433 if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
1434 /* Setup early bridge if appropriate */
1436 }
1437 }
1438 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1441 break;
1442 case AST_CONTROL_BUSY:
1443 ast_verb(3, "%s is busy\n", ast_channel_name(c));
1445 ast_channel_publish_dial(in, c, NULL, "BUSY");
1446 ast_hangup(c);
1447 c = o->chan = NULL;
1450 break;
1452 ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1454 ast_channel_publish_dial(in, c, NULL, "CONGESTION");
1455 ast_hangup(c);
1456 c = o->chan = NULL;
1459 break;
1461 /* This is a tricky area to get right when using a native
1462 * CC agent. The reason is that we do the best we can to send only a
1463 * single ringing notification to the caller.
1464 *
1465 * Call completion complicates the logic used here. CCNR is typically
1466 * offered during a ringing message. Let's say that party A calls
1467 * parties B, C, and D. B and C do not support CC requests, but D
1468 * does. If we were to receive a ringing notification from B before
1469 * the others, then we would end up sending a ringing message to
1470 * A with no CCNR offer present.
1471 *
1472 * The approach that we have taken is that if we receive a ringing
1473 * response from a party and no CCNR offer is present, we need to
1474 * wait. Specifically, we need to wait until either a) a called party
1475 * offers CCNR in its ringing response or b) all called parties have
1476 * responded in some way to our call and none offers CCNR.
1477 *
1478 * The drawback to this is that if one of the parties has a delayed
1479 * response or, god forbid, one just plain doesn't respond to our
1480 * outgoing call, then this will result in a significant delay between
1481 * when the caller places the call and hears ringback.
1482 *
1483 * Note also that if CC is disabled for this call, then it is perfectly
1484 * fine for ringing frames to get sent through.
1485 */
1486 ++num_ringing;
1487 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1488 ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1489 /* Setup early media if appropriate */
1490 if (single && !caller_entertained
1491 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1493 }
1496 pa->sentringing++;
1497 }
1498 if (!sent_ring) {
1499 struct timeval now, then;
1500 int64_t diff;
1501
1502 now = ast_tvnow();
1503
1506
1508 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1509 set_duration_var(in, "RINGTIME", diff);
1510
1513 sent_ring = 1;
1514 }
1515 }
1516 ast_channel_publish_dial(in, c, NULL, "RINGING");
1517 break;
1519 ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1520 /* Setup early media if appropriate */
1521 if (single && !caller_entertained
1522 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1524 }
1526 if (single || (!single && !pa->sentringing)) {
1528 }
1529 }
1530 if (!sent_progress) {
1531 struct timeval now, then;
1532 int64_t diff;
1533
1534 now = ast_tvnow();
1535
1538
1540 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1541 set_duration_var(in, "PROGRESSTIME", diff);
1542
1545 sent_progress = 1;
1546
1547 if (!ast_strlen_zero(mf_progress)) {
1548 ast_verb(3,
1549 "Sending MF '%s' to %s as result of "
1550 "receiving a PROGRESS message.\n",
1551 mf_progress, hearpulsing ? "parties" : "called party");
1552 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1553 (hearpulsing ? in : NULL), mf_progress, 50, 55, 120, 65, 0);
1554 }
1555 if (!ast_strlen_zero(sf_progress)) {
1556 ast_verb(3,
1557 "Sending SF '%s' to %s as result of "
1558 "receiving a PROGRESS message.\n",
1559 sf_progress, (hearpulsing ? "parties" : "called party"));
1560 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1561 (hearpulsing ? in : NULL), sf_progress, 0, 0);
1562 }
1563 if (!ast_strlen_zero(dtmf_progress)) {
1564 ast_verb(3,
1565 "Sending DTMF '%s' to the called party as result of "
1566 "receiving a PROGRESS message.\n",
1567 dtmf_progress);
1568 res |= ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1569 }
1570 if (res) {
1571 ast_log(LOG_WARNING, "Called channel %s hung up post-progress before all digits could be sent\n", ast_channel_name(c));
1572 goto wait_over;
1573 }
1574 }
1575 ast_channel_publish_dial(in, c, NULL, "PROGRESS");
1576 break;
1577 case AST_CONTROL_WINK:
1578 ast_verb(3, "%s winked, passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1579 if (!sent_wink) {
1580 sent_wink = 1;
1581 if (!ast_strlen_zero(mf_wink)) {
1582 ast_verb(3,
1583 "Sending MF '%s' to %s as result of "
1584 "receiving a WINK message.\n",
1585 mf_wink, (hearpulsing ? "parties" : "called party"));
1586 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1587 (hearpulsing ? in : NULL), mf_wink, 50, 55, 120, 65, 0);
1588 }
1589 if (!ast_strlen_zero(sf_wink)) {
1590 ast_verb(3,
1591 "Sending SF '%s' to %s as result of "
1592 "receiving a WINK message.\n",
1593 sf_wink, (hearpulsing ? "parties" : "called party"));
1594 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1595 (hearpulsing ? in : NULL), sf_wink, 0, 0);
1596 }
1597 if (res) {
1598 ast_log(LOG_WARNING, "Called channel %s hung up post-wink before all digits could be sent\n", ast_channel_name(c));
1599 goto wait_over;
1600 }
1601 }
1603 break;
1607 if (!single || caller_entertained) {
1608 break;
1609 }
1610 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1613 break;
1616 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1617 break;
1618 }
1619 if (!single) {
1621
1622 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
1629 break;
1630 }
1631 if (ast_channel_connected_line_sub(c, in, f, 1)) {
1633 }
1634 break;
1635 case AST_CONTROL_AOC:
1636 {
1637 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1638 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1640 o->aoc_s_rate_list = decoded;
1641 } else {
1642 ast_aoc_destroy_decoded(decoded);
1643 }
1644 }
1645 break;
1647 if (!single) {
1648 /*
1649 * Redirecting updates to the caller make sense only on single
1650 * calls.
1651 */
1652 break;
1653 }
1655 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1656 break;
1657 }
1658 ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
1660 if (ast_channel_redirecting_sub(c, in, f, 1)) {
1662 }
1663 pa->sentringing = 0;
1664 break;
1666 ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1667 if (single && !caller_entertained
1668 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1670 }
1673 ast_channel_publish_dial(in, c, NULL, "PROCEEDING");
1674 break;
1675 case AST_CONTROL_HOLD:
1676 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1677 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1679 break;
1680 case AST_CONTROL_UNHOLD:
1681 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1682 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1684 break;
1686 case AST_CONTROL_FLASH:
1687 /* Ignore going off hook and flash */
1688 break;
1689 case AST_CONTROL_CC:
1690 if (!ignore_cc) {
1692 cc_frame_received = 1;
1693 }
1694 break;
1697 break;
1698 case -1:
1699 if (single && !caller_entertained) {
1700 ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1701 ast_indicate(in, -1);
1702 pa->sentringing = 0;
1703 }
1704 break;
1705 default:
1706 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1707 break;
1708 }
1709 break;
1710 case AST_FRAME_VIDEO:
1711 case AST_FRAME_VOICE:
1712 case AST_FRAME_IMAGE:
1714 case AST_FRAME_DTMF_END:
1715 if (caller_entertained) {
1716 break;
1717 }
1718 /* Fall through */
1719 case AST_FRAME_TEXT:
1720 if (single && ast_write(in, f)) {
1721 ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
1722 f->frametype);
1723 }
1724 break;
1725 case AST_FRAME_HTML:
1727 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1728 ast_log(LOG_WARNING, "Unable to send URL\n");
1729 }
1730 break;
1731 default:
1732 break;
1733 }
1734 ast_frfree(f);
1735 } /* end for */
1736 if (winner == in) {
1737 struct ast_frame *f = ast_read(in);
1738#if 0
1739 if (f && (f->frametype != AST_FRAME_VOICE))
1740 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1741 else if (!f || (f->frametype != AST_FRAME_VOICE))
1742 printf("Hangup received on %s\n", in->name);
1743#endif
1744 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1745 /* Got hung up */
1746 *to = -1;
1747 strcpy(pa->status, "CANCEL");
1748 pa->canceled = 1;
1749 publish_dial_end_event(in, out_chans, NULL, pa->status);
1750 if (f) {
1751 if (f->data.uint32) {
1753 }
1754 ast_frfree(f);
1755 }
1756 if (is_cc_recall) {
1757 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1758 }
1759 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller hung up\n", ast_channel_name(in));
1760 }
1761
1762 /* now f is guaranteed non-NULL */
1763 if (f->frametype == AST_FRAME_DTMF) {
1764 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1765 const char *context;
1767 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
1768 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1769 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1770 *to = 0;
1771 *result = f->subclass.integer;
1772 strcpy(pa->status, "CANCEL");
1773 pa->canceled = 1;
1774 publish_dial_end_event(in, out_chans, NULL, pa->status);
1775 ast_frfree(f);
1777 if (is_cc_recall) {
1778 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1779 }
1780 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller pressed %c to end call\n",
1782 }
1784 }
1785
1786 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1787 detect_disconnect(in, f->subclass.integer, &featurecode)) {
1788 ast_verb(3, "User requested call disconnect.\n");
1789 *to = 0;
1790 strcpy(pa->status, "CANCEL");
1791 pa->canceled = 1;
1792 publish_dial_end_event(in, out_chans, NULL, pa->status);
1793 ast_frfree(f);
1794 if (is_cc_recall) {
1795 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1796 }
1797 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller requested disconnect\n",
1799 }
1800 }
1801
1802 /* Send the frame from the in channel to all outgoing channels. */
1803 AST_LIST_TRAVERSE(out_chans, o, node) {
1804 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1805 /* This outgoing channel has died so don't send the frame to it. */
1806 continue;
1807 }
1808 switch (f->frametype) {
1809 case AST_FRAME_HTML:
1810 /* Forward HTML stuff */
1812 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1813 ast_log(LOG_WARNING, "Unable to send URL\n");
1814 }
1815 break;
1816 case AST_FRAME_VIDEO:
1817 case AST_FRAME_VOICE:
1818 case AST_FRAME_IMAGE:
1819 if (!single || caller_entertained) {
1820 /*
1821 * We are calling multiple parties or caller is being
1822 * entertained and has thus not been made compatible.
1823 * No need to check any other called parties.
1824 */
1825 goto skip_frame;
1826 }
1827 /* Fall through */
1828 case AST_FRAME_TEXT:
1830 case AST_FRAME_DTMF_END:
1831 if (ast_write(o->chan, f)) {
1832 ast_log(LOG_WARNING, "Unable to forward frametype: %u\n",
1833 f->frametype);
1834 }
1835 break;
1836 case AST_FRAME_CONTROL:
1837 switch (f->subclass.integer) {
1838 case AST_CONTROL_HOLD:
1839 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1841 break;
1842 case AST_CONTROL_UNHOLD:
1843 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1845 break;
1846 case AST_CONTROL_FLASH:
1847 ast_verb(3, "Hook flash on %s\n", ast_channel_name(o->chan));
1849 break;
1853 if (!single || caller_entertained) {
1854 /*
1855 * We are calling multiple parties or caller is being
1856 * entertained and has thus not been made compatible.
1857 * No need to check any other called parties.
1858 */
1859 goto skip_frame;
1860 }
1861 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1864 break;
1867 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
1868 break;
1869 }
1870 if (ast_channel_connected_line_sub(in, o->chan, f, 1)) {
1872 }
1873 break;
1876 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
1877 break;
1878 }
1879 if (ast_channel_redirecting_sub(in, o->chan, f, 1)) {
1881 }
1882 break;
1883 default:
1884 /* We are not going to do anything with this frame. */
1885 goto skip_frame;
1886 }
1887 break;
1888 default:
1889 /* We are not going to do anything with this frame. */
1890 goto skip_frame;
1891 }
1892 }
1893skip_frame:;
1894 ast_frfree(f);
1895 }
1896 }
1897
1898wait_over:
1899 if (!*to || ast_check_hangup(in)) {
1900 ast_verb(3, "Nobody picked up in %d ms\n", orig);
1901 publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
1902 }
1903
1904 if (is_cc_recall) {
1905 ast_cc_completed(in, "Recall completed!");
1906 }
1907 SCOPE_EXIT_RTN_VALUE(peer, "%s: %s%s\n", ast_channel_name(in),
1908 peer ? "Answered by " : "No answer", peer ? ast_channel_name(peer) : "");
1909}
1910
1911static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
1912{
1913 char disconnect_code[AST_FEATURE_MAX_LEN];
1914 int res;
1915
1916 ast_str_append(featurecode, 1, "%c", code);
1917
1918 res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
1919 if (res) {
1920 ast_str_reset(*featurecode);
1921 return 0;
1922 }
1923
1924 if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
1925 /* Could be a partial match, anyway */
1926 if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
1927 ast_str_reset(*featurecode);
1928 }
1929 return 0;
1930 }
1931
1932 if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
1933 ast_str_reset(*featurecode);
1934 return 0;
1935 }
1936
1937 return 1;
1938}
1939
1940/* returns true if there is a valid privacy reply */
1941static int valid_priv_reply(struct ast_flags64 *opts, int res)
1942{
1943 if (res < '1')
1944 return 0;
1945 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1946 return 1;
1947 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1948 return 1;
1949 return 0;
1950}
1951
1952static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1953 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1954{
1955
1956 int res2;
1957 int loopcount = 0;
1958
1959 /* Get the user's intro, store it in priv-callerintros/$CID,
1960 unless it is already there-- this should be done before the
1961 call is actually dialed */
1962
1963 /* all ring indications and moh for the caller has been halted as soon as the
1964 target extension was picked up. We are going to have to kill some
1965 time and make the caller believe the peer hasn't picked up yet */
1966
1968 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
1969 ast_indicate(chan, -1);
1970 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
1971 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
1972 ast_channel_musicclass_set(chan, original_moh);
1975 pa->sentringing++;
1976 }
1977
1978 /* Start autoservice on the other chan ?? */
1979 res2 = ast_autoservice_start(chan);
1980 /* Now Stream the File */
1981 for (loopcount = 0; loopcount < 3; loopcount++) {
1982 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
1983 break;
1984 if (!res2) /* on timeout, play the message again */
1985 res2 = ast_play_and_wait(peer, "priv-callpending");
1986 if (!valid_priv_reply(opts, res2))
1987 res2 = 0;
1988 /* priv-callpending script:
1989 "I have a caller waiting, who introduces themselves as:"
1990 */
1991 if (!res2)
1992 res2 = ast_play_and_wait(peer, pa->privintro);
1993 if (!valid_priv_reply(opts, res2))
1994 res2 = 0;
1995 /* now get input from the called party, as to their choice */
1996 if (!res2) {
1997 /* XXX can we have both, or they are mutually exclusive ? */
1998 if (ast_test_flag64(opts, OPT_PRIVACY))
1999 res2 = ast_play_and_wait(peer, "priv-callee-options");
2000 if (ast_test_flag64(opts, OPT_SCREENING))
2001 res2 = ast_play_and_wait(peer, "screen-callee-options");
2002 }
2003
2004 /*! \page DialPrivacy Dial Privacy scripts
2005 * \par priv-callee-options script:
2006 * \li Dial 1 if you wish this caller to reach you directly in the future,
2007 * and immediately connect to their incoming call.
2008 * \li Dial 2 if you wish to send this caller to voicemail now and forevermore.
2009 * \li Dial 3 to send this caller to the torture menus, now and forevermore.
2010 * \li Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
2011 * \li Dial 5 to allow this caller to come straight thru to you in the future,
2012 * but right now, just this once, send them to voicemail.
2013 *
2014 * \par screen-callee-options script:
2015 * \li Dial 1 if you wish to immediately connect to the incoming call
2016 * \li Dial 2 if you wish to send this caller to voicemail.
2017 * \li Dial 3 to send this caller to the torture menus.
2018 * \li Dial 4 to send this caller to a simple "go away" menu.
2019 */
2020 if (valid_priv_reply(opts, res2))
2021 break;
2022 /* invalid option */
2023 res2 = ast_play_and_wait(peer, "vm-sorry");
2024 }
2025
2026 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
2027 ast_moh_stop(chan);
2029 ast_indicate(chan, -1);
2030 pa->sentringing = 0;
2031 }
2033 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
2034 /* map keypresses to various things, the index is res2 - '1' */
2035 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
2037 int i = res2 - '1';
2038 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
2039 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
2040 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
2041 }
2042 switch (res2) {
2043 case '1':
2044 break;
2045 case '2':
2046 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2047 break;
2048 case '3':
2049 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2050 break;
2051 case '4':
2052 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2053 break;
2054 case '5':
2055 if (ast_test_flag64(opts, OPT_PRIVACY)) {
2056 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2057 break;
2058 }
2059 /* if not privacy, then 5 is the same as "default" case */
2060 default: /* bad input or -1 if failure to start autoservice */
2061 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
2062 /* well, there seems basically two choices. Just patch the caller thru immediately,
2063 or,... put 'em thru to voicemail. */
2064 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
2065 ast_verb(3, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
2066 /* XXX should we set status to DENY ? */
2067 /* XXX what about the privacy flags ? */
2068 break;
2069 }
2070
2071 if (res2 == '1') { /* the only case where we actually connect */
2072 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
2073 just clog things up, and it's not useful information, not being tied to a CID */
2074 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
2076 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2077 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2078 else
2079 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2080 }
2081 return 0; /* the good exit path */
2082 } else {
2083 return -1;
2084 }
2085}
2086
2087/*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
2088static int setup_privacy_args(struct privacy_args *pa,
2089 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
2090{
2091 char callerid[60];
2092 int res;
2093 char *l;
2094
2095 if (ast_channel_caller(chan)->id.number.valid
2096 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2097 l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2099 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
2100 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
2101 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
2102 } else {
2103 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
2105 }
2106 } else {
2107 char *tnam, *tn2;
2108
2109 tnam = ast_strdupa(ast_channel_name(chan));
2110 /* clean the channel name so slashes don't try to end up in disk file name */
2111 for (tn2 = tnam; *tn2; tn2++) {
2112 if (*tn2 == '/') /* any other chars to be afraid of? */
2113 *tn2 = '=';
2114 }
2115 ast_verb(3, "Privacy-- callerid is empty\n");
2116
2117 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
2118 l = callerid;
2120 }
2121
2122 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
2123
2124 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
2125 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
2126 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
2128 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
2129 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
2130 }
2131
2132 if (pa->privdb_val == AST_PRIVACY_DENY) {
2133 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
2134 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2135 return 0;
2136 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
2137 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2138 return 0; /* Is this right? */
2139 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
2140 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2141 return 0; /* is this right??? */
2142 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
2143 /* Get the user's intro, store it in priv-callerintros/$CID,
2144 unless it is already there-- this should be done before the
2145 call is actually dialed */
2146
2147 /* make sure the priv-callerintros dir actually exists */
2148 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
2149 if ((res = ast_mkdir(pa->privintro, 0755))) {
2150 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
2151 return -1;
2152 }
2153
2154 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
2155 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
2156 /* the DELUX version of this code would allow this caller the
2157 option to hear and retape their previously recorded intro.
2158 */
2159 } else {
2160 int duration; /* for feedback from play_and_wait */
2161 /* the file doesn't exist yet. Let the caller submit his
2162 vocal intro for posterity */
2163 /* priv-recordintro script:
2164 "At the tone, please say your name:"
2165 */
2167 ast_answer(chan);
2168 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 */
2169 /* don't think we'll need a lock removed, we took care of
2170 conflicts by naming the pa.privintro file */
2171 if (res == -1) {
2172 /* Delete the file regardless since they hung up during recording */
2174 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2175 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2176 else
2177 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2178 return -1;
2179 }
2180 if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
2181 ast_waitstream(chan, "");
2182 }
2183 }
2184 return 1; /* success */
2185}
2186
2187static void end_bridge_callback(void *data)
2188{
2189 struct ast_channel *chan = data;
2190
2191 ast_channel_lock(chan);
2193 set_duration_var(chan, "ANSWEREDTIME", ast_channel_get_up_time_ms(chan));
2194 set_duration_var(chan, "DIALEDTIME", ast_channel_get_duration_ms(chan));
2196 ast_channel_unlock(chan);
2197}
2198
2199static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
2200 bconfig->end_bridge_callback_data = originator;
2201}
2202
2203static int dial_handle_playtones(struct ast_channel *chan, const char *data)
2204{
2205 struct ast_tone_zone_sound *ts = NULL;
2206 int res;
2207 const char *str = data;
2208
2209 if (ast_strlen_zero(str)) {
2210 ast_debug(1,"Nothing to play\n");
2211 return -1;
2212 }
2213
2215
2216 if (ts && ts->data[0]) {
2217 res = ast_playtones_start(chan, 0, ts->data, 0);
2218 } else {
2219 res = -1;
2220 }
2221
2222 if (ts) {
2224 }
2225
2226 if (res) {
2227 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
2228 }
2229
2230 return res;
2231}
2232
2233/*!
2234 * \internal
2235 * \brief Setup the after bridge goto location on the peer.
2236 * \since 12.0.0
2237 *
2238 * \param chan Calling channel for bridge.
2239 * \param peer Peer channel for bridge.
2240 * \param opts Dialing option flags.
2241 * \param opt_args Dialing option argument strings.
2242 */
2243static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
2244{
2245 const char *context;
2246 const char *extension;
2247 int priority;
2248
2249 if (ast_test_flag64(opts, OPT_PEER_H)) {
2250 ast_channel_lock(chan);
2252 ast_channel_unlock(chan);
2254 } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
2255 ast_channel_lock(chan);
2259 ast_channel_unlock(chan);
2261 opt_args[OPT_ARG_CALLEE_GO_ON]);
2262 }
2263}
2264
2265static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
2266{
2267 int res = -1; /* default: error */
2268 char *rest, *cur; /* scan the list of destinations */
2269 struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2270 struct chanlist *outgoing;
2271 struct chanlist *tmp;
2272 struct ast_channel *peer = NULL;
2273 int to; /* timeout */
2274 struct cause_args num = { chan, 0, 0, 0 };
2275 int cause, hanguptreecause = -1;
2276
2277 struct ast_bridge_config config = { { 0, } };
2278 struct timeval calldurationlimit = { 0, };
2279 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL;
2280 char *mf_progress = NULL, *mf_wink = NULL;
2281 char *sf_progress = NULL, *sf_wink = NULL;
2282 struct privacy_args pa = {
2283 .sentringing = 0,
2284 .privdb_val = 0,
2285 .status = "INVALIDARGS",
2286 .canceled = 0,
2287 };
2288 int sentringing = 0, moh = 0;
2289 const char *outbound_group = NULL;
2290 int result = 0;
2291 char *parse;
2292 int opermode = 0;
2293 int delprivintro = 0;
2296 AST_APP_ARG(timeout);
2299 );
2300 struct ast_flags64 opts = { 0, };
2301 char *opt_args[OPT_ARG_ARRAY_SIZE];
2302 int fulldial = 0, num_dialed = 0;
2303 int ignore_cc = 0;
2304 char device_name[AST_CHANNEL_NAME];
2305 char forced_clid_name[AST_MAX_EXTENSION];
2306 char stored_clid_name[AST_MAX_EXTENSION];
2307 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2308 /*!
2309 * \brief Forced CallerID party information to send.
2310 * \note This will not have any malloced strings so do not free it.
2311 */
2312 struct ast_party_id forced_clid;
2313 /*!
2314 * \brief Stored CallerID information if needed.
2315 *
2316 * \note If OPT_ORIGINAL_CLID set then this is the o option
2317 * CallerID. Otherwise it is the dialplan extension and hint
2318 * name.
2319 *
2320 * \note This will not have any malloced strings so do not free it.
2321 */
2322 struct ast_party_id stored_clid;
2323 /*!
2324 * \brief CallerID party information to store.
2325 * \note This will not have any malloced strings so do not free it.
2326 */
2327 struct ast_party_caller caller;
2328 int max_forwards;
2329 SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data);
2330
2331 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2332 ast_channel_lock(chan);
2334 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2335 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2336 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2337 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2338 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");
2339 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2340 pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");
2341 pbx_builtin_setvar_helper(chan, "RINGTIME", "");
2342 pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");
2343 pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");
2344 pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");
2347 ast_channel_unlock(chan);
2348
2349 if (max_forwards <= 0) {
2350 ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2351 ast_channel_name(chan));
2352 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2353 SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan));
2354 }
2355
2356 if (ast_check_hangup_locked(chan)) {
2357 /*
2358 * Caller hung up before we could dial. If dial is executed
2359 * within an AGI then the AGI has likely eaten all queued
2360 * frames before executing the dial in DeadAGI mode. With
2361 * the caller hung up and no pending frames from the caller's
2362 * read queue, dial would not know that the call has hung up
2363 * until a called channel answers. It is rather annoying to
2364 * whoever just answered the non-existent call.
2365 *
2366 * Dial should not continue execution in DeadAGI mode, hangup
2367 * handlers, or the h exten.
2368 */
2369 ast_verb(3, "Caller hung up before dial.\n");
2370 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
2371 SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan));
2372 }
2373
2374 parse = ast_strdupa(data ?: "");
2375
2377
2378 if (!ast_strlen_zero(args.options) &&
2379 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2380 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2381 goto done;
2382 }
2383
2384 if (ast_cc_call_init(chan, &ignore_cc)) {
2385 goto done;
2386 }
2387
2389 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2390
2391 if (delprivintro < 0 || delprivintro > 1) {
2392 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2393 delprivintro = 0;
2394 }
2395 }
2396
2397 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2398 opt_args[OPT_ARG_RINGBACK] = NULL;
2399 }
2400
2401 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2402 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2403 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2404 }
2405
2407 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2408 if (!calldurationlimit.tv_sec) {
2409 ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);
2410 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2411 goto done;
2412 }
2413 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2414 }
2415
2416 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2417 sf_wink = opt_args[OPT_ARG_SENDDTMF];
2418 dtmfcalled = strsep(&sf_wink, ":");
2419 dtmfcalling = strsep(&sf_wink, ":");
2420 dtmf_progress = strsep(&sf_wink, ":");
2421 mf_progress = strsep(&sf_wink, ":");
2422 mf_wink = strsep(&sf_wink, ":");
2423 sf_progress = strsep(&sf_wink, ":");
2424 }
2425
2427 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2428 goto done;
2429 }
2430
2431 /* Setup the forced CallerID information to send if used. */
2432 ast_party_id_init(&forced_clid);
2433 force_forwards_only = 0;
2434 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2435 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2436 ast_channel_lock(chan);
2437 forced_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2438 ast_channel_unlock(chan);
2439 forced_clid_name[0] = '\0';
2440 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2441 sizeof(forced_clid_name), chan);
2442 force_forwards_only = 1;
2443 } else {
2444 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2445 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2446 &forced_clid.number.str);
2447 }
2448 if (!ast_strlen_zero(forced_clid.name.str)) {
2449 forced_clid.name.valid = 1;
2450 }
2451 if (!ast_strlen_zero(forced_clid.number.str)) {
2452 forced_clid.number.valid = 1;
2453 }
2454 }
2456 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2457 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2458 }
2461 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2462 int pres;
2463
2465 if (0 <= pres) {
2466 forced_clid.number.presentation = pres;
2467 }
2468 }
2469
2470 /* Setup the stored CallerID information if needed. */
2471 ast_party_id_init(&stored_clid);
2472 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2473 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2474 ast_channel_lock(chan);
2475 ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2476 if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2477 stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2478 }
2479 if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2480 stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2481 }
2482 if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2483 stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2484 }
2485 if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2486 stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2487 }
2488 ast_channel_unlock(chan);
2489 } else {
2490 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2491 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2492 &stored_clid.number.str);
2493 if (!ast_strlen_zero(stored_clid.name.str)) {
2494 stored_clid.name.valid = 1;
2495 }
2496 if (!ast_strlen_zero(stored_clid.number.str)) {
2497 stored_clid.number.valid = 1;
2498 }
2499 }
2500 } else {
2501 /*
2502 * In case the new channel has no preset CallerID number by the
2503 * channel driver, setup the dialplan extension and hint name.
2504 */
2505 stored_clid_name[0] = '\0';
2506 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2507 sizeof(stored_clid_name), chan);
2508 if (ast_strlen_zero(stored_clid.name.str)) {
2509 stored_clid.name.str = NULL;
2510 } else {
2511 stored_clid.name.valid = 1;
2512 }
2513 ast_channel_lock(chan);
2514 stored_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2515 stored_clid.number.valid = 1;
2516 ast_channel_unlock(chan);
2517 }
2518
2519 if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2521 }
2524
2526 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2527 if (res <= 0)
2528 goto out;
2529 res = -1; /* reset default */
2530 }
2531
2532 if (continue_exec)
2533 *continue_exec = 0;
2534
2535 /* If a channel group has been specified, get it for use when we create peer channels */
2536
2537 ast_channel_lock(chan);
2538 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2539 outbound_group = ast_strdupa(outbound_group);
2540 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2541 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2542 outbound_group = ast_strdupa(outbound_group);
2543 }
2544 ast_channel_unlock(chan);
2545
2546 /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2550
2551 /* PREDIAL: Run gosub on the caller's channel */
2553 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2555 ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2556 }
2557
2558 /* loop through the list of dial destinations */
2559 rest = args.peers;
2560 while ((cur = strsep(&rest, "&"))) {
2561 struct ast_channel *tc; /* channel for this destination */
2562 char *number;
2563 char *tech;
2564 int i;
2565 size_t tech_len;
2566 size_t number_len;
2567 struct ast_stream_topology *topology;
2568 struct ast_stream *stream;
2569
2570 cur = ast_strip(cur);
2571 if (ast_strlen_zero(cur)) {
2572 /* No tech/resource in this position. */
2573 continue;
2574 }
2575
2576 /* Get a technology/resource pair */
2577 number = cur;
2578 tech = strsep(&number, "/");
2579
2580 num_dialed++;
2581 if (ast_strlen_zero(number)) {
2582 ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2583 goto out;
2584 }
2585
2586 tech_len = strlen(tech) + 1;
2587 number_len = strlen(number) + 1;
2588 tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2589 if (!tmp) {
2590 goto out;
2591 }
2592
2593 /* Save tech, number, and interface. */
2594 cur = tmp->stuff;
2595 strcpy(cur, tech);
2596 tmp->tech = cur;
2597 cur += tech_len;
2598 strcpy(cur, tech);
2599 cur[tech_len - 1] = '/';
2600 tmp->interface = cur;
2601 cur += tech_len;
2602 strcpy(cur, number);
2603 tmp->number = cur;
2604
2605 if (opts.flags) {
2606 /* Set per outgoing call leg options. */
2607 ast_copy_flags64(tmp, &opts,
2617 }
2618
2619 /* Request the peer */
2620
2621 ast_channel_lock(chan);
2622 /*
2623 * Seed the chanlist's connected line information with previously
2624 * acquired connected line info from the incoming channel. The
2625 * previously acquired connected line info could have been set
2626 * through the CONNECTED_LINE dialplan function.
2627 */
2629
2631
2632 ast_channel_unlock(chan);
2633
2634 for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
2635 stream = ast_stream_topology_get_stream(topology, i);
2636 /* For both recvonly and sendonly the stream state reflects our state, that is we
2637 * are receiving only and we are sending only. Since we are requesting a
2638 * channel for the peer, we need to swap this to reflect what we will be doing.
2639 * That is, if we are receiving from Alice then we want to be sending to Bob,
2640 * so swap recvonly to sendonly and vice versa.
2641 */
2644 } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {
2646 }
2647 }
2648
2649 tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
2650
2651 ast_stream_topology_free(topology);
2652
2653 if (!tc) {
2654 /* If we can't, just go on to the next call */
2655 /* Failure doesn't necessarily mean user error. DAHDI channels could be busy. */
2656 ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n",
2657 tmp->tech, cause, ast_cause2str(cause));
2658 handle_cause(cause, &num);
2659 if (!rest) {
2660 /* we are on the last destination */
2661 ast_channel_hangupcause_set(chan, cause);
2662 }
2663 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2664 if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2665 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, "");
2666 }
2667 }
2669 continue;
2670 }
2671
2672 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2673 if (!ignore_cc) {
2674 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2675 }
2676
2677 ast_channel_lock_both(tc, chan);
2679
2680 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2681
2682 /* Setup outgoing SDP to match incoming one */
2683 if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2684 /* We are on the only destination. */
2686 }
2687
2688 /* Inherit specially named variables from parent channel */
2692
2693 ast_channel_appl_set(tc, "AppDial");
2694 ast_channel_data_set(tc, "(Outgoing Line)");
2695
2696 memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2697
2698 /* Determine CallerID to store in outgoing channel. */
2700 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2701 caller.id = stored_clid;
2702 ast_channel_set_caller_event(tc, &caller, NULL);
2704 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2705 ast_channel_caller(tc)->id.number.str, NULL))) {
2706 /*
2707 * The new channel has no preset CallerID number by the channel
2708 * driver. Use the dialplan extension and hint name.
2709 */
2710 caller.id = stored_clid;
2711 if (!caller.id.name.valid
2712 && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2713 ast_channel_connected(chan)->id.name.str, NULL))) {
2714 /*
2715 * No hint name available. We have a connected name supplied by
2716 * the dialplan we can use instead.
2717 */
2718 caller.id.name.valid = 1;
2719 caller.id.name = ast_channel_connected(chan)->id.name;
2720 }
2721 ast_channel_set_caller_event(tc, &caller, NULL);
2723 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2724 NULL))) {
2725 /* The new channel has no preset CallerID name by the channel driver. */
2726 if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2727 ast_channel_connected(chan)->id.name.str, NULL))) {
2728 /*
2729 * We have a connected name supplied by the dialplan we can
2730 * use instead.
2731 */
2732 caller.id.name.valid = 1;
2733 caller.id.name = ast_channel_connected(chan)->id.name;
2734 ast_channel_set_caller_event(tc, &caller, NULL);
2735 }
2736 }
2737
2738 /* Determine CallerID for outgoing channel to send. */
2739 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2741
2743 connected.id = forced_clid;
2745 } else {
2747 }
2748
2750
2752
2755 ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2756 }
2757
2758 /* Pass ADSI CPE and transfer capability */
2761
2762 /* If we have an outbound group, set this peer channel to it */
2763 if (outbound_group)
2764 ast_app_group_set_channel(tc, outbound_group);
2765 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2768
2769 /* Check if we're forced by configuration */
2772
2773
2774 /* Inherit context and extension */
2775 ast_channel_dialcontext_set(tc, ast_channel_context(chan));
2777
2779
2780 /* Save the original channel name to detect call pickup masquerading in. */
2781 tmp->orig_chan_name = ast_strdup(ast_channel_name(tc));
2782
2784 ast_channel_unlock(chan);
2785
2786 /* Put channel in the list of outgoing thingies. */
2787 tmp->chan = tc;
2788 AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
2789 }
2790
2791 /* As long as we attempted to dial valid peers, don't throw a warning. */
2792 /* If a DAHDI peer is busy, out_chans will be empty so checking list size is misleading. */
2793 if (!num_dialed) {
2794 ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");
2795 if (continue_exec) {
2796 /* There is no point in having RetryDial try again */
2797 *continue_exec = 1;
2798 }
2799 strcpy(pa.status, "CHANUNAVAIL");
2800 res = 0;
2801 goto out;
2802 }
2803
2804 /*
2805 * PREDIAL: Run gosub on all of the callee channels
2806 *
2807 * We run the callee predial before ast_call() in case the user
2808 * wishes to do something on the newly created channels before
2809 * the channel does anything important.
2810 *
2811 * Inside the target gosub we will be able to do something with
2812 * the newly created channel name ie: now the calling channel
2813 * can know what channel will be used to call the destination
2814 * ex: now we will know that SIP/abc-123 is calling SIP/def-124
2815 */
2818 && !AST_LIST_EMPTY(&out_chans)) {
2819 const char *predial_callee;
2820
2822 predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
2823 if (predial_callee) {
2825 AST_LIST_TRAVERSE(&out_chans, tmp, node) {
2826 ast_pre_call(tmp->chan, predial_callee);
2827 }
2829 ast_free((char *) predial_callee);
2830 }
2831 }
2832
2833 /* Start all outgoing calls */
2834 AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
2835 res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
2836 ast_channel_lock(chan);
2837
2838 /* check the results of ast_call */
2839 if (res) {
2840 /* Again, keep going even if there's an error */
2841 ast_debug(1, "ast call on peer returned %d\n", res);
2842 ast_verb(3, "Couldn't call %s\n", tmp->interface);
2843 if (ast_channel_hangupcause(tmp->chan)) {
2845 }
2846 ast_channel_unlock(chan);
2847 ast_cc_call_failed(chan, tmp->chan, tmp->interface);
2848 ast_hangup(tmp->chan);
2849 tmp->chan = NULL;
2852 continue;
2853 }
2854
2855 ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
2856 ast_channel_unlock(chan);
2857
2858 ast_verb(3, "Called %s\n", tmp->interface);
2860
2861 /* If this line is up, don't try anybody else */
2862 if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
2863 break;
2864 }
2865 }
2867
2868 if (ast_strlen_zero(args.timeout)) {
2869 to = -1;
2870 } else {
2871 to = atoi(args.timeout);
2872 if (to > 0)
2873 to *= 1000;
2874 else {
2875 ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2876 to = -1;
2877 }
2878 }
2879
2880 outgoing = AST_LIST_FIRST(&out_chans);
2881 if (!outgoing) {
2882 strcpy(pa.status, "CHANUNAVAIL");
2883 if (fulldial == num_dialed) {
2884 res = -1;
2885 goto out;
2886 }
2887 } else {
2888 /* Our status will at least be NOANSWER */
2889 strcpy(pa.status, "NOANSWER");
2891 moh = 1;
2892 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2893 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2894 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2895 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2896 ast_channel_musicclass_set(chan, original_moh);
2897 } else {
2898 ast_moh_start(chan, NULL, NULL);
2899 }
2902 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2903 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2905 sentringing++;
2906 } else {
2908 }
2909 } else {
2911 sentringing++;
2912 }
2913 }
2914 }
2915
2916 peer = wait_for_answer(chan, &out_chans, &to, peerflags, opt_args, &pa, &num, &result,
2917 dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink,
2918 (ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
2919 ignore_cc, &forced_clid, &stored_clid, &config);
2920
2921 if (!peer) {
2922 if (result) {
2923 res = result;
2924 } else if (to) { /* Musta gotten hung up */
2925 res = -1;
2926 } else { /* Nobody answered, next please? */
2927 res = 0;
2928 }
2929 } else {
2930 const char *number;
2931 const char *name;
2932 int dial_end_raised = 0;
2933 int cause = -1;
2934
2935 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
2936 ast_answer(chan);
2937 }
2938
2939 /* Ah ha! Someone answered within the desired timeframe. Of course after this
2940 we will always return with -1 so that it is hung up properly after the
2941 conversation. */
2942
2944 && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
2945 cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
2946 if (cause <= 0) {
2947 if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
2948 cause = 0;
2949 } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
2950 || cause < 0) {
2951 ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
2952 opt_args[OPT_ARG_HANGUPCAUSE]);
2953 cause = -1;
2954 }
2955 }
2956 }
2957 hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
2958
2959 /* If appropriate, log that we have a destination channel and set the answer time */
2960
2961 ast_channel_lock(peer);
2963
2964 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
2965 if (ast_strlen_zero(number)) {
2966 number = NULL;
2967 } else {
2969 }
2970 ast_channel_unlock(peer);
2971
2972 ast_channel_lock(chan);
2974
2975 strcpy(pa.status, "ANSWER");
2976 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2977
2978 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
2979 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
2980
2982 ast_channel_unlock(chan);
2983
2984 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
2985 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
2986 ast_channel_sendurl( peer, args.url );
2987 }
2989 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
2990 ast_channel_publish_dial(chan, peer, NULL, pa.status);
2991 /* hang up on the callee -- he didn't want to talk anyway! */
2993 res = 0;
2994 goto out;
2995 }
2996 }
2997 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
2998 res = 0;
2999 } else {
3000 int digit = 0;
3001 struct ast_channel *chans[2];
3002 struct ast_channel *active_chan;
3003 char *calledfile = NULL, *callerfile = NULL;
3004 int calledstream = 0, callerstream = 0;
3005
3006 chans[0] = chan;
3007 chans[1] = peer;
3008
3009 /* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
3010 callerfile = opt_args[OPT_ARG_ANNOUNCE];
3011 calledfile = strsep(&callerfile, ":");
3012
3013 /* stream the file(s) */
3014 if (!ast_strlen_zero(calledfile)) {
3015 res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
3016 if (res) {
3017 res = 0;
3018 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
3019 } else {
3020 calledstream = 1;
3021 }
3022 }
3023 if (!ast_strlen_zero(callerfile)) {
3024 res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
3025 if (res) {
3026 res = 0;
3027 ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
3028 } else {
3029 callerstream = 1;
3030 }
3031 }
3032
3033 /* can't use ast_waitstream, because we're streaming two files at once, and can't block
3034 We'll need to handle both channels at once. */
3035
3037 while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
3038 int mspeer, mschan;
3039
3040 mspeer = ast_sched_wait(ast_channel_sched(peer));
3041 mschan = ast_sched_wait(ast_channel_sched(chan));
3042
3043 if (calledstream) {
3044 if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
3045 ast_stopstream(peer);
3046 calledstream = 0;
3047 }
3048 }
3049 if (callerstream) {
3050 if (mschan < 0 && !ast_channel_timingfunc(chan)) {
3051 ast_stopstream(chan);
3052 callerstream = 0;
3053 }
3054 }
3055
3056 if (!calledstream && !callerstream) {
3057 break;
3058 }
3059
3060 if (mspeer < 0)
3061 mspeer = 1000;
3062
3063 if (mschan < 0)
3064 mschan = 1000;
3065
3066 /* wait for the lowest maximum of the two */
3067 active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
3068 if (active_chan) {
3069 struct ast_channel *other_chan;
3070 struct ast_frame *fr = ast_read(active_chan);
3071
3072 if (!fr) {
3074 res = -1;
3075 goto done;
3076 }
3077 switch (fr->frametype) {
3078 case AST_FRAME_DTMF_END:
3079 digit = fr->subclass.integer;
3080 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
3081 ast_stopstream(peer);
3082 res = ast_senddigit(chan, digit, 0);
3083 }
3084 break;
3085 case AST_FRAME_CONTROL:
3086 switch (fr->subclass.integer) {
3087 case AST_CONTROL_HANGUP:
3088 ast_frfree(fr);
3090 res = -1;
3091 goto done;
3093 /* Pass COLP update to the other channel. */
3094 if (active_chan == chan) {
3095 other_chan = peer;
3096 } else {
3097 other_chan = chan;
3098 }
3099 if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)) {
3100 ast_indicate_data(other_chan, fr->subclass.integer,
3101 fr->data.ptr, fr->datalen);
3102 }
3103 break;
3104 default:
3105 break;
3106 }
3107 break;
3108 default:
3109 /* Ignore all others */
3110 break;
3111 }
3112 ast_frfree(fr);
3113 }
3116 }
3118 }
3119
3120 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
3121 /* chan and peer are going into the PBX; as such neither are considered
3122 * outgoing channels any longer */
3124
3126 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
3127 /* peer goes to the same context and extension as chan, so just copy info from chan*/
3128 ast_channel_lock(peer);
3135 ast_channel_unlock(peer);
3136 if (ast_pbx_start(peer)) {
3138 }
3139 if (continue_exec)
3140 *continue_exec = 1;
3141 res = 0;
3142 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3143 goto done;
3144 }
3145
3147 const char *gosub_result_peer;
3148 char *gosub_argstart;
3149 char *gosub_args = NULL;
3150 int gosub_res = -1;
3151
3153 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
3154 if (gosub_argstart) {
3155 const char *what_is_s = "s";
3156 *gosub_argstart = 0;
3157 if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
3158 ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
3159 what_is_s = "~~s~~";
3160 }
3161 if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
3162 gosub_args = NULL;
3163 }
3164 *gosub_argstart = ',';
3165 } else {
3166 const char *what_is_s = "s";
3167 if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
3168 ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
3169 what_is_s = "~~s~~";
3170 }
3171 if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
3172 gosub_args = NULL;
3173 }
3174 }
3175 if (gosub_args) {
3176 gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
3177 ast_free(gosub_args);
3178 } else {
3179 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
3180 }
3181
3182 ast_channel_lock_both(chan, peer);
3183
3184 if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
3185 char *gosub_transfer_dest;
3186 char *gosub_result = ast_strdupa(gosub_result_peer);
3187 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
3188
3189 /* Inherit return value from the peer, so it can be used in the master */
3190 if (gosub_retval) {
3191 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
3192 }
3193
3194 ast_channel_unlock(peer);
3195 ast_channel_unlock(chan);
3196
3197 if (!strcasecmp(gosub_result, "BUSY")) {
3198 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3199 ast_set_flag64(peerflags, OPT_GO_ON);
3200 gosub_res = -1;
3201 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
3202 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3203 ast_set_flag64(peerflags, OPT_GO_ON);
3204 gosub_res = -1;
3205 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
3206 /* Hangup peer and continue with the next extension priority. */
3207 ast_set_flag64(peerflags, OPT_GO_ON);
3208 gosub_res = -1;
3209 } else if (!strcasecmp(gosub_result, "ABORT")) {
3210 /* Hangup both ends unless the caller has the g flag */
3211 gosub_res = -1;
3212 } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
3213 gosub_transfer_dest = gosub_result + 5;
3214 gosub_res = -1;
3215 /* perform a transfer to a new extension */
3216 if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
3217 ast_replace_subargument_delimiter(gosub_transfer_dest);
3218 }
3219 if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
3220 ast_set_flag64(peerflags, OPT_GO_ON);
3221 }
3222 }
3223 if (gosub_res) {
3224 res = gosub_res;
3225 if (!dial_end_raised) {
3226 ast_channel_publish_dial(chan, peer, NULL, gosub_result);
3227 dial_end_raised = 1;
3228 }
3229 }
3230 } else {
3231 ast_channel_unlock(peer);
3232 ast_channel_unlock(chan);
3233 }
3234 }
3235
3236 if (!res) {
3237
3238 /* None of the Dial options changed our status; inform
3239 * everyone that this channel answered
3240 */
3241 if (!dial_end_raised) {
3242 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3243 dial_end_raised = 1;
3244 }
3245
3246 if (!ast_tvzero(calldurationlimit)) {
3247 struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
3248 ast_channel_lock(peer);
3249 ast_channel_whentohangup_set(peer, &whentohangup);
3250 ast_channel_unlock(peer);
3251 }
3252 if (!ast_strlen_zero(dtmfcalled)) {
3253 ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
3254 res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
3255 }
3256 if (!ast_strlen_zero(dtmfcalling)) {
3257 ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
3258 res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
3259 }
3260 }
3261
3262 if (res) { /* some error */
3263 if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
3265 }
3266 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3268 || ast_pbx_start(peer)) {
3270 }
3271 res = -1;
3272 } else {
3273 if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
3274 ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
3275 if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
3276 ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
3277 if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
3278 ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
3279 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
3280 ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
3281 if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
3282 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
3283 if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
3284 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
3285 if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
3286 ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
3287 if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
3288 ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
3289 if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
3290 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
3291 if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
3292 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
3293
3294 config.end_bridge_callback = end_bridge_callback;
3295 config.end_bridge_callback_data = chan;
3296 config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
3297
3298 if (moh) {
3299 moh = 0;
3300 ast_moh_stop(chan);
3301 } else if (sentringing) {
3302 sentringing = 0;
3303 ast_indicate(chan, -1);
3304 }
3305 /* Be sure no generators are left on it and reset the visible indication */
3308 /* Make sure channels are compatible */
3309 res = ast_channel_make_compatible(chan, peer);
3310 if (res < 0) {
3311 ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", ast_channel_name(chan), ast_channel_name(peer));
3313 res = -1;
3314 goto done;
3315 }
3316 if (opermode) {
3317 struct oprmode oprmode;
3318
3319 oprmode.peer = peer;
3320 oprmode.mode = opermode;
3321
3323 }
3324 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3325
3326 res = ast_bridge_call(chan, peer, &config);
3327 }
3328 }
3329out:
3330 if (moh) {
3331 moh = 0;
3332 ast_moh_stop(chan);
3333 } else if (sentringing) {
3334 sentringing = 0;
3335 ast_indicate(chan, -1);
3336 }
3337
3338 if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3340 if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3341 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
3342 } else {
3343 ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
3344 }
3345 }
3346
3348 /* forward 'answered elsewhere' if we received it */
3350 hanguptreecause = AST_CAUSE_ANSWERED_ELSEWHERE;
3351 } else if (pa.canceled) { /* Caller canceled */
3352 if (ast_channel_hangupcause(chan))
3353 hanguptreecause = ast_channel_hangupcause(chan);
3354 else
3355 hanguptreecause = AST_CAUSE_NORMAL_CLEARING;
3356 }
3357 hanguptree(&out_chans, NULL, hanguptreecause);
3358 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3359 ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
3360
3361 if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
3362 if (!ast_tvzero(calldurationlimit))
3363 memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
3364 res = 0;
3365 }
3366
3367done:
3368 if (config.answer_topology) {
3369 ast_trace(2, "%s Cleaning up topology: %p %s\n",
3370 peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology,
3371 ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP)));
3372
3373 /*
3374 * At this point, the channel driver that answered should have bumped the
3375 * topology refcount for itself. Here we're cleaning up the reference we added
3376 * in wait_for_answer().
3377 */
3378 ast_stream_topology_free(config.answer_topology);
3379 }
3380 if (config.warning_sound) {
3381 ast_free((char *)config.warning_sound);
3382 }
3383 if (config.end_sound) {
3384 ast_free((char *)config.end_sound);
3385 }
3386 if (config.start_sound) {
3387 ast_free((char *)config.start_sound);
3388 }
3389 ast_ignore_cc(chan);
3390 SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan));
3391}
3392
3393static int dial_exec(struct ast_channel *chan, const char *data)
3394{
3395 struct ast_flags64 peerflags;
3396
3397 memset(&peerflags, 0, sizeof(peerflags));
3398
3399 return dial_exec_full(chan, data, &peerflags, NULL);
3400}
3401
3402static int retrydial_exec(struct ast_channel *chan, const char *data)
3403{
3404 char *parse;
3405 const char *context = NULL;
3406 int sleepms = 0, loops = 0, res = -1;
3407 struct ast_flags64 peerflags = { 0, };
3409 AST_APP_ARG(announce);
3410 AST_APP_ARG(sleep);
3411 AST_APP_ARG(retries);
3412 AST_APP_ARG(dialdata);
3413 );
3414
3415 if (ast_strlen_zero(data)) {
3416 ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
3417 return -1;
3418 }
3419
3420 parse = ast_strdupa(data);
3422
3423 if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
3424 sleepms *= 1000;
3425
3426 if (!ast_strlen_zero(args.retries)) {
3427 loops = atoi(args.retries);
3428 }
3429
3430 if (!args.dialdata) {
3431 ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
3432 goto done;
3433 }
3434
3435 if (sleepms < 1000)
3436 sleepms = 10000;
3437
3438 if (!loops)
3439 loops = -1; /* run forever */
3440
3441 ast_channel_lock(chan);
3442 context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
3444 ast_channel_unlock(chan);
3445
3446 res = 0;
3447 while (loops) {
3448 int continue_exec;
3449
3450 ast_channel_data_set(chan, "Retrying");
3452 ast_moh_stop(chan);
3453
3454 res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
3455 if (continue_exec)
3456 break;
3457
3458 if (res == 0) {
3459 if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
3460 if (!ast_strlen_zero(args.announce)) {
3461 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3462 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3464 } else
3465 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3466 }
3467 if (!res && sleepms) {
3469 ast_moh_start(chan, NULL, NULL);
3470 res = ast_waitfordigit(chan, sleepms);
3471 }
3472 } else {
3473 if (!ast_strlen_zero(args.announce)) {
3474 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3475 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3476 res = ast_waitstream(chan, "");
3477 } else
3478 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3479 }
3480 if (sleepms) {
3482 ast_moh_start(chan, NULL, NULL);
3483 if (!res)
3484 res = ast_waitfordigit(chan, sleepms);
3485 }
3486 }
3487 }
3488
3489 if (res < 0 || res == AST_PBX_INCOMPLETE) {
3490 break;
3491 } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
3492 if (onedigit_goto(chan, context, (char) res, 1)) {
3493 res = 0;
3494 break;
3495 }
3496 }
3497 loops--;
3498 }
3499 if (loops == 0)
3500 res = 0;
3501 else if (res == 1)
3502 res = 0;
3503
3505 ast_moh_stop(chan);
3506 done:
3507 return res;
3508}
3509
3510static int unload_module(void)
3511{
3512 int res;
3513
3516
3517 return res;
3518}
3519
3520static int load_module(void)
3521{
3522 int res;
3523
3526
3527 return res;
3528}
3529
3531 .support_level = AST_MODULE_SUPPORT_CORE,
3532 .load = load_module,
3533 .unload = unload_module,
3534 .requires = "ccss",
Generic Advice of Charge encode and decode routines.
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition: aoc.c:313
enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
get the message type, AOC-D, AOC-E, or AOC Request
Definition: aoc.c:892
struct ast_aoc_decoded * ast_aoc_decode(struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
decodes an encoded aoc payload.
Definition: aoc.c:449
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:307
struct ast_aoc_encoded * ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
encodes a decoded aoc structure so it can be passed on the wire
Definition: aoc.c:650
@ AST_AOC_S
Definition: aoc.h:64
char digit
#define DIAL_STILLGOING
Definition: app_dial.c:693
static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
Definition: app_dial.c:2265
#define OPT_PREDIAL_CALLER
Definition: app_dial.c:704
@ OPT_RESETCDR
Definition: app_dial.c:661
@ OPT_SCREEN_NOINTRO
Definition: app_dial.c:671
@ OPT_DTMF_EXIT
Definition: app_dial.c:662
@ OPT_ANNOUNCE
Definition: app_dial.c:660
@ OPT_CALLEE_PARK
Definition: app_dial.c:684
@ OPT_DURATION_LIMIT
Definition: app_dial.c:669
@ OPT_SCREEN_NOCALLERID
Definition: app_dial.c:672
@ OPT_IGNORE_FORWARDING
Definition: app_dial.c:686
@ OPT_OPERMODE
Definition: app_dial.c:683
@ OPT_DURATION_STOP
Definition: app_dial.c:677
@ OPT_GO_ON
Definition: app_dial.c:665
@ OPT_RINGBACK
Definition: app_dial.c:676
@ OPT_GOTO
Definition: app_dial.c:682
@ OPT_IGNORE_CONNECTEDLINE
Definition: app_dial.c:673
@ OPT_CALLEE_TRANSFER
Definition: app_dial.c:678
@ OPT_SENDDTMF
Definition: app_dial.c:663
@ OPT_CALLER_MIXMONITOR
Definition: app_dial.c:689
@ OPT_CALLER_PARK
Definition: app_dial.c:685
@ OPT_CALLER_MONITOR
Definition: app_dial.c:681
@ OPT_CALLEE_MONITOR
Definition: app_dial.c:680
@ OPT_CALLEE_GOSUB
Definition: app_dial.c:687
@ OPT_CALLER_HANGUP
Definition: app_dial.c:667
@ OPT_FORCECLID
Definition: app_dial.c:664
@ OPT_CALLEE_HANGUP
Definition: app_dial.c:666
@ OPT_SCREENING
Definition: app_dial.c:674
@ OPT_MUSICBACK
Definition: app_dial.c:670
@ OPT_CALLER_TRANSFER
Definition: app_dial.c:679
@ OPT_CALLEE_MIXMONITOR
Definition: app_dial.c:688
@ OPT_ORIGINAL_CLID
Definition: app_dial.c:668
@ OPT_PRIVACY
Definition: app_dial.c:675
#define OPT_CANCEL_ELSEWHERE
Definition: app_dial.c:696
static const char * get_cid_name(char *name, int namelen, struct ast_channel *chan)
Definition: app_dial.c:888
static const char app[]
Definition: app_dial.c:656
static const struct ast_app_option dial_exec_options[128]
Definition: app_dial.c:776
#define OPT_PEER_H
Definition: app_dial.c:697
static void do_forward(struct chanlist *o, struct cause_args *num, struct ast_flags64 *peerflags, int single, int caller_entertained, int *to, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
Definition: app_dial.c:918
#define OPT_PREDIAL_CALLEE
Definition: app_dial.c:703
#define DIAL_CALLERID_ABSENT
Definition: app_dial.c:695
#define OPT_FORCE_CID_PRES
Definition: app_dial.c:701
static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
Definition: app_dial.c:2243
#define CAN_EARLY_BRIDGE(flags, chan, peer)
Definition: app_dial.c:778
#define OPT_RING_WITH_EARLY_MEDIA
Definition: app_dial.c:705
#define OPT_FORCE_CID_TAG
Definition: app_dial.c:700
#define OPT_HEARPULSING
Definition: app_dial.c:707
static int dial_exec(struct ast_channel *chan, const char *data)
Definition: app_dial.c:3393
#define DIAL_NOFORWARDHTML
Definition: app_dial.c:694
static struct ast_channel * wait_for_answer(struct ast_channel *in, struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags, char *opt_args[], struct privacy_args *pa, const struct cause_args *num_in, int *result, char *dtmf_progress, char *mf_progress, char *mf_wink, char *sf_progress, char *sf_wink, const int hearpulsing, const int ignore_cc, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid, struct ast_bridge_config *config)
Definition: app_dial.c:1183
#define AST_MAX_WATCHERS
Definition: app_dial.c:839
#define OPT_CANCEL_TIMEOUT
Definition: app_dial.c:699
static void chanlist_free(struct chanlist *outgoing)
Definition: app_dial.c:813
static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
Definition: app_dial.c:1130
static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
Definition: app_dial.c:873
static const char rapp[]
Definition: app_dial.c:657
static void handle_cause(int cause, struct cause_args *num)
Definition: app_dial.c:851
static int setup_privacy_args(struct privacy_args *pa, struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
returns 1 if successful, 0 or <0 if the caller should 'goto out'
Definition: app_dial.c:2088
static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
Definition: app_dial.c:1170
static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
Definition: app_dial.c:1150
static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
Definition: app_dial.c:1911
#define OPT_HANGUPCAUSE
Definition: app_dial.c:706
static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
Definition: app_dial.c:821
@ OPT_ARG_CALLEE_GO_ON
Definition: app_dial.c:717
@ OPT_ARG_SENDDTMF
Definition: app_dial.c:711
@ OPT_ARG_DURATION_STOP
Definition: app_dial.c:719
@ OPT_ARG_PREDIAL_CALLEE
Definition: app_dial.c:726
@ OPT_ARG_RINGBACK
Definition: app_dial.c:715
@ OPT_ARG_MUSICBACK
Definition: app_dial.c:714
@ OPT_ARG_CALLEE_GOSUB
Definition: app_dial.c:716
@ OPT_ARG_HANGUPCAUSE
Definition: app_dial.c:728
@ OPT_ARG_FORCE_CID_PRES
Definition: app_dial.c:725
@ OPT_ARG_ANNOUNCE
Definition: app_dial.c:710
@ OPT_ARG_GOTO
Definition: app_dial.c:712
@ OPT_ARG_DURATION_LIMIT
Definition: app_dial.c:713
@ OPT_ARG_ORIGINAL_CLID
Definition: app_dial.c:722
@ OPT_ARG_OPERMODE
Definition: app_dial.c:720
@ OPT_ARG_FORCECLID
Definition: app_dial.c:723
@ OPT_ARG_PREDIAL_CALLER
Definition: app_dial.c:727
@ OPT_ARG_ARRAY_SIZE
Definition: app_dial.c:730
@ OPT_ARG_PRIVACY
Definition: app_dial.c:718
@ OPT_ARG_SCREEN_NOINTRO
Definition: app_dial.c:721
@ OPT_ARG_FORCE_CID_TAG
Definition: app_dial.c:724
static int load_module(void)
Definition: app_dial.c:3520
static int retrydial_exec(struct ast_channel *chan, const char *data)
Definition: app_dial.c:3402
static int dial_handle_playtones(struct ast_channel *chan, const char *data)
Definition: app_dial.c:2203
static void end_bridge_callback(void *data)
Definition: app_dial.c:2187
static int unload_module(void)
Definition: app_dial.c:3510
#define OPT_CALLER_ANSWER
Definition: app_dial.c:702
static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition: app_dial.c:2199
static int valid_priv_reply(struct ast_flags64 *opts, int res)
Definition: app_dial.c:1941
#define OPT_CALLEE_GO_ON
Definition: app_dial.c:698
jack_status_t status
Definition: app_jack.c:146
const char * str
Definition: app_jack.c:147
static int silencethreshold
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
After Bridge Execution API.
int ast_bridge_setup_after_goto(struct ast_channel *chan)
Setup any after bridge goto location to begin execution.
Definition: bridge_after.c:435
void ast_bridge_set_after_go_on(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *parseable_goto)
Set channel to go on in the dialplan after the bridge.
Definition: bridge_after.c:622
void ast_bridge_set_after_h(struct ast_channel *chan, const char *context)
Set channel to run the h exten after the bridge.
Definition: bridge_after.c:617
static int tmp()
Definition: bt_open.c:389
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN
Definition: callerid.h:426
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
Definition: callerid.c:1244
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1063
@ AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER
Definition: callerid.h:540
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition: callerid.c:1002
Internal Asterisk hangup causes.
#define AST_CAUSE_CONGESTION
Definition: causes.h:153
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition: causes.h:114
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:100
#define AST_CAUSE_UNREGISTERED
Definition: causes.h:154
#define AST_CAUSE_BUSY
Definition: causes.h:149
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:109
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:106
Call Completion Supplementary Services API.
void ast_cc_call_failed(struct ast_channel *incoming, struct ast_channel *outgoing, const char *const dialstring)
Make CCBS available in the case that ast_call fails.
Definition: ccss.c:4164
void ast_ignore_cc(struct ast_channel *chan)
Mark the channel to ignore further CC activity.
Definition: ccss.c:3685
int ast_cc_is_recall(struct ast_channel *chan, int *core_id, const char *const monitor_type)
Decide if a call to a particular channel is a CC recall.
Definition: ccss.c:3405
void ast_handle_cc_control_frame(struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data)
Properly react to a CC control frame.
Definition: ccss.c:2293
int ast_cc_completed(struct ast_channel *chan, const char *const debug,...)
Indicate recall has been acknowledged.
Definition: ccss.c:3807
void ast_cc_busy_interface(struct ast_channel *inbound, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, void *private_data)
Callback made from ast_cc_callback for certain channel types.
Definition: ccss.c:4197
void ast_cc_extension_monitor_add_dialstring(struct ast_channel *incoming, const char *const dialstring, const char *const device_name)
Add a child dialstring to an extension monitor.
Definition: ccss.c:1983
int ast_cc_call_init(struct ast_channel *chan, int *ignore_cc)
Start the CC process on a call.
Definition: ccss.c:2386
int ast_cc_failed(int core_id, const char *const debug,...)
Indicate failure has occurred.
Definition: ccss.c:3844
int ast_cc_callback(struct ast_channel *inbound, const char *const tech, const char *const dest, ast_cc_callback_fn callback)
Run a callback for potential matching destinations.
Definition: ccss.c:4209
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition: cdr.c:3660
static int priority
static PGresult * result
Definition: cel_pgsql.c:84
static const char config[]
Definition: chan_ooh323.c:111
General Asterisk PBX channel definitions.
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3169
int ast_str2cause(const char *name) attribute_pure
Convert the string form of a cause code to a number.
Definition: channel.c:625
const char * ast_channel_name(const struct ast_channel *chan)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
Get a device name given its channel structure.
Definition: channel.c:10488
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition: channel.c:2116
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6454
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition: channel.c:11017
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition: channel.c:1751
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame)
Run a connected line interception subroutine and update a channel's connected line information.
Definition: channel.c:10330
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1638
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2535
@ AST_CHANNEL_REQUESTOR_BRIDGE_PEER
Definition: channel.h:1477
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Set the connected line information in the Asterisk channel.
Definition: channel.c:8301
const char * ast_channel_musicclass(const struct ast_channel *chan)
int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen)
Sends HTML on given channel Send HTML or URL on link.
Definition: channel.c:6621
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition: channel.c:2066
int64_t ast_channel_get_up_time_ms(struct ast_channel *chan)
Obtain how long it has been since the channel was answered in ms.
Definition: channel.c:2829
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name...
Definition: channel.c:7365
struct ast_channel * ast_waitfor_n(struct ast_channel **chan, int n, int *ms)
Waits for input on a group of channels Wait for input on an array of channels for a given # of millis...
Definition: channel.c:3151
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4967
#define ast_channel_lock(chan)
Definition: channel.h:2922
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition: channel.c:6713
void ast_channel_data_set(struct ast_channel *chan, const char *value)
@ AST_FEATURE_AUTOMIXMON
Definition: channel.h:1069
@ AST_FEATURE_REDIRECT
Definition: channel.h:1064
@ AST_FEATURE_PARKCALL
Definition: channel.h:1068
@ AST_FEATURE_AUTOMON
Definition: channel.h:1067
@ AST_FEATURE_DISCONNECT
Definition: channel.h:1065
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2025
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
Set the connected line information based on another connected line source.
Definition: channel.c:2048
int ast_channel_priority(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2362
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6427
const char * ast_channel_context(const struct ast_channel *chan)
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2887
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:459
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5137
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4250
void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Indicate that the connected line information has changed.
Definition: channel.c:9086
ast_channel_adsicpe
Definition: channel.h:868
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
Initialize the given caller structure using the given guide for a set update operation.
Definition: channel.c:1993
void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide)
Initialize the given party id structure using the given guide for a set update operation.
Definition: channel.c:1774
struct timeval ast_channel_creationtime(struct ast_channel *chan)
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
Run a redirecting interception subroutine and update a channel's redirecting information.
Definition: channel.c:10375
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6764
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
Parse connected line indication frame data.
Definition: channel.c:8778
struct ast_channel * ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel (specifying stream topology)
Definition: channel.c:6352
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition: channel.c:6616
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
int ast_channel_hangupcause(const struct ast_channel *chan)
int64_t ast_channel_get_duration_ms(struct ast_channel *chan)
Obtain how long it's been, in milliseconds, since the channel was created.
Definition: channel.c:2814
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4646
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
Definition: channel.c:11010
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Indicate that the redirecting id has changed.
Definition: channel.c:10276
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
#define AST_CHANNEL_NAME
Definition: channel.h:171
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:1685
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2016
int ast_channel_sendurl(struct ast_channel *channel, const char *url)
Sends a URL on a given link Send URL on link.
Definition: channel.c:6628
const char * ast_channel_language(const struct ast_channel *chan)
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
Definition: channel.c:612
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition: channel.c:2173
void ast_channel_context_set(struct ast_channel *chan, const char *value)
struct ast_sched_context * ast_channel_sched(const struct ast_channel *chan)
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8286
const char * ast_channel_call_forward(const struct ast_channel *chan)
@ AST_FLAG_OUTGOING
Definition: channel.h:999
@ AST_FLAG_END_DTMF_ONLY
Definition: channel.h:1007
@ AST_FLAG_MOH
Definition: channel.h:991
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
int ast_pre_call(struct ast_channel *chan, const char *sub_args)
Execute a Gosub call on the channel before a call is placed.
Definition: channel.c:6437
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7415
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation.
Definition: channel.c:2039
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer)
Put chan into autoservice while hanging up peer.
Definition: autoservice.c:342
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2799
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels together (early)
Definition: channel.c:7405
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4270
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define AST_MAX_EXTENSION
Definition: channel.h:134
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2129
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
Dialing API.
const char * ast_hangup_cause_to_dial_status(int hangup_cause)
Convert a hangup cause to a publishable dial status.
Definition: dial.c:749
Convenient Signal Processing routines.
@ THRESHOLD_SILENCE
Definition: dsp.h:73
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:1999
char connected
Definition: eagi_proxy.c:82
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Call Parking and Pickup API Includes code and algorithms from the Zapata library.
int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
Bridge a call, optionally allowing redirection.
Definition: features.c:685
int ast_bridge_timelimit(struct ast_channel *chan, struct ast_bridge_config *config, char *parse, struct timeval *calldurationlimit)
parse L option and read associated channel variables to set warning, warning frequency,...
Definition: features.c:857
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1293
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition: file.c:1129
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
Definition: file.c:1141
#define AST_DIGIT_ANY
Definition: file.h:48
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1839
static const char name[]
Definition: format_mp3.c:68
FrameHook Architecture.
void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:278
#define AST_APP_ARG(name)
Define an application argument.
int ast_sf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
Send a string of SF digits to a channel.
Definition: main/app.c:1097
#define END_OPTIONS
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence_ms, const char *path)
Record a file based on input from a channel. Use default accept and cancel DTMF. This function will p...
Definition: main/app.c:2144
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
Set the group for a channel, splitting the provided data into group and category, if specified.
Definition: main/app.c:2183
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define BEGIN_OPTIONS
int ast_play_and_wait(struct ast_channel *chan, const char *fn)
Play a stream and wait for a digit, returning the digit that was pressed.
Definition: main/app.c:1616
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:297
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
Definition: main/app.c:1127
int ast_mf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int between, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
Send a string of MF digits to a channel.
Definition: main/app.c:1113
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3061
char * strsep(char **str, const char *delims)
Configuration File Parser.
#define AST_FEATURE_MAX_LEN
int ast_get_builtin_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a builtin feature.
#define AST_FRAME_DTMF
#define AST_OPTION_OPRMODE
#define ast_frfree(fr)
@ AST_FRAME_VIDEO
@ AST_FRAME_HTML
@ AST_FRAME_IMAGE
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_VOICE
@ AST_FRAME_CONTROL
@ AST_FRAME_TEXT
@ AST_CONTROL_SRCUPDATE
@ AST_CONTROL_WINK
@ AST_CONTROL_PROGRESS
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_BUSY
@ AST_CONTROL_UNHOLD
@ AST_CONTROL_VIDUPDATE
@ AST_CONTROL_PROCEEDING
@ AST_CONTROL_REDIRECTING
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_CC
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_HANGUP
@ AST_CONTROL_HOLD
@ AST_CONTROL_CONNECTED_LINE
@ AST_CONTROL_FLASH
@ AST_CONTROL_AOC