From: Josef 'Jeff' Sipek Date: Thu, 18 Jul 2019 15:45:28 +0000 (-0400) Subject: lib: Allow event filtering with wildcarded integers X-Git-Tag: 2.3.9~363 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9793fb39e0a4f1b2581693712c24a373d4d4e74;p=thirdparty%2Fdovecot%2Fcore.git lib: Allow event filtering with wildcarded integers --- diff --git a/src/lib/event-filter.c b/src/lib/event-filter.c index 05364a17d5..ac522f8cab 100644 --- a/src/lib/event-filter.c +++ b/src/lib/event-filter.c @@ -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;