From: Timo Sirainen Date: Mon, 9 Jan 2023 14:26:02 +0000 (+0200) Subject: config: config_parse_file() - Change expand_values parameter to enum X-Git-Tag: 2.4.0~3054 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dc2cf3eed2afe08a151605766c530ba5ab8a765;p=thirdparty%2Fdovecot%2Fcore.git config: config_parse_file() - Change expand_values parameter to enum --- diff --git a/src/config/config-connection.c b/src/config/config-connection.c index e2225b6b0d..30eeb06ac4 100644 --- a/src/config/config-connection.c +++ b/src/config/config-connection.c @@ -58,7 +58,7 @@ static int config_connection_request(struct config_connection *conn, const char *path, *error; path = master_service_get_config_path(master_service); - if (config_parse_file(path, TRUE, NULL, &error) <= 0) { + if (config_parse_file(path, CONFIG_PARSE_FLAG_EXPAND_VALUES, NULL, &error) <= 0) { o_stream_nsend_str(conn->output, t_strconcat("-", error, "\n", NULL)); return 0; diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 099b577a40..b95d86e1d7 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -997,7 +997,7 @@ void config_parser_apply_line(struct config_parser_context *ctx, } } -int config_parse_file(const char *path, bool expand_values, +int config_parse_file(const char *path, enum config_parse_flags flags, const char *const *modules, const char **error_r) { struct input_stack root; @@ -1039,7 +1039,7 @@ int config_parse_file(const char *path, bool expand_values, i_zero(&root); root.path = path; ctx.cur_input = &root; - ctx.expand_values = expand_values; + ctx.expand_values = (flags & CONFIG_PARSE_FLAG_EXPAND_VALUES) != 0; ctx.modules = modules; hash_table_create(&ctx.seen_settings, ctx.pool, 0, str_hash, strcmp); diff --git a/src/config/config-parser.h b/src/config/config-parser.h index e0a0a5bea3..92ea73d1b3 100644 --- a/src/config/config-parser.h +++ b/src/config/config-parser.h @@ -5,6 +5,10 @@ #define IS_WHITE(c) ((c) == ' ' || (c) == '\t') +enum config_parse_flags { + CONFIG_PARSE_FLAG_EXPAND_VALUES = BIT(0), +}; + struct config_module_parser { const struct setting_parser_info *root; struct setting_parser_context *parser; @@ -18,7 +22,7 @@ extern struct module *modules; int config_parse_net(const char *value, struct ip_addr *ip_r, unsigned int *bits_r, const char **error_r); -int config_parse_file(const char *path, bool expand_values, +int config_parse_file(const char *path, enum config_parse_flags flags, const char *const *modules, const char **error_r) ATTR_NULL(3); diff --git a/src/config/doveconf.c b/src/config/doveconf.c index dd75b8f251..27bc3eab17 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -965,8 +965,11 @@ int main(int argc, char *argv[]) } } + enum config_parse_flags flags = 0; + if (expand_vars) + flags |= CONFIG_PARSE_FLAG_EXPAND_VALUES; if ((ret = config_parse_file(dump_defaults ? NULL : config_path, - expand_vars, NULL, + flags, NULL, &error)) == 0 && access(EXAMPLE_CONFIG_DIR, X_OK) == 0) { i_fatal("%s (copy example configs from "EXAMPLE_CONFIG_DIR"/)", diff --git a/src/config/main.c b/src/config/main.c index 13dc76d264..1a5b8eb777 100644 --- a/src/config/main.c +++ b/src/config/main.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) config_parse_load_modules(); path = master_service_get_config_path(master_service); - if (config_parse_file(path, TRUE, NULL, &error) <= 0) + if (config_parse_file(path, CONFIG_PARSE_FLAG_EXPAND_VALUES, NULL, &error) <= 0) i_fatal("%s", error); /* notify about our success only after successfully parsing the diff --git a/src/config/test-config-parser.c b/src/config/test-config-parser.c index baf91a1d45..5503d3da80 100644 --- a/src/config/test-config-parser.c +++ b/src/config/test-config-parser.c @@ -117,7 +117,7 @@ static void test_config_parser(void) putenv("bar=test2"); putenv("FOO$ENV:FOO=works"); - test_assert(config_parse_file(TEST_CONFIG_FILE, TRUE, NULL, &error) == 1); + test_assert(config_parse_file(TEST_CONFIG_FILE, CONFIG_PARSE_FLAG_EXPAND_VALUES, NULL, &error) == 1); if (error != NULL) i_error("config_parse_file(): %s", error); @@ -138,7 +138,7 @@ static void test_config_parser(void) test_assert_strcmp(set->protocols, "pop3 imap"); /* try again unexpanded */ - test_assert(config_parse_file(TEST_CONFIG_FILE, FALSE, NULL, &error) == 1); + test_assert(config_parse_file(TEST_CONFIG_FILE, 0, NULL, &error) == 1); set = settings_parser_get(config_module_parsers[0].parser); test_assert_strcmp(set->key, "value");