dovecot-1.3: imap and pop3 now use mail-storage-service API.

dovecot at dovecot.org dovecot at dovecot.org
Sun Apr 12 06:34:33 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.3/rev/e560b92ed763
changeset: 9080:e560b92ed763
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Apr 11 23:34:26 2009 -0400
description:
imap and pop3 now use mail-storage-service API.

diffstat:

15 files changed, 138 insertions(+), 466 deletions(-)
src/imap/Makefile.am                   |    1 
src/imap/client.c                      |    3 
src/imap/common.h                      |    2 
src/imap/imap-settings.c               |   65 ---------
src/imap/imap-settings.h               |    3 
src/imap/main.c                        |  222 ++++++++------------------------
src/lib-storage/mail-storage-service.c |   27 ++-
src/lib-storage/mail-storage-service.h |    4 
src/master/child-process.c             |    1 
src/pop3/Makefile.am                   |    1 
src/pop3/client.c                      |    3 
src/pop3/common.h                      |    2 
src/pop3/main.c                        |  200 ++++++----------------------
src/pop3/pop3-settings.c               |   67 ---------
src/pop3/pop3-settings.h               |    3 

diffs (truncated from 918 to 300 lines):

diff -r a817f39d255f -r e560b92ed763 src/imap/Makefile.am
--- a/src/imap/Makefile.am	Sat Apr 11 23:23:34 2009 -0400
+++ b/src/imap/Makefile.am	Sat Apr 11 23:34:26 2009 -0400
@@ -6,6 +6,7 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
 	-I$(top_srcdir)/src/lib-settings \
 	-I$(top_srcdir)/src/lib-dict \
+	-I$(top_srcdir)/src/lib-master \
 	-I$(top_srcdir)/src/lib-mail \
 	-I$(top_srcdir)/src/lib-imap \
 	-I$(top_srcdir)/src/lib-index \
diff -r a817f39d255f -r e560b92ed763 src/imap/client.c
--- a/src/imap/client.c	Sat Apr 11 23:23:34 2009 -0400
+++ b/src/imap/client.c	Sat Apr 11 23:34:26 2009 -0400
@@ -8,6 +8,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "var-expand.h"
+#include "master-service.h"
 #include "imap-resp-code.h"
 #include "imap-util.h"
 #include "mail-namespace.h"
@@ -203,7 +204,7 @@ void client_destroy(struct client *clien
 
 	/* quit the program */
 	my_client = NULL;
-	io_loop_stop(ioloop);
+	master_service_stop(service);
 }
 
 void client_disconnect(struct client *client, const char *reason)
diff -r a817f39d255f -r e560b92ed763 src/imap/common.h
--- a/src/imap/common.h	Sat Apr 11 23:23:34 2009 -0400
+++ b/src/imap/common.h	Sat Apr 11 23:34:26 2009 -0400
@@ -23,7 +23,7 @@ enum client_workarounds {
 #include "client.h"
 #include "imap-settings.h"
 
-extern struct ioloop *ioloop;
+extern struct master_service *service;
 
 extern void (*hook_client_created)(struct client **client);
 
diff -r a817f39d255f -r e560b92ed763 src/imap/imap-settings.c
--- a/src/imap/imap-settings.c	Sat Apr 11 23:23:34 2009 -0400
+++ b/src/imap/imap-settings.c	Sat Apr 11 23:34:26 2009 -0400
@@ -59,68 +59,3 @@ struct setting_parser_info imap_setting_
 	MEMBER(struct_size) sizeof(struct imap_settings),
 	MEMBER(check_func) NULL
 };
-
-static pool_t settings_pool = NULL;
-
-static void
-parse_expand_vars(struct setting_parser_context *parser, const char *value)
-{
-	const char *const *expanded;
-
-	expanded = t_strsplit(value, " ");
-	settings_parse_set_keys_expandeded(parser, settings_pool, expanded);
-	/* settings from userdb are in the VARS_EXPANDED list. for each
-	   unknown setting in the list assume it's a plugin setting. */
-	for (; *expanded != NULL; expanded++) {
-		if (settings_parse_is_valid_key(parser, *expanded))
-			continue;
-
-		value = getenv(t_str_ucase(*expanded));
-		if (value == NULL)
-			continue;
-
-		settings_parse_line(parser, t_strconcat("plugin/", *expanded,
-							"=", value, NULL));
-	}
-}
-
-void imap_settings_read(const struct imap_settings **set_r,
-			const struct mail_user_settings **user_set_r)
-{
-	static const struct setting_parser_info *roots[] = {
-                &imap_setting_parser_info,
-                &mail_user_setting_parser_info
-	};
-	struct setting_parser_context *parser;
-	const char *value, *error;
-	void **sets;
-
-	if (settings_pool == NULL)
-		settings_pool = pool_alloconly_create("imap settings", 4096);
-	else
-		p_clear(settings_pool);
-
-	settings_parser_info_update(settings_pool,
-				    mail_storage_get_dynamic_parsers());
-
-	parser = settings_parser_init_list(settings_pool,
-				roots, N_ELEMENTS(roots),
-				SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS);
-
-	if (settings_parse_environ(parser) < 0) {
-		i_fatal("Error reading configuration: %s",
-			settings_parser_get_error(parser));
-	}
-
-	value = getenv("VARS_EXPANDED");
-	if (value != NULL)
-		parse_expand_vars(parser, value);
-
-	if (settings_parser_check(parser, settings_pool, &error) < 0)
-		i_fatal("Invalid settings: %s", error);
-
-	sets = settings_parser_get_list(parser);
-	*set_r = sets[0];
-	*user_set_r = sets[1];
-	settings_parser_deinit(&parser);
-}
diff -r a817f39d255f -r e560b92ed763 src/imap/imap-settings.h
--- a/src/imap/imap-settings.h	Sat Apr 11 23:23:34 2009 -0400
+++ b/src/imap/imap-settings.h	Sat Apr 11 23:34:26 2009 -0400
@@ -17,7 +17,6 @@ struct imap_settings {
 	const char *imap_id_log;
 };
 
-void imap_settings_read(const struct imap_settings **set_r,
-			const struct mail_user_settings **user_set_r);
+extern struct setting_parser_info imap_setting_parser_info;
 
 #endif
diff -r a817f39d255f -r e560b92ed763 src/imap/main.c
--- a/src/imap/main.c	Sat Apr 11 23:23:34 2009 -0400
+++ b/src/imap/main.c	Sat Apr 11 23:34:26 2009 -0400
@@ -2,25 +2,21 @@
 
 #include "common.h"
 #include "ioloop.h"
-#include "network.h"
+#include "istream.h"
 #include "ostream.h"
 #include "str.h"
 #include "base64.h"
-#include "istream.h"
-#include "lib-signals.h"
 #include "restrict-access.h"
 #include "fd-close-on-exec.h"
 #include "process-title.h"
-#include "module-dir.h"
-#include "dict.h"
-#include "mail-storage.h"
+#include "master-service.h"
+#include "mail-user.h"
+#include "mail-storage-service.h"
 #include "commands.h"
-#include "mail-namespace.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 
 #define IS_STANDALONE() \
         (getenv("IMAPLOGINTAG") == NULL)
@@ -38,33 +34,17 @@ static struct client_workaround_list cli
 	{ NULL, 0 }
 };
 
-struct ioloop *ioloop;
-
 static struct io *log_io = NULL;
-static struct module *modules = NULL;
-static char log_prefix[128]; /* syslog() needs this to be permanent */
-
+
+struct master_service *service;
 void (*hook_client_created)(struct client **client) = NULL;
-
-static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED)
-{
-	/* warn about being killed because of some signal, except SIGINT (^C)
-	   which is too common at least while testing :) */
-	if (si->si_signo != SIGINT) {
-		i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)",
-			  si->si_signo, dec2str(si->si_pid),
-			  dec2str(si->si_uid),
-			  lib_signal_code_to_str(si->si_signo, si->si_code));
-	}
-	io_loop_stop(ioloop);
-}
 
 static void log_error_callback(void *context ATTR_UNUSED)
 {
 	/* the log fd is closed, don't die when trying to log later */
 	i_set_failure_ignore_errors(TRUE);
 
-	io_loop_stop(ioloop);
+	master_service_stop(service);
 }
 
 static enum client_workarounds
@@ -90,111 +70,12 @@ parse_workarounds(const struct imap_sett
 	return client_workarounds;
 }
 
-static void open_logfile(void)
-{
-	const char *user;
-
-	if (getenv("LOG_TO_MASTER") != NULL) {
-		i_set_failure_internal();
-		return;
-	}
-
-	if (getenv("LOG_PREFIX") != NULL)
-		i_strocpy(log_prefix, getenv("LOG_PREFIX"), sizeof(log_prefix));
-	else {
-		user = getenv("USER");
-		if (user == NULL) {
-			if (IS_STANDALONE())
-				user = getlogin();
-			if (user == NULL)
-				user = "??";
-		}
-		if (strlen(user) >= sizeof(log_prefix)-6) {
-			/* quite a long user name, cut it */
-			user = t_strndup(user, sizeof(log_prefix)-6-2);
-			user = t_strconcat(user, "..", NULL);
-		}
-		i_snprintf(log_prefix, sizeof(log_prefix), "imap(%s): ", user);
-	}
-	if (getenv("USE_SYSLOG") != NULL) {
-		const char *env = getenv("SYSLOG_FACILITY");
-		i_set_failure_syslog(log_prefix, LOG_NDELAY,
-				     env == NULL ? LOG_MAIL : atoi(env));
-	} else {
-		/* log to file or stderr */
-		i_set_failure_file(getenv("LOGFILE"), log_prefix);
-	}
-
-	if (getenv("INFOLOGFILE") != NULL)
-		i_set_info_file(getenv("INFOLOGFILE"));
-
-	i_set_failure_timestamp_format(getenv("LOGSTAMP"));
-}
-
-static void main_preinit(const struct imap_settings **set_r,
-			 const struct mail_user_settings **user_set_r)
-{
-	const char *version;
-
-	version = getenv("DOVECOT_VERSION");
-	if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
-		i_fatal("Dovecot version mismatch: "
-			"Master is v%s, imap is v"PACKAGE_VERSION" "
-			"(if you don't care, set version_ignore=yes)", version);
-	}
-
-	/* Log file or syslog opening probably requires roots */
-	open_logfile();
-
-        mail_storage_init();
-	mail_storage_register_all();
-	mailbox_list_register_all();
-
-	/* read settings after registering storages so they can have their
-	   own setting definitions too */
-	imap_settings_read(set_r, user_set_r);
-
-	/* Load the plugins before chrooting. Their init() is called later. */
-	modules = *(*user_set_r)->mail_plugins == '\0' ? NULL :
-		module_dir_load((*user_set_r)->mail_plugin_dir,
-				(*user_set_r)->mail_plugins, TRUE, version);
-
-	restrict_access_by_env(getenv("HOME"), !IS_STANDALONE());
-	restrict_access_allow_coredumps(TRUE);
-}
-
-static void main_init(const struct imap_settings *set,
-		      const struct mail_user_settings *user_set)
+static void main_init(const struct imap_settings *set, struct mail_user *user,
+		      bool dump_capability)
 {
 	struct client *client;
 	struct ostream *output;
-	struct mail_user *user;
-	const char *username, *home, *str, *tag, *error;
-	bool dump_capability;
-
-	lib_signals_init();
-        lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
-        lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
-        lib_signals_ignore(SIGPIPE, TRUE);
-        lib_signals_ignore(SIGALRM, FALSE);
-	
-	dump_capability = getenv("DUMP_CAPABILITY") != NULL;
-
-	username = getenv("USER");
-	if (username == NULL) {
-		if (IS_STANDALONE())
-			username = getlogin();
-		if (username == NULL)
-			i_fatal("USER environment missing");
-	}


More information about the dovecot-cvs mailing list