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 = "0901e4e500243c855563a2d78b0c03e4" , .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 211 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 217 of file func_channel.c.
Referenced by func_channel_write().
| static void __reg_module | ( | void | ) | [static] |
Definition at line 417 of file func_channel.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 417 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 230 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, ast_tone_zone::country, ast_channel_tech::func_channel_read, ast_channel::language, locked_copy_string, LOG_WARNING, ast_channel::musicclass, ast_channel::nativeformats, ast_channel::parkinglot, ast_channel::readformat, ast_channel::tech, ast_channel::transfercapability, ast_channel_tech::type, ast_channel::writeformat, and ast_channel::zone.
00232 { 00233 int ret = 0; 00234 00235 if (!strcasecmp(data, "audionativeformat")) 00236 /* use the _multiple version when chan->nativeformats holds multiple formats */ 00237 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */ 00238 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len); 00239 else if (!strcasecmp(data, "videonativeformat")) 00240 /* use the _multiple version when chan->nativeformats holds multiple formats */ 00241 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */ 00242 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len); 00243 else if (!strcasecmp(data, "audioreadformat")) 00244 ast_copy_string(buf, ast_getformatname(chan->readformat), len); 00245 else if (!strcasecmp(data, "audiowriteformat")) 00246 ast_copy_string(buf, ast_getformatname(chan->writeformat), len); 00247 #ifdef CHANNEL_TRACE 00248 else if (!strcasecmp(data, "trace")) { 00249 ast_channel_lock(chan); 00250 ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len); 00251 ast_channel_unlock(chan); 00252 } 00253 #endif 00254 else if (!strcasecmp(data, "tonezone") && chan->zone) 00255 locked_copy_string(chan, buf, chan->zone->country, len); 00256 else if (!strcasecmp(data, "language")) 00257 locked_copy_string(chan, buf, chan->language, len); 00258 else if (!strcasecmp(data, "musicclass")) 00259 locked_copy_string(chan, buf, chan->musicclass, len); 00260 else if (!strcasecmp(data, "parkinglot")) 00261 locked_copy_string(chan, buf, chan->parkinglot, len); 00262 else if (!strcasecmp(data, "state")) 00263 locked_copy_string(chan, buf, ast_state2str(chan->_state), len); 00264 else if (!strcasecmp(data, "channeltype")) 00265 locked_copy_string(chan, buf, chan->tech->type, len); 00266 else if (!strcasecmp(data, "transfercapability")) 00267 locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len); 00268 else if (!strcasecmp(data, "callgroup")) { 00269 char groupbuf[256]; 00270 locked_copy_string(chan, buf, ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len); 00271 } else if (!chan->tech->func_channel_read 00272 || chan->tech->func_channel_read(chan, function, data, buf, len)) { 00273 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data); 00274 ret = -1; 00275 } 00276 00277 return ret; 00278 }
| static int func_channel_write | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 280 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_tone_zone_ref(), ast_tone_zone_unref(), 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.
00282 { 00283 int ret = 0; 00284 signed char gainset; 00285 00286 if (!strcasecmp(data, "language")) 00287 locked_string_field_set(chan, language, value); 00288 else if (!strcasecmp(data, "parkinglot")) 00289 locked_string_field_set(chan, parkinglot, value); 00290 else if (!strcasecmp(data, "musicclass")) 00291 locked_string_field_set(chan, musicclass, value); 00292 #ifdef CHANNEL_TRACE 00293 else if (!strcasecmp(data, "trace")) { 00294 ast_channel_lock(chan); 00295 if (ast_true(value)) 00296 ret = ast_channel_trace_enable(chan); 00297 else if (ast_false(value)) 00298 ret = ast_channel_trace_disable(chan); 00299 else { 00300 ret = -1; 00301 ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace)."); 00302 } 00303 ast_channel_unlock(chan); 00304 } 00305 #endif 00306 else if (!strcasecmp(data, "tonezone")) { 00307 struct ast_tone_zone *new_zone; 00308 if (!(new_zone = ast_get_indication_zone(value))) { 00309 ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value); 00310 ret = -1; 00311 } else { 00312 ast_channel_lock(chan); 00313 if (chan->zone) { 00314 chan->zone = ast_tone_zone_unref(chan->zone); 00315 } 00316 chan->zone = ast_tone_zone_ref(new_zone); 00317 ast_channel_unlock(chan); 00318 new_zone = ast_tone_zone_unref(new_zone); 00319 } 00320 } else if (!strcasecmp(data, "callgroup")) 00321 chan->callgroup = ast_get_group(value); 00322 else if (!strcasecmp(data, "txgain")) { 00323 sscanf(value, "%4hhd", &gainset); 00324 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0); 00325 } else if (!strcasecmp(data, "rxgain")) { 00326 sscanf(value, "%4hhd", &gainset); 00327 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0); 00328 } else if (!strcasecmp(data, "transfercapability")) { 00329 unsigned short i; 00330 for (i = 0; i < 0x20; i++) { 00331 if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) { 00332 chan->transfercapability = i; 00333 break; 00334 } 00335 } 00336 } else if (!chan->tech->func_channel_write 00337 || chan->tech->func_channel_write(chan, function, data, value)) { 00338 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", 00339 data); 00340 ret = -1; 00341 } 00342 00343 return ret; 00344 }
| static int func_channels_read | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | maxlen | |||
| ) | [static] |
Definition at line 352 of file func_channel.c.
References ast_channel_unlock, ast_channel_walk_locked(), ast_log(), ast_strlen_zero(), LOG_WARNING, and ast_channel::name.
00353 { 00354 struct ast_channel *c = NULL; 00355 regex_t re; 00356 int res; 00357 size_t buflen = 0; 00358 00359 buf[0] = '\0'; 00360 00361 if (!ast_strlen_zero(data)) { 00362 if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) { 00363 regerror(res, &re, buf, maxlen); 00364 ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf); 00365 return -1; 00366 } 00367 } 00368 00369 for (c = ast_channel_walk_locked(NULL); c; ast_channel_unlock(c), c = ast_channel_walk_locked(c)) { 00370 if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) { 00371 size_t namelen = strlen(c->name); 00372 if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) { 00373 if (!ast_strlen_zero(buf)) { 00374 strcat(buf, " "); 00375 buflen++; 00376 } 00377 strcat(buf, c->name); 00378 buflen += namelen; 00379 } else { 00380 ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space. Output will be truncated!\n"); 00381 } 00382 } 00383 } 00384 00385 if (!ast_strlen_zero(data)) { 00386 regfree(&re); 00387 } 00388 00389 return 0; 00390 }
| static int load_module | ( | void | ) | [static] |
Definition at line 407 of file func_channel.c.
References ast_custom_function_register.
00408 { 00409 int res = 0; 00410 00411 res |= ast_custom_function_register(&channel_function); 00412 res |= ast_custom_function_register(&channels_function); 00413 00414 return res; 00415 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 397 of file func_channel.c.
References ast_custom_function_unregister().
00398 { 00399 int res = 0; 00400 00401 res |= ast_custom_function_unregister(&channel_function); 00402 res |= ast_custom_function_unregister(&channels_function); 00403 00404 return res; 00405 }
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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 417 of file func_channel.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 417 of file func_channel.c.
struct ast_custom_function channel_function [static] |
{
.name = "CHANNEL",
.read = func_channel_read,
.write = func_channel_write,
}
Definition at line 346 of file func_channel.c.
struct ast_custom_function channels_function [static] |
{
.name = "CHANNELS",
.read = func_channels_read,
}
Definition at line 392 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 224 of file func_channel.c.
1.6.2