Asterisk - The Open Source Telephony Project GIT-master-545c459
Loading...
Searching...
No Matches
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 = ASTERISK_GPL_KEY , .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 370 of file func_channel.c.

371 { \
372 ast_channel_lock(chan); \
373 ast_copy_string(dest, source, len); \
374 ast_channel_unlock(chan); \
375 } while (0)

◆ 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 376 of file func_channel.c.

377 { \
378 ast_channel_lock(chan); \
379 ast_channel_##field##_set(chan, source); \
380 ast_channel_unlock(chan); \
381 } while (0)

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 989 of file func_channel.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 989 of file func_channel.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 989 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 899 of file func_channel.c.

900{
901 struct ast_channel *chan_found = NULL;
902
903 if (ast_strlen_zero(data)) {
904 ast_log(LOG_WARNING, "%s: Channel name or unique ID required\n", function);
905 return -1;
906 }
907
908 chan_found = ast_channel_get_by_name(data);
909 snprintf(buf, maxlen, "%d", (chan_found ? 1 : 0));
910 if (chan_found) {
911 ast_channel_unref(chan_found);
912 }
913 return 0;
914}
#define ast_log
Definition astobj2.c:42
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1417
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3019
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 389 of file func_channel.c.

391{
392 int ret = 0;
393 struct ast_format_cap *tmpcap;
394
395 if (!chan) {
396 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
397 return -1;
398 }
399
400 if (!strcasecmp(data, "audionativeformat")) {
402 if (tmpcap) {
404
405 ast_channel_lock(chan);
407 ast_channel_unlock(chan);
408 ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
409 ao2_ref(tmpcap, -1);
410 }
411 } else if (!strcasecmp(data, "videonativeformat")) {
413 if (tmpcap) {
415
416 ast_channel_lock(chan);
418 ast_channel_unlock(chan);
419 ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
420 ao2_ref(tmpcap, -1);
421 }
422 } else if (!strcasecmp(data, "audioreadformat")) {
424 } else if (!strcasecmp(data, "audiowriteformat")) {
426 } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
428 } else if (!strcasecmp(data, "adsicpe")) {
429 int adsi;
430 ast_channel_lock(chan);
432 ast_channel_unlock(chan);
433 switch (adsi) {
435 ast_copy_string(buf, "available", len);
436 break;
438 ast_copy_string(buf, "unavailable", len);
439 break;
441 ast_copy_string(buf, "offhookonly", len);
442 break;
443 default:
444 ast_copy_string(buf, "unknown", len);
445 break;
446 }
447 } else if (!strcasecmp(data, "dtmf_features")) {
449 buf[0] = '\0';
450 }
451 } else if (!strcasecmp(data, "language"))
453 else if (!strcasecmp(data, "musicclass"))
455 else if (!strcasecmp(data, "name")) {
457 } else if (!strcasecmp(data, "parkinglot"))
459 else if (!strcasecmp(data, "state"))
461 else if (!strcasecmp(data, "onhold")) {
463 ast_channel_hold_state(chan) == AST_CONTROL_HOLD ? "1" : "0", len);
464 } else if (!strcasecmp(data, "channeltype"))
466 ast_channel_tech(chan) ? ast_channel_tech(chan)->type : "", len);
467 else if (!strcasecmp(data, "accountcode"))
469 else if (!strcasecmp(data, "checkhangup")) {
470 locked_copy_string(chan, buf, ast_check_hangup(chan) ? "1" : "0", len);
471 } else if (!strcasecmp(data, "peeraccount"))
473 else if (!strcasecmp(data, "hangupsource"))
475 else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
477 else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
479 else if (!strcasecmp(data, "exten"))
481 else if (!strcasecmp(data, "context"))
483 else if (!strcasecmp(data, "lastexten"))
485 else if (!strcasecmp(data, "lastcontext"))
487 else if (!strcasecmp(data, "userfield"))
489 else if (!strcasecmp(data, "channame"))
491 else if (!strcasecmp(data, "linkedid")) {
492 ast_channel_lock(chan);
494 /* fall back on the channel's uniqueid if linkedid is unset */
496 }
497 else {
499 }
500 ast_channel_unlock(chan);
501 } else if (!strcasecmp(data, "peer")) {
502 struct ast_channel *peer;
503
504 peer = ast_channel_bridge_peer(chan);
505 if (peer) {
506 /* Only real channels could have a bridge peer this way. */
507 ast_channel_lock(peer);
509 ast_channel_unlock(peer);
510 ast_channel_unref(peer);
511 } else {
512 buf[0] = '\0';
513 ast_channel_lock(chan);
514 if (!ast_channel_tech(chan)) {
515 const char *pname;
516
517 /*
518 * A dummy channel can still pass along bridged peer info
519 * via the BRIDGEPEER variable.
520 *
521 * A horrible kludge, but... how else?
522 */
523 pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
524 if (!ast_strlen_zero(pname)) {
525 ast_copy_string(buf, pname, len);
526 }
527 }
528 ast_channel_unlock(chan);
529 }
530 } else if (!strcasecmp(data, "uniqueid")) {
532 } else if (!strcasecmp(data, "transfercapability")) {
534 } else if (!strcasecmp(data, "callgroup")) {
535 char groupbuf[256];
536
537 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
538 } else if (!strcasecmp(data, "pickupgroup")) {
539 char groupbuf[256];
540
541 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
542 } else if (!strcasecmp(data, "namedcallgroup")) {
543 struct ast_str *tmp_str = ast_str_alloca(1024);
544
546 } else if (!strcasecmp(data, "namedpickupgroup")) {
547 struct ast_str *tmp_str = ast_str_alloca(1024);
548
550 } else if (!strcasecmp(data, "after_bridge_goto")) {
552 } else if (!strcasecmp(data, "amaflags")) {
553 ast_channel_lock(chan);
554 snprintf(buf, len, "%u", ast_channel_amaflags(chan));
555 ast_channel_unlock(chan);
556 } else if (!strncasecmp(data, "secure_bridge_", 14)) {
557 struct ast_datastore *ds;
558
559 buf[0] = '\0';
560 ast_channel_lock(chan);
562 struct ast_secure_call_store *encrypt = ds->data;
563
564 if (!strcasecmp(data, "secure_bridge_signaling")) {
565 snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
566 } else if (!strcasecmp(data, "secure_bridge_media")) {
567 snprintf(buf, len, "%s", encrypt->media ? "1" : "");
568 }
569 }
570 ast_channel_unlock(chan);
571 } else if (!strcasecmp(data, "max_forwards")) {
572 ast_channel_lock(chan);
573 snprintf(buf, len, "%d", ast_max_forwards_get(chan));
574 ast_channel_unlock(chan);
575 } else if (!strcasecmp(data, "callid")) {
576 ast_callid callid;
577
578 buf[0] = '\0';
579 ast_channel_lock(chan);
580 callid = ast_channel_callid(chan);
581 if (callid) {
582 ast_callid_strnprint(buf, len, callid);
583 }
584 ast_channel_unlock(chan);
585 } else if (!strcasecmp(data, "tdd")) {
586 char status;
587 int status_size = (int) sizeof(status);
588 ret = ast_channel_queryoption(chan, AST_OPTION_TDD, &status, &status_size, 0);
589 if (!ret) {
590 ast_copy_string(buf, status == 2 ? "mate" : status ? "1" : "0", len);
591 }
592 } else if (!strcasecmp(data, "digitdetect")) {
593 char status;
594 int status_size = (int) sizeof(status);
595 ret = ast_channel_queryoption(chan, AST_OPTION_DIGIT_DETECT, &status, &status_size, 0);
596 if (!ret) {
597 ast_copy_string(buf, status ? "1" : "0", len);
598 }
599 } else if (!strcasecmp(data, "faxdetect")) {
600 char status;
601 int status_size = (int) sizeof(status);
602 ret = ast_channel_queryoption(chan, AST_OPTION_FAX_DETECT, &status, &status_size, 0);
603 if (!ret) {
604 ast_copy_string(buf, status ? "1" : "0", len);
605 }
606 } else if (!strcasecmp(data, "device_name")) {
607 ret = ast_channel_get_device_name(chan, buf, len);
608 } else if (!strcasecmp(data, "tenantid")) {
610 } 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)) {
611 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
612 ret = -1;
613 }
614
615 return ret;
616}
jack_status_t status
Definition app_jack.c:149
#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.
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
static int adsi
Definition chan_iax2.c:514
static const char type[]
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
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)
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)
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
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
const char * ast_channel_parkinglot(const struct ast_channel *chan)
ast_channel_adsicpe
Definition channel.h:888
@ 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)
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:446
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:637
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
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_copy_string(chan, dest, source, len)
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)
const struct ast_datastore_info secure_call_info
#define AST_OPTION_DIGIT_DETECT
#define AST_OPTION_TDD
#define AST_OPTION_FAX_DETECT
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
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
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:214
#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 describe a channel "technology", ie a channel driver See for examples:
Definition channel.h:648
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 adsi, ao2_ref, AST_ADSI_AVAILABLE, AST_ADSI_OFFHOOKONLY, AST_ADSI_UNAVAILABLE, 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_tenantid(), 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 ast_channel_tech::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 812 of file func_channel.c.

813{
814 int res;
815 ast_chan_write_info_t write_info = {
817 .write_fn = func_channel_write_real,
818 .chan = chan,
819 .function = function,
820 .data = data,
821 .value = value,
822 };
823
824 if (!chan) {
825 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
826 return -1;
827 }
828
829 res = func_channel_write_real(chan, function, data, value);
830 ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
831
832 return res;
833}
#define AST_CHAN_WRITE_INFO_T_VERSION
ast_chan_write_info_t version. Must be incremented if structure is changed
Definition channel.h:593
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
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value)
#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:591
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 618 of file func_channel.c.

620{
621 int ret = 0;
622 signed char gainset;
623
624 if (!strcasecmp(data, "language"))
626 else if (!strcasecmp(data, "parkinglot"))
627 locked_string_field_set(chan, parkinglot, value);
628 else if (!strcasecmp(data, "musicclass"))
629 locked_string_field_set(chan, musicclass, value);
630 else if (!strcasecmp(data, "accountcode"))
632 else if (!strcasecmp(data, "userfield"))
633 locked_string_field_set(chan, userfield, value);
634 else if (!strcasecmp(data, "after_bridge_goto")) {
635 if (ast_strlen_zero(value)) {
637 } else {
639 }
640 } else if (!strcasecmp(data, "amaflags")) {
641 int amaflags;
642
643 if (isdigit(*value)) {
644 if (sscanf(value, "%30d", &amaflags) != 1) {
646 }
647 } else {
649 }
650 ast_channel_lock(chan);
652 ast_channel_unlock(chan);
653 } else if (!strcasecmp(data, "peeraccount"))
654 locked_string_field_set(chan, peeraccount, value);
655 else if (!strcasecmp(data, "hangupsource"))
656 /* XXX - should we be forcing this here? */
657 ast_set_hangupsource(chan, value, 0);
658 else if (!strcasecmp(data, "tonezone")) {
659 struct ast_tone_zone *new_zone;
660 if (!(new_zone = ast_get_indication_zone(value))) {
661 ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
662 ret = -1;
663 } else {
664 ast_channel_lock(chan);
665 if (ast_channel_zone(chan)) {
667 }
669 ast_channel_unlock(chan);
670 new_zone = ast_tone_zone_unref(new_zone);
671 }
672 } else if (!strcasecmp(data, "adsicpe")) {
673 int adsi;
674 if (!strcasecmp(value, "unknown")) {
676 } else if (!strcasecmp(value, "available")) {
678 } else if (!strcasecmp(value, "unavailable")) {
680 } else if (!strcasecmp(value, "offhookonly")) {
682 } else {
683 ast_log(LOG_ERROR, "Unknown ADSI availability '%s'\n", value);
684 return -1;
685 }
686 ast_channel_lock(chan);
688 ast_channel_unlock(chan);
689 } else if (!strcasecmp(data, "dtmf_features")) {
691 } else if (!strcasecmp(data, "callgroup")) {
692 ast_channel_lock(chan);
694 ast_channel_unlock(chan);
695 } else if (!strcasecmp(data, "pickupgroup")) {
696 ast_channel_lock(chan);
698 ast_channel_unlock(chan);
699 } else if (!strcasecmp(data, "namedcallgroup")) {
700 struct ast_namedgroups *groups = ast_get_namedgroups(value);
701
702 ast_channel_lock(chan);
704 ast_channel_unlock(chan);
706 } else if (!strcasecmp(data, "namedpickupgroup")) {
707 struct ast_namedgroups *groups = ast_get_namedgroups(value);
708
709 ast_channel_lock(chan);
711 ast_channel_unlock(chan);
713 } else if (!strcasecmp(data, "tdd")) {
714 char enabled;
715 if (!strcasecmp(value, "mate")) {
716 enabled = 2;
717 } else {
718 enabled = ast_true(value) ? 1 : 0;
719 }
721 } else if (!strcasecmp(data, "relaxdtmf")) {
722 char enabled = ast_true(value) ? 1 : 0;
724 } else if (!strcasecmp(data, "txgain")) {
725 sscanf(value, "%4hhd", &gainset);
726 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
727 } else if (!strcasecmp(data, "rxgain")) {
728 sscanf(value, "%4hhd", &gainset);
729 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
730 } else if (!strcasecmp(data, "digitdetect")) {
731 char enabled = ast_true(value) ? 1 : 0;
733 } else if (!strcasecmp(data, "faxdetect")) {
734 char enabled = ast_true(value) ? 1 : 0;
736 } else if (!strcasecmp(data, "transfercapability")) {
737 unsigned short i;
738
739 ast_channel_lock(chan);
740 for (i = 0; i < 0x20; i++) {
741 if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
743 break;
744 }
745 }
746 ast_channel_unlock(chan);
747 } else if (!strcasecmp(data, "hangup_handler_pop")) {
748 /* Pop one hangup handler before pushing the new handler. */
751 } else if (!strcasecmp(data, "hangup_handler_push")) {
753 } else if (!strcasecmp(data, "hangup_handler_wipe")) {
754 /* Pop all hangup handlers before pushing the new handler. */
755 while (ast_pbx_hangup_handler_pop(chan)) {
756 }
758 } else if (!strncasecmp(data, "secure_bridge_", 14)) {
759 struct ast_datastore *ds;
760 struct ast_secure_call_store *store;
761
762 if (!chan || !value) {
763 return -1;
764 }
765
766 ast_channel_lock(chan);
767 if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
769 ast_channel_unlock(chan);
770 return -1;
771 }
772 if (!(store = ast_calloc(1, sizeof(*store)))) {
773 ast_channel_unlock(chan);
774 ast_free(ds);
775 return -1;
776 }
777 ds->data = store;
779 } else {
780 store = ds->data;
781 }
782
783 if (!strcasecmp(data, "secure_bridge_signaling")) {
784 store->signaling = ast_true(value) ? 1 : 0;
785 } else if (!strcasecmp(data, "secure_bridge_media")) {
786 store->media = ast_true(value) ? 1 : 0;
787 }
788 ast_channel_unlock(chan);
789 } else if (!strcasecmp(data, "max_forwards")) {
790 int max_forwards;
791 if (sscanf(value, "%d", &max_forwards) != 1) {
792 ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value);
793 ret = -1;
794 } else {
795 ast_channel_lock(chan);
797 ast_channel_unlock(chan);
798 }
799 } else if (!strcasecmp(data, "tenantid")) {
801 } else if (!ast_channel_tech(chan)
803 || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
804 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
805 data);
806 ret = -1;
807 }
808
809 return ret;
810}
#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.
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.
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 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
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:2376
void ast_channel_tenantid_set(struct ast_channel *chan, const char *value)
int ast_channel_priority(const struct ast_channel *chan)
@ AST_AMA_NONE
Definition channel.h:1198
@ AST_ADSI_UNKNOWN
Definition channel.h:889
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)
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)
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:4382
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:7768
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
#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)
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
#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.
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_set(struct ast_channel *chan, int starting_count)
Set the starting max forwards for a particular channel.
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:2233
A set of tones for a given locale.
Definition indications.h:74
Channel datastore data for max forwards.

References accountcode, adsi, amaflags, AST_ADSI_AVAILABLE, AST_ADSI_OFFHOOKONLY, AST_ADSI_UNAVAILABLE, AST_ADSI_UNKNOWN, AST_AMA_NONE, ast_bridge_discard_after_goto(), ast_bridge_features_ds_set_string(), ast_bridge_set_after_go_on(), ast_calloc, ast_channel_adsicpe_set(), 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_tenantid_set(), 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 841 of file func_channel.c.

842{
843 struct ast_channel *c = NULL;
844 regex_t re;
845 int res;
846 size_t buflen = 0;
847 struct ast_channel_iterator *iter;
848
849 buf[0] = '\0';
850
851 if (!ast_strlen_zero(data)) {
852 if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
853 regerror(res, &re, buf, maxlen);
854 ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
855 return -1;
856 }
857 }
858
859 if (!(iter = ast_channel_iterator_all_new())) {
860 if (!ast_strlen_zero(data)) {
861 regfree(&re);
862 }
863 return -1;
864 }
865
866 while ((c = ast_channel_iterator_next(iter))) {
868 if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
869 size_t namelen = strlen(ast_channel_name(c));
870 if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
871 if (!ast_strlen_zero(buf)) {
872 strcat(buf, " ");
873 buflen++;
874 }
875 strcat(buf, ast_channel_name(c));
876 buflen += namelen;
877 } else {
878 ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n");
879 }
880 }
883 }
884
886
887 if (!ast_strlen_zero(data)) {
888 regfree(&re);
889 }
890
891 return 0;
892}
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_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition channel.c:1388
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition channel.c:1380
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 921 of file func_channel.c.

923{
924 struct ast_channel *mchan;
925 char *template = ast_alloca(4 + strlen(data));
926
927 if (!chan) {
928 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
929 return -1;
930 }
931
933 sprintf(template, "${%s}", data); /* SAFE */
934 ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
935 if (mchan) {
936 ast_channel_unref(mchan);
937 }
938 return 0;
939}
#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 941 of file func_channel.c.

943{
944 struct ast_channel *mchan;
945
946 if (!chan) {
947 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
948 return -1;
949 }
950
952 pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
953 if (mchan) {
954 ast_channel_unref(mchan);
955 }
956 return 0;
957}
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 977 of file func_channel.c.

978{
979 int res = 0;
980
985
986 return res;
987}
static struct ast_custom_function channels_function
static struct ast_custom_function channel_function
static struct ast_custom_function mchan_function
static struct ast_custom_function chan_exists_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1563

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 965 of file func_channel.c.

966{
967 int res = 0;
968
973
974 return res;
975}
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 = ASTERISK_GPL_KEY , .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 989 of file func_channel.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 989 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 at line 916 of file func_channel.c.

916 {
917 .name = "CHANNEL_EXISTS",
918 .read = func_chan_exists_read,
919};

Referenced by load_module(), and unload_module().

◆ channel_function

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

Definition at line 835 of file func_channel.c.

835 {
836 .name = "CHANNEL",
837 .read = func_channel_read,
838 .write = func_channel_write,
839};

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 at line 894 of file func_channel.c.

894 {
895 .name = "CHANNELS",
896 .read = func_channels_read,
897};

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)
static int func_mchan_write(struct ast_channel *chan, const char *function, char *data, const char *value)

Definition at line 959 of file func_channel.c.

959 {
960 .name = "MASTER_CHANNEL",
961 .read2 = func_mchan_read,
962 .write = func_mchan_write,
963};

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 383 of file func_channel.c.

383 {
384 "SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
385 "DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
386 "3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
387 "VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", };

Referenced by func_channel_read(), and func_channel_write_real().