aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'funcs/func_strings.c')
-rw-r--r--funcs/func_strings.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index 91564d9e4..b9c45014e 100644
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -68,6 +68,44 @@ struct ast_custom_function fieldqty_function = {
.read = function_fieldqty,
};
+static char *builtin_function_filter(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ char *allowed, *string, *outbuf=buf;
+
+ string = ast_strdupa(data);
+ if (!string) {
+ ast_log(LOG_ERROR, "Out of memory");
+ return "";
+ }
+
+ allowed = strsep(&string, "|");
+
+ if (!string) {
+ ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n");
+ return "";
+ }
+
+ for ( ; *string && (buf + len - 1 > outbuf); string++) {
+ if (strchr(allowed, *string)) {
+ *outbuf = *string;
+ outbuf++;
+ }
+ }
+ *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 = builtin_function_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] = "";