dovecot-2.2: lib-storage: Added a way to create plugins that for...

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 19 23:30:04 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/7a334ebc0145
changeset: 16053:7a334ebc0145
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Mar 19 19:08:17 2013 +0200
description:
lib-storage: Added a way to create plugins that forcibly hook into mail storage.
Mostly meant for doveadm_sieve plugin.

diffstat:

 src/lib-storage/mail-storage-hooks.c   |  20 ++++++++++++++++++--
 src/lib-storage/mail-storage-hooks.h   |   4 ++++
 src/lib-storage/mail-storage-private.h |   3 +++
 3 files changed, 25 insertions(+), 2 deletions(-)

diffs (81 lines):

diff -r 0e5a359b7b7f -r 7a334ebc0145 src/lib-storage/mail-storage-hooks.c
--- a/src/lib-storage/mail-storage-hooks.c	Tue Mar 19 19:05:27 2013 +0200
+++ b/src/lib-storage/mail-storage-hooks.c	Tue Mar 19 19:08:17 2013 +0200
@@ -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 @@
 
 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 @@
 	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 @@
 	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 -r 0e5a359b7b7f -r 7a334ebc0145 src/lib-storage/mail-storage-hooks.h
--- a/src/lib-storage/mail-storage-hooks.h	Tue Mar 19 19:05:27 2013 +0200
+++ b/src/lib-storage/mail-storage-hooks.h	Tue Mar 19 19:08:17 2013 +0200
@@ -25,6 +25,10 @@
 
 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 -r 0e5a359b7b7f -r 7a334ebc0145 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Tue Mar 19 19:05:27 2013 +0200
+++ b/src/lib-storage/mail-storage-private.h	Tue Mar 19 19:08:17 2013 +0200
@@ -644,6 +644,9 @@
 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);


More information about the dovecot-cvs mailing list