diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-02-17 00:09:21 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-02-17 00:09:21 +0000 |
commit | c3f8a7d7207af526939ea872390577a883b96b8d (patch) | |
tree | 9a06e5092da60aed233f5c99ac4b142907db9cdb | |
parent | bac85d924ff7980e5b71e2d80b8aa725ab472ed0 (diff) |
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: http://svn.digium.com/svn/asterisk/branches/1.2@247081 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | funcs/func_strings.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 9ce8b08d2..f40c79550 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(<allowed-chars>|<string>)\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(<allowed-chars>|<string>)", + .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] = ""; |