]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add time of day routing attrs to condition tags in xml dialplan
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 6 Jul 2009 18:31:23 +0000 (18:31 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 6 Jul 2009 18:31:23 +0000 (18:31 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14137 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_utils.h
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
src/switch_utils.c

index f67fc4a8a7d4907452fd095c9a18f9e5d0610cdd..3bb578e98fc93142df80d4383eccbaf6f5f83c92 100644 (file)
@@ -564,6 +564,8 @@ 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);
+
 /* malloc or DIE macros */
 #ifdef NDEBUG
 #define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
index 1bbf5c2cf3abb9f567ee8009a618a5acef94c5bd..24e945084a2e989fa9c2f6adb2d9492014fcc2f4 100644 (file)
@@ -44,6 +44,7 @@ typedef enum {
        BREAK_NEVER
 } break_t;
 
+
 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;
@@ -64,6 +65,18 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
                switch_regex_t *re = NULL;
                int ovector[30];
                break_t do_break_i = BREAK_ON_FALSE;
+               
+               const char *xyear = switch_xml_attr(xcond, "year");
+               const char *xyday = switch_xml_attr(xcond, "yday");
+               const char *xmon = switch_xml_attr(xcond, "mon");
+               const char *xmday = switch_xml_attr(xcond, "mday");
+               const char *xweek = switch_xml_attr(xcond, "week");
+               const char *xwday = switch_xml_attr(xcond, "wday");
+               const char *xhour = switch_xml_attr(xcond, "hour");
+               const char *xminute = switch_xml_attr(xcond, "minute");
+               switch_time_t ts = switch_micro_time_now();
+               int time_match = -1;
+               switch_time_exp_t tm;
 
                switch_safe_free(field_expanded);
                switch_safe_free(expression_expanded);
@@ -74,6 +87,40 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
                        goto done;
                }
 
+               switch_time_exp_lt(&tm, ts);
+               
+               if (time_match && xyear) {
+                       time_match = switch_number_cmp(xyear, tm.tm_year + 1900);
+               }
+
+               if (time_match && xyday) {
+                       time_match = switch_number_cmp(xyday, tm.tm_yday + 1);
+               }
+
+               if (time_match && xmon) {
+                       time_match = switch_number_cmp(xmon, tm.tm_mon + 1);
+               }
+
+               if (time_match && xmday) {
+                       time_match = switch_number_cmp(xmday, tm.tm_mday);
+               }
+
+               if (time_match && xweek) {
+                       time_match = switch_number_cmp(xweek, (int) (tm.tm_yday + 1 / 7));
+               }
+
+               if (time_match && xwday) {
+                       time_match = switch_number_cmp(xwday, tm.tm_wday + 1);
+               }
+
+               if (time_match && xhour) {
+                       time_match = switch_number_cmp(xhour, tm.tm_hour);
+               }
+
+               if (time_match && xminute) {
+                       time_match = switch_number_cmp(xminute, tm.tm_min + 1);
+               }
+               
                field = (char *) switch_xml_attr(xcond, "field");
 
                if ((xexpression = switch_xml_child(xcond, "expression"))) {
@@ -102,6 +149,17 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
                        }
                }
 
+               if (time_match == 0) {
+                       if (do_break_i == BREAK_ON_FALSE || do_break_i == BREAK_ALWAYS) {
+                               break;
+                       } else if (do_break_i == BREAK_NEVER) {
+                               continue;
+                       } else {
+                               proceed = 0;
+                               goto done;
+                       }
+               }
+
                if (field) {
                        if (strchr(field, '$')) {
                                if ((field_expanded = switch_channel_expand_variables(channel, field)) == field) {
index 9073796b2d6bb24b96ea099900f856f0dd19b0aa..079ee7bc302b1682c164369df034bf634cee6a59 100644 (file)
@@ -1949,6 +1949,47 @@ SWITCH_DECLARE(int) switch_isxdigit(int c)
        return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
 }
 
+SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
+{
+    char *p;
+       
+    if ((p=strchr(exp, '-'))) {
+        int min;
+        int max;
+
+        min = atol(exp);
+        p++;
+        max = atol(p);
+
+        if (val >= min && val <= max) {
+            return 1;
+        }
+    } else if ((p=strchr(exp, ','))) {
+        const char *cur = exp;
+               p++;
+        while(cur) {
+            if (atol(cur) == val) {
+                return 1;
+            }
+                       
+            cur = p;
+                       if (p && p+1) {
+                               if ((p = strchr((p+1), ','))) {
+                                       p++;
+                               }
+                       }
+        }
+    } else {
+        if (atol(exp) == val) {
+            return 1;
+        }
+    }
+
+    return 0;
+
+}
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c