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 dependency graph for func_channel.c:

Go to the source code of this file.

Defines

#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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
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 <kpfleming@digium.com>

Ben Winslow

Definition in file func_channel.c.


Define Documentation

#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)

Definition at line 405 of file func_channel.c.

Referenced by func_channel_read().

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

Referenced by func_channel_write_real().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 909 of file func_channel.c.

static void __unreg_module ( void   )  [static]

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

References ao2_ref, ast_bridge_features_ds_get_string(), ast_bridge_read_after_goto(), ast_channel_accountcode(), ast_channel_amaflags(), ast_channel_appl(), ast_channel_bridge_peer(), ast_channel_callgroup(), 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_get_name(), ast_log, 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, and type.

00426 {
00427    int ret = 0;
00428    struct ast_format_cap *tmpcap;
00429 
00430    if (!chan) {
00431       ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
00432       return -1;
00433    }
00434 
00435    if (!strcasecmp(data, "audionativeformat")) {
00436       tmpcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00437       if (tmpcap) {
00438          struct ast_str *codec_buf = ast_str_alloca(128);
00439 
00440          ast_channel_lock(chan);
00441          ast_format_cap_append_from_cap(tmpcap, ast_channel_nativeformats(chan), AST_MEDIA_TYPE_AUDIO);
00442          ast_channel_unlock(chan);
00443          ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
00444          ao2_ref(tmpcap, -1);
00445       }
00446    } else if (!strcasecmp(data, "videonativeformat")) {
00447       tmpcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00448       if (tmpcap) {
00449          struct ast_str *codec_buf = ast_str_alloca(128);
00450 
00451          ast_channel_lock(chan);
00452          ast_format_cap_append_from_cap(tmpcap, ast_channel_nativeformats(chan), AST_MEDIA_TYPE_VIDEO);
00453          ast_channel_unlock(chan);
00454          ast_copy_string(buf, ast_format_cap_get_names(tmpcap, &codec_buf), len);
00455          ao2_ref(tmpcap, -1);
00456       }
00457    } else if (!strcasecmp(data, "audioreadformat")) {
00458       locked_copy_string(chan, buf, ast_format_get_name(ast_channel_readformat(chan)), len);
00459    } else if (!strcasecmp(data, "audiowriteformat")) {
00460       locked_copy_string(chan, buf, ast_format_get_name(ast_channel_writeformat(chan)), len);
00461 #ifdef CHANNEL_TRACE
00462    } else if (!strcasecmp(data, "trace")) {
00463       locked_copy_string(chan, buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
00464 #endif
00465    } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
00466       locked_copy_string(chan, buf, ast_channel_zone(chan)->country, len);
00467    } else if (!strcasecmp(data, "dtmf_features")) {
00468       if (ast_bridge_features_ds_get_string(chan, buf, len)) {
00469          buf[0] = '\0';
00470       }
00471    } else if (!strcasecmp(data, "language"))
00472       locked_copy_string(chan, buf, ast_channel_language(chan), len);
00473    else if (!strcasecmp(data, "musicclass"))
00474       locked_copy_string(chan, buf, ast_channel_musicclass(chan), len);
00475    else if (!strcasecmp(data, "name")) {
00476       locked_copy_string(chan, buf, ast_channel_name(chan), len);
00477    } else if (!strcasecmp(data, "parkinglot"))
00478       locked_copy_string(chan, buf, ast_channel_parkinglot(chan), len);
00479    else if (!strcasecmp(data, "state"))
00480       locked_copy_string(chan, buf, ast_state2str(ast_channel_state(chan)), len);
00481    else if (!strcasecmp(data, "onhold")) {
00482       locked_copy_string(chan, buf,
00483          ast_channel_hold_state(chan) == AST_CONTROL_HOLD ? "1" : "0", len);
00484    } else if (!strcasecmp(data, "channeltype"))
00485       locked_copy_string(chan, buf, ast_channel_tech(chan)->type, len);
00486    else if (!strcasecmp(data, "accountcode"))
00487       locked_copy_string(chan, buf, ast_channel_accountcode(chan), len);
00488    else if (!strcasecmp(data, "checkhangup")) {
00489       locked_copy_string(chan, buf, ast_check_hangup(chan) ? "1" : "0", len);
00490    } else if (!strcasecmp(data, "peeraccount"))
00491       locked_copy_string(chan, buf, ast_channel_peeraccount(chan), len);
00492    else if (!strcasecmp(data, "hangupsource"))
00493       locked_copy_string(chan, buf, ast_channel_hangupsource(chan), len);
00494    else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
00495       locked_copy_string(chan, buf, ast_channel_appl(chan), len);
00496    else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
00497       locked_copy_string(chan, buf, ast_channel_data(chan), len);
00498    else if (!strcasecmp(data, "exten") && ast_channel_data(chan))
00499       locked_copy_string(chan, buf, ast_channel_exten(chan), len);
00500    else if (!strcasecmp(data, "context") && ast_channel_data(chan))
00501       locked_copy_string(chan, buf, ast_channel_context(chan), len);
00502    else if (!strcasecmp(data, "userfield") && ast_channel_data(chan))
00503       locked_copy_string(chan, buf, ast_channel_userfield(chan), len);
00504    else if (!strcasecmp(data, "channame") && ast_channel_data(chan))
00505       locked_copy_string(chan, buf, ast_channel_name(chan), len);
00506    else if (!strcasecmp(data, "linkedid")) {
00507       ast_channel_lock(chan);
00508       if (ast_strlen_zero(ast_channel_linkedid(chan))) {
00509          /* fall back on the channel's uniqueid if linkedid is unset */
00510          ast_copy_string(buf, ast_channel_uniqueid(chan), len);
00511       }
00512       else {
00513          ast_copy_string(buf, ast_channel_linkedid(chan), len);
00514       }
00515       ast_channel_unlock(chan);
00516    } else if (!strcasecmp(data, "peer")) {
00517       struct ast_channel *peer;
00518 
00519       peer = ast_channel_bridge_peer(chan);
00520       if (peer) {
00521          /* Only real channels could have a bridge peer this way. */
00522          ast_channel_lock(peer);
00523          ast_copy_string(buf, ast_channel_name(peer), len);
00524          ast_channel_unlock(peer);
00525          ast_channel_unref(peer);
00526       } else {
00527          buf[0] = '\0';
00528          ast_channel_lock(chan);
00529          if (!ast_channel_tech(chan)) {
00530             const char *pname;
00531 
00532             /*
00533              * A dummy channel can still pass along bridged peer info
00534              * via the BRIDGEPEER variable.
00535              *
00536              * A horrible kludge, but... how else?
00537              */
00538             pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
00539             if (!ast_strlen_zero(pname)) {
00540                ast_copy_string(buf, pname, len);
00541             }
00542          }
00543          ast_channel_unlock(chan);
00544       }
00545    } else if (!strcasecmp(data, "uniqueid")) {
00546       locked_copy_string(chan, buf, ast_channel_uniqueid(chan), len);
00547    } else if (!strcasecmp(data, "transfercapability")) {
00548       locked_copy_string(chan, buf, transfercapability_table[ast_channel_transfercapability(chan) & 0x1f], len);
00549    } else if (!strcasecmp(data, "callgroup")) {
00550       char groupbuf[256];
00551 
00552       locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
00553    } else if (!strcasecmp(data, "pickupgroup")) {
00554       char groupbuf[256];
00555 
00556       locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
00557    } else if (!strcasecmp(data, "namedcallgroup")) {
00558       struct ast_str *tmp_str = ast_str_alloca(1024);
00559 
00560       locked_copy_string(chan, buf,  ast_print_namedgroups(&tmp_str, ast_channel_named_callgroups(chan)), len);
00561    } else if (!strcasecmp(data, "namedpickupgroup")) {
00562       struct ast_str *tmp_str = ast_str_alloca(1024);
00563 
00564       locked_copy_string(chan, buf,  ast_print_namedgroups(&tmp_str, ast_channel_named_pickupgroups(chan)), len);
00565    } else if (!strcasecmp(data, "after_bridge_goto")) {
00566       ast_bridge_read_after_goto(chan, buf, len);
00567    } else if (!strcasecmp(data, "amaflags")) {
00568       ast_channel_lock(chan);
00569       snprintf(buf, len, "%u", ast_channel_amaflags(chan));
00570       ast_channel_unlock(chan);
00571    } else if (!strncasecmp(data, "secure_bridge_", 14)) {
00572       struct ast_datastore *ds;
00573 
00574       buf[0] = '\0';
00575       ast_channel_lock(chan);
00576       if ((ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
00577          struct ast_secure_call_store *encrypt = ds->data;
00578 
00579          if (!strcasecmp(data, "secure_bridge_signaling")) {
00580             snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
00581          } else if (!strcasecmp(data, "secure_bridge_media")) {
00582             snprintf(buf, len, "%s", encrypt->media ? "1" : "");
00583          }
00584       }
00585       ast_channel_unlock(chan);
00586    } 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)) {
00587       ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
00588       ret = -1;
00589    }
00590 
00591    return ret;
00592 }

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

Definition at line 756 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(), and LOG_WARNING.

Referenced by func_channel_write_real().

00757 {
00758    int res;
00759    ast_chan_write_info_t write_info = {
00760       .version = AST_CHAN_WRITE_INFO_T_VERSION,
00761       .write_fn = func_channel_write_real,
00762       .chan = chan,
00763       .function = function,
00764       .data = data,
00765       .value = value,
00766    };
00767 
00768    if (!chan) {
00769       ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
00770       return -1;
00771    }
00772 
00773    res = func_channel_write_real(chan, function, data, value);
00774    ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
00775 
00776    return res;
00777 }

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

Definition at line 594 of file func_channel.c.

References accountcode, amaflags, 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_tech(), ast_channel_transfercapability_set(), ast_channel_unlock, ast_channel_zone(), ast_channel_zone_set(), ast_datastore_alloc, ast_false(), ast_free, ast_get_group(), ast_get_indication_zone(), ast_get_namedgroups(), ast_log, 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, and ast_secure_call_store::signaling.

Referenced by func_channel_write().

00596 {
00597    int ret = 0;
00598    signed char gainset;
00599 
00600    if (!strcasecmp(data, "language"))
00601       locked_string_field_set(chan, language, value);
00602    else if (!strcasecmp(data, "parkinglot"))
00603       locked_string_field_set(chan, parkinglot, value);
00604    else if (!strcasecmp(data, "musicclass"))
00605       locked_string_field_set(chan, musicclass, value);
00606    else if (!strcasecmp(data, "accountcode"))
00607       locked_string_field_set(chan, accountcode, value);
00608    else if (!strcasecmp(data, "userfield"))
00609       locked_string_field_set(chan, userfield, value);
00610    else if (!strcasecmp(data, "after_bridge_goto")) {
00611       if (ast_strlen_zero(value)) {
00612          ast_bridge_discard_after_goto(chan);
00613       } else {
00614          ast_bridge_set_after_go_on(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), value);
00615       }
00616    } else if (!strcasecmp(data, "amaflags")) {
00617       ast_channel_lock(chan);
00618       if (isdigit(*value)) {
00619          int amaflags;
00620          sscanf(value, "%30d", &amaflags);
00621          ast_channel_amaflags_set(chan, amaflags);
00622       } else if (!strcasecmp(value,"OMIT")){
00623          ast_channel_amaflags_set(chan, 1);
00624       } else if (!strcasecmp(value,"BILLING")){
00625          ast_channel_amaflags_set(chan, 2);
00626       } else if (!strcasecmp(value,"DOCUMENTATION")){
00627          ast_channel_amaflags_set(chan, 3);
00628       }
00629       ast_channel_unlock(chan);
00630    } else if (!strcasecmp(data, "peeraccount"))
00631       locked_string_field_set(chan, peeraccount, value);
00632    else if (!strcasecmp(data, "hangupsource"))
00633       /* XXX - should we be forcing this here? */
00634       ast_set_hangupsource(chan, value, 0);
00635 #ifdef CHANNEL_TRACE
00636    else if (!strcasecmp(data, "trace")) {
00637       ast_channel_lock(chan);
00638       if (ast_true(value))
00639          ret = ast_channel_trace_enable(chan);
00640       else if (ast_false(value))
00641          ret = ast_channel_trace_disable(chan);
00642       else {
00643          ret = -1;
00644          ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).\n");
00645       }
00646       ast_channel_unlock(chan);
00647    }
00648 #endif
00649    else if (!strcasecmp(data, "tonezone")) {
00650       struct ast_tone_zone *new_zone;
00651       if (!(new_zone = ast_get_indication_zone(value))) {
00652          ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
00653          ret = -1;
00654       } else {
00655          ast_channel_lock(chan);
00656          if (ast_channel_zone(chan)) {
00657             ast_channel_zone_set(chan, ast_tone_zone_unref(ast_channel_zone(chan)));
00658          }
00659          ast_channel_zone_set(chan, ast_tone_zone_ref(new_zone));
00660          ast_channel_unlock(chan);
00661          new_zone = ast_tone_zone_unref(new_zone);
00662       }
00663    } else if (!strcasecmp(data, "dtmf_features")) {
00664       ret = ast_bridge_features_ds_set_string(chan, value);
00665    } else if (!strcasecmp(data, "callgroup")) {
00666       ast_channel_lock(chan);
00667       ast_channel_callgroup_set(chan, ast_get_group(value));
00668       ast_channel_unlock(chan);
00669    } else if (!strcasecmp(data, "pickupgroup")) {
00670       ast_channel_lock(chan);
00671       ast_channel_pickupgroup_set(chan, ast_get_group(value));
00672       ast_channel_unlock(chan);
00673    } else if (!strcasecmp(data, "namedcallgroup")) {
00674       struct ast_namedgroups *groups = ast_get_namedgroups(value);
00675 
00676       ast_channel_lock(chan);
00677       ast_channel_named_callgroups_set(chan, groups);
00678       ast_channel_unlock(chan);
00679       ast_unref_namedgroups(groups);
00680    } else if (!strcasecmp(data, "namedpickupgroup")) {
00681       struct ast_namedgroups *groups = ast_get_namedgroups(value);
00682 
00683       ast_channel_lock(chan);
00684       ast_channel_named_pickupgroups_set(chan, groups);
00685       ast_channel_unlock(chan);
00686       ast_unref_namedgroups(groups);
00687    } else if (!strcasecmp(data, "txgain")) {
00688       sscanf(value, "%4hhd", &gainset);
00689       ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
00690    } else if (!strcasecmp(data, "rxgain")) {
00691       sscanf(value, "%4hhd", &gainset);
00692       ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
00693    } else if (!strcasecmp(data, "transfercapability")) {
00694       unsigned short i;
00695 
00696       ast_channel_lock(chan);
00697       for (i = 0; i < 0x20; i++) {
00698          if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
00699             ast_channel_transfercapability_set(chan, i);
00700             break;
00701          }
00702       }
00703       ast_channel_unlock(chan);
00704    } else if (!strcasecmp(data, "hangup_handler_pop")) {
00705       /* Pop one hangup handler before pushing the new handler. */
00706       ast_pbx_hangup_handler_pop(chan);
00707       ast_pbx_hangup_handler_push(chan, value);
00708    } else if (!strcasecmp(data, "hangup_handler_push")) {
00709       ast_pbx_hangup_handler_push(chan, value);
00710    } else if (!strcasecmp(data, "hangup_handler_wipe")) {
00711       /* Pop all hangup handlers before pushing the new handler. */
00712       while (ast_pbx_hangup_handler_pop(chan)) {
00713       }
00714       ast_pbx_hangup_handler_push(chan, value);
00715    } else if (!strncasecmp(data, "secure_bridge_", 14)) {
00716       struct ast_datastore *ds;
00717       struct ast_secure_call_store *store;
00718 
00719       if (!chan || !value) {
00720          return -1;
00721       }
00722 
00723       ast_channel_lock(chan);
00724       if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
00725          if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
00726             ast_channel_unlock(chan);
00727             return -1;
00728          }
00729          if (!(store = ast_calloc(1, sizeof(*store)))) {
00730             ast_channel_unlock(chan);
00731             ast_free(ds);
00732             return -1;
00733          }
00734          ds->data = store;
00735          ast_channel_datastore_add(chan, ds);
00736       } else {
00737          store = ds->data;
00738       }
00739 
00740       if (!strcasecmp(data, "secure_bridge_signaling")) {
00741          store->signaling = ast_true(value) ? 1 : 0;
00742       } else if (!strcasecmp(data, "secure_bridge_media")) {
00743          store->media = ast_true(value) ? 1 : 0;
00744       }
00745       ast_channel_unlock(chan);
00746    } else if (!ast_channel_tech(chan)->func_channel_write
00747        || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
00748       ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
00749             data);
00750       ret = -1;
00751    }
00752 
00753    return ret;
00754 }

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

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

00786 {
00787    struct ast_channel *c = NULL;
00788    regex_t re;
00789    int res;
00790    size_t buflen = 0;
00791    struct ast_channel_iterator *iter;
00792 
00793    buf[0] = '\0';
00794 
00795    if (!ast_strlen_zero(data)) {
00796       if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
00797          regerror(res, &re, buf, maxlen);
00798          ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
00799          return -1;
00800       }
00801    }
00802 
00803    if (!(iter = ast_channel_iterator_all_new())) {
00804       if (!ast_strlen_zero(data)) {
00805          regfree(&re);
00806       }
00807       return -1;
00808    }
00809 
00810    while ((c = ast_channel_iterator_next(iter))) {
00811       ast_channel_lock(c);
00812       if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
00813          size_t namelen = strlen(ast_channel_name(c));
00814          if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
00815             if (!ast_strlen_zero(buf)) {
00816                strcat(buf, " ");
00817                buflen++;
00818             }
00819             strcat(buf, ast_channel_name(c));
00820             buflen += namelen;
00821          } else {
00822             ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space.  Output will be truncated!\n");
00823          }
00824       }
00825       ast_channel_unlock(c);
00826       c = ast_channel_unref(c);
00827    }
00828 
00829    ast_channel_iterator_destroy(iter);
00830 
00831    if (!ast_strlen_zero(data)) {
00832       regfree(&re);
00833    }
00834 
00835    return 0;
00836 }

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 843 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.

00845 {
00846    struct ast_channel *mchan;
00847    char *template = ast_alloca(4 + strlen(data));
00848 
00849    if (!chan) {
00850       ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
00851       return -1;
00852    }
00853 
00854    mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
00855    sprintf(template, "${%s}", data); /* SAFE */
00856    ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
00857    if (mchan) {
00858       ast_channel_unref(mchan);
00859    }
00860    return 0;
00861 }

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

Definition at line 863 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().

00865 {
00866    struct ast_channel *mchan;
00867 
00868    if (!chan) {
00869       ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function);
00870       return -1;
00871    }
00872 
00873    mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
00874    pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
00875    if (mchan) {
00876       ast_channel_unref(mchan);
00877    }
00878    return 0;
00879 }

static int load_module ( void   )  [static]

Definition at line 898 of file func_channel.c.

References ast_custom_function_register.

00899 {
00900    int res = 0;
00901 
00902    res |= ast_custom_function_register(&channel_function);
00903    res |= ast_custom_function_register(&channels_function);
00904    res |= ast_custom_function_register(&mchan_function);
00905 
00906    return res;
00907 }

static int unload_module ( void   )  [static]

Definition at line 887 of file func_channel.c.

References ast_custom_function_unregister().

00888 {
00889    int res = 0;
00890 
00891    res |= ast_custom_function_unregister(&channel_function);
00892    res |= ast_custom_function_unregister(&channels_function);
00893    res |= ast_custom_function_unregister(&mchan_function);
00894 
00895    return res;
00896 }


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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 909 of file func_channel.c.

Definition at line 909 of file func_channel.c.

Initial value:

 {
   .name = "CHANNEL",
   .read = func_channel_read,
   .write = func_channel_write,
}

Definition at line 779 of file func_channel.c.

Initial value:

 {
   .name = "CHANNELS",
   .read = func_channels_read,
}

Definition at line 838 of file func_channel.c.

Initial value:

 {
   .name = "MASTER_CHANNEL",
   .read2 = func_mchan_read,
   .write = func_mchan_write,
}

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


Generated on Thu Apr 16 06:31:13 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6