FS-8416: Regex feature in param field

This commit is contained in:
Kirill Sysoev 2015-11-05 22:17:54 +03:00
parent 3f3b85596b
commit b9278a8f0d
1 changed files with 19 additions and 0 deletions

View File

@ -365,6 +365,7 @@ switch_status_t mod_xml_radius_add_params(switch_core_session_t *session, switch
char *skip_if_set = (char *) switch_xml_attr(param, "skip_if_set");
char *format = (char *) switch_xml_attr(param, "format");
char *other_leg = (char *) switch_xml_attr(param, "other_leg");
char *regex = (char *) switch_xml_attr(param, "regex");
attribute = rc_dict_findattr(handle, var);
@ -528,6 +529,24 @@ switch_status_t mod_xml_radius_add_params(switch_core_session_t *session, switch
}
}
if ( regex && val ) {
switch_regex_t *re = NULL;
int ovector[30];
int proceed;
char replace[1024] = "";
proceed = 0;
proceed = switch_regex_perform(val, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
if ( proceed > 0 ) {
switch_regex_copy_substring(val, ovector, proceed, proceed - 1, replace, sizeof(replace));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "original value: %s, regex: %s, result: %s\n", val, regex, replace);
val = replace;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "original value: %s, regex: %s, result: nomatch, value left intact\n", val, regex);
}
switch_regex_safe_free(re);
}
if ( val == NULL && val_default != NULL) {
av_value = switch_mprintf(format, val_default);
} else {