Wed Jan 8 2020 09:50:12

Asterisk developer's documentation


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/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/indications.h"
#include "asterisk/stringfields.h"
#include "asterisk/global_datastores.h"

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)
 
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

#define locked_copy_string (   chan,
  dest,
  source,
  len 
)
Value:
do { \
ast_copy_string(dest, source, len); \
} while (0)
#define ast_channel_lock(chan)
Definition: channel.h:2466
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223

Definition at line 317 of file func_channel.c.

Referenced by func_channel_read().

#define locked_string_field_set (   chan,
  field,
  source 
)
Value:
do { \
ast_string_field_set(chan, field, source); \
} while (0)
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define ast_channel_unlock(chan)
Definition: channel.h:2467
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344

Definition at line 323 of file func_channel.c.

Referenced by func_channel_write_real().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 729 of file func_channel.c.

static void __unreg_module ( void  )
static

Definition at line 729 of file func_channel.c.

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

Definition at line 336 of file func_channel.c.

References ast_channel::_state, ast_channel::accountcode, ast_channel::amaflags, ast_channel::appl, ast_bridged_channel(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_copy_string(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, ast_getformatname(), ast_log(), ast_print_group(), ast_state2str(), ast_strlen_zero(), ast_channel::callgroup, ast_channel::cdr, ast_channel::context, ast_tone_zone::country, ast_datastore::data, ast_channel::data, ast_channel::exten, ast_channel_tech::func_channel_read, ast_channel::hangupsource, ast_channel::language, ast_channel::linkedid, locked_copy_string, LOG_WARNING, ast_secure_call_store::media, ast_channel::musicclass, ast_channel::name, ast_channel::nativeformats, ast_channel::parkinglot, pbx_builtin_getvar_helper(), ast_channel::peeraccount, ast_channel::readformat, secure_call_info, ast_secure_call_store::signaling, ast_channel::tech, ast_channel::transfercapability, ast_channel_tech::type, ast_channel::uniqueid, ast_channel::userfield, ast_channel::writeformat, and ast_channel::zone.

338 {
339  int ret = 0;
340 
341  if (!chan) {
342  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
343  return -1;
344  }
345 
346  if (!strcasecmp(data, "audionativeformat"))
347  /* use the _multiple version when chan->nativeformats holds multiple formats */
348  /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
350  else if (!strcasecmp(data, "videonativeformat"))
351  /* use the _multiple version when chan->nativeformats holds multiple formats */
352  /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
354  else if (!strcasecmp(data, "audioreadformat"))
356  else if (!strcasecmp(data, "audiowriteformat"))
358 #ifdef CHANNEL_TRACE
359  else if (!strcasecmp(data, "trace")) {
360  ast_channel_lock(chan);
361  ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
362  ast_channel_unlock(chan);
363  }
364 #endif
365  else if (!strcasecmp(data, "tonezone") && chan->zone)
366  locked_copy_string(chan, buf, chan->zone->country, len);
367  else if (!strcasecmp(data, "language"))
368  locked_copy_string(chan, buf, chan->language, len);
369  else if (!strcasecmp(data, "musicclass"))
370  locked_copy_string(chan, buf, chan->musicclass, len);
371  else if (!strcasecmp(data, "name")) {
372  locked_copy_string(chan, buf, chan->name, len);
373  } else if (!strcasecmp(data, "parkinglot"))
374  locked_copy_string(chan, buf, chan->parkinglot, len);
375  else if (!strcasecmp(data, "state"))
376  locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
377  else if (!strcasecmp(data, "channeltype"))
378  locked_copy_string(chan, buf, chan->tech->type, len);
379  else if (!strcasecmp(data, "accountcode"))
380  locked_copy_string(chan, buf, chan->accountcode, len);
381  else if (!strcasecmp(data, "checkhangup")) {
382  ast_channel_lock(chan);
383  ast_copy_string(buf, ast_check_hangup(chan) ? "1" : "0", len);
384  ast_channel_unlock(chan);
385  } else if (!strcasecmp(data, "peeraccount"))
386  locked_copy_string(chan, buf, chan->peeraccount, len);
387  else if (!strcasecmp(data, "hangupsource"))
388  locked_copy_string(chan, buf, chan->hangupsource, len);
389  else if (!strcasecmp(data, "appname") && chan->appl)
390  locked_copy_string(chan, buf, chan->appl, len);
391  else if (!strcasecmp(data, "appdata") && chan->data)
392  locked_copy_string(chan, buf, chan->data, len);
393  else if (!strcasecmp(data, "exten") && chan->data)
394  locked_copy_string(chan, buf, chan->exten, len);
395  else if (!strcasecmp(data, "context") && chan->data)
396  locked_copy_string(chan, buf, chan->context, len);
397  else if (!strcasecmp(data, "userfield") && chan->data)
398  locked_copy_string(chan, buf, chan->userfield, len);
399  else if (!strcasecmp(data, "channame") && chan->data)
400  locked_copy_string(chan, buf, chan->name, len);
401  else if (!strcasecmp(data, "linkedid")) {
402  ast_channel_lock(chan);
403  if (ast_strlen_zero(chan->linkedid)) {
404  /* fall back on the channel's uniqueid if linkedid is unset */
405  ast_copy_string(buf, chan->uniqueid, len);
406  }
407  else {
408  ast_copy_string(buf, chan->linkedid, len);
409  }
410  ast_channel_unlock(chan);
411  } else if (!strcasecmp(data, "peer")) {
412  struct ast_channel *p;
413  ast_channel_lock(chan);
414  p = ast_bridged_channel(chan);
415  if (p || chan->tech || chan->cdr) /* dummy channel? if so, we hid the peer name in the language */
416  ast_copy_string(buf, (p ? p->name : ""), len);
417  else {
418  /* a dummy channel can still pass along bridged peer info via
419  the BRIDGEPEER variable */
420  const char *pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
421  if (!ast_strlen_zero(pname))
422  ast_copy_string(buf, pname, len); /* a horrible kludge, but... how else? */
423  else
424  buf[0] = 0;
425  }
426  ast_channel_unlock(chan);
427  } else if (!strcasecmp(data, "uniqueid")) {
428  locked_copy_string(chan, buf, chan->uniqueid, len);
429  } else if (!strcasecmp(data, "transfercapability"))
431  else if (!strcasecmp(data, "callgroup")) {
432  char groupbuf[256];
433  locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
434  } else if (!strcasecmp(data, "amaflags")) {
435  char amabuf[256];
436  snprintf(amabuf,sizeof(amabuf), "%d", chan->amaflags);
437  locked_copy_string(chan, buf, amabuf, len);
438  } else if (!strncasecmp(data, "secure_bridge_", 14)) {
439  struct ast_datastore *ds;
440  ast_channel_lock(chan);
441  if ((ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
442  struct ast_secure_call_store *encrypt = ds->data;
443  if (!strcasecmp(data, "secure_bridge_signaling")) {
444  snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
445  } else if (!strcasecmp(data, "secure_bridge_media")) {
446  snprintf(buf, len, "%s", encrypt->media ? "1" : "");
447  }
448  }
449  ast_channel_unlock(chan);
450  } else if (!chan->tech || !chan->tech->func_channel_read || chan->tech->func_channel_read(chan, function, data, buf, len)) {
451  ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
452  ret = -1;
453  }
454 
455  return ret;
456 }
int(* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
Provide additional read items for CHANNEL() dialplan function.
Definition: channel.h:600
const ast_string_field peeraccount
Definition: channel.h:787
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
const char *const type
Definition: channel.h:508
struct ast_tone_zone * zone
Definition: channel.h:767
const ast_string_field uniqueid
Definition: channel.h:787
format_t writeformat
Definition: channel.h:854
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define LOG_WARNING
Definition: logger.h:144
struct ast_cdr * cdr
Definition: channel.h:766
unsigned short transfercapability
Definition: channel.h:863
format_t nativeformats
Definition: channel.h:852
Structure for a data store object.
Definition: datastore.h:54
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:2604
const char * ast_state2str(enum ast_channel_state)
Gives the string form of a given channel state.
Definition: channel.c:1007
const char * data
Definition: channel.h:755
const ast_string_field linkedid
Definition: channel.h:787
const char * appl
Definition: channel.h:754
ast_group_t callgroup
Definition: channel.h:818
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Definition: pbx.c:10475
char * ast_print_group(char *buf, int buflen, ast_group_t group)
print call- and pickup groups into buffer
Definition: channel.c:8236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define locked_copy_string(chan, dest, source, len)
Definition: func_channel.c:317
const ast_string_field parkinglot
Definition: channel.h:787
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:806
struct ast_datastore_info secure_call_info
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
const ast_string_field hangupsource
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_FORMAT_VIDEO_MASK
Definition: frame.h:290
#define ast_channel_unlock(chan)
Definition: channel.h:2467
#define AST_FORMAT_AUDIO_MASK
Definition: frame.h:274
const ast_string_field userfield
Definition: channel.h:787
static const char *const transfercapability_table[0x20]
Definition: func_channel.c:330
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void * data
Definition: datastore.h:56
format_t readformat
Definition: channel.h:853
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
const ast_string_field musicclass
Definition: channel.h:787
const ast_string_field accountcode
Definition: channel.h:787
int amaflags
Definition: channel.h:843
struct ast_channel_tech * tech
Definition: channel.h:743
const ast_string_field language
Definition: channel.h:787
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
static int func_channel_write ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
)
static

Definition at line 576 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.

577 {
578  int res;
579  ast_chan_write_info_t write_info = {
581  .write_fn = func_channel_write_real,
582  .chan = chan,
583  .function = function,
584  .data = data,
585  .value = value,
586  };
587 
588  if (!chan) {
589  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
590  return -1;
591  }
592 
593  res = func_channel_write_real(chan, function, data, value);
594  ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
595 
596  return res;
597 }
#define LOG_WARNING
Definition: logger.h:144
const char * data
Definition: channel.h:755
int value
Definition: syslog.c:39
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:7795
#define AST_OPTION_CHANNEL_WRITE
Handle channel write data If a channel needs to process the data from a func_channel write operation ...
Definition: frame.h:484
#define AST_CHAN_WRITE_INFO_T_VERSION
ast_chan_write_info_t version. Must be incremented if structure is changed
Definition: channel.h:484
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
Structure to handle passing func_channel_write info to channels via setoption.
Definition: channel.h:482
static int func_channel_write_real(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:458
static int func_channel_write_real ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
)
static

Definition at line 458 of file func_channel.c.

References accountcode, ast_channel::amaflags, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_setoption(), ast_channel_unlock, ast_datastore_alloc(), ast_false(), ast_free, ast_get_group(), ast_get_indication_zone(), ast_log(), AST_OPTION_RXGAIN, AST_OPTION_TXGAIN, ast_set_hangupsource(), ast_tone_zone_ref(), ast_tone_zone_unref(), ast_true(), ast_channel::callgroup, ast_datastore::data, ast_channel_tech::func_channel_write, language, locked_string_field_set, LOG_ERROR, LOG_WARNING, ast_secure_call_store::media, musicclass, parkinglot, secure_call_info, ast_secure_call_store::signaling, ast_channel::tech, ast_channel::transfercapability, and ast_channel::zone.

Referenced by func_channel_write().

460 {
461  int ret = 0;
462  signed char gainset;
463 
464  if (!strcasecmp(data, "language"))
466  else if (!strcasecmp(data, "parkinglot"))
468  else if (!strcasecmp(data, "musicclass"))
470  else if (!strcasecmp(data, "accountcode"))
472  else if (!strcasecmp(data, "userfield"))
473  locked_string_field_set(chan, userfield, value);
474  else if (!strcasecmp(data, "amaflags")) {
475  ast_channel_lock(chan);
476  if(isdigit(*value)) {
477  sscanf(value, "%30d", &chan->amaflags);
478  } else if (!strcasecmp(value,"OMIT")){
479  chan->amaflags = 1;
480  } else if (!strcasecmp(value,"BILLING")){
481  chan->amaflags = 2;
482  } else if (!strcasecmp(value,"DOCUMENTATION")){
483  chan->amaflags = 3;
484  }
485  ast_channel_unlock(chan);
486  } else if (!strcasecmp(data, "peeraccount"))
487  locked_string_field_set(chan, peeraccount, value);
488  else if (!strcasecmp(data, "hangupsource"))
489  /* XXX - should we be forcing this here? */
490  ast_set_hangupsource(chan, value, 0);
491 #ifdef CHANNEL_TRACE
492  else if (!strcasecmp(data, "trace")) {
493  ast_channel_lock(chan);
494  if (ast_true(value))
495  ret = ast_channel_trace_enable(chan);
496  else if (ast_false(value))
497  ret = ast_channel_trace_disable(chan);
498  else {
499  ret = -1;
500  ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).\n");
501  }
502  ast_channel_unlock(chan);
503  }
504 #endif
505  else if (!strcasecmp(data, "tonezone")) {
506  struct ast_tone_zone *new_zone;
507  if (!(new_zone = ast_get_indication_zone(value))) {
508  ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
509  ret = -1;
510  } else {
511  ast_channel_lock(chan);
512  if (chan->zone) {
513  chan->zone = ast_tone_zone_unref(chan->zone);
514  }
515  chan->zone = ast_tone_zone_ref(new_zone);
516  ast_channel_unlock(chan);
517  new_zone = ast_tone_zone_unref(new_zone);
518  }
519  } else if (!strcasecmp(data, "callgroup"))
520  chan->callgroup = ast_get_group(value);
521  else if (!strcasecmp(data, "txgain")) {
522  sscanf(value, "%4hhd", &gainset);
523  ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
524  } else if (!strcasecmp(data, "rxgain")) {
525  sscanf(value, "%4hhd", &gainset);
526  ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
527  } else if (!strcasecmp(data, "transfercapability")) {
528  unsigned short i;
529  for (i = 0; i < 0x20; i++) {
530  if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
531  chan->transfercapability = i;
532  break;
533  }
534  }
535  } else if (!strncasecmp(data, "secure_bridge_", 14)) {
536  struct ast_datastore *ds;
537  struct ast_secure_call_store *store;
538 
539  if (!chan || !value) {
540  return -1;
541  }
542 
543  ast_channel_lock(chan);
544  if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
545  if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
546  ast_channel_unlock(chan);
547  return -1;
548  }
549  if (!(store = ast_calloc(1, sizeof(*store)))) {
550  ast_channel_unlock(chan);
551  ast_free(ds);
552  return -1;
553  }
554  ds->data = store;
555  ast_channel_datastore_add(chan, ds);
556  } else {
557  store = ds->data;
558  }
559  ast_channel_unlock(chan);
560 
561  if (!strcasecmp(data, "secure_bridge_signaling")) {
562  store->signaling = ast_true(value) ? 1 : 0;
563  } else if (!strcasecmp(data, "secure_bridge_media")) {
564  store->media = ast_true(value) ? 1 : 0;
565  }
566  } else if (!chan->tech->func_channel_write
567  || chan->tech->func_channel_write(chan, function, data, value)) {
568  ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
569  data);
570  ret = -1;
571  }
572 
573  return ret;
574 }
static char musicclass[MAX_MUSICCLASS]
Definition: chan_mgcp.c:155
static char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: chan_iax2.c:383
#define ast_channel_lock(chan)
Definition: channel.h:2466
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:156
struct ast_tone_zone * zone
Definition: channel.h:767
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:204
#define LOG_WARNING
Definition: logger.h:144
unsigned short transfercapability
Definition: channel.h:863
Structure for a data store object.
Definition: datastore.h:54
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:2604
int value
Definition: syslog.c:39
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:7795
ast_group_t callgroup
Definition: channel.h:818
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:2769
A set of tones for a given locale.
Definition: indications.h:73
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:108
ast_group_t ast_get_group(const char *s)
Definition: channel.c:7987
struct ast_datastore_info secure_call_info
#define LOG_ERROR
Definition: logger.h:155
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is &quot;true&quot;. This function checks to see whether a string passed to it is an indication of an &quot;true&quot; value. It checks to see if the string is &quot;yes&quot;, &quot;true&quot;, &quot;y&quot;, &quot;t&quot;, &quot;on&quot; or &quot;1&quot;.
Definition: utils.c:1533
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:451
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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:215
struct ast_datastore * ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
Definition: datastore.c:98
#define locked_string_field_set(chan, field, source)
Definition: func_channel.c:323
#define ast_channel_unlock(chan)
Definition: channel.h:2467
#define ast_free(a)
Definition: astmm.h:97
static const char *const transfercapability_table[0x20]
Definition: func_channel.c:330
void * data
Definition: datastore.h:56
#define ast_calloc(a, b)
Definition: astmm.h:82
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is &quot;false&quot;...
Definition: utils.c:1550
#define AST_OPTION_RXGAIN
Definition: frame.h:463
int(* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value)
Provide additional write items for CHANNEL() dialplan function.
Definition: channel.h:603
int amaflags
Definition: channel.h:843
struct ast_channel_tech * tech
Definition: channel.h:743
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2590
#define AST_OPTION_TXGAIN
Definition: frame.h:458
static int func_channels_read ( struct ast_channel chan,
const char *  function,
char *  data,
char *  buf,
size_t  maxlen 
)
static

Definition at line 605 of file func_channel.c.

References ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, ast_log(), ast_strlen_zero(), LOG_WARNING, and ast_channel::name.

606 {
607  struct ast_channel *c = NULL;
608  regex_t re;
609  int res;
610  size_t buflen = 0;
611  struct ast_channel_iterator *iter;
612 
613  buf[0] = '\0';
614 
615  if (!ast_strlen_zero(data)) {
616  if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
617  regerror(res, &re, buf, maxlen);
618  ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
619  return -1;
620  }
621  }
622 
623  if (!(iter = ast_channel_iterator_all_new())) {
624  if (!ast_strlen_zero(data)) {
625  regfree(&re);
626  }
627  return -1;
628  }
629 
630  while ((c = ast_channel_iterator_next(iter))) {
631  ast_channel_lock(c);
632  if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) {
633  size_t namelen = strlen(c->name);
634  if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
635  if (!ast_strlen_zero(buf)) {
636  strcat(buf, " ");
637  buflen++;
638  }
639  strcat(buf, c->name);
640  buflen += namelen;
641  } else {
642  ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n");
643  }
644  }
646  c = ast_channel_unref(c);
647  }
648 
650 
651  if (!ast_strlen_zero(data)) {
652  regfree(&re);
653  }
654 
655  return 0;
656 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1715
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
#define LOG_WARNING
Definition: logger.h:144
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1649
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
Definition: channel.c:1701
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 663 of file func_channel.c.

References ast_alloca, ast_channel_get_by_name(), ast_channel_unref, ast_log(), ast_str_substitute_variables(), ast_channel::linkedid, and LOG_WARNING.

665 {
666  struct ast_channel *mchan;
667  char *template = ast_alloca(4 + strlen(data));
668 
669  if (!chan) {
670  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
671  return -1;
672  }
673 
674  mchan = ast_channel_get_by_name(chan->linkedid);
675  sprintf(template, "${%s}", data); /* SAFE */
676  ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
677  if (mchan) {
678  ast_channel_unref(mchan);
679  }
680  return 0;
681 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
#define LOG_WARNING
Definition: logger.h:144
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
Definition: pbx.c:4468
const char * data
Definition: channel.h:755
const ast_string_field linkedid
Definition: channel.h:787
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
static int func_mchan_write ( struct ast_channel chan,
const char *  function,
char *  data,
const char *  value 
)
static

Definition at line 683 of file func_channel.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_log(), ast_channel::linkedid, LOG_WARNING, and pbx_builtin_setvar_helper().

685 {
686  struct ast_channel *mchan;
687 
688  if (!chan) {
689  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
690  return -1;
691  }
692 
693  mchan = ast_channel_get_by_name(chan->linkedid);
694  pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
695  if (mchan) {
696  ast_channel_unref(mchan);
697  }
698  return 0;
699 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
#define LOG_WARNING
Definition: logger.h:144
const char * data
Definition: channel.h:755
int value
Definition: syslog.c:39
const ast_string_field linkedid
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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...
Definition: pbx.c:10546
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
static int load_module ( void  )
static

Definition at line 718 of file func_channel.c.

References ast_custom_function_register.

719 {
720  int res = 0;
721 
725 
726  return res;
727 }
static struct ast_custom_function channel_function
Definition: func_channel.c:599
static struct ast_custom_function channels_function
Definition: func_channel.c:658
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static struct ast_custom_function mchan_function
Definition: func_channel.c:701
static int unload_module ( void  )
static

Definition at line 707 of file func_channel.c.

References ast_custom_function_unregister().

708 {
709  int res = 0;
710 
714 
715  return res;
716 }
static struct ast_custom_function channel_function
Definition: func_channel.c:599
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function channels_function
Definition: func_channel.c:658
static struct ast_custom_function mchan_function
Definition: func_channel.c:701

Variable Documentation

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

Definition at line 729 of file func_channel.c.

Definition at line 729 of file func_channel.c.

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:336
static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
Definition: func_channel.c:576

Definition at line 599 of file func_channel.c.

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:605

Definition at line 658 of file func_channel.c.

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:683
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:663

Definition at line 701 of file func_channel.c.

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