diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index 2ff472afea..6b685d547d 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -79,6 +79,17 @@ static switch_status_t exec_app(switch_core_session_t *session, const char *app, return status; } + +#define check_tz() tzoff = switch_channel_get_variable(channel, "tod_tz_offset"); \ + do { \ + if (!zstr(tzoff) && switch_is_number(tzoff)) { \ + offset = atoi(tzoff); \ + } else { \ + tzoff = NULL; \ + } \ + break; \ + } while(tzoff) + static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t xexten, switch_caller_extension_t **extension) { switch_xml_t xcond, xaction, xexpression, xregex; @@ -88,13 +99,10 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * char *expression_expanded = NULL, *field_expanded = NULL; switch_regex_t *re = NULL, *save_re = NULL; int offset = 0; - const char *tzoff = switch_channel_get_variable(channel, "tod_tz_offset"); + const char *tzoff; + + check_tz(); - if (!zstr(tzoff) && switch_is_number(tzoff)) { - offset = atoi(tzoff); - } else { - tzoff = NULL; - } if (!exten_name) { exten_name = "_anon_"; @@ -109,8 +117,11 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * int ovector[30]; switch_bool_t anti_action = SWITCH_TRUE; break_t do_break_i = BREAK_ON_FALSE; + int time_match; + + check_tz(); + time_match = switch_xml_std_datetime_check(xcond, tzoff ? &offset : NULL); - int time_match = switch_xml_std_datetime_check(xcond, tzoff ? &offset : NULL); switch_safe_free(field_expanded); switch_safe_free(expression_expanded); @@ -161,8 +172,9 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * switch_channel_del_variable_prefix(channel, "DP_REGEX_MATCH"); for (xregex = switch_xml_child(xcond, "regex"); xregex; xregex = xregex->next) { + check_tz(); time_match = switch_xml_std_datetime_check(xregex, tzoff ? &offset : NULL); - + if (time_match == 1) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG, "Dialplan: %s Date/Time Match (PASS) [%s]\n", diff --git a/src/switch_xml.c b/src/switch_xml.c index ec7eddec0a..237873e15d 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -2899,22 +2899,54 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offse const char *xminday = switch_xml_attr(xcond, "minute-of-day"); const char *xtod = switch_xml_attr(xcond, "time-of-day"); const char *tzoff = switch_xml_attr(xcond, "tz-offset"); - int loffset = 0; + const char *isdst = switch_xml_attr(xcond, "dst"); + int loffset = -1000; + int eoffset = -1000; + int dst = -1000; switch_time_t ts = switch_micro_time_now(); int time_match = -1; - switch_time_exp_t tm; + switch_time_exp_t tm, tm2; + + if (!zstr(isdst)) { + dst = switch_true(isdst); + } if (!zstr(tzoff) && switch_is_number(tzoff)) { loffset = atoi(tzoff); - offset = &loffset; + } + + switch_time_exp_lt(&tm2, ts); + + if (offset) { + eoffset = *offset; + switch_time_exp_tz(&tm, ts, *offset); + } else { + tm = tm2; + } + + if (eoffset == -1000) { + eoffset = tm.tm_gmtoff / 3600; + } + + if (loffset == -1000) { + loffset = eoffset; } - if (offset) { - switch_time_exp_tz(&tm, ts, *offset); - } else { - switch_time_exp_lt(&tm, ts); + if (time_match && tzoff) { + time_match = loffset == eoffset; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, + "XML DateTime Check: TZOFFSET[%d] == %d (%s)\n", eoffset, loffset, time_match ? "PASS" : "FAIL"); + + } + + if (time_match && dst > -1) { + time_match = (tm2.tm_isdst > 0 && dst > 0); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, + "XML DateTime Check: DST[%s] == %s (%s)\n", + tm2.tm_isdst > 0 ? "true" : "false", dst > 0 ? "true" : "false", time_match ? "PASS" : "FAIL"); + } if (time_match && xdt) {