Mercurial > dovecot > core-2.2
changeset 10981:02e0d6f0e1d4 HEAD
doveconf: When module is given, ignore checks for non-required settings.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 25 Mar 2010 19:19:02 +0200 |
parents | 5b0a88cb9a12 |
children | 2ed4d6da04af |
files | src/config/config-connection.c src/config/config-filter.c src/config/config-parser-private.h src/config/config-parser.c src/config/config-parser.h src/config/config-request.c src/config/doveconf.c src/config/main.c |
diffstat | 8 files changed, 41 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/config/config-connection.c Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/config-connection.c Thu Mar 25 19:19:02 2010 +0200 @@ -100,7 +100,7 @@ if (strcmp(module, "master") == 0) { /* master reads configuration only when reloading settings */ path = master_service_get_config_path(master_service); - if (config_parse_file(path, TRUE, &error) <= 0) { + if (config_parse_file(path, TRUE, "", &error) <= 0) { o_stream_send_str(conn->output, t_strconcat("ERROR ", error, "\n", NULL)); config_connection_destroy(conn);
--- a/src/config/config-filter.c Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/config-filter.c Thu Mar 25 19:19:02 2010 +0200 @@ -174,7 +174,8 @@ for (i = 0; parser->parsers[i].root != NULL; i++) { if (*module != '\0' && - !config_module_want_parser(module, parser->parsers[i].root)) + !config_module_want_parser(config_module_parsers, + module, parser->parsers[i].root)) continue; changes = settings_parser_get_changes(parser->parsers[i].parser);
--- a/src/config/config-parser-private.h Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/config-parser-private.h Thu Mar 25 19:19:02 2010 +0200 @@ -36,6 +36,7 @@ struct config_parser_context { pool_t pool; const char *path; + const char *module; ARRAY_DEFINE(all_parsers, struct config_filter_parser *); struct config_module_parser *root_parsers;
--- a/src/config/config-parser.c Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/config-parser.c Thu Mar 25 19:19:02 2010 +0200 @@ -275,6 +275,11 @@ const struct config_module_parser *p, const char **error_r) { + /* skip checking settings we don't care about */ + if (*ctx->module != '\0' && + !config_module_want_parser(ctx->root_parsers, ctx->module, p->root)) + return 0; + for (; p->root != NULL; p++) { settings_parse_var_skip(p->parser); if (!settings_parser_check(p->parser, ctx->pool, error_r)) @@ -603,6 +608,23 @@ return NULL; } +static bool +config_require_key(struct config_parser_context *ctx, const char *key) +{ + struct config_module_parser *l; + + if (*ctx->module == '\0') + return TRUE; + + for (l = ctx->cur_section->parsers; l->root != NULL; l++) { + if (config_module_want_parser(ctx->root_parsers, + ctx->module, l->root) && + settings_parse_is_valid_key(l->parser, key)) + return TRUE; + } + return FALSE; +} + static int config_write_value(struct config_parser_context *ctx, enum config_line_type type, const char *key, const char *value) @@ -622,7 +644,8 @@ str_append_c(str, '<'); str_append(str, value); } else { - if (str_append_file(str, key, value, &error) < 0) { + if (str_append_file(str, key, value, &error) < 0 && + config_require_key(ctx, key)) { /* file reading failed */ ctx->error = p_strdup(ctx->pool, error); return -1; @@ -737,7 +760,7 @@ } } -int config_parse_file(const char *path, bool expand_values, +int config_parse_file(const char *path, bool expand_values, const char *module, const char **error_r) { struct input_stack root; @@ -773,6 +796,7 @@ root.path = path; ctx.cur_input = &root; ctx.expand_values = expand_values; + ctx.module = module; p_array_init(&ctx.all_parsers, ctx.pool, 128); ctx.cur_section = p_new(ctx.pool, struct config_section_stack, 1); @@ -883,7 +907,8 @@ return FALSE; } -bool config_module_want_parser(const char *module, +bool config_module_want_parser(struct config_module_parser *parsers, + const char *module, const struct setting_parser_info *root) { struct config_module_parser *l; @@ -895,7 +920,7 @@ return TRUE; } - for (l = config_module_parsers; l->root != NULL; l++) { + for (l = parsers; l->root != NULL; l++) { if (strcmp(l->root->module_name, module) != 0) continue;
--- a/src/config/config-parser.h Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/config-parser.h Thu Mar 25 19:19:02 2010 +0200 @@ -13,12 +13,13 @@ extern struct config_module_parser *config_module_parsers; extern struct config_filter_context *config_filter; -int config_parse_file(const char *path, bool expand_values, +int config_parse_file(const char *path, bool expand_values, const char *module, const char **error_r); void config_parse_load_modules(void); -bool config_module_want_parser(const char *module, +bool config_module_want_parser(struct config_module_parser *parsers, + const char *module, const struct setting_parser_info *root); #endif
--- a/src/config/config-request.c Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/config-request.c Thu Mar 25 19:19:02 2010 +0200 @@ -367,7 +367,8 @@ for (i = 0; ctx->parsers[i].root != NULL; i++) { parser = &ctx->parsers[i]; if (*ctx->module != '\0' && - !config_module_want_parser(ctx->module, parser->root)) + !config_module_want_parser(config_module_parsers, + ctx->module, parser->root)) continue; settings_export(ctx, parser->root, FALSE,
--- a/src/config/doveconf.c Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/doveconf.c Thu Mar 25 19:19:02 2010 +0200 @@ -517,7 +517,8 @@ master_service_init_finish(master_service); config_parse_load_modules(); - if ((ret = config_parse_file(config_path, expand_vars, &error)) == 0 && + if ((ret = config_parse_file(config_path, expand_vars, + module, &error)) == 0 && access(EXAMPLE_CONFIG_DIR, X_OK) == 0) { i_fatal("%s (copy example configs from "EXAMPLE_CONFIG_DIR"/)", error);
--- a/src/config/main.c Thu Mar 25 17:41:16 2010 +0200 +++ b/src/config/main.c Thu Mar 25 19:19:02 2010 +0200 @@ -30,7 +30,7 @@ config_parse_load_modules(); path = master_service_get_config_path(master_service); - if (config_parse_file(path, TRUE, &error) <= 0) + if (config_parse_file(path, TRUE, "", &error) <= 0) i_fatal("%s", error); master_service_run(master_service, client_connected);