Wed Aug 15 01:25:11 2007

Asterisk developer's documentation


func_callerid.c File Reference

Caller ID related dialplan functions. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/options.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 function")
static int callerid_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int callerid_write (struct ast_channel *chan, 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


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

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

Definition at line 41 of file func_callerid.c.

References ast_callerid_split(), ast_log(), ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_rdnis, LOG_ERROR, name, S_OR, and strsep().

00043 {
00044    char *opt = data;
00045 
00046    if (!chan)
00047       return -1;
00048 
00049    if (strchr(opt, '|')) {
00050       char name[80], num[80];
00051 
00052       data = strsep(&opt, "|");
00053       ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));
00054 
00055       if (!strncasecmp("all", data, 3)) {
00056          snprintf(buf, len, "\"%s\" <%s>", name, num);
00057       } else if (!strncasecmp("name", data, 4)) {
00058          ast_copy_string(buf, name, len);
00059       } else if (!strncasecmp("num", data, 3) ||
00060             !strncasecmp("number", data, 6)) {
00061 
00062          ast_copy_string(buf, num, len);
00063       } else {
00064          ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00065       }
00066    } else {
00067       if (!strncasecmp("all", data, 3)) {
00068          snprintf(buf, len, "\"%s\" <%s>",
00069              S_OR(chan->cid.cid_name, ""),
00070              S_OR(chan->cid.cid_num, ""));
00071       } else if (!strncasecmp("name", data, 4)) {
00072          if (chan->cid.cid_name) {
00073             ast_copy_string(buf, chan->cid.cid_name, len);
00074          }
00075       } else if (!strncasecmp("num", data, 3)
00076                || !strncasecmp("number", data, 6)) {
00077          if (chan->cid.cid_num) {
00078             ast_copy_string(buf, chan->cid.cid_num, len);
00079          }
00080       } else if (!strncasecmp("ani", data, 3)) {
00081          if (chan->cid.cid_ani) {
00082             ast_copy_string(buf, chan->cid.cid_ani, len);
00083          }
00084       } else if (!strncasecmp("dnid", data, 4)) {
00085          if (chan->cid.cid_dnid) {
00086             ast_copy_string(buf, chan->cid.cid_dnid, len);
00087          }
00088       } else if (!strncasecmp("rdnis", data, 5)) {
00089          if (chan->cid.cid_rdnis) {
00090             ast_copy_string(buf, chan->cid.cid_rdnis, len);
00091          }
00092       } else {
00093          ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00094       }
00095    }
00096 
00097    return 0;
00098 }

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

Definition at line 100 of file func_callerid.c.

References ast_callerid_split(), ast_log(), ast_set_callerid(), ast_strdup, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_rdnis, free, LOG_ERROR, and name.

00102 {
00103    if (!value || !chan)
00104       return -1;
00105 
00106    if (!strncasecmp("all", data, 3)) {
00107       char name[256];
00108       char num[256];
00109 
00110       if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
00111          ast_set_callerid(chan, num, name, num);
00112    } else if (!strncasecmp("name", data, 4)) {
00113       ast_set_callerid(chan, NULL, value, NULL);
00114    } else if (!strncasecmp("num", data, 3) ||
00115          !strncasecmp("number", data, 6)) {
00116       ast_set_callerid(chan, value, NULL, NULL);
00117    } else if (!strncasecmp("ani", data, 3)) {
00118       ast_set_callerid(chan, NULL, NULL, value);
00119    } else if (!strncasecmp("dnid", data, 4)) {
00120       /* do we need to lock chan here? */
00121       if (chan->cid.cid_dnid)
00122          free(chan->cid.cid_dnid);
00123       chan->cid.cid_dnid = ast_strdup(value);
00124    } else if (!strncasecmp("rdnis", data, 5)) {
00125       /* do we need to lock chan here? */
00126       if (chan->cid.cid_rdnis)
00127          free(chan->cid.cid_rdnis);
00128       chan->cid.cid_rdnis = ast_strdup(value);
00129    } else {
00130       ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00131    }
00132 
00133    return 0;
00134 }

static int load_module ( void   )  [static]

Definition at line 153 of file func_callerid.c.

References ast_custom_function_register().

00154 {
00155    return ast_custom_function_register(&callerid_function);
00156 }

static int unload_module ( void   )  [static]

Definition at line 148 of file func_callerid.c.

References ast_custom_function_unregister().

00149 {
00150    return ast_custom_function_unregister(&callerid_function);
00151 }


Variable Documentation

struct ast_custom_function callerid_function [static]

Definition at line 136 of file func_callerid.c.


Generated on Wed Aug 15 01:25:11 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3