From: Timo Sirainen Date: Fri, 4 Dec 2009 22:15:51 +0000 (-0600) Subject: lib-storage: Plugin hook API changed to support per-user plugins within a process. X-Git-Tag: 2.0.beta1~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5666a3d6a7ea89362b8d9e8b39b15424cd9d6388;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Plugin hook API changed to support per-user plugins within a process. --HG-- branch : HEAD --- diff --git a/src/lib-storage/Makefile.am b/src/lib-storage/Makefile.am index ac9b4dbd82..dddc2924c9 100644 --- a/src/lib-storage/Makefile.am +++ b/src/lib-storage/Makefile.am @@ -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 --git a/src/lib-storage/list/index-mailbox-list-sync.c b/src/lib-storage/list/index-mailbox-list-sync.c index 5543fa5dbc..c64cf4a483 100644 --- a/src/lib-storage/list/index-mailbox-list-sync.c +++ b/src/lib-storage/list/index-mailbox-list-sync.c @@ -42,8 +42,6 @@ static struct index_list_map index_list_map[] = { { 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_allocated(struct mailbox *box) 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(struct mailbox_list *list) } } +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 --git a/src/lib-storage/list/index-mailbox-list.c b/src/lib-storage/list/index-mailbox-list.c index edb2e04199..9cae0ee1fd 100644 --- a/src/lib-storage/list/index-mailbox-list.c +++ b/src/lib-storage/list/index-mailbox-list.c @@ -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(struct mailbox_list *list) } } +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 --git a/src/lib-storage/mail-namespace.c b/src/lib-storage/mail-namespace.c index 3b0b22ad86..df4c7d84e5 100644 --- a/src/lib-storage/mail-namespace.c +++ b/src/lib-storage/mail-namespace.c @@ -10,8 +10,6 @@ #include -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_user *user, const char **error_r) } 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 --git a/src/lib-storage/mail-namespace.h b/src/lib-storage/mail-namespace.h index 69a41950f4..1bb420810c 100644 --- a/src/lib-storage/mail-namespace.h +++ b/src/lib-storage/mail-namespace.h @@ -66,9 +66,6 @@ struct mail_namespace { 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); /* Deinitialize all namespaces. mail_user_deinit() calls this automatically diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 202bf6058c..b0ffd9bb84 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -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" @@ -12,13 +13,6 @@ /* 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 --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index b9dafb9deb..b06369367c 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -23,15 +23,12 @@ struct mail_module_register mail_module_register = { 0 }; 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_namespace *ns, const char *driver, 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 mailbox_list *list, const char *name, 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 --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index fd5ee22964..72cc61a157 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -22,8 +22,6 @@ 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 *user, const char **error_r) 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 --git a/src/lib-storage/mail-user.h b/src/lib-storage/mail-user.h index 88ee81c77c..1593626f14 100644 --- a/src/lib-storage/mail-user.h +++ b/src/lib-storage/mail-user.h @@ -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 *); @@ -56,9 +57,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, const struct mail_user_settings *set); diff --git a/src/lib-storage/mailbox-list-private.h b/src/lib-storage/mailbox-list-private.h index db75a59207..8eb47f03e0 100644 --- a/src/lib-storage/mailbox-list-private.h +++ b/src/lib-storage/mailbox-list-private.h @@ -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 --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index 774443a56a..86df9d8caf 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -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 *driver, struct mail_namespace *ns, } 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 --git a/src/lib/module-dir.c b/src/lib/module-dir.c index ffe40a958d..06ce9a3946 100644 --- a/src/lib/module-dir.c +++ b/src/lib/module-dir.c @@ -146,7 +146,7 @@ module_load(const char *path, const char *name, bool require_init_funcs, } /* 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 *modules) for (module = modules; module != NULL; module = module->next) { if (module->init != NULL) { T_BEGIN { - module->init(); + module->init(module); } T_END; } } diff --git a/src/lib/module-dir.h b/src/lib/module-dir.h index 6846668b68..0f83a34f4f 100644 --- a/src/lib/module-dir.h +++ b/src/lib/module-dir.h @@ -5,7 +5,7 @@ struct module { char *path, *name; void *handle; - void (*init)(void); + void (*init)(struct module *module); void (*deinit)(void); struct module *next; diff --git a/src/lib/strfuncs.c b/src/lib/strfuncs.c index f072646fd7..b9f310b469 100644 --- a/src/lib/strfuncs.c +++ b/src/lib/strfuncs.c @@ -541,6 +541,15 @@ bool str_array_remove(const char **arr, const char *value) return FALSE; } +bool str_array_find(const char *const *arr, const char *value) +{ + for (; *arr != NULL; arr++) { + if (strcmp(*arr, value) == 0) + return TRUE; + } + return FALSE; +} + bool str_array_icase_find(const char *const *arr, const char *value) { for (; *arr != NULL; arr++) { diff --git a/src/lib/strfuncs.h b/src/lib/strfuncs.h index 63902bc35b..f6ed85c1ff 100644 --- a/src/lib/strfuncs.h +++ b/src/lib/strfuncs.h @@ -80,8 +80,9 @@ const char *t_strarray_join(const char *const *arr, const char *separator) ATTR_MALLOC; /* Removes a value from NULL-terminated string array. Returns TRUE if found. */ bool str_array_remove(const char **arr, const char *value); -/* Returns TRUE if value exists in NULL-terminated string array. - Strings are compared case-insensitively. */ +/* Returns TRUE if value exists in NULL-terminated string array. */ +bool str_array_find(const char *const *arr, const char *value); +/* Like str_array_find(), but use strcasecmp(). */ bool str_array_icase_find(const char *const *arr, const char *value); /* INTERNAL */ diff --git a/src/plugins/acl/acl-mailbox-list.c b/src/plugins/acl/acl-mailbox-list.c index f191f80fe0..7539777023 100644 --- a/src/plugins/acl/acl-mailbox-list.c +++ b/src/plugins/acl/acl-mailbox-list.c @@ -620,7 +620,4 @@ void acl_mailbox_list_created(struct mailbox_list *list) } else { acl_mailbox_list_init_default(list); } - - if (acl_next_hook_mailbox_list_created != NULL) - acl_next_hook_mailbox_list_created(list); } diff --git a/src/plugins/acl/acl-plugin.c b/src/plugins/acl/acl-plugin.c index a7a2019bea..9ac8645ea7 100644 --- a/src/plugins/acl/acl-plugin.c +++ b/src/plugins/acl/acl-plugin.c @@ -7,27 +7,20 @@ #include -void (*acl_next_hook_mail_storage_created)(struct mail_storage *storage); -void (*acl_next_hook_mailbox_list_created)(struct mailbox_list *list); -void (*acl_next_hook_mail_user_created)(struct mail_user *user); - const char *acl_plugin_version = PACKAGE_VERSION; -void acl_plugin_init(void) -{ - acl_next_hook_mail_storage_created = hook_mail_storage_created; - hook_mail_storage_created = acl_mail_storage_created; - - acl_next_hook_mailbox_list_created = hook_mailbox_list_created; - hook_mailbox_list_created = acl_mailbox_list_created; +static struct mail_storage_hooks acl_mail_storage_hooks = { + .mail_user_created = acl_mail_user_created, + .mail_storage_created = acl_mail_storage_created, + .mailbox_list_created = acl_mailbox_list_created +}; - acl_next_hook_mail_user_created = hook_mail_user_created; - hook_mail_user_created = acl_mail_user_created; +void acl_plugin_init(struct module *module) +{ + mail_storage_hooks_add(module, &acl_mail_storage_hooks); } void acl_plugin_deinit(void) { - hook_mail_storage_created = acl_next_hook_mail_storage_created; - hook_mailbox_list_created = acl_next_hook_mailbox_list_created; - hook_mail_user_created = acl_next_hook_mail_user_created; + mail_storage_hooks_remove(&acl_mail_storage_hooks); } diff --git a/src/plugins/acl/acl-plugin.h b/src/plugins/acl/acl-plugin.h index ae5f233fe5..221bd68bbf 100644 --- a/src/plugins/acl/acl-plugin.h +++ b/src/plugins/acl/acl-plugin.h @@ -34,9 +34,6 @@ struct acl_mailbox_list { struct acl_storage_rights_context rights; }; -extern void (*acl_next_hook_mail_storage_created)(struct mail_storage *storage); -extern void (*acl_next_hook_mailbox_list_created)(struct mailbox_list *list); -extern void (*acl_next_hook_mail_user_created)(struct mail_user *user); extern MODULE_CONTEXT_DEFINE(acl_storage_module, &mail_storage_module_register); extern MODULE_CONTEXT_DEFINE(acl_user_module, &mail_user_module_register); extern MODULE_CONTEXT_DEFINE(acl_mailbox_list_module, @@ -56,7 +53,7 @@ int acl_mailbox_list_have_right(struct mailbox_list *list, const char *name, bool parent, unsigned int acl_storage_right_idx, bool *can_see_r); -void acl_plugin_init(void); +void acl_plugin_init(struct module *module); void acl_plugin_deinit(void); #endif diff --git a/src/plugins/acl/acl-storage.c b/src/plugins/acl/acl-storage.c index 1d12835a2e..a36029df8e 100644 --- a/src/plugins/acl/acl-storage.c +++ b/src/plugins/acl/acl-storage.c @@ -23,17 +23,14 @@ void acl_mail_storage_created(struct mail_storage *storage) if (auser == NULL) { /* ACLs disabled for this user */ - } else { - 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); + return; } - if (acl_next_hook_mail_storage_created != NULL) - acl_next_hook_mail_storage_created(storage); + 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) @@ -76,7 +73,4 @@ void acl_mail_user_created(struct mail_user *user) if (user->mail_debug) i_debug("acl: No acl setting - ACLs are disabled"); } - - if (acl_next_hook_mail_user_created != NULL) - acl_next_hook_mail_user_created(user); } diff --git a/src/plugins/autocreate/autocreate-plugin.c b/src/plugins/autocreate/autocreate-plugin.c index e331be6c27..fdf9757c3b 100644 --- a/src/plugins/autocreate/autocreate-plugin.c +++ b/src/plugins/autocreate/autocreate-plugin.c @@ -2,6 +2,7 @@ #include "lib.h" #include "mail-storage.h" +#include "mail-storage-hooks.h" #include "mail-namespace.h" #include "autocreate-plugin.h" @@ -9,9 +10,6 @@ const char *autocreate_plugin_version = PACKAGE_VERSION; -static void (*autocreate_next_hook_mail_namespaces_created) - (struct mail_namespace *ns); - static void autocreate_mailbox(struct mail_namespace *namespaces, const char *name) { @@ -102,20 +100,18 @@ autocreate_mail_namespaces_created(struct mail_namespace *namespaces) { autocreate_mailboxes(namespaces); autosubscribe_mailboxes(namespaces); - - if (autocreate_next_hook_mail_namespaces_created != NULL) - autocreate_next_hook_mail_namespaces_created(namespaces); } -void autocreate_plugin_init(void) +static struct mail_storage_hooks autocreate_mail_storage_hooks = { + .mail_namespaces_created = autocreate_mail_namespaces_created +}; + +void autocreate_plugin_init(struct module *module) { - autocreate_next_hook_mail_namespaces_created = - hook_mail_namespaces_created; - hook_mail_namespaces_created = autocreate_mail_namespaces_created; + mail_storage_hooks_add(module, &autocreate_mail_storage_hooks); } void autocreate_plugin_deinit(void) { - hook_mail_namespaces_created = - autocreate_next_hook_mail_namespaces_created; + mail_storage_hooks_remove(&autocreate_mail_storage_hooks); } diff --git a/src/plugins/autocreate/autocreate-plugin.h b/src/plugins/autocreate/autocreate-plugin.h index d24d801eac..59a363db3a 100644 --- a/src/plugins/autocreate/autocreate-plugin.h +++ b/src/plugins/autocreate/autocreate-plugin.h @@ -1,7 +1,7 @@ #ifndef AUTOCREATE_PLUGIN_H #define AUTOCREATE_PLUGIN_H -void autocreate_plugin_init(void); +void autocreate_plugin_init(struct module *module); void autocreate_plugin_deinit(void); #endif diff --git a/src/plugins/convert/convert-plugin.c b/src/plugins/convert/convert-plugin.c index 1052892c36..0ec468f943 100644 --- a/src/plugins/convert/convert-plugin.c +++ b/src/plugins/convert/convert-plugin.c @@ -2,6 +2,7 @@ #include "lib.h" #include "mail-namespace.h" +#include "mail-storage-hooks.h" #include "convert-storage.h" #include "convert-plugin.h" @@ -9,9 +10,6 @@ const char *convert_plugin_version = PACKAGE_VERSION; -static void (*convert_next_hook_mail_namespaces_created) - (struct mail_namespace *namespaces); - static void convert_mail_storage(struct mail_namespace *namespaces, const char *convert_mail) { @@ -38,7 +36,7 @@ static void convert_mail_storage(struct mail_namespace *namespaces, } static void -convert_hook_mail_namespaces_created(struct mail_namespace *namespaces) +convert_mail_namespaces_created(struct mail_namespace *namespaces) { const char *convert_mail; @@ -48,20 +46,18 @@ convert_hook_mail_namespaces_created(struct mail_namespace *namespaces) convert_mail_storage(namespaces, convert_mail); else if (namespaces->user->mail_debug) i_debug("convert: No convert_mail setting - plugin disabled"); - - if (convert_next_hook_mail_namespaces_created != NULL) - convert_next_hook_mail_namespaces_created(namespaces); } -void convert_plugin_init(void) +static struct mail_storage_hooks convert_mail_storage_hooks = { + .mail_namespaces_created = convert_mail_namespaces_created +}; + +void convert_plugin_init(struct module *module) { - convert_next_hook_mail_namespaces_created = - hook_mail_namespaces_created; - hook_mail_namespaces_created = convert_hook_mail_namespaces_created; + mail_storage_hooks_add(module, &convert_mail_storage_hooks); } void convert_plugin_deinit(void) { - hook_mail_namespaces_created = - convert_next_hook_mail_namespaces_created; + mail_storage_hooks_remove(&convert_mail_storage_hooks); } diff --git a/src/plugins/convert/convert-plugin.h b/src/plugins/convert/convert-plugin.h index e8822b12c9..7df2ca1e37 100644 --- a/src/plugins/convert/convert-plugin.h +++ b/src/plugins/convert/convert-plugin.h @@ -1,7 +1,7 @@ #ifndef CONVERT_PLUGIN_H #define CONVERT_PLUGIN_H -void convert_plugin_init(void); +void convert_plugin_init(struct module *module); void convert_plugin_deinit(void); #endif diff --git a/src/plugins/expire/expire-plugin.c b/src/plugins/expire/expire-plugin.c index a2e3108d23..611f431d38 100644 --- a/src/plugins/expire/expire-plugin.c +++ b/src/plugins/expire/expire-plugin.c @@ -43,9 +43,6 @@ struct expire_transaction_context { const char *expire_plugin_version = PACKAGE_VERSION; -static void (*next_hook_mailbox_allocated)(struct mailbox *box); -static void (*next_hook_mail_namespaces_created)(struct mail_namespace *ns); - static MODULE_CONTEXT_DEFINE_INIT(expire_storage_module, &mail_storage_module_register); static MODULE_CONTEXT_DEFINE_INIT(expire_mail_module, &mail_module_register); @@ -280,9 +277,6 @@ static void expire_mailbox_allocated(struct mailbox *box) if (euser != NULL) expire_mailbox_allocate_init(box, euser); - - if (next_hook_mailbox_allocated != NULL) - next_hook_mailbox_allocated(box); } static void expire_mail_user_deinit(struct mail_user *user) @@ -329,22 +323,19 @@ static void expire_mail_namespaces_created(struct mail_namespace *ns) else MODULE_CONTEXT_SET(user, expire_mail_user_module, euser); } - - if (next_hook_mail_namespaces_created != NULL) - next_hook_mail_namespaces_created(ns); } -void expire_plugin_init(void) -{ - next_hook_mailbox_allocated = hook_mailbox_allocated; - hook_mailbox_allocated = expire_mailbox_allocated; +static struct mail_storage_hooks expire_mail_storage_hooks = { + .mail_namespaces_created = expire_mail_namespaces_created, + .mailbox_allocated = expire_mailbox_allocated +}; - next_hook_mail_namespaces_created = hook_mail_namespaces_created; - hook_mail_namespaces_created = expire_mail_namespaces_created; +void expire_plugin_init(struct module *module) +{ + mail_storage_hooks_add(module, &expire_mail_storage_hooks); } void expire_plugin_deinit(void) { - hook_mailbox_allocated = next_hook_mailbox_allocated; - hook_mail_namespaces_created = next_hook_mail_namespaces_created; + mail_storage_hooks_remove(&expire_mail_storage_hooks); } diff --git a/src/plugins/expire/expire-plugin.h b/src/plugins/expire/expire-plugin.h index 827ab940d3..9f46c0ac89 100644 --- a/src/plugins/expire/expire-plugin.h +++ b/src/plugins/expire/expire-plugin.h @@ -1,7 +1,7 @@ #ifndef EXPIRE_PLUGIN_H #define EXPIRE_PLUGIN_H -void expire_plugin_init(void); +void expire_plugin_init(struct module *module); void expire_plugin_deinit(void); #endif diff --git a/src/plugins/fts-lucene/fts-lucene-plugin.c b/src/plugins/fts-lucene/fts-lucene-plugin.c index 7dd9420c5f..4cd99941f7 100644 --- a/src/plugins/fts-lucene/fts-lucene-plugin.c +++ b/src/plugins/fts-lucene/fts-lucene-plugin.c @@ -8,7 +8,7 @@ const char *fts_lucene_plugin_version = PACKAGE_VERSION; unsigned int fts_lucene_storage_module_id; -void fts_lucene_plugin_init(void) +void fts_lucene_plugin_init(struct module *module ATTR_UNUSED) { fts_backend_register(&fts_backend_lucene); } diff --git a/src/plugins/fts-lucene/fts-lucene-plugin.h b/src/plugins/fts-lucene/fts-lucene-plugin.h index 66d68b2d68..2a371d0b1a 100644 --- a/src/plugins/fts-lucene/fts-lucene-plugin.h +++ b/src/plugins/fts-lucene/fts-lucene-plugin.h @@ -5,7 +5,7 @@ extern struct fts_backend fts_backend_lucene; -void fts_lucene_plugin_init(void); +void fts_lucene_plugin_init(struct module *module); void fts_lucene_plugin_deinit(void); #endif diff --git a/src/plugins/fts-solr/fts-solr-plugin.c b/src/plugins/fts-solr/fts-solr-plugin.c index bbff7cf1f6..1e686fbd1c 100644 --- a/src/plugins/fts-solr/fts-solr-plugin.c +++ b/src/plugins/fts-solr/fts-solr-plugin.c @@ -3,13 +3,13 @@ #include "lib.h" #include "array.h" #include "mail-user.h" +#include "mail-storage-hooks.h" #include "fts-solr-plugin.h" #include const char *fts_solr_plugin_version = PACKAGE_VERSION; -static void (*fts_solr_next_hook_mail_user_created)(struct mail_user *user); struct fts_solr_user_module fts_solr_user_module = MODULE_CONTEXT_INIT(&mail_user_module_register); @@ -65,23 +65,22 @@ static void fts_solr_mail_user_created(struct mail_user *user) env = mail_user_plugin_getenv(user, "fts_solr"); if (env != NULL) fts_solr_mail_user_create(user, env); - - if (fts_solr_next_hook_mail_user_created != NULL) - fts_solr_next_hook_mail_user_created(user); } -void fts_solr_plugin_init(void) +static struct mail_storage_hooks fts_solr_mail_storage_hooks = { + .mail_user_created = fts_solr_mail_user_created +}; + +void fts_solr_plugin_init(struct module *module) { fts_backend_register(&fts_backend_solr); - - fts_solr_next_hook_mail_user_created = hook_mail_user_created; - hook_mail_user_created = fts_solr_mail_user_created; + mail_storage_hooks_add(module, &fts_solr_mail_storage_hooks); } void fts_solr_plugin_deinit(void) { fts_backend_unregister(fts_backend_solr.name); - hook_mail_user_created = fts_solr_next_hook_mail_user_created; + mail_storage_hooks_remove(&fts_solr_mail_storage_hooks); } const char *fts_solr_plugin_dependencies[] = { "fts", NULL }; diff --git a/src/plugins/fts-solr/fts-solr-plugin.h b/src/plugins/fts-solr/fts-solr-plugin.h index 2069d131ff..aa2025704d 100644 --- a/src/plugins/fts-solr/fts-solr-plugin.h +++ b/src/plugins/fts-solr/fts-solr-plugin.h @@ -22,7 +22,7 @@ extern const char *fts_solr_plugin_dependencies[]; extern struct fts_backend fts_backend_solr; extern MODULE_CONTEXT_DEFINE(fts_solr_user_module, &mail_user_module_register); -void fts_solr_plugin_init(void); +void fts_solr_plugin_init(struct module *module); void fts_solr_plugin_deinit(void); #endif diff --git a/src/plugins/fts-squat/fts-squat-plugin.c b/src/plugins/fts-squat/fts-squat-plugin.c index 2b88600768..f3f15c48e8 100644 --- a/src/plugins/fts-squat/fts-squat-plugin.c +++ b/src/plugins/fts-squat/fts-squat-plugin.c @@ -5,7 +5,7 @@ const char *fts_squat_plugin_version = PACKAGE_VERSION; -void fts_squat_plugin_init(void) +void fts_squat_plugin_init(struct module *module ATTR_UNUSED) { fts_backend_register(&fts_backend_squat); } diff --git a/src/plugins/fts-squat/fts-squat-plugin.h b/src/plugins/fts-squat/fts-squat-plugin.h index b37951189e..0d6bfcbfe6 100644 --- a/src/plugins/fts-squat/fts-squat-plugin.h +++ b/src/plugins/fts-squat/fts-squat-plugin.h @@ -3,10 +3,12 @@ #include "fts-api-private.h" +struct module; + extern const char *fts_squat_plugin_dependencies[]; extern struct fts_backend fts_backend_squat; -void fts_squat_plugin_init(void); +void fts_squat_plugin_init(struct module *module); void fts_squat_plugin_deinit(void); #endif diff --git a/src/plugins/fts/fts-plugin.c b/src/plugins/fts/fts-plugin.c index 2309237978..80926dc332 100644 --- a/src/plugins/fts/fts-plugin.c +++ b/src/plugins/fts/fts-plugin.c @@ -1,22 +1,23 @@ /* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */ #include "lib.h" -#include "mail-storage-private.h" +#include "mail-storage-hooks.h" #include "fts-plugin.h" #include const char *fts_plugin_version = PACKAGE_VERSION; -void (*fts_next_hook_mailbox_allocated)(struct mailbox *box); +static struct mail_storage_hooks fts_mail_storage_hooks = { + .mailbox_allocated = fts_mailbox_allocated +}; -void fts_plugin_init(void) +void fts_plugin_init(struct module *module) { - fts_next_hook_mailbox_allocated = hook_mailbox_allocated; - hook_mailbox_allocated = fts_mailbox_allocated; + mail_storage_hooks_add(module, &fts_mail_storage_hooks); } void fts_plugin_deinit(void) { - hook_mailbox_allocated = fts_next_hook_mailbox_allocated; + mail_storage_hooks_remove(&fts_mail_storage_hooks); } diff --git a/src/plugins/fts/fts-plugin.h b/src/plugins/fts/fts-plugin.h index 93fc68b119..13533dfd83 100644 --- a/src/plugins/fts/fts-plugin.h +++ b/src/plugins/fts/fts-plugin.h @@ -1,11 +1,9 @@ #ifndef FTS_PLUGIN_H #define FTS_PLUGIN_H -extern void (*fts_next_hook_mailbox_allocated)(struct mailbox *box); - void fts_mailbox_allocated(struct mailbox *box); -void fts_plugin_init(void); +void fts_plugin_init(struct module *module); void fts_plugin_deinit(void); #endif diff --git a/src/plugins/fts/fts-storage.c b/src/plugins/fts/fts-storage.c index 4a6704e759..c7b3a7810d 100644 --- a/src/plugins/fts/fts-storage.c +++ b/src/plugins/fts/fts-storage.c @@ -1050,7 +1050,4 @@ void fts_mailbox_allocated(struct mailbox *box) env = mail_user_plugin_getenv(box->storage->user, "fts"); if (env != NULL) fts_mailbox_init(box, env); - - if (fts_next_hook_mailbox_allocated != NULL) - fts_next_hook_mailbox_allocated(box); } diff --git a/src/plugins/imap-acl/imap-acl-plugin.c b/src/plugins/imap-acl/imap-acl-plugin.c index aaefb1aacc..b1d5ecf469 100644 --- a/src/plugins/imap-acl/imap-acl-plugin.c +++ b/src/plugins/imap-acl/imap-acl-plugin.c @@ -621,7 +621,7 @@ static void imap_acl_client_created(struct client **client) next_hook_client_created(client); } -void imap_acl_plugin_init(void) +void imap_acl_plugin_init(struct module *module ATTR_UNUSED) { command_register("LISTRIGHTS", cmd_listrights, 0); command_register("GETACL", cmd_getacl, 0); diff --git a/src/plugins/imap-acl/imap-acl-plugin.h b/src/plugins/imap-acl/imap-acl-plugin.h index 71ce66b028..0435ac6331 100644 --- a/src/plugins/imap-acl/imap-acl-plugin.h +++ b/src/plugins/imap-acl/imap-acl-plugin.h @@ -3,7 +3,7 @@ extern const char *imap_acl_plugin_dependencies[]; -void imap_acl_plugin_init(void); +void imap_acl_plugin_init(struct module *module); void imap_acl_plugin_deinit(void); #endif diff --git a/src/plugins/imap-quota/imap-quota-plugin.c b/src/plugins/imap-quota/imap-quota-plugin.c index 86ecd7330a..740849b7a7 100644 --- a/src/plugins/imap-quota/imap-quota-plugin.c +++ b/src/plugins/imap-quota/imap-quota-plugin.c @@ -205,7 +205,7 @@ static void imap_quota_client_created(struct client **client) next_hook_client_created(client); } -void imap_quota_plugin_init(void) +void imap_quota_plugin_init(struct module *module ATTR_UNUSED) { command_register("GETQUOTAROOT", cmd_getquotaroot, 0); command_register("GETQUOTA", cmd_getquota, 0); diff --git a/src/plugins/imap-quota/imap-quota-plugin.h b/src/plugins/imap-quota/imap-quota-plugin.h index 057e4f6ace..dc0ed542a1 100644 --- a/src/plugins/imap-quota/imap-quota-plugin.h +++ b/src/plugins/imap-quota/imap-quota-plugin.h @@ -1,9 +1,11 @@ #ifndef IMAP_QUOTA_PLUGIN_H #define IMAP_QUOTA_PLUGIN_H +struct module; + extern const char *imap_quota_plugin_dependencies[]; -void imap_quota_plugin_init(void); +void imap_quota_plugin_init(struct module *module); void imap_quota_plugin_deinit(void); #endif diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.c b/src/plugins/lazy-expunge/lazy-expunge-plugin.c index 38587b3915..d56a953c1b 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c @@ -59,13 +59,6 @@ struct lazy_expunge_transaction { const char *lazy_expunge_plugin_version = PACKAGE_VERSION; -static void (*lazy_expunge_next_hook_mail_namespaces_created) - (struct mail_namespace *namespaces); -static void (*lazy_expunge_next_hook_mailbox_allocated)(struct mailbox *box); -static void (*lazy_expunge_next_hook_mailbox_list_created) - (struct mailbox_list *list); -static void (*lazy_expunge_next_hook_mail_user_created)(struct mail_user *user); - static MODULE_CONTEXT_DEFINE_INIT(lazy_expunge_mail_storage_module, &mail_storage_module_register); static MODULE_CONTEXT_DEFINE_INIT(lazy_expunge_mail_module, @@ -254,9 +247,6 @@ static void lazy_expunge_mailbox_allocated(struct mailbox *box) MODULE_CONTEXT_SET_SELF(box, lazy_expunge_mail_storage_module, mbox); } - - if (lazy_expunge_next_hook_mailbox_allocated != NULL) - lazy_expunge_next_hook_mailbox_allocated(box); } static int @@ -377,13 +367,10 @@ static void lazy_expunge_mailbox_list_created(struct mailbox_list *list) MODULE_CONTEXT_SET(list, lazy_expunge_mailbox_list_module, llist); } - - if (lazy_expunge_next_hook_mailbox_list_created != NULL) - lazy_expunge_next_hook_mailbox_list_created(list); } static void -lazy_expunge_hook_mail_namespaces_created(struct mail_namespace *namespaces) +lazy_expunge_mail_namespaces_created(struct mail_namespace *namespaces) { struct lazy_expunge_mail_user *luser = LAZY_EXPUNGE_USER_CONTEXT(namespaces->user); @@ -411,9 +398,6 @@ lazy_expunge_hook_mail_namespaces_created(struct mail_namespace *namespaces) llist = LAZY_EXPUNGE_LIST_CONTEXT(luser->lazy_ns[i]->list); llist->internal_namespace = TRUE; } - - if (lazy_expunge_next_hook_mail_namespaces_created != NULL) - lazy_expunge_next_hook_mail_namespaces_created(namespaces); } static void lazy_expunge_mail_user_created(struct mail_user *user) @@ -432,33 +416,21 @@ static void lazy_expunge_mail_user_created(struct mail_user *user) i_debug("lazy_expunge: No lazy_expunge setting - " "plugin disabled"); } - - if (lazy_expunge_next_hook_mail_user_created != NULL) - lazy_expunge_next_hook_mail_user_created(user); } -void lazy_expunge_plugin_init(void) -{ - lazy_expunge_next_hook_mail_namespaces_created = - hook_mail_namespaces_created; - hook_mail_namespaces_created = - lazy_expunge_hook_mail_namespaces_created; - - lazy_expunge_next_hook_mailbox_allocated = hook_mailbox_allocated; - hook_mailbox_allocated = lazy_expunge_mailbox_allocated; - - lazy_expunge_next_hook_mailbox_list_created = hook_mailbox_list_created; - hook_mailbox_list_created = lazy_expunge_mailbox_list_created; +static struct mail_storage_hooks lazy_expunge_mail_storage_hooks = { + .mail_user_created = lazy_expunge_mail_user_created, + .mail_namespaces_created = lazy_expunge_mail_namespaces_created, + .mailbox_list_created = lazy_expunge_mailbox_list_created, + .mailbox_allocated = lazy_expunge_mailbox_allocated +}; - lazy_expunge_next_hook_mail_user_created = hook_mail_user_created; - hook_mail_user_created = lazy_expunge_mail_user_created; +void lazy_expunge_plugin_init(struct module *module) +{ + mail_storage_hooks_add(module, &lazy_expunge_mail_storage_hooks); } void lazy_expunge_plugin_deinit(void) { - hook_mail_namespaces_created = - lazy_expunge_hook_mail_namespaces_created; - hook_mailbox_allocated = lazy_expunge_next_hook_mailbox_allocated; - hook_mailbox_list_created = lazy_expunge_next_hook_mailbox_list_created; - hook_mail_user_created = lazy_expunge_next_hook_mail_user_created; + mail_storage_hooks_remove(&lazy_expunge_mail_storage_hooks); } diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.h b/src/plugins/lazy-expunge/lazy-expunge-plugin.h index a49326b7e6..4875c69b62 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.h +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.h @@ -1,7 +1,7 @@ #ifndef LAZY_EXPUNGE_PLUGIN_H #define TLAZY_EXPUNGE_PLUGIN_H -void lazy_expunge_plugin_init(void); +void lazy_expunge_plugin_init(struct module *module); void lazy_expunge_plugin_deinit(void); #endif diff --git a/src/plugins/listescape/listescape-plugin.c b/src/plugins/listescape/listescape-plugin.c index 5ca6afedaa..8cf3a00a9a 100644 --- a/src/plugins/listescape/listescape-plugin.c +++ b/src/plugins/listescape/listescape-plugin.c @@ -32,11 +32,6 @@ struct listescape_mailbox_list { const char *listescape_plugin_version = PACKAGE_VERSION; -static void (*listescape_next_hook_mail_storage_created) - (struct mail_storage *storage); -static void (*listescape_next_hook_mailbox_list_created) - (struct mailbox_list *list); - static MODULE_CONTEXT_DEFINE_INIT(listescape_storage_module, &mail_storage_module_register); static MODULE_CONTEXT_DEFINE_INIT(listescape_list_module, @@ -299,9 +294,6 @@ static void listescape_mail_storage_created(struct mail_storage *storage) { struct listescape_mail_storage *mstorage; - if (listescape_next_hook_mail_storage_created != NULL) - listescape_next_hook_mail_storage_created(storage); - mstorage = p_new(storage->pool, struct listescape_mail_storage, 1); mstorage->module_ctx.super = storage->v; storage->v.mailbox_alloc = listescape_mailbox_alloc; @@ -314,9 +306,6 @@ static void listescape_mailbox_list_created(struct mailbox_list *list) struct listescape_mailbox_list *mlist; const char *env; - if (listescape_next_hook_mailbox_list_created != NULL) - listescape_next_hook_mailbox_list_created(list); - if (list->hierarchy_sep == list->ns->sep) return; @@ -342,17 +331,17 @@ static void listescape_mailbox_list_created(struct mailbox_list *list) MODULE_CONTEXT_SET(list, listescape_list_module, mlist); } -void listescape_plugin_init(void) -{ - listescape_next_hook_mail_storage_created = hook_mail_storage_created; - hook_mail_storage_created = listescape_mail_storage_created; +static struct mail_storage_hooks listescape_mail_storage_hooks = { + .mail_storage_created = listescape_mail_storage_created, + .mailbox_list_created = listescape_mailbox_list_created +}; - listescape_next_hook_mailbox_list_created = hook_mailbox_list_created; - hook_mailbox_list_created = listescape_mailbox_list_created; +void listescape_plugin_init(struct module *module) +{ + mail_storage_hooks_add(module, &listescape_mail_storage_hooks); } void listescape_plugin_deinit(void) { - hook_mail_storage_created = listescape_next_hook_mail_storage_created; - hook_mailbox_list_created = listescape_next_hook_mailbox_list_created; + mail_storage_hooks_remove(&listescape_mail_storage_hooks); } diff --git a/src/plugins/listescape/listescape-plugin.h b/src/plugins/listescape/listescape-plugin.h index d088191dc1..f8ff4fc5ae 100644 --- a/src/plugins/listescape/listescape-plugin.h +++ b/src/plugins/listescape/listescape-plugin.h @@ -1,7 +1,7 @@ #ifndef LISTESCAPE_PLUGIN_H #define LISTESCAPE_PLUGIN_H -void listescape_plugin_init(void); +void listescape_plugin_init(struct module *module); void listescape_plugin_deinit(void); #endif diff --git a/src/plugins/mail-log/mail-log-plugin.c b/src/plugins/mail-log/mail-log-plugin.c index be5652ffaa..f379d6f63a 100644 --- a/src/plugins/mail-log/mail-log-plugin.c +++ b/src/plugins/mail-log/mail-log-plugin.c @@ -420,7 +420,7 @@ static const struct notify_vfuncs mail_log_vfuncs = { static struct notify_context *mail_log_ctx; -void mail_log_plugin_init(void) +void mail_log_plugin_init(struct module *module ATTR_UNUSED) { mail_log_read_settings(&mail_log_set); mail_log_ctx = notify_register(&mail_log_vfuncs); diff --git a/src/plugins/mail-log/mail-log-plugin.h b/src/plugins/mail-log/mail-log-plugin.h index face3ca39d..0af47ac7ae 100644 --- a/src/plugins/mail-log/mail-log-plugin.h +++ b/src/plugins/mail-log/mail-log-plugin.h @@ -3,7 +3,7 @@ extern const char *mail_log_plugin_dependencies[]; -void mail_log_plugin_init(void); +void mail_log_plugin_init(struct module *module); void mail_log_plugin_deinit(void); #endif diff --git a/src/plugins/mbox-snarf/mbox-snarf-plugin.c b/src/plugins/mbox-snarf/mbox-snarf-plugin.c index aac7bfa389..578d3092fe 100644 --- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c +++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c @@ -28,9 +28,6 @@ struct mbox_snarf_mailbox { const char *mbox_snarf_plugin_version = PACKAGE_VERSION; -static void (*mbox_snarf_next_hook_mail_storage_created) - (struct mail_storage *storage); - static MODULE_CONTEXT_DEFINE_INIT(mbox_snarf_storage_module, &mail_storage_module_register); @@ -190,18 +187,18 @@ static void mbox_snarf_mail_storage_created(struct mail_storage *storage) path = mail_user_plugin_getenv(storage->user, "mbox_snarf"); if (path != NULL) mbox_snarf_mail_storage_create(storage, path); - - if (mbox_snarf_next_hook_mail_storage_created != NULL) - mbox_snarf_next_hook_mail_storage_created(storage); } -void mbox_snarf_plugin_init(void) +static struct mail_storage_hooks mbox_snarf_mail_storage_hooks = { + .mail_storage_created = mbox_snarf_mail_storage_created +}; + +void mbox_snarf_plugin_init(struct module *module) { - mbox_snarf_next_hook_mail_storage_created = hook_mail_storage_created; - hook_mail_storage_created = mbox_snarf_mail_storage_created; + mail_storage_hooks_add(module, &mbox_snarf_mail_storage_hooks); } void mbox_snarf_plugin_deinit(void) { - hook_mail_storage_created = mbox_snarf_next_hook_mail_storage_created; + mail_storage_hooks_remove(&mbox_snarf_mail_storage_hooks); } diff --git a/src/plugins/mbox-snarf/mbox-snarf-plugin.h b/src/plugins/mbox-snarf/mbox-snarf-plugin.h index f6cac265f6..6d82f0c60b 100644 --- a/src/plugins/mbox-snarf/mbox-snarf-plugin.h +++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.h @@ -1,7 +1,7 @@ #ifndef MBOX_SNARF_PLUGIN_H #define MBOX_SNARF_PLUGIN_H -void mbox_snarf_plugin_init(void); +void mbox_snarf_plugin_init(struct module *module); void mbox_snarf_plugin_deinit(void); #endif diff --git a/src/plugins/notify/notify-plugin-private.h b/src/plugins/notify/notify-plugin-private.h index d464cfe7ab..a5f0c529a9 100644 --- a/src/plugins/notify/notify-plugin-private.h +++ b/src/plugins/notify/notify-plugin-private.h @@ -24,7 +24,7 @@ void notify_contexts_mailbox_rename(struct mailbox_list *oldlist, struct mailbox_list *newlist, const char *newname, bool rename_children); -void notify_plugin_init_storage(void); +void notify_plugin_init_storage(struct module *module); void notify_plugin_deinit_storage(void); #endif diff --git a/src/plugins/notify/notify-plugin.c b/src/plugins/notify/notify-plugin.c index ccd6f6f874..779631691e 100644 --- a/src/plugins/notify/notify-plugin.c +++ b/src/plugins/notify/notify-plugin.c @@ -199,9 +199,9 @@ void notify_unregister(struct notify_context *ctx) i_free(ctx); } -void notify_plugin_init(void) +void notify_plugin_init(struct module *module) { - notify_plugin_init_storage(); + notify_plugin_init_storage(module); } void notify_plugin_deinit(void) diff --git a/src/plugins/notify/notify-plugin.h b/src/plugins/notify/notify-plugin.h index f268897d5e..560b22e3d4 100644 --- a/src/plugins/notify/notify-plugin.h +++ b/src/plugins/notify/notify-plugin.h @@ -8,6 +8,7 @@ struct mail_storage; struct mailbox_transaction_context; struct mailbox_list; struct notify_context; +struct module; struct notify_vfuncs { void *(*mail_transaction_begin)(struct mailbox_transaction_context *t); @@ -57,7 +58,7 @@ struct notify_context * notify_register(const struct notify_vfuncs *vfuncs); void notify_unregister(struct notify_context *ctx); -void notify_plugin_init(void); +void notify_plugin_init(struct module *module); void notify_plugin_deinit(void); #endif diff --git a/src/plugins/notify/notify-storage.c b/src/plugins/notify/notify-storage.c index b5bdea852b..c24d8c2a8f 100644 --- a/src/plugins/notify/notify-storage.c +++ b/src/plugins/notify/notify-storage.c @@ -23,11 +23,6 @@ static MODULE_CONTEXT_DEFINE_INIT(notify_mail_module, static MODULE_CONTEXT_DEFINE_INIT(notify_mailbox_list_module, &mailbox_list_module_register); -static void (*notify_next_hook_mail_storage_created) - (struct mail_storage *storage); -static void (*notify_next_hook_mailbox_list_created) - (struct mailbox_list *list); - static void notify_mail_expunge(struct mail *_mail) { @@ -269,9 +264,6 @@ static void notify_mail_storage_created(struct mail_storage *storage) storage->v.mailbox_alloc = notify_mailbox_alloc; MODULE_CONTEXT_SET_SELF(storage, notify_storage_module, lstorage); - - if (notify_next_hook_mail_storage_created != NULL) - notify_next_hook_mail_storage_created(storage); } static void notify_mailbox_list_created(struct mailbox_list *list) @@ -284,22 +276,19 @@ static void notify_mailbox_list_created(struct mailbox_list *list) list->v.rename_mailbox = notify_mailbox_list_rename; MODULE_CONTEXT_SET_SELF(list, notify_mailbox_list_module, llist); - - if (notify_next_hook_mailbox_list_created != NULL) - notify_next_hook_mailbox_list_created(list); } -void notify_plugin_init_storage(void) -{ - notify_next_hook_mail_storage_created = hook_mail_storage_created; - hook_mail_storage_created = notify_mail_storage_created; +static struct mail_storage_hooks notify_mail_storage_hooks = { + .mail_storage_created = notify_mail_storage_created, + .mailbox_list_created = notify_mailbox_list_created +}; - notify_next_hook_mailbox_list_created = hook_mailbox_list_created; - hook_mailbox_list_created = notify_mailbox_list_created; +void notify_plugin_init_storage(struct module *module) +{ + mail_storage_hooks_add(module, ¬ify_mail_storage_hooks); } void notify_plugin_deinit_storage(void) { - hook_mail_storage_created = notify_next_hook_mail_storage_created; - hook_mailbox_list_created = notify_next_hook_mailbox_list_created; + mail_storage_hooks_remove(¬ify_mail_storage_hooks); } diff --git a/src/plugins/quota/quota-plugin.c b/src/plugins/quota/quota-plugin.c index 44f3c96f58..89dec660c4 100644 --- a/src/plugins/quota/quota-plugin.c +++ b/src/plugins/quota/quota-plugin.c @@ -1,42 +1,27 @@ /* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */ #include "lib.h" -#include "mail-storage.h" -#include "mailbox-list-private.h" -#include "quota.h" +#include "mail-user.h" +#include "mail-storage-hooks.h" #include "quota-plugin.h" #include -/* defined by imap, pop3, lda */ -extern void (*hook_mail_storage_created)(struct mail_storage *storage); - -void (*quota_next_hook_mail_user_created)(struct mail_user *user); -void (*quota_next_hook_mail_storage_created)(struct mail_storage *storage); -void (*quota_next_hook_mailbox_list_created)(struct mailbox_list *list); -void (*quota_next_hook_mail_namespaces_created)(struct mail_namespace *namespaces); - const char *quota_plugin_version = PACKAGE_VERSION; -void quota_plugin_init(void) -{ - quota_next_hook_mail_user_created = hook_mail_user_created; - hook_mail_user_created = quota_mail_user_created; - - quota_next_hook_mail_storage_created = hook_mail_storage_created; - hook_mail_storage_created = quota_mail_storage_created; - - quota_next_hook_mailbox_list_created = hook_mailbox_list_created; - hook_mailbox_list_created = quota_mailbox_list_created; +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, + .mailbox_list_created = quota_mailbox_list_created +}; - quota_next_hook_mail_namespaces_created = hook_mail_namespaces_created; - hook_mail_namespaces_created = quota_mail_namespaces_created; +void quota_plugin_init(struct module *module) +{ + mail_storage_hooks_add(module, "a_mail_storage_hooks); } void quota_plugin_deinit(void) { - hook_mail_user_created = quota_next_hook_mail_user_created; - hook_mail_storage_created = quota_next_hook_mail_storage_created; - hook_mailbox_list_created = quota_next_hook_mailbox_list_created; - hook_mail_namespaces_created = quota_next_hook_mail_namespaces_created; + mail_storage_hooks_remove("a_mail_storage_hooks); } diff --git a/src/plugins/quota/quota-plugin.h b/src/plugins/quota/quota-plugin.h index 24edb9f1cc..2b0268ecdd 100644 --- a/src/plugins/quota/quota-plugin.h +++ b/src/plugins/quota/quota-plugin.h @@ -3,6 +3,8 @@ #include "module-context.h" +struct module; + #define QUOTA_USER_CONTEXT(obj) \ MODULE_CONTEXT(obj, quota_user_module) @@ -14,11 +16,6 @@ struct quota_user { struct mail_storage; -extern void (*quota_next_hook_mail_user_created)(struct mail_user *user); -extern void (*quota_next_hook_mail_storage_created) - (struct mail_storage *storage); -extern void (*quota_next_hook_mailbox_list_created)(struct mailbox_list *list); - extern MODULE_CONTEXT_DEFINE(quota_user_module, &mail_user_module_register); void quota_mail_user_created(struct mail_user *user); @@ -26,7 +23,7 @@ void quota_mail_storage_created(struct mail_storage *storage); void quota_mailbox_list_created(struct mailbox_list *list); void quota_mail_namespaces_created(struct mail_namespace *namespaces); -void quota_plugin_init(void); +void quota_plugin_init(struct module *module); void quota_plugin_deinit(void); #endif diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index a8225aa1a5..4b9db09999 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -487,9 +487,6 @@ void quota_mail_user_created(struct mail_user *user) } else if (user->mail_debug) { i_debug("quota: No quota setting - plugin disabled"); } - - if (quota_next_hook_mail_user_created != NULL) - quota_next_hook_mail_user_created(user); } static void quota_maildir_storage_set(struct mail_storage *storage) @@ -514,9 +511,6 @@ void quota_mail_storage_created(struct mail_storage *storage) MODULE_CONTEXT_SET_SELF(storage, quota_storage_module, qstorage); quota_maildir_storage_set(storage); - - if (quota_next_hook_mail_storage_created != NULL) - quota_next_hook_mail_storage_created(storage); } static struct quota_root * @@ -568,8 +562,6 @@ void quota_mailbox_list_created(struct mailbox_list *list) quota_get_mail_user_quota(list->ns->user); quota_add_user_namespace(quota, list->ns); } - if (quota_next_hook_mailbox_list_created != NULL) - quota_next_hook_mailbox_list_created(list); } static void quota_root_set_namespace(struct quota_root *root, diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index a6a91f06c7..e4380ecbda 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -45,8 +45,6 @@ const char *trash_plugin_version = PACKAGE_VERSION; static MODULE_CONTEXT_DEFINE_INIT(trash_user_module, &mail_user_module_register); -static void (*trash_next_hook_mail_namespaces_created) - (struct mail_namespace *namespaces); static int (*trash_next_quota_test_alloc)(struct quota_transaction_context *, uoff_t, bool *); @@ -294,7 +292,7 @@ static int read_configuration(struct mail_user *user, const char *path) } static void -trash_hook_mail_namespaces_created(struct mail_namespace *namespaces) +trash_mail_namespaces_created(struct mail_namespace *namespaces) { struct mail_user *user = namespaces->user; struct quota_user *quser = QUOTA_USER_CONTEXT(user); @@ -318,20 +316,20 @@ trash_hook_mail_namespaces_created(struct mail_namespace *namespaces) quser->quota->set->test_alloc = trash_quota_test_alloc; } } - - if (trash_next_hook_mail_namespaces_created != NULL) - trash_next_hook_mail_namespaces_created(namespaces); } -void trash_plugin_init(void) +static struct mail_storage_hooks trash_mail_storage_hooks = { + .mail_namespaces_created = trash_mail_namespaces_created +}; + +void trash_plugin_init(struct module *module) { - trash_next_hook_mail_namespaces_created = hook_mail_namespaces_created; - hook_mail_namespaces_created = trash_hook_mail_namespaces_created; + mail_storage_hooks_add(module, &trash_mail_storage_hooks); } void trash_plugin_deinit(void) { - hook_mail_namespaces_created = trash_hook_mail_namespaces_created; + mail_storage_hooks_remove(&trash_mail_storage_hooks); } const char *trash_plugin_dependencies[] = { "quota", NULL }; diff --git a/src/plugins/trash/trash-plugin.h b/src/plugins/trash/trash-plugin.h index 6d9873f3fb..bd6db6bfd2 100644 --- a/src/plugins/trash/trash-plugin.h +++ b/src/plugins/trash/trash-plugin.h @@ -3,7 +3,7 @@ extern const char *trash_plugin_dependencies[]; -void trash_plugin_init(void); +void trash_plugin_init(struct module *module); void trash_plugin_deinit(void); #endif diff --git a/src/plugins/virtual/virtual-plugin.c b/src/plugins/virtual/virtual-plugin.c index c5ed5f40d2..0e678fe406 100644 --- a/src/plugins/virtual/virtual-plugin.c +++ b/src/plugins/virtual/virtual-plugin.c @@ -7,7 +7,7 @@ const char *virtual_plugin_version = PACKAGE_VERSION; -void virtual_plugin_init(void) +void virtual_plugin_init(struct module *module ATTR_UNUSED) { mail_storage_class_register(&virtual_storage); } diff --git a/src/plugins/virtual/virtual-plugin.h b/src/plugins/virtual/virtual-plugin.h index 59b5c7a2a6..39f04bbc07 100644 --- a/src/plugins/virtual/virtual-plugin.h +++ b/src/plugins/virtual/virtual-plugin.h @@ -1,7 +1,7 @@ #ifndef VIRTUAL_PLUGIN_H #define VIRTUAL_PLUGIN_H -void virtual_plugin_init(void); +void virtual_plugin_init(struct module *module); void virtual_plugin_deinit(void); #endif diff --git a/src/plugins/zlib/zlib-plugin.c b/src/plugins/zlib/zlib-plugin.c index c196408ebe..e87307400a 100644 --- a/src/plugins/zlib/zlib-plugin.c +++ b/src/plugins/zlib/zlib-plugin.c @@ -37,9 +37,6 @@ struct zlib_transaction_context { const char *zlib_plugin_version = PACKAGE_VERSION; -static void (*zlib_next_hook_mail_storage_created) - (struct mail_storage *storage); - static MODULE_CONTEXT_DEFINE_INIT(zlib_storage_module, &mail_storage_module_register); static MODULE_CONTEXT_DEFINE_INIT(zlib_mail_module, &mail_module_register); @@ -333,18 +330,18 @@ static void zlib_mail_storage_created(struct mail_storage *storage) storage->v.mailbox_alloc = zlib_mailbox_alloc; MODULE_CONTEXT_SET_SELF(storage, zlib_storage_module, qstorage); - - if (zlib_next_hook_mail_storage_created != NULL) - zlib_next_hook_mail_storage_created(storage); } -void zlib_plugin_init(void) +static struct mail_storage_hooks zlib_mail_storage_hooks = { + .mail_storage_created = zlib_mail_storage_created +}; + +void zlib_plugin_init(struct module *module) { - zlib_next_hook_mail_storage_created = hook_mail_storage_created; - hook_mail_storage_created = zlib_mail_storage_created; + mail_storage_hooks_add(module, &zlib_mail_storage_hooks); } void zlib_plugin_deinit(void) { - hook_mail_storage_created = zlib_next_hook_mail_storage_created; + mail_storage_hooks_remove(&zlib_mail_storage_hooks); } diff --git a/src/plugins/zlib/zlib-plugin.h b/src/plugins/zlib/zlib-plugin.h index 809c884224..98f520d9b7 100644 --- a/src/plugins/zlib/zlib-plugin.h +++ b/src/plugins/zlib/zlib-plugin.h @@ -1,7 +1,7 @@ #ifndef ZLIB_PLUGIN_H #define ZLIB_PLUGIN_H -void zlib_plugin_init(void); +void zlib_plugin_init(struct module *module); void zlib_plugin_deinit(void); #endif