From: Karl Fleischmann Date: Thu, 22 Dec 2022 11:54:16 +0000 (+0100) Subject: lib: Add warning that timeval event field filtering is unimplemented X-Git-Tag: 2.4.0~3235 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e03477f417da3cd696693666e2c182cc93ae0bc;p=thirdparty%2Fdovecot%2Fcore.git lib: Add warning that timeval event field filtering is unimplemented --- diff --git a/src/lib/event-filter-private.h b/src/lib/event-filter-private.h index bb9b0f638a..cdf5036f09 100644 --- a/src/lib/event-filter-private.h +++ b/src/lib/event-filter-private.h @@ -89,6 +89,7 @@ struct event_filter_node { bool warned_ambiguous_unit:1; bool warned_string_inequality:1; bool warned_type_mismatch:1; + bool warned_timeval_not_implemented:1; }; bool event_filter_category_to_log_type(const char *name, diff --git a/src/lib/event-filter.c b/src/lib/event-filter.c index a36e4e43ee..39cf64b6bd 100644 --- a/src/lib/event-filter.c +++ b/src/lib/event-filter.c @@ -255,6 +255,7 @@ clone_expr(pool_t pool, struct event_filter_node *old) new->warned_ambiguous_unit = old->warned_ambiguous_unit; new->warned_type_mismatch = old->warned_type_mismatch; new->warned_string_inequality = old->warned_string_inequality; + new->warned_timeval_not_implemented = old->warned_timeval_not_implemented; return new; } @@ -677,9 +678,19 @@ event_match_field(struct event *event, struct event_filter_node *node, 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 */ + case EVENT_FIELD_VALUE_TYPE_TIMEVAL: { + /* Filtering for timeval fields is not implemented. */ + if (!node->warned_timeval_not_implemented) { + const char *name = event->sending_name; + i_warning("Event filter for timeval field '%s' is " + "currently not implemented. (event=%s, " + "source=%s:%u)", + wanted_field->key, name != NULL ? name : "", + source_filename, source_linenum); + node->warned_timeval_not_implemented = TRUE; + } return FALSE; + } case EVENT_FIELD_VALUE_TYPE_STRLIST: /* check if the value is (or is not) on the list, only string matching makes sense here. */ diff --git a/src/lib/test-event-filter.c b/src/lib/test-event-filter.c index 3b317bcae3..6de95b2ed2 100644 --- a/src/lib/test-event-filter.c +++ b/src/lib/test-event-filter.c @@ -329,7 +329,7 @@ static void test_event_filter_strlist(void) filter = event_filter_create(); event_filter_parse("abc>one", filter, NULL); - test_expect_error_string("Event filter for string field 'abc' only " + test_expect_error_string("Event filter for string list field 'abc' only " "supports equality operation '=' not '>'."); test_assert(!event_filter_match(filter, e, &failure_ctx)); test_expect_no_more_errors(); @@ -909,6 +909,44 @@ static void test_event_filter_ambiguous_units(void) test_end(); } +static void test_event_filter_timeval_values(void) +{ + struct event_filter *filter; + const char *error; + const struct failure_context failure_ctx = { + .type = LOG_TYPE_DEBUG, + }; + + test_begin("event filter: timeval filters"); + + struct event *e = event_create(NULL); + + struct timeval tv = (struct timeval){ .tv_sec = 0, .tv_usec = 0 }; + event_add_timeval(e, "last_run_time", &tv); + + filter = event_filter_create(); + test_assert(event_filter_parse("last_run_time = 0", filter, &error) == 0); + test_expect_error_string("Event filter for timeval field " + "'last_run_time' is currently not implemented."); + test_assert(!event_filter_match(filter, e, &failure_ctx)); + test_expect_no_more_errors(); + event_filter_unref(&filter); + + tv = (struct timeval){ .tv_sec = 1, .tv_usec = 1 }; + event_add_timeval(e, "last_run_time", &tv); + + filter = event_filter_create(); + test_assert(event_filter_parse("last_run_time > 1000000", filter, &error) == 0); + test_expect_error_string("Event filter for timeval field " + "'last_run_time' is currently not implemented."); + test_assert(!event_filter_match(filter, e, &failure_ctx)); + test_expect_no_more_errors(); + event_filter_unref(&filter); + + event_unref(&e); + test_end(); +} + void test_event_filter(void) { test_event_filter_override_parent_fields(); @@ -928,4 +966,5 @@ void test_event_filter(void) test_event_filter_size_values(); test_event_filter_interval_values(); test_event_filter_ambiguous_units(); + test_event_filter_timeval_values(); }