Mon Mar 31 07:40:50 2008

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

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

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

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

Definition at line 105 of file func_callerid.c.

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

00107 {
00108    if (!value || !chan)
00109       return -1;
00110 
00111    if (!strncasecmp("all", data, 3)) {
00112       char name[256];
00113       char num[256];
00114 
00115       if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
00116          ast_set_callerid(chan, num, name, num);
00117    } else if (!strncasecmp("name", data, 4)) {
00118       ast_set_callerid(chan, NULL, value, NULL);
00119    } else if (!strncasecmp("num", data, 3) ||
00120          !strncasecmp("number", data, 6)) {
00121       ast_set_callerid(chan, value, NULL, NULL);
00122    } else if (!strncasecmp("ani", data, 3)) {
00123       ast_set_callerid(chan, NULL, NULL, value);
00124    } else if (!strncasecmp("dnid", data, 4)) {
00125       ast_channel_lock(chan);
00126       if (chan->cid.cid_dnid)
00127          free(chan->cid.cid_dnid);
00128       chan->cid.cid_dnid = ast_strdup(value);
00129       ast_channel_unlock(chan);
00130    } else if (!strncasecmp("rdnis", data, 5)) {
00131       ast_channel_lock(chan);
00132       if (chan->cid.cid_rdnis)
00133          free(chan->cid.cid_rdnis);
00134       chan->cid.cid_rdnis = ast_strdup(value);
00135       ast_channel_unlock(chan);
00136    } else {
00137       ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00138    }
00139 
00140    return 0;
00141 }

static int load_module ( void   )  [static]

Definition at line 160 of file func_callerid.c.

References ast_custom_function_register(), and callerid_function.

00161 {
00162    return ast_custom_function_register(&callerid_function);
00163 }

static int unload_module ( void   )  [static]

Definition at line 155 of file func_callerid.c.

References ast_custom_function_unregister(), and callerid_function.

00156 {
00157    return ast_custom_function_unregister(&callerid_function);
00158 }


Variable Documentation

struct ast_custom_function callerid_function [static]

Definition at line 143 of file func_callerid.c.

Referenced by load_module(), and unload_module().


Generated on Mon Mar 31 07:40:50 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.1