diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 2e53ef6..4ae49bb 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -276,6 +276,7 @@ SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channe SWITCH_DECLARE(uint32_t) switch_channel_del_variable_prefix(switch_channel_t *channel, const char *prefix); SWITCH_DECLARE(switch_status_t) switch_channel_transfer_variable_prefix(switch_channel_t *orig_channel, switch_channel_t *new_channel, const char *prefix); +SWITCH_DECLARE(uint32_t) switch_channel_del_variable_regex(switch_channel_t *channel, const char *pattern); #define switch_channel_set_variable_safe(_channel, _var, _val) switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_FALSE) #define switch_channel_set_variable(_channel, _var, _val) switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_TRUE) diff --git a/src/include/switch_regex.h b/src/include/switch_regex.h index 9317a5f..a265ef7 100644 --- a/src/include/switch_regex.h +++ b/src/include/switch_regex.h @@ -35,12 +35,17 @@ #define SWITCH_REGEX_H SWITCH_BEGIN_EXTERN_C + +/* Keep in sync with pcre.h flags plz :) */ +#define SWITCH_REGEX_FLAG_CASELESS 0x00000001 +#define SWITCH_REGEX_FLAG_DOTALL 0x00000004 + /** * @defgroup switch_regex Regular Expressions * @ingroup FREESWITCH * @{ */ - typedef struct real_pcre switch_regex_t; +typedef struct real_pcre switch_regex_t; SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern, int options, const char **errorptr, int *erroroffset, const unsigned char *tables); diff --git a/src/switch_channel.c b/src/switch_channel.c index ae94061..6c50535 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1314,6 +1314,40 @@ SWITCH_DECLARE(switch_status_t) switch_channel_transfer_variable_prefix(switch_c return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(uint32_t) switch_channel_del_variable_regex(switch_channel_t *channel, const char *pattern) +{ + switch_event_t *event = NULL; + switch_event_header_t *hp = NULL; + switch_regex_t *re = NULL; + const char *error = NULL; + uint32_t r = 0; + int erroffset = 0; + switch_regex_flag_t flags = SWITCH_REGEX_FLAG_CASELESS | SWITCH_REGEX_FLAG_DOTALL; + + re = switch_regex_compile(pattern, flags, &error, &erroffset, NULL); + if (error) { + goto end; + } + switch_channel_get_variables(channel, &event); + + if (event) { + for (hp = event->headers; hp; hp = hp->next) { + if (zstr(prefix) || !strncasecmp(hp->name, prefix, strlen(prefix))) { + switch_channel_set_variable(channel, hp->name, NULL); + } + } + } + + switch_event_destroy(&event); + +end: + + switch_regex_safe_free(re); + + return r; +} + + SWITCH_DECLARE(void) switch_channel_set_presence_data_vals(switch_channel_t *channel, const char *presence_data_cols) { if (!zstr(presence_data_cols)) {