From: Tilghman Lesher Date: Wed, 17 Feb 2010 00:09:21 +0000 (+0000) Subject: AST-2010-002: Backport FILTER() function to 1.2, as it needed for the suggested solution. X-Git-Tag: 1.2.40~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fc112b07e89984844dc176c8fc5ae480327609e;p=thirdparty%2Fasterisk.git AST-2010-002: Backport FILTER() function to 1.2, as it needed for the suggested solution. Review: http://reviewboard.digium.internal/r/31/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@247081 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 9ce8b08d22..f40c79550e 100644 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -77,6 +77,44 @@ struct ast_custom_function fieldqty_function = { .read = function_fieldqty, }; +static char *filter(struct ast_channel *chan, char *cmd, char *parse, char *buf, size_t len) +{ + char *string, *allowed; + char *outbuf = buf; + + ast_copy_string(buf, "0", len); + + if (!(string = ast_strdupa(parse))) { + return buf; + } + + allowed = strsep(&string, "|"); + + if (!string) { + ast_log(LOG_ERROR, "Usage: FILTER(|)\n"); + return buf; + } + + for (; *string && (buf + len - 1 > outbuf); string++) { + if (strchr(allowed, *string)) { + *outbuf++ = *string; + } + } + *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 = 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] = "";