From: Josef 'Jeff' Sipek Date: Mon, 11 May 2020 18:07:11 +0000 (-0400) Subject: lib: Add a way to merge filter queries with an overridden context X-Git-Tag: 2.3.13~503 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43159ecb2c26bfe54e38dedf0bf7bcaffab6dc3a;p=thirdparty%2Fdovecot%2Fcore.git lib: Add a way to merge filter queries with an overridden context 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. --- diff --git a/src/lib/event-filter.c b/src/lib/event-filter.c index e3e692dbe0..d2678b21f9 100644 --- a/src/lib/event-filter.c +++ b/src/lib/event-filter.c @@ -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) diff --git a/src/lib/event-filter.h b/src/lib/event-filter.h index 781d8c290e..be79825fe7 100644 --- a/src/lib/event-filter.h +++ b/src/lib/event-filter.h @@ -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