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