aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
authormogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-02-23 22:59:16 +0000
committermogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-02-23 22:59:16 +0000
commiteaf5d33648cb2db65109220dd917f7e814133bee (patch)
tree174db494fe49878c75871aceb2f56ca708f59e2e /funcs/func_strings.c
parent9e00342852dd3ae1806f2edcc1d2754edfef97ed (diff)
added function QUOTE into strings, which allows
for quoted strings, and escapes them properly. slightly modified patch from bug #6257 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@10934 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_strings.c')
-rw-r--r--funcs/func_strings.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index 26712f8d5..059c1ce21 100644
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -204,6 +204,36 @@ static struct ast_custom_function array_function = {
"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 @@ int unload_module(void)
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 @@ int load_module(void)
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);