aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-23 21:03:25 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-23 21:03:25 +0000
commite19e560da2cd5e8bbfe03afc6bb360ac764357d1 (patch)
tree71826c3f0b0f64d2e17e9080575c05ce0d211bc6 /funcs/func_strings.c
parent9b9d26173e3c9287114bb8d8866b2628b600b9dc (diff)
Bug 5327 - new function FILTER and optional argument to CALLERID
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7614 f38db490-d61c-443f-a65b-d21fe96a405b
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] = "";