Asterisk - The Open Source Telephony Project  18.5.0
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_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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 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

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

Referenced by func_channel_read().

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

Referenced by func_channel_write_real().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 780 of file func_channel.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 780 of file func_channel.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 780 of file func_channel.c.

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

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_hangupsource(), ast_channel_hold_state(), ast_channel_language(), 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_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_print_group(), ast_print_namedgroups(), ast_state2str(), ast_str_alloca, ast_strlen_zero, country, ast_datastore::data, locked_copy_string, LOG_WARNING, ast_secure_call_store::media, NULL, pbx_builtin_getvar_helper(), secure_call_info, ast_secure_call_store::signaling, transfercapability_table, and type.

292 {
293  int ret = 0;
294  struct ast_format_cap *tmpcap;
295 
296  if (!chan) {
297  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
298  return -1;
299  }
300 
301  if (!strcasecmp(data, "audionativeformat")) {
303  if (tmpcap) {
304  struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
305 
306  ast_channel_lock(chan);
308  ast_channel_unlock(chan);
309  ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
310  ao2_ref(tmpcap, -1);
311  }
312  } else if (!strcasecmp(data, "videonativeformat")) {
314  if (tmpcap) {
315  struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
316 
317  ast_channel_lock(chan);
319  ast_channel_unlock(chan);
320  ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
321  ao2_ref(tmpcap, -1);
322  }
323  } else if (!strcasecmp(data, "audioreadformat")) {
325  } else if (!strcasecmp(data, "audiowriteformat")) {
327  } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
329  } else if (!strcasecmp(data, "dtmf_features")) {
331  buf[0] = '\0';
332  }
333  } else if (!strcasecmp(data, "language"))
335  else if (!strcasecmp(data, "musicclass"))
337  else if (!strcasecmp(data, "name")) {
339  } else if (!strcasecmp(data, "parkinglot"))
341  else if (!strcasecmp(data, "state"))
343  else if (!strcasecmp(data, "onhold")) {
344  locked_copy_string(chan, buf,
345  ast_channel_hold_state(chan) == AST_CONTROL_HOLD ? "1" : "0", len);
346  } else if (!strcasecmp(data, "channeltype"))
348  else if (!strcasecmp(data, "accountcode"))
350  else if (!strcasecmp(data, "checkhangup")) {
351  locked_copy_string(chan, buf, ast_check_hangup(chan) ? "1" : "0", len);
352  } else if (!strcasecmp(data, "peeraccount"))
354  else if (!strcasecmp(data, "hangupsource"))
356  else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
358  else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
360  else if (!strcasecmp(data, "exten"))
362  else if (!strcasecmp(data, "context"))
364  else if (!strcasecmp(data, "userfield"))
366  else if (!strcasecmp(data, "channame"))
368  else if (!strcasecmp(data, "linkedid")) {
369  ast_channel_lock(chan);
371  /* fall back on the channel's uniqueid if linkedid is unset */
373  }
374  else {
376  }
377  ast_channel_unlock(chan);
378  } else if (!strcasecmp(data, "peer")) {
379  struct ast_channel *peer;
380 
381  peer = ast_channel_bridge_peer(chan);
382  if (peer) {
383  /* Only real channels could have a bridge peer this way. */
384  ast_channel_lock(peer);
386  ast_channel_unlock(peer);
387  ast_channel_unref(peer);
388  } else {
389  buf[0] = '\0';
390  ast_channel_lock(chan);
391  if (!ast_channel_tech(chan)) {
392  const char *pname;
393 
394  /*
395  * A dummy channel can still pass along bridged peer info
396  * via the BRIDGEPEER variable.
397  *
398  * A horrible kludge, but... how else?
399  */
400  pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
401  if (!ast_strlen_zero(pname)) {
402  ast_copy_string(buf, pname, len);
403  }
404  }
405  ast_channel_unlock(chan);
406  }
407  } else if (!strcasecmp(data, "uniqueid")) {
409  } else if (!strcasecmp(data, "transfercapability")) {
411  } else if (!strcasecmp(data, "callgroup")) {
412  char groupbuf[256];
413 
414  locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
415  } else if (!strcasecmp(data, "pickupgroup")) {
416  char groupbuf[256];
417 
418  locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
419  } else if (!strcasecmp(data, "namedcallgroup")) {
420  struct ast_str *tmp_str = ast_str_alloca(1024);
421 
423  } else if (!strcasecmp(data, "namedpickupgroup")) {
424  struct ast_str *tmp_str = ast_str_alloca(1024);
425 
427  } else if (!strcasecmp(data, "after_bridge_goto")) {
429  } else if (!strcasecmp(data, "amaflags")) {
430  ast_channel_lock(chan);
431  snprintf(buf, len, "%u", ast_channel_amaflags(chan));
432  ast_channel_unlock(chan);
433  } else if (!strncasecmp(data, "secure_bridge_", 14)) {
434  struct ast_datastore *ds;
435 
436  buf[0] = '\0';
437  ast_channel_lock(chan);
438  if ((ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
439  struct ast_secure_call_store *encrypt = ds->data;
440 
441  if (!strcasecmp(data, "secure_bridge_signaling")) {
442  snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
443  } else if (!strcasecmp(data, "secure_bridge_media")) {
444  snprintf(buf, len, "%s", encrypt->media ? "1" : "");
445  }
446  }
447  ast_channel_unlock(chan);
448  } else if (!strcasecmp(data, "max_forwards")) {
449  ast_channel_lock(chan);
450  snprintf(buf, len, "%d", ast_max_forwards_get(chan));
451  ast_channel_unlock(chan);
452  } else if (!strcasecmp(data, "callid")) {
453  ast_callid callid;
454 
455  buf[0] = '\0';
456  ast_channel_lock(chan);
457  callid = ast_channel_callid(chan);
458  if (callid) {
459  ast_callid_strnprint(buf, len, callid);
460  }
461  ast_channel_unlock(chan);
462  } 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)) {
463  ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
464  ret = -1;
465  }
466 
467  return ret;
468 }
static const char type[]
Definition: chan_ooh323.c:109
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
Definition: max_forwards.c:121
int ast_channel_hold_state(const struct ast_channel *chan)
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
unsigned int ast_callid
Definition: logger.h:87
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
Structure for a data store object.
Definition: datastore.h:68
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:2404
const char * ast_state2str(enum ast_channel_state)
Gives the string form of a given channel state.
Definition: channel.c:642
#define NULL
Definition: resample.c:96
const char * data
const struct ast_datastore_info secure_call_info
const char * ast_channel_linkedid(const struct ast_channel *chan)
struct ast_namedgroups * ast_channel_named_callgroups(const struct ast_channel *chan)
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call and pickup groups into buffer.
Definition: channel.c:8133
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
#define ast_log
Definition: astobj2.c:42
const char * ast_channel_accountcode(const struct ast_channel *chan)
#define locked_copy_string(chan, dest, source, len)
Definition: func_channel.c:271
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
const char * ast_channel_exten(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
int ast_bridge_features_ds_get_string(struct ast_channel *chan, char *buffer, size_t buf_size)
writes a channel&#39;s DTMF features to a buffer string
Definition: bridge_basic.c:208
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_userfield(const struct ast_channel *chan)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
static char country[80]
Definition: pbx_dundi.c:205
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:1952
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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:736
const char * ast_channel_appl(const struct ast_channel *chan)
const char * ast_channel_peeraccount(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * ast_channel_hangupsource(const struct ast_channel *chan)
static const char *const transfercapability_table[0x20]
Definition: func_channel.c:284
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
const char * ast_channel_data(const struct ast_channel *chan)
void * data
Definition: datastore.h:70
static int func_channel_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
Definition: func_channel.c:290
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct ast_namedgroups * ast_channel_named_pickupgroups(const struct ast_channel *chan)
struct ast_channel * ast_channel_bridge_peer(struct ast_channel *chan)
Get the channel&#39;s bridge peer only if the bridge is two-party.
Definition: channel.c:10765
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
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:406
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
ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
struct ast_format * ast_channel_writeformat(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:8158
enum ama_flags ast_channel_amaflags(const struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
ast_callid ast_channel_callid(const struct ast_channel *chan)
const char * ast_channel_parkinglot(const struct ast_channel *chan)
const char * ast_channel_musicclass(const struct ast_channel *chan)

◆ func_channel_write()

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

Definition at line 627 of file func_channel.c.

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().

628 {
629  int res;
630  ast_chan_write_info_t write_info = {
632  .write_fn = func_channel_write_real,
633  .chan = chan,
634  .function = function,
635  .data = data,
636  .value = value,
637  };
638 
639  if (!chan) {
640  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
641  return -1;
642  }
643 
644  res = func_channel_write_real(chan, function, data, value);
645  ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
646 
647  return res;
648 }
#define LOG_WARNING
Definition: logger.h:274
const char * data
int value
Definition: syslog.c:37
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:7522
#define ast_log
Definition: astobj2.c:42
#define AST_CHAN_WRITE_INFO_T_VERSION
ast_chan_write_info_t version. Must be incremented if structure is changed
Definition: channel.h:592
#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:590
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:470

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

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_RXGAIN, 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, func_channel_write(), language, locked_string_field_set, LOG_ERROR, LOG_WARNING, ast_secure_call_store::media, musicclass, NULL, parkinglot, secure_call_info, ast_secure_call_store::signaling, and transfercapability_table.

Referenced by func_channel_write().

472 {
473  int ret = 0;
474  signed char gainset;
475 
476  if (!strcasecmp(data, "language"))
478  else if (!strcasecmp(data, "parkinglot"))
480  else if (!strcasecmp(data, "musicclass"))
482  else if (!strcasecmp(data, "accountcode"))
484  else if (!strcasecmp(data, "userfield"))
485  locked_string_field_set(chan, userfield, value);
486  else if (!strcasecmp(data, "after_bridge_goto")) {
487  if (ast_strlen_zero(value)) {
489  } else {
491  }
492  } else if (!strcasecmp(data, "amaflags")) {
493  int amaflags;
494 
495  if (isdigit(*value)) {
496  if (sscanf(value, "%30d", &amaflags) != 1) {
497  amaflags = AST_AMA_NONE;
498  }
499  } else {
500  amaflags = ast_channel_string2amaflag(value);
501  }
502  ast_channel_lock(chan);
503  ast_channel_amaflags_set(chan, amaflags);
504  ast_channel_unlock(chan);
505  } else if (!strcasecmp(data, "peeraccount"))
506  locked_string_field_set(chan, peeraccount, value);
507  else if (!strcasecmp(data, "hangupsource"))
508  /* XXX - should we be forcing this here? */
509  ast_set_hangupsource(chan, value, 0);
510  else if (!strcasecmp(data, "tonezone")) {
511  struct ast_tone_zone *new_zone;
512  if (!(new_zone = ast_get_indication_zone(value))) {
513  ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
514  ret = -1;
515  } else {
516  ast_channel_lock(chan);
517  if (ast_channel_zone(chan)) {
519  }
520  ast_channel_zone_set(chan, ast_tone_zone_ref(new_zone));
521  ast_channel_unlock(chan);
522  new_zone = ast_tone_zone_unref(new_zone);
523  }
524  } else if (!strcasecmp(data, "dtmf_features")) {
526  } else if (!strcasecmp(data, "callgroup")) {
527  ast_channel_lock(chan);
529  ast_channel_unlock(chan);
530  } else if (!strcasecmp(data, "pickupgroup")) {
531  ast_channel_lock(chan);
533  ast_channel_unlock(chan);
534  } else if (!strcasecmp(data, "namedcallgroup")) {
535  struct ast_namedgroups *groups = ast_get_namedgroups(value);
536 
537  ast_channel_lock(chan);
538  ast_channel_named_callgroups_set(chan, groups);
539  ast_channel_unlock(chan);
540  ast_unref_namedgroups(groups);
541  } else if (!strcasecmp(data, "namedpickupgroup")) {
542  struct ast_namedgroups *groups = ast_get_namedgroups(value);
543 
544  ast_channel_lock(chan);
546  ast_channel_unlock(chan);
547  ast_unref_namedgroups(groups);
548  } else if (!strcasecmp(data, "txgain")) {
549  sscanf(value, "%4hhd", &gainset);
550  ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
551  } else if (!strcasecmp(data, "rxgain")) {
552  sscanf(value, "%4hhd", &gainset);
553  ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
554  } else if (!strcasecmp(data, "transfercapability")) {
555  unsigned short i;
556 
557  ast_channel_lock(chan);
558  for (i = 0; i < 0x20; i++) {
559  if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
561  break;
562  }
563  }
564  ast_channel_unlock(chan);
565  } else if (!strcasecmp(data, "hangup_handler_pop")) {
566  /* Pop one hangup handler before pushing the new handler. */
569  } else if (!strcasecmp(data, "hangup_handler_push")) {
571  } else if (!strcasecmp(data, "hangup_handler_wipe")) {
572  /* Pop all hangup handlers before pushing the new handler. */
573  while (ast_pbx_hangup_handler_pop(chan)) {
574  }
576  } else if (!strncasecmp(data, "secure_bridge_", 14)) {
577  struct ast_datastore *ds;
578  struct ast_secure_call_store *store;
579 
580  if (!chan || !value) {
581  return -1;
582  }
583 
584  ast_channel_lock(chan);
585  if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
586  if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
587  ast_channel_unlock(chan);
588  return -1;
589  }
590  if (!(store = ast_calloc(1, sizeof(*store)))) {
591  ast_channel_unlock(chan);
592  ast_free(ds);
593  return -1;
594  }
595  ds->data = store;
596  ast_channel_datastore_add(chan, ds);
597  } else {
598  store = ds->data;
599  }
600 
601  if (!strcasecmp(data, "secure_bridge_signaling")) {
602  store->signaling = ast_true(value) ? 1 : 0;
603  } else if (!strcasecmp(data, "secure_bridge_media")) {
604  store->media = ast_true(value) ? 1 : 0;
605  }
606  ast_channel_unlock(chan);
607  } else if (!strcasecmp(data, "max_forwards")) {
608  int max_forwards;
609  if (sscanf(value, "%d", &max_forwards) != 1) {
610  ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value);
611  ret = -1;
612  } else {
613  ast_channel_lock(chan);
614  ret = ast_max_forwards_set(chan, max_forwards);
615  ast_channel_unlock(chan);
616  }
617  } else if (!ast_channel_tech(chan)->func_channel_write
618  || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
619  ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
620  data);
621  ret = -1;
622  }
623 
624  return ret;
625 }
static char musicclass[MAX_MUSICCLASS]
Definition: chan_mgcp.c:162
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_iax2.c:428
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
#define ast_channel_lock(chan)
Definition: channel.h:2945
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
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:163
static int amaflags
Definition: chan_iax2.c:431
#define AST_OPTION_TXGAIN
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
#define LOG_WARNING
Definition: logger.h:274
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
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
int ast_pbx_hangup_handler_pop(struct ast_channel *chan)
Pop the top of the channel hangup handler stack.
Structure for a data store object.
Definition: datastore.h:68
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:2404
#define NULL
Definition: resample.c:96
const struct ast_datastore_info secure_call_info
int value
Definition: syslog.c:37
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
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:7522
int ast_channel_priority(const struct ast_channel *chan)
#define ast_strlen_zero(foo)
Definition: strings.h:52
enum ama_flags ast_channel_string2amaflag(const char *flag)
Convert a string to a detail record AMA flag.
Definition: channel.c:4405
#define ast_log
Definition: astobj2.c:42
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it&#39;s bridge.
Definition: channel.c:2504
A set of tones for a given locale.
Definition: indications.h:74
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:117
void ast_bridge_discard_after_goto(struct ast_channel *chan)
Discard channel after bridge goto location.
Definition: bridge_after.c:396
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7718
const char * ast_channel_exten(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:7775
#define LOG_ERROR
Definition: logger.h:285
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
#define AST_OPTION_RXGAIN
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
Channel datastore data for max forwards.
Definition: max_forwards.c:29
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:433
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
#define locked_string_field_set(chan, field, source)
Definition: func_channel.c:277
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_pbx_hangup_handler_push(struct ast_channel *chan, const char *handler)
Push the given hangup handler onto the channel hangup handler stack.
static const char *const transfercapability_table[0x20]
Definition: func_channel.c:284
void * data
Definition: datastore.h:70
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:627
const char * ast_channel_context(const struct ast_channel *chan)
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:636
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
struct ast_namedgroups * ast_unref_namedgroups(struct ast_namedgroups *groups)
Definition: channel.c:7832
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)

◆ 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 656 of file func_channel.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, c, LOG_WARNING, and NULL.

657 {
658  struct ast_channel *c = NULL;
659  regex_t re;
660  int res;
661  size_t buflen = 0;
662  struct ast_channel_iterator *iter;
663 
664  buf[0] = '\0';
665 
666  if (!ast_strlen_zero(data)) {
667  if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
668  regerror(res, &re, buf, maxlen);
669  ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
670  return -1;
671  }
672  }
673 
674  if (!(iter = ast_channel_iterator_all_new())) {
675  if (!ast_strlen_zero(data)) {
676  regfree(&re);
677  }
678  return -1;
679  }
680 
681  while ((c = ast_channel_iterator_next(iter))) {
682  ast_channel_lock(c);
683  if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
684  size_t namelen = strlen(ast_channel_name(c));
685  if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
686  if (!ast_strlen_zero(buf)) {
687  strcat(buf, " ");
688  buflen++;
689  }
690  strcat(buf, ast_channel_name(c));
691  buflen += namelen;
692  } else {
693  ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n");
694  }
695  }
697  c = ast_channel_unref(c);
698  }
699 
701 
702  if (!ast_strlen_zero(data)) {
703  regfree(&re);
704  }
705 
706  return 0;
707 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1422
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
static struct test_val c
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1360
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1408

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

References ast_alloca, ast_channel_get_by_name(), ast_channel_linkedid(), ast_channel_unref, ast_log, ast_str_substitute_variables(), and LOG_WARNING.

716 {
717  struct ast_channel *mchan;
718  char *template = ast_alloca(4 + strlen(data));
719 
720  if (!chan) {
721  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
722  return -1;
723  }
724 
726  sprintf(template, "${%s}", data); /* SAFE */
727  ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
728  if (mchan) {
729  ast_channel_unref(mchan);
730  }
731  return 0;
732 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define LOG_WARNING
Definition: logger.h:274
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * data
const char * ast_channel_linkedid(const struct ast_channel *chan)
#define ast_log
Definition: astobj2.c:42
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

◆ func_mchan_write()

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

Definition at line 734 of file func_channel.c.

References ast_channel_get_by_name(), ast_channel_linkedid(), ast_channel_unref, ast_log, LOG_WARNING, and pbx_builtin_setvar_helper().

736 {
737  struct ast_channel *mchan;
738 
739  if (!chan) {
740  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
741  return -1;
742  }
743 
745  pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
746  if (mchan) {
747  ast_channel_unref(mchan);
748  }
749  return 0;
750 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define LOG_WARNING
Definition: logger.h:274
const char * data
int value
Definition: syslog.c:37
const char * ast_channel_linkedid(const struct ast_channel *chan)
#define ast_log
Definition: astobj2.c:42
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...
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

◆ load_module()

static int load_module ( void  )
static

Definition at line 769 of file func_channel.c.

References ast_custom_function_register.

770 {
771  int res = 0;
772 
776 
777  return res;
778 }
static struct ast_custom_function channel_function
Definition: func_channel.c:650
static struct ast_custom_function channels_function
Definition: func_channel.c:709
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508
static struct ast_custom_function mchan_function
Definition: func_channel.c:752

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 758 of file func_channel.c.

References ast_custom_function_unregister().

759 {
760  int res = 0;
761 
765 
766  return res;
767 }
static struct ast_custom_function channel_function
Definition: func_channel.c:650
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function channels_function
Definition: func_channel.c:709
static struct ast_custom_function mchan_function
Definition: func_channel.c:752

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 780 of file func_channel.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 780 of file func_channel.c.

◆ channel_function

struct ast_custom_function channel_function
static
Initial value:
= {
.name = "CHANNEL",
}
static int func_channel_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
Definition: func_channel.c:290
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:627

Definition at line 650 of file func_channel.c.

◆ 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:656

Definition at line 709 of file func_channel.c.

◆ 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_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:734
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:714

Definition at line 752 of file func_channel.c.

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

Referenced by func_channel_read(), and func_channel_write_real().