Bug 5327 - new function FILTER and optional argument to CALLERID

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7614 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2005-12-23 21:03:25 +00:00
parent 06d1a99163
commit 5323442db4
3 changed files with 83 additions and 26 deletions

View File

@@ -37,7 +37,7 @@ FUNCS+=$(STANDALONE_FUNCS:.o=.so)
FUNC_SOURCES=$(BUILTINS:.o=.c)
FUNC_STRUCTS=$(shell grep 'struct ast_custom_function' $(FUNC_SOURCES) | awk '{print $$3};')
FUNC_STRUCTS=$(shell grep 'struct ast_custom_function' $(FUNC_SOURCES) | awk '{print $$3};' | sort)
ifeq (${OSARCH},CYGWIN)
CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols

View File

@@ -42,6 +42,24 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
char *opt = data;
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) || !strncasecmp("number", data, 6)) {
ast_copy_string(buf, num, len);
} else {
ast_log(LOG_ERROR, "Unknown callerid data type.\n");
}
} else {
if (!strncasecmp("all", data, 3)) {
snprintf(buf, len, "\"%s\" <%s>", chan->cid.cid_name ? chan->cid.cid_name : "", chan->cid.cid_num ? chan->cid.cid_num : "");
} else if (!strncasecmp("name", data, 4)) {
@@ -67,7 +85,7 @@ static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char
} else {
ast_log(LOG_ERROR, "Unknown callerid data type.\n");
}
}
return buf;
}
@@ -108,9 +126,10 @@ static
struct ast_custom_function callerid_function = {
.name = "CALLERID",
.synopsis = "Gets or sets Caller*ID data on the channel.",
.syntax = "CALLERID(datatype)",
.syntax = "CALLERID(datatype[,<optional-CID>])",
.desc = "Gets or sets Caller*ID data on the channel. The allowable datatypes\n"
"are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n",
"are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n"
"Uses channel callerid by default or optional callerid, if specified.\n",
.read = callerid_read,
.write = callerid_write,
};

View File

@@ -68,6 +68,44 @@ struct ast_custom_function fieldqty_function = {
.read = function_fieldqty,
};
static char *builtin_function_filter(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
char *allowed, *string, *outbuf=buf;
string = ast_strdupa(data);
if (!string) {
ast_log(LOG_ERROR, "Out of memory");
return "";
}
allowed = strsep(&string, "|");
if (!string) {
ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n");
return "";
}
for ( ; *string && (buf + len - 1 > outbuf); string++) {
if (strchr(allowed, *string)) {
*outbuf = *string;
outbuf++;
}
}
*outbuf = '\0';
return buf;
}
#ifndef BUILTIN_FUNC
static
#endif
struct ast_custom_function filter_function = {
.name = "FILTER",
.synopsis = "Filter the string to include only the allowed characters",
.syntax = "FILTER(<allowed-chars>,<string>)",
.read = builtin_function_filter,
};
static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
char *arg, *earg = NULL, *tmp, errstr[256] = "";