dovecot-2.2: lib-storage: Added mail_user_get_storage_class(), w...

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 12 03:18:12 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/985ebfb17f35
changeset: 15207:985ebfb17f35
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 12 03:12:19 2012 +0300
description:
lib-storage: Added mail_user_get_storage_class(), which auto-loads storage plugins.
The auto-loading is done only if there's already a stub storage registered.

diffstat:

 src/lib-storage/index/shared/shared-storage.c |   2 +-
 src/lib-storage/mail-storage.c                |   2 +-
 src/lib-storage/mail-user.c                   |  54 +++++++++++++++++++++++++++
 src/lib-storage/mail-user.h                   |   5 ++
 4 files changed, 61 insertions(+), 2 deletions(-)

diffs (105 lines):

diff -r dbf88dc1b873 -r 985ebfb17f35 src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c	Fri Oct 12 03:09:27 2012 +0300
+++ b/src/lib-storage/index/shared/shared-storage.c	Fri Oct 12 03:12:19 2012 +0300
@@ -49,7 +49,7 @@
 		p_strdup(_storage->pool, ns->unexpanded_set->location);
 	storage->storage_class_name = p_strdup(_storage->pool, driver);
 
-	storage_class = mail_storage_find_class(driver);
+	storage_class = mail_user_get_storage_class(_storage->user, driver);
 	if (storage_class != NULL)
 		_storage->class_flags = storage_class->class_flags;
 	else if (strcmp(driver, "auto") != 0) {
diff -r dbf88dc1b873 -r 985ebfb17f35 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Fri Oct 12 03:09:27 2012 +0300
+++ b/src/lib-storage/mail-storage.c	Fri Oct 12 03:12:19 2012 +0300
@@ -144,7 +144,7 @@
 			list_set->root_dir = NULL;
 		}
 	} else {
-		storage_class = mail_storage_find_class(driver);
+		storage_class = mail_user_get_storage_class(ns->user, driver);
 		if (storage_class == NULL) {
 			*error_r = t_strdup_printf(
 				"Unknown mail storage driver %s", driver);
diff -r dbf88dc1b873 -r 985ebfb17f35 src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c	Fri Oct 12 03:09:27 2012 +0300
+++ b/src/lib-storage/mail-user.c	Fri Oct 12 03:12:19 2012 +0300
@@ -16,6 +16,7 @@
 #include "mountpoint-list.h"
 #include "mail-storage-settings.h"
 #include "mail-storage-private.h"
+#include "mail-storage-service.h"
 #include "mail-namespace.h"
 #include "mail-storage.h"
 #include "mail-user.h"
@@ -430,3 +431,56 @@
 	}
 	return TRUE;
 }
+
+static void
+mail_user_try_load_class_plugin(struct mail_user *user, const char *name)
+{
+	struct module_dir_load_settings mod_set;
+	struct module *module;
+	unsigned int name_len = strlen(name);
+
+	memset(&mod_set, 0, sizeof(mod_set));
+	mod_set.abi_version = DOVECOT_ABI_VERSION;
+	mod_set.binary_name = master_service_get_name(master_service);
+	mod_set.setting_name = "<built-in storage lookup>";
+	mod_set.require_init_funcs = TRUE;
+	mod_set.debug = user->mail_debug;
+
+	mail_storage_service_modules =
+		module_dir_load_missing(mail_storage_service_modules,
+					user->set->mail_plugin_dir,
+					name, &mod_set);
+	/* initialize the module (and only this module!) immediately so that
+	   the class gets registered */
+	for (module = mail_storage_service_modules; module != NULL; module = module->next) {
+		if (strncmp(module->name, name, name_len) == 0 &&
+		    strcmp(module->name + name_len, "_plugin") == 0) {
+			if (!module->initialized) {
+				module->initialized = TRUE;
+				module->init(module);
+			}
+			break;
+		}
+	}
+}
+
+struct mail_storage *
+mail_user_get_storage_class(struct mail_user *user, const char *name)
+{
+	struct mail_storage *storage;
+
+	storage = mail_storage_find_class(name);
+	if (storage == NULL || storage->v.alloc != NULL)
+		return storage;
+
+	/* it's implemented by a plugin. load it and check again. */
+	mail_user_try_load_class_plugin(user, name);
+
+	storage = mail_storage_find_class(name);
+	if (storage != NULL && storage->v.alloc == NULL) {
+		i_error("Storage driver '%s' exists as a stub, "
+			"but its plugin couldn't be loaded", name);
+		return NULL;
+	}
+	return storage;
+}
diff -r dbf88dc1b873 -r 985ebfb17f35 src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h	Fri Oct 12 03:09:27 2012 +0300
+++ b/src/lib-storage/mail-user.h	Fri Oct 12 03:12:19 2012 +0300
@@ -137,4 +137,9 @@
 bool mail_user_is_path_mounted(struct mail_user *user, const char *path,
 			       const char **error_r);
 
+/* Basically the same as mail_storage_find_class(), except automatically load
+   storage plugins when needed. */
+struct mail_storage *
+mail_user_get_storage_class(struct mail_user *user, const char *name);
+
 #endif


More information about the dovecot-cvs mailing list