dovecot-2.0: lib-storage: Plugin hook API changed to support per...

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 5 00:15:58 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/a9eda7672869
changeset: 10412:a9eda7672869
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Dec 04 16:15:51 2009 -0600
description:
lib-storage: Plugin hook API changed to support per-user plugins within a process.

diffstat:

59 files changed, 219 insertions(+), 353 deletions(-)
src/lib-storage/Makefile.am                    |    2 
src/lib-storage/list/index-mailbox-list-sync.c |   14 ++---
src/lib-storage/list/index-mailbox-list.c      |   10 ++--
src/lib-storage/mail-namespace.c               |   10 +---
src/lib-storage/mail-namespace.h               |    3 -
src/lib-storage/mail-storage-private.h         |    8 ---
src/lib-storage/mail-storage.c                 |   11 +---
src/lib-storage/mail-user.c                    |    5 --
src/lib-storage/mail-user.h                    |    4 -
src/lib-storage/mailbox-list-private.h         |    2 
src/lib-storage/mailbox-list.c                 |    5 --
src/lib/module-dir.c                           |    4 -
src/lib/module-dir.h                           |    2 
src/lib/strfuncs.c                             |    9 +++
src/lib/strfuncs.h                             |    5 +-
src/plugins/acl/acl-mailbox-list.c             |    5 --
src/plugins/acl/acl-plugin.c                   |   25 +++-------
src/plugins/acl/acl-plugin.h                   |    5 --
src/plugins/acl/acl-storage.c                  |   18 ++-----
src/plugins/autocreate/autocreate-plugin.c     |   20 +++-----
src/plugins/autocreate/autocreate-plugin.h     |    2 
src/plugins/convert/convert-plugin.c           |   22 +++------
src/plugins/convert/convert-plugin.h           |    2 
src/plugins/expire/expire-plugin.c             |   33 ++++---------
src/plugins/expire/expire-plugin.h             |    2 
src/plugins/fts-lucene/fts-lucene-plugin.c     |    2 
src/plugins/fts-lucene/fts-lucene-plugin.h     |    2 
src/plugins/fts-solr/fts-solr-plugin.c         |   17 +++----
src/plugins/fts-solr/fts-solr-plugin.h         |    2 
src/plugins/fts-squat/fts-squat-plugin.c       |    2 
src/plugins/fts-squat/fts-squat-plugin.h       |    4 +
src/plugins/fts/fts-plugin.c                   |   13 ++---
src/plugins/fts/fts-plugin.h                   |    4 -
src/plugins/fts/fts-storage.c                  |    5 --
src/plugins/imap-acl/imap-acl-plugin.c         |    2 
src/plugins/imap-acl/imap-acl-plugin.h         |    2 
src/plugins/imap-quota/imap-quota-plugin.c     |    2 
src/plugins/imap-quota/imap-quota-plugin.h     |    4 +
src/plugins/lazy-expunge/lazy-expunge-plugin.c |   58 ++++++------------------
src/plugins/lazy-expunge/lazy-expunge-plugin.h |    2 
src/plugins/listescape/listescape-plugin.c     |   31 ++++--------
src/plugins/listescape/listescape-plugin.h     |    2 
src/plugins/mail-log/mail-log-plugin.c         |    2 
src/plugins/mail-log/mail-log-plugin.h         |    2 
src/plugins/mbox-snarf/mbox-snarf-plugin.c     |   25 ++++------
src/plugins/mbox-snarf/mbox-snarf-plugin.h     |    2 
src/plugins/notify/notify-plugin-private.h     |    2 
src/plugins/notify/notify-plugin.c             |    6 +-
src/plugins/notify/notify-plugin.h             |    3 -
src/plugins/notify/notify-storage.c            |   35 ++++----------
src/plugins/quota/quota-plugin.c               |   39 ++++------------
src/plugins/quota/quota-plugin.h               |    9 +--
src/plugins/quota/quota-storage.c              |    8 ---
src/plugins/trash/trash-plugin.c               |   24 ++++-----
src/plugins/trash/trash-plugin.h               |    2 
src/plugins/virtual/virtual-plugin.c           |    2 
src/plugins/virtual/virtual-plugin.h           |    2 
src/plugins/zlib/zlib-plugin.c                 |   25 ++++------
src/plugins/zlib/zlib-plugin.h                 |    2 

diffs (truncated from 1524 to 300 lines):

diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/Makefile.am
--- a/src/lib-storage/Makefile.am	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/Makefile.am	Fri Dec 04 16:15:51 2009 -0600
@@ -23,6 +23,7 @@ libstorage_la_SOURCES = \
 	mail-search.c \
 	mail-search-build.c \
 	mail-storage.c \
+	mail-storage-hooks.c \
 	mail-storage-settings.c \
 	mail-thread.c \
 	mail-user.c \
@@ -43,6 +44,7 @@ headers = \
 	mail-thread.h \
 	mail-storage.h \
 	mail-storage-private.h \
+	mail-storage-hooks.h \
 	mail-storage-service.h \
 	mail-storage-settings.h \
 	mail-user.h \
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/list/index-mailbox-list-sync.c
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Fri Dec 04 16:15:51 2009 -0600
@@ -42,8 +42,6 @@ static struct index_list_map index_list_
 	{ NULL, 0, 0 }
 };
 
-static void (*index_list_next_hook_mailbox_created)(struct mailbox *box);
-
 static MODULE_CONTEXT_DEFINE_INIT(index_list_storage_module,
 				  &mail_storage_module_register);
 
@@ -363,9 +361,6 @@ static void index_list_mail_mailbox_allo
 		INDEX_LIST_CONTEXT(box->list);
 	struct index_list_mailbox *ibox;
 
-	if (index_list_next_hook_mailbox_created != NULL)
-		index_list_next_hook_mailbox_created(box);
-
 	if (ilist == NULL)
 		return;
 
@@ -394,8 +389,11 @@ void index_mailbox_list_sync_init_list(s
 	}
 }
 
+static struct mail_storage_hooks index_mailbox_list_sync_hooks = {
+	.mailbox_allocated = index_list_mail_mailbox_allocated
+};
+
 void index_mailbox_list_sync_init(void)
 {
-	index_list_next_hook_mailbox_created = hook_mailbox_allocated;
-	hook_mailbox_allocated = index_list_mail_mailbox_allocated;
-}
+	mail_storage_hooks_add_internal(&index_mailbox_list_sync_hooks);
+}
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/list/index-mailbox-list.c
--- a/src/lib-storage/list/index-mailbox-list.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/list/index-mailbox-list.c	Fri Dec 04 16:15:51 2009 -0600
@@ -7,6 +7,7 @@
 #include "imap-match.h"
 #include "mail-index.h"
 #include "mail-storage.h"
+#include "mail-storage-hooks.h"
 #include "mailbox-tree.h"
 #include "mailbox-list-subscriptions.h"
 #include "mailbox-list-index.h"
@@ -21,7 +22,6 @@
 
 struct index_mailbox_list_module index_mailbox_list_module =
 	MODULE_CONTEXT_INIT(&mailbox_list_module_register);
-static void (*index_next_hook_mailbox_list_created)(struct mailbox_list *list);
 
 static enum mailbox_info_flags
 index_mailbox_list_index_flags_translate(enum mailbox_list_index_flags flags)
@@ -533,12 +533,14 @@ static void index_mailbox_list_created(s
 	}
 }
 
+static struct mail_storage_hooks index_mailbox_list_hooks = {
+	.mailbox_list_created = index_mailbox_list_created
+};
+
 void index_mailbox_list_init(void); /* called in mailbox-list-register.c */
 
 void index_mailbox_list_init(void)
 {
-	index_next_hook_mailbox_list_created = hook_mailbox_list_created;
-	hook_mailbox_list_created = index_mailbox_list_created;
-
+	mail_storage_hooks_add_internal(&index_mailbox_list_hooks);
 	index_mailbox_list_sync_init();
 }
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mail-namespace.c	Fri Dec 04 16:15:51 2009 -0600
@@ -9,8 +9,6 @@
 #include "mail-namespace.h"
 
 #include <stdlib.h>
-
-void (*hook_mail_namespaces_created)(struct mail_namespace *namespaces);
 
 void mail_namespace_add_storage(struct mail_namespace *ns,
 				struct mail_storage *storage)
@@ -260,11 +258,9 @@ int mail_namespaces_init(struct mail_use
 		}
 		mail_user_add_namespace(user, &namespaces);
 
-		if (hook_mail_namespaces_created != NULL) {
-			T_BEGIN {
-				hook_mail_namespaces_created(namespaces);
-			} T_END;
-		}
+		T_BEGIN {
+			hook_mail_namespaces_created(namespaces);
+		} T_END;
 		return 0;
 	}
 
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mail-namespace.h	Fri Dec 04 16:15:51 2009 -0600
@@ -65,9 +65,6 @@ struct mail_namespace {
 	const struct mail_namespace_settings *set;
 	const struct mail_storage_settings *mail_set;
 };
-
-/* Called after namespaces has been created */
-extern void (*hook_mail_namespaces_created)(struct mail_namespace *namespaces);
 
 int mail_namespaces_init(struct mail_user *user, const char **error_r);
 struct mail_namespace *mail_namespaces_init_empty(struct mail_user *user);
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mail-storage-private.h	Fri Dec 04 16:15:51 2009 -0600
@@ -4,6 +4,7 @@
 #include "module-context.h"
 #include "file-lock.h"
 #include "mail-storage.h"
+#include "mail-storage-hooks.h"
 #include "mail-storage-settings.h"
 #include "mail-index-private.h"
 
@@ -11,13 +12,6 @@
 #define MAIL_READ_HDR_BLOCK_SIZE (1024*4)
 /* Block size when read()ing message (header and) body. */
 #define MAIL_READ_FULL_BLOCK_SIZE (1024*8)
-
-/* Called after mail storage has been created */
-extern void (*hook_mail_storage_created)(struct mail_storage *storage);
-/* Called after mailbox has been allocated */
-extern void (*hook_mailbox_allocated)(struct mailbox *box);
-/* Called after mailbox index has been opened */
-extern void (*hook_mailbox_index_opened)(struct mailbox *box);
 
 struct mail_storage_module_register {
 	unsigned int id;
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mail-storage.c	Fri Dec 04 16:15:51 2009 -0600
@@ -23,15 +23,12 @@ struct mail_storage_mail_index_module ma
 struct mail_storage_mail_index_module mail_storage_mail_index_module =
 	MODULE_CONTEXT_INIT(&mail_index_module_register);
 
-void (*hook_mail_storage_created)(struct mail_storage *storage);
-void (*hook_mailbox_allocated)(struct mailbox *box) = NULL;
-void (*hook_mailbox_index_opened)(struct mailbox *box) = NULL;
-
 ARRAY_TYPE(mail_storage) mail_storage_classes;
 
 void mail_storage_init(void)
 {
 	mailbox_lists_init();
+	mail_storage_hooks_init();
 	i_array_init(&mail_storage_classes, 8);
 }
 
@@ -39,6 +36,7 @@ void mail_storage_deinit(void)
 {
 	if (array_is_created(&mail_storage_classes))
 		array_free(&mail_storage_classes);
+	mail_storage_hooks_deinit();
 	mailbox_lists_deinit();
 }
 
@@ -298,7 +296,7 @@ int mail_storage_create(struct mail_name
 		return -1;
 	}
 
-	if (hook_mail_storage_created != NULL) T_BEGIN {
+	T_BEGIN {
 		hook_mail_storage_created(storage);
 	} T_END;
 
@@ -466,8 +464,7 @@ struct mailbox *mailbox_alloc(struct mai
 	T_BEGIN {
 		box = storage->v.mailbox_alloc(storage, new_list,
 					       name, input, flags);
-		if (hook_mailbox_allocated != NULL)
-			hook_mailbox_allocated(box);
+		hook_mailbox_allocated(box);
 	} T_END;
 	return box;
 }
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mail-user.c	Fri Dec 04 16:15:51 2009 -0600
@@ -22,8 +22,6 @@ struct mail_user_module_register mail_us
 struct mail_user_module_register mail_user_module_register = { 0 };
 struct auth_master_connection *mail_user_auth_master_conn;
 
-void (*hook_mail_user_created)(struct mail_user *user) = NULL;
-
 static void mail_user_deinit_base(struct mail_user *user)
 {
 	mail_namespaces_deinit(&user->namespaces);
@@ -107,8 +105,7 @@ int mail_user_init(struct mail_user *use
 	user->mail_debug = mail_set->mail_debug;
 
 	user->initialized = TRUE;
-	if (hook_mail_user_created != NULL)
-		hook_mail_user_created(user);
+	hook_mail_user_created(user);
 	return 0;
 }
 
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mail-user.h	Fri Dec 04 16:15:51 2009 -0600
@@ -30,6 +30,7 @@ struct mail_user {
 	struct mail_user_settings *set;
 	struct mail_namespace *namespaces;
 	struct mail_storage *storages;
+	ARRAY_DEFINE(hooks, const struct mail_storage_hooks *);
 
 	/* Module-specific contexts. See mail_storage_module_id. */
 	ARRAY_DEFINE(module_contexts, union mail_user_module_context *);
@@ -55,9 +56,6 @@ union mail_user_module_context {
 };
 extern struct mail_user_module_register mail_user_module_register;
 extern struct auth_master_connection *mail_user_auth_master_conn;
-
-/* Called after user has been created */
-extern void (*hook_mail_user_created)(struct mail_user *user);
 
 struct mail_user *mail_user_alloc(const char *username,
 				  const struct setting_parser_info *set_info,
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mailbox-list-private.h	Fri Dec 04 16:15:51 2009 -0600
@@ -132,8 +132,6 @@ struct mailbox_list_iter_update_context 
    use objects' module_contexts[id] for their own purposes. */
 extern struct mailbox_list_module_register mailbox_list_module_register;
 
-extern void (*hook_mailbox_list_created)(struct mailbox_list *list);
-
 void mailbox_lists_init(void);
 void mailbox_lists_deinit(void);
 
diff -r 3448f1bc6966 -r a9eda7672869 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib-storage/mailbox-list.c	Fri Dec 04 16:15:51 2009 -0600
@@ -43,8 +43,6 @@ struct ns_list_iterate_context {
 
 struct mailbox_list_module_register mailbox_list_module_register = { 0 };
 
-void (*hook_mailbox_list_created)(struct mailbox_list *list);
-
 static ARRAY_DEFINE(mailbox_list_drivers, const struct mailbox_list *);
 
 void mailbox_lists_init(void)
@@ -168,8 +166,7 @@ int mailbox_list_create(const char *driv
 	}
 	mail_namespace_finish_list_init(ns, list);
 
-	if (hook_mailbox_list_created != NULL)
-		hook_mailbox_list_created(list);
+	hook_mailbox_list_created(list);
 	return 0;
 }
 
diff -r 3448f1bc6966 -r a9eda7672869 src/lib/module-dir.c
--- a/src/lib/module-dir.c	Fri Dec 04 15:10:43 2009 -0600
+++ b/src/lib/module-dir.c	Fri Dec 04 16:15:51 2009 -0600
@@ -146,7 +146,7 @@ module_load(const char *path, const char
 	}
 
 	/* get our init func */
-	module->init = (void (*)(void))
+	module->init = (void (*)(struct module *))
 		get_symbol(module, t_strconcat(name, "_init", NULL),
 			   !require_init_funcs);
 	module->deinit = module->init == NULL ? NULL : (void (*)(void))
@@ -346,7 +346,7 @@ void module_dir_init(struct module *modu
 	for (module = modules; module != NULL; module = module->next) {
 		if (module->init != NULL) {
 			T_BEGIN {
-				module->init();
+				module->init(module);


More information about the dovecot-cvs mailing list