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 __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Caller ID related dialplan functions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_custom_function | callerid_function |
| static struct ast_custom_function | callerpres_function |
Caller ID related dialplan functions.
Definition in file func_callerid.c.
| static void __reg_module | ( | void | ) | [static] |
Definition at line 307 of file func_callerid.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 307 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 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().
{
char *opt = data;
/* Ensure that the buffer is empty */
*buf = 0;
if (!chan)
return -1;
if (strchr(opt, ',')) {
char name[80], num[80];
data = strsep(&opt, ",");
ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));
if (!strncasecmp("all", data, 3)) {
snprintf(buf, len, "\"%s\" <%s>", name, num);
} else if (!strncasecmp("name", data, 4)) {
ast_copy_string(buf, name, len);
} else if (!strncasecmp("num", data, 3)) {
/* also matches "number" */
ast_copy_string(buf, num, len);
} else {
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
}
} else {
ast_channel_lock(chan);
if (!strncasecmp("all", data, 3)) {
snprintf(buf, len, "\"%s\" <%s>",
S_OR(chan->cid.cid_name, ""),
S_OR(chan->cid.cid_num, ""));
} else if (!strncasecmp("name", data, 4)) {
if (chan->cid.cid_name) {
ast_copy_string(buf, chan->cid.cid_name, len);
}
} else if (!strncasecmp("num", data, 3)) {
/* also matches "number" */
if (chan->cid.cid_num) {
ast_copy_string(buf, chan->cid.cid_num, len);
}
} else if (!strncasecmp("ani", data, 3)) {
if (!strncasecmp(data + 3, "2", 1)) {
snprintf(buf, len, "%d", chan->cid.cid_ani2);
} else if (chan->cid.cid_ani) {
ast_copy_string(buf, chan->cid.cid_ani, len);
}
} else if (!strncasecmp("dnid", data, 4)) {
if (chan->cid.cid_dnid) {
ast_copy_string(buf, chan->cid.cid_dnid, len);
}
} else if (!strncasecmp("rdnis", data, 5)) {
if (chan->cid.cid_rdnis) {
ast_copy_string(buf, chan->cid.cid_rdnis, len);
}
} else if (!strncasecmp("pres", data, 4)) {
ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
} else if (!strncasecmp("ton", data, 3)) {
snprintf(buf, len, "%d", chan->cid.cid_ton);
} else {
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
}
ast_channel_unlock(chan);
}
return 0;
}
| 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, num, and val.
{
int valid = 1;
if (!value || !chan)
return -1;
value = ast_skip_blanks(value);
if (!strncasecmp("all", data, 3)) {
char name[256];
char num[256];
ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
ast_set_callerid(chan, num, name, num);
if (chan->cdr) {
ast_cdr_setcid(chan->cdr, chan);
}
} else if (!strncasecmp("name", data, 4)) {
ast_set_callerid(chan, NULL, value, NULL);
if (chan->cdr) {
ast_cdr_setcid(chan->cdr, chan);
}
} else if (!strncasecmp("num", data, 3)) {
/* also matches "number" */
ast_set_callerid(chan, value, NULL, NULL);
if (chan->cdr) {
ast_cdr_setcid(chan->cdr, chan);
}
} else if (!strncasecmp("ani", data, 3)) {
if (!strncasecmp(data + 3, "2", 1)) {
chan->cid.cid_ani2 = atoi(value);
} else {
ast_set_callerid(chan, NULL, NULL, value);
}
if (chan->cdr) {
ast_cdr_setcid(chan->cdr, chan);
}
} else if (!strncasecmp("dnid", data, 4)) {
ast_channel_lock(chan);
if (chan->cid.cid_dnid) {
ast_free(chan->cid.cid_dnid);
}
chan->cid.cid_dnid = ast_strdup(value);
if (chan->cdr) {
ast_cdr_setcid(chan->cdr, chan);
}
ast_channel_unlock(chan);
} else if (!strncasecmp("rdnis", data, 5)) {
ast_channel_lock(chan);
if (chan->cid.cid_rdnis) {
ast_free(chan->cid.cid_rdnis);
}
chan->cid.cid_rdnis = ast_strdup(value);
if (chan->cdr) {
ast_cdr_setcid(chan->cdr, chan);
}
ast_channel_unlock(chan);
} else if (!strncasecmp("pres", data, 4)) {
int i;
char *val;
val = ast_strdupa(value);
ast_trim_blanks(val);
if ((val[0] >= '0') && (val[0] <= '9')) {
i = atoi(val);
} else {
i = ast_parse_caller_presentation(val);
}
if (i < 0) {
ast_log(LOG_ERROR, "Unknown calling number presentation '%s', value unchanged\n", val);
} else {
chan->cid.cid_pres = i;
}
} else if (!strncasecmp("ton", data, 3)) {
chan->cid.cid_ton = atoi(value);
} else {
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
valid = 0;
}
if (valid) {
chan->cid.cid_tns = 1;
}
return 0;
}
| static int callerpres_read | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
Definition at line 104 of file func_callerid.c.
References ast_copy_string(), ast_named_caller_presentation(), ast_channel::cid, and ast_callerid::cid_pres.
{
ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
return 0;
}
| 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.
{
int pres = ast_parse_caller_presentation(value);
if (pres < 0)
ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
else
chan->cid.cid_pres = pres;
return 0;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 300 of file func_callerid.c.
References ast_custom_function_register.
{
int res = ast_custom_function_register(&callerpres_function);
res |= ast_custom_function_register(&callerid_function);
return res;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 293 of file func_callerid.c.
References ast_custom_function_unregister().
{
int res = ast_custom_function_unregister(&callerpres_function);
res |= ast_custom_function_unregister(&callerid_function);
return res;
}
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Caller ID related dialplan functions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 307 of file func_callerid.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 307 of file func_callerid.c.
struct ast_custom_function callerid_function [static] |
{
.name = "CALLERID",
.read = callerid_read,
.write = callerid_write,
}
Definition at line 281 of file func_callerid.c.
struct ast_custom_function callerpres_function [static] |
{
.name = "CALLERPRES",
.read = callerpres_read,
.write = callerpres_write,
}
Definition at line 287 of file func_callerid.c.