From e19e560da2cd5e8bbfe03afc6bb360ac764357d1 Mon Sep 17 00:00:00 2001 From: tilghman Date: Fri, 23 Dec 2005 21:03:25 +0000 Subject: Bug 5327 - new function FILTER and optional argument to CALLERID git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7614 f38db490-d61c-443f-a65b-d21fe96a405b --- funcs/func_strings.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'funcs/func_strings.c') diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 91564d9e4..b9c45014e 100644 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -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(,)\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(,)", + .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] = ""; -- cgit v1.2.3