From: Timo Sirainen Date: Tue, 25 Apr 2023 14:07:09 +0000 (+0300) Subject: config: Remove filter parameter from functions where callers only used empty filters X-Git-Tag: 2.4.0~2104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3606defcbdf2cc29118f78f596c4de8ec8645f17;p=thirdparty%2Fdovecot%2Fcore.git config: Remove filter parameter from functions where callers only used empty filters Some of the function names no longer make sense, but these will be fixed by later commits. --- diff --git a/src/config/config-dump-full.c b/src/config/config-dump-full.c index edbe3aa9e9..27c20aae38 100644 --- a/src/config/config-dump-full.c +++ b/src/config/config-dump-full.c @@ -208,9 +208,7 @@ config_dump_full_sections(struct config_filter_context *config_filter, struct config_export_context *export_ctx; int ret = 0; - struct config_filter empty_filter; - i_zero(&empty_filter); - filters = config_filter_find_subset(config_filter, &empty_filter); + filters = config_filter_find_subset(config_filter); /* first filter should be the global one */ i_assert(filters[0] != NULL && filters[0]->filter.service == NULL); @@ -264,7 +262,6 @@ int config_dump_full(struct config_filter_context *config_filter, const char **import_environment_r) { struct config_export_context *export_ctx; - struct config_filter empty_filter; const char *error; unsigned int section_idx = 0; int fd = -1; @@ -283,8 +280,7 @@ int config_dump_full(struct config_filter_context *config_filter, CONFIG_DUMP_SCOPE_CHANGED, flags, config_dump_full_callback, &dump_ctx); } - i_zero(&empty_filter); - if (config_export_by_filter(export_ctx, config_filter, &empty_filter) < 0) { + if (config_export_by_filter(export_ctx, config_filter) < 0) { config_export_free(&export_ctx); str_free(&dump_ctx.delayed_output); return -1; @@ -326,7 +322,6 @@ int config_dump_full(struct config_filter_context *config_filter, } struct ostream *output = dump_ctx.output; - i_zero(&empty_filter); o_stream_cork(output); *import_environment_r = diff --git a/src/config/config-filter.c b/src/config/config-filter.c index 2660dec540..be80cfa815 100644 --- a/src/config/config-filter.c +++ b/src/config/config-filter.c @@ -177,22 +177,12 @@ config_filter_parser_cmp_rev(struct config_filter_parser *const *p1, } static struct config_filter_parser *const * -config_filter_find_all(struct config_filter_context *ctx, pool_t pool, - const struct config_filter *filter) +config_filter_find_all(struct config_filter_context *ctx, pool_t pool) { ARRAY_TYPE(config_filter_parsers) matches; - unsigned int i; p_array_init(&matches, pool, 8); - for (i = 0; ctx->parsers[i] != NULL; i++) { - const struct config_filter *mask = &ctx->parsers[i]->filter; - - if (!config_filter_match_service(mask, filter)) - continue; - - if (config_filter_match_rest(mask, filter)) - array_push_back(&matches, &ctx->parsers[i]); - } + array_push_back(&matches, &ctx->parsers[0]); array_sort(&matches, config_filter_parser_cmp); array_append_zero(&matches); @@ -200,33 +190,15 @@ config_filter_find_all(struct config_filter_context *ctx, pool_t pool, } struct config_filter_parser *const * -config_filter_find_subset(struct config_filter_context *ctx, - const struct config_filter *filter) +config_filter_find_subset(struct config_filter_context *ctx) { ARRAY_TYPE(config_filter_parsers) matches; - struct config_filter tmp_mask; unsigned int i; t_array_init(&matches, 8); - for (i = 0; ctx->parsers[i] != NULL; i++) { - const struct config_filter *mask = &ctx->parsers[i]->filter; - - if (filter->service != NULL) { - if (!config_filter_match_service(mask, filter)) - continue; - } - - tmp_mask = *mask; - if (filter->local_name == NULL) - tmp_mask.local_name = NULL; - if (filter->local_bits == 0) - tmp_mask.local_bits = 0; - if (filter->remote_bits == 0) - tmp_mask.remote_bits = 0; + for (i = 0; ctx->parsers[i] != NULL; i++) + array_push_back(&matches, &ctx->parsers[i]); - if (config_filter_match_rest(&tmp_mask, filter)) - array_push_back(&matches, &ctx->parsers[i]); - } array_sort(&matches, config_filter_parser_cmp_rev); array_append_zero(&matches); return array_front(&matches); @@ -275,7 +247,6 @@ config_module_parser_apply_changes(struct config_module_parser *dest, } int config_filter_parsers_get(struct config_filter_context *ctx, pool_t pool, - const struct config_filter *filter, struct config_module_parser **parsers_r, const char **error_r) { @@ -289,7 +260,7 @@ int config_filter_parsers_get(struct config_filter_context *ctx, pool_t pool, with an error. Merging SET_STRLIST types requires settings_parser_apply_changes() to work a bit unintuitively by letting the destination settings override the source settings. */ - src = config_filter_find_all(ctx, pool, filter); + src = config_filter_find_all(ctx, pool); /* all of them should have the same number of parsers. duplicate our initial parsers from the first match */ diff --git a/src/config/config-filter.h b/src/config/config-filter.h index 551e9cbc60..c955dec406 100644 --- a/src/config/config-filter.h +++ b/src/config/config-filter.h @@ -39,15 +39,13 @@ config_filter_get_errors(struct config_filter_context *ctx); /* Build new parsers from all existing ones matching the given filter. */ int config_filter_parsers_get(struct config_filter_context *ctx, pool_t pool, - const struct config_filter *filter, struct config_module_parser **parsers_r, const char **error_r) ATTR_NULL(3); void config_filter_parsers_free(struct config_module_parser *parsers); /* Return a list of filters that are a subset of the given filter. */ struct config_filter_parser *const * -config_filter_find_subset(struct config_filter_context *ctx, - const struct config_filter *filter); +config_filter_find_subset(struct config_filter_context *ctx); /* Returns TRUE if filter matches mask. */ bool config_filter_match(const struct config_filter *mask, diff --git a/src/config/config-request.c b/src/config/config-request.c index b52455e42a..99fea441f3 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -398,12 +398,11 @@ config_export_init(enum config_dump_scope scope, } int config_export_by_filter(struct config_export_context *ctx, - struct config_filter_context *config_filter, - const struct config_filter *filter) + struct config_filter_context *config_filter) { const char *error; - if (config_filter_parsers_get(config_filter, ctx->pool, filter, + if (config_filter_parsers_get(config_filter, ctx->pool, &ctx->dup_parsers, &error) < 0) { i_error("%s", error); return -1; diff --git a/src/config/config-request.h b/src/config/config-request.h index 90e8d4af23..6dd3d61ecc 100644 --- a/src/config/config-request.h +++ b/src/config/config-request.h @@ -39,8 +39,7 @@ config_export_init(enum config_dump_scope scope, config_request_callback_t *callback, void *context) ATTR_NULL(1, 5); int config_export_by_filter(struct config_export_context *ctx, - struct config_filter_context *config_filter, - const struct config_filter *filter); + struct config_filter_context *config_filter); void config_export_set_parsers(struct config_export_context *ctx, const struct config_module_parser *parsers); unsigned int config_export_get_parser_count(struct config_export_context *ctx); diff --git a/src/config/doveconf.c b/src/config/doveconf.c index 5684f74877..152e9bd4ac 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -537,12 +537,11 @@ static void config_dump_human_sections(struct ostream *output, bool hide_passwords) { - struct config_filter empty_filter = {}; struct config_filter_parser *const *filters; struct config_dump_human_context *ctx; unsigned int indent; - filters = config_filter_find_subset(config_filter, &empty_filter); + filters = config_filter_find_subset(config_filter); /* first filter should be the global one */ i_assert(filters[0] != NULL && filters[0]->filter.service == NULL); @@ -565,7 +564,6 @@ config_dump_human(enum config_dump_scope scope, const char *setting_name_filter, bool hide_passwords) { struct config_dump_human_context *ctx; - struct config_filter empty_filter = {}; struct ostream *output; const char *str; int ret = 0; @@ -575,7 +573,7 @@ config_dump_human(enum config_dump_scope scope, const char *setting_name_filter, o_stream_cork(output); ctx = config_dump_human_init(scope); - if ((ret = config_export_by_filter(ctx->export_ctx, config_filter, &empty_filter)) < 0) + if ((ret = config_export_by_filter(ctx->export_ctx, config_filter)) < 0) config_export_free(&ctx->export_ctx); else config_dump_human_output(ctx, output, 0, setting_name_filter, hide_passwords); @@ -600,14 +598,13 @@ config_dump_one(bool hide_key, bool hide_passwords) { struct config_dump_human_context *ctx; - struct config_filter empty_filter = {}; const char *str; size_t len; unsigned int section_idx = 0; bool dump_section = FALSE; ctx = config_dump_human_init(scope); - if (config_export_by_filter(ctx->export_ctx, config_filter, &empty_filter) < 0) { + if (config_export_by_filter(ctx->export_ctx, config_filter) < 0) { config_export_free(&ctx->export_ctx); return -1; } @@ -970,14 +967,12 @@ int main(int argc, char *argv[]) ret2 = -1; } else if (simple_output) { struct config_export_context *ctx; - struct config_filter empty_filter = {}; unsigned int section_idx = 0; ctx = config_export_init(scope, 0, config_request_simple_stdout, setting_name_filters); - if ((ret2 = config_export_by_filter(ctx, config_filter, - &empty_filter)) < 0) + if ((ret2 = config_export_by_filter(ctx, config_filter)) < 0) config_export_free(&ctx); else { if (config_export_all_parsers(&ctx, §ion_idx) < 0)