]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
switch_utils: Add day of week 3 letter initial usage in "wday" field in the dialplan...
authorMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 17 Sep 2010 04:26:27 +0000 (00:26 -0400)
committerMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 17 Sep 2010 04:26:27 +0000 (00:26 -0400)
src/include/switch_utils.h
src/switch_utils.c
src/switch_xml.c

index a52676dddae59eb4a85252db684c471fe25ad7af..4dc7ed7f1b0599e4c3017325cbac00a6b9c27aad 100644 (file)
@@ -680,6 +680,9 @@ 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(const char *) switch_dow_int2str(int val);
+SWITCH_DECLARE(int) switch_dow_str2int(const char *exp);
+SWITCH_DECLARE(int) switch_dow_cmp(const char *exp, int val);
 SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val);
 SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val);
 
index 6df515906e6c7084c7c448ff028d0320a48b89bb..b8879049609b7af82f03e4140b0cae014d5803ab 100644 (file)
@@ -2466,6 +2466,82 @@ SWITCH_DECLARE(int) switch_isxdigit(int c)
        return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_N | _X)));
 }
 
+static const char *DOW[] = {
+       "sat",
+       "sun",
+       "mon",
+       "tue",
+       "wed",
+       "thu",
+       "fri",
+       "sat",
+       "sun",
+       NULL
+};
+
+SWITCH_DECLARE(const char *) switch_dow_int2str(int val) {
+       if (val >= sizeof(DOW) / sizeof (const char*)) {
+               return NULL;
+       }
+       return DOW[val];
+}
+
+SWITCH_DECLARE(int) switch_dow_str2int(const char *exp) {
+       int ret = -1;
+       int x = -1;
+       for (x = 0;; x++) {
+               if (!DOW[x]) {
+                       break;  
+               }
+
+               if (!strcasecmp(DOW[x], exp)) {
+                       ret =  x;
+                       break;
+               }
+       }
+       return ret;
+}
+
+SWITCH_DECLARE(int) switch_dow_cmp(const char *exp, int val)
+{
+       char *dup = strdup(exp);
+       char *p_start;
+       char *p_end;
+       int ret = 0;
+       int start, end;
+
+       switch_assert(dup);
+
+       p_start = dup;
+
+       if ((p_end=strchr(dup, '-'))) {
+               *p_end++ = '\0';
+       } else {
+               p_end = p_start;
+       }
+       if (strlen(p_start) == 3) {
+               start = switch_dow_str2int(p_start);
+       } else {
+               start = atol(p_start);
+       }
+       if (strlen(p_end) == 3) {
+               end = switch_dow_str2int(p_end);
+       } else {
+               end = atol(p_end);
+       }
+       /* Following used for this example : mon-sat = 2-0, so we need to make 0(sat) + 7 */
+       if (end < start) {
+               end += 7;
+       }
+       if (start != -1 && end != -1 && val >= start && val <= end) {
+               ret = 1;
+       }
+
+       switch_safe_free(dup);
+
+       return ret;     
+}
+
 SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
 {
        char *p;
index 3e46fc0ae23a817b1ebfb4fe24e7f266c9e6b69d..95b82cb20d190fd05db63ff4ce29872c961d6f63 100644 (file)
@@ -2733,9 +2733,9 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) {
 
        if (time_match && xwday) {
                int test = tm.tm_wday + 1;
-               time_match = switch_number_cmp(xwday, test);
+               time_match = switch_dow_cmp(xwday, test);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9,
-                               "XML DateTime Check: day of week[%d] =~ %s (%s)\n", test, xwday, time_match ? "PASS" : "FAIL");
+                               "XML DateTime Check: day of week[%s] =~ %s (%s)\n", switch_dow_int2str(test), xwday, time_match ? "PASS" : "FAIL");
        }
        if (time_match && xhour) {
                int test = tm.tm_hour;