mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-15 05:08:26 +00:00
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
This commit is contained in:
parent
7d6d4d3693
commit
8d720d5bcc
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <switch_channel.h>
|
#include <switch_channel.h>
|
||||||
|
#include <pcre.h>
|
||||||
|
|
||||||
struct switch_cause_table {
|
struct switch_cause_table {
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -4277,7 +4277,47 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (x) {
|
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 {
|
} else {
|
||||||
switch_channel_set_variable(channel, "digits_dialed", "none");
|
switch_channel_set_variable(channel, "digits_dialed", "none");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user