Index: funcs/func_strings.c =================================================================== --- funcs/func_strings.c (revision 8104) +++ funcs/func_strings.c (working copy) @@ -238,6 +238,38 @@ "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; +} + +#ifndef BUILTIN_FUNC +static +#endif +struct ast_custom_function quote_function = { + .name = "QUOTE", + .synopsis = "Quotes a given string, escaping embedded quotes as necessary", + .syntax = "QUOTE()", + .read = builtin_function_quote, +}; + static char *builtin_function_len(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { int length = 0;