]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Allow event filtering with wildcarded integers
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Thu, 18 Jul 2019 15:45:28 +0000 (11:45 -0400)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 23 Jul 2019 10:59:45 +0000 (10:59 +0000)
src/lib/event-filter.c

index 05364a17d555871c3a8724085c7c66ec727839a2..ac522f8cab4ecbd2d0150064362a2f3ba72ef41c 100644 (file)
@@ -175,7 +175,9 @@ event_filter_add_fields(struct event_filter *filter,
                   and numbers. */
                int_fields[i].value.str = p_strdup(filter->pool, fields[i].value);
                if (str_to_intmax(fields[i].value, &int_fields[i].value.intmax) < 0) {
-                       /* not a number - no problem */
+                       /* not a number - no problem
+                          Either we have a string, or a number with wildcards */
+                       int_fields[i].value.intmax = INT_MIN;
                }
        }
        int_query->fields_count = count;
@@ -467,7 +469,15 @@ event_match_field(struct event *event, const struct event_field *wanted_field)
                }
                return wildcard_match_icase(field->value.str, wanted_field->value.str);
        case EVENT_FIELD_VALUE_TYPE_INTMAX:
-               return field->value.intmax == wanted_field->value.intmax;
+               if (wanted_field->value.intmax > INT_MIN) {
+                       /* compare against an integer */
+                       return field->value.intmax == wanted_field->value.intmax;
+               } else {
+                       /* compare against an "integer" with wildcards */
+                       char tmp[MAX_INT_STRLEN];
+                       i_snprintf(tmp, sizeof(tmp), "%jd", field->value.intmax);
+                       return wildcard_match_icase(tmp, wanted_field->value.str);
+               }
        case EVENT_FIELD_VALUE_TYPE_TIMEVAL:
                /* there's no point to support matching exact timestamps */
                return FALSE;