Fri Jul 24 00:41:44 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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static 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 253 of file func_callerid.c.

static void __unreg_module ( void   )  [static]

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

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

Definition at line 122 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_skip_blanks(), ast_strdup, ast_strdupa, ast_trim_blanks(), 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, and num.

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

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 246 of file func_callerid.c.

References ast_custom_function_register, callerid_function, and callerpres_function.

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

static int unload_module ( void   )  [static]

Definition at line 239 of file func_callerid.c.

References ast_custom_function_unregister(), callerid_function, and callerpres_function.

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


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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 253 of file func_callerid.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 253 of file func_callerid.c.

struct ast_custom_function callerid_function [static]

Definition at line 206 of file func_callerid.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function callerpres_function [static]

Definition at line 219 of file func_callerid.c.

Referenced by load_module(), and unload_module().


Generated on Fri Jul 24 00:41:44 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7