]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
AST-2010-002: Backport FILTER() function to 1.2, as it needed for the suggested solution.
authorTilghman Lesher <tilghman@meg.abyt.es>
Wed, 17 Feb 2010 00:09:21 +0000 (00:09 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Wed, 17 Feb 2010 00:09:21 +0000 (00:09 +0000)
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

funcs/func_strings.c

index 9ce8b08d22b90c81726bfa79ec0008b43c676834..f40c79550ea3e9baa51929c0cbc3d8fe937ff413 100644 (file)
@@ -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] = "";