dovecot-2.0: config: Added support for reading v1.2 config files.
dovecot at dovecot.org
dovecot at dovecot.org
Tue Mar 9 00:34:25 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/3a575415ce1a
changeset: 10874:3a575415ce1a
user: Timo Sirainen <tss at iki.fi>
date: Tue Mar 09 00:34:22 2010 +0200
description:
config: Added support for reading v1.2 config files.
diffstat:
src/config/Makefile.am | 3 +
src/config/config-parser.c | 305 ++++++++++++--------------
src/config/old-set-parser.c | 529 ++++++++++++++++++++++++++++++++++++++++++++++++
src/config/old-set-parser.h | 12 +
4 files changed, 685 insertions(+), 164 deletions(-)
diffs (truncated from 1109 to 300 lines):
diff -r 7c2e38d7390c -r 3a575415ce1a src/config/Makefile.am
--- a/src/config/Makefile.am Tue Mar 09 00:27:01 2010 +0200
+++ b/src/config/Makefile.am Tue Mar 09 00:34:22 2010 +0200
@@ -32,6 +32,7 @@
config-filter.c \
config-parser.c \
config-request.c \
+ old-set-parser.c \
sysinfo-get.c
config_SOURCES = \
@@ -47,7 +48,9 @@
config-connection.h \
config-filter.h \
config-parser.h \
+ config-parser-private.h \
config-request.h \
+ old-set-parser.h \
sysinfo-get.h
all-settings.c: $(SETTING_FILES) $(top_srcdir)/src/config/settings-get.pl
diff -r 7c2e38d7390c -r 3a575415ce1a src/config/config-parser.c
--- a/src/config/config-parser.c Tue Mar 09 00:27:01 2010 +0200
+++ b/src/config/config-parser.c Tue Mar 09 00:34:22 2010 +0200
@@ -11,9 +11,9 @@
#include "service-settings.h"
#include "master-service-settings.h"
#include "all-settings.h"
-#include "config-filter.h"
+#include "old-set-parser.h"
#include "config-request.h"
-#include "config-parser.h"
+#include "config-parser-private.h"
#include <stdlib.h>
#include <unistd.h>
@@ -28,36 +28,6 @@
#define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
-struct config_section_stack {
- struct config_section_stack *prev;
-
- struct config_filter filter;
- /* root=NULL-terminated list of parsers */
- struct config_module_parser *parsers;
- unsigned int pathlen;
-};
-
-struct input_stack {
- struct input_stack *prev;
-
- struct istream *input;
- const char *path;
- unsigned int linenum;
-};
-
-struct parser_context {
- pool_t pool;
- const char *path;
-
- ARRAY_DEFINE(all_parsers, struct config_filter_parser *);
- struct config_module_parser *root_parsers;
- struct config_section_stack *cur_section;
- struct input_stack *cur_input;
-
- struct config_filter_context *filter;
- unsigned int expand_values:1;
-};
-
static const enum settings_parser_flags settings_parser_flags =
SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS |
SETTINGS_PARSER_FLAG_TRACK_CHANGES;
@@ -103,10 +73,8 @@
i_assert(ret > 0);
}
-static int
-config_apply_line(struct parser_context *ctx, const char *key,
- const char *line, const char *section_name,
- const char **error_r)
+int config_apply_line(struct config_parser_context *ctx, const char *key,
+ const char *line, const char *section_name)
{
struct config_module_parser *l;
bool found = FALSE;
@@ -119,15 +87,15 @@
if (section_name != NULL)
config_add_type(l->parser, line, section_name);
} else if (ret < 0) {
- *error_r = settings_parser_get_error(l->parser);
+ ctx->error = settings_parser_get_error(l->parser);
return -1;
}
}
if (!found) {
- *error_r = t_strconcat("Unknown setting: ", key, NULL);
+ ctx->error = p_strconcat(ctx->pool, "Unknown setting: ",
+ key, NULL);
return -1;
}
- *error_r = NULL;
return 0;
}
@@ -164,7 +132,7 @@
}
static void
-config_add_new_parser(struct parser_context *ctx)
+config_add_new_parser(struct config_parser_context *ctx)
{
struct config_section_stack *cur_section = ctx->cur_section;
struct config_filter_parser *parser;
@@ -188,7 +156,7 @@
}
static struct config_section_stack *
-config_add_new_section(struct parser_context *ctx)
+config_add_new_section(struct config_parser_context *ctx)
{
struct config_section_stack *section;
@@ -200,7 +168,7 @@
}
static struct config_filter_parser *
-config_filter_parser_find(struct parser_context *ctx,
+config_filter_parser_find(struct config_parser_context *ctx,
const struct config_filter *filter)
{
struct config_filter_parser *const *parsers;
@@ -215,7 +183,7 @@
}
static int
-config_parse_net(struct parser_context *ctx, const char *value,
+config_parse_net(struct config_parser_context *ctx, const char *value,
const char **host_r, struct ip_addr *ip_r,
unsigned int *bits_r, const char **error_r)
{
@@ -249,47 +217,47 @@
}
static bool
-config_filter_add_new_filter(struct parser_context *ctx,
- const char *key, const char *value,
- const char **error_r)
+config_filter_add_new_filter(struct config_parser_context *ctx,
+ const char *key, const char *value)
{
struct config_filter *filter = &ctx->cur_section->filter;
struct config_filter *parent = &ctx->cur_section->prev->filter;
struct config_filter_parser *parser;
+ const char *error;
if (strcmp(key, "protocol") == 0) {
if (parent->service != NULL)
- *error_r = "protocol must not be under protocol";
+ ctx->error = "protocol must not be under protocol";
else
filter->service = p_strdup(ctx->pool, value);
} else if (strcmp(key, "local") == 0) {
if (parent->remote_bits > 0)
- *error_r = "local must not be under remote";
+ ctx->error = "local must not be under remote";
else if (parent->service != NULL)
- *error_r = "local must not be under protocol";
+ ctx->error = "local must not be under protocol";
else if (config_parse_net(ctx, value, &filter->local_host,
&filter->local_net,
- &filter->local_bits, error_r) < 0)
- ;
+ &filter->local_bits, &error) < 0)
+ ctx->error = p_strdup(ctx->pool, error);
else if (parent->local_bits > filter->local_bits ||
(parent->local_bits > 0 &&
!net_is_in_network(&filter->local_net,
&parent->local_net,
parent->local_bits)))
- *error_r = "local not a subset of parent local";
+ ctx->error = "local not a subset of parent local";
} else if (strcmp(key, "remote") == 0) {
if (parent->service != NULL)
- *error_r = "remote must not be under protocol";
+ ctx->error = "remote must not be under protocol";
else if (config_parse_net(ctx, value, &filter->remote_host,
&filter->remote_net,
- &filter->remote_bits, error_r) < 0)
- ;
+ &filter->remote_bits, &error) < 0)
+ ctx->error = p_strdup(ctx->pool, error);
else if (parent->remote_bits > filter->remote_bits ||
(parent->remote_bits > 0 &&
!net_is_in_network(&filter->remote_net,
&parent->remote_net,
parent->remote_bits)))
- *error_r = "remote not a subset of parent remote";
+ ctx->error = "remote not a subset of parent remote";
} else {
return FALSE;
}
@@ -303,7 +271,7 @@
}
static int
-config_filter_parser_check(struct parser_context *ctx,
+config_filter_parser_check(struct config_parser_context *ctx,
const struct config_module_parser *p,
const char **error_r)
{
@@ -316,7 +284,7 @@
}
static int
-config_all_parsers_check(struct parser_context *ctx,
+config_all_parsers_check(struct config_parser_context *ctx,
struct config_filter_context *new_filter,
const char **error_r)
{
@@ -372,7 +340,7 @@
return ret < 0 ? -1 : 0;
}
-static int settings_add_include(struct parser_context *ctx, const char *path,
+static int settings_add_include(struct config_parser_context *ctx, const char *path,
bool ignore_errors, const char **error_r)
{
struct input_stack *tmp, *new_input;
@@ -406,9 +374,10 @@
}
static int
-settings_include(struct parser_context *ctx, const char *pattern,
- bool ignore_errors, const char **error_r)
+settings_include(struct config_parser_context *ctx, const char *pattern,
+ bool ignore_errors)
{
+ const char *error;
#ifdef HAVE_GLOB
glob_t globbers;
unsigned int i;
@@ -417,48 +386,43 @@
case 0:
break;
case GLOB_NOSPACE:
- *error_r = "glob() failed: Not enough memory";
+ ctx->error = "glob() failed: Not enough memory";
return -1;
case GLOB_ABORTED:
- *error_r = "glob() failed: Read error";
+ ctx->error = "glob() failed: Read error";
return -1;
case GLOB_NOMATCH:
if (ignore_errors)
return 0;
- *error_r = "No matches";
+ ctx->error = "No matches";
return -1;
default:
- *error_r = "glob() failed: Unknown error";
+ ctx->error = "glob() failed: Unknown error";
return -1;
}
/* iterate throuth the different files matching the globbing */
for (i = 0; i < globbers.gl_pathc; i++) {
if (settings_add_include(ctx, globbers.gl_pathv[i],
- ignore_errors, error_r) < 0)
+ ignore_errors, &error) < 0) {
+ ctx->error = p_strdup(ctx->pool, error);
return -1;
+ }
}
globfree(&globbers);
return 0;
#else
- return settings_add_include(ctx, pattern, ignore_errors, error_r);
+ if (settings_add_include(ctx, pattern, ignore_errors, &error) < 0) {
+ ctx->error = p_strdup(ctx->pool, error);
+ return -1;
+ }
+ return 0;
#endif
}
-enum config_line_type {
- CONFIG_LINE_TYPE_SKIP,
- CONFIG_LINE_TYPE_ERROR,
- CONFIG_LINE_TYPE_KEYVALUE,
- CONFIG_LINE_TYPE_KEYFILE,
- CONFIG_LINE_TYPE_KEYVARIABLE,
- CONFIG_LINE_TYPE_SECTION_BEGIN,
- CONFIG_LINE_TYPE_SECTION_END,
- CONFIG_LINE_TYPE_INCLUDE,
- CONFIG_LINE_TYPE_INCLUDE_TRY
-};
-
static enum config_line_type
-config_parse_line(struct parser_context *ctx, char *line, string_t *full_line,
More information about the dovecot-cvs
mailing list