Thu Jul 9 13:41:19 2009

Asterisk developer's documentation


func_callerid.c File Reference

Caller ID related dialplan functions. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/callerid.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int callerid_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int callerid_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
static int callerpres_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int callerpres_write (struct ast_channel *chan, const char *cmd, 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_DEFAULT , .description = "Caller ID related 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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, }
static const struct ast_module_infoast_module_info = &__mod_info
static struct ast_custom_function callerid_function
static struct ast_custom_function callerpres_function


Detailed Description

Caller ID related dialplan functions.

Definition in file func_callerid.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 254 of file func_callerid.c.

static void __unreg_module ( void   )  [static]

Definition at line 254 of file func_callerid.c.

static int callerid_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 51 of file func_callerid.c.

References ast_callerid_split(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_log(), ast_named_caller_presentation(), chan, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_ani2, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_ton, LOG_ERROR, name, num, S_OR, and strsep().

00053 {
00054    char *opt = data;
00055 
00056    if (!chan)
00057       return -1;
00058 
00059    if (strchr(opt, ',')) {
00060       char name[80], num[80];
00061 
00062       data = strsep(&opt, ",");
00063       ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));
00064 
00065       if (!strncasecmp("all", data, 3)) {
00066          snprintf(buf, len, "\"%s\" <%s>", name, num);
00067       } else if (!strncasecmp("name", data, 4)) {
00068          ast_copy_string(buf, name, len);
00069       } else if (!strncasecmp("num", data, 3)) {
00070          /* also matches "number" */
00071          ast_copy_string(buf, num, len);
00072       } else {
00073          ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00074       }
00075    } else {
00076       ast_channel_lock(chan);
00077 
00078       if (!strncasecmp("all", data, 3)) {
00079          snprintf(buf, len, "\"%s\" <%s>",
00080              S_OR(chan->cid.cid_name, ""),
00081              S_OR(chan->cid.cid_num, ""));
00082       } else if (!strncasecmp("name", data, 4)) {
00083          if (chan->cid.cid_name) {
00084             ast_copy_string(buf, chan->cid.cid_name, len);
00085          }
00086       } else if (!strncasecmp("num", data, 3)) {
00087          /* also matches "number" */
00088          if (chan->cid.cid_num) {
00089             ast_copy_string(buf, chan->cid.cid_num, len);
00090          }
00091       } else if (!strncasecmp("ani", data, 3)) {
00092          if (!strncasecmp(data + 3, "2", 1)) {
00093             snprintf(buf, len, "%d", chan->cid.cid_ani2);
00094          } else if (chan->cid.cid_ani) {
00095             ast_copy_string(buf, chan->cid.cid_ani, len);
00096          }
00097       } else if (!strncasecmp("dnid", data, 4)) {
00098          if (chan->cid.cid_dnid) {
00099             ast_copy_string(buf, chan->cid.cid_dnid, len);
00100          }
00101       } else if (!strncasecmp("rdnis", data, 5)) {
00102          if (chan->cid.cid_rdnis) {
00103             ast_copy_string(buf, chan->cid.cid_rdnis, len);
00104          }
00105       } else if (!strncasecmp("pres", data, 4)) {
00106          ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
00107       } else if (!strncasecmp("ton", data, 3)) {
00108          snprintf(buf, len, "%d", chan->cid.cid_ton);
00109       } else {
00110          ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00111       }
00112 
00113       ast_channel_unlock(chan);
00114    }
00115 
00116    return 0;
00117 }

static int callerid_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 119 of file func_callerid.c.

References ast_callerid_split(), ast_cdr_setcid(), ast_channel_lock, ast_channel_unlock, ast_free, ast_log(), ast_parse_caller_presentation(), ast_set_callerid(), ast_strdup, ast_strdupa, ast_channel::cdr, chan, ast_channel::cid, ast_callerid::cid_ani2, ast_callerid::cid_dnid, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_ton, LOG_ERROR, name, num, and s.

00121 {
00122    if (!value || !chan)
00123       return -1;
00124 
00125    if (!strncasecmp("all", data, 3)) {
00126       char name[256];
00127       char num[256];
00128 
00129       ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
00130       ast_set_callerid(chan, num, name, num);
00131       if (chan->cdr) {
00132          ast_cdr_setcid(chan->cdr, chan);
00133       }
00134    } else if (!strncasecmp("name", data, 4)) {
00135       ast_set_callerid(chan, NULL, value, NULL);
00136       if (chan->cdr) {
00137          ast_cdr_setcid(chan->cdr, chan);
00138       }
00139    } else if (!strncasecmp("num", data, 3)) {
00140       /* also matches "number" */
00141       ast_set_callerid(chan, value, NULL, NULL);
00142       if (chan->cdr) {
00143          ast_cdr_setcid(chan->cdr, chan);
00144       }
00145    } else if (!strncasecmp("ani", data, 3)) {
00146       if (!strncasecmp(data + 3, "2", 1)) {
00147          int i = atoi(value);
00148          chan->cid.cid_ani2 = i;
00149       } else
00150          ast_set_callerid(chan, NULL, NULL, value);
00151       if (chan->cdr) {
00152          ast_cdr_setcid(chan->cdr, chan);
00153       }
00154    } else if (!strncasecmp("dnid", data, 4)) {
00155       ast_channel_lock(chan);
00156       if (chan->cid.cid_dnid)
00157          ast_free(chan->cid.cid_dnid);
00158       chan->cid.cid_dnid = ast_strdup(value);
00159       if (chan->cdr) {
00160          ast_cdr_setcid(chan->cdr, chan);
00161       }
00162       ast_channel_unlock(chan);
00163    } else if (!strncasecmp("rdnis", data, 5)) {
00164       ast_channel_lock(chan);
00165       if (chan->cid.cid_rdnis)
00166          ast_free(chan->cid.cid_rdnis);
00167       chan->cid.cid_rdnis = ast_strdup(value);
00168       if (chan->cdr) {
00169          ast_cdr_setcid(chan->cdr, chan);
00170       }
00171       ast_channel_unlock(chan);
00172    } else if (!strncasecmp("pres", data, 4)) {
00173       int i;
00174       char *s, *val;
00175 
00176       /* Strip leading spaces */
00177       while ((value[0] == '\t') || (value[0] == ' '))
00178          ++value;
00179 
00180       val = ast_strdupa(value);
00181 
00182       /* Strip trailing spaces */
00183       s = val + strlen(val);
00184       while ((s != val) && ((s[-1] == '\t') || (s[-1] == ' ')))
00185          --s;
00186       *s = '\0';
00187 
00188       if ((val[0] >= '0') && (val[0] <= '9'))
00189          i = atoi(val);
00190       else
00191          i = ast_parse_caller_presentation(val);
00192 
00193       if (i < 0)
00194          ast_log(LOG_ERROR, "Unknown calling number presentation '%s', value unchanged\n", val);
00195       else
00196          chan->cid.cid_pres = i;
00197    } else if (!strncasecmp("ton", data, 3)) {
00198       int i = atoi(value);
00199       chan->cid.cid_ton = i;
00200    } else {
00201       ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00202    }
00203 
00204    return 0;
00205 }

static int callerpres_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 35 of file func_callerid.c.

References ast_copy_string(), ast_named_caller_presentation(), chan, ast_channel::cid, and ast_callerid::cid_pres.

00036 {
00037    ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
00038    return 0;
00039 }

static int callerpres_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 41 of file func_callerid.c.

References ast_log(), ast_parse_caller_presentation(), chan, ast_channel::cid, ast_callerid::cid_pres, and LOG_WARNING.

00042 {
00043    int pres = ast_parse_caller_presentation(value);
00044    if (pres < 0)
00045       ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
00046    else
00047       chan->cid.cid_pres = pres;
00048    return 0;
00049 }

static int load_module ( void   )  [static]

Definition at line 247 of file func_callerid.c.

References ast_custom_function_register, callerid_function, and callerpres_function.

00248 {
00249    int res = ast_custom_function_register(&callerpres_function);
00250    res |= ast_custom_function_register(&callerid_function);
00251    return res;
00252 }

static int unload_module ( void   )  [static]

Definition at line 240 of file func_callerid.c.

References ast_custom_function_unregister(), callerid_function, and callerpres_function.

00241 {
00242    int res = ast_custom_function_unregister(&callerpres_function);
00243    res |= ast_custom_function_unregister(&callerid_function);
00244    return res;
00245 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Caller ID related 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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static]

Definition at line 254 of file func_callerid.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 254 of file func_callerid.c.

struct ast_custom_function callerid_function [static]

Definition at line 207 of file func_callerid.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function callerpres_function [static]

Definition at line 220 of file func_callerid.c.

Referenced by load_module(), and unload_module().


Generated on Thu Jul 9 13:41:19 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7