[asterisk-commits] tilghman: branch 1.2 r247081 - /branches/1.2/funcs/func_strings.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 16 18:09:26 CST 2010


Author: tilghman
Date: Tue Feb 16 18:09:21 2010
New Revision: 247081

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247081
Log:
AST-2010-002: Backport FILTER() function to 1.2, as it needed for the suggested solution.

Review: http://reviewboard.digium.internal/r/31/

Modified:
    branches/1.2/funcs/func_strings.c

Modified: branches/1.2/funcs/func_strings.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.2/funcs/func_strings.c?view=diff&rev=247081&r1=247080&r2=247081
==============================================================================
--- branches/1.2/funcs/func_strings.c (original)
+++ branches/1.2/funcs/func_strings.c Tue Feb 16 18:09:21 2010
@@ -77,6 +77,44 @@
 	.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] = "";




More information about the asterisk-commits mailing list