]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update filters to have optional - prefix to omit a match within a match from the...
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 30 Oct 2008 23:37:16 +0000 (23:37 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 30 Oct 2008 23:37:16 +0000 (23:37 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10207 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_event_socket/mod_event_socket.c

index cc6b6a9cf0a31767f2df25f36c5b4ba1185e7d0e..624b2308bc435c05105d8ebafc639460f48bd76a 100644 (file)
@@ -239,22 +239,51 @@ static void event_handler(switch_event_t *event)
                        }
                }
                
-               if (send && l->filters) {
+               if (send && l->filters && l->filters->headers) {
                        switch_event_header_t *hp;
                        const char *hval;
 
                        send = 0;
                        switch_mutex_lock(l->filter_mutex);
-                       for (hp = l->filters->headers; hp && !send; hp = hp->next) {
+                       for (hp = l->filters->headers; hp hp = hp->next) {
                                if ((hval = switch_event_get_header(event, hp->name))) {
+                                       const char *comp_to = hp->value;
+                                       int pos = 1, cmp = 0;
+
+                                       while (comp_to && *comp_to) {
+                                               if (*comp_to == '+') {
+                                                       pos = 1;
+                                               } else if (*comp_to == '-') {
+                                                       pos = 0;
+                                               } else if (*comp_to != ' ') {
+                                                       break;
+                                               }
+                                               comp_to++;
+                                       }
+
+                                       if (send && pos) {
+                                               continue;
+                                       }
+
+                                       if (!comp_to) {
+                                               continue;
+                                       }
+                                       
                                        if (*hp->value == '/') {
                                                switch_regex_t *re = NULL;
                                                int ovector[30];
-                                               send = switch_regex_perform(hval, hp->value, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
+                                               cmp = !!switch_regex_perform(hval, comp_to, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
                                                switch_regex_safe_free(re);                                             
                                        } else {
-                                               if (!strcasecmp(hp->value, hval)) {
+                                               cmp = !strcasecmp(hval, comp_to);
+                                       }
+
+                                       if (cmp) {
+                                               if (pos) {
                                                        send = 1;
+                                               } else {
+                                                       send = 0;
+                                                       break;
                                                }
                                        }
                                }