FS-3655 add xor to regex attr
This commit is contained in:
parent
032155c51e
commit
7c7b006873
|
@ -144,8 +144,10 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
|
||||||
|
|
||||||
if ((regex_rule = (char *) switch_xml_attr(xcond, "regex"))) {
|
if ((regex_rule = (char *) switch_xml_attr(xcond, "regex"))) {
|
||||||
int all = !strcasecmp(regex_rule, "all");
|
int all = !strcasecmp(regex_rule, "all");
|
||||||
|
int xor = !strcasecmp(regex_rule, "xor");
|
||||||
int pass = 0;
|
int pass = 0;
|
||||||
int fail = 0;
|
int fail = 0;
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
for (xregex = switch_xml_child(xcond, "regex"); xregex; xregex = xregex->next) {
|
for (xregex = switch_xml_child(xcond, "regex"); xregex; xregex = xregex->next) {
|
||||||
time_match = switch_xml_std_datetime_check(xregex);
|
time_match = switch_xml_std_datetime_check(xregex);
|
||||||
|
@ -174,6 +176,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
|
||||||
expression = expression_expanded;
|
expression = expression_expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
total++;
|
||||||
|
|
||||||
field = (char *) switch_xml_attr(xregex, "field");
|
field = (char *) switch_xml_attr(xregex, "field");
|
||||||
|
|
||||||
|
@ -197,19 +200,22 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
|
||||||
"Dialplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ match=%s\n",
|
"Dialplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ match=%s\n",
|
||||||
switch_channel_get_name(channel), exten_name, field, field_data, expression, all ? "all" : "any");
|
switch_channel_get_name(channel), exten_name, field, field_data, expression, all ? "all" : "any");
|
||||||
pass++;
|
pass++;
|
||||||
if (!all) break;
|
if (!all && !xor) break;
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
|
||||||
"Dialplan: %s Regex (FAIL) [%s] %s(%s) =~ /%s/ match=%s\n",
|
"Dialplan: %s Regex (FAIL) [%s] %s(%s) =~ /%s/ match=%s\n",
|
||||||
switch_channel_get_name(channel), exten_name, field, field_data, expression, all ? "all" : "any");
|
switch_channel_get_name(channel), exten_name, field, field_data, expression, all ? "all" : "any");
|
||||||
fail++;
|
fail++;
|
||||||
if (all) break;
|
if (all && !xor) break;
|
||||||
}
|
}
|
||||||
} else if (time_match == -1) {
|
} else if (time_match == -1) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
|
||||||
"Dialplan: %s Absolute Condition [%s] match=%s\n", switch_channel_get_name(channel), exten_name, all ? "all" : "any");
|
"Dialplan: %s Absolute Condition [%s] match=%s\n", switch_channel_get_name(channel), exten_name, all ? "all" : "any");
|
||||||
pass++;
|
pass++;
|
||||||
if (!all) break;
|
if (!all && !xor) break;
|
||||||
|
} else if (time_match == 1) {
|
||||||
|
pass++;
|
||||||
|
if (!all && !xor) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field && strchr(expression, '(')) {
|
if (field && strchr(expression, '(')) {
|
||||||
|
@ -234,9 +240,15 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (xor) {
|
||||||
|
if (pass == 1) {
|
||||||
|
anti_action = SWITCH_FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if ((all && !fail) || (!all && pass)) {
|
if ((all && !fail) || (!all && pass)) {
|
||||||
anti_action = SWITCH_FALSE;
|
anti_action = SWITCH_FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch_safe_free(field_expanded);
|
switch_safe_free(field_expanded);
|
||||||
switch_safe_free(expression_expanded);
|
switch_safe_free(expression_expanded);
|
||||||
|
|
Loading…
Reference in New Issue