Asterisk - The Open Source Telephony Project GIT-master-35be64c
Loading...
Searching...
No Matches
func_channel.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2006, Digium, Inc.
5 *
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
11 *
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
15 */
16
17/*! \file
18 *
19 * \brief Channel info dialplan functions
20 *
21 * \author Kevin P. Fleming <kpfleming@digium.com>
22 * \author Ben Winslow
23 * \author Naveen Albert <asterisk@phreaknet.org>
24 *
25 * \ingroup functions
26 */
27
28/*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include <regex.h>
35#include <ctype.h>
36
37#include "asterisk/module.h"
38#include "asterisk/channel.h"
39#include "asterisk/bridge.h"
40#include "asterisk/pbx.h"
41#include "asterisk/utils.h"
42#include "asterisk/app.h"
49
50/*** DOCUMENTATION
51 <function name="CHANNELS" language="en_US">
52 <since>
53 <version>1.6.1.0</version>
54 </since>
55 <synopsis>
56 Gets the list of channels, optionally filtering by a regular expression.
57 </synopsis>
58 <syntax>
59 <parameter name="regular_expression" />
60 </syntax>
61 <description>
62 <para>Gets the list of channels, optionally filtering by a <replaceable>regular_expression</replaceable>. If
63 no argument is provided, all known channels are returned. The
64 <replaceable>regular_expression</replaceable> must correspond to
65 the POSIX.2 specification, as shown in <emphasis>regex(7)</emphasis>. The list returned
66 will be space-delimited.</para>
67 </description>
68 </function>
69 <function name="CHANNEL_EXISTS" language="en_US">
70 <since>
71 <version>16.22.0</version>
72 <version>18.8.0</version>
73 </since>
74 <synopsis>
75 Checks if the specified channel exists.
76 </synopsis>
77 <syntax>
78 <parameter name="name_or_uid" required="true">
79 <para>The name or unique ID of the channel to check.</para>
80 </parameter>
81 </syntax>
82 <description>
83 <para>Returns 1 if the channel <replaceable>name_or_uid</replaceable> exists, 0 if not.</para>
84 </description>
85 </function>
86 <function name="MASTER_CHANNEL" language="en_US">
87 <since>
88 <version>1.8.0</version>
89 </since>
90 <synopsis>
91 Gets or sets variables on the master channel
92 </synopsis>
93 <description>
94 <para>Allows access to the oldest channel associated with the current
95 channel if it still exists. If the channel is the master channel or
96 the master channel no longer exists then access local channel variables
97 instead. In other words, the master channel is the channel identified by
98 the channel's linkedid.</para>
99 </description>
100 </function>
101 <function name="CHANNEL" language="en_US">
102 <since>
103 <version>1.2.0</version>
104 </since>
105 <synopsis>
106 Gets/sets various pieces of information about the channel.
107 </synopsis>
108 <syntax>
109 <parameter name="item" required="true">
110 <para>Standard items (provided by all channel technologies) are:</para>
111 <enumlist>
112 <enum name="amaflags">
113 <para>R/W the Automatic Message Accounting (AMA) flags on the channel.
114 When read from a channel, the integer value will always be returned.
115 When written to a channel, both the string format or integer value
116 is accepted.</para>
117 <enumlist>
118 <enum name="1"><para><literal>OMIT</literal></para></enum>
119 <enum name="2"><para><literal>BILLING</literal></para></enum>
120 <enum name="3"><para><literal>DOCUMENTATION</literal></para></enum>
121 </enumlist>
122 </enum>
123 <enum name="accountcode">
124 <para>R/W the channel's account code.</para>
125 </enum>
126 <enum name="adsicpe">
127 <para>R/W The channel's support for ADSI (Analog Display Services Interface) CPE.</para>
128 <enumlist>
129 <enum name="available" />
130 <enum name="offhookonly" />
131 <enum name="unavailable" />
132 <enum name="unknown" />
133 </enumlist>
134 </enum>
135 <enum name="audiorawreadformat">
136 <para>R/O raw format currently being read from channel technology, before read translation.</para>
137 </enum>
138 <enum name="audiorawwriteformat">
139 <para>R/O raw format currently being written to channel technology, after write translation.</para>
140 </enum>
141 <enum name="audioreadformat">
142 <para>R/O format currently being read.</para>
143 </enum>
144 <enum name="audionativeformat">
145 <para>R/O format used natively for audio.</para>
146 </enum>
147 <enum name="audiowriteformat">
148 <para>R/O format currently being written.</para>
149 </enum>
150 <enum name="dtmf_features">
151 <para>R/W The channel's DTMF bridge features.
152 May include one or more of 'T' 'K' 'H' 'W' and 'X' in a similar manner to options
153 in the <literal>Dial</literal> application. When setting it, the features string
154 must be all upper case.</para>
155 </enum>
156 <enum name="callgroup">
157 <para>R/W numeric call pickup groups that this channel is a member.</para>
158 </enum>
159 <enum name="pickupgroup">
160 <para>R/W numeric call pickup groups this channel can pickup.</para>
161 </enum>
162 <enum name="namedcallgroup">
163 <para>R/W named call pickup groups that this channel is a member.</para>
164 </enum>
165 <enum name="namedpickupgroup">
166 <para>R/W named call pickup groups this channel can pickup.</para>
167 </enum>
168 <enum name="channeltype">
169 <para>R/O technology used for channel.</para>
170 </enum>
171 <enum name="checkhangup">
172 <para>R/O Whether the channel is hanging up (1/0)</para>
173 </enum>
174 <enum name="digitdetect">
175 <para>R/W Enable or disable DTMF detection on channel drivers that support it.</para>
176 <para>If set on a DAHDI channel, this will only disable DTMF detection, not pulse dialing detection.
177 To disable pulse dialing, use the <literal>dialmode</literal> option.</para>
178 <para>On DAHDI channels, this will disable DSP if it is not needed for anything else.
179 This will prevent DTMF detection regardless of the <literal>dialmode</literal> setting.</para>
180 </enum>
181 <enum name="faxdetect">
182 <para>R/W Enable or disable fax detection on channel drivers that support it.</para>
183 </enum>
184 <enum name="after_bridge_goto">
185 <para>R/W the parseable goto string indicating where the channel is
186 expected to return to in the PBX after exiting the next bridge it joins
187 on the condition that it doesn't hang up. The parseable goto string uses
188 the same syntax as the <literal>Goto</literal> application.</para>
189 </enum>
190 <enum name="hangup_handler_pop">
191 <para>W/O Replace the most recently added hangup handler
192 with a new hangup handler on the channel if supplied. The
193 assigned string is passed to the Gosub application when
194 the channel is hung up. Any optionally omitted context
195 and exten are supplied by the channel pushing the handler
196 before it is pushed.</para>
197 </enum>
198 <enum name="hangup_handler_push">
199 <para>W/O Push a hangup handler onto the channel hangup
200 handler stack. The assigned string is passed to the
201 Gosub application when the channel is hung up. Any
202 optionally omitted context and exten are supplied by the
203 channel pushing the handler before it is pushed.</para>
204 </enum>
205 <enum name="hangup_handler_wipe">
206 <para>W/O Wipe the entire hangup handler stack and replace
207 with a new hangup handler on the channel if supplied. The
208 assigned string is passed to the Gosub application when
209 the channel is hung up. Any optionally omitted context
210 and exten are supplied by the channel pushing the handler
211 before it is pushed.</para>
212 </enum>
213 <enum name="onhold">
214 <para>R/O Whether or not the channel is onhold. (1/0)</para>
215 </enum>
216 <enum name="language">
217 <para>R/W language for sounds played.</para>
218 </enum>
219 <enum name="musicclass">
220 <para>R/W class (from musiconhold.conf) for hold music.</para>
221 </enum>
222 <enum name="name">
223 <para>The name of the channel</para>
224 </enum>
225 <enum name="parkinglot">
226 <para>R/W parkinglot for parking.</para>
227 </enum>
228 <enum name="relaxdtmf">
229 <para>W/O Enable or disable relaxed DTMF detection for channel drivers that support it,
230 overriding any setting previously defaulted by the channel driver.</para>
231 </enum>
232 <enum name="rxgain">
233 <para>R/W set rxgain level on channel drivers that support it.</para>
234 </enum>
235 <enum name="secure_bridge_signaling">
236 <para>Whether or not channels bridged to this channel require secure signaling (1/0)</para>
237 </enum>
238 <enum name="secure_bridge_media">
239 <para>Whether or not channels bridged to this channel require secure media (1/0)</para>
240 </enum>
241 <enum name="state">
242 <para>R/O state of the channel</para>
243 </enum>
244 <enum name="tdd">
245 <para>R/W Enable or disable TDD mode on channel drivers that support it.</para>
246 <para>When reading this option, 1 indicates TDD mode enabled, 0 indicates TDD mode disabled,
247 and <literal>mate</literal> indicates TDD mate mode.</para>
248 </enum>
249 <enum name="tonezone">
250 <para>R/W zone for indications played</para>
251 </enum>
252 <enum name="transfercapability">
253 <para>R/W ISDN Transfer Capability, one of:</para>
254 <enumlist>
255 <enum name="SPEECH" />
256 <enum name="DIGITAL" />
257 <enum name="RESTRICTED_DIGITAL" />
258 <enum name="3K1AUDIO" />
259 <enum name="DIGITAL_W_TONES" />
260 <enum name="VIDEO" />
261 </enumlist>
262 </enum>
263 <enum name="txgain">
264 <para>R/W set txgain level on channel drivers that support it.</para>
265 </enum>
266 <enum name="videonativeformat">
267 <para>R/O format used natively for video</para>
268 </enum>
269 <enum name="hangupsource">
270 <para>R/W returns the channel responsible for hangup.</para>
271 </enum>
272 <enum name="appname">
273 <para>R/O returns the internal application name.</para>
274 </enum>
275 <enum name="appdata">
276 <para>R/O returns the application data if available.</para>
277 </enum>
278 <enum name="exten">
279 <para>R/O returns the extension for an outbound channel.</para>
280 </enum>
281 <enum name="context">
282 <para>R/O returns the context for an outbound channel.</para>
283 </enum>
284 <enum name="lastexten">
285 <para>R/O returns the last unique extension for an outbound channel.</para>
286 </enum>
287 <enum name="lastcontext">
288 <para>R/O returns the last unique context for an outbound channel.</para>
289 </enum>
290 <enum name="channame">
291 <para>R/O returns the channel name for an outbound channel.</para>
292 </enum>
293 <enum name="uniqueid">
294 <para>R/O returns the channel uniqueid.</para>
295 </enum>
296 <enum name="linkedid">
297 <para>R/O returns the linkedid if available, otherwise returns the uniqueid.</para>
298 </enum>
299 <enum name="tenantid">
300 <para>R/W The channel tenantid.</para>
301 </enum>
302 <enum name="max_forwards">
303 <para>R/W The maximum number of forwards allowed.</para>
304 </enum>
305 <enum name="callid">
306 <para>R/O Call identifier log tag associated with the channel
307 e.g., <literal>[C-00000000]</literal>.</para>
308 </enum>
309 </enumlist>
310 <xi:include xpointer="xpointer(/docs/info[@name='CHANNEL'])" />
311 </parameter>
312 </syntax>
313 <description>
314 <para>Gets/sets various pieces of information about the channel, additional <replaceable>item</replaceable> may
315 be available from the channel driver; see its documentation for details. Any <replaceable>item</replaceable>
316 requested that is not available on the current channel will return an empty string.</para>
317 <example title="Standard CHANNEL item examples">
318 ; Push a hangup handler subroutine existing at dialplan
319 ; location default,s,1 onto the current channel
320 same => n,Set(CHANNEL(hangup_handler_push)=default,s,1)
321
322 ; Set the current tonezone to Germany (de)
323 same => n,Set(CHANNEL(tonezone)=de)
324
325 ; Set the allowed maximum number of forwarding attempts
326 same => n,Set(CHANNEL(max_forwards)=10)
327
328 ; If this channel is ejected from its next bridge, and if
329 ; the channel is not hung up, begin executing dialplan at
330 ; location default,after-bridge,1
331 same => n,Set(CHANNEL(after_bridge_goto)=default,after-bridge,1)
332
333 ; Log the current state of the channel
334 same => n,Log(NOTICE, This channel is: ${CHANNEL(state)})
335 </example>
336 <xi:include xpointer="xpointer(/docs/info[@name='CHANNEL_EXAMPLES'])" />
337 <para>The following channel variables are available as special built-in
338 dialplan channel variables. These variables cannot be set or modified
339 and are read-only.</para>
340 <variablelist>
341 <variable name="CALLINGPRES">
342 <para>Caller ID presentation for incoming calls (PRI channels)</para>
343 </variable>
344 <variable name="CALLINGANI2">
345 <para>Caller ANI2 (PRI channels)</para>
346 </variable>
347 <variable name="CALLINGTON">
348 <para>Caller Type of Number (PRI channels)</para>
349 </variable>
350 <variable name="CALLINGTNS">
351 <para>Transit Network Selector (PRI channels)</para>
352 </variable>
353 <variable name="EXTEN">
354 <para>Current extension</para>
355 </variable>
356 <variable name="CONTEXT">
357 <para>Current context</para>
358 </variable>
359 <variable name="PRIORITY">
360 <para>Current priority</para>
361 </variable>
362 <variable name="CHANNEL">
363 <para>Current channel name</para>
364 </variable>
365 <variable name="UNIQUEID">
366 <para>Current call unique identifier</para>
367 </variable>
368 <variable name="HANGUPCAUSE">
369 <para>Asterisk cause of hangup (inbound/outbound)</para>
370 </variable>
371 </variablelist>
372 </description>
373 </function>
374 ***/
375
376#define locked_copy_string(chan, dest, source, len) \
377 do { \
378 ast_channel_lock(chan); \
379 ast_copy_string(dest, source, len); \
380 ast_channel_unlock(chan); \
381 } while (0)
382#define locked_string_field_set(chan, field, source) \
383 do { \
384 ast_channel_lock(chan); \
385 ast_channel_##field##_set(chan, source); \
386 ast_channel_unlock(chan); \
387 } while (0)
388
389static const char * const transfercapability_table[0x20] = {
390 "SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
391 "DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
392 "3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
393 "VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", };
394
395static int func_channel_read(struct ast_channel *chan, const char *function,
396 char *data, char *buf, size_t len)
397{
398 int ret = 0;
399 struct ast_format_cap *tmpcap;
400
401 if (!chan) {
402 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
403 return -1;
404 }
405
406 if (!strcasecmp(data, "audionativeformat")) {
408 if (tmpcap) {
410
411 ast_channel_lock(chan);
413 ast_channel_unlock(chan);
414 ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
415 ao2_ref(tmpcap, -1);
416 }
417 } else if (!strcasecmp(data, "videonativeformat")) {
419 if (tmpcap) {
421
422 ast_channel_lock(chan);
424 ast_channel_unlock(chan);
425 ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
426 ao2_ref(tmpcap, -1);
427 }
428 } else if (!strcasecmp(data, "audiorawreadformat")) {
430 } else if (!strcasecmp(data, "audiorawwriteformat")) {
432 } else if (!strcasecmp(data, "audioreadformat")) {
434 } else if (!strcasecmp(data, "audiowriteformat")) {
436 } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
438 } else if (!strcasecmp(data, "adsicpe")) {
439 int adsi;
440 ast_channel_lock(chan);
442 ast_channel_unlock(chan);
443 switch (adsi) {
445 ast_copy_string(buf, "available", len);
446 break;
448 ast_copy_string(buf, "unavailable", len);
449 break;
451 ast_copy_string(buf, "offhookonly", len);
452 break;
453 default:
454 ast_copy_string(buf, "unknown", len);
455 break;
456 }
457 } else if (!strcasecmp(data, "dtmf_features")) {
459 buf[0] = '\0';
460 }
461 } else if (!strcasecmp(data, "language"))
463 else if (!strcasecmp(data, "musicclass"))
465 else if (!strcasecmp(data, "name")) {
467 } else if (!strcasecmp(data, "parkinglot"))
469 else if (!strcasecmp(data, "state"))
471 else if (!strcasecmp(data, "onhold")) {
473 ast_channel_hold_state(chan) == AST_CONTROL_HOLD ? "1" : "0", len);
474 } else if (!strcasecmp(data, "channeltype"))
476 ast_channel_tech(chan) ? ast_channel_tech(chan)->type : "", len);
477 else if (!strcasecmp(data, "accountcode"))
479 else if (!strcasecmp(data, "checkhangup")) {
480 locked_copy_string(chan, buf, ast_check_hangup(chan) ? "1" : "0", len);
481 } else if (!strcasecmp(data, "peeraccount"))
483 else if (!strcasecmp(data, "hangupsource"))
485 else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
487 else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
489 else if (!strcasecmp(data, "exten"))
491 else if (!strcasecmp(data, "context"))
493 else if (!strcasecmp(data, "lastexten"))
495 else if (!strcasecmp(data, "lastcontext"))
497 else if (!strcasecmp(data, "userfield"))
499 else if (!strcasecmp(data, "channame"))
501 else if (!strcasecmp(data, "linkedid")) {
502 ast_channel_lock(chan);
504 /* fall back on the channel's uniqueid if linkedid is unset */
506 }
507 else {
509 }
510 ast_channel_unlock(chan);
511 } else if (!strcasecmp(data, "peer")) {
512 struct ast_channel *peer;
513
514 peer = ast_channel_bridge_peer(chan);
515 if (peer) {
516 /* Only real channels could have a bridge peer this way. */
517 ast_channel_lock(peer);
519 ast_channel_unlock(peer);
520 ast_channel_unref(peer);
521 } else {
522 buf[0] = '\0';
523 ast_channel_lock(chan);
524 if (!ast_channel_tech(chan)) {
525 const char *pname;
526
527 /*
528 * A dummy channel can still pass along bridged peer info
529 * via the BRIDGEPEER variable.
530 *
531 * A horrible kludge, but... how else?
532 */
533 pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
534 if (!ast_strlen_zero(pname)) {
535 ast_copy_string(buf, pname, len);
536 }
537 }
538 ast_channel_unlock(chan);
539 }
540 } else if (!strcasecmp(data, "uniqueid")) {
542 } else if (!strcasecmp(data, "transfercapability")) {
544 } else if (!strcasecmp(data, "callgroup")) {
545 char groupbuf[256];
546
547 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
548 } else if (!strcasecmp(data, "pickupgroup")) {
549 char groupbuf[256];
550
551 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
552 } else if (!strcasecmp(data, "namedcallgroup")) {
553 struct ast_str *tmp_str = ast_str_alloca(1024);
554
556 } else if (!strcasecmp(data, "namedpickupgroup")) {
557 struct ast_str *tmp_str = ast_str_alloca(1024);
558
560 } else if (!strcasecmp(data, "after_bridge_goto")) {
562 } else if (!strcasecmp(data, "amaflags")) {
563 ast_channel_lock(chan);
564 snprintf(buf, len, "%u", ast_channel_amaflags(chan));
565 ast_channel_unlock(chan);
566 } else if (!strncasecmp(data, "secure_bridge_", 14)) {
567 struct ast_datastore *ds;
568
569 buf[0] = '\0';
570 ast_channel_lock(chan);
572 struct ast_secure_call_store *encrypt = ds->data;
573
574 if (!strcasecmp(data, "secure_bridge_signaling")) {
575 snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
576 } else if (!strcasecmp(data, "secure_bridge_media")) {
577 snprintf(buf, len, "%s", encrypt->media ? "1" : "");
578 }
579 }
580 ast_channel_unlock(chan);
581 } else if (!strcasecmp(data, "max_forwards")) {
582 ast_channel_lock(chan);
583 snprintf(buf, len, "%d", ast_max_forwards_get(chan));
584 ast_channel_unlock(chan);
585 } else if (!strcasecmp(data, "callid")) {
586 ast_callid callid;
587
588 buf[0] = '\0';
589 ast_channel_lock(chan);
590 callid = ast_channel_callid(chan);
591 if (callid) {
592 ast_callid_strnprint(buf, len, callid);
593 }
594 ast_channel_unlock(chan);
595 } else if (!strcasecmp(data, "tdd")) {
596 char status;
597 int status_size = (int) sizeof(status);
598 ret = ast_channel_queryoption(chan, AST_OPTION_TDD, &status, &status_size, 0);
599 if (!ret) {
600 ast_copy_string(buf, status == 2 ? "mate" : status ? "1" : "0", len);
601 }
602 } else if (!strcasecmp(data, "digitdetect")) {
603 char status;
604 int status_size = (int) sizeof(status);
605 ret = ast_channel_queryoption(chan, AST_OPTION_DIGIT_DETECT, &status, &status_size, 0);
606 if (!ret) {
607 ast_copy_string(buf, status ? "1" : "0", len);
608 }
609 } else if (!strcasecmp(data, "faxdetect")) {
610 char status;
611 int status_size = (int) sizeof(status);
612 ret = ast_channel_queryoption(chan, AST_OPTION_FAX_DETECT, &status, &status_size, 0);
613 if (!ret) {
614 ast_copy_string(buf, status ? "1" : "0", len);
615 }
616 } else if (!strcasecmp(data, "device_name")) {
617 ret = ast_channel_get_device_name(chan, buf, len);
618 } else if (!strcasecmp(data, "tenantid")) {
620 } else if (!ast_channel_tech(chan) || !ast_channel_tech(chan)->func_channel_read || ast_channel_tech(chan)->func_channel_read(chan, function, data, buf, len)) {
621 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
622 ret = -1;
623 }
624
625 return ret;
626}
627
628static int func_channel_write_real(struct ast_channel *chan, const char *function,
629 char *data, const char *value)
630{
631 int ret = 0;
632 signed char gainset;
633
634 if (!strcasecmp(data, "language"))
636 else if (!strcasecmp(data, "parkinglot"))
637 locked_string_field_set(chan, parkinglot, value);
638 else if (!strcasecmp(data, "musicclass"))
639 locked_string_field_set(chan, musicclass, value);
640 else if (!strcasecmp(data, "accountcode"))
642 else if (!strcasecmp(data, "userfield"))
643 locked_string_field_set(chan, userfield, value);
644 else if (!strcasecmp(data, "after_bridge_goto")) {
645 if (ast_strlen_zero(value)) {
647 } else {
649 }
650 } else if (!strcasecmp(data, "amaflags")) {
651 int amaflags;
652
653 if (isdigit(*value)) {
654 if (sscanf(value, "%30d", &amaflags) != 1) {
656 }
657 } else {
659 }
660 ast_channel_lock(chan);
662 ast_channel_unlock(chan);
663 } else if (!strcasecmp(data, "peeraccount"))
664 locked_string_field_set(chan, peeraccount, value);
665 else if (!strcasecmp(data, "hangupsource"))
666 /* XXX - should we be forcing this here? */
667 ast_set_hangupsource(chan, value, 0);
668 else if (!strcasecmp(data, "tonezone")) {
669 struct ast_tone_zone *new_zone;
670 if (!(new_zone = ast_get_indication_zone(value))) {
671 ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
672 ret = -1;
673 } else {
674 ast_channel_lock(chan);
675 if (ast_channel_zone(chan)) {
677 }
679 ast_channel_unlock(chan);
680 new_zone = ast_tone_zone_unref(new_zone);
681 }
682 } else if (!strcasecmp(data, "adsicpe")) {
683 int adsi;
684 if (!strcasecmp(value, "unknown")) {
686 } else if (!strcasecmp(value, "available")) {
688 } else if (!strcasecmp(value, "unavailable")) {
690 } else if (!strcasecmp(value, "offhookonly")) {
692 } else {
693 ast_log(LOG_ERROR, "Unknown ADSI availability '%s'\n", value);
694 return -1;
695 }
696 ast_channel_lock(chan);
698 ast_channel_unlock(chan);
699 } else if (!strcasecmp(data, "dtmf_features")) {
701 } else if (!strcasecmp(data, "callgroup")) {
702 ast_channel_lock(chan);
704 ast_channel_unlock(chan);
705 } else if (!strcasecmp(data, "pickupgroup")) {
706 ast_channel_lock(chan);
708 ast_channel_unlock(chan);
709 } else if (!strcasecmp(data, "namedcallgroup")) {
710 struct ast_namedgroups *groups = ast_get_namedgroups(value);
711
712 ast_channel_lock(chan);
714 ast_channel_unlock(chan);
716 } else if (!strcasecmp(data, "namedpickupgroup")) {
717 struct ast_namedgroups *groups = ast_get_namedgroups(value);
718
719 ast_channel_lock(chan);
721 ast_channel_unlock(chan);
723 } else if (!strcasecmp(data, "tdd")) {
724 char enabled;
725 if (!strcasecmp(value, "mate")) {
726 enabled = 2;
727 } else {
728 enabled = ast_true(value) ? 1 : 0;
729 }
731 } else if (!strcasecmp(data, "relaxdtmf")) {
732 char enabled = ast_true(value) ? 1 : 0;
734 } else if (!strcasecmp(data, "txgain")) {
735 sscanf(value, "%4hhd", &gainset);
736 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
737 } else if (!strcasecmp(data, "rxgain")) {
738 sscanf(value, "%4hhd", &gainset);
739 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
740 } else if (!strcasecmp(data, "digitdetect")) {
741 char enabled = ast_true(value) ? 1 : 0;
743 } else if (!strcasecmp(data, "faxdetect")) {
744 char enabled = ast_true(value) ? 1 : 0;
746 } else if (!strcasecmp(data, "transfercapability")) {
747 unsigned short i;
748
749 ast_channel_lock(chan);
750 for (i = 0; i < 0x20; i++) {
751 if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
753 break;
754 }
755 }
756 ast_channel_unlock(chan);
757 } else if (!strcasecmp(data, "hangup_handler_pop")) {
758 /* Pop one hangup handler before pushing the new handler. */
761 } else if (!strcasecmp(data, "hangup_handler_push")) {
763 } else if (!strcasecmp(data, "hangup_handler_wipe")) {
764 /* Pop all hangup handlers before pushing the new handler. */
765 while (ast_pbx_hangup_handler_pop(chan)) {
766 }
768 } else if (!strncasecmp(data, "secure_bridge_", 14)) {
769 struct ast_datastore *ds;
770 struct ast_secure_call_store *store;
771
772 if (!chan || !value) {
773 return -1;
774 }
775
776 ast_channel_lock(chan);
777 if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
779 ast_channel_unlock(chan);
780 return -1;
781 }
782 if (!(store = ast_calloc(1, sizeof(*store)))) {
783 ast_channel_unlock(chan);
784 ast_free(ds);
785 return -1;
786 }
787 ds->data = store;
789 } else {
790 store = ds->data;
791 }
792
793 if (!strcasecmp(data, "secure_bridge_signaling")) {
794 store->signaling = ast_true(value) ? 1 : 0;
795 } else if (!strcasecmp(data, "secure_bridge_media")) {
796 store->media = ast_true(value) ? 1 : 0;
797 }
798 ast_channel_unlock(chan);
799 } else if (!strcasecmp(data, "max_forwards")) {
800 int max_forwards;
801 if (sscanf(value, "%d", &max_forwards) != 1) {
802 ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value);
803 ret = -1;
804 } else {
805 ast_channel_lock(chan);
807 ast_channel_unlock(chan);
808 }
809 } else if (!strcasecmp(data, "tenantid")) {
811 } else if (!ast_channel_tech(chan)
813 || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
814 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
815 data);
816 ret = -1;
817 }
818
819 return ret;
820}
821
822static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
823{
824 int res;
825 ast_chan_write_info_t write_info = {
827 .write_fn = func_channel_write_real,
828 .chan = chan,
829 .function = function,
830 .data = data,
831 .value = value,
832 };
833
834 if (!chan) {
835 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
836 return -1;
837 }
838
839 res = func_channel_write_real(chan, function, data, value);
840 ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
841
842 return res;
843}
844
846 .name = "CHANNEL",
847 .read = func_channel_read,
848 .write = func_channel_write,
849};
850
851static int func_channels_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
852{
853 struct ast_channel *c = NULL;
854 regex_t re;
855 int res;
856 size_t buflen = 0;
857 struct ast_channel_iterator *iter;
858
859 buf[0] = '\0';
860
861 if (!ast_strlen_zero(data)) {
862 if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
863 regerror(res, &re, buf, maxlen);
864 ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
865 return -1;
866 }
867 }
868
869 if (!(iter = ast_channel_iterator_all_new())) {
870 if (!ast_strlen_zero(data)) {
871 regfree(&re);
872 }
873 return -1;
874 }
875
876 while ((c = ast_channel_iterator_next(iter))) {
878 if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
879 size_t namelen = strlen(ast_channel_name(c));
880 if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
881 if (!ast_strlen_zero(buf)) {
882 strcat(buf, " ");
883 buflen++;
884 }
885 strcat(buf, ast_channel_name(c));
886 buflen += namelen;
887 } else {
888 ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n");
889 }
890 }
893 }
894
896
897 if (!ast_strlen_zero(data)) {
898 regfree(&re);
899 }
900
901 return 0;
902}
903
905 .name = "CHANNELS",
906 .read = func_channels_read,
907};
908
909static int func_chan_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
910{
911 struct ast_channel *chan_found = NULL;
912
913 if (ast_strlen_zero(data)) {
914 ast_log(LOG_WARNING, "%s: Channel name or unique ID required\n", function);
915 return -1;
916 }
917
918 chan_found = ast_channel_get_by_name(data);
919 snprintf(buf, maxlen, "%d", (chan_found ? 1 : 0));
920 if (chan_found) {
921 ast_channel_unref(chan_found);
922 }
923 return 0;
924}
925
927 .name = "CHANNEL_EXISTS",
928 .read = func_chan_exists_read,
929};
930
931static int func_mchan_read(struct ast_channel *chan, const char *function,
932 char *data, struct ast_str **buf, ssize_t len)
933{
934 struct ast_channel *mchan;
935 char *template = ast_alloca(4 + strlen(data));
936
937 if (!chan) {
938 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
939 return -1;
940 }
941
943 sprintf(template, "${%s}", data); /* SAFE */
944 ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
945 if (mchan) {
946 ast_channel_unref(mchan);
947 }
948 return 0;
949}
950
951static int func_mchan_write(struct ast_channel *chan, const char *function,
952 char *data, const char *value)
953{
954 struct ast_channel *mchan;
955
956 if (!chan) {
957 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
958 return -1;
959 }
960
962 pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
963 if (mchan) {
964 ast_channel_unref(mchan);
965 }
966 return 0;
967}
968
970 .name = "MASTER_CHANNEL",
971 .read2 = func_mchan_read,
972 .write = func_mchan_write,
973};
974
986
987static int load_module(void)
988{
989 int res = 0;
990
995
996 return res;
997}
998
999AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel information dialplan functions");
jack_status_t status
Definition app_jack.c:149
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition astmm.h:288
#define ast_free(a)
Definition astmm.h:180
#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
Bridging API.
After Bridge Execution API.
void ast_bridge_discard_after_goto(struct ast_channel *chan)
Discard channel after bridge goto location.
void ast_bridge_read_after_goto(struct ast_channel *chan, char *buffer, size_t buf_size)
Read after bridge goto if it exists.
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.
Basic bridge subclass API.
int ast_bridge_features_ds_get_string(struct ast_channel *chan, char *buffer, size_t buf_size)
writes a channel's DTMF features to a buffer string
int ast_bridge_features_ds_set_string(struct ast_channel *chan, const char *features)
Sets the features a channel will use upon being bridged.
static int adsi
Definition chan_iax2.c:514
static int amaflags
Definition chan_iax2.c:513
static char language[MAX_LANGUAGE]
Definition chan_iax2.c:361
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition chan_iax2.c:510
General Asterisk PBX channel definitions.
const char * ast_channel_linkedid(const struct ast_channel *chan)
const char * ast_channel_name(const struct ast_channel *chan)
char * ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *groups)
Print named call groups and named pickup groups.
Definition channel.c:8232
void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *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:10676
struct ast_namedgroups * ast_channel_named_pickupgroups(const struct ast_channel *chan)
const char * ast_channel_data(const struct ast_channel *chan)
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2376
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
void ast_channel_tenantid_set(struct ast_channel *chan, const char *value)
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition channel.c:1349
struct ast_channel * ast_channel_bridge_peer(struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition channel.c:10744
const char * ast_channel_tenantid(const struct ast_channel *chan)
const char * ast_channel_musicclass(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition channel.h:2983
const char * ast_channel_lastexten(const struct ast_channel *chan)
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
struct ast_namedgroups * ast_channel_named_callgroups(const struct ast_channel *chan)
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition channel.c:1388
int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block)
Checks the value of an option.
Definition channel.c:7478
int ast_channel_priority(const struct ast_channel *chan)
ast_callid ast_channel_callid(const struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_accountcode(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_channel_userfield(const struct ast_channel *chan)
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call and pickup groups into buffer.
Definition channel.c:8207
@ AST_AMA_NONE
Definition channel.h:1198
const char * ast_channel_parkinglot(const struct ast_channel *chan)
ast_channel_adsicpe
Definition channel.h:888
@ AST_ADSI_UNKNOWN
Definition channel.h:889
@ AST_ADSI_UNAVAILABLE
Definition channel.h:891
@ AST_ADSI_AVAILABLE
Definition channel.h:890
@ AST_ADSI_OFFHOOKONLY
Definition channel.h:892
const char * ast_channel_appl(const struct ast_channel *chan)
const char * ast_channel_peeraccount(const struct ast_channel *chan)
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1417
enum ama_flags ast_channel_amaflags(const struct ast_channel *chan)
struct ast_namedgroups * ast_get_namedgroups(const char *s)
Create an ast_namedgroups set with group names from comma separated string.
Definition channel.c:7711
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
struct ast_format * ast_channel_rawwriteformat(struct ast_channel *chan)
const char * ast_channel_hangupsource(const struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition channel.c:446
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
Definition channel.c:2498
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
const char * ast_channel_lastcontext(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3019
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
int ast_channel_hold_state(const struct ast_channel *chan)
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
const char * ast_channel_language(const struct ast_channel *chan)
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
Definition channel.c:637
enum ama_flags ast_channel_string2amaflag(const char *flag)
Convert a string to a detail record AMA flag.
Definition channel.c:4382
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
#define AST_CHAN_WRITE_INFO_T_VERSION
ast_chan_write_info_t version. Must be incremented if structure is changed
Definition channel.h:593
struct ast_namedgroups * ast_unref_namedgroups(struct ast_namedgroups *groups)
Definition channel.c:7768
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:7458
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
ast_group_t ast_get_group(const char *s)
Definition channel.c:7654
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition channel.c:1380
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2984
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:2390
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
ast_channel_state
ast_channel states
@ AST_MEDIA_TYPE_AUDIO
Definition codec.h:32
@ AST_MEDIA_TYPE_VIDEO
Definition codec.h:33
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
static int enabled
Definition dnsmgr.c:91
char buf[BUFSIZE]
Definition eagi_proxy.c:66
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition format.c:334
#define AST_FORMAT_CAP_NAMES_LEN
Definition format_cap.h:324
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition format_cap.h:38
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition format_cap.c:269
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition format_cap.c:742
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition format_cap.h:49
#define locked_string_field_set(chan, field, source)
static int func_mchan_read(struct ast_channel *chan, const char *function, char *data, struct ast_str **buf, ssize_t len)
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value)
static struct ast_custom_function channels_function
static struct ast_custom_function channel_function
static int func_channels_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
#define locked_copy_string(chan, dest, source, len)
static struct ast_custom_function mchan_function
static int func_chan_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
static int load_module(void)
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
static int func_mchan_write(struct ast_channel *chan, const char *function, char *data, const char *value)
static int unload_module(void)
static struct ast_custom_function chan_exists_function
static const char *const transfercapability_table[0x20]
static int func_channel_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
globally accessible channel datastores
const struct ast_datastore_info secure_call_info
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_OPTION_RELAXDTMF
#define AST_OPTION_RXGAIN
#define AST_OPTION_DIGIT_DETECT
#define AST_OPTION_CHANNEL_WRITE
Handle channel write data If a channel needs to process the data from a func_channel write operation ...
#define AST_OPTION_TDD
#define AST_OPTION_FAX_DETECT
#define AST_OPTION_TXGAIN
void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid)
copy a string representation of the callid into a target string
Definition logger.c:2277
unsigned int ast_callid
#define LOG_ERROR
#define LOG_WARNING
Tone Indication Support.
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
int ast_max_forwards_set(struct ast_channel *chan, int starting_count)
Set the starting max forwards for a particular channel.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
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.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
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.
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1563
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
void ast_pbx_hangup_handler_push(struct ast_channel *chan, const char *handler)
Push the given hangup handler onto the channel hangup handler stack.
int ast_pbx_hangup_handler_pop(struct ast_channel *chan)
Pop the top of the channel hangup handler stack.
static char country[80]
Definition pbx_dundi.c:214
#define NULL
Definition resample.c:96
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2233
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_alloca(init_len)
Definition strings.h:848
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
Structure to handle passing func_channel_write info to channels via setoption.
Definition channel.h:591
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition channel.h:648
const char *const type
Definition channel.h:649
Main Channel structure associated with a channel.
const char * data
Data structure associated with a custom dialplan function.
Definition pbx.h:118
const char * name
Definition pbx.h:119
Structure for a data store object.
Definition datastore.h:64
void * data
Definition datastore.h:66
Format capabilities structure, holds formats + preference order + etc.
Definition format_cap.c:54
Support for dynamic strings.
Definition strings.h:623
A set of tones for a given locale.
Definition indications.h:74
Channel datastore data for max forwards.
int value
Definition syslog.c:37
static struct test_val c
Utility functions.