dovecot-2.0: lib-storage: Plugin API changed to run plugin funct...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 7 19:07:09 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/4b20e692c606
changeset: 11488:4b20e692c606
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 07 17:06:17 2010 +0100
description:
lib-storage: Plugin API changed to run plugin functions in correct order.
Previously the hooks were run in correct order, but the functions they
overrode were run in reverse order. This caused problems when multiple
plugins were used.

diffstat:

 src/lib-storage/mail-storage-hooks.c           |  16 ++++++++
 src/lib-storage/mail-storage-hooks.h           |   3 +
 src/lib-storage/mail-storage-private.h         |   6 +-
 src/lib-storage/mail-user.h                    |   2 +-
 src/lib-storage/mail.c                         |   9 ++++-
 src/lib-storage/mailbox-list-private.h         |   2 +-
 src/plugins/acl/acl-mailbox-list.c             |  20 ++++++----
 src/plugins/acl/acl-mailbox.c                  |  57 ++++++++++++++--------------
 src/plugins/acl/acl-plugin.c                   |   3 +-
 src/plugins/acl/acl-plugin.h                   |   1 +
 src/plugins/acl/acl-storage.c                  |   6 ++-
 src/plugins/expire/expire-plugin.c             |  47 ++++++++++++-----------
 src/plugins/fts-solr/fts-solr-plugin.c         |   1 -
 src/plugins/fts/fts-plugin.c                   |   3 +-
 src/plugins/fts/fts-plugin.h                   |   1 +
 src/plugins/fts/fts-storage.c                  |  53 ++++++++++++--------------
 src/plugins/lazy-expunge/lazy-expunge-plugin.c |  45 ++++++++++------------
 src/plugins/listescape/listescape-plugin.c     |  24 +++++++-----
 src/plugins/mbox-snarf/mbox-snarf-plugin.c     |   6 ++-
 src/plugins/notify/notify-storage.c            |  47 ++++++++++-------------
 src/plugins/quota/quota-plugin.c               |   3 +-
 src/plugins/quota/quota-plugin.h               |   2 +
 src/plugins/quota/quota-storage.c              |  60 +++++++++++++++--------------
 src/plugins/trash/trash-plugin.c               |   1 -
 src/plugins/virtual/virtual-storage.c          |   6 ++-
 src/plugins/zlib/zlib-plugin.c                 |  49 ++++++++++++------------
 26 files changed, 254 insertions(+), 219 deletions(-)

diffs (truncated from 1077 to 300 lines):

diff -r 3a0601cb9e67 -r 4b20e692c606 src/lib-storage/mail-storage-hooks.c
--- a/src/lib-storage/mail-storage-hooks.c	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/lib-storage/mail-storage-hooks.c	Mon Jun 07 17:06:17 2010 +0100
@@ -125,6 +125,7 @@
 
 	mail_user_add_plugin_hooks(user);
 
+	user->vlast = &user->v;
 	array_foreach(&user->hooks, hooks) {
 		if ((*hooks)->mail_user_created != NULL)
 			(*hooks)->mail_user_created(user);
@@ -155,6 +156,7 @@
 {
 	const struct mail_storage_hooks *const *hooks;
 
+	storage->vlast = &storage->v;
 	array_foreach(&storage->user->hooks, hooks) {
 		if ((*hooks)->mail_storage_created != NULL)
 			(*hooks)->mail_storage_created(storage);
@@ -165,6 +167,7 @@
 {
 	const struct mail_storage_hooks *const *hooks;
 
+	list->vlast = &list->v;
 	array_foreach(&list->ns->user->hooks, hooks) {
 		if ((*hooks)->mailbox_list_created != NULL)
 			(*hooks)->mailbox_list_created(list);
@@ -175,6 +178,7 @@
 {
 	const struct mail_storage_hooks *const *hooks;
 
+	box->vlast = &box->v;
 	array_foreach(&box->storage->user->hooks, hooks) {
 		if ((*hooks)->mailbox_allocated != NULL)
 			(*hooks)->mailbox_allocated(box);
@@ -190,3 +194,15 @@
 			(*hooks)->mailbox_opened(box);
 	}
 }
+
+void hook_mail_allocated(struct mail *mail)
+{
+	const struct mail_storage_hooks *const *hooks;
+	struct mail_private *pmail = (struct mail_private *)mail;
+
+	pmail->vlast = &pmail->v;
+	array_foreach(&mail->box->storage->user->hooks, hooks) {
+		if ((*hooks)->mail_allocated != NULL)
+			(*hooks)->mail_allocated(mail);
+	}
+}
diff -r 3a0601cb9e67 -r 4b20e692c606 src/lib-storage/mail-storage-hooks.h
--- a/src/lib-storage/mail-storage-hooks.h	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/lib-storage/mail-storage-hooks.h	Mon Jun 07 17:06:17 2010 +0100
@@ -7,6 +7,7 @@
 struct mail_namespace;
 struct mailbox_list;
 struct mailbox;
+struct mail;
 
 struct mail_storage_hooks {
 	void (*mail_user_created)(struct mail_user *user);
@@ -16,6 +17,7 @@
 	void (*mailbox_list_created)(struct mailbox_list *list);
 	void (*mailbox_allocated)(struct mailbox *box);
 	void (*mailbox_opened)(struct mailbox *box);
+	void (*mail_allocated)(struct mail *mail);
 };
 
 void mail_storage_hooks_init(void);
@@ -35,5 +37,6 @@
 void hook_mailbox_list_created(struct mailbox_list *list);
 void hook_mailbox_allocated(struct mailbox *box);
 void hook_mailbox_opened(struct mailbox *box);
+void hook_mail_allocated(struct mail *mail);
 
 #endif
diff -r 3a0601cb9e67 -r 4b20e692c606 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/lib-storage/mail-storage-private.h	Mon Jun 07 17:06:17 2010 +0100
@@ -61,7 +61,7 @@
 	const char *name;
 	enum mail_storage_class_flags class_flags;
 
-        struct mail_storage_vfuncs v;
+        struct mail_storage_vfuncs v, *vlast;
 
 /* private: */
 	pool_t pool;
@@ -219,7 +219,7 @@
 	struct mail_storage *storage;
 	struct mailbox_list *list;
 
-        struct mailbox_vfuncs v;
+        struct mailbox_vfuncs v, *vlast;
 /* private: */
 	pool_t pool;
 
@@ -327,7 +327,7 @@
 
 struct mail_private {
 	struct mail mail;
-	struct mail_vfuncs v;
+	struct mail_vfuncs v, *vlast;
 
 	enum mail_fetch_field wanted_fields;
 	struct mailbox_header_lookup_ctx *wanted_headers;
diff -r 3a0601cb9e67 -r 4b20e692c606 src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/lib-storage/mail-user.h	Mon Jun 07 17:06:17 2010 +0100
@@ -13,7 +13,7 @@
 
 struct mail_user {
 	pool_t pool;
-	struct mail_user_vfuncs v;
+	struct mail_user_vfuncs v, *vlast;
 	int refcount;
 
 	const char *username;
diff -r 3a0601cb9e67 -r 4b20e692c606 src/lib-storage/mail.c
--- a/src/lib-storage/mail.c	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/lib-storage/mail.c	Mon Jun 07 17:06:17 2010 +0100
@@ -15,7 +15,14 @@
 			enum mail_fetch_field wanted_fields,
 			struct mailbox_header_lookup_ctx *wanted_headers)
 {
-	return t->box->v.mail_alloc(t, wanted_fields, wanted_headers);
+	struct mail *mail;
+
+	T_BEGIN {
+		mail = t->box->v.mail_alloc(t, wanted_fields, wanted_headers);
+		hook_mail_allocated(mail);
+	} T_END;
+
+	return mail;
 }
 
 void mail_free(struct mail **mail)
diff -r 3a0601cb9e67 -r 4b20e692c606 src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/lib-storage/mailbox-list-private.h	Mon Jun 07 17:06:17 2010 +0100
@@ -88,7 +88,7 @@
 	enum mailbox_list_properties props;
 	size_t mailbox_name_max_length;
 
-	struct mailbox_list_vfuncs v;
+	struct mailbox_list_vfuncs v, *vlast;
 
 /* private: */
 	pool_t pool;
diff -r 3a0601cb9e67 -r 4b20e692c606 src/plugins/acl/acl-mailbox-list.c
--- a/src/plugins/acl/acl-mailbox-list.c	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/plugins/acl/acl-mailbox-list.c	Mon Jun 07 17:06:17 2010 +0100
@@ -502,10 +502,12 @@
 static void acl_mailbox_list_init_shared(struct mailbox_list *list)
 {
 	struct acl_mailbox_list *alist;
+	struct mailbox_list_vfuncs *v = list->vlast;
 
 	alist = p_new(list->pool, struct acl_mailbox_list, 1);
-	alist->module_ctx.super = list->v;
-	list->v.iter_init = acl_mailbox_list_iter_init_shared;
+	alist->module_ctx.super = *v;
+	list->vlast = &alist->module_ctx.super;
+	v->iter_init = acl_mailbox_list_iter_init_shared;
 
 	MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist);
 }
@@ -526,6 +528,7 @@
 static void acl_mailbox_list_init_default(struct mailbox_list *list)
 {
 	struct acl_user *auser = ACL_USER_CONTEXT(list->ns->user);
+	struct mailbox_list_vfuncs *v = list->vlast;
 	struct acl_mailbox_list *alist;
 	struct acl_backend *backend;
 	struct mail_namespace *ns;
@@ -558,12 +561,13 @@
 	}
 
 	alist = p_new(list->pool, struct acl_mailbox_list, 1);
-	alist->module_ctx.super = list->v;
-	list->v.iter_init = acl_mailbox_list_iter_init;
-	list->v.iter_next = acl_mailbox_list_iter_next;
-	list->v.iter_deinit = acl_mailbox_list_iter_deinit;
-	list->v.get_mailbox_name_status = acl_get_mailbox_name_status;
-	list->v.create_mailbox_dir = acl_mailbox_list_create_dir;
+	alist->module_ctx.super = *v;
+	list->vlast = &alist->module_ctx.super;
+	v->iter_init = acl_mailbox_list_iter_init;
+	v->iter_next = acl_mailbox_list_iter_next;
+	v->iter_deinit = acl_mailbox_list_iter_deinit;
+	v->get_mailbox_name_status = acl_get_mailbox_name_status;
+	v->create_mailbox_dir = acl_mailbox_list_create_dir;
 
 	acl_storage_rights_ctx_init(&alist->rights, backend);
 	MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist);
diff -r 3a0601cb9e67 -r 4b20e692c606 src/plugins/acl/acl-mailbox.c
--- a/src/plugins/acl/acl-mailbox.c	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/plugins/acl/acl-mailbox.c	Mon Jun 07 17:06:17 2010 +0100
@@ -20,6 +20,7 @@
 	union mailbox_module_context module_ctx;
 	struct acl_object *aclobj;
 	bool skip_acl_checks;
+	bool acl_enabled;
 };
 
 struct acl_transaction_context {
@@ -335,28 +336,24 @@
 	amail->super.expunge(_mail);
 }
 
-static struct mail *
-acl_mail_alloc(struct mailbox_transaction_context *t,
-	       enum mail_fetch_field wanted_fields,
-	       struct mailbox_header_lookup_ctx *wanted_headers)
+void acl_mail_allocated(struct mail *_mail)
 {
-	struct acl_mailbox *abox = ACL_CONTEXT(t->box);
+	struct acl_mailbox *abox = ACL_CONTEXT(_mail->box);
+	struct mail_private *mail = (struct mail_private *)_mail;
+	struct mail_vfuncs *v = mail->vlast;
 	union mail_module_context *amail;
-	struct mail *_mail;
-	struct mail_private *mail;
 
-	_mail = abox->module_ctx.super.
-		mail_alloc(t, wanted_fields, wanted_headers);
-	mail = (struct mail_private *)_mail;
+	if (abox == NULL || !abox->acl_enabled)
+		return;
 
 	amail = p_new(mail->pool, union mail_module_context, 1);
-	amail->super = mail->v;
+	amail->super = *v;
+	mail->vlast = &amail->super;
 
-	mail->v.update_flags = acl_mail_update_flags;
-	mail->v.update_keywords = acl_mail_update_keywords;
-	mail->v.expunge = acl_mail_expunge;
+	v->update_flags = acl_mail_update_flags;
+	v->update_keywords = acl_mail_update_keywords;
+	v->expunge = acl_mail_expunge;
 	MODULE_CONTEXT_SET_SELF(mail, acl_mail_module, amail);
-	return _mail;
 }
 
 static int acl_save_get_flags(struct mailbox *box, enum mail_flags *flags,
@@ -502,6 +499,7 @@
 void acl_mailbox_allocated(struct mailbox *box)
 {
 	struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(box->list);
+	struct mailbox_vfuncs *v = box->vlast;
 	struct acl_mailbox *abox;
 
 	if (alist == NULL) {
@@ -510,24 +508,25 @@
 	}
 
 	abox = p_new(box->pool, struct acl_mailbox, 1);
-	abox->module_ctx.super = box->v;
+	abox->module_ctx.super = *v;
+	box->vlast = &abox->module_ctx.super;
 	abox->aclobj = acl_object_init_from_name(alist->rights.backend,
 						 mailbox_get_name(box));
 
 	if ((box->flags & MAILBOX_FLAG_IGNORE_ACLS) == 0) {
-		box->v.is_readonly = acl_is_readonly;
-		box->v.allow_new_keywords = acl_allow_new_keywords;
-		box->v.open = acl_mailbox_open;
-		box->v.free = acl_mailbox_free;
-		box->v.create = acl_mailbox_create;
-		box->v.update = acl_mailbox_update;
-		box->v.delete = acl_mailbox_delete;
-		box->v.rename = acl_mailbox_rename;
-		box->v.mail_alloc = acl_mail_alloc;
-		box->v.save_begin = acl_save_begin;
-		box->v.keywords_create = acl_keywords_create;
-		box->v.copy = acl_copy;
-		box->v.transaction_commit = acl_transaction_commit;
+		abox->acl_enabled = TRUE;
+		v->is_readonly = acl_is_readonly;
+		v->allow_new_keywords = acl_allow_new_keywords;
+		v->open = acl_mailbox_open;
+		v->free = acl_mailbox_free;
+		v->create = acl_mailbox_create;
+		v->update = acl_mailbox_update;
+		v->delete = acl_mailbox_delete;
+		v->rename = acl_mailbox_rename;
+		v->save_begin = acl_save_begin;
+		v->keywords_create = acl_keywords_create;
+		v->copy = acl_copy;
+		v->transaction_commit = acl_transaction_commit;
 	}
 	MODULE_CONTEXT_SET(box, acl_storage_module, abox);
 }
diff -r 3a0601cb9e67 -r 4b20e692c606 src/plugins/acl/acl-plugin.c
--- a/src/plugins/acl/acl-plugin.c	Mon Jun 07 14:05:42 2010 +0100
+++ b/src/plugins/acl/acl-plugin.c	Mon Jun 07 17:06:17 2010 +0100
@@ -12,7 +12,8 @@
 static struct mail_storage_hooks acl_mail_storage_hooks = {


More information about the dovecot-cvs mailing list