Asterisk - The Open Source Telephony Project GIT-master-a358458
Macros | Functions | Variables
func_channel.c File Reference

Channel info dialplan functions. More...

#include "asterisk.h"
#include <regex.h>
#include <ctype.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/bridge.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/indications.h"
#include "asterisk/stringfields.h"
#include "asterisk/global_datastores.h"
#include "asterisk/bridge_basic.h"
#include "asterisk/bridge_after.h"
#include "asterisk/max_forwards.h"
Include dependency graph for func_channel.c:

Go to the source code of this file.

Macros

#define locked_copy_string(chan, dest, source, len)
 
#define locked_string_field_set(chan, field, source)
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int func_chan_exists_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
 
static int func_channel_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
 
static int func_channel_write (struct ast_channel *chan, const char *function, char *data, const char *value)
 
static int func_channel_write_real (struct ast_channel *chan, const char *function, char *data, const char *value)
 
static int func_channels_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
 
static int func_mchan_read (struct ast_channel *chan, const char *function, char *data, struct ast_str **buf, ssize_t len)
 
static int func_mchan_write (struct ast_channel *chan, const char *function, char *data, const char *value)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Channel information dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function chan_exists_function
 
static struct ast_custom_function channel_function
 
static struct ast_custom_function channels_function
 
static struct ast_custom_function mchan_function
 
static const char *const transfercapability_table [0x20]
 

Detailed Description

Channel info dialplan functions.

Author
Kevin P. Fleming kpfle.nosp@m.ming.nosp@m.@digi.nosp@m.um.c.nosp@m.om
Ben Winslow
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

Definition in file func_channel.c.

Macro Definition Documentation

◆ locked_copy_string

#define locked_copy_string (   chan,
  dest,
  source,
  len 
)
Value:
do { \
ast_channel_lock(chan); \
ast_copy_string(dest, source, len); \
ast_channel_unlock(chan); \
} while (0)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

Definition at line 350 of file func_channel.c.

◆ locked_string_field_set

#define locked_string_field_set (   chan,
  field,
  source 
)
Value:
do { \
ast_channel_lock(chan); \
ast_channel_##field##_set(chan, source); \
ast_channel_unlock(chan); \
} while (0)

Definition at line 356 of file func_channel.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 927 of file func_channel.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 927 of file func_channel.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 927 of file func_channel.c.

◆ func_chan_exists_read()

static int func_chan_exists_read ( struct ast_channel chan,
const char *  function,
char *  data,
char *  buf,
size_t  maxlen 
)
static

Definition at line 837 of file func_channel.c.

838{
839 struct ast_channel *chan_found = NULL;
840
841 if (ast_strlen_zero(data)) {
842 ast_log(LOG_WARNING, "%s: Channel name or unique ID required\n", function);
843 return -1;
844 }
845
846 chan_found = ast_channel_get_by_name(data);
847 snprintf(buf, maxlen, "%d", (chan_found ? 1 : 0));
848 if (chan_found) {
849 ast_channel_unref(chan_found);
850 }
851 return 0;
852}
#define ast_log
Definition: astobj2.c:42
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
const char * data

References ast_channel_get_by_name(), ast_channel_unref, ast_log, ast_strlen_zero(), buf, ast_channel::data, LOG_WARNING, and NULL.

◆ func_channel_read()

static int func_channel_read ( struct ast_channel chan,
const char *  function,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 369 of file func_channel.c.

371{
372 int ret = 0;
373 struct ast_format_cap *tmpcap;
374
375 if (!chan) {
376 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
377 return -1;
378 }
379
380 if (!strcasecmp(data, "audionativeformat")) {
382 if (tmpcap) {
384
385 ast_channel_lock(chan);
387 ast_channel_unlock(chan);
388 ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
389 ao2_ref(tmpcap, -1);
390 }
391 } else if (!strcasecmp(data, "videonativeformat")) {
393 if (tmpcap) {
395
396 ast_channel_lock(chan);
398 ast_channel_unlock(chan);
399 ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
400 ao2_ref(tmpcap, -1);
401 }
402 } else if (!strcasecmp(data, "audioreadformat")) {
404 } else if (!strcasecmp(data, "audiowriteformat")) {
406 } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
408 } else if (!strcasecmp(data, "dtmf_features")) {
410 buf[0] = '\0';
411 }
412 } else if (!strcasecmp(data, "language"))
414 else if (!strcasecmp(data, "musicclass"))
416 else if (!strcasecmp(data, "name")) {
418 } else if (!strcasecmp(data, "parkinglot"))
420 else if (!strcasecmp(data, "state"))
422 else if (!strcasecmp(data, "onhold")) {
424 ast_channel_hold_state(chan) == AST_CONTROL_HOLD ? "1" : "0", len);
425 } else if (!strcasecmp(data, "channeltype"))
427 else if (!strcasecmp(data, "accountcode"))
429 else if (!strcasecmp(data, "checkhangup")) {
430 locked_copy_string(chan, buf, ast_check_hangup(chan) ? "1" : "0", len);
431 } else if (!strcasecmp(data, "peeraccount"))
433 else if (!strcasecmp(data, "hangupsource"))
435 else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
437 else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
439 else if (!strcasecmp(data, "exten"))
441 else if (!strcasecmp(data, "context"))
443 else if (!strcasecmp(data, "lastexten"))
445 else if (!strcasecmp(data, "lastcontext"))
447 else if (!strcasecmp(data, "userfield"))
449 else if (!strcasecmp(data, "channame"))
451 else if (!strcasecmp(data, "linkedid")) {
452 ast_channel_lock(chan);
454 /* fall back on the channel's uniqueid if linkedid is unset */
456 }
457 else {
459 }
460 ast_channel_unlock(chan);
461 } else if (!strcasecmp(data, "peer")) {
462 struct ast_channel *peer;
463
464 peer = ast_channel_bridge_peer(chan);
465 if (peer) {
466 /* Only real channels could have a bridge peer this way. */
467 ast_channel_lock(peer);
469 ast_channel_unlock(peer);
470 ast_channel_unref(peer);
471 } else {
472 buf[0] = '\0';
473 ast_channel_lock(chan);
474 if (!ast_channel_tech(chan)) {
475 const char *pname;
476
477 /*
478 * A dummy channel can still pass along bridged peer info
479 * via the BRIDGEPEER variable.
480 *
481 * A horrible kludge, but... how else?
482 */
483 pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
484 if (!ast_strlen_zero(pname)) {
485 ast_copy_string(buf, pname, len);
486 }
487 }
488 ast_channel_unlock(chan);
489 }
490 } else if (!strcasecmp(data, "uniqueid")) {
492 } else if (!strcasecmp(data, "transfercapability")) {
494 } else if (!strcasecmp(data, "callgroup")) {
495 char groupbuf[256];
496
497 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
498 } else if (!strcasecmp(data, "pickupgroup")) {
499 char groupbuf[256];
500
501 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
502 } else if (!strcasecmp(data, "namedcallgroup")) {
503 struct ast_str *tmp_str = ast_str_alloca(1024);
504
506 } else if (!strcasecmp(data, "namedpickupgroup")) {
507 struct ast_str *tmp_str = ast_str_alloca(1024);
508
510 } else if (!strcasecmp(data, "after_bridge_goto")) {
512 } else if (!strcasecmp(data, "amaflags")) {
513 ast_channel_lock(chan);
514 snprintf(buf, len, "%u", ast_channel_amaflags(chan));
515 ast_channel_unlock(chan);
516 } else if (!strncasecmp(data, "secure_bridge_", 14)) {
517 struct ast_datastore *ds;
518
519 buf[0] = '\0';
520 ast_channel_lock(chan);
522 struct ast_secure_call_store *encrypt = ds->data;
523
524 if (!strcasecmp(data, "secure_bridge_signaling")) {
525 snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
526 } else if (!strcasecmp(data, "secure_bridge_media")) {
527 snprintf(buf, len, "%s", encrypt->media ? "1" : "");
528 }
529 }
530 ast_channel_unlock(chan);
531 } else if (!strcasecmp(data, "max_forwards")) {
532 ast_channel_lock(chan);
533 snprintf(buf, len, "%d", ast_max_forwards_get(chan));
534 ast_channel_unlock(chan);
535 } else if (!strcasecmp(data, "callid")) {
536 ast_callid callid;
537
538 buf[0] = '\0';
539 ast_channel_lock(chan);
540 callid = ast_channel_callid(chan);
541 if (callid) {
542 ast_callid_strnprint(buf, len, callid);
543 }
544 ast_channel_unlock(chan);
545 } else if (!strcasecmp(data, "tdd")) {
546 char status;
547 int status_size = (int) sizeof(status);
548 ret = ast_channel_queryoption(chan, AST_OPTION_TDD, &status, &status_size, 0);
549 if (!ret) {
550 ast_copy_string(buf, status == 2 ? "mate" : status ? "1" : "0", len);
551 }
552 } else if (!strcasecmp(data, "digitdetect")) {
553 char status;
554 int status_size = (int) sizeof(status);
555 ret = ast_channel_queryoption(chan, AST_OPTION_DIGIT_DETECT, &status, &status_size, 0);
556 if (!ret) {
557 ast_copy_string(buf, status ? "1" : "0", len);
558 }
559 } else if (!strcasecmp(data, "faxdetect")) {
560 char status;
561 int status_size = (int) sizeof(status);
562 ret = ast_channel_queryoption(chan, AST_OPTION_FAX_DETECT, &status, &status_size, 0);
563 if (!ret) {
564 ast_copy_string(buf, status ? "1" : "0", len);
565 }
566 } else if (!strcasecmp(data, "device_name")) {
567 ret = ast_channel_get_device_name(chan, buf, len);
568 } 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)) {
569 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
570 ret = -1;
571 }
572
573 return ret;
574}
jack_status_t status
Definition: app_jack.c:146
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ast_bridge_read_after_goto(struct ast_channel *chan, char *buffer, size_t buf_size)
Read after bridge goto if it exists.
Definition: bridge_after.c:394
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
Definition: bridge_basic.c:208
static const char type[]
Definition: chan_ooh323.c:109
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:8056
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:10496
struct ast_namedgroups * ast_channel_named_pickupgroups(const struct ast_channel *chan)
const char * ast_channel_data(const struct ast_channel *chan)
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:10564
const char * ast_channel_musicclass(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2922
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)
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:7442
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:8031
const char * ast_channel_parkinglot(const struct ast_channel *chan)
const char * ast_channel_appl(const struct ast_channel *chan)
const char * ast_channel_peeraccount(const struct ast_channel *chan)
enum ama_flags ast_channel_amaflags(const 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:445
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
const char * ast_channel_lastcontext(const struct ast_channel *chan)
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)
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:636
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
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:2399
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
@ AST_MEDIA_TYPE_VIDEO
Definition: codec.h:33
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:734
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
#define locked_copy_string(chan, dest, source, len)
Definition: func_channel.c:350
static const char *const transfercapability_table[0x20]
Definition: func_channel.c:363
static int func_channel_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
Definition: func_channel.c:369
const struct ast_datastore_info secure_call_info
#define AST_OPTION_DIGIT_DETECT
#define AST_OPTION_TDD
#define AST_OPTION_FAX_DETECT
@ AST_CONTROL_HOLD
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:2276
unsigned int ast_callid
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
Definition: max_forwards.c:121
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
static char country[80]
Definition: pbx_dundi.c:205
#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 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

References ao2_ref, ast_bridge_features_ds_get_string(), ast_bridge_read_after_goto(), ast_callid_strnprint(), ast_channel_accountcode(), ast_channel_amaflags(), ast_channel_appl(), ast_channel_bridge_peer(), ast_channel_callgroup(), ast_channel_callid(), ast_channel_context(), ast_channel_data(), ast_channel_datastore_find(), ast_channel_exten(), ast_channel_get_device_name(), ast_channel_hangupsource(), ast_channel_hold_state(), ast_channel_language(), ast_channel_lastcontext(), ast_channel_lastexten(), ast_channel_linkedid(), ast_channel_lock, ast_channel_musicclass(), ast_channel_name(), ast_channel_named_callgroups(), ast_channel_named_pickupgroups(), ast_channel_nativeformats(), ast_channel_parkinglot(), ast_channel_peeraccount(), ast_channel_pickupgroup(), ast_channel_queryoption(), ast_channel_readformat(), ast_channel_tech(), ast_channel_transfercapability(), ast_channel_uniqueid(), ast_channel_unlock, ast_channel_unref, ast_channel_userfield(), ast_channel_writeformat(), ast_channel_zone(), ast_check_hangup(), AST_CONTROL_HOLD, ast_copy_string(), ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_names(), AST_FORMAT_CAP_NAMES_LEN, ast_format_get_name(), ast_log, ast_max_forwards_get(), AST_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_VIDEO, AST_OPTION_DIGIT_DETECT, AST_OPTION_FAX_DETECT, AST_OPTION_TDD, ast_print_group(), ast_print_namedgroups(), ast_state2str(), ast_str_alloca, ast_strlen_zero(), buf, country, ast_datastore::data, ast_channel::data, func_channel_read(), len(), locked_copy_string, LOG_WARNING, ast_secure_call_store::media, NULL, pbx_builtin_getvar_helper(), secure_call_info, ast_secure_call_store::signaling, status, transfercapability_table, and type.

Referenced by func_channel_read().

◆ func_channel_write()

static int func_channel_write ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
)
static

Definition at line 750 of file func_channel.c.

751{
752 int res;
753 ast_chan_write_info_t write_info = {
755 .write_fn = func_channel_write_real,
756 .chan = chan,
757 .function = function,
758 .data = data,
759 .value = value,
760 };
761
762 if (!chan) {
763 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
764 return -1;
765 }
766
767 res = func_channel_write_real(chan, function, data, value);
768 ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
769
770 return res;
771}
#define AST_CHAN_WRITE_INFO_T_VERSION
ast_chan_write_info_t version. Must be incremented if structure is changed
Definition: channel.h:591
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:7422
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:576
#define AST_OPTION_CHANNEL_WRITE
Handle channel write data If a channel needs to process the data from a func_channel write operation ...
Structure to handle passing func_channel_write info to channels via setoption.
Definition: channel.h:589
int value
Definition: syslog.c:37

References AST_CHAN_WRITE_INFO_T_VERSION, ast_channel_setoption(), ast_log, AST_OPTION_CHANNEL_WRITE, ast_channel::data, func_channel_write_real(), LOG_WARNING, value, and ast_chan_write_info_t::version.

Referenced by func_channel_write_real().

◆ func_channel_write_real()

static int func_channel_write_real ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
)
static

Definition at line 576 of file func_channel.c.

578{
579 int ret = 0;
580 signed char gainset;
581
582 if (!strcasecmp(data, "language"))
584 else if (!strcasecmp(data, "parkinglot"))
585 locked_string_field_set(chan, parkinglot, value);
586 else if (!strcasecmp(data, "musicclass"))
587 locked_string_field_set(chan, musicclass, value);
588 else if (!strcasecmp(data, "accountcode"))
590 else if (!strcasecmp(data, "userfield"))
591 locked_string_field_set(chan, userfield, value);
592 else if (!strcasecmp(data, "after_bridge_goto")) {
593 if (ast_strlen_zero(value)) {
595 } else {
597 }
598 } else if (!strcasecmp(data, "amaflags")) {
599 int amaflags;
600
601 if (isdigit(*value)) {
602 if (sscanf(value, "%30d", &amaflags) != 1) {
604 }
605 } else {
607 }
608 ast_channel_lock(chan);
610 ast_channel_unlock(chan);
611 } else if (!strcasecmp(data, "peeraccount"))
612 locked_string_field_set(chan, peeraccount, value);
613 else if (!strcasecmp(data, "hangupsource"))
614 /* XXX - should we be forcing this here? */
615 ast_set_hangupsource(chan, value, 0);
616 else if (!strcasecmp(data, "tonezone")) {
617 struct ast_tone_zone *new_zone;
618 if (!(new_zone = ast_get_indication_zone(value))) {
619 ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
620 ret = -1;
621 } else {
622 ast_channel_lock(chan);
623 if (ast_channel_zone(chan)) {
625 }
627 ast_channel_unlock(chan);
628 new_zone = ast_tone_zone_unref(new_zone);
629 }
630 } else if (!strcasecmp(data, "dtmf_features")) {
632 } else if (!strcasecmp(data, "callgroup")) {
633 ast_channel_lock(chan);
635 ast_channel_unlock(chan);
636 } else if (!strcasecmp(data, "pickupgroup")) {
637 ast_channel_lock(chan);
639 ast_channel_unlock(chan);
640 } else if (!strcasecmp(data, "namedcallgroup")) {
641 struct ast_namedgroups *groups = ast_get_namedgroups(value);
642
643 ast_channel_lock(chan);
645 ast_channel_unlock(chan);
647 } else if (!strcasecmp(data, "namedpickupgroup")) {
648 struct ast_namedgroups *groups = ast_get_namedgroups(value);
649
650 ast_channel_lock(chan);
652 ast_channel_unlock(chan);
654 } else if (!strcasecmp(data, "tdd")) {
655 char enabled;
656 if (!strcasecmp(value, "mate")) {
657 enabled = 2;
658 } else {
659 enabled = ast_true(value) ? 1 : 0;
660 }
662 } else if (!strcasecmp(data, "relaxdtmf")) {
663 char enabled = ast_true(value) ? 1 : 0;
665 } else if (!strcasecmp(data, "txgain")) {
666 sscanf(value, "%4hhd", &gainset);
667 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
668 } else if (!strcasecmp(data, "rxgain")) {
669 sscanf(value, "%4hhd", &gainset);
670 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
671 } else if (!strcasecmp(data, "digitdetect")) {
672 char enabled = ast_true(value) ? 1 : 0;
674 } else if (!strcasecmp(data, "faxdetect")) {
675 char enabled = ast_true(value) ? 1 : 0;
677 } else if (!strcasecmp(data, "transfercapability")) {
678 unsigned short i;
679
680 ast_channel_lock(chan);
681 for (i = 0; i < 0x20; i++) {
682 if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
684 break;
685 }
686 }
687 ast_channel_unlock(chan);
688 } else if (!strcasecmp(data, "hangup_handler_pop")) {
689 /* Pop one hangup handler before pushing the new handler. */
692 } else if (!strcasecmp(data, "hangup_handler_push")) {
694 } else if (!strcasecmp(data, "hangup_handler_wipe")) {
695 /* Pop all hangup handlers before pushing the new handler. */
696 while (ast_pbx_hangup_handler_pop(chan)) {
697 }
699 } else if (!strncasecmp(data, "secure_bridge_", 14)) {
700 struct ast_datastore *ds;
701 struct ast_secure_call_store *store;
702
703 if (!chan || !value) {
704 return -1;
705 }
706
707 ast_channel_lock(chan);
708 if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
710 ast_channel_unlock(chan);
711 return -1;
712 }
713 if (!(store = ast_calloc(1, sizeof(*store)))) {
714 ast_channel_unlock(chan);
715 ast_free(ds);
716 return -1;
717 }
718 ds->data = store;
720 } else {
721 store = ds->data;
722 }
723
724 if (!strcasecmp(data, "secure_bridge_signaling")) {
725 store->signaling = ast_true(value) ? 1 : 0;
726 } else if (!strcasecmp(data, "secure_bridge_media")) {
727 store->media = ast_true(value) ? 1 : 0;
728 }
729 ast_channel_unlock(chan);
730 } else if (!strcasecmp(data, "max_forwards")) {
731 int max_forwards;
732 if (sscanf(value, "%d", &max_forwards) != 1) {
733 ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value);
734 ret = -1;
735 } else {
736 ast_channel_lock(chan);
738 ast_channel_unlock(chan);
739 }
740 } else if (!ast_channel_tech(chan)->func_channel_write
741 || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
742 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
743 data);
744 ret = -1;
745 }
746
747 return ret;
748}
#define ast_free(a)
Definition: astmm.h:180
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
void ast_bridge_discard_after_goto(struct ast_channel *chan)
Discard channel after bridge goto location.
Definition: bridge_after.c:384
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
int ast_bridge_features_ds_set_string(struct ast_channel *chan, const char *features)
Sets the features a channel will use upon being bridged.
Definition: bridge_basic.c:189
static int amaflags
Definition: chan_iax2.c:476
static char language[MAX_LANGUAGE]
Definition: chan_iax2.c:324
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_iax2.c:473
void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
int ast_channel_priority(const struct ast_channel *chan)
@ AST_AMA_NONE
Definition: channel.h:1178
struct ast_namedgroups * ast_get_namedgroups(const char *s)
Create an ast_namedgroups set with group names from comma separated string.
Definition: channel.c:7675
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
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:2499
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
enum ama_flags ast_channel_string2amaflag(const char *flag)
Convert a string to a detail record AMA flag.
Definition: channel.c:4360
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
struct ast_namedgroups * ast_unref_namedgroups(struct ast_namedgroups *groups)
Definition: channel.c:7732
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)
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7618
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
static int enabled
Definition: dnsmgr.c:91
#define locked_string_field_set(chan, field, source)
Definition: func_channel.c:356
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:750
#define AST_OPTION_RELAXDTMF
#define AST_OPTION_RXGAIN
#define AST_OPTION_TXGAIN
#define LOG_ERROR
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:205
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:439
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:216
int ast_max_forwards_set(struct ast_channel *chan, int starting_count)
Set the starting max forwards for a particular channel.
Definition: max_forwards.c:105
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.
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:2199
A set of tones for a given locale.
Definition: indications.h:74
Channel datastore data for max forwards.
Definition: max_forwards.c:29

References accountcode, amaflags, AST_AMA_NONE, ast_bridge_discard_after_goto(), ast_bridge_features_ds_set_string(), ast_bridge_set_after_go_on(), ast_calloc, ast_channel_amaflags_set(), ast_channel_callgroup_set(), ast_channel_context(), ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_exten(), ast_channel_lock, ast_channel_named_callgroups_set(), ast_channel_named_pickupgroups_set(), ast_channel_pickupgroup_set(), ast_channel_priority(), ast_channel_setoption(), ast_channel_string2amaflag(), ast_channel_tech(), ast_channel_transfercapability_set(), ast_channel_unlock, ast_channel_zone(), ast_channel_zone_set(), ast_datastore_alloc, ast_free, ast_get_group(), ast_get_indication_zone(), ast_get_namedgroups(), ast_log, ast_max_forwards_set(), AST_OPTION_DIGIT_DETECT, AST_OPTION_FAX_DETECT, AST_OPTION_RELAXDTMF, AST_OPTION_RXGAIN, AST_OPTION_TDD, AST_OPTION_TXGAIN, ast_pbx_hangup_handler_pop(), ast_pbx_hangup_handler_push(), ast_set_hangupsource(), ast_strlen_zero(), ast_tone_zone_ref(), ast_tone_zone_unref(), ast_true(), ast_unref_namedgroups(), ast_datastore::data, enabled, func_channel_write(), language, locked_string_field_set, LOG_ERROR, LOG_WARNING, ast_secure_call_store::media, NULL, secure_call_info, ast_secure_call_store::signaling, transfercapability_table, and value.

Referenced by func_channel_write().

◆ func_channels_read()

static int func_channels_read ( struct ast_channel chan,
const char *  function,
char *  data,
char *  buf,
size_t  maxlen 
)
static

Definition at line 779 of file func_channel.c.

780{
781 struct ast_channel *c = NULL;
782 regex_t re;
783 int res;
784 size_t buflen = 0;
785 struct ast_channel_iterator *iter;
786
787 buf[0] = '\0';
788
789 if (!ast_strlen_zero(data)) {
790 if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
791 regerror(res, &re, buf, maxlen);
792 ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
793 return -1;
794 }
795 }
796
797 if (!(iter = ast_channel_iterator_all_new())) {
798 if (!ast_strlen_zero(data)) {
799 regfree(&re);
800 }
801 return -1;
802 }
803
804 while ((c = ast_channel_iterator_next(iter))) {
806 if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
807 size_t namelen = strlen(ast_channel_name(c));
808 if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
809 if (!ast_strlen_zero(buf)) {
810 strcat(buf, " ");
811 buflen++;
812 }
813 strcat(buf, ast_channel_name(c));
814 buflen += namelen;
815 } else {
816 ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n");
817 }
818 }
821 }
822
824
825 if (!ast_strlen_zero(data)) {
826 regfree(&re);
827 }
828
829 return 0;
830}
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1360
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1422
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1408
static struct test_val c

References ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_channel_unref, ast_log, ast_strlen_zero(), buf, c, LOG_WARNING, and NULL.

◆ func_mchan_read()

static int func_mchan_read ( struct ast_channel chan,
const char *  function,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 859 of file func_channel.c.

861{
862 struct ast_channel *mchan;
863 char *template = ast_alloca(4 + strlen(data));
864
865 if (!chan) {
866 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
867 return -1;
868 }
869
871 sprintf(template, "${%s}", data); /* SAFE */
872 ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
873 if (mchan) {
874 ast_channel_unref(mchan);
875 }
876 return 0;
877}
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)

References ast_alloca, ast_channel_get_by_name(), ast_channel_linkedid(), ast_channel_unref, ast_log, ast_str_substitute_variables(), buf, ast_channel::data, len(), and LOG_WARNING.

◆ func_mchan_write()

static int func_mchan_write ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
)
static

Definition at line 879 of file func_channel.c.

881{
882 struct ast_channel *mchan;
883
884 if (!chan) {
885 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
886 return -1;
887 }
888
890 pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
891 if (mchan) {
892 ast_channel_unref(mchan);
893 }
894 return 0;
895}
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.

References ast_channel_get_by_name(), ast_channel_linkedid(), ast_channel_unref, ast_log, ast_channel::data, LOG_WARNING, pbx_builtin_setvar_helper(), and value.

◆ load_module()

static int load_module ( void  )
static

Definition at line 915 of file func_channel.c.

916{
917 int res = 0;
918
923
924 return res;
925}
static struct ast_custom_function channels_function
Definition: func_channel.c:832
static struct ast_custom_function channel_function
Definition: func_channel.c:773
static struct ast_custom_function mchan_function
Definition: func_channel.c:897
static struct ast_custom_function chan_exists_function
Definition: func_channel.c:854
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, chan_exists_function, channel_function, channels_function, and mchan_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 903 of file func_channel.c.

904{
905 int res = 0;
906
911
912 return res;
913}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), chan_exists_function, channel_function, channels_function, and mchan_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Channel information dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 927 of file func_channel.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 927 of file func_channel.c.

◆ chan_exists_function

struct ast_custom_function chan_exists_function
static
Initial value:
= {
.name = "CHANNEL_EXISTS",
}
static int func_chan_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
Definition: func_channel.c:837

Definition at line 854 of file func_channel.c.

Referenced by load_module(), and unload_module().

◆ channel_function

struct ast_custom_function channel_function
static
Initial value:
= {
.name = "CHANNEL",
}

Definition at line 773 of file func_channel.c.

Referenced by load_module(), and unload_module().

◆ channels_function

struct ast_custom_function channels_function
static
Initial value:
= {
.name = "CHANNELS",
}
static int func_channels_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
Definition: func_channel.c:779

Definition at line 832 of file func_channel.c.

Referenced by load_module(), and unload_module().

◆ mchan_function

struct ast_custom_function mchan_function
static
Initial value:
= {
.name = "MASTER_CHANNEL",
.read2 = func_mchan_read,
.write = func_mchan_write,
}
static int func_mchan_read(struct ast_channel *chan, const char *function, char *data, struct ast_str **buf, ssize_t len)
Definition: func_channel.c:859
static int func_mchan_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:879

Definition at line 897 of file func_channel.c.

Referenced by load_module(), and unload_module().

◆ transfercapability_table

const char* const transfercapability_table[0x20]
static
Initial value:
= {
"SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
"DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
"3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
"VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", }

Definition at line 363 of file func_channel.c.

Referenced by func_channel_read(), and func_channel_write_real().