dovecot-2.0: module_dir_load*() API changed to take settings str...

dovecot at dovecot.org dovecot at dovecot.org
Mon Dec 7 22:31:24 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/55c42d2f7002
changeset: 10422:55c42d2f7002
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Dec 07 15:31:18 2009 -0500
description:
module_dir_load*() API changed to take settings struct, with debug field.
Fixed debug logging to also go from info log to debug log.

diffstat:

6 files changed, 66 insertions(+), 37 deletions(-)
src/auth/main.c                        |   12 +++++++--
src/config/config-parser.c             |    4 ++-
src/dict/main.c                        |    8 ++++--
src/lib-storage/mail-storage-service.c |   20 ++++++++++-----
src/lib/module-dir.c                   |   41 ++++++++++++++------------------
src/lib/module-dir.h                   |   18 ++++++++++----

diffs (284 lines):

diff -r abe02cf3bd47 -r 55c42d2f7002 src/auth/main.c
--- a/src/auth/main.c	Mon Dec 07 15:06:27 2009 -0500
+++ b/src/auth/main.c	Mon Dec 07 15:31:18 2009 -0500
@@ -39,6 +39,8 @@ static ARRAY_DEFINE(listen_fd_types, enu
 
 static void main_preinit(struct auth_settings *set)
 {
+	struct module_dir_load_settings mod_set;
+
 	/* Open /dev/urandom before chrooting */
 	random_init();
 
@@ -50,9 +52,15 @@ static void main_preinit(struct auth_set
 	   only by root. Also load all modules here. */
 	passdbs_init();
 	userdbs_init();
-	modules = module_dir_load(AUTH_MODULE_DIR, NULL, TRUE,
-			master_service_get_version_string(master_service));
+
+	memset(&mod_set, 0, sizeof(mod_set));
+	mod_set.version = master_service_get_version_string(master_service);
+	mod_set.require_init_funcs = TRUE;
+	mod_set.debug = set->debug;
+
+	modules = module_dir_load(AUTH_MODULE_DIR, NULL, &mod_set);
 	module_dir_init(modules);
+
 	auth = auth_preinit(set);
 
 	/* Password lookups etc. may require roots, allow it. */
diff -r abe02cf3bd47 -r 55c42d2f7002 src/config/config-parser.c
--- a/src/config/config-parser.c	Mon Dec 07 15:06:27 2009 -0500
+++ b/src/config/config-parser.c	Mon Dec 07 15:31:18 2009 -0500
@@ -754,6 +754,7 @@ prevfile:
 
 void config_parse_load_modules(void)
 {
+	struct module_dir_load_settings mod_set;
 	struct module *modules, *m;
 	const struct setting_parser_info **roots;
 	ARRAY_DEFINE(new_roots, const struct setting_parser_info *);
@@ -761,7 +762,8 @@ void config_parse_load_modules(void)
 	struct service_settings *const *services, *service_set;
 	unsigned int i, count;
 
-	modules = module_dir_load(CONFIG_MODULE_DIR, NULL, FALSE, NULL);
+	memset(&mod_set, 0, sizeof(mod_set));
+	modules = module_dir_load(CONFIG_MODULE_DIR, NULL, &mod_set);
 	module_dir_init(modules);
 
 	i_array_init(&new_roots, 64);
diff -r abe02cf3bd47 -r 55c42d2f7002 src/dict/main.c
--- a/src/dict/main.c	Mon Dec 07 15:06:27 2009 -0500
+++ b/src/dict/main.c	Mon Dec 07 15:31:18 2009 -0500
@@ -41,6 +41,7 @@ static void main_preinit(void)
 
 static void main_init(void)
 {
+	struct module_dir_load_settings mod_set;
 	void **sets;
 
 	sets = master_service_settings_get_others(master_service);
@@ -52,8 +53,11 @@ static void main_init(void)
 				    NULL));
 	}
 
-	modules = module_dir_load(DICT_MODULE_DIR, NULL, TRUE,
-			master_service_get_version_string(master_service));
+	memset(&mod_set, 0, sizeof(mod_set));
+	mod_set.version = master_service_get_version_string(master_service);
+	mod_set.require_init_funcs = TRUE;
+
+	modules = module_dir_load(DICT_MODULE_DIR, NULL, &mod_set);
 	module_dir_init(modules);
 
 	/* Register only after loading modules. They may contain SQL drivers,
diff -r abe02cf3bd47 -r 55c42d2f7002 src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Mon Dec 07 15:06:27 2009 -0500
+++ b/src/lib-storage/mail-storage-service.c	Mon Dec 07 15:31:18 2009 -0500
@@ -643,17 +643,25 @@ mail_storage_service_first_init(struct m
 
 static void
 mail_storage_service_load_modules(struct mail_storage_service_ctx *ctx,
+				  const struct setting_parser_info *user_info,
 				  const struct mail_user_settings *user_set)
 {
-	const char *version;
+	const struct mail_storage_settings *mail_set;
+	struct module_dir_load_settings mod_set;
 
 	if (*user_set->mail_plugins == '\0')
 		return;
 
-	version = master_service_get_version_string(ctx->service);
+	mail_set = mail_user_set_get_driver_settings(user_info, user_set,
+						MAIL_STORAGE_SET_DRIVER_NAME);
+
+	memset(&mod_set, 0, sizeof(mod_set));
+	mod_set.version = master_service_get_version_string(ctx->service);
+	mod_set.require_init_funcs = TRUE;
+	mod_set.debug = mail_set->mail_debug;
+
 	modules = module_dir_load_missing(modules, user_set->mail_plugin_dir,
-					  user_set->mail_plugins, TRUE,
-					  version);
+					  user_set->mail_plugins, &mod_set);
 }
 
 int mail_storage_service_lookup(struct mail_storage_service_ctx *ctx,
@@ -684,7 +692,7 @@ int mail_storage_service_lookup(struct m
 	if (ctx->conn == NULL)
 		mail_storage_service_first_init(ctx, user_info, user_set);
 	/* load global plugins */
-	mail_storage_service_load_modules(ctx, user_set);
+	mail_storage_service_load_modules(ctx, user_info, user_set);
 
 	temp_pool = pool_alloconly_create("userdb lookup", 1024);
 	if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0) {
@@ -727,7 +735,7 @@ int mail_storage_service_lookup(struct m
 	pool_unref(&temp_pool);
 
 	/* load per-user plugins */
-	mail_storage_service_load_modules(ctx, user->user_set);
+	mail_storage_service_load_modules(ctx, user_info, user->user_set);
 
 	*user_r = user;
 	return ret;
diff -r abe02cf3bd47 -r 55c42d2f7002 src/lib/module-dir.c
--- a/src/lib/module-dir.c	Mon Dec 07 15:06:27 2009 -0500
+++ b/src/lib/module-dir.c	Mon Dec 07 15:31:18 2009 -0500
@@ -117,8 +117,9 @@ module_check_missing_dependencies(struct
 }
 
 static struct module *
-module_load(const char *path, const char *name, bool require_init_funcs,
-	    const char *version, struct module *all_modules)
+module_load(const char *path, const char *name,
+	    const struct module_dir_load_settings *set,
+	    struct module *all_modules)
 {
 	void *handle;
 	struct module *module;
@@ -135,10 +136,10 @@ module_load(const char *path, const char
 	module->name = i_strdup(name);
 	module->handle = handle;
 
-	module_version = version == NULL ? NULL :
+	module_version = set->version == NULL ? NULL :
 		get_symbol(module, t_strconcat(name, "_version", NULL), TRUE);
 	if (module_version != NULL &&
-	    strcmp(*module_version, version) != 0) {
+	    strcmp(*module_version, set->version) != 0) {
 		i_error("Module is for different version %s: %s",
 			*module_version, path);
 		module_free(module);
@@ -148,13 +149,13 @@ module_load(const char *path, const char
 	/* get our init func */
 	module->init = (void (*)(struct module *))
 		get_symbol(module, t_strconcat(name, "_init", NULL),
-			   !require_init_funcs);
+			   !set->require_init_funcs);
 	module->deinit = module->init == NULL ? NULL : (void (*)(void))
 		get_symbol(module, t_strconcat(name, "_deinit", NULL),
-			   !require_init_funcs);
+			   !set->require_init_funcs);
 
 	if ((module->init == NULL || module->deinit == NULL) &&
-	    require_init_funcs) {
+	    set->require_init_funcs) {
 		i_error("Module doesn't have %s function: %s",
 			module->init == NULL ? "init" : "deinit", path);
 		module->deinit = NULL;
@@ -168,8 +169,8 @@ module_load(const char *path, const char
 		return NULL;
 	}
 
-	if (getenv("DEBUG") != NULL)
-		i_info("Module loaded: %s", path);
+	if (set->debug)
+		i_debug("Module loaded: %s", path);
 	return module;
 }
 
@@ -246,7 +247,7 @@ static struct module *
 static struct module *
 module_dir_load_real(struct module *old_modules,
 		     const char *dir, const char **module_names,
-		     bool require_init_funcs, const char *version)
+		     const struct module_dir_load_settings *set)
 {
 	DIR *dirp;
 	struct dirent *d;
@@ -256,8 +257,8 @@ module_dir_load_real(struct module *old_
 	ARRAY_TYPE(const_string) names;
 	pool_t pool;
 
-	if (getenv("DEBUG") != NULL)
-		i_info("Loading modules from directory: %s", dir);
+	if (set->debug)
+		i_debug("Loading modules from directory: %s", dir);
 
 	dirp = opendir(dir);
 	if (dirp == NULL) {
@@ -317,9 +318,7 @@ module_dir_load_real(struct module *old_
 			module = NULL;
 		else {
 			path = t_strconcat(dir, "/", name, NULL);
-			module = module_load(path, stripped_name,
-					     require_init_funcs, version,
-					     modules);
+			module = module_load(path, stripped_name, set, modules);
 			if (module == NULL && module_names != NULL)
 				i_fatal("Couldn't load required plugins");
 		}
@@ -348,16 +347,15 @@ module_dir_load_real(struct module *old_
 }
 
 struct module *module_dir_load(const char *dir, const char *module_names,
-			       bool require_init_funcs, const char *version)
-{
-	return module_dir_load_missing(NULL, dir, module_names,
-				       require_init_funcs, version);
+			       const struct module_dir_load_settings *set)
+{
+	return module_dir_load_missing(NULL, dir, module_names, set);
 }
 
 struct module *
 module_dir_load_missing(struct module *old_modules,
 			const char *dir, const char *module_names,
-			bool require_init_funcs, const char *version)
+			const struct module_dir_load_settings *set)
 {
 	struct module *modules;
 
@@ -365,8 +363,7 @@ module_dir_load_missing(struct module *o
 		const char **arr = module_names == NULL ? NULL :
 			t_strsplit_spaces(module_names, ", ");
 
-		modules = module_dir_load_real(old_modules, dir, arr,
-					       require_init_funcs, version);
+		modules = module_dir_load_real(old_modules, dir, arr, set);
 	} T_END;
 	return modules;
 }
diff -r abe02cf3bd47 -r 55c42d2f7002 src/lib/module-dir.h
--- a/src/lib/module-dir.h	Mon Dec 07 15:06:27 2009 -0500
+++ b/src/lib/module-dir.h	Mon Dec 07 15:31:18 2009 -0500
@@ -1,5 +1,16 @@
 #ifndef MODULE_DIR_H
 #define MODULE_DIR_H
+
+struct module_dir_load_settings {
+	/* If version is non-NULL and the module contains a version symbol,
+	   fail the load if they're different. */
+	const char *version;
+
+	/* Require all plugins to have <plugin_name>_init() function */
+	unsigned int require_init_funcs:1;
+	/* Enable debug logging */
+	unsigned int debug:1;
+};
 
 struct module {
 	char *path, *name;
@@ -14,15 +25,14 @@ struct module {
 };
 
 /* Load modules in given directory. module_names is a space separated list of
-   module names to load, or NULL to load everything. If version is non-NULL and
-   the module contains a version symbol, fail the load if they're different. */
+   module names to load, or NULL to load everything. */
 struct module *module_dir_load(const char *dir, const char *module_names,
-			       bool require_init_funcs, const char *version);
+			       const struct module_dir_load_settings *set);
 /* Load modules that aren't already loaded. */
 struct module *
 module_dir_load_missing(struct module *old_modules,
 			const char *dir, const char *module_names,
-			bool require_init_funcs, const char *version);
+			const struct module_dir_load_settings *set);
 /* Call init() in all modules */
 void module_dir_init(struct module *modules);
 /* Call deinit() in all modules and mark them NULL so module_dir_unload()


More information about the dovecot-cvs mailing list