[asterisk-commits] trunk r10934 - /trunk/funcs/func_strings.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Feb 23 15:59:17 MST 2006


Author: mogorman
Date: Thu Feb 23 16:59:16 2006
New Revision: 10934

URL: http://svn.digium.com/view/asterisk?rev=10934&view=rev
Log:
added function QUOTE into strings, which allows
for quoted strings, and escapes them properly.
slightly modified patch from bug #6257

Modified:
    trunk/funcs/func_strings.c

Modified: trunk/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_strings.c?rev=10934&r1=10933&r2=10934&view=diff
==============================================================================
--- trunk/funcs/func_strings.c (original)
+++ trunk/funcs/func_strings.c Thu Feb 23 16:59:16 2006
@@ -203,6 +203,36 @@
 		"Note: remember to either backslash your commas in extensions.conf or quote the\n"
 		"entire argument, since Set can take multiple arguments itself.\n",
 };
+
+static char *builtin_function_quote(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+	char *bufptr = buf, *dataptr = data;
+	*bufptr++ = '"';
+	for (; bufptr < buf + len - 1; dataptr++) {
+		if (*dataptr == '\\') {
+			*bufptr++ = '\\';
+			*bufptr++ = '\\';
+		} else if (*dataptr == '"') {
+			*bufptr++ = '\\';
+			*bufptr++ = '"';
+		} else if (*dataptr == '\0') {
+			break;
+		} else {
+			*bufptr++ = *dataptr;
+		}
+	}
+	*bufptr++ = '"';
+	*bufptr = '\0';
+	return buf;
+}
+
+static struct ast_custom_function quote_function = {
+	.name = "QUOTE",
+	.synopsis = "Quotes a given string, escaping embedded quotes as necessary",
+	.syntax = "QUOTE(<string>)",
+	.read = builtin_function_quote,
+};
+
 
 static int len(struct ast_channel *chan, char *cmd, char *data, char *buf,
 	       size_t len)
@@ -402,6 +432,7 @@
 	res |= ast_custom_function_unregister(&filter_function);
 	res |= ast_custom_function_unregister(&regex_function);
 	res |= ast_custom_function_unregister(&array_function);
+	res |= ast_custom_function_unregister(&quote_function);
 	res |= ast_custom_function_unregister(&len_function);
 	res |= ast_custom_function_unregister(&strftime_function);
 	res |= ast_custom_function_unregister(&strptime_function);
@@ -419,6 +450,7 @@
 	res |= ast_custom_function_register(&filter_function);
 	res |= ast_custom_function_register(&regex_function);
 	res |= ast_custom_function_register(&array_function);
+	res |= ast_custom_function_register(&quote_function);
 	res |= ast_custom_function_register(&len_function);
 	res |= ast_custom_function_register(&strftime_function);
 	res |= ast_custom_function_register(&strptime_function);



More information about the asterisk-commits mailing list