static int escape(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { AST_DECLARE_APP_ARGS(args, AST_APP_ARG(escaped); AST_APP_ARG(string); ); AST_STANDARD_APP_ARGS(args, data); if (!args.string) { ast_log(LOG_ERROR, "Usage: ESCAPE(|)\n"); return -1; } char *bufptr = buf; int strlength = strlen(args.string), escplength = strlen(args.escaped), a = 0, b = 0; ast_log(LOG_DEBUG, "Characters to escape: (%s)\n", args.escaped); ast_log(LOG_DEBUG, "String to escape: (%s)\n", args.string); for (a = 0; a < strlength; a++) { for (b = 0; b < escplength; b++) { if ( args.string[a] == args.escaped[b]) { *bufptr++ = '\\'; } } *bufptr++ = args.string[a]; } *bufptr = '\0'; return 0; } static struct ast_custom_function escape_function = { .name = "ESCAPE", .synopsis = "Escapes characters in a given string", .syntax = "ESCAPE(|)", .read = escape, }; res |= ast_custom_function_unregister(&escape_function); res |= ast_custom_function_register(&escape_function);