Tue Aug 24 20:36:04 2010

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"
Include dependency graph for func_callerid.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Caller ID related dialplan functions")
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_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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Caller ID related dialplan functions"   
)
static int callerid_read ( struct ast_channel *  chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 120 of file func_callerid.c.

References ast_callerid_split(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_log(), ast_named_caller_presentation(), 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().

00122 {
00123    char *opt = data;
00124 
00125    /* Ensure that the buffer is empty */
00126    *buf = 0;
00127 
00128    if (!chan)
00129       return -1;
00130 
00131    if (strchr(opt, ',')) {
00132       char name[80], num[80];
00133 
00134       data = strsep(&opt, ",");
00135       ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));
00136 
00137       if (!strncasecmp("all", data, 3)) {
00138          snprintf(buf, len, "\"%s\" <%s>", name, num);
00139       } else if (!strncasecmp("name", data, 4)) {
00140          ast_copy_string(buf, name, len);
00141       } else if (!strncasecmp("num", data, 3)) {
00142          /* also matches "number" */
00143          ast_copy_string(buf, num, len);
00144       } else {
00145          ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00146       }
00147    } else {
00148       ast_channel_lock(chan);
00149 
00150       if (!strncasecmp("all", data, 3)) {
00151          snprintf(buf, len, "\"%s\" <%s>",
00152             S_OR(chan->cid.cid_name, ""),
00153             S_OR(chan->cid.cid_num, ""));
00154       } else if (!strncasecmp("name", data, 4)) {
00155          if (chan->cid.cid_name) {
00156             ast_copy_string(buf, chan->cid.cid_name, len);
00157          }
00158       } else if (!strncasecmp("num", data, 3)) {
00159          /* also matches "number" */
00160          if (chan->cid.cid_num) {
00161             ast_copy_string(buf, chan->cid.cid_num, len);
00162          }
00163       } else if (!strncasecmp("ani", data, 3)) {
00164          if (!strncasecmp(data + 3, "2", 1)) {
00165             snprintf(buf, len, "%d", chan->cid.cid_ani2);
00166          } else if (chan->cid.cid_ani) {
00167             ast_copy_string(buf, chan->cid.cid_ani, len);
00168          }
00169       } else if (!strncasecmp("dnid", data, 4)) {
00170          if (chan->cid.cid_dnid) {
00171             ast_copy_string(buf, chan->cid.cid_dnid, len);
00172          }
00173       } else if (!strncasecmp("rdnis", data, 5)) {
00174          if (chan->cid.cid_rdnis) {
00175             ast_copy_string(buf, chan->cid.cid_rdnis, len);
00176          }
00177       } else if (!strncasecmp("pres", data, 4)) {
00178          ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
00179       } else if (!strncasecmp("ton", data, 3)) {
00180          snprintf(buf, len, "%d", chan->cid.cid_ton);
00181       } else {
00182          ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00183       }
00184 
00185       ast_channel_unlock(chan);
00186    }
00187 
00188    return 0;
00189 }

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

Definition at line 191 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, ast_channel::cid, ast_callerid::cid_ani2, ast_callerid::cid_dnid, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_tns, ast_callerid::cid_ton, LOG_ERROR, name, and num.

00193 {
00194    int valid = 1;
00195    if (!value || !chan)
00196       return -1;
00197 
00198    value = ast_skip_blanks(value);
00199 
00200    if (!strncasecmp("all", data, 3)) {
00201       char name[256];
00202       char num[256];
00203 
00204       ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
00205       ast_set_callerid(chan, num, name, num);
00206       if (chan->cdr) {
00207          ast_cdr_setcid(chan->cdr, chan);
00208       }
00209    } else if (!strncasecmp("name", data, 4)) {
00210       ast_set_callerid(chan, NULL, value, NULL);
00211       if (chan->cdr) {
00212          ast_cdr_setcid(chan->cdr, chan);
00213       }
00214    } else if (!strncasecmp("num", data, 3)) {
00215       /* also matches "number" */
00216       ast_set_callerid(chan, value, NULL, NULL);
00217       if (chan->cdr) {
00218          ast_cdr_setcid(chan->cdr, chan);
00219       }
00220    } else if (!strncasecmp("ani", data, 3)) {
00221       if (!strncasecmp(data + 3, "2", 1)) {
00222          chan->cid.cid_ani2 = atoi(value);
00223       } else {
00224          ast_set_callerid(chan, NULL, NULL, value);
00225       }
00226       if (chan->cdr) {
00227          ast_cdr_setcid(chan->cdr, chan);
00228       }
00229    } else if (!strncasecmp("dnid", data, 4)) {
00230       ast_channel_lock(chan);
00231       if (chan->cid.cid_dnid) {
00232          ast_free(chan->cid.cid_dnid);
00233       }
00234       chan->cid.cid_dnid = ast_strdup(value);
00235       if (chan->cdr) {
00236          ast_cdr_setcid(chan->cdr, chan);
00237       }
00238       ast_channel_unlock(chan);
00239    } else if (!strncasecmp("rdnis", data, 5)) {
00240       ast_channel_lock(chan);
00241       if (chan->cid.cid_rdnis) {
00242          ast_free(chan->cid.cid_rdnis);
00243       }
00244       chan->cid.cid_rdnis = ast_strdup(value);
00245       if (chan->cdr) {
00246          ast_cdr_setcid(chan->cdr, chan);
00247       }
00248       ast_channel_unlock(chan);
00249    } else if (!strncasecmp("pres", data, 4)) {
00250       int i;
00251       char *val;
00252 
00253       val = ast_strdupa(value);
00254       ast_trim_blanks(val);
00255 
00256       if ((val[0] >= '0') && (val[0] <= '9')) {
00257          i = atoi(val);
00258       } else {
00259          i = ast_parse_caller_presentation(val);
00260       }
00261 
00262       if (i < 0) {
00263          ast_log(LOG_ERROR, "Unknown calling number presentation '%s', value unchanged\n", val);
00264       } else {
00265          chan->cid.cid_pres = i;
00266       }
00267    } else if (!strncasecmp("ton", data, 3)) {
00268       chan->cid.cid_ton = atoi(value);
00269    } else {
00270       ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00271       valid = 0;
00272    }
00273 
00274    if (valid) {
00275       chan->cid.cid_tns = 1;
00276    }
00277 
00278    return 0;
00279 }

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

Definition at line 110 of file func_callerid.c.

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

00111 {
00112    int pres = ast_parse_caller_presentation(value);
00113    if (pres < 0)
00114       ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
00115    else
00116       chan->cid.cid_pres = pres;
00117    return 0;
00118 }

static int load_module ( void   )  [static]

Definition at line 300 of file func_callerid.c.

References ast_custom_function_register.

00301 {
00302    int res = ast_custom_function_register(&callerpres_function);
00303    res |= ast_custom_function_register(&callerid_function);
00304    return res;
00305 }

static int unload_module ( void   )  [static]

Definition at line 293 of file func_callerid.c.

References ast_custom_function_unregister().

00294 {
00295    int res = ast_custom_function_unregister(&callerpres_function);
00296    res |= ast_custom_function_unregister(&callerid_function);
00297    return res;
00298 }


Variable Documentation

Initial value:
 {
   .name = "CALLERID",
   .read = callerid_read,
   .write = callerid_write,
}

Definition at line 281 of file func_callerid.c.

Initial value:
 {
   .name = "CALLERPRES",
   .read = callerpres_read,
   .write = callerpres_write,
}

Definition at line 287 of file func_callerid.c.


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