Channel info dialplan functions. More...
#include "asterisk.h"#include <regex.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"
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_channels_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen) |
| static int | load_module (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_custom_function | channel_function |
| static struct ast_custom_function | channels_function |
| char * | transfercapability_table [0x20] |
Channel info dialplan functions.
Definition in file func_channel.c.
| #define locked_copy_string | ( | chan, | |||
| dest, | |||||
| source, | |||||
| len | ) |
do { \ ast_channel_lock(chan); \ ast_copy_string(dest, source, len); \ ast_channel_unlock(chan); \ } while (0)
Definition at line 41 of file func_channel.c.
Referenced by func_channel_read().
| #define locked_string_field_set | ( | chan, | |||
| field, | |||||
| source | ) |
do { \ ast_channel_lock(chan); \ ast_string_field_set(chan, field, source); \ ast_channel_unlock(chan); \ } while (0)
Definition at line 47 of file func_channel.c.
Referenced by func_channel_write().
| static void __reg_module | ( | void | ) | [static] |
Definition at line 322 of file func_channel.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 322 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 60 of file func_channel.c.
References ast_channel::_state, ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, ast_getformatname(), ast_log(), ast_print_group(), ast_state2str(), ast_channel::callgroup, tone_zone::country, ast_channel_tech::func_channel_read, locked_copy_string, LOG_WARNING, ast_channel::nativeformats, ast_channel::readformat, ast_channel::tech, ast_channel::transfercapability, ast_channel_tech::type, ast_channel::writeformat, and ast_channel::zone.
00062 { 00063 int ret = 0; 00064 00065 if (!strcasecmp(data, "audionativeformat")) 00066 /* use the _multiple version when chan->nativeformats holds multiple formats */ 00067 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */ 00068 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len); 00069 else if (!strcasecmp(data, "videonativeformat")) 00070 /* use the _multiple version when chan->nativeformats holds multiple formats */ 00071 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */ 00072 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len); 00073 else if (!strcasecmp(data, "audioreadformat")) 00074 ast_copy_string(buf, ast_getformatname(chan->readformat), len); 00075 else if (!strcasecmp(data, "audiowriteformat")) 00076 ast_copy_string(buf, ast_getformatname(chan->writeformat), len); 00077 #ifdef CHANNEL_TRACE 00078 else if (!strcasecmp(data, "trace")) { 00079 ast_channel_lock(chan); 00080 ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len); 00081 ast_channel_unlock(chan); 00082 } 00083 #endif 00084 else if (!strcasecmp(data, "tonezone") && chan->zone) 00085 locked_copy_string(chan, buf, chan->zone->country, len); 00086 else if (!strcasecmp(data, "language")) 00087 locked_copy_string(chan, buf, chan->language, len); 00088 else if (!strcasecmp(data, "musicclass")) 00089 locked_copy_string(chan, buf, chan->musicclass, len); 00090 else if (!strcasecmp(data, "parkinglot")) 00091 locked_copy_string(chan, buf, chan->parkinglot, len); 00092 else if (!strcasecmp(data, "state")) 00093 locked_copy_string(chan, buf, ast_state2str(chan->_state), len); 00094 else if (!strcasecmp(data, "channeltype")) 00095 locked_copy_string(chan, buf, chan->tech->type, len); 00096 else if (!strcasecmp(data, "transfercapability")) 00097 locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len); 00098 else if (!strcasecmp(data, "callgroup")) { 00099 char groupbuf[256]; 00100 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len); 00101 } else if (!chan->tech->func_channel_read 00102 || chan->tech->func_channel_read(chan, function, data, buf, len)) { 00103 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data); 00104 ret = -1; 00105 } 00106 00107 return ret; 00108 }
| static int func_channel_write | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 110 of file func_channel.c.
References ast_channel_lock, ast_channel_setoption(), ast_channel_unlock, ast_false(), ast_get_group(), ast_get_indication_zone(), ast_log(), AST_OPTION_RXGAIN, AST_OPTION_TXGAIN, ast_true(), ast_channel::callgroup, ast_channel_tech::func_channel_write, language, locked_string_field_set, LOG_ERROR, LOG_WARNING, musicclass, parkinglot, ast_channel::tech, ast_channel::transfercapability, and ast_channel::zone.
00112 { 00113 int ret = 0; 00114 signed char gainset; 00115 00116 if (!strcasecmp(data, "language")) 00117 locked_string_field_set(chan, language, value); 00118 else if (!strcasecmp(data, "parkinglot")) 00119 locked_string_field_set(chan, parkinglot, value); 00120 else if (!strcasecmp(data, "musicclass")) 00121 locked_string_field_set(chan, musicclass, value); 00122 #ifdef CHANNEL_TRACE 00123 else if (!strcasecmp(data, "trace")) { 00124 ast_channel_lock(chan); 00125 if (ast_true(value)) 00126 ret = ast_channel_trace_enable(chan); 00127 else if (ast_false(value)) 00128 ret = ast_channel_trace_disable(chan); 00129 else { 00130 ret = -1; 00131 ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace)."); 00132 } 00133 ast_channel_unlock(chan); 00134 } 00135 #endif 00136 else if (!strcasecmp(data, "tonezone")) { 00137 struct tone_zone *new_zone; 00138 if (!(new_zone = ast_get_indication_zone(value))) { 00139 ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value); 00140 ret = -1; 00141 } else 00142 chan->zone = new_zone; 00143 } else if (!strcasecmp(data, "callgroup")) 00144 chan->callgroup = ast_get_group(value); 00145 else if (!strcasecmp(data, "txgain")) { 00146 sscanf(value, "%4hhd", &gainset); 00147 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0); 00148 } else if (!strcasecmp(data, "rxgain")) { 00149 sscanf(value, "%4hhd", &gainset); 00150 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0); 00151 } else if (!strcasecmp(data, "transfercapability")) { 00152 unsigned short i; 00153 for (i = 0; i < 0x20; i++) { 00154 if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) { 00155 chan->transfercapability = i; 00156 break; 00157 } 00158 } 00159 } else if (!chan->tech->func_channel_write 00160 || chan->tech->func_channel_write(chan, function, data, value)) { 00161 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", 00162 data); 00163 ret = -1; 00164 } 00165 00166 return ret; 00167 }
| static int func_channels_read | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | maxlen | |||
| ) | [static] |
Definition at line 250 of file func_channel.c.
References ast_channel_unlock, ast_channel_walk_locked(), ast_log(), ast_strlen_zero(), and LOG_WARNING.
00251 { 00252 struct ast_channel *c = NULL; 00253 regex_t re; 00254 int res; 00255 size_t buflen = 0; 00256 00257 buf[0] = '\0'; 00258 00259 if (!ast_strlen_zero(data)) { 00260 if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) { 00261 regerror(res, &re, buf, maxlen); 00262 ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf); 00263 return -1; 00264 } 00265 } 00266 00267 for (c = ast_channel_walk_locked(NULL); c; ast_channel_unlock(c), c = ast_channel_walk_locked(c)) { 00268 if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) { 00269 size_t namelen = strlen(c->name); 00270 if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) { 00271 if (!ast_strlen_zero(buf)) { 00272 strcat(buf, " "); 00273 buflen++; 00274 } 00275 strcat(buf, c->name); 00276 buflen += namelen; 00277 } else { 00278 ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n"); 00279 } 00280 } 00281 } 00282 00283 if (!ast_strlen_zero(data)) { 00284 regfree(&re); 00285 } 00286 00287 return 0; 00288 }
| static int load_module | ( | void | ) | [static] |
Definition at line 312 of file func_channel.c.
References ast_custom_function_register.
00313 { 00314 int res = 0; 00315 00316 res |= ast_custom_function_register(&channel_function); 00317 res |= ast_custom_function_register(&channels_function); 00318 00319 return res; 00320 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 302 of file func_channel.c.
References ast_custom_function_unregister().
00303 { 00304 int res = 0; 00305 00306 res |= ast_custom_function_unregister(&channel_function); 00307 res |= ast_custom_function_unregister(&channels_function); 00308 00309 return res; 00310 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 322 of file func_channel.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 322 of file func_channel.c.
struct ast_custom_function channel_function [static] |
Definition at line 169 of file func_channel.c.
struct ast_custom_function channels_function [static] |
Definition at line 290 of file func_channel.c.
| char* transfercapability_table[0x20] |
{
"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 54 of file func_channel.c.
1.6.1