]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add a way to merge filter queries with an overridden context
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Mon, 11 May 2020 18:07:11 +0000 (14:07 -0400)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 26 Jun 2020 07:18:18 +0000 (07:18 +0000)
This allows the consumers to construct a filter without setting the context
on each query, and then when merging it with another query "filling in" the
context on the fly.

src/lib/event-filter.c
src/lib/event-filter.h

index e3e692dbe01da13c7dd7bb3285f87015acd07f3b..d2678b21f9862a02fdca53e46a80b874029bcf01 100644 (file)
@@ -212,8 +212,10 @@ void event_filter_add(struct event_filter *filter,
        }
 }
 
-void event_filter_merge(struct event_filter *dest,
-                       const struct event_filter *src)
+static void
+event_filter_merge_with_context_internal(struct event_filter *dest,
+                                        const struct event_filter *src,
+                                        void *new_context, bool with_context)
 {
        const struct event_filter_query_internal *int_query;
        struct event_filter_query query;
@@ -221,7 +223,7 @@ void event_filter_merge(struct event_filter *dest,
 
        array_foreach(&src->queries, int_query) T_BEGIN {
                i_zero(&query);
-               query.context = int_query->context;
+               query.context = with_context ? new_context : int_query->context;
                query.name = int_query->name;
                query.source_filename = int_query->source_filename;
                query.source_linenum = int_query->source_linenum;
@@ -262,6 +264,19 @@ void event_filter_merge(struct event_filter *dest,
        } T_END;
 }
 
+void event_filter_merge(struct event_filter *dest,
+                       const struct event_filter *src)
+{
+       event_filter_merge_with_context_internal(dest, src, NULL, FALSE);
+}
+
+void event_filter_merge_with_context(struct event_filter *dest,
+                                    const struct event_filter *src,
+                                    void *new_context)
+{
+       event_filter_merge_with_context_internal(dest, src, new_context, TRUE);
+}
+
 static void
 event_filter_export_query(const struct event_filter_query_internal *query,
                          string_t *dest)
index 781d8c290e16c851e147c096636f4cbe879e8244..be79825fe7b30a5460fb8227f9d6543e7c7fc8c6 100644 (file)
@@ -38,6 +38,11 @@ void event_filter_add(struct event_filter *filter,
 /* Add queries from source filter to destination filter. */
 void event_filter_merge(struct event_filter *dest,
                        const struct event_filter *src);
+/* Add queries from source filter to destination filter, but with supplied
+   context overriding whatever context source queries had. */
+void event_filter_merge_with_context(struct event_filter *dest,
+                                    const struct event_filter *src,
+                                    void *new_context);
 
 /* Export the filter into a tabescaped string, so its fields are separated
    with TABs and there are no NUL, CR or LF characters. The context pointers