dovecot-2.0: plugins: Simplified code by using mailbox_allocated...

dovecot at dovecot.org dovecot at dovecot.org
Thu Dec 17 20:33:52 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/8e9e67a94e16
changeset: 10515:8e9e67a94e16
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Dec 17 13:33:45 2009 -0500
description:
plugins: Simplified code by using mailbox_allocated hook.

diffstat:

8 files changed, 22 insertions(+), 83 deletions(-)
src/plugins/acl/acl-mailbox.c       |   21 +++++++++------------
src/plugins/acl/acl-plugin.c        |    4 ++--
src/plugins/acl/acl-plugin.h        |    6 +-----
src/plugins/acl/acl-storage.c       |   17 -----------------
src/plugins/notify/notify-storage.c |   25 +++----------------------
src/plugins/quota/quota-plugin.c    |    4 ++--
src/plugins/quota/quota-plugin.h    |    2 +-
src/plugins/quota/quota-storage.c   |   26 ++++----------------------

diffs (233 lines):

diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/acl/acl-mailbox.c
--- a/src/plugins/acl/acl-mailbox.c	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/acl/acl-mailbox.c	Thu Dec 17 13:33:45 2009 -0500
@@ -444,17 +444,15 @@ static int acl_mailbox_open(struct mailb
 	return abox->module_ctx.super.open(box);
 }
 
-struct mailbox *
-acl_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-		  const char *name, struct istream *input,
-		  enum mailbox_flags flags)
-{
-	union mail_storage_module_context *astorage = ACL_CONTEXT(storage);
-	struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(list);
+void acl_mailbox_allocated(struct mailbox *box)
+{
+	struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(box->list);
 	struct acl_mailbox *abox;
-	struct mailbox *box;
-
-	box = astorage->super.mailbox_alloc(storage, list, name, input, flags);
+
+	if (alist == NULL) {
+		/* ACLs disabled */
+		return;
+	}
 
 	abox = p_new(box->pool, struct acl_mailbox, 1);
 	abox->module_ctx.super = box->v;
@@ -475,5 +473,4 @@ acl_mailbox_alloc(struct mail_storage *s
 		box->v.transaction_commit = acl_transaction_commit;
 	}
 	MODULE_CONTEXT_SET(box, acl_storage_module, abox);
-	return box;
-}
+}
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/acl/acl-plugin.c
--- a/src/plugins/acl/acl-plugin.c	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/acl/acl-plugin.c	Thu Dec 17 13:33:45 2009 -0500
@@ -11,8 +11,8 @@ const char *acl_plugin_version = PACKAGE
 
 static struct mail_storage_hooks acl_mail_storage_hooks = {
 	.mail_user_created = acl_mail_user_created,
-	.mail_storage_created = acl_mail_storage_created,
-	.mail_namespace_storage_added = acl_mail_namespace_storage_added
+	.mail_namespace_storage_added = acl_mail_namespace_storage_added,
+	.mailbox_allocated = acl_mailbox_allocated
 };
 
 void acl_plugin_init(struct module *module)
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/acl/acl-plugin.h
--- a/src/plugins/acl/acl-plugin.h	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/acl/acl-plugin.h	Thu Dec 17 13:33:45 2009 -0500
@@ -39,14 +39,10 @@ extern MODULE_CONTEXT_DEFINE(acl_mailbox
 extern MODULE_CONTEXT_DEFINE(acl_mailbox_list_module,
 			     &mailbox_list_module_register);
 
-void acl_mail_storage_created(struct mail_storage *storage);
 void acl_mail_namespace_storage_added(struct mail_namespace *ns);
 void acl_mail_user_created(struct mail_user *list);
 
-struct mailbox *
-acl_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-		  const char *name, struct istream *input,
-		  enum mailbox_flags flags);
+void acl_mailbox_allocated(struct mailbox *box);
 
 struct acl_backend *acl_mailbox_list_get_backend(struct mailbox_list *list);
 int acl_mailbox_list_have_right(struct mailbox_list *list, const char *name,
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/acl/acl-storage.c
--- a/src/plugins/acl/acl-storage.c	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/acl/acl-storage.c	Thu Dec 17 13:33:45 2009 -0500
@@ -15,23 +15,6 @@ struct acl_storage_module acl_storage_mo
 	MODULE_CONTEXT_INIT(&mail_storage_module_register);
 struct acl_user_module acl_user_module =
 	MODULE_CONTEXT_INIT(&mail_user_module_register);
-
-void acl_mail_storage_created(struct mail_storage *storage)
-{
-	struct acl_user *auser = ACL_USER_CONTEXT(storage->user);
-	union mail_storage_module_context *astorage;
-
-	if (auser == NULL) {
-		/* ACLs disabled for this user */
-		return;
-	}
-
-	astorage = p_new(storage->pool, union mail_storage_module_context, 1);
-	astorage->super = storage->v;
-	storage->v.mailbox_alloc = acl_mailbox_alloc;
-
-	MODULE_CONTEXT_SET_SELF(storage, acl_storage_module, astorage);
-}
 
 static void acl_user_deinit(struct mail_user *user)
 {
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/notify/notify-storage.c
--- a/src/plugins/notify/notify-storage.c	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/notify/notify-storage.c	Thu Dec 17 13:33:45 2009 -0500
@@ -199,16 +199,9 @@ notify_transaction_rollback(struct mailb
 	lbox->super.transaction_rollback(t);
 }
 
-static struct mailbox *
-notify_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-		     const char *name, struct istream *input,
-		     enum mailbox_flags flags)
-{
-	union mail_storage_module_context *lstorage = NOTIFY_CONTEXT(storage);
-	struct mailbox *box;
+static void notify_mailbox_allocated(struct mailbox *box)
+{
 	union mailbox_module_context *lbox;
-
-	box = lstorage->super.mailbox_alloc(storage, list, name, input, flags);
 
 	lbox = p_new(box->pool, union mailbox_module_context, 1);
 	lbox->super = box->v;
@@ -221,7 +214,6 @@ notify_mailbox_alloc(struct mail_storage
 	box->v.transaction_commit = notify_transaction_commit;
 	box->v.transaction_rollback = notify_transaction_rollback;
 	MODULE_CONTEXT_SET_SELF(box, notify_storage_module, lbox);
-	return box;
 }
 
 static int
@@ -253,17 +245,6 @@ notify_mailbox_list_rename(struct mailbo
 	notify_contexts_mailbox_rename(oldlist, oldname, newlist, newname,
 				       rename_children);
 	return 0;
-}
-
-static void notify_mail_storage_created(struct mail_storage *storage)
-{
-	union mail_storage_module_context *lstorage;
-
-	lstorage = p_new(storage->pool, union mail_storage_module_context, 1);
-	lstorage->super = storage->v;
-	storage->v.mailbox_alloc = notify_mailbox_alloc;
-
-	MODULE_CONTEXT_SET_SELF(storage, notify_storage_module, lstorage);
 }
 
 static void notify_mail_namespace_storage_added(struct mail_namespace *ns)
@@ -280,7 +261,7 @@ static void notify_mail_namespace_storag
 }
 
 static struct mail_storage_hooks notify_mail_storage_hooks = {
-	.mail_storage_created = notify_mail_storage_created,
+	.mailbox_allocated = notify_mailbox_allocated,
 	.mail_namespace_storage_added = notify_mail_namespace_storage_added
 };
 
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/quota/quota-plugin.c
--- a/src/plugins/quota/quota-plugin.c	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/quota/quota-plugin.c	Thu Dec 17 13:33:45 2009 -0500
@@ -12,8 +12,8 @@ static struct mail_storage_hooks quota_m
 static struct mail_storage_hooks quota_mail_storage_hooks = {
 	.mail_user_created = quota_mail_user_created,
 	.mail_namespaces_created = quota_mail_namespaces_created,
-	.mail_storage_created = quota_mail_storage_created,
-	.mail_namespace_storage_added = quota_mail_namespace_storage_added
+	.mail_namespace_storage_added = quota_mail_namespace_storage_added,
+	.mailbox_allocated = quota_mailbox_allocated
 };
 
 void quota_plugin_init(struct module *module)
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/quota/quota-plugin.h
--- a/src/plugins/quota/quota-plugin.h	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/quota/quota-plugin.h	Thu Dec 17 13:33:45 2009 -0500
@@ -19,9 +19,9 @@ extern MODULE_CONTEXT_DEFINE(quota_user_
 extern MODULE_CONTEXT_DEFINE(quota_user_module, &mail_user_module_register);
 
 void quota_mail_user_created(struct mail_user *user);
-void quota_mail_storage_created(struct mail_storage *storage);
 void quota_mail_namespace_storage_added(struct mail_namespace *ns);
 void quota_mail_namespaces_created(struct mail_namespace *namespaces);
+void quota_mailbox_allocated(struct mailbox *box);
 
 void quota_plugin_init(struct module *module);
 void quota_plugin_deinit(void);
diff -r 55baae8ed874 -r 8e9e67a94e16 src/plugins/quota/quota-storage.c
--- a/src/plugins/quota/quota-storage.c	Wed Dec 16 22:50:36 2009 -0500
+++ b/src/plugins/quota/quota-storage.c	Thu Dec 17 13:33:45 2009 -0500
@@ -345,18 +345,12 @@ static void quota_mailbox_close(struct m
 	qbox->module_ctx.super.close(box);
 }
 
-static struct mailbox *
-quota_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-		    const char *name, struct istream *input,
-		    enum mailbox_flags flags)
-{
-	union mail_storage_module_context *qstorage = QUOTA_CONTEXT(storage);
-	struct mailbox *box;
+void quota_mailbox_allocated(struct mailbox *box)
+{
 	struct quota_mailbox *qbox;
 
-	box = qstorage->super.mailbox_alloc(storage, list, name, input, flags);
-	if (box == NULL || QUOTA_LIST_CONTEXT(list) == NULL)
-		return box;
+	if (QUOTA_LIST_CONTEXT(box->list) == NULL)
+		return;
 
 	qbox = p_new(box->pool, struct quota_mailbox, 1);
 	qbox->module_ctx.super = box->v;
@@ -372,7 +366,6 @@ quota_mailbox_alloc(struct mail_storage 
 	box->v.sync_deinit = quota_mailbox_sync_deinit;
 	box->v.close = quota_mailbox_close;
 	MODULE_CONTEXT_SET(box, quota_storage_module, qbox);
-	return box;
 }
 
 static int
@@ -488,17 +481,6 @@ void quota_mail_user_created(struct mail
 	}
 }
 
-void quota_mail_storage_created(struct mail_storage *storage)
-{
-	union mail_storage_module_context *qstorage;
-
-	qstorage = p_new(storage->pool, union mail_storage_module_context, 1);
-	qstorage->super = storage->v;
-	storage->v.mailbox_alloc = quota_mailbox_alloc;
-
-	MODULE_CONTEXT_SET_SELF(storage, quota_storage_module, qstorage);
-}
-
 static struct quota_root *
 quota_find_root_for_ns(struct quota *quota, struct mail_namespace *ns)
 {


More information about the dovecot-cvs mailing list