dovecot-2.0: Added a notify plugin that can be used as a generic...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Aug 24 23:59:01 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/f751c23561f9
changeset: 9812:f751c23561f9
user: Timo Sirainen <tss at iki.fi>
date: Mon Aug 24 16:57:50 2009 -0400
description:
Added a notify plugin that can be used as a generic event catching framework by other plugins.
Patch by Mark Washenberger / Rackspace.
diffstat:
8 files changed, 677 insertions(+)
configure.in | 1
src/plugins/Makefile.am | 1
src/plugins/notify/Makefile.am | 29 ++
src/plugins/notify/notify-noop.c | 32 ++
src/plugins/notify/notify-plugin-private.h | 30 ++
src/plugins/notify/notify-plugin.c | 210 ++++++++++++++++++
src/plugins/notify/notify-plugin.h | 63 +++++
src/plugins/notify/notify-storage.c | 311 ++++++++++++++++++++++++++++
diffs (truncated from 721 to 300 lines):
diff -r 211853d48eaf -r f751c23561f9 configure.in
--- a/configure.in Mon Aug 24 16:55:12 2009 -0400
+++ b/configure.in Mon Aug 24 16:57:50 2009 -0400
@@ -2506,6 +2506,7 @@ src/plugins/listescape/Makefile
src/plugins/listescape/Makefile
src/plugins/mail-log/Makefile
src/plugins/mbox-snarf/Makefile
+src/plugins/notify/Makefile
src/plugins/quota/Makefile
src/plugins/imap-quota/Makefile
src/plugins/trash/Makefile
diff -r 211853d48eaf -r f751c23561f9 src/plugins/Makefile.am
--- a/src/plugins/Makefile.am Mon Aug 24 16:55:12 2009 -0400
+++ b/src/plugins/Makefile.am Mon Aug 24 16:57:50 2009 -0400
@@ -22,6 +22,7 @@ SUBDIRS = \
listescape \
mail-log \
mbox-snarf \
+ notify \
quota \
imap-quota \
trash \
diff -r 211853d48eaf -r f751c23561f9 src/plugins/notify/Makefile.am
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/notify/Makefile.am Mon Aug 24 16:57:50 2009 -0400
@@ -0,0 +1,29 @@
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-mail \
+ -I$(top_srcdir)/src/lib-imap \
+ -I$(top_srcdir)/src/lib-index \
+ -I$(top_srcdir)/src/lib-storage \
+ -I$(top_srcdir)/src/lib-storage/index \
+ -I$(top_srcdir)/src/lib-storage/index/maildir
+
+lib15_notify_plugin_la_LDFLAGS = -module -avoid-version
+
+module_LTLIBRARIES = \
+ lib15_notify_plugin.la
+
+lib15_notify_plugin_la_SOURCES = \
+ notify-plugin.c \
+ notify-noop.c \
+ notify-storage.c
+
+noinst_HEADERS = \
+ notify-plugin.h
+ notify-plugin-private.h
+
+install-exec-local:
+ for d in imap pop3 lda; do \
+ $(mkdir_p) $(DESTDIR)$(moduledir)/$$d; \
+ rm -f $(DESTDIR)$(moduledir)/$$d/lib15_notify_plugin$(MODULE_SUFFIX); \
+ $(LN_S) ../lib15_notify_plugin$(MODULE_SUFFIX) $(DESTDIR)$(moduledir)/$$d; \
+ done
diff -r 211853d48eaf -r f751c23561f9 src/plugins/notify/notify-noop.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/notify/notify-noop.c Mon Aug 24 16:57:50 2009 -0400
@@ -0,0 +1,32 @@
+#include "lib.h"
+#include "mail-types.h"
+#include "notify-plugin.h"
+
+void notify_noop_mail_transaction_begin(struct mailbox_transaction_context *t ATTR_UNUSED) {}
+void notify_noop_mail_save(void *txn ATTR_UNUSED,
+ struct mail *mail ATTR_UNUSED) {}
+void notify_noop_mail_copy(void *txn ATTR_UNUSED,
+ struct mail *src ATTR_UNUSED,
+ struct mail *dst ATTR_UNUSED) {}
+void notify_noop_mail_expunge(void *txn ATTR_UNUSED,
+ struct mail *mail ATTR_UNUSED) {}
+void notify_noop_mail_update_flags(void *txn ATTR_UNUSED,
+ struct mail *mail ATTR_UNUSED,
+ enum mail_flags old_flags ATTR_UNUSED) {}
+void notify_noop_mail_update_keywords(void *txn ATTR_UNUSED,
+ struct mail *mail ATTR_UNUSED,
+ const char *const *old_keywords ATTR_UNUSED) {}
+void notify_noop_mail_transaction_commit(void *txn ATTR_UNUSED,
+ struct mail_transaction_commit_changes *changes ATTR_UNUSED) {}
+void notify_noop_mail_transaction_rollback(void *txn ATTR_UNUSED) {}
+void *notify_noop_mailbox_delete_begin(struct mailbox_list *list ATTR_UNUSED,
+ const char *name ATTR_UNUSED) { return NULL; }
+void notify_noop_mailbox_delete_commit(void *txn ATTR_UNUSED,
+ struct mailbox_list *list ATTR_UNUSED,
+ const char *name ATTR_UNUSED) {}
+void notify_noop_mailbox_delete_rollback(void *txn ATTR_UNUSED) {}
+void notify_noop_mailbox_rename(struct mailbox_list *oldlist ATTR_UNUSED,
+ const char *oldname ATTR_UNUSED,
+ struct mailbox_list *newlist ATTR_UNUSED,
+ const char *newname ATTR_UNUSED,
+ bool rename_children ATTR_UNUSED) {}
diff -r 211853d48eaf -r f751c23561f9 src/plugins/notify/notify-plugin-private.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/notify/notify-plugin-private.h Mon Aug 24 16:57:50 2009 -0400
@@ -0,0 +1,30 @@
+#ifndef NOTIFY_PLUGIN_PRIVATE_H
+#define NOTIFY_PLUGIN_PRIVATE_H
+
+#include "notify-plugin.h"
+
+void notify_contexts_mail_transaction_begin(struct mailbox_transaction_context *t);
+void notify_contexts_mail_save(struct mail *mail);
+void notify_contexts_mail_copy(struct mail *src, struct mail *dst);
+void notify_contexts_mail_expunge(struct mail *mail);
+void notify_contexts_mail_update_flags(struct mail *mail,
+ enum mail_flags old_flags);
+void notify_contexts_mail_update_keywords(struct mail *mail,
+ const char *const *old_keywords);
+void notify_contexts_mail_transaction_commit(struct mailbox_transaction_context *t,
+ struct mail_transaction_commit_changes *changes);
+void notify_contexts_mail_transaction_rollback(struct mailbox_transaction_context *t);
+void notify_contexts_mailbox_delete_begin(struct mailbox_list *list,
+ const char *name);
+void notify_contexts_mailbox_delete_commit(struct mailbox_list *list,
+ const char *name);
+void notify_contexts_mailbox_delete_rollback(void);
+void notify_contexts_mailbox_rename(struct mailbox_list *oldlist,
+ const char *oldname,
+ struct mailbox_list *newlist,
+ const char *newname, bool rename_children);
+
+void notify_plugin_init_storage(void);
+void notify_plugin_deinit_storage(void);
+
+#endif
diff -r 211853d48eaf -r f751c23561f9 src/plugins/notify/notify-plugin.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/notify/notify-plugin.c Mon Aug 24 16:57:50 2009 -0400
@@ -0,0 +1,210 @@
+#include "lib.h"
+#include "llist.h"
+#include "mail-storage.h"
+#include "notify-plugin-private.h"
+
+#include <stdlib.h>
+
+struct notify_mail_txn {
+ struct notify_mail_txn *prev, *next;
+ struct mailbox_transaction_context *parent_mailbox_txn;
+ struct mail *tmp_mail;
+ void *txn;
+};
+
+struct notify_context {
+ struct notify_context *prev, *next;
+ struct notify_vfuncs v;
+ struct notify_mail_txn *mail_txn_list;
+ void *mailbox_delete_txn;
+};
+
+static struct notify_context *ctx_list = NULL;
+
+static struct notify_mail_txn *
+notify_context_find_mail_txn(struct notify_context *ctx,
+ struct mailbox_transaction_context *t)
+{
+ struct notify_mail_txn *mail_txn = ctx->mail_txn_list;
+
+ for (; mail_txn != NULL; mail_txn = mail_txn->next) {
+ if (mail_txn->parent_mailbox_txn == t)
+ return mail_txn;
+ }
+ i_panic("no notify_mail_txn found");
+}
+
+void notify_contexts_mail_transaction_begin(struct mailbox_transaction_context *t)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = i_new(struct notify_mail_txn, 1);
+ mail_txn->parent_mailbox_txn = t;
+ mail_txn->txn = ctx->v.mail_transaction_begin(t);
+ DLLIST_PREPEND(&ctx->mail_txn_list, mail_txn);
+ }
+}
+
+void notify_contexts_mail_save(struct mail *mail)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
+ ctx->v.mail_save(mail_txn->txn, mail);
+ }
+}
+
+void notify_contexts_mail_copy(struct mail *src, struct mail *dst)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, dst->transaction);
+ ctx->v.mail_copy(mail_txn->txn, src, dst);
+ }
+}
+
+void notify_contexts_mail_expunge(struct mail *mail)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
+ ctx->v.mail_expunge(mail_txn->txn, mail);
+ }
+}
+
+void notify_contexts_mail_update_flags(struct mail *mail,
+ enum mail_flags old_flags)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
+ ctx->v.mail_update_flags(mail_txn->txn, mail, old_flags);
+ }
+}
+
+void notify_contexts_mail_update_keywords(struct mail *mail,
+ const char *const *old_keywords)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
+ ctx->v.mail_update_keywords(mail_txn->txn, mail, old_keywords);
+ }
+}
+
+void notify_contexts_mail_transaction_commit(struct mailbox_transaction_context *t,
+ struct mail_transaction_commit_changes *changes)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, t);
+ ctx->v.mail_transaction_commit(mail_txn->txn, changes);
+ DLLIST_REMOVE(&ctx->mail_txn_list, mail_txn);
+ i_free(mail_txn);
+ }
+}
+
+void notify_contexts_mail_transaction_rollback(struct mailbox_transaction_context *t)
+{
+ struct notify_context *ctx;
+ struct notify_mail_txn *mail_txn;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ mail_txn = notify_context_find_mail_txn(ctx, t);
+ ctx->v.mail_transaction_rollback(mail_txn->txn);
+ DLLIST_REMOVE(&ctx->mail_txn_list, mail_txn);
+ i_free(mail_txn);
+ }
+}
+
+void notify_contexts_mailbox_delete_begin(struct mailbox_list *list,
+ const char *name)
+{
+ struct notify_context *ctx;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ ctx->mailbox_delete_txn =
+ ctx->v.mailbox_delete_begin(list, name);
+ }
+}
+
+void notify_contexts_mailbox_delete_commit(struct mailbox_list *list,
+ const char *name)
+{
+ struct notify_context *ctx;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ ctx->v.mailbox_delete_commit(ctx->mailbox_delete_txn,
+ list, name);
+ ctx->mailbox_delete_txn = NULL;
+ }
+}
+
+void notify_contexts_mailbox_delete_rollback(void)
+{
+ struct notify_context *ctx;
+
+ for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
+ ctx->v.mailbox_delete_rollback(ctx->mailbox_delete_txn);
+ ctx->mailbox_delete_txn = NULL;
+ }
+}
+
+void notify_contexts_mailbox_rename(struct mailbox_list *oldlist,
+ const char *oldname,
+ struct mailbox_list *newlist,
+ const char *newname, bool rename_children)
+{
More information about the dovecot-cvs
mailing list