Asterisk - The Open Source Telephony Project GIT-master-a63eec2
Loading...
Searching...
No Matches
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 <since>
74 <version>0.1.0</version>
75 </since>
76 <synopsis>
77 Attempt to connect to another device or endpoint and bridge the call.
78 </synopsis>
79 <syntax>
80 <parameter name="Technology/Resource" required="false" argsep="&amp;">
81 <argument name="Technology/Resource" required="true">
82 <para>Specification of the device(s) to dial. These must be in the format of
83 <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
84 represents a particular channel driver, and <replaceable>Resource</replaceable>
85 represents a resource available to that particular channel driver.</para>
86 </argument>
87 <argument name="Technology2/Resource2" required="false" multiple="true">
88 <para>Optional extra devices to dial in parallel</para>
89 <para>If you need more than one enter them as
90 Technology2/Resource2&amp;Technology3/Resource3&amp;.....</para>
91 </argument>
92 <xi:include xpointer="xpointer(/docs/info[@name='Dial_Resource'])" />
93 </parameter>
94 <parameter name="timeout" required="false" argsep="^">
95 <para>Specifies the number of seconds we attempt to dial the specified devices.</para>
96 <para>If not specified, this defaults to 136 years.</para>
97 <para>If a second argument is specified, this controls the number of seconds we attempt to dial the specified devices
98 without receiving early media or ringing. If neither progress, ringing, nor voice frames have been received when this
99 timeout expires, the call will be treated as a CHANUNAVAIL. This can be used to skip destinations that may not be responsive.</para>
100 <para>The timeouts need not be whole numbers; both arguments accept fractional seconds.</para>
101 </parameter>
102 <parameter name="options" required="false">
103 <optionlist>
104 <option name="A" argsep=":">
105 <argument name="x">
106 <para>The file to play to the called party</para>
107 </argument>
108 <argument name="y">
109 <para>The file to play to the calling party</para>
110 </argument>
111 <para>Play an announcement to the called and/or calling parties, where <replaceable>x</replaceable>
112 is the prompt to be played to the called party and <replaceable>y</replaceable> is the prompt
113 to be played to the caller. The files may be different and will be played to each party
114 simultaneously.</para>
115 </option>
116 <option name="a">
117 <para>Immediately answer the calling channel when the called channel answers in
118 all cases. Normally, the calling channel is answered when the called channel
119 answers, but when options such as <literal>A()</literal> and
120 <literal>M()</literal> are used, the calling channel is
121 not answered until all actions on the called channel (such as playing an
122 announcement) are completed. This option can be used to answer the calling
123 channel before doing anything on the called channel. You will rarely need to use
124 this option, the default behavior is adequate in most cases.</para>
125 </option>
126 <option name="b" argsep="^">
127 <para>Before initiating an outgoing call, <literal>Gosub</literal> to the specified
128 location using the newly created channel. The <literal>Gosub</literal> will be
129 executed for each destination channel.</para>
130 <argument name="context" required="false" />
131 <argument name="exten" required="false" />
132 <argument name="priority" required="true" hasparams="optional" argsep="^">
133 <argument name="arg1" multiple="true" required="true" />
134 <argument name="argN" />
135 </argument>
136 </option>
137 <option name="B" argsep="^">
138 <para>Before initiating the outgoing call(s), <literal>Gosub</literal> to the
139 specified location using the current channel.</para>
140 <argument name="context" required="false" />
141 <argument name="exten" required="false" />
142 <argument name="priority" required="true" hasparams="optional" argsep="^">
143 <argument name="arg1" multiple="true" required="true" />
144 <argument name="argN" />
145 </argument>
146 </option>
147 <option name="C">
148 <para>Reset the call detail record (CDR) for this call.</para>
149 </option>
150 <option name="c">
151 <para>If the Dial() application cancels this call, always set
152 <variable>HANGUPCAUSE</variable> to 'answered elsewhere'</para>
153 </option>
154 <option name="d">
155 <para>Allow the calling user to dial a 1 digit extension while waiting for
156 a call to be answered. Exit to that extension if it exists in the
157 current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
158 if it exists.</para>
159 <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
160 connected. If you wish to use this option with these phones, you
161 can use the <literal>Answer</literal> application before dialing.</para>
162 </option>
163 <option name="D" argsep=":">
164 <argument name="called" />
165 <argument name="calling" />
166 <argument name="progress" />
167 <argument name="mfprogress" />
168 <argument name="mfwink" />
169 <argument name="sfprogress" />
170 <argument name="sfwink" />
171 <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
172 party has answered, but before the call gets bridged. The
173 <replaceable>called</replaceable> DTMF string is sent to the called party, and the
174 <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
175 can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
176 to the called party immediately after receiving a <literal>PROGRESS</literal> message.</para>
177 <para>See <literal>SendDTMF</literal> for valid digits.</para>
178 <para>If <replaceable>mfprogress</replaceable> is specified, its MF is sent
179 to the called party immediately after receiving a <literal>PROGRESS</literal> message.
180 If <replaceable>mfwink</replaceable> is specified, its MF is sent
181 to the called party immediately after receiving a <literal>WINK</literal> message.</para>
182 <para>See <literal>SendMF</literal> for valid digits.</para>
183 <para>If <replaceable>sfprogress</replaceable> is specified, its SF is sent
184 to the called party immediately after receiving a <literal>PROGRESS</literal> message.
185 If <replaceable>sfwink</replaceable> is specified, its SF is sent
186 to the called party immediately after receiving a <literal>WINK</literal> message.</para>
187 <para>See <literal>SendSF</literal> for valid digits.</para>
188 </option>
189 <option name="E">
190 <para>Enable echoing of sent MF or SF digits back to caller (e.g. "hearpulsing").
191 Used in conjunction with the D option.</para>
192 </option>
193 <option name="e">
194 <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
195 </option>
196 <option name="f">
197 <argument name="x" required="false" />
198 <para>If <replaceable>x</replaceable> is not provided, force the CallerID sent on a call-forward or
199 deflection to the dialplan extension of this <literal>Dial()</literal> using a dialplan <literal>hint</literal>.
200 For example, some PSTNs do not allow CallerID to be set to anything
201 other than the numbers assigned to you.
202 If <replaceable>x</replaceable> is provided, force the CallerID sent to <replaceable>x</replaceable>.</para>
203 </option>
204 <option name="F" argsep="^">
205 <argument name="context" required="false" />
206 <argument name="exten" required="false" />
207 <argument name="priority" required="true" />
208 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party
209 to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
210 <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
211 prefixed with one or two underbars ('_').</para>
212 </option>
213 <option name="F">
214 <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party to the next priority of the current extension
215 and <emphasis>start</emphasis> execution at that location.</para>
216 <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
217 prefixed with one or two underbars ('_').</para>
218 <para>NOTE: Using this option from a Gosub() might not make sense as there would be no return points.</para>
219 </option>
220 <option name="g">
221 <para>Proceed with dialplan execution at the next priority in the current extension if the
222 destination channel hangs up.</para>
223 </option>
224 <option name="G" argsep="^">
225 <argument name="context" required="false" />
226 <argument name="exten" required="false" />
227 <argument name="priority" required="true" />
228 <para>If the call is answered, transfer the calling party to
229 the specified <replaceable>priority</replaceable> and the called party to the specified
230 <replaceable>priority</replaceable> plus one.</para>
231 <para>NOTE: You cannot use any additional action post answer options in conjunction with this option.</para>
232 </option>
233 <option name="h">
234 <para>Allow the called party to hang up by sending the DTMF sequence
235 defined for disconnect in <filename>features.conf</filename>.</para>
236 </option>
237 <option name="H">
238 <para>Allow the calling party to hang up by sending the DTMF sequence
239 defined for disconnect in <filename>features.conf</filename>.</para>
240 <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
241 connected. If you wish to allow DTMF disconnect before the dialed
242 party answers with these phones, you can use the <literal>Answer</literal>
243 application before dialing.</para>
244 </option>
245 <option name="i">
246 <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
247 </option>
248 <option name="I">
249 <para>Asterisk will ignore any connected line update requests or any redirecting party
250 update requests it may receive on this dial attempt.</para>
251 </option>
252 <option name="j">
253 <para>Use the initial stream topology of the caller for outgoing channels, even if the caller topology has changed.</para>
254 <para>NOTE: For this option to work, it has to be present in all invocations of Dial that the caller channel goes through.</para>
255 </option>
256 <option name="k">
257 <para>Allow the called party to enable parking of the call by sending
258 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
259 </option>
260 <option name="K">
261 <para>Allow the calling party to enable parking of the call by sending
262 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
263 </option>
264 <option name="L" argsep=":">
265 <argument name="x" required="true">
266 <para>Maximum call time, in milliseconds</para>
267 </argument>
268 <argument name="y">
269 <para>Warning time, in milliseconds</para>
270 </argument>
271 <argument name="z">
272 <para>Repeat time, in milliseconds</para>
273 </argument>
274 <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
275 left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
276 <para>This option is affected by the following variables:</para>
277 <variablelist>
278 <variable name="LIMIT_PLAYAUDIO_CALLER">
279 <value name="yes" default="true" />
280 <value name="no" />
281 <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
282 </variable>
283 <variable name="LIMIT_PLAYAUDIO_CALLEE">
284 <value name="yes" />
285 <value name="no" default="true"/>
286 <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
287 </variable>
288 <variable name="LIMIT_TIMEOUT_FILE">
289 <value name="filename"/>
290 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
291 If not set, the time remaining will be announced.</para>
292 </variable>
293 <variable name="LIMIT_CONNECT_FILE">
294 <value name="filename"/>
295 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
296 If not set, the time remaining will be announced.</para>
297 </variable>
298 <variable name="LIMIT_WARNING_FILE">
299 <value name="filename"/>
300 <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
301 a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
302 </variable>
303 </variablelist>
304 </option>
305 <option name="m">
306 <argument name="class" required="false"/>
307 <para>Provide hold music to the calling party until a requested
308 channel answers. A specific music on hold <replaceable>class</replaceable>
309 (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
310 </option>
311 <option name="n">
312 <argument name="delete">
313 <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
314 the recorded introduction will not be deleted if the caller hangs up while the remote party has not
315 yet answered.</para>
316 <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
317 always be deleted.</para>
318 </argument>
319 <para>This option is a modifier for the call screening/privacy mode. (See the
320 <literal>p</literal> and <literal>P</literal> options.) It specifies
321 that no introductions are to be saved in the <directory>priv-callerintros</directory>
322 directory.</para>
323 </option>
324 <option name="N">
325 <para>This option is a modifier for the call screening/privacy mode. It specifies
326 that if CallerID is present, do not screen the call.</para>
327 </option>
328 <option name="o">
329 <argument name="x" required="false" />
330 <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
331 <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
332 This was the behavior of Asterisk 1.0 and earlier.
333 If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
334 Note that <literal>o(${CALLERID(all)})</literal> is similar to option <literal>o</literal> without the parameter.</para>
335 </option>
336 <option name="O">
337 <argument name="mode">
338 <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
339 the originator hanging up will cause the phone to ring back immediately.</para>
340 <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
341 flashes the trunk, it will ring their phone back.</para>
342 </argument>
343 <para>Enables <emphasis>operator services</emphasis> mode. This option only
344 works when bridging a DAHDI channel to another DAHDI channel
345 only. If specified on non-DAHDI interfaces, it will be ignored.
346 When the destination answers (presumably an operator services
347 station), the originator no longer has control of their line.
348 They may hang up, but the switch will not release their line
349 until the destination party (the operator) hangs up.</para>
350 </option>
351 <option name="p">
352 <para>This option enables screening mode. This is basically Privacy mode
353 without memory.</para>
354 </option>
355 <option name="P">
356 <argument name="x" />
357 <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
358 it is provided. The current extension is used if a database family/key is not specified.</para>
359 </option>
360 <option name="Q">
361 <argument name="cause" required="true"/>
362 <para>Specify the Q.850/Q.931 <replaceable>cause</replaceable> to send on
363 unanswered channels when another channel answers the call.
364 As with <literal>Hangup()</literal>, <replaceable>cause</replaceable>
365 can be a numeric cause code or a name such as
366 <literal>NO_ANSWER</literal>,
367 <literal>USER_BUSY</literal>,
368 <literal>CALL_REJECTED</literal> or
369 <literal>ANSWERED_ELSEWHERE</literal> (the default if Q isn't specified).
370 You can also specify <literal>0</literal> or <literal>NONE</literal>
371 to send no cause. See the <filename>causes.h</filename> file for the
372 full list of valid causes and names.
373 </para>
374 </option>
375 <option name="r">
376 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
377 party until the called channel has answered.</para>
378 <argument name="tone" required="false">
379 <para>Indicate progress to calling party. Send audio 'tone' from the <filename>indications.conf</filename> tonezone currently in use.</para>
380 </argument>
381 </option>
382 <option name="R">
383 <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing.
384 Allow interruption of the ringback if early media is received on the channel.</para>
385 </option>
386 <option name="S">
387 <argument name="x" required="true" />
388 <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
389 answered the call.</para>
390 </option>
391 <option name="s">
392 <argument name="x" required="true" />
393 <para>Force the outgoing CallerID tag parameter to be set to the string <replaceable>x</replaceable>.</para>
394 <para>Works with the <literal>f</literal> option.</para>
395 </option>
396 <option name="t">
397 <para>Allow the called party to transfer the calling party by sending the
398 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
399 transfers initiated by other methods.</para>
400 </option>
401 <option name="T">
402 <para>Allow the calling party to transfer the called party by sending the
403 DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
404 transfers initiated by other methods.</para>
405 </option>
406 <option name="U" argsep="^">
407 <argument name="x" required="true">
408 <para>Name of the subroutine context to execute via <literal>Gosub</literal>.
409 The subroutine execution starts in the named context at the s exten and priority 1.</para>
410 </argument>
411 <argument name="arg" multiple="true" required="false">
412 <para>Arguments for the <literal>Gosub</literal> routine</para>
413 </argument>
414 <para>Execute via <literal>Gosub</literal> the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
415 to the calling channel. Arguments can be specified to the <literal>Gosub</literal>
416 using <literal>^</literal> as a delimiter. The <literal>Gosub</literal> routine can set the variable
417 <variable>GOSUB_RESULT</variable> to specify the following actions after the <literal>Gosub</literal> returns.</para>
418 <variablelist>
419 <variable name="GOSUB_RESULT">
420 <value name="ABORT">
421 Hangup both legs of the call.
422 </value>
423 <value name="CONGESTION">
424 Behave as if line congestion was encountered.
425 </value>
426 <value name="BUSY">
427 Behave as if a busy signal was encountered.
428 </value>
429 <value name="CONTINUE">
430 Hangup the called party and allow the calling party
431 to continue dialplan execution at the next priority.
432 </value>
433 <value name="GOTO:[[&lt;context&gt;^]&lt;exten&gt;^]&lt;priority&gt;">
434 Transfer the call to the specified destination.
435 </value>
436 </variable>
437 </variablelist>
438 <para>NOTE: You cannot use any additional action post answer options in conjunction
439 with this option. Also, pbx services are run on the <emphasis>called</emphasis> channel,
440 so you will not be able to set timeouts via the <literal>TIMEOUT()</literal> function in this routine.</para>
441 </option>
442 <option name="u">
443 <argument name = "x" required="true">
444 <para>Force the outgoing callerid presentation indicator parameter to be set
445 to one of the values passed in <replaceable>x</replaceable>:
446 <literal>allowed_not_screened</literal>
447 <literal>allowed_passed_screen</literal>
448 <literal>allowed_failed_screen</literal>
449 <literal>allowed</literal>
450 <literal>prohib_not_screened</literal>
451 <literal>prohib_passed_screen</literal>
452 <literal>prohib_failed_screen</literal>
453 <literal>prohib</literal>
454 <literal>unavailable</literal></para>
455 </argument>
456 <para>Works with the <literal>f</literal> option.</para>
457 </option>
458 <option name="w">
459 <para>Allow the called party to enable recording of the call by sending
460 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
461 </option>
462 <option name="W">
463 <para>Allow the calling party to enable recording of the call by sending
464 the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
465 </option>
466 <option name="x">
467 <para>Allow the called party to enable recording of the call by sending
468 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
469 </option>
470 <option name="X">
471 <para>Allow the calling party to enable recording of the call by sending
472 the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
473 </option>
474 <option name="z">
475 <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
476 </option>
477 </optionlist>
478 </parameter>
479 <parameter name="URL">
480 <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
481 </parameter>
482 </syntax>
483 <description>
484 <para>This application will place calls to one or more specified channels. As soon
485 as one of the requested channels answers, the originating channel will be
486 answered, if it has not already been answered. These two channels will then
487 be active in a bridged call. All other channels that were requested will then
488 be hung up.</para>
489 <para>Unless there is a timeout specified, the Dial application will wait
490 indefinitely until one of the called channels answers, the user hangs up, or
491 if all of the called channels are busy or unavailable. Dialplan execution will
492 continue if no requested channels can be called, or if the timeout expires.
493 This application will report normal termination if the originating channel
494 hangs up, or if the call is bridged and either of the parties in the bridge
495 ends the call.</para>
496 <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
497 application will be put into that group (as in <literal>Set(GROUP()=...</literal>).
498 If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
499 application will be put into that group (as in <literal>Set(GROUP()=...</literal>). Unlike <variable>OUTBOUND_GROUP</variable>,
500 however, the variable will be unset after use.</para>
501 <example title="Dial with 30 second timeout">
502 same => n,Dial(PJSIP/alice,30)
503 </example>
504 <example title="Parallel dial with 45 second timeout">
505 same => n,Dial(PJSIP/alice&amp;PJIP/bob,45)
506 </example>
507 <example title="Dial with 'g' continuation option">
508 same => n,Dial(PJSIP/alice,,g)
509 same => n,Log(NOTICE, Alice call result: ${DIALSTATUS})
510 </example>
511 <example title="Dial with transfer/recording features for calling party">
512 same => n,Dial(PJSIP/alice,,TX)
513 </example>
514 <example title="Dial with call length limit">
515 same => n,Dial(PJSIP/alice,,L(60000:30000:10000))
516 </example>
517 <example title="Dial alice and bob and send NO_ANSWER to bob instead of ANSWERED_ELSEWHERE when alice answers">
518 same => n,Dial(PJSIP/alice&amp;PJSIP/bob,,Q(NO_ANSWER))
519 </example>
520 <example title="Dial with pre-dial subroutines">
521 [default]
522 exten => callee_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
523 same => n,Log(NOTICE, I'm called on channel ${CHANNEL} prior to it starting the dial attempt)
524 same => n,Return()
525 exten => called_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
526 same => n,Log(NOTICE, I'm called on outbound channel ${CHANNEL} prior to it being used to dial someone)
527 same => n,Return()
528 exten => _X.,1,NoOp()
529 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)))
530 same => n,Hangup()
531 </example>
532 <example title="Dial with post-answer subroutine executed on outbound channel">
533 [my_gosub_routine]
534 exten => s,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
535 same => n,Playback(hello)
536 same => n,Return()
537 [default]
538 exten => _X.,1,NoOp()
539 same => n,Dial(PJSIP/alice,,U(my_gosub_routine^my_gosub_arg1^my_gosub_arg2))
540 same => n,Hangup()
541 </example>
542 <example title="Dial into ConfBridge using 'G' option">
543 same => n,Dial(PJSIP/alice,,G(jump_to_here))
544 same => n(jump_to_here),Goto(confbridge)
545 same => n,Goto(confbridge)
546 same => n(confbridge),ConfBridge(${EXTEN})
547 </example>
548 <para>This application sets the following channel variables:</para>
549 <variablelist>
550 <variable name="DIALEDTIME">
551 <para>This is the time from dialing a channel until when it is disconnected.</para>
552 </variable>
553 <variable name="DIALEDTIME_MS">
554 <para>This is the milliseconds version of the DIALEDTIME variable.</para>
555 </variable>
556 <variable name="ANSWEREDTIME">
557 <para>This is the amount of time for actual call.</para>
558 </variable>
559 <variable name="ANSWEREDTIME_MS">
560 <para>This is the milliseconds version of the ANSWEREDTIME variable.</para>
561 </variable>
562 <variable name="RINGTIME">
563 <para>This is the time from creating the channel to the first RINGING event received. Empty if there was no ring.</para>
564 </variable>
565 <variable name="RINGTIME_MS">
566 <para>This is the milliseconds version of the RINGTIME variable.</para>
567 </variable>
568 <variable name="PROGRESSTIME">
569 <para>This is the time from creating the channel to the first PROGRESS event received. Empty if there was no such event.</para>
570 </variable>
571 <variable name="PROGRESSTIME_MS">
572 <para>This is the milliseconds version of the PROGRESSTIME variable.</para>
573 </variable>
574 <variable name="DIALEDPEERNAME">
575 <para>The name of the outbound channel that answered the call.</para>
576 </variable>
577 <variable name="DIALEDPEERNUMBER">
578 <para>The number that was dialed for the answered outbound channel.</para>
579 </variable>
580 <variable name="FORWARDERNAME">
581 <para>If a call forward occurred, the name of the forwarded channel.</para>
582 </variable>
583 <variable name="DIALSTATUS">
584 <para>This is the status of the call</para>
585 <value name="CHANUNAVAIL">
586 Either the dialed peer exists but is not currently reachable, e.g.
587 endpoint is not registered, or an attempt was made to call a
588 nonexistent location, e.g. nonexistent DNS hostname.
589 </value>
590 <value name="CONGESTION">
591 Channel or switching congestion occurred when routing the call.
592 This can occur if there is a slow or no response from the remote end.
593 </value>
594 <value name="NOANSWER">
595 Called party did not answer.
596 </value>
597 <value name="BUSY">
598 The called party was busy or indicated a busy status.
599 Note that some SIP devices will respond with 486 Busy if their Do Not Disturb
600 modes are active. In this case, you can use DEVICE_STATUS to check if the
601 endpoint is actually in use, if needed.
602 </value>
603 <value name="ANSWER">
604 The call was answered.
605 Any other result implicitly indicates the call was not answered.
606 </value>
607 <value name="CANCEL">
608 Dial was cancelled before call was answered or reached some other terminating event.
609 </value>
610 <value name="DONTCALL">
611 For the Privacy and Screening Modes.
612 Will be set if the called party chooses to send the calling party to the 'Go Away' script.
613 </value>
614 <value name="TORTURE">
615 For the Privacy and Screening Modes.
616 Will be set if the called party chooses to send the calling party to the 'torture' script.
617 </value>
618 <value name="INVALIDARGS">
619 Dial failed due to invalid syntax.
620 </value>
621 </variable>
622 </variablelist>
623 </description>
624 <see-also>
625 <ref type="application">RetryDial</ref>
626 <ref type="application">SendDTMF</ref>
627 <ref type="application">Gosub</ref>
628 </see-also>
629 </application>
630 <application name="RetryDial" language="en_US">
631 <since>
632 <version>1.2.0</version>
633 </since>
634 <synopsis>
635 Place a call, retrying on failure allowing an optional exit extension.
636 </synopsis>
637 <syntax>
638 <parameter name="announce" required="true">
639 <para>Filename of sound that will be played when no channel can be reached</para>
640 </parameter>
641 <parameter name="sleep" required="true">
642 <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
643 </parameter>
644 <parameter name="retries" required="true">
645 <para>Number of retries</para>
646 <para>When this is reached flow will continue at the next priority in the dialplan</para>
647 </parameter>
648 <parameter name="dialargs" required="true">
649 <para>Same format as arguments provided to the Dial application</para>
650 </parameter>
651 </syntax>
652 <description>
653 <para>This application will attempt to place a call using the normal Dial application.
654 If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
655 Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
656 After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
657 If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
658 While waiting to retry a call, a 1 digit extension may be dialed. If that
659 extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
660 one, The call will jump to that extension immediately.
661 The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
662 to the Dial application.</para>
663 </description>
664 <see-also>
665 <ref type="application">Dial</ref>
666 </see-also>
667 </application>
668 ***/
669
670static const char app[] = "Dial";
671static const char rapp[] = "RetryDial";
672
673enum {
674 OPT_ANNOUNCE = (1 << 0),
675 OPT_RESETCDR = (1 << 1),
676 OPT_DTMF_EXIT = (1 << 2),
677 OPT_SENDDTMF = (1 << 3),
678 OPT_FORCECLID = (1 << 4),
679 OPT_GO_ON = (1 << 5),
684 OPT_MUSICBACK = (1 << 10),
688 OPT_SCREENING = (1 << 15),
689 OPT_PRIVACY = (1 << 16),
690 OPT_RINGBACK = (1 << 17),
691 OPT_DURATION_STOP = (1 << 18),
696 OPT_GOTO = (1 << 23),
697 OPT_OPERMODE = (1 << 24),
698 OPT_CALLEE_PARK = (1 << 25),
699 OPT_CALLER_PARK = (1 << 26),
701 OPT_CALLEE_GOSUB = (1 << 28),
704};
705
706/* flags are now 64 bits, so keep it up! */
707#define DIAL_STILLGOING (1LLU << 31)
708#define DIAL_NOFORWARDHTML (1LLU << 32)
709#define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
710#define OPT_CANCEL_ELSEWHERE (1LLU << 34)
711#define OPT_PEER_H (1LLU << 35)
712#define OPT_CALLEE_GO_ON (1LLU << 36)
713#define OPT_CANCEL_TIMEOUT (1LLU << 37)
714#define OPT_FORCE_CID_TAG (1LLU << 38)
715#define OPT_FORCE_CID_PRES (1LLU << 39)
716#define OPT_CALLER_ANSWER (1LLU << 40)
717#define OPT_PREDIAL_CALLEE (1LLU << 41)
718#define OPT_PREDIAL_CALLER (1LLU << 42)
719#define OPT_RING_WITH_EARLY_MEDIA (1LLU << 43)
720#define OPT_HANGUPCAUSE (1LLU << 44)
721#define OPT_HEARPULSING (1LLU << 45)
722#define OPT_TOPOLOGY_PRESERVE (1LLU << 46)
723
724enum {
744 /* note: this entry _MUST_ be the last one in the enum */
747
793
794#define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
795 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
796 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
797 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_GOSUB) && \
798 !ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \
799 ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer)))
800
801/*
802 * The list of active channels
803 */
804struct chanlist {
807 /*! Channel interface dialing string (is tech/number). (Stored in stuff[]) */
808 const char *interface;
809 /*! Channel technology name. (Stored in stuff[]) */
810 const char *tech;
811 /*! Channel device addressing. (Stored in stuff[]) */
812 const char *number;
813 /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
815 uint64_t flags;
816 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
818 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
821 /*! The interface, tech, and number strings are stuffed here. */
822 char stuff[0];
823};
824
826
827static void topology_ds_destroy(void *data) {
828 struct ast_stream_topology *top = data;
830}
831
833 .type = "app_dial_topology_preserve",
834 .destroy = topology_ds_destroy,
835};
836
837static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode);
838
839static void chanlist_free(struct chanlist *outgoing)
840{
842 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
843 ast_free(outgoing->orig_chan_name);
845}
846
847static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
848{
849 /* Hang up a tree of stuff */
850 struct chanlist *outgoing;
851
852 while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
853 /* Hangup any existing lines we have open */
854 if (outgoing->chan && (outgoing->chan != exception)) {
855 if (hangupcause >= 0) {
856 /* This is for the channel drivers */
857 ast_channel_hangupcause_set(outgoing->chan, hangupcause);
858 }
859 ast_hangup(outgoing->chan);
860 }
862 }
863}
864
865#define AST_MAX_WATCHERS 256
866
867/*
868 * argument to handle_cause() and other functions.
869 */
872 int busy;
875};
876
877static void handle_cause(int cause, struct cause_args *num)
878{
879 switch(cause) {
880 case AST_CAUSE_BUSY:
881 num->busy++;
882 break;
884 num->congestion++;
885 break;
888 num->nochan++;
889 break;
892 break;
893 default:
894 num->nochan++;
895 break;
896 }
897}
898
899static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
900{
901 char rexten[2] = { exten, '\0' };
902
903 if (context) {
904 if (!ast_goto_if_exists(chan, context, rexten, pri))
905 return 1;
906 } else {
907 if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
908 return 1;
909 }
910 return 0;
911}
912
913/* do not call with chan lock held */
914static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
915{
916 const char *context;
917 const char *exten;
918
919 ast_channel_lock(chan);
922 ast_channel_unlock(chan);
923
924 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
925}
926
927/*!
928 * helper function for wait_for_answer()
929 *
930 * \param o Outgoing call channel list.
931 * \param num Incoming call channel cause accumulation
932 * \param peerflags Dial option flags
933 * \param single TRUE if there is only one outgoing call.
934 * \param caller_entertained TRUE if the caller is being entertained by MOH or ringback.
935 * \param to Remaining call timeout time.
936 * \param forced_clid OPT_FORCECLID caller id to send
937 * \param stored_clid Caller id representing the called party if needed
938 *
939 * XXX this code is highly suspicious, as it essentially overwrites
940 * the outgoing channel without properly deleting it.
941 *
942 * \todo eventually this function should be integrated into and replaced by ast_call_forward()
943 */
944static void do_forward(struct chanlist *o, struct cause_args *num,
945 struct ast_flags64 *peerflags, int single, int caller_entertained, int *to,
946 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
947{
948 char tmpchan[256];
949 char forwarder[AST_CHANNEL_NAME];
950 struct ast_channel *original = o->chan;
951 struct ast_channel *c = o->chan; /* the winner */
952 struct ast_channel *in = num->chan; /* the input channel */
953 char *stuff;
954 char *tech;
955 int cause;
956 struct ast_party_caller caller;
957
958 ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
959 ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
960 if ((stuff = strchr(tmpchan, '/'))) {
961 *stuff++ = '\0';
962 tech = tmpchan;
963 } else {
964 const char *forward_context;
966 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
967 if (ast_strlen_zero(forward_context)) {
968 forward_context = NULL;
969 }
970 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
972 stuff = tmpchan;
973 tech = "Local";
974 }
975 if (!strcasecmp(tech, "Local")) {
976 /*
977 * Drop the connected line update block for local channels since
978 * this is going to run dialplan and the user can change his
979 * mind about what connected line information he wants to send.
980 */
982 }
983
984 /* Before processing channel, go ahead and check for forwarding */
985 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
986 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
987 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
988 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
989 ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
990 ast_channel_call_forward(original));
991 c = o->chan = NULL;
992 cause = AST_CAUSE_BUSY;
993 } else {
994 struct ast_stream_topology *topology;
995
999
1000 /* Setup parameters */
1001 c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
1002
1003 ast_stream_topology_free(topology);
1004
1005 if (c) {
1006 if (single && !caller_entertained) {
1008 }
1012 pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
1016 /* When a call is forwarded, we don't want to track new interfaces
1017 * dialed for CC purposes. Setting the done flag will ensure that
1018 * any Dial operations that happen later won't record CC interfaces.
1019 */
1020 ast_ignore_cc(o->chan);
1021 ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",
1023 } else
1025 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
1026 tech, stuff, cause);
1027 }
1028 if (!c) {
1029 ast_channel_publish_dial(in, original, stuff, "BUSY");
1031 handle_cause(cause, num);
1032 ast_hangup(original);
1033 } else {
1034 ast_channel_lock_both(c, original);
1036 ast_channel_redirecting(original));
1038 ast_channel_unlock(original);
1039
1041
1042 if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
1044 }
1045
1046 if (!ast_channel_redirecting(c)->from.number.valid
1047 || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
1048 /*
1049 * The call was not previously redirected so it is
1050 * now redirected from this number.
1051 */
1057 }
1058
1060
1061 /* Determine CallerID to store in outgoing channel. */
1063 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1064 caller.id = *stored_clid;
1067 } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
1068 ast_channel_caller(c)->id.number.str, NULL))) {
1069 /*
1070 * The new channel has no preset CallerID number by the channel
1071 * driver. Use the dialplan extension and hint name.
1072 */
1073 caller.id = *stored_clid;
1076 } else {
1078 }
1079
1080 /* Determine CallerID for outgoing channel to send. */
1083
1085 connected.id = *forced_clid;
1087 } else {
1089 }
1090
1092
1093 ast_channel_appl_set(c, "AppDial");
1094 ast_channel_data_set(c, "(Outgoing Line)");
1096
1098 if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1099 struct ast_party_redirecting redirecting;
1100
1101 /*
1102 * Redirecting updates to the caller make sense only on single
1103 * calls.
1104 *
1105 * Need to re-evalute if unlocking is still required here as macro is gone
1106 */
1107 ast_party_redirecting_init(&redirecting);
1110 if (ast_channel_redirecting_sub(c, in, &redirecting, 0)) {
1111 ast_channel_update_redirecting(in, &redirecting, NULL);
1112 }
1113 ast_party_redirecting_free(&redirecting);
1114 } else {
1116 }
1117
1118 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1119 *to = -1;
1120 }
1121
1122 if (ast_call(c, stuff, 0)) {
1123 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1124 tech, stuff);
1125 ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1127 ast_hangup(original);
1128 ast_hangup(c);
1129 c = o->chan = NULL;
1130 num->nochan++;
1131 } else {
1132 ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1133 ast_channel_call_forward(original));
1134
1136
1137 /* Hangup the original channel now, in case we needed it */
1138 ast_hangup(original);
1139 }
1140 if (single && !caller_entertained) {
1141 ast_indicate(in, -1);
1142 }
1143 }
1144}
1145
1146/* argument used for some functions. */
1150 char privcid[256];
1151 char privintro[1024];
1152 char status[256];
1154};
1155
1156static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
1157{
1158 struct chanlist *outgoing;
1159 AST_LIST_TRAVERSE(out_chans, outgoing, node) {
1160 if (!outgoing->chan || outgoing->chan == exception) {
1161 continue;
1162 }
1164 }
1165}
1166
1167/*!
1168 * \internal
1169 * \brief Update connected line on chan from peer.
1170 * \since 13.6.0
1171 *
1172 * \param chan Channel to get connected line updated.
1173 * \param peer Channel providing connected line information.
1174 * \param is_caller Non-zero if chan is the calling channel.
1175 */
1176static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
1177{
1178 struct ast_party_connected_line connected_caller;
1179
1180 ast_party_connected_line_init(&connected_caller);
1181
1182 ast_channel_lock(peer);
1184 ast_channel_unlock(peer);
1186 if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)) {
1187 ast_channel_update_connected_line(chan, &connected_caller, NULL);
1188 }
1189 ast_party_connected_line_free(&connected_caller);
1190}
1191
1192/*!
1193 * \internal
1194 * \pre chan is locked
1195 */
1196static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
1197{
1198 char buf[32];
1199 char full_var_name[128];
1200
1201 snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000);
1202 pbx_builtin_setvar_helper(chan, var_base, buf);
1203
1204 snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base);
1205 snprintf(buf, sizeof(buf), "%" PRId64, duration);
1206 pbx_builtin_setvar_helper(chan, full_var_name, buf);
1207}
1208
1210 struct dial_head *out_chans, int *to_answer, int *to_progress, struct ast_flags64 *peerflags,
1211 char *opt_args[],
1212 struct privacy_args *pa,
1213 const struct cause_args *num_in, int *result, char *dtmf_progress,
1214 char *mf_progress, char *mf_wink,
1215 char *sf_progress, char *sf_wink,
1216 const int hearpulsing,
1217 const int ignore_cc,
1218 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid,
1219 struct ast_bridge_config *config)
1220{
1221 struct cause_args num = *num_in;
1222 int prestart = num.busy + num.congestion + num.nochan;
1223 int orig_answer_to = *to_answer;
1224 int orig_progress_to = *to_progress;
1225 struct ast_channel *peer = NULL;
1226 struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
1227 /* single is set if only one destination is enabled */
1228 int single = outgoing && !AST_LIST_NEXT(outgoing, node);
1229 int caller_entertained = outgoing
1231 struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
1232 int cc_recall_core_id;
1233 int is_cc_recall;
1234 int cc_frame_received = 0;
1235 int num_ringing = 0;
1236 int sent_ring = 0;
1237 int sent_progress = 0, sent_wink = 0;
1238 struct timeval start = ast_tvnow();
1239 SCOPE_ENTER(3, "%s\n", ast_channel_name(in));
1240
1241 if (single) {
1242 /* Turn off hold music, etc */
1243 if (!caller_entertained) {
1245 /* If we are calling a single channel, and not providing ringback or music, */
1246 /* then, make them compatible for in-band tone purpose */
1247 if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
1248 /* If these channels can not be made compatible,
1249 * there is no point in continuing. The bridge
1250 * will just fail if it gets that far.
1251 */
1252 *to_answer = -1;
1253 strcpy(pa->status, "CONGESTION");
1255 SCOPE_EXIT_RTN_VALUE(NULL, "%s: can't be made compat with %s\n",
1257 }
1258 }
1259
1263 }
1264 }
1265
1266 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1267
1268 while ((*to_answer = ast_remaining_ms(start, orig_answer_to)) && (*to_progress = ast_remaining_ms(start, orig_progress_to)) && !peer) {
1269 struct chanlist *o;
1270 int pos = 0; /* how many channels do we handle */
1271 int numlines = prestart;
1272 struct ast_channel *winner;
1273 struct ast_channel *watchers[AST_MAX_WATCHERS];
1274
1275 watchers[pos++] = in;
1276 AST_LIST_TRAVERSE(out_chans, o, node) {
1277 /* Keep track of important channels */
1278 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1279 watchers[pos++] = o->chan;
1280 numlines++;
1281 }
1282 if (pos == 1) { /* only the input channel is available */
1283 if (numlines == (num.busy + num.congestion + num.nochan)) {
1284 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1285 if (num.busy)
1286 strcpy(pa->status, "BUSY");
1287 else if (num.congestion)
1288 strcpy(pa->status, "CONGESTION");
1289 else if (num.nochan)
1290 strcpy(pa->status, "CHANUNAVAIL");
1291 } else {
1292 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1293 }
1294 *to_answer = 0;
1295 if (is_cc_recall) {
1296 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1297 }
1298 SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outgoing channels available\n", ast_channel_name(in));
1299 }
1300
1301 /* If progress timeout is active, use that if it's the shorter of the 2 timeouts. */
1302 winner = ast_waitfor_n(watchers, pos, *to_progress > 0 && (*to_answer < 0 || *to_progress < *to_answer) ? to_progress : to_answer);
1303
1304 AST_LIST_TRAVERSE(out_chans, o, node) {
1305 int res = 0;
1306 struct ast_frame *f;
1307 struct ast_channel *c = o->chan;
1308
1309 if (c == NULL)
1310 continue;
1312 if (!peer) {
1313 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1314 if (o->orig_chan_name
1315 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1316 /*
1317 * The channel name changed so we must generate COLP update.
1318 * Likely because a call pickup channel masqueraded in.
1319 */
1321 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1322 if (o->pending_connected_update) {
1325 }
1326 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1328 }
1329 }
1330 if (o->aoc_s_rate_list) {
1331 size_t encoded_size;
1332 struct ast_aoc_encoded *encoded;
1333 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1334 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1335 ast_aoc_destroy_encoded(encoded);
1336 }
1337 }
1338 peer = c;
1339 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1340 ast_copy_flags64(peerflags, o,
1347 ast_channel_dialcontext_set(c, "");
1349 }
1350 continue;
1351 }
1352 if (c != winner)
1353 continue;
1354 /* here, o->chan == c == winner */
1356 pa->sentringing = 0;
1357 if (!ignore_cc && (f = ast_read(c))) {
1359 /* This channel is forwarding the call, and is capable of CC, so
1360 * be sure to add the new device interface to the list
1361 */
1363 }
1364 ast_frfree(f);
1365 }
1366
1367 if (o->pending_connected_update) {
1368 /*
1369 * Re-seed the chanlist's connected line information with
1370 * previously acquired connected line info from the incoming
1371 * channel. The previously acquired connected line info could
1372 * have been set through the CONNECTED_LINE dialplan function.
1373 */
1378 }
1379
1380 do_forward(o, &num, peerflags, single, caller_entertained, &orig_answer_to,
1381 forced_clid, stored_clid);
1382
1383 if (o->chan) {
1386 if (single
1390 }
1391 }
1392 continue;
1393 }
1394 f = ast_read(winner);
1395 if (!f) {
1398 ast_hangup(c);
1399 c = o->chan = NULL;
1402 continue;
1403 }
1404 switch (f->frametype) {
1405 case AST_FRAME_CONTROL:
1406 switch (f->subclass.integer) {
1407 case AST_CONTROL_ANSWER:
1408 /* This is our guy if someone answered. */
1409 if (!peer) {
1410 ast_trace(-1, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1411 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1412 if (o->orig_chan_name
1413 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1414 /*
1415 * The channel name changed so we must generate COLP update.
1416 * Likely because a call pickup channel masqueraded in.
1417 */
1419 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1420 if (o->pending_connected_update) {
1423 }
1424 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1426 }
1427 }
1428 if (o->aoc_s_rate_list) {
1429 size_t encoded_size;
1430 struct ast_aoc_encoded *encoded;
1431 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1432 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1433 ast_aoc_destroy_encoded(encoded);
1434 }
1435 }
1436 peer = c;
1437 /* Answer can optionally include a topology */
1438 if (f->subclass.topology) {
1439 /*
1440 * We need to bump the refcount on the topology to prevent it
1441 * from being cleaned up when the frame is cleaned up.
1442 */
1443 config->answer_topology = ao2_bump(f->subclass.topology);
1444 ast_trace(-1, "%s Found topology in frame: %p %p %s\n",
1445 ast_channel_name(peer), f, config->answer_topology,
1446 ast_str_tmp(256, ast_stream_topology_to_str(config->answer_topology, &STR_TMP)));
1447 }
1448
1449 /* Inform everyone else that they've been canceled.
1450 * The dial end event for the peer will be sent out after
1451 * other Dial options have been handled.
1452 */
1453 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1454 ast_copy_flags64(peerflags, o,
1461 ast_channel_dialcontext_set(c, "");
1463 if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
1464 /* Setup early bridge if appropriate */
1466 }
1467 }
1468 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1471 break;
1472 case AST_CONTROL_BUSY:
1473 ast_verb(3, "%s is busy\n", ast_channel_name(c));
1475 ast_channel_publish_dial(in, c, NULL, "BUSY");
1476 ast_hangup(c);
1477 c = o->chan = NULL;
1480 break;
1482 ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1484 ast_channel_publish_dial(in, c, NULL, "CONGESTION");
1485 ast_hangup(c);
1486 c = o->chan = NULL;
1489 break;
1491 /* This is a tricky area to get right when using a native
1492 * CC agent. The reason is that we do the best we can to send only a
1493 * single ringing notification to the caller.
1494 *
1495 * Call completion complicates the logic used here. CCNR is typically
1496 * offered during a ringing message. Let's say that party A calls
1497 * parties B, C, and D. B and C do not support CC requests, but D
1498 * does. If we were to receive a ringing notification from B before
1499 * the others, then we would end up sending a ringing message to
1500 * A with no CCNR offer present.
1501 *
1502 * The approach that we have taken is that if we receive a ringing
1503 * response from a party and no CCNR offer is present, we need to
1504 * wait. Specifically, we need to wait until either a) a called party
1505 * offers CCNR in its ringing response or b) all called parties have
1506 * responded in some way to our call and none offers CCNR.
1507 *
1508 * The drawback to this is that if one of the parties has a delayed
1509 * response or, god forbid, one just plain doesn't respond to our
1510 * outgoing call, then this will result in a significant delay between
1511 * when the caller places the call and hears ringback.
1512 *
1513 * Note also that if CC is disabled for this call, then it is perfectly
1514 * fine for ringing frames to get sent through.
1515 */
1516 ++num_ringing;
1517 *to_progress = -1;
1518 orig_progress_to = -1;
1519 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1520 ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1521 /* Setup early media if appropriate */
1522 if (single && !caller_entertained
1523 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1525 }
1528 pa->sentringing++;
1529 }
1530 if (!sent_ring) {
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, "RINGTIME", diff);
1542
1545 sent_ring = 1;
1546 }
1547 }
1548 ast_channel_publish_dial(in, c, NULL, "RINGING");
1549 break;
1551 ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1552 /* Setup early media if appropriate */
1553 if (single && !caller_entertained
1554 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1556 }
1558 if (single || (!single && !pa->sentringing)) {
1560 }
1561 }
1562 *to_progress = -1;
1563 orig_progress_to = -1;
1564 if (!sent_progress) {
1565 struct timeval now, then;
1566 int64_t diff;
1567
1568 now = ast_tvnow();
1569
1572
1574 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1575 set_duration_var(in, "PROGRESSTIME", diff);
1576
1579 sent_progress = 1;
1580
1581 if (!ast_strlen_zero(mf_progress)) {
1582 ast_verb(3,
1583 "Sending MF '%s' to %s as result of "
1584 "receiving a PROGRESS message.\n",
1585 mf_progress, hearpulsing ? "parties" : "called party");
1586 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1587 (hearpulsing ? in : NULL), mf_progress, 50, 55, 120, 65, 0);
1588 }
1589 if (!ast_strlen_zero(sf_progress)) {
1590 ast_verb(3,
1591 "Sending SF '%s' to %s as result of "
1592 "receiving a PROGRESS message.\n",
1593 sf_progress, (hearpulsing ? "parties" : "called party"));
1594 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1595 (hearpulsing ? in : NULL), sf_progress, 0, 0);
1596 }
1597 if (!ast_strlen_zero(dtmf_progress)) {
1598 ast_verb(3,
1599 "Sending DTMF '%s' to the called party as result of "
1600 "receiving a PROGRESS message.\n",
1601 dtmf_progress);
1602 res |= ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1603 }
1604 if (res) {
1605 ast_log(LOG_WARNING, "Called channel %s hung up post-progress before all digits could be sent\n", ast_channel_name(c));
1606 goto wait_over;
1607 }
1608 }
1609 ast_channel_publish_dial(in, c, NULL, "PROGRESS");
1610 break;
1611 case AST_CONTROL_WINK:
1612 ast_verb(3, "%s winked, passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1613 if (!sent_wink) {
1614 sent_wink = 1;
1615 if (!ast_strlen_zero(mf_wink)) {
1616 ast_verb(3,
1617 "Sending MF '%s' to %s as result of "
1618 "receiving a WINK message.\n",
1619 mf_wink, (hearpulsing ? "parties" : "called party"));
1620 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1621 (hearpulsing ? in : NULL), mf_wink, 50, 55, 120, 65, 0);
1622 }
1623 if (!ast_strlen_zero(sf_wink)) {
1624 ast_verb(3,
1625 "Sending SF '%s' to %s as result of "
1626 "receiving a WINK message.\n",
1627 sf_wink, (hearpulsing ? "parties" : "called party"));
1628 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1629 (hearpulsing ? in : NULL), sf_wink, 0, 0);
1630 }
1631 if (res) {
1632 ast_log(LOG_WARNING, "Called channel %s hung up post-wink before all digits could be sent\n", ast_channel_name(c));
1633 goto wait_over;
1634 }
1635 }
1637 break;
1641 if (!single || caller_entertained) {
1642 break;
1643 }
1644 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1647 break;
1650 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1651 break;
1652 }
1653 if (!single) {
1655
1656 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
1663 break;
1664 }
1665 if (ast_channel_connected_line_sub(c, in, f, 1)) {
1667 }
1668 break;
1669 case AST_CONTROL_AOC:
1670 {
1671 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1672 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1674 o->aoc_s_rate_list = decoded;
1675 } else {
1676 ast_aoc_destroy_decoded(decoded);
1677 }
1678 }
1679 break;
1681 if (!single) {
1682 /*
1683 * Redirecting updates to the caller make sense only on single
1684 * calls.
1685 */
1686 break;
1687 }
1689 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1690 break;
1691 }
1692 ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
1694 if (ast_channel_redirecting_sub(c, in, f, 1)) {
1696 }
1697 pa->sentringing = 0;
1698 break;
1700 ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1701 if (single && !caller_entertained
1702 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1704 }
1707 ast_channel_publish_dial(in, c, NULL, "PROCEEDING");
1708 break;
1709 case AST_CONTROL_HOLD:
1710 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1711 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1713 break;
1714 case AST_CONTROL_UNHOLD:
1715 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1716 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1718 break;
1720 case AST_CONTROL_FLASH:
1721 /* Ignore going off hook and flash */
1722 break;
1723 case AST_CONTROL_CC:
1724 if (!ignore_cc) {
1726 cc_frame_received = 1;
1727 }
1728 break;
1731 break;
1733 if (!f->data.ptr) {
1734 ast_log(LOG_WARNING, "Got playback begin directive without filename on %s\n", ast_channel_name(c));
1735 } else {
1736 const char *filename = f->data.ptr;
1737 ast_verb(3, "Playing audio file %s on %s\n", filename, ast_channel_name(in));
1739 }
1740 break;
1741 case -1:
1742 if (single && !caller_entertained) {
1743 ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1744 ast_indicate(in, -1);
1745 pa->sentringing = 0;
1746 }
1747 break;
1748 default:
1749 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
1750 break;
1751 }
1752 break;
1753 case AST_FRAME_VIDEO:
1754 case AST_FRAME_VOICE:
1755 case AST_FRAME_IMAGE:
1757 case AST_FRAME_DTMF_END:
1758 if (caller_entertained) {
1759 break;
1760 }
1761 *to_progress = -1;
1762 orig_progress_to = -1;
1763 /* Fall through */
1764 case AST_FRAME_TEXT:
1765 if (single && ast_write(in, f)) {
1766 ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
1767 f->frametype);
1768 }
1769 break;
1770 case AST_FRAME_HTML:
1772 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1773 ast_log(LOG_WARNING, "Unable to send URL\n");
1774 }
1775 break;
1776 default:
1777 break;
1778 }
1779 ast_frfree(f);
1780 } /* end for */
1781 if (winner == in) {
1782 struct ast_frame *f = ast_read(in);
1783#if 0
1784 if (f && (f->frametype != AST_FRAME_VOICE))
1785 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
1786 else if (!f || (f->frametype != AST_FRAME_VOICE))
1787 printf("Hangup received on %s\n", in->name);
1788#endif
1789 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1790 /* Got hung up */
1791 *to_answer = -1;
1792 strcpy(pa->status, "CANCEL");
1793 pa->canceled = 1;
1794 publish_dial_end_event(in, out_chans, NULL, pa->status);
1795 if (f) {
1796 if (f->data.uint32) {
1798 }
1799 ast_frfree(f);
1800 }
1801 if (is_cc_recall) {
1802 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1803 }
1804 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller hung up\n", ast_channel_name(in));
1805 }
1806
1807 /* now f is guaranteed non-NULL */
1808 if (f->frametype == AST_FRAME_DTMF) {
1809 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1810 const char *context;
1812 if ((context = pbx_builtin_getvar_helper(in, "EXITCONTEXT"))) {
1813 context = ast_strdupa(context);
1814 }
1816 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1817 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1818 *to_answer = 0;
1819 *result = f->subclass.integer;
1820 strcpy(pa->status, "CANCEL");
1821 pa->canceled = 1;
1822 publish_dial_end_event(in, out_chans, NULL, pa->status);
1823 ast_frfree(f);
1824 if (is_cc_recall) {
1825 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1826 }
1827 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller pressed %c to end call\n",
1829 }
1830 }
1831
1832 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1833 detect_disconnect(in, f->subclass.integer, &featurecode)) {
1834 ast_verb(3, "User requested call disconnect.\n");
1835 *to_answer = 0;
1836 strcpy(pa->status, "CANCEL");
1837 pa->canceled = 1;
1838 publish_dial_end_event(in, out_chans, NULL, pa->status);
1839 ast_frfree(f);
1840 if (is_cc_recall) {
1841 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1842 }
1843 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller requested disconnect\n",
1845 }
1846 }
1847
1848 /* Send the frame from the in channel to all outgoing channels. */
1849 AST_LIST_TRAVERSE(out_chans, o, node) {
1850 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1851 /* This outgoing channel has died so don't send the frame to it. */
1852 continue;
1853 }
1854 switch (f->frametype) {
1855 case AST_FRAME_HTML:
1856 /* Forward HTML stuff */
1858 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1859 ast_log(LOG_WARNING, "Unable to send URL\n");
1860 }
1861 break;
1862 case AST_FRAME_VIDEO:
1863 case AST_FRAME_VOICE:
1864 case AST_FRAME_IMAGE:
1865 if (!single || caller_entertained) {
1866 /*
1867 * We are calling multiple parties or caller is being
1868 * entertained and has thus not been made compatible.
1869 * No need to check any other called parties.
1870 */
1871 goto skip_frame;
1872 }
1873 /* Fall through */
1874 case AST_FRAME_TEXT:
1876 case AST_FRAME_DTMF_END:
1877 if (ast_write(o->chan, f)) {
1878 ast_log(LOG_WARNING, "Unable to forward frametype: %u\n",
1879 f->frametype);
1880 }
1881 break;
1882 case AST_FRAME_CONTROL:
1883 switch (f->subclass.integer) {
1884 case AST_CONTROL_HOLD:
1885 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1887 break;
1888 case AST_CONTROL_UNHOLD:
1889 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1891 break;
1892 case AST_CONTROL_FLASH:
1893 ast_verb(3, "Hook flash on %s\n", ast_channel_name(o->chan));
1895 break;
1899 if (!single || caller_entertained) {
1900 /*
1901 * We are calling multiple parties or caller is being
1902 * entertained and has thus not been made compatible.
1903 * No need to check any other called parties.
1904 */
1905 goto skip_frame;
1906 }
1907 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1910 break;
1913 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
1914 break;
1915 }
1916 if (ast_channel_connected_line_sub(in, o->chan, f, 1)) {
1918 }
1919 break;
1922 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
1923 break;
1924 }
1925 if (ast_channel_redirecting_sub(in, o->chan, f, 1)) {
1927 }
1928 break;
1929 default:
1930 /* We are not going to do anything with this frame. */
1931 goto skip_frame;
1932 }
1933 break;
1934 default:
1935 /* We are not going to do anything with this frame. */
1936 goto skip_frame;
1937 }
1938 }
1939skip_frame:;
1940 ast_frfree(f);
1941 }
1942 }
1943
1944wait_over:
1945 if (!*to_answer || ast_check_hangup(in)) {
1946 ast_verb(3, "Nobody picked up in %d ms\n", orig_answer_to);
1947 publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
1948 } else if (!*to_progress) {
1949 ast_verb(3, "No early media received in %d ms\n", orig_progress_to);
1950 publish_dial_end_event(in, out_chans, NULL, "CHANUNAVAIL");
1951 strcpy(pa->status, "CHANUNAVAIL");
1952 *to_answer = 0; /* Reset to prevent hangup */
1953 }
1954
1955 if (is_cc_recall) {
1956 ast_cc_completed(in, "Recall completed!");
1957 }
1958 SCOPE_EXIT_RTN_VALUE(peer, "%s: %s%s\n", ast_channel_name(in),
1959 peer ? "Answered by " : "No answer", peer ? ast_channel_name(peer) : "");
1960}
1961
1962static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
1963{
1964 char disconnect_code[AST_FEATURE_MAX_LEN];
1965 int res;
1966
1967 ast_str_append(featurecode, 1, "%c", code);
1968
1969 res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
1970 if (res) {
1971 ast_str_reset(*featurecode);
1972 return 0;
1973 }
1974
1975 if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
1976 /* Could be a partial match, anyway */
1977 if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
1978 ast_str_reset(*featurecode);
1979 }
1980 return 0;
1981 }
1982
1983 if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
1984 ast_str_reset(*featurecode);
1985 return 0;
1986 }
1987
1988 return 1;
1989}
1990
1991/* returns true if there is a valid privacy reply */
1992static int valid_priv_reply(struct ast_flags64 *opts, int res)
1993{
1994 if (res < '1')
1995 return 0;
1996 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1997 return 1;
1998 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1999 return 1;
2000 return 0;
2001}
2002
2003static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
2004 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
2005{
2006
2007 int res2;
2008 int loopcount = 0;
2009
2010 /* Get the user's intro, store it in priv-callerintros/$CID,
2011 unless it is already there-- this should be done before the
2012 call is actually dialed */
2013
2014 /* all ring indications and moh for the caller has been halted as soon as the
2015 target extension was picked up. We are going to have to kill some
2016 time and make the caller believe the peer hasn't picked up yet */
2017
2019 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2020 ast_indicate(chan, -1);
2021 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2022 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2023 ast_channel_musicclass_set(chan, original_moh);
2026 pa->sentringing++;
2027 }
2028
2029 /* Start autoservice on the other chan ?? */
2030 res2 = ast_autoservice_start(chan);
2031 /* Now Stream the File */
2032 for (loopcount = 0; loopcount < 3; loopcount++) {
2033 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
2034 break;
2035 if (!res2) /* on timeout, play the message again */
2036 res2 = ast_play_and_wait(peer, "priv-callpending");
2037 if (!valid_priv_reply(opts, res2))
2038 res2 = 0;
2039 /* priv-callpending script:
2040 "I have a caller waiting, who introduces themselves as:"
2041 */
2042 if (!res2)
2043 res2 = ast_play_and_wait(peer, pa->privintro);
2044 if (!valid_priv_reply(opts, res2))
2045 res2 = 0;
2046 /* now get input from the called party, as to their choice */
2047 if (!res2) {
2048 /* XXX can we have both, or they are mutually exclusive ? */
2049 if (ast_test_flag64(opts, OPT_PRIVACY))
2050 res2 = ast_play_and_wait(peer, "priv-callee-options");
2051 if (ast_test_flag64(opts, OPT_SCREENING))
2052 res2 = ast_play_and_wait(peer, "screen-callee-options");
2053 }
2054
2055 /*! \page DialPrivacy Dial Privacy scripts
2056 * \par priv-callee-options script:
2057 * \li Dial 1 if you wish this caller to reach you directly in the future,
2058 * and immediately connect to their incoming call.
2059 * \li Dial 2 if you wish to send this caller to voicemail now and forevermore.
2060 * \li Dial 3 to send this caller to the torture menus, now and forevermore.
2061 * \li Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
2062 * \li Dial 5 to allow this caller to come straight thru to you in the future,
2063 * but right now, just this once, send them to voicemail.
2064 *
2065 * \par screen-callee-options script:
2066 * \li Dial 1 if you wish to immediately connect to the incoming call
2067 * \li Dial 2 if you wish to send this caller to voicemail.
2068 * \li Dial 3 to send this caller to the torture menus.
2069 * \li Dial 4 to send this caller to a simple "go away" menu.
2070 */
2071 if (valid_priv_reply(opts, res2))
2072 break;
2073 /* invalid option */
2074 res2 = ast_play_and_wait(peer, "vm-sorry");
2075 }
2076
2077 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
2078 ast_moh_stop(chan);
2080 ast_indicate(chan, -1);
2081 pa->sentringing = 0;
2082 }
2084 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
2085 /* map keypresses to various things, the index is res2 - '1' */
2086 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
2088 int i = res2 - '1';
2089 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
2090 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
2091 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
2092 }
2093 switch (res2) {
2094 case '1':
2095 break;
2096 case '2':
2097 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2098 break;
2099 case '3':
2100 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2101 break;
2102 case '4':
2103 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2104 break;
2105 case '5':
2106 if (ast_test_flag64(opts, OPT_PRIVACY)) {
2107 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2108 break;
2109 }
2110 /* if not privacy, then 5 is the same as "default" case */
2111 default: /* bad input or -1 if failure to start autoservice */
2112 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
2113 /* well, there seems basically two choices. Just patch the caller thru immediately,
2114 or,... put 'em thru to voicemail. */
2115 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
2116 ast_verb(3, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
2117 /* XXX should we set status to DENY ? */
2118 /* XXX what about the privacy flags ? */
2119 break;
2120 }
2121
2122 if (res2 == '1') { /* the only case where we actually connect */
2123 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
2124 just clog things up, and it's not useful information, not being tied to a CID */
2125 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
2127 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2128 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2129 else
2130 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2131 }
2132 return 0; /* the good exit path */
2133 } else {
2134 return -1;
2135 }
2136}
2137
2138/*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
2139static int setup_privacy_args(struct privacy_args *pa,
2140 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
2141{
2142 char callerid[60];
2143 int res;
2144 char *l;
2145
2146 if (ast_channel_caller(chan)->id.number.valid
2147 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2148 l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2150 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
2151 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
2152 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
2153 } else {
2154 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
2156 }
2157 } else {
2158 char *tnam, *tn2;
2159
2160 tnam = ast_strdupa(ast_channel_name(chan));
2161 /* clean the channel name so slashes don't try to end up in disk file name */
2162 for (tn2 = tnam; *tn2; tn2++) {
2163 if (*tn2 == '/') /* any other chars to be afraid of? */
2164 *tn2 = '=';
2165 }
2166 ast_verb(3, "Privacy-- callerid is empty\n");
2167
2168 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
2169 l = callerid;
2171 }
2172
2173 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
2174
2175 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
2176 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
2177 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
2179 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
2180 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
2181 }
2182
2183 if (pa->privdb_val == AST_PRIVACY_DENY) {
2184 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
2185 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2186 return 0;
2187 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
2188 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2189 return 0; /* Is this right? */
2190 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
2191 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2192 return 0; /* is this right??? */
2193 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
2194 /* Get the user's intro, store it in priv-callerintros/$CID,
2195 unless it is already there-- this should be done before the
2196 call is actually dialed */
2197
2198 /* make sure the priv-callerintros dir actually exists */
2199 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
2200 if ((res = ast_mkdir(pa->privintro, 0755))) {
2201 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
2202 return -1;
2203 }
2204
2205 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
2206 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
2207 /* the DELUX version of this code would allow this caller the
2208 option to hear and retape their previously recorded intro.
2209 */
2210 } else {
2211 int duration; /* for feedback from play_and_wait */
2212 /* the file doesn't exist yet. Let the caller submit his
2213 vocal intro for posterity */
2214 /* priv-recordintro script:
2215 "At the tone, please say your name:"
2216 */
2218 ast_answer(chan);
2219 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 */
2220 /* don't think we'll need a lock removed, we took care of
2221 conflicts by naming the pa.privintro file */
2222 if (res == -1) {
2223 /* Delete the file regardless since they hung up during recording */
2225 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2226 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2227 else
2228 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2229 return -1;
2230 }
2231 if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
2232 ast_waitstream(chan, "");
2233 }
2234 }
2235 return 1; /* success */
2236}
2237
2238static void end_bridge_callback(void *data)
2239{
2240 struct ast_channel *chan = data;
2241
2242 ast_channel_lock(chan);
2244 set_duration_var(chan, "ANSWEREDTIME", ast_channel_get_up_time_ms(chan));
2245 set_duration_var(chan, "DIALEDTIME", ast_channel_get_duration_ms(chan));
2247 ast_channel_unlock(chan);
2248}
2249
2250static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
2251 bconfig->end_bridge_callback_data = originator;
2252}
2253
2254static int dial_handle_playtones(struct ast_channel *chan, const char *data)
2255{
2256 struct ast_tone_zone_sound *ts = NULL;
2257 int res;
2258 const char *str = data;
2259
2260 if (ast_strlen_zero(str)) {
2261 ast_debug(1,"Nothing to play\n");
2262 return -1;
2263 }
2264
2266
2267 if (ts && ts->data[0]) {
2268 res = ast_playtones_start(chan, 0, ts->data, 0);
2269 } else {
2270 res = -1;
2271 }
2272
2273 if (ts) {
2275 }
2276
2277 if (res) {
2278 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
2279 }
2280
2281 return res;
2282}
2283
2284/*!
2285 * \internal
2286 * \brief Setup the after bridge goto location on the peer.
2287 * \since 12.0.0
2288 *
2289 * \param chan Calling channel for bridge.
2290 * \param peer Peer channel for bridge.
2291 * \param opts Dialing option flags.
2292 * \param opt_args Dialing option argument strings.
2293 */
2294static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
2295{
2296 const char *context;
2297 const char *extension;
2298 int priority;
2299
2300 if (ast_test_flag64(opts, OPT_PEER_H)) {
2301 ast_channel_lock(chan);
2302 context = ast_strdupa(ast_channel_context(chan));
2303 ast_channel_unlock(chan);
2304 ast_bridge_set_after_h(peer, context);
2305 } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
2306 ast_channel_lock(chan);
2307 context = ast_strdupa(ast_channel_context(chan));
2310 ast_channel_unlock(chan);
2312 opt_args[OPT_ARG_CALLEE_GO_ON]);
2313 }
2314}
2315
2316static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
2317{
2318 int res = -1; /* default: error */
2319 char *rest, *cur; /* scan the list of destinations */
2320 struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2321 struct chanlist *outgoing;
2322 struct chanlist *tmp;
2323 struct ast_channel *peer = NULL;
2324 int to_answer, to_progress; /* timeouts */
2325 struct cause_args num = { chan, 0, 0, 0 };
2326 int cause, hanguptreecause = -1;
2327
2328 struct ast_bridge_config config = { { 0, } };
2329 struct timeval calldurationlimit = { 0, };
2330 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL;
2331 char *mf_progress = NULL, *mf_wink = NULL;
2332 char *sf_progress = NULL, *sf_wink = NULL;
2333 struct privacy_args pa = {
2334 .sentringing = 0,
2335 .privdb_val = 0,
2336 .status = "INVALIDARGS",
2337 .canceled = 0,
2338 };
2339 int sentringing = 0, moh = 0;
2340 const char *outbound_group = NULL;
2341 int result = 0;
2342 char *parse;
2343 int opermode = 0;
2344 int delprivintro = 0;
2347 AST_APP_ARG(timeout);
2350 );
2351 struct ast_flags64 opts = { 0, };
2352 char *opt_args[OPT_ARG_ARRAY_SIZE];
2353 int fulldial = 0, num_dialed = 0;
2354 int ignore_cc = 0;
2355 char device_name[AST_CHANNEL_NAME];
2356 char forced_clid_name[AST_MAX_EXTENSION];
2357 char stored_clid_name[AST_MAX_EXTENSION];
2358 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2359 /*!
2360 * \brief Forced CallerID party information to send.
2361 * \note This will not have any malloced strings so do not free it.
2362 */
2363 struct ast_party_id forced_clid;
2364 /*!
2365 * \brief Stored CallerID information if needed.
2366 *
2367 * \note If OPT_ORIGINAL_CLID set then this is the o option
2368 * CallerID. Otherwise it is the dialplan extension and hint
2369 * name.
2370 *
2371 * \note This will not have any malloced strings so do not free it.
2372 */
2373 struct ast_party_id stored_clid;
2374 /*!
2375 * \brief CallerID party information to store.
2376 * \note This will not have any malloced strings so do not free it.
2377 */
2378 struct ast_party_caller caller;
2379 int max_forwards;
2380 struct ast_datastore *topology_ds = NULL;
2381 SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data);
2382
2383 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2384 ast_channel_lock(chan);
2386 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2387 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2388 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2389 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2390 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");
2391 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2392 pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");
2393 pbx_builtin_setvar_helper(chan, "RINGTIME", "");
2394 pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");
2395 pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");
2396 pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");
2399 ast_channel_unlock(chan);
2400
2401 if (max_forwards <= 0) {
2402 ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2403 ast_channel_name(chan));
2404 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2405 SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan));
2406 }
2407
2408 if (ast_check_hangup_locked(chan)) {
2409 /*
2410 * Caller hung up before we could dial. If dial is executed
2411 * within an AGI then the AGI has likely eaten all queued
2412 * frames before executing the dial in DeadAGI mode. With
2413 * the caller hung up and no pending frames from the caller's
2414 * read queue, dial would not know that the call has hung up
2415 * until a called channel answers. It is rather annoying to
2416 * whoever just answered the non-existent call.
2417 *
2418 * Dial should not continue execution in DeadAGI mode, hangup
2419 * handlers, or the h exten.
2420 */
2421 ast_verb(3, "Caller hung up before dial.\n");
2422 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
2423 SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan));
2424 }
2425
2426 parse = ast_strdupa(data ?: "");
2427
2429
2430 if (!ast_strlen_zero(args.options) &&
2431 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2432 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2433 goto done;
2434 }
2435
2436 if (ast_cc_call_init(chan, &ignore_cc)) {
2437 goto done;
2438 }
2439
2441 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2442
2443 if (delprivintro < 0 || delprivintro > 1) {
2444 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2445 delprivintro = 0;
2446 }
2447 }
2448
2449 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2450 opt_args[OPT_ARG_RINGBACK] = NULL;
2451 }
2452
2453 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2454 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2455 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2456 }
2457
2459 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2460 if (!calldurationlimit.tv_sec) {
2461 ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);
2462 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2463 goto done;
2464 }
2465 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2466 }
2467
2468 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2469 sf_wink = opt_args[OPT_ARG_SENDDTMF];
2470 dtmfcalled = strsep(&sf_wink, ":");
2471 dtmfcalling = strsep(&sf_wink, ":");
2472 dtmf_progress = strsep(&sf_wink, ":");
2473 mf_progress = strsep(&sf_wink, ":");
2474 mf_wink = strsep(&sf_wink, ":");
2475 sf_progress = strsep(&sf_wink, ":");
2476 }
2477
2479 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2480 goto done;
2481 }
2482
2483 /* Setup the forced CallerID information to send if used. */
2484 ast_party_id_init(&forced_clid);
2485 force_forwards_only = 0;
2486 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2487 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2488 ast_channel_lock(chan);
2489 forced_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2490 ast_channel_unlock(chan);
2491 forced_clid_name[0] = '\0';
2492 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2493 sizeof(forced_clid_name), chan);
2494 force_forwards_only = 1;
2495 } else {
2496 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2497 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2498 &forced_clid.number.str);
2499 }
2500 if (!ast_strlen_zero(forced_clid.name.str)) {
2501 forced_clid.name.valid = 1;
2502 }
2503 if (!ast_strlen_zero(forced_clid.number.str)) {
2504 forced_clid.number.valid = 1;
2505 }
2506 }
2508 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2509 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2510 }
2513 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2514 int pres;
2515
2517 if (0 <= pres) {
2518 forced_clid.number.presentation = pres;
2519 }
2520 }
2521
2522 /* Setup the stored CallerID information if needed. */
2523 ast_party_id_init(&stored_clid);
2524 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2525 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2526 ast_channel_lock(chan);
2527 ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2528 if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2529 stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2530 }
2531 if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2532 stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2533 }
2534 if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2535 stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2536 }
2537 if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2538 stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2539 }
2540 ast_channel_unlock(chan);
2541 } else {
2542 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2543 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2544 &stored_clid.number.str);
2545 if (!ast_strlen_zero(stored_clid.name.str)) {
2546 stored_clid.name.valid = 1;
2547 }
2548 if (!ast_strlen_zero(stored_clid.number.str)) {
2549 stored_clid.number.valid = 1;
2550 }
2551 }
2552 } else {
2553 /*
2554 * In case the new channel has no preset CallerID number by the
2555 * channel driver, setup the dialplan extension and hint name.
2556 */
2557 stored_clid_name[0] = '\0';
2558 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2559 sizeof(stored_clid_name), chan);
2560 if (ast_strlen_zero(stored_clid.name.str)) {
2561 stored_clid.name.str = NULL;
2562 } else {
2563 stored_clid.name.valid = 1;
2564 }
2565 ast_channel_lock(chan);
2566 stored_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2567 stored_clid.number.valid = 1;
2568 ast_channel_unlock(chan);
2569 }
2570
2571 if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2573 }
2576
2578 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2579 if (res <= 0)
2580 goto out;
2581 res = -1; /* reset default */
2582 }
2583
2584 if (continue_exec)
2585 *continue_exec = 0;
2586
2587 /* If a channel group has been specified, get it for use when we create peer channels */
2588
2589 ast_channel_lock(chan);
2590 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2591 outbound_group = ast_strdupa(outbound_group);
2592 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2593 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2594 outbound_group = ast_strdupa(outbound_group);
2595 }
2596 ast_channel_unlock(chan);
2597
2598 /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2602
2603 /* PREDIAL: Run gosub on the caller's channel */
2605 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2607 ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2608 }
2609
2610 /* loop through the list of dial destinations */
2611 rest = args.peers;
2612 while ((cur = strsep(&rest, "&"))) {
2613 struct ast_channel *tc; /* channel for this destination */
2614 char *number;
2615 char *tech;
2616 int i;
2617 size_t tech_len;
2618 size_t number_len;
2619 struct ast_stream_topology *topology;
2620 struct ast_stream *stream;
2621
2622 cur = ast_strip(cur);
2623 if (ast_strlen_zero(cur)) {
2624 /* No tech/resource in this position. */
2625 continue;
2626 }
2627
2628 /* Get a technology/resource pair */
2629 number = cur;
2630 tech = strsep(&number, "/");
2631
2632 num_dialed++;
2633 if (ast_strlen_zero(number)) {
2634 ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2635 goto out;
2636 }
2637
2638 tech_len = strlen(tech) + 1;
2639 number_len = strlen(number) + 1;
2640 tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2641 if (!tmp) {
2642 goto out;
2643 }
2644
2645 /* Save tech, number, and interface. */
2646 cur = tmp->stuff;
2647 strcpy(cur, tech);
2648 tmp->tech = cur;
2649 cur += tech_len;
2650 strcpy(cur, tech);
2651 cur[tech_len - 1] = '/';
2652 tmp->interface = cur;
2653 cur += tech_len;
2654 strcpy(cur, number);
2655 tmp->number = cur;
2656
2657 if (opts.flags) {
2658 /* Set per outgoing call leg options. */
2659 ast_copy_flags64(tmp, &opts,
2669 }
2670
2671 /* Request the peer */
2672
2673 ast_channel_lock(chan);
2674 /*
2675 * Seed the chanlist's connected line information with previously
2676 * acquired connected line info from the incoming channel. The
2677 * previously acquired connected line info could have been set
2678 * through the CONNECTED_LINE dialplan function.
2679 */
2681
2683 topology_ds = ast_channel_datastore_find(chan, &topology_ds_info, NULL);
2684
2685 if (!topology_ds && (topology_ds = ast_datastore_alloc(&topology_ds_info, NULL))) {
2687 ast_channel_datastore_add(chan, topology_ds);
2688 }
2689 }
2690
2691 if (topology_ds) {
2692 ao2_ref(topology_ds->data, +1);
2693 topology = topology_ds->data;
2694 } else {
2696 }
2697
2698 ast_channel_unlock(chan);
2699
2700 for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
2701 stream = ast_stream_topology_get_stream(topology, i);
2702 /* For both recvonly and sendonly the stream state reflects our state, that is we
2703 * are receiving only and we are sending only. Since we are requesting a
2704 * channel for the peer, we need to swap this to reflect what we will be doing.
2705 * That is, if we are receiving from Alice then we want to be sending to Bob,
2706 * so swap recvonly to sendonly and vice versa.
2707 */
2710 } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {
2712 }
2713 }
2714
2715 tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
2716
2717 ast_stream_topology_free(topology);
2718
2719 if (!tc) {
2720 /* If we can't, just go on to the next call */
2721 /* Failure doesn't necessarily mean user error. DAHDI channels could be busy. */
2722 ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n",
2723 tmp->tech, cause, ast_cause2str(cause));
2724 handle_cause(cause, &num);
2725 if (!rest) {
2726 /* we are on the last destination */
2727 ast_channel_hangupcause_set(chan, cause);
2728 }
2729 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2730 if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2732 }
2733 }
2734 chanlist_free(tmp);
2735 continue;
2736 }
2737
2738 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2739 if (!ignore_cc) {
2740 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2741 }
2742
2743 ast_channel_lock_both(tc, chan);
2745
2746 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2747
2748 /* Setup outgoing SDP to match incoming one */
2749 if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2750 /* We are on the only destination. */
2752 }
2753
2754 /* Inherit specially named variables from parent channel */
2758
2759 ast_channel_appl_set(tc, "AppDial");
2760 ast_channel_data_set(tc, "(Outgoing Line)");
2761
2762 memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2763
2764 /* Determine CallerID to store in outgoing channel. */
2766 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2767 caller.id = stored_clid;
2768 ast_channel_set_caller_event(tc, &caller, NULL);
2770 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2771 ast_channel_caller(tc)->id.number.str, NULL))) {
2772 /*
2773 * The new channel has no preset CallerID number by the channel
2774 * driver. Use the dialplan extension and hint name.
2775 */
2776 caller.id = stored_clid;
2777 if (!caller.id.name.valid
2778 && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2779 ast_channel_connected(chan)->id.name.str, NULL))) {
2780 /*
2781 * No hint name available. We have a connected name supplied by
2782 * the dialplan we can use instead.
2783 */
2784 caller.id.name.valid = 1;
2785 caller.id.name = ast_channel_connected(chan)->id.name;
2786 }
2787 ast_channel_set_caller_event(tc, &caller, NULL);
2789 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2790 NULL))) {
2791 /* The new channel has no preset CallerID name by the channel driver. */
2792 if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2793 ast_channel_connected(chan)->id.name.str, NULL))) {
2794 /*
2795 * We have a connected name supplied by the dialplan we can
2796 * use instead.
2797 */
2798 caller.id.name.valid = 1;
2799 caller.id.name = ast_channel_connected(chan)->id.name;
2800 ast_channel_set_caller_event(tc, &caller, NULL);
2801 }
2802 }
2803
2804 /* Determine CallerID for outgoing channel to send. */
2805 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2807
2809 connected.id = forced_clid;
2811 } else {
2813 }
2814
2816
2818
2821 ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2822 }
2823
2824 /* Pass ADSI CPE and transfer capability */
2827
2828 /* If we have an outbound group, set this peer channel to it */
2829 if (outbound_group)
2830 ast_app_group_set_channel(tc, outbound_group);
2831 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2834
2835 /* Check if we're forced by configuration */
2838
2839
2840 /* Inherit context and extension */
2841 ast_channel_dialcontext_set(tc, ast_channel_context(chan));
2843
2845
2846 /* Save the original channel name to detect call pickup masquerading in. */
2848
2850 ast_channel_unlock(chan);
2851
2852 /* Put channel in the list of outgoing thingies. */
2853 tmp->chan = tc;
2854 AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
2855 }
2856
2857 /* As long as we attempted to dial valid peers, don't throw a warning. */
2858 /* If a DAHDI peer is busy, out_chans will be empty so checking list size is misleading. */
2859 if (!num_dialed) {
2860 ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");
2861 if (continue_exec) {
2862 /* There is no point in having RetryDial try again */
2863 *continue_exec = 1;
2864 }
2865 strcpy(pa.status, "CHANUNAVAIL");
2866 res = 0;
2867 goto out;
2868 }
2869
2870 /*
2871 * PREDIAL: Run gosub on all of the callee channels
2872 *
2873 * We run the callee predial before ast_call() in case the user
2874 * wishes to do something on the newly created channels before
2875 * the channel does anything important.
2876 *
2877 * Inside the target gosub we will be able to do something with
2878 * the newly created channel name ie: now the calling channel
2879 * can know what channel will be used to call the destination
2880 * ex: now we will know that SIP/abc-123 is calling SIP/def-124
2881 */
2884 && !AST_LIST_EMPTY(&out_chans)) {
2885 const char *predial_callee;
2886
2888 predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
2889 if (predial_callee) {
2891 AST_LIST_TRAVERSE(&out_chans, tmp, node) {
2892 ast_pre_call(tmp->chan, predial_callee);
2893 }
2895 ast_free((char *) predial_callee);
2896 }
2897 }
2898
2899 /* Start all outgoing calls */
2900 AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
2901 res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
2902 ast_channel_lock(chan);
2903
2904 /* check the results of ast_call */
2905 if (res) {
2906 /* Again, keep going even if there's an error */
2907 ast_debug(1, "ast call on peer returned %d\n", res);
2908 ast_verb(3, "Couldn't call %s\n", tmp->interface);
2909 if (ast_channel_hangupcause(tmp->chan)) {
2911 }
2912 ast_channel_unlock(chan);
2913 ast_cc_call_failed(chan, tmp->chan, tmp->interface);
2914 ast_hangup(tmp->chan);
2915 tmp->chan = NULL;
2917 chanlist_free(tmp);
2918 continue;
2919 }
2920
2921 ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
2922 ast_channel_unlock(chan);
2923
2924 ast_verb(3, "Called %s\n", tmp->interface);
2926
2927 /* If this line is up, don't try anybody else */
2928 if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
2929 break;
2930 }
2931 }
2933
2934 if (ast_strlen_zero(args.timeout)) {
2935 to_answer = -1;
2936 to_progress = -1;
2937 } else {
2938 double tmp;
2939 char *anstimeout = strsep(&args.timeout, "^");
2940 if (!ast_strlen_zero(anstimeout)) {
2941 if (sscanf(anstimeout, "%30lf", &tmp) == 1 && tmp > 0) {
2942 to_answer = tmp * 1000;
2943 ast_debug(3, "Dial timeout set to %d ms\n", to_answer);
2944 } else {
2945 ast_log(LOG_WARNING, "Invalid answer timeout specified: '%s'. Setting timeout to infinite\n", anstimeout);
2946 to_answer = -1;
2947 }
2948 } else {
2949 to_answer = -1;
2950 }
2951 if (!ast_strlen_zero(args.timeout)) {
2952 if (sscanf(args.timeout, "%30lf", &tmp) == 1 && tmp > 0) {
2953 to_progress = tmp * 1000;
2954 ast_debug(3, "Dial progress timeout set to %d ms\n", to_progress);
2955 } else {
2956 ast_log(LOG_WARNING, "Invalid progress timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2957 to_progress = -1;
2958 }
2959 } else {
2960 to_progress = -1;
2961 }
2962 }
2963
2964 outgoing = AST_LIST_FIRST(&out_chans);
2965 if (!outgoing) {
2966 strcpy(pa.status, "CHANUNAVAIL");
2967 if (fulldial == num_dialed) {
2968 res = -1;
2969 goto out;
2970 }
2971 } else {
2972 /* Our status will at least be NOANSWER */
2973 strcpy(pa.status, "NOANSWER");
2975 moh = 1;
2976 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2977 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2978 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2979 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2980 ast_channel_musicclass_set(chan, original_moh);
2981 } else {
2982 ast_moh_start(chan, NULL, NULL);
2983 }
2986 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2987 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2989 sentringing++;
2990 } else {
2992 }
2993 } else {
2995 sentringing++;
2996 }
2997 }
2998 }
2999
3000 peer = wait_for_answer(chan, &out_chans, &to_answer, &to_progress, peerflags, opt_args, &pa, &num, &result,
3001 dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink,
3002 (ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
3003 ignore_cc, &forced_clid, &stored_clid, &config);
3004
3005 if (!peer) {
3006 if (result) {
3007 res = result;
3008 } else if (to_answer) { /* Musta gotten hung up */
3009 res = -1;
3010 } else { /* Nobody answered, next please? */
3011 res = 0;
3012 }
3013 } else {
3014 const char *number;
3015 const char *name;
3016 int dial_end_raised = 0;
3017 int cause = -1;
3018
3019 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
3020 ast_answer(chan);
3021 }
3022
3023 /* Ah ha! Someone answered within the desired timeframe. Of course after this
3024 we will always return with -1 so that it is hung up properly after the
3025 conversation. */
3026
3028 && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
3029 cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
3030 if (cause <= 0) {
3031 if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
3032 cause = 0;
3033 } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
3034 || cause < 0) {
3035 ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
3036 opt_args[OPT_ARG_HANGUPCAUSE]);
3037 cause = -1;
3038 }
3039 }
3040 }
3041 hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
3042
3043 /* If appropriate, log that we have a destination channel and set the answer time */
3044
3045 ast_channel_lock(peer);
3047
3048 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
3049 if (ast_strlen_zero(number)) {
3050 number = NULL;
3051 } else {
3053 }
3054 ast_channel_unlock(peer);
3055
3056 ast_channel_lock(chan);
3058
3059 strcpy(pa.status, "ANSWER");
3060 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3061
3062 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
3063 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
3064
3066 ast_channel_unlock(chan);
3067
3068 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
3069 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
3070 ast_channel_sendurl( peer, args.url );
3071 }
3073 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
3074 ast_channel_publish_dial(chan, peer, NULL, pa.status);
3075 /* hang up on the callee -- he didn't want to talk anyway! */
3077 res = 0;
3078 goto out;
3079 }
3080 }
3081 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
3082 res = 0;
3083 } else {
3084 int digit = 0;
3085 struct ast_channel *chans[2];
3086 struct ast_channel *active_chan;
3087 char *calledfile = NULL, *callerfile = NULL;
3088 int calledstream = 0, callerstream = 0;
3089
3090 chans[0] = chan;
3091 chans[1] = peer;
3092
3093 /* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
3094 callerfile = opt_args[OPT_ARG_ANNOUNCE];
3095 calledfile = strsep(&callerfile, ":");
3096
3097 /* stream the file(s) */
3098 if (!ast_strlen_zero(calledfile)) {
3099 res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
3100 if (res) {
3101 res = 0;
3102 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
3103 } else {
3104 calledstream = 1;
3105 }
3106 }
3107 if (!ast_strlen_zero(callerfile)) {
3108 res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
3109 if (res) {
3110 res = 0;
3111 ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
3112 } else {
3113 callerstream = 1;
3114 }
3115 }
3116
3117 /* can't use ast_waitstream, because we're streaming two files at once, and can't block
3118 We'll need to handle both channels at once. */
3119
3121 while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
3122 int mspeer, mschan;
3123
3124 mspeer = ast_sched_wait(ast_channel_sched(peer));
3125 mschan = ast_sched_wait(ast_channel_sched(chan));
3126
3127 if (calledstream) {
3128 if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
3129 ast_stopstream(peer);
3130 calledstream = 0;
3131 }
3132 }
3133 if (callerstream) {
3134 if (mschan < 0 && !ast_channel_timingfunc(chan)) {
3135 ast_stopstream(chan);
3136 callerstream = 0;
3137 }
3138 }
3139
3140 if (!calledstream && !callerstream) {
3141 break;
3142 }
3143
3144 if (mspeer < 0)
3145 mspeer = 1000;
3146
3147 if (mschan < 0)
3148 mschan = 1000;
3149
3150 /* wait for the lowest maximum of the two */
3151 active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
3152 if (active_chan) {
3153 struct ast_channel *other_chan;
3154 struct ast_frame *fr = ast_read(active_chan);
3155
3156 if (!fr) {
3158 res = -1;
3159 goto done;
3160 }
3161 switch (fr->frametype) {
3162 case AST_FRAME_DTMF_END:
3163 digit = fr->subclass.integer;
3164 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
3165 ast_stopstream(peer);
3166 res = ast_senddigit(chan, digit, 0);
3167 }
3168 break;
3169 case AST_FRAME_CONTROL:
3170 switch (fr->subclass.integer) {
3171 case AST_CONTROL_HANGUP:
3172 ast_frfree(fr);
3174 res = -1;
3175 goto done;
3177 /* Pass COLP update to the other channel. */
3178 if (active_chan == chan) {
3179 other_chan = peer;
3180 } else {
3181 other_chan = chan;
3182 }
3183 if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)) {
3184 ast_indicate_data(other_chan, fr->subclass.integer,
3185 fr->data.ptr, fr->datalen);
3186 }
3187 break;
3188 default:
3189 break;
3190 }
3191 break;
3192 default:
3193 /* Ignore all others */
3194 break;
3195 }
3196 ast_frfree(fr);
3197 }
3200 }
3202 }
3203
3204 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
3205 /* chan and peer are going into the PBX; as such neither are considered
3206 * outgoing channels any longer */
3208
3210 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
3211 /* peer goes to the same context and extension as chan, so just copy info from chan*/
3212 ast_channel_lock(peer);
3219 ast_channel_unlock(peer);
3220 if (ast_pbx_start(peer)) {
3222 }
3223 if (continue_exec)
3224 *continue_exec = 1;
3225 res = 0;
3226 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3227 goto done;
3228 }
3229
3231 const char *gosub_result_peer;
3232 char *gosub_argstart;
3233 char *gosub_args = NULL;
3234 int gosub_res = -1;
3235
3237 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
3238 if (gosub_argstart) {
3239 const char *what_is_s = "s";
3240 *gosub_argstart = 0;
3241 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)) &&
3242 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))) {
3243 what_is_s = "~~s~~";
3244 }
3245 if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
3246 gosub_args = NULL;
3247 }
3248 *gosub_argstart = ',';
3249 } else {
3250 const char *what_is_s = "s";
3251 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)) &&
3252 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))) {
3253 what_is_s = "~~s~~";
3254 }
3255 if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
3256 gosub_args = NULL;
3257 }
3258 }
3259 if (gosub_args) {
3260 gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
3261 ast_free(gosub_args);
3262 } else {
3263 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
3264 }
3265
3266 ast_channel_lock_both(chan, peer);
3267
3268 if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
3269 char *gosub_transfer_dest;
3270 char *gosub_result = ast_strdupa(gosub_result_peer);
3271 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
3272
3273 /* Inherit return value from the peer, so it can be used in the master */
3274 if (gosub_retval) {
3275 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
3276 }
3277
3278 ast_channel_unlock(peer);
3279 ast_channel_unlock(chan);
3280
3281 if (!strcasecmp(gosub_result, "BUSY")) {
3282 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3283 ast_set_flag64(peerflags, OPT_GO_ON);
3284 gosub_res = -1;
3285 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
3286 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3287 ast_set_flag64(peerflags, OPT_GO_ON);
3288 gosub_res = -1;
3289 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
3290 /* Hangup peer and continue with the next extension priority. */
3291 ast_set_flag64(peerflags, OPT_GO_ON);
3292 gosub_res = -1;
3293 } else if (!strcasecmp(gosub_result, "ABORT")) {
3294 /* Hangup both ends unless the caller has the g flag */
3295 gosub_res = -1;
3296 } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
3297 gosub_transfer_dest = gosub_result + 5;
3298 gosub_res = -1;
3299 /* perform a transfer to a new extension */
3300 if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
3301 ast_replace_subargument_delimiter(gosub_transfer_dest);
3302 }
3303 if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
3304 ast_set_flag64(peerflags, OPT_GO_ON);
3305 }
3306 }
3307 if (gosub_res) {
3308 res = gosub_res;
3309 if (!dial_end_raised) {
3310 ast_channel_publish_dial(chan, peer, NULL, gosub_result);
3311 dial_end_raised = 1;
3312 }
3313 }
3314 } else {
3315 ast_channel_unlock(peer);
3316 ast_channel_unlock(chan);
3317 }
3318 }
3319
3320 if (!res) {
3321
3322 /* None of the Dial options changed our status; inform
3323 * everyone that this channel answered
3324 */
3325 if (!dial_end_raised) {
3326 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3327 dial_end_raised = 1;
3328 }
3329
3330 if (!ast_tvzero(calldurationlimit)) {
3331 struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
3332 ast_channel_lock(peer);
3333 ast_channel_whentohangup_set(peer, &whentohangup);
3334 ast_channel_unlock(peer);
3335 }
3336 if (!ast_strlen_zero(dtmfcalled)) {
3337 ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
3338 res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
3339 }
3340 if (!ast_strlen_zero(dtmfcalling)) {
3341 ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
3342 res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
3343 }
3344 }
3345
3346 if (res) { /* some error */
3347 if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
3349 }
3350 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3352 || ast_pbx_start(peer)) {
3354 }
3355 res = -1;
3356 } else {
3357 if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
3358 ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
3359 if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
3360 ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
3361 if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
3362 ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
3363 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
3364 ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
3365 if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
3366 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
3367 if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
3368 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
3369 if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
3370 ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
3371 if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
3372 ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
3373 if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
3374 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
3375 if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
3376 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
3377
3378 config.end_bridge_callback = end_bridge_callback;
3379 config.end_bridge_callback_data = chan;
3380 config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
3381
3382 if (moh) {
3383 moh = 0;
3384 ast_moh_stop(chan);
3385 } else if (sentringing) {
3386 sentringing = 0;
3387 ast_indicate(chan, -1);
3388 }
3389 /* Be sure no generators are left on it and reset the visible indication */
3392 /* Make sure channels are compatible */
3393 res = ast_channel_make_compatible(chan, peer);
3394 if (res < 0) {
3395 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));
3397 res = -1;
3398 goto done;
3399 }
3400 if (opermode) {
3401 struct oprmode oprmode;
3402
3403 oprmode.peer = peer;
3404 oprmode.mode = opermode;
3405
3407 }
3408 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3409
3410 res = ast_bridge_call(chan, peer, &config);
3411 }
3412 }
3413out:
3414 if (moh) {
3415 moh = 0;
3416 ast_moh_stop(chan);
3417 } else if (sentringing) {
3418 sentringing = 0;
3419 ast_indicate(chan, -1);
3420 }
3421
3422 if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3424 if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3425 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
3426 } else {
3427 ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
3428 }
3429 }
3430
3432 /* forward 'answered elsewhere' if we received it */
3434 hanguptreecause = AST_CAUSE_ANSWERED_ELSEWHERE;
3435 } else if (pa.canceled) { /* Caller canceled */
3436 if (ast_channel_hangupcause(chan))
3437 hanguptreecause = ast_channel_hangupcause(chan);
3438 else
3439 hanguptreecause = AST_CAUSE_NORMAL_CLEARING;
3440 }
3441 hanguptree(&out_chans, NULL, hanguptreecause);
3442 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3443 ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
3444
3445 if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
3446 if (!ast_tvzero(calldurationlimit))
3447 memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
3448 res = 0;
3449 }
3450
3451done:
3452 if (config.answer_topology) {
3453 ast_trace(2, "%s Cleaning up topology: %p %s\n",
3454 peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology,
3455 ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP)));
3456
3457 /*
3458 * At this point, the channel driver that answered should have bumped the
3459 * topology refcount for itself. Here we're cleaning up the reference we added
3460 * in wait_for_answer().
3461 */
3462 ast_stream_topology_free(config.answer_topology);
3463 }
3464 if (config.warning_sound) {
3465 ast_free((char *)config.warning_sound);
3466 }
3467 if (config.end_sound) {
3468 ast_free((char *)config.end_sound);
3469 }
3470 if (config.start_sound) {
3471 ast_free((char *)config.start_sound);
3472 }
3473 ast_ignore_cc(chan);
3474 SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan));
3475}
3476
3477static int dial_exec(struct ast_channel *chan, const char *data)
3478{
3479 struct ast_flags64 peerflags;
3480
3481 memset(&peerflags, 0, sizeof(peerflags));
3482
3483 return dial_exec_full(chan, data, &peerflags, NULL);
3484}
3485
3486static int retrydial_exec(struct ast_channel *chan, const char *data)
3487{
3488 char *parse;
3489 const char *context = NULL;
3490 int sleepms = 0, loops = 0, res = -1;
3491 struct ast_flags64 peerflags = { 0, };
3493 AST_APP_ARG(announce);
3494 AST_APP_ARG(sleep);
3495 AST_APP_ARG(retries);
3496 AST_APP_ARG(dialdata);
3497 );
3498
3499 if (ast_strlen_zero(data)) {
3500 ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
3501 return -1;
3502 }
3503
3504 parse = ast_strdupa(data);
3506
3507 if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
3508 sleepms *= 1000;
3509
3510 if (!ast_strlen_zero(args.retries)) {
3511 loops = atoi(args.retries);
3512 }
3513
3514 if (!args.dialdata) {
3515 ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
3516 goto done;
3517 }
3518
3519 if (sleepms < 1000)
3520 sleepms = 10000;
3521
3522 if (!loops)
3523 loops = -1; /* run forever */
3524
3525 ast_channel_lock(chan);
3526 context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
3527 context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
3528 ast_channel_unlock(chan);
3529
3530 res = 0;
3531 while (loops) {
3532 int continue_exec;
3533
3534 ast_channel_data_set(chan, "Retrying");
3536 ast_moh_stop(chan);
3537
3538 res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
3539 if (continue_exec)
3540 break;
3541
3542 if (res == 0) {
3543 if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
3544 if (!ast_strlen_zero(args.announce)) {
3545 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3546 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3548 } else
3549 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3550 }
3551 if (!res && sleepms) {
3553 ast_moh_start(chan, NULL, NULL);
3554 res = ast_waitfordigit(chan, sleepms);
3555 }
3556 } else {
3557 if (!ast_strlen_zero(args.announce)) {
3558 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3559 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3560 res = ast_waitstream(chan, "");
3561 } else
3562 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3563 }
3564 if (sleepms) {
3566 ast_moh_start(chan, NULL, NULL);
3567 if (!res)
3568 res = ast_waitfordigit(chan, sleepms);
3569 }
3570 }
3571 }
3572
3573 if (res < 0 || res == AST_PBX_INCOMPLETE) {
3574 break;
3575 } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
3576 if (onedigit_goto(chan, context, (char) res, 1)) {
3577 res = 0;
3578 break;
3579 }
3580 }
3581 loops--;
3582 }
3583 if (loops == 0)
3584 res = 0;
3585 else if (res == 1)
3586 res = 0;
3587
3589 ast_moh_stop(chan);
3590 done:
3591 return res;
3592}
3593
3594static int unload_module(void)
3595{
3596 int res;
3597
3600
3601 return res;
3602}
3603
3604static int load_module(void)
3605{
3606 int res;
3607
3610
3611 return res;
3612}
3613
3615 .support_level = AST_MODULE_SUPPORT_CORE,
3616 .load = load_module,
3617 .unload = unload_module,
3618 .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:322
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:901
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:458
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition aoc.c:316
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:659
@ AST_AOC_S
Definition aoc.h:64
char digit
static void topology_ds_destroy(void *data)
Definition app_dial.c:827
#define DIAL_STILLGOING
Definition app_dial.c:707
static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
Definition app_dial.c:2316
#define OPT_PREDIAL_CALLER
Definition app_dial.c:718
#define OPT_CANCEL_ELSEWHERE
Definition app_dial.c:710
static const char * get_cid_name(char *name, int namelen, struct ast_channel *chan)
Definition app_dial.c:914
static const char app[]
Definition app_dial.c:670
static const struct ast_app_option dial_exec_options[128]
Definition app_dial.c:792
#define OPT_PEER_H
Definition app_dial.c:711
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:944
#define OPT_PREDIAL_CALLEE
Definition app_dial.c:717
#define DIAL_CALLERID_ABSENT
Definition app_dial.c:709
#define OPT_FORCE_CID_PRES
Definition app_dial.c:715
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:2294
#define CAN_EARLY_BRIDGE(flags, chan, peer)
Definition app_dial.c:794
#define OPT_TOPOLOGY_PRESERVE
Definition app_dial.c:722
#define OPT_RING_WITH_EARLY_MEDIA
Definition app_dial.c:719
#define OPT_FORCE_CID_TAG
Definition app_dial.c:714
#define OPT_HEARPULSING
Definition app_dial.c:721
static int dial_exec(struct ast_channel *chan, const char *data)
Definition app_dial.c:3477
#define DIAL_NOFORWARDHTML
Definition app_dial.c:708
#define AST_MAX_WATCHERS
Definition app_dial.c:865
#define OPT_CANCEL_TIMEOUT
Definition app_dial.c:713
static void chanlist_free(struct chanlist *outgoing)
Definition app_dial.c:839
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:1156
static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
Definition app_dial.c:899
static const char rapp[]
Definition app_dial.c:671
static void handle_cause(int cause, struct cause_args *num)
Definition app_dial.c:877
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:2139
static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
Definition app_dial.c:1196
static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
Definition app_dial.c:1176
@ OPT_ARG_CALLEE_GO_ON
Definition app_dial.c:732
@ OPT_ARG_SENDDTMF
Definition app_dial.c:726
@ OPT_ARG_DURATION_STOP
Definition app_dial.c:734
@ OPT_ARG_PREDIAL_CALLEE
Definition app_dial.c:741
@ OPT_ARG_RINGBACK
Definition app_dial.c:730
@ OPT_ARG_MUSICBACK
Definition app_dial.c:729
@ OPT_ARG_CALLEE_GOSUB
Definition app_dial.c:731
@ OPT_ARG_HANGUPCAUSE
Definition app_dial.c:743
@ OPT_ARG_FORCE_CID_PRES
Definition app_dial.c:740
@ OPT_ARG_ANNOUNCE
Definition app_dial.c:725
@ OPT_ARG_GOTO
Definition app_dial.c:727
@ OPT_ARG_DURATION_LIMIT
Definition app_dial.c:728
@ OPT_ARG_ORIGINAL_CLID
Definition app_dial.c:737
@ OPT_ARG_OPERMODE
Definition app_dial.c:735
@ OPT_ARG_FORCECLID
Definition app_dial.c:738
@ OPT_ARG_PREDIAL_CALLER
Definition app_dial.c:742
@ OPT_ARG_ARRAY_SIZE
Definition app_dial.c:745
@ OPT_ARG_PRIVACY
Definition app_dial.c:733
@ OPT_ARG_SCREEN_NOINTRO
Definition app_dial.c:736
@ OPT_ARG_FORCE_CID_TAG
Definition app_dial.c:739
static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
Definition app_dial.c:1962
#define OPT_HANGUPCAUSE
Definition app_dial.c:720
static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
Definition app_dial.c:847
@ OPT_RESETCDR
Definition app_dial.c:675
@ OPT_SCREEN_NOINTRO
Definition app_dial.c:685
@ OPT_DTMF_EXIT
Definition app_dial.c:676
@ OPT_ANNOUNCE
Definition app_dial.c:674
@ OPT_CALLEE_PARK
Definition app_dial.c:698
@ OPT_DURATION_LIMIT
Definition app_dial.c:683
@ OPT_SCREEN_NOCALLERID
Definition app_dial.c:686
@ OPT_IGNORE_FORWARDING
Definition app_dial.c:700
@ OPT_OPERMODE
Definition app_dial.c:697
@ OPT_DURATION_STOP
Definition app_dial.c:691
@ OPT_GO_ON
Definition app_dial.c:679
@ OPT_RINGBACK
Definition app_dial.c:690
@ OPT_GOTO
Definition app_dial.c:696
@ OPT_IGNORE_CONNECTEDLINE
Definition app_dial.c:687
@ OPT_CALLEE_TRANSFER
Definition app_dial.c:692
@ OPT_SENDDTMF
Definition app_dial.c:677
@ OPT_CALLER_MIXMONITOR
Definition app_dial.c:703
@ OPT_CALLER_PARK
Definition app_dial.c:699
@ OPT_CALLER_MONITOR
Definition app_dial.c:695
@ OPT_CALLEE_MONITOR
Definition app_dial.c:694
@ OPT_CALLEE_GOSUB
Definition app_dial.c:701
@ OPT_CALLER_HANGUP
Definition app_dial.c:681
@ OPT_FORCECLID
Definition app_dial.c:678
@ OPT_CALLEE_HANGUP
Definition app_dial.c:680
@ OPT_SCREENING
Definition app_dial.c:688
@ OPT_MUSICBACK
Definition app_dial.c:684
@ OPT_CALLER_TRANSFER
Definition app_dial.c:693
@ OPT_CALLEE_MIXMONITOR
Definition app_dial.c:702
@ OPT_ORIGINAL_CLID
Definition app_dial.c:682
@ OPT_PRIVACY
Definition app_dial.c:689
static const struct ast_datastore_info topology_ds_info
Definition app_dial.c:832
static int load_module(void)
Definition app_dial.c:3604
static int retrydial_exec(struct ast_channel *chan, const char *data)
Definition app_dial.c:3486
static int dial_handle_playtones(struct ast_channel *chan, const char *data)
Definition app_dial.c:2254
static void end_bridge_callback(void *data)
Definition app_dial.c:2238
static int unload_module(void)
Definition app_dial.c:3594
#define OPT_CALLER_ANSWER
Definition app_dial.c:716
static struct ast_channel * wait_for_answer(struct ast_channel *in, struct dial_head *out_chans, int *to_answer, int *to_progress, 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:1209
static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition app_dial.c:2250
static int valid_priv_reply(struct ast_flags64 *opts, int res)
Definition app_dial.c:1992
#define OPT_CALLEE_GO_ON
Definition app_dial.c:712
jack_status_t status
Definition app_jack.c:149
const char * str
Definition app_jack.c:150
static int silencethreshold
char * strsep(char **str, const char *delims)
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_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#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.
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.
void ast_bridge_set_after_h(struct ast_channel *chan, const char *context)
Set channel to run the h exten after the bridge.
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:440
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
Definition callerid.c:1343
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition callerid.c:1162
@ AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER
Definition callerid.h:554
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:1101
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:4170
void ast_ignore_cc(struct ast_channel *chan)
Mark the channel to ignore further CC activity.
Definition ccss.c:3691
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:3411
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:2299
int ast_cc_completed(struct ast_channel *chan, const char *const debug,...)
Indicate recall has been acknowledged.
Definition ccss.c:3813
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:4203
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:1989
int ast_cc_call_init(struct ast_channel *chan, int *ignore_cc)
Start the CC process on a call.
Definition ccss.c:2392
int ast_cc_failed(int core_id, const char *const debug,...)
Indicate failure has occurred.
Definition ccss.c:3850
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:4215
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition cdr.c:3746
static int priority
static int connected
Definition cdr_pgsql.c:73
static PGresult * result
Definition cel_pgsql.c:84
static const char config[]
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:3145
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...
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:10510
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition channel.c:2090
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition channel.c:6429
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition channel.c:11048
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2355
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition channel.c:1725
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:10352
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition channel.c:1612
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2511
@ AST_CHANNEL_REQUESTOR_BRIDGE_PEER
Definition channel.h:1525
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:8322
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:6596
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition channel.c:2040
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:2806
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:7354
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:3127
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition channel.c:4942
#define ast_channel_lock(chan)
Definition channel.h:2972
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition channel.c:6688
void ast_channel_data_set(struct ast_channel *chan, const char *value)
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:1999
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:2022
int ast_channel_priority(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition channel.h:2979
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:2338
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:6402
const char * ast_channel_context(const struct ast_channel *chan)
void ast_deactivate_generator(struct ast_channel *chan)
Definition channel.c:2863
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:5112
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition channel.c:4223
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:9107
ast_channel_adsicpe
Definition channel.h:888
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:1967
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:1748
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:10397
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:6744
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:8799
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:6327
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition channel.c:6591
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:2791
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:4621
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:11041
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:10298
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
#define AST_CHANNEL_NAME
Definition channel.h:173
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:1659
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition channel.c:1990
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:6603
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:2147
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:8307
const char * ast_channel_call_forward(const struct ast_channel *chan)
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:6412
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:7404
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:2013
@ AST_FLAG_OUTGOING
Definition channel.h:1019
@ AST_FLAG_END_DTMF_ONLY
Definition channel.h:1027
@ AST_FLAG_MOH
Definition channel.h:1011
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.
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:2776
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:7394
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition channel.c:4243
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2973
#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:2103
@ AST_FEATURE_AUTOMIXMON
Definition channel.h:1089
@ AST_FEATURE_REDIRECT
Definition channel.h:1084
@ AST_FEATURE_PARKCALL
Definition channel.h:1088
@ AST_FEATURE_AUTOMON
Definition channel.h:1087
@ AST_FEATURE_DISCONNECT
Definition channel.h:1085
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition channel.c:2369
ast_channel_state
ast_channel states
@ AST_STATE_UP
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
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:2013
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:694
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:866
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:223
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition file.c:1312
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition file.c:1148
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
Definition file.c:1160
#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:1874
static const char name[]
Definition format_mp3.c:68
FrameHook Architecture.
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_ENTER(level,...)
#define ast_trace(level,...)
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:2154
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:2193
#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:3071
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_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_SRCUPDATE
@ AST_CONTROL_PROGRESS
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_UNHOLD
@ AST_CONTROL_VIDUPDATE
@ AST_CONTROL_PROCEEDING
@ AST_CONTROL_REDIRECTING
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_PLAYBACK_BEGIN
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_HANGUP
@ AST_CONTROL_CONNECTED_LINE
@ AST_CONTROL_FLASH
@ AST_CONTROL_SRCCHANGE
@ AST_CONTROL_PVT_CAUSE_CODE
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
Tone Indication Support.
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Asterisk locking-related definitions:
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640
Music on hold handling.
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition channel.c:7748
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition channel.c:7758
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_DATA_DIR
Definition options.c:159
Core PBX routines and definitions.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition pbx.c:4196
#define AST_PBX_INCOMPLETE
Definition pbx.h:51
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition pbx.c:8806
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition pbx.c:4729
int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
Definition pbx.c:4158
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition pbx.c:8891
Persistent data storage (akin to *doze registry)
#define AST_PRIVACY_KILL
Definition privacy.h:32
#define AST_PRIVACY_ALLOW
Definition privacy.h:31
#define AST_PRIVACY_DENY
Definition privacy.h:30
int ast_privacy_set(char *dest, char *cid, int status)
Definition privacy.c:82
int ast_privacy_check(char *dest, char *cid)
Definition privacy.c:46
#define AST_PRIVACY_UNKNOWN
Definition privacy.h:34
#define AST_PRIVACY_TORTURE
Definition privacy.h:33
static char url[512]
static struct @519 args
#define NULL
Definition resample.c:96
Pluggable RTP Architecture.
void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src)
Make two channels compatible for early bridging.
Say numbers and dates (maybe words one day too)
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
Definition sched.c:786
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Definition sched.c:433
Media Stream API.
@ AST_STREAM_STATE_RECVONLY
Set when the stream is receiving media only.
Definition stream.h:90
@ AST_STREAM_STATE_SENDONLY
Set when the stream is sending media only.
Definition stream.h:86
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state)
Set the state of a stream.
Definition stream.c:380
const char * ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf)
Get a string representing the topology for debugging/display purposes.
Definition stream.c:939
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int position)
Get a specific stream from the topology.
Definition stream.c:791
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition stream.c:768
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream)
Get the current state of a stream.
Definition stream.c:373
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition stream.c:746
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
Definition stream.c:670
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
Definition strings.h:1189
#define ast_str_alloca(init_len)
Definition strings.h:848
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition strings.h:693
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
bridge configuration
Definition channel.h:1096
void * end_bridge_callback_data
Definition channel.h:1111
Main Channel structure associated with a channel.
char exten[AST_MAX_EXTENSION]
const char * data
const struct ast_channel_tech * tech
char context[AST_MAX_CONTEXT]
Structure for a data store type.
Definition datastore.h:31
const char * type
Definition datastore.h:32
Structure for a data store object.
Definition datastore.h:64
void * data
Definition datastore.h:66
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition utils.h:222
uint64_t flags
Definition utils.h:223
struct ast_stream_topology * topology
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@239 data
Caller Party information.
Definition channel.h:420
struct ast_party_id id
Caller party ID.
Definition channel.h:422
Connected Line/Party information.
Definition channel.h:458
int source
Information about the source of an update.
Definition channel.h:484
struct ast_party_id id
Connected party ID.
Definition channel.h:460
int transit_network_select
Transit Network Select.
Definition channel.h:399
Information needed to identify an endpoint in a call.
Definition channel.h:340
struct ast_party_subaddress subaddress
Subscriber subaddress.
Definition channel.h:346
char * tag
User-set "tag".
Definition channel.h:356
struct ast_party_name name
Subscriber name.
Definition channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition channel.h:344
unsigned char valid
TRUE if the name information is valid/present.
Definition channel.h:281
char * str
Subscriber name (Malloced)
Definition channel.h:266
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition channel.h:297
unsigned char valid
TRUE if the number information is valid/present.
Definition channel.h:299
char * str
Subscriber phone number (Malloced)
Definition channel.h:293
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition channel.h:524
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition channel.h:529
struct ast_party_id to
Call is redirecting to a new party (Sent to the caller)
Definition channel.h:532
char * str
Malloced subaddress string.
Definition channel.h:315
Support for dynamic strings.
Definition strings.h:623
Description of a tone.
Definition indications.h:35
const char * data
Description of a tone.
Definition indications.h:52
int congestion
Definition app_dial.c:873
struct ast_channel * chan
Definition app_dial.c:871
List of channel drivers.
Definition app_dial.c:804
const char * number
Definition app_dial.c:812
const char * interface
Definition app_dial.c:808
struct ast_aoc_decoded * aoc_s_rate_list
Definition app_dial.c:820
struct ast_party_connected_line connected
Definition app_dial.c:817
struct chanlist::@17 node
char * orig_chan_name
Definition app_dial.c:814
char stuff[0]
Definition app_dial.c:822
struct ast_channel * chan
Definition app_dial.c:806
uint64_t flags
Definition app_dial.c:815
const char * tech
Definition app_dial.c:810
unsigned int pending_connected_update
Definition app_dial.c:819
Definition astman.c:88
structure to hold extensions
Channel datastore data for max forwards.
Number structure.
struct ast_channel * peer
char status[256]
Definition app_dial.c:1152
char privcid[256]
Definition app_dial.c:1150
char privintro[1024]
Definition app_dial.c:1151
int done
static struct test_options options
static struct test_val c
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition time.h:117
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c:2317
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition extconf.c:2280
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159
Support for translation of data formats. translate.c.
FILE * out
Definition utils/frame.c:33
FILE * in
Definition utils/frame.c:33
Utility functions.
#define ast_test_flag(p, flag)
Definition utils.h:63
#define ast_set2_flag64(p, value, flag)
Definition utils.h:168
#define ast_test_flag64(p, flag)
Definition utils.h:137
#define ast_clear_flag64(p, flag)
Definition utils.h:151
#define ast_clear_flag(p, flag)
Definition utils.h:77
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition utils.c:2515
#define ast_copy_flags64(dest, src, flagz)
Definition utils.h:158
#define ast_set_flag64(p, flag)
Definition utils.h:144
#define ast_set_flag(p, flag)
Definition utils.h:70
void ast_replace_subargument_delimiter(char *s)
Replace '^' in a string with ','.
Definition utils.c:2379