dovecot-1.3: Moved most of the dict settings handling to dict bi...

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 21 20:35:13 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.3/rev/6d374fc3ae1d
changeset: 9149:6d374fc3ae1d
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 20 19:33:41 2009 -0400
description:
Moved most of the dict settings handling to dict binary.

diffstat:

8 files changed, 110 insertions(+), 30 deletions(-)
src/dict/Makefile.am         |    5 ++-
src/dict/dict-server.c       |   13 +++++++-
src/dict/dict-settings.c     |   65 ++++++++++++++++++++++++++++++++++++++++++
src/dict/dict-settings.h     |   13 ++++++++
src/dict/main.c              |   12 ++++++-
src/master/dict-process.c    |   24 +++------------
src/master/master-settings.c |    5 ---
src/master/master-settings.h |    3 -

diffs (281 lines):

diff -r e3f61d434616 -r 6d374fc3ae1d src/dict/Makefile.am
--- a/src/dict/Makefile.am	Mon Apr 20 19:11:50 2009 -0400
+++ b/src/dict/Makefile.am	Mon Apr 20 19:33:41 2009 -0400
@@ -4,6 +4,7 @@ pkglibexec_PROGRAMS = dict
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-settings \
 	-I$(top_srcdir)/src/lib-dict \
 	-I$(top_srcdir)/src/lib-sql \
 	-DDICT_MODULE_DIR=\""$(moduledir)/dict"\" \
@@ -25,7 +26,9 @@ dict_DEPENDENCIES = $(libs)
 
 dict_SOURCES = \
 	dict-server.c \
+	dict-settings.c \
 	main.c
 
 noinst_HEADERS = \
-	dict-server.h
+	dict-server.h \
+	dict-settings.h
diff -r e3f61d434616 -r 6d374fc3ae1d src/dict/dict-server.c
--- a/src/dict/dict-server.c	Mon Apr 20 19:11:50 2009 -0400
+++ b/src/dict/dict-server.c	Mon Apr 20 19:33:41 2009 -0400
@@ -8,6 +8,7 @@
 #include "ostream.h"
 #include "str.h"
 #include "dict.h"
+#include "dict-settings.h"
 #include "dict-client.h"
 #include "dict-server.h"
 
@@ -395,14 +396,22 @@ static int dict_client_parse_handshake(s
 
 static int dict_client_dict_init(struct dict_client_connection *conn)
 {
+	const char *const *strlist;
+	unsigned int i, count;
 	const char *uri;
 
-	uri = getenv(t_strconcat("DICT_", conn->name, NULL));
-	if (uri == NULL) {
+	strlist = array_get(&dict_settings->dicts, &count);
+	for (i = 0; i < count; i += 2) {
+		if (strcmp(strlist[i], conn->name) == 0)
+			break;
+	}
+
+	if (i == count) {
 		i_error("dict client: Unconfigured dictionary name '%s'",
 			conn->name);
 		return -1;
 	}
+	uri = strlist[i+1];
 
 	conn->dict = dict_init(uri, conn->value_type, conn->username);
 	if (conn->dict == NULL) {
diff -r e3f61d434616 -r 6d374fc3ae1d src/dict/dict-settings.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dict/dict-settings.c	Mon Apr 20 19:33:41 2009 -0400
@@ -0,0 +1,65 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "settings-parser.h"
+#include "dict-settings.h"
+
+#undef DEF
+#define DEF(type, name) \
+	{ type, #name, offsetof(struct dict_settings, name), NULL }
+
+static struct setting_define dict_setting_defines[] = {
+	DEF(SET_STR, dict_db_config),
+	{ SET_STRLIST, "dict", offsetof(struct dict_settings, dicts), NULL },
+
+	SETTING_DEFINE_LIST_END
+};
+
+struct dict_settings dict_default_settings = {
+	MEMBER(dict_db_config) "",
+	MEMBER(dicts) ARRAY_INIT
+};
+
+struct setting_parser_info dict_setting_parser_info = {
+	MEMBER(defines) dict_setting_defines,
+	MEMBER(defaults) &dict_default_settings,
+
+	MEMBER(parent) NULL,
+	MEMBER(dynamic_parsers) NULL,
+
+	MEMBER(parent_offset) (size_t)-1,
+	MEMBER(type_offset) (size_t)-1,
+	MEMBER(struct_size) sizeof(struct dict_settings)
+};
+
+struct dict_settings *dict_settings;
+
+static pool_t settings_pool = NULL;
+
+struct dict_settings *dict_settings_read(void)
+{
+	struct setting_parser_context *parser;
+	struct dict_settings *set;
+	const char *error;
+
+	if (settings_pool == NULL)
+		settings_pool = pool_alloconly_create("auth settings", 1024);
+	else
+		p_clear(settings_pool);
+
+	parser = settings_parser_init(settings_pool,
+				      &dict_setting_parser_info,
+				      SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS);
+
+	if (settings_parse_environ(parser) < 0) {
+		i_fatal("Error reading configuration: %s",
+			settings_parser_get_error(parser));
+	}
+
+	if (settings_parser_check(parser, settings_pool, &error) < 0)
+		i_fatal("Invalid settings: %s", error);
+
+	set = settings_parser_get(parser);
+	settings_parser_deinit(&parser);
+	return set;
+}
diff -r e3f61d434616 -r 6d374fc3ae1d src/dict/dict-settings.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dict/dict-settings.h	Mon Apr 20 19:33:41 2009 -0400
@@ -0,0 +1,13 @@
+#ifndef DICT_SETTINGS_H
+#define DICT_SETTINGS_H
+
+struct dict_settings {
+	const char *dict_db_config;
+	ARRAY_DEFINE(dicts, const char *);
+};
+
+extern struct dict_settings *dict_settings;
+
+struct dict_settings *dict_settings_read(void);
+
+#endif
diff -r e3f61d434616 -r 6d374fc3ae1d src/dict/main.c
--- a/src/dict/main.c	Mon Apr 20 19:11:50 2009 -0400
+++ b/src/dict/main.c	Mon Apr 20 19:33:41 2009 -0400
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "lib-signals.h"
 #include "ioloop.h"
+#include "env-util.h"
 #include "fd-close-on-exec.h"
 #include "restrict-access.h"
 #include "randgen.h"
@@ -10,11 +11,11 @@
 #include "dict.h"
 #include "dict-client.h"
 #include "dict-server.h"
+#include "dict-settings.h"
 #include "module-dir.h"
 
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 
 #define DICT_MASTER_LISTENER_FD 3
 
@@ -79,6 +80,14 @@ static void main_init(void)
         lib_signals_ignore(SIGPIPE, TRUE);
         lib_signals_ignore(SIGALRM, FALSE);
 
+	dict_settings = dict_settings_read();
+
+	if (*dict_settings->dict_db_config != '\0') {
+		/* for berkeley db library */
+		env_put(t_strconcat("DB_CONFIG=", dict_settings->dict_db_config,
+				    NULL));
+	}
+
 	/* If master dies, the log fd gets closed and we'll quit */
 	log_io = io_add(STDERR_FILENO, IO_ERROR, log_error_callback, NULL);
 
@@ -109,7 +118,6 @@ static void main_deinit(void)
 	sql_drivers_deinit();
 	random_deinit();
 	lib_signals_deinit();
-	closelog();
 }
 
 int main(void)
diff -r e3f61d434616 -r 6d374fc3ae1d src/master/dict-process.c
--- a/src/master/dict-process.c	Mon Apr 20 19:11:50 2009 -0400
+++ b/src/master/dict-process.c	Mon Apr 20 19:33:41 2009 -0400
@@ -39,8 +39,8 @@ static int dict_process_create(struct di
 {
 	struct dict_process *process;
 	struct log_io *log;
-	const char *executable, *const *dicts;
-	unsigned int i, count;
+	const char *executable;
+	unsigned int i;
 	int log_fd;
 	pid_t pid;
 
@@ -100,19 +100,9 @@ static int dict_process_create(struct di
 		fd_close_on_exec(i, FALSE);
 
 	child_process_init_env(master_set->defaults);
+	master_settings_export_to_env(master_set->defaults);
 	env_put(t_strconcat("DICT_LISTEN_FROM_FD=",
 			    process->listener->path, NULL));
-
-	if (master_set->defaults->dict_db_config != NULL) {
-		env_put(t_strconcat("DB_CONFIG=",
-				    master_set->defaults->dict_db_config,
-				    NULL));
-	}
-
-	dicts = array_get(&master_set->defaults->dicts, &count);
-	i_assert((count % 2) == 0);
-	for (i = 0; i < count; i += 2)
-		env_put(t_strdup_printf("DICT_%s=%s", dicts[i], dicts[i+1]));
 
 	executable = PKG_LIBEXECDIR"/dict";
 	client_process_exec(executable, "");
@@ -152,11 +142,9 @@ static void dict_listener_input(struct d
 
 	i_assert(listener->processes == NULL);
 
-	if (array_is_created(&master_set->defaults->dicts)) {
-		for (i = 0; i < master_set->defaults->dict_process_count; i++) {
-			if (dict_process_create(listener) < 0)
-				break;
-		}
+	for (i = 0; i < master_set->defaults->dict_process_count; i++) {
+		if (dict_process_create(listener) < 0)
+			break;
 	}
 	if (i > 0)
 		io_remove(&listener->io);
diff -r e3f61d434616 -r 6d374fc3ae1d src/master/master-settings.c
--- a/src/master/master-settings.c	Mon Apr 20 19:11:50 2009 -0400
+++ b/src/master/master-settings.c	Mon Apr 20 19:33:41 2009 -0400
@@ -198,10 +198,8 @@ static struct setting_define master_sett
 	DEF(SET_UINT, mail_log_max_lines_per_sec),
 
 	/* dict */
-	DEF(SET_STR, dict_db_config),
 	DEF(SET_UINT, dict_process_count),
 	DEFLIST(auths, "auth", &master_auth_setting_parser_info),
-	{ SET_STRLIST, "dict", offsetof(struct master_settings, dicts), NULL },
 
 	SETTING_DEFINE_LIST_END
 };
@@ -267,8 +265,7 @@ struct master_settings master_default_se
 	MEMBER(mail_log_max_lines_per_sec) 10,
 
 	/* dict */
-	MEMBER(dict_db_config) NULL,
-	MEMBER(dict_process_count) 1,
+	MEMBER(dict_process_count) 1
 
 	/* .. */
 };
diff -r e3f61d434616 -r 6d374fc3ae1d src/master/master-settings.h
--- a/src/master/master-settings.h	Mon Apr 20 19:11:50 2009 -0400
+++ b/src/master/master-settings.h	Mon Apr 20 19:33:41 2009 -0400
@@ -109,12 +109,9 @@ struct master_settings {
 	unsigned int mail_log_max_lines_per_sec;
 
 	/* dict */
-	const char *dict_db_config;
 	unsigned int dict_process_count;
 
 	ARRAY_DEFINE(auths, struct master_auth_settings *);
-
-	ARRAY_DEFINE(dicts, const char *);
 
 #ifndef CONFIG_BINARY
 	/* .. */


More information about the dovecot-cvs mailing list