Tue Aug 24 20:36:04 2010

Asterisk developer's documentation


func_channel.c File Reference

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"
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

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Channel information dialplan functions")
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_custom_function channel_function
static struct ast_custom_function channels_function
char * 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 212 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_string_field_set(chan, field, source); \
      ast_channel_unlock(chan); \
   } while (0)

Definition at line 218 of file func_channel.c.

Referenced by func_channel_write().


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Channel information dialplan functions"   
)
static int func_channel_read ( struct ast_channel *  chan,
const char *  function,
char *  data,
char *  buf,
size_t  len 
) [static]

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

00233 {
00234    int ret = 0;
00235 
00236    if (!strcasecmp(data, "audionativeformat"))
00237       /* use the _multiple version when chan->nativeformats holds multiple formats */
00238       /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
00239       ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
00240    else if (!strcasecmp(data, "videonativeformat"))
00241       /* use the _multiple version when chan->nativeformats holds multiple formats */
00242       /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
00243       ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
00244    else if (!strcasecmp(data, "audioreadformat"))
00245       ast_copy_string(buf, ast_getformatname(chan->readformat), len);
00246    else if (!strcasecmp(data, "audiowriteformat"))
00247       ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
00248 #ifdef CHANNEL_TRACE
00249    else if (!strcasecmp(data, "trace")) {
00250       ast_channel_lock(chan);
00251       ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
00252       ast_channel_unlock(chan);
00253    }
00254 #endif
00255    else if (!strcasecmp(data, "tonezone") && chan->zone)
00256       locked_copy_string(chan, buf, chan->zone->country, len);
00257    else if (!strcasecmp(data, "language"))
00258       locked_copy_string(chan, buf, chan->language, len);
00259    else if (!strcasecmp(data, "musicclass"))
00260       locked_copy_string(chan, buf, chan->musicclass, len);
00261    else if (!strcasecmp(data, "parkinglot"))
00262       locked_copy_string(chan, buf, chan->parkinglot, len);
00263    else if (!strcasecmp(data, "state"))
00264       locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
00265    else if (!strcasecmp(data, "channeltype"))
00266       locked_copy_string(chan, buf, chan->tech->type, len);
00267    else if (!strcasecmp(data, "transfercapability"))
00268       locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
00269    else if (!strcasecmp(data, "callgroup")) {
00270       char groupbuf[256];
00271       locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
00272    } else if (!chan->tech->func_channel_read
00273        || chan->tech->func_channel_read(chan, function, data, buf, len)) {
00274       ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
00275       ret = -1;
00276    }
00277 
00278    return ret;
00279 }

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

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

00283 {
00284    int ret = 0;
00285    signed char gainset;
00286 
00287    if (!strcasecmp(data, "language"))
00288       locked_string_field_set(chan, language, value);
00289    else if (!strcasecmp(data, "parkinglot"))
00290       locked_string_field_set(chan, parkinglot, value);
00291    else if (!strcasecmp(data, "musicclass"))
00292       locked_string_field_set(chan, musicclass, value);
00293 #ifdef CHANNEL_TRACE
00294    else if (!strcasecmp(data, "trace")) {
00295       ast_channel_lock(chan);
00296       if (ast_true(value)) 
00297          ret = ast_channel_trace_enable(chan);
00298       else if (ast_false(value)) 
00299          ret = ast_channel_trace_disable(chan);
00300       else {
00301          ret = -1;
00302          ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).");
00303       }
00304       ast_channel_unlock(chan);
00305    }
00306 #endif
00307    else if (!strcasecmp(data, "tonezone")) {
00308       struct ast_tone_zone *new_zone;
00309       if (!(new_zone = ast_get_indication_zone(value))) {
00310          ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
00311          ret = -1;   
00312       } else {
00313          ast_channel_lock(chan);
00314          if (chan->zone) {
00315             chan->zone = ast_tone_zone_unref(chan->zone);
00316          }
00317          chan->zone = ast_tone_zone_ref(new_zone);
00318          ast_channel_unlock(chan);
00319          new_zone = ast_tone_zone_unref(new_zone);
00320       }
00321    } else if (!strcasecmp(data, "callgroup"))
00322       chan->callgroup = ast_get_group(value);
00323    else if (!strcasecmp(data, "txgain")) {
00324       sscanf(value, "%4hhd", &gainset);
00325       ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
00326    } else if (!strcasecmp(data, "rxgain")) {
00327       sscanf(value, "%4hhd", &gainset);
00328       ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
00329    } else if (!strcasecmp(data, "transfercapability")) {
00330       unsigned short i;
00331       for (i = 0; i < 0x20; i++) {
00332          if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
00333             chan->transfercapability = i;
00334             break;
00335          }
00336       }
00337    } else if (!chan->tech->func_channel_write
00338        || chan->tech->func_channel_write(chan, function, data, value)) {
00339       ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
00340             data);
00341       ret = -1;
00342    }
00343 
00344    return ret;
00345 }

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

Definition at line 353 of file func_channel.c.

References ast_channel_unlock, ast_channel_walk_locked(), ast_log(), ast_strlen_zero(), and LOG_WARNING.

00354 {
00355    struct ast_channel *c = NULL;
00356    regex_t re;
00357    int res;
00358    size_t buflen = 0;
00359    
00360    buf[0] = '\0';
00361 
00362    if (!ast_strlen_zero(data)) {
00363       if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
00364          regerror(res, &re, buf, maxlen);
00365          ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
00366          return -1;
00367       }
00368    }
00369 
00370    for (c = ast_channel_walk_locked(NULL); c; ast_channel_unlock(c), c = ast_channel_walk_locked(c)) {
00371       if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) {
00372          size_t namelen = strlen(c->name);
00373          if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
00374             if (!ast_strlen_zero(buf)) {
00375                strcat(buf, " ");
00376                buflen++;
00377             }
00378             strcat(buf, c->name);
00379             buflen += namelen;
00380          } else {
00381             ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space.  Output will be truncated!\n");
00382          }
00383       }
00384    }
00385 
00386    if (!ast_strlen_zero(data)) {
00387       regfree(&re);
00388    }
00389 
00390    return 0;
00391 }

static int load_module ( void   )  [static]

Definition at line 408 of file func_channel.c.

References ast_custom_function_register.

00409 {
00410    int res = 0;
00411    
00412    res |= ast_custom_function_register(&channel_function);
00413    res |= ast_custom_function_register(&channels_function);
00414    
00415    return res;
00416 }

static int unload_module ( void   )  [static]

Definition at line 398 of file func_channel.c.

References ast_custom_function_unregister().

00399 {
00400    int res = 0;
00401    
00402    res |= ast_custom_function_unregister(&channel_function);
00403    res |= ast_custom_function_unregister(&channels_function);
00404    
00405    return res;
00406 }


Variable Documentation

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

Definition at line 347 of file func_channel.c.

Initial value:
 {
   .name = "CHANNELS",
   .read = func_channels_read,
}

Definition at line 393 of file func_channel.c.

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


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1