]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add warning that timeval event field filtering is unimplemented
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Thu, 22 Dec 2022 11:54:16 +0000 (12:54 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 9 Jan 2023 09:48:38 +0000 (09:48 +0000)
src/lib/event-filter-private.h
src/lib/event-filter.c
src/lib/test-event-filter.c

index bb9b0f638a95ad7eadb36f81a619137218120ea3..cdf5036f098f66ea96dface39f3f6808c93556cb 100644 (file)
@@ -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,
index a36e4e43eea6295fd4ccd738ef1271b51903c7e0..39cf64b6bda6682584e2a4c6587d5c8ad25879f1 100644 (file)
@@ -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. */
index 3b317bcae388a5cdf08f539369ea34f0df54f71b..6de95b2ed2e0ec85b28326c2b8305d4f7d0e2243 100644 (file)
@@ -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();
 }