dovecot-1.2: Shared mailboxes: Find the final storage before cal...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 8 01:02:03 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/7d484e0f0789
changeset: 8927:7d484e0f0789
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 07 17:54:32 2009 -0400
description:
Shared mailboxes: Find the final storage before calling mail_storage.mailbox_open(), not inside it.
This fixes some crashes with plugins.

diffstat:

6 files changed, 27 insertions(+), 32 deletions(-)
src/lib-storage/index/shared/shared-list.c    |   13 +++++++++++
src/lib-storage/index/shared/shared-storage.c |   29 -------------------------
src/lib-storage/list/mailbox-list-fs.c        |    1 
src/lib-storage/list/mailbox-list-maildir.c   |    2 +
src/lib-storage/mail-storage.c                |   12 ++++++----
src/lib-storage/mailbox-list-private.h        |    2 +

diffs (151 lines):

diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/index/shared/shared-list.c
--- a/src/lib-storage/index/shared/shared-list.c	Tue Apr 07 16:38:47 2009 -0400
+++ b/src/lib-storage/index/shared/shared-list.c	Tue Apr 07 17:54:32 2009 -0400
@@ -40,6 +40,18 @@ static void shared_list_copy_error(struc
 
 	str = mailbox_list_get_last_error(backend_ns->list, &error);
 	mailbox_list_set_error(shared_list, error, str);
+}
+
+static int
+shared_get_storage(struct mailbox_list *list, const char *name,
+		   struct mail_storage **storage_r)
+{
+	struct mail_namespace *ns;
+
+	if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
+		return -1;
+	*storage_r = ns->storage;
+	return 0;
 }
 
 static bool
@@ -292,6 +304,7 @@ struct mailbox_list shared_mailbox_list 
 	{
 		shared_list_alloc,
 		shared_list_deinit,
+		shared_get_storage,
 		shared_is_valid_pattern,
 		shared_is_valid_existing_name,
 		shared_is_valid_create_name,
diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c	Tue Apr 07 16:38:47 2009 -0400
+++ b/src/lib-storage/index/shared/shared-storage.c	Tue Apr 07 17:54:32 2009 -0400
@@ -274,33 +274,6 @@ static void shared_mailbox_copy_error(st
 	mail_storage_set_error(shared_storage, error, str);
 }
 
-static struct mailbox *
-shared_mailbox_open(struct mail_storage *storage, const char *name,
-		    struct istream *input, enum mailbox_open_flags flags)
-{
-	struct mail_namespace *ns;
-	struct mailbox *box;
-
-	if (input != NULL) {
-		mail_storage_set_critical(storage,
-			"Shared storage doesn't support streamed mailboxes");
-		return NULL;
-	}
-
-	if (shared_storage_get_namespace(storage, &name, &ns) < 0)
-		return NULL;
-
-	/* if we call the normal mailbox_open() here the plugins will see
-	   mailbox_open() called twice and they could break. */
-	box = ns->storage->storage_class->v.
-		mailbox_open(ns->storage, name, NULL, flags);
-	if (box == NULL)
-		shared_mailbox_copy_error(storage, ns);
-	else
-		ns->flags |= NAMESPACE_FLAG_USABLE;
-	return box;
-}
-
 static int shared_mailbox_create(struct mail_storage *storage,
 				 const char *name, bool directory)
 {
@@ -327,7 +300,7 @@ struct mail_storage shared_storage = {
 		shared_create,
 		index_storage_destroy,
 		NULL,
-		shared_mailbox_open,
+		NULL,
 		shared_mailbox_create
 	}
 };
diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/list/mailbox-list-fs.c
--- a/src/lib-storage/list/mailbox-list-fs.c	Tue Apr 07 16:38:47 2009 -0400
+++ b/src/lib-storage/list/mailbox-list-fs.c	Tue Apr 07 17:54:32 2009 -0400
@@ -370,6 +370,7 @@ struct mailbox_list fs_mailbox_list = {
 	{
 		fs_list_alloc,
 		fs_list_deinit,
+		NULL,
 		fs_is_valid_pattern,
 		fs_is_valid_existing_name,
 		fs_is_valid_create_name,
diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/list/mailbox-list-maildir.c
--- a/src/lib-storage/list/mailbox-list-maildir.c	Tue Apr 07 16:38:47 2009 -0400
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Tue Apr 07 17:54:32 2009 -0400
@@ -444,6 +444,7 @@ struct mailbox_list maildir_mailbox_list
 	{
 		maildir_list_alloc,
 		maildir_list_deinit,
+		NULL,
 		maildir_is_valid_pattern,
 		maildir_is_valid_existing_name,
 		maildir_is_valid_create_name,
@@ -471,6 +472,7 @@ struct mailbox_list imapdir_mailbox_list
 	{
 		imapdir_list_alloc,
 		maildir_list_deinit,
+		NULL,
 		maildir_is_valid_pattern,
 		maildir_is_valid_existing_name,
 		maildir_is_valid_create_name,
diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Tue Apr 07 16:38:47 2009 -0400
+++ b/src/lib-storage/mail-storage.c	Tue Apr 07 17:54:32 2009 -0400
@@ -458,11 +458,18 @@ struct mailbox *mailbox_open(struct mail
 			     enum mailbox_open_flags flags)
 {
 	struct mail_storage *storage = *_storage;
+	struct mailbox_list *list = storage->list;
 	struct mailbox *box;
 
+	if (list->v.get_storage != NULL) {
+		if (list->v.get_storage(list, name, &storage) < 0)
+			return NULL;
+		*_storage = storage;
+	}
+
 	mail_storage_clear_error(storage);
 
-	if (!mailbox_list_is_valid_existing_name(storage->list, name)) {
+	if (!mailbox_list_is_valid_existing_name(list, name)) {
 		mail_storage_set_error(storage, MAIL_ERROR_PARAMS,
 				       "Invalid mailbox name");
 		return NULL;
@@ -473,9 +480,6 @@ struct mailbox *mailbox_open(struct mail
 		if (hook_mailbox_opened != NULL && box != NULL)
 			hook_mailbox_opened(box);
 	} T_END;
-
-	if (box != NULL)
-		*_storage = box->storage;
 	return box;
 }
 
diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h	Tue Apr 07 16:38:47 2009 -0400
+++ b/src/lib-storage/mailbox-list-private.h	Tue Apr 07 17:54:32 2009 -0400
@@ -12,6 +12,8 @@ struct mailbox_list_vfuncs {
 	struct mailbox_list *(*alloc)(void);
 	void (*deinit)(struct mailbox_list *list);
 
+	int (*get_storage)(struct mailbox_list *list,
+			   const char *name, struct mail_storage **storage_r);
 	bool (*is_valid_pattern)(struct mailbox_list *list,
 				 const char *pattern);
 	bool (*is_valid_existing_name)(struct mailbox_list *list,


More information about the dovecot-cvs mailing list