]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
switch_utils: Add time of day string compare function switch_tod_cmp. It usable...
authorMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 17 Sep 2010 04:07:30 +0000 (00:07 -0400)
committerMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 17 Sep 2010 04:07:30 +0000 (00:07 -0400)
src/include/switch_utils.h
src/switch_utils.c
src/switch_xml.c

index f24cee5e9fccbbfd166f5dcf8a5e656e976df813..4eac906f59e592053a13746eb2a2c428fa62b697 100644 (file)
@@ -681,6 +681,7 @@ SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip_token(switch_netwo
 SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst);
 
 SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val);
+SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val);
 
 /*!
   \brief Split a user@domain string as user and domain
index 91b78f7bbbc68dde615dc0b0425a755476136e8d..cb4679d53ad9c421e553f9f2e694d9835de11317 100644 (file)
@@ -2375,6 +2375,49 @@ SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
 
 }
 
+SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val)
+{
+       char *dup = strdup(exp);
+       char *minh;
+       char *minm;
+       char *mins;
+       char *maxh;
+       char *maxm;
+       char *maxs;
+
+       switch_assert(dup);
+
+       minh = dup;
+       if ((minm=strchr(dup, ':'))) {
+               *minm++ = '\0';
+               if ((maxh=strchr(minm, '-'))) {
+                       if ((maxm=strchr(maxh, ':'))) {
+                               *maxh++ = '\0';
+                               *maxm++ = '\0';
+                               /* Check if min/max seconds are present */
+                               if ((mins=strchr(minm, ':'))) {
+                                       *mins++ = '\0';
+                               } else {
+                                       mins = "00";
+                               }
+                               if ((maxs=strchr(maxm, ':'))) {
+                                       *maxs++ = '\0';
+                               } else {
+                                       maxs = "00";
+                               }
+
+                               if (val >= (atol(minh) * 60 * 60) + (atol(minm) * 60) + atol(mins) && val < (atol(maxh) * 60 * 60) + (atol(maxm) * 60) + atol(maxs)) {
+                                       switch_safe_free(dup);
+                                       return 1;
+                               }
+                       }
+               }
+       }
+       switch_safe_free(dup);
+       return 0;
+
+}
+
 SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domain)
 {
        char *p = NULL, *h = NULL, *u = in;
index 688978907f19f1d959a8df7a8a92e3b023cffaa5..77c3a5e20e539cc852717571e607bb8e3b97f89b 100644 (file)
@@ -2662,6 +2662,7 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) {
        const char *xhour = switch_xml_attr(xcond, "hour");
        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");
 
        switch_time_t ts = switch_micro_time_now();
        int time_match = -1;
@@ -2747,6 +2748,15 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) {
                                "XML DateTime Check: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ? "PASS" : "FAIL");
        }
 
+       if (time_match && xtod) {
+               int test = (tm.tm_hour * 60 * 60) + (tm.tm_min * 60) + tm.tm_sec;
+               char tmpdate[10];
+               switch_snprintf(tmpdate, 6, "%d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
+               time_match = switch_tod_cmp(xtod, test);
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9,
+                               "XML DateTime Check: time of day[%s] =~ %s (%s)\n", tmpdate, xtod, time_match ? "PASS" : "FAIL");
+       }
+
        return time_match;
 }