From 8d720d5bcc7a5d6ee006ccb91757b41ea5201f19 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Oct 2014 12:47:27 -0500 Subject: [PATCH] FS-6940 #resolve #comment %FEATURE use the variable digits_dialed_filter to set regular expressions with () captures and anything matched will be replaced with X's in the CDR --- src/switch_channel.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index 49aa4e1923..7fae7f16a2 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -33,7 +33,7 @@ #include #include - +#include struct switch_cause_table { const char *name; @@ -4277,7 +4277,47 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t * } if (x) { - switch_channel_set_variable(channel, "digits_dialed", dtstr); + const char *var = switch_channel_get_variable(channel, "digits_dialed_filter"); + char *digit_string = dtstr; + char *X = NULL; + switch_regex_t *re = NULL; + char *substituted = NULL; + + if (!zstr(var)) { + int proceed = 0; + int ovector[30]; + + if ((proceed = switch_regex_perform(dtstr, var, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { + int len = (strlen(dtstr) + strlen(var) + 10) * proceed; + int i = 0; + const char *replace = NULL; + + X = malloc(len); + + for (i = 0; i < proceed; i++) { + if (pcre_get_substring(dtstr, ovector, proceed, i, &replace) > 0) { + switch_size_t plen = strlen(replace); + memset(X, 'X', plen); + *(X+plen) = '\0'; + + switch_safe_free(substituted); + substituted = switch_string_replace(substituted ? substituted : dtstr, replace, X); + + printf("WTF [%s][%s]\n", replace, substituted); + pcre_free_substring(replace); + } + } + + if (!zstr(substituted)) { + digit_string = substituted; + } + } + } + + switch_channel_set_variable(channel, "digits_dialed", digit_string); + switch_regex_safe_free(re); + switch_safe_free(substituted); + switch_safe_free(X); } else { switch_channel_set_variable(channel, "digits_dialed", "none"); }