From: Timo Sirainen Date: Tue, 19 Mar 2013 17:08:17 +0000 (+0200) Subject: lib-storage: Added a way to create plugins that forcibly hook into mail storage. X-Git-Tag: 2.2.rc3~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e563b8a1457be8c08cc7567043c9f06b8243a025;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added a way to create plugins that forcibly hook into mail storage. Mostly meant for doveadm_sieve plugin. --- diff --git a/src/lib-storage/mail-storage-hooks.c b/src/lib-storage/mail-storage-hooks.c index d4630f1122..fd8d9a6a30 100644 --- a/src/lib-storage/mail-storage-hooks.c +++ b/src/lib-storage/mail-storage-hooks.c @@ -12,6 +12,7 @@ struct mail_storage_module_hooks { struct module *module; const struct mail_storage_hooks *hooks; + bool forced; }; struct hook_stack { @@ -41,7 +42,8 @@ static ARRAY(const struct mail_storage_hooks *) internal_hooks = ARRAY_INIT; void mail_storage_hooks_init(void) { - i_array_init(&module_hooks, 32); + if (!array_is_created(&module_hooks)) + i_array_init(&module_hooks, 32); i_array_init(&internal_hooks, 8); } @@ -60,9 +62,23 @@ void mail_storage_hooks_add(struct module *module, new_hook.module = module; new_hook.hooks = hooks; + /* allow adding hooks before mail_storage_hooks_init() */ + if (!array_is_created(&module_hooks)) + i_array_init(&module_hooks, 32); array_append(&module_hooks, &new_hook, 1); } +void mail_storage_hooks_add_forced(struct module *module, + const struct mail_storage_hooks *hooks) +{ + struct mail_storage_module_hooks *hook; + + mail_storage_hooks_add(module, hooks); + hook = array_idx_modifiable(&module_hooks, + array_count(&module_hooks)-1); + hook->forced = TRUE; +} + void mail_storage_hooks_remove(const struct mail_storage_hooks *hooks) { const struct mail_storage_module_hooks *module_hook; @@ -125,7 +141,7 @@ static void mail_user_add_plugin_hooks(struct mail_user *user) plugins = t_strsplit_spaces(user->set->mail_plugins, ", "); array_foreach(&module_hooks, module_hook) { name = module_get_plugin_name(module_hook->module); - if (str_array_find(plugins, name)) + if (str_array_find(plugins, name) || module_hook->forced) array_append(&tmp_hooks, module_hook, 1); } diff --git a/src/lib-storage/mail-storage-hooks.h b/src/lib-storage/mail-storage-hooks.h index ae8583e91d..0cba2a08f4 100644 --- a/src/lib-storage/mail-storage-hooks.h +++ b/src/lib-storage/mail-storage-hooks.h @@ -25,6 +25,10 @@ void mail_storage_hooks_deinit(void); void mail_storage_hooks_add(struct module *module, const struct mail_storage_hooks *hooks); +/* Add hooks to this plugin regardless of whether it exists in user's + mail_plugins setting. */ +void mail_storage_hooks_add_forced(struct module *module, + const struct mail_storage_hooks *hooks); void mail_storage_hooks_remove(const struct mail_storage_hooks *hooks); void mail_storage_hooks_add_internal(const struct mail_storage_hooks *hooks); diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 3c31ef0997..a1ffe251e0 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -644,6 +644,9 @@ int mailbox_create_fd(struct mailbox *box, const char *path, int flags, unsigned int mail_storage_get_lock_timeout(struct mail_storage *storage, unsigned int secs); void mail_storage_free_binary_cache(struct mail_storage *storage); +int mailbox_attribute_value_to_string(struct mail_storage *storage, + const struct mail_attribute_value *value, + const char **str_r); enum mail_index_open_flags mail_storage_settings_to_index_flags(const struct mail_storage_settings *set);