From 65a756643a45a9462270a83238a396d742b7103f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 7 Nov 2011 14:31:25 -0600 Subject: [PATCH] add tod_tz_offset variable to set to the integer value of the tz offset or the tz-offset tag on a per-tag basis --- src/include/switch_xml.h | 2 +- src/mod/applications/mod_sms/mod_sms.c | 2 +- .../mod_dialplan_xml/mod_dialplan_xml.c | 12 ++++++++++-- src/switch_xml.c | 17 +++++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index 6961b2da23..0d436fac2f 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -421,7 +421,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function_ptr(_In_ switc ///\return the section mask SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(_In_opt_z_ const char *str); -SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond); +SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offset); SWITCH_DECLARE(switch_status_t) switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language); diff --git a/src/mod/applications/mod_sms/mod_sms.c b/src/mod/applications/mod_sms/mod_sms.c index 50778da81f..e3e3f49578 100644 --- a/src/mod/applications/mod_sms/mod_sms.c +++ b/src/mod/applications/mod_sms/mod_sms.c @@ -81,7 +81,7 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_ switch_bool_t anti_action = SWITCH_TRUE; break_t do_break_i = BREAK_ON_FALSE; - int time_match = switch_xml_std_datetime_check(xcond); + int time_match = switch_xml_std_datetime_check(xcond, NULL); switch_safe_free(field_expanded); switch_safe_free(expression_expanded); 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 b2fb858e31..45a736facf 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -87,6 +87,14 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * int proceed = 0, save_proceed = 0; 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"); + + if (!zstr(tzoff) && switch_is_number(tzoff)) { + offset = atoi(tzoff); + } else { + tzoff = NULL; + } if (!exten_name) { exten_name = "_anon_"; @@ -102,7 +110,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * switch_bool_t anti_action = SWITCH_TRUE; break_t do_break_i = BREAK_ON_FALSE; - int time_match = switch_xml_std_datetime_check(xcond); + int time_match = switch_xml_std_datetime_check(xcond, tzoff ? &offset : NULL); switch_safe_free(field_expanded); switch_safe_free(expression_expanded); @@ -152,7 +160,7 @@ 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) { - time_match = switch_xml_std_datetime_check(xregex); + 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, diff --git a/src/switch_xml.c b/src/switch_xml.c index d4d7c3f12d..7790c17612 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -2783,7 +2783,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_cut(switch_xml_t xml) return xml; } -SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) { +SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offset) +{ const char *xdt = switch_xml_attr(xcond, "date-time"); const char *xyear = switch_xml_attr(xcond, "year"); @@ -2797,12 +2798,24 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) { const char *xminute = switch_xml_attr(xcond, "minute"); 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; switch_time_t ts = switch_micro_time_now(); int time_match = -1; switch_time_exp_t tm; - switch_time_exp_lt(&tm, ts); + if (!zstr(tzoff) && switch_is_number(tzoff)) { + loffset = atoi(tzoff); + offset = &loffset; + } + + + if (offset) { + switch_time_exp_tz(&tm, ts, *offset); + } else { + switch_time_exp_lt(&tm, ts); + } if (time_match && xdt) { char tmpdate[80];