dovecot-2.2: Added push-notification plugin

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 23 11:50:01 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/1afdeb1cae62
changeset: 19189:1afdeb1cae62
user:      Michael M Slusarz <michael.slusarz at dovecot.fi>
date:      Tue Sep 22 22:33:41 2015 -0600
description:
Added push-notification plugin

diffstat:

 configure.ac                                                               |    1 +
 dovecot-config.in.in                                                       |    1 +
 src/plugins/Makefile.am                                                    |    1 +
 src/plugins/push-notification/Makefile.am                                  |   60 +
 src/plugins/push-notification/push-notification-driver-dlog.c              |  116 +++
 src/plugins/push-notification/push-notification-driver-ox.c                |  341 ++++++++++
 src/plugins/push-notification/push-notification-drivers.c                  |  189 +++++
 src/plugins/push-notification/push-notification-drivers.h                  |  121 +++
 src/plugins/push-notification/push-notification-event-flagsclear.c         |  179 +++++
 src/plugins/push-notification/push-notification-event-flagsclear.h         |   25 +
 src/plugins/push-notification/push-notification-event-flagsset.c           |  174 +++++
 src/plugins/push-notification/push-notification-event-flagsset.h           |   26 +
 src/plugins/push-notification/push-notification-event-mailboxcreate.c      |   51 +
 src/plugins/push-notification/push-notification-event-mailboxcreate.h      |   14 +
 src/plugins/push-notification/push-notification-event-mailboxdelete.c      |   47 +
 src/plugins/push-notification/push-notification-event-mailboxdelete.h      |   14 +
 src/plugins/push-notification/push-notification-event-mailboxrename.c      |   52 +
 src/plugins/push-notification/push-notification-event-mailboxrename.h      |   13 +
 src/plugins/push-notification/push-notification-event-mailboxsubscribe.c   |   48 +
 src/plugins/push-notification/push-notification-event-mailboxsubscribe.h   |   14 +
 src/plugins/push-notification/push-notification-event-mailboxunsubscribe.c |   48 +
 src/plugins/push-notification/push-notification-event-mailboxunsubscribe.h |   14 +
 src/plugins/push-notification/push-notification-event-message-common.h     |   22 +
 src/plugins/push-notification/push-notification-event-messageappend.c      |  115 +++
 src/plugins/push-notification/push-notification-event-messageappend.h      |   20 +
 src/plugins/push-notification/push-notification-event-messageexpunge.c     |   55 +
 src/plugins/push-notification/push-notification-event-messageexpunge.h     |   14 +
 src/plugins/push-notification/push-notification-event-messagenew.c         |  136 +++
 src/plugins/push-notification/push-notification-event-messagenew.h         |   30 +
 src/plugins/push-notification/push-notification-event-messageread.c        |   58 +
 src/plugins/push-notification/push-notification-event-messageread.h        |   13 +
 src/plugins/push-notification/push-notification-event-messagetrash.c       |   58 +
 src/plugins/push-notification/push-notification-event-messagetrash.h       |   14 +
 src/plugins/push-notification/push-notification-events-rfc5423.c           |   46 +
 src/plugins/push-notification/push-notification-events-rfc5423.h           |   11 +
 src/plugins/push-notification/push-notification-events.c                   |  105 +++
 src/plugins/push-notification/push-notification-events.h                   |  127 +++
 src/plugins/push-notification/push-notification-plugin.c                   |  327 +++++++++
 src/plugins/push-notification/push-notification-plugin.h                   |   13 +
 src/plugins/push-notification/push-notification-triggers.c                 |  222 ++++++
 src/plugins/push-notification/push-notification-triggers.h                 |   78 ++
 src/plugins/push-notification/push-notification-txn-mbox.c                 |   90 ++
 src/plugins/push-notification/push-notification-txn-mbox.h                 |   34 +
 src/plugins/push-notification/push-notification-txn-msg.c                  |  135 +++
 src/plugins/push-notification/push-notification-txn-msg.h                  |   43 +
 45 files changed, 3315 insertions(+), 0 deletions(-)

diffs (truncated from 3521 to 300 lines):

diff -r 3a942625aaa0 -r 1afdeb1cae62 configure.ac
--- a/configure.ac	Tue Sep 22 21:16:51 2015 +0300
+++ b/configure.ac	Tue Sep 22 22:33:41 2015 -0600
@@ -2929,6 +2929,7 @@
 src/plugins/mail-log/Makefile
 src/plugins/mailbox-alias/Makefile
 src/plugins/notify/Makefile
+src/plugins/push-notification/Makefile
 src/plugins/pop3-migration/Makefile
 src/plugins/quota/Makefile
 src/plugins/quota-clone/Makefile
diff -r 3a942625aaa0 -r 1afdeb1cae62 dovecot-config.in.in
--- a/dovecot-config.in.in	Tue Sep 22 21:16:51 2015 +0300
+++ b/dovecot-config.in.in	Tue Sep 22 22:33:41 2015 -0600
@@ -31,6 +31,7 @@
 LIBDOVECOT_IMAPC_INCLUDE="-I$(incdir)/src/lib-imap-client -I$(incdir)/src/lib-storage/index/imapc"
 LIBDOVECOT_FTS_INCLUDE="-I$(incdir)/src/plugins/fts"
 LIBDOVECOT_NOTIFY_INCLUDE="-I$(incdir)/src/plugins/notify"
+LIBDOVECOT_PUSH_NOTIFICATION_INCLUDE="-I$(incdir)/src/plugins/push-notification"
 LIBDOVECOT_ACL_INCLUDE="-I$(incdir)/src/plugins/acl"
 
 dovecot_pkgincludedir=
diff -r 3a942625aaa0 -r 1afdeb1cae62 src/plugins/Makefile.am
--- a/src/plugins/Makefile.am	Tue Sep 22 21:16:51 2015 +0300
+++ b/src/plugins/Makefile.am	Tue Sep 22 22:33:41 2015 -0600
@@ -21,6 +21,7 @@
 	lazy-expunge \
 	listescape \
 	notify \
+	push-notification \
 	mail-filter \
 	mail-log \
 	mailbox-alias \
diff -r 3a942625aaa0 -r 1afdeb1cae62 src/plugins/push-notification/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/push-notification/Makefile.am	Tue Sep 22 22:33:41 2015 -0600
@@ -0,0 +1,60 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-http \
+	-I$(top_srcdir)/src/lib-index \
+	-I$(top_srcdir)/src/lib-mail \
+	-I$(top_srcdir)/src/lib-storage \
+	-I$(top_srcdir)/src/plugins/notify
+
+NOPLUGIN_LDFLAGS =
+lib20_push_notification_plugin_la_LDFLAGS = -module -avoid-version
+
+module_LTLIBRARIES = lib20_push_notification_plugin.la
+
+lib20_push_notification_plugin_la_SOURCES = \
+	push-notification-driver-dlog.c \
+	push-notification-driver-ox.c \
+	push-notification-drivers.c \
+	push-notification-event-flagsclear.c \
+	push-notification-event-flagsset.c \
+	push-notification-event-mailboxcreate.c \
+	push-notification-event-mailboxdelete.c \
+	push-notification-event-mailboxrename.c \
+	push-notification-event-mailboxsubscribe.c \
+	push-notification-event-mailboxunsubscribe.c \
+	push-notification-event-messageappend.c \
+	push-notification-event-messageexpunge.c \
+	push-notification-event-messagenew.c \
+	push-notification-event-messageread.c \
+	push-notification-event-messagetrash.c \
+	push-notification-events.c \
+	push-notification-events-rfc5423.c \
+	push-notification-plugin.c \
+	push-notification-triggers.c \
+	push-notification-txn-mbox.c \
+	push-notification-txn-msg.c
+
+headers = \
+	push-notification-drivers.h \
+	push-notification-event-flagsclear.h \
+	push-notification-event-flagsset.h \
+	push-notification-event-mailboxcreate.h \
+	push-notification-event-mailboxdelete.h \
+	push-notification-event-mailboxrename.h \
+	push-notification-event-mailboxsubscribe.h \
+	push-notification-event-mailboxunsubscribe.h \
+	push-notification-event-message-common.h \
+	push-notification-event-messageappend.h \
+	push-notification-event-messageexpunge.h \
+	push-notification-event-messagenew.h \
+	push-notification-event-messageread.h \
+	push-notification-event-messagetrash.h \
+	push-notification-events.h \
+	push-notification-events-rfc5423.h \
+	push-notification-plugin.h \
+	push-notification-triggers.h \
+	push-notification-txn-mbox.h \
+	push-notification-txn-msg.h
+
+pkginc_libdir = $(pkgincludedir)
+pkginc_lib_HEADERS = $(headers)
diff -r 3a942625aaa0 -r 1afdeb1cae62 src/plugins/push-notification/push-notification-driver-dlog.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/push-notification/push-notification-driver-dlog.c	Tue Sep 22 22:33:41 2015 -0600
@@ -0,0 +1,116 @@
+/* Copyright (c) 2015 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+
+#include "push-notification-drivers.h"
+#include "push-notification-events.h"
+#include "push-notification-txn-mbox.h"
+#include "push-notification-txn-msg.h"
+
+
+static int
+push_notification_driver_dlog_init(struct push_notification_driver_config *config,
+                                   struct mail_user *user ATTR_UNUSED,
+                                   pool_t pool ATTR_UNUSED,
+                                   void **context ATTR_UNUSED,
+                                   const char **error_r ATTR_UNUSED)
+{
+    i_debug("Called init push_notification plugin hook.");
+
+    if (config->raw_config != NULL) {
+        i_debug("Config string for dlog push_notification driver: %s",
+                config->raw_config);
+    }
+
+    return 0;
+}
+
+static bool push_notification_driver_dlog_begin_txn
+(struct push_notification_driver_txn *dtxn)
+{
+    const struct push_notification_event *const *event;
+
+    i_debug("Called begin_txn push_notification plugin hook.");
+
+    array_foreach(&push_notification_events, event) {
+        push_notification_event_init(dtxn, (*event)->name, NULL);
+    }
+
+    return TRUE;
+}
+
+static void push_notification_driver_dlog_process_mbox
+(struct push_notification_driver_txn *dtxn ATTR_UNUSED,
+ struct push_notification_txn_mbox *mbox)
+{
+    struct push_notification_txn_event *const *event;
+
+    i_debug("Called process_mbox push_notification plugin hook.");
+
+    i_debug("Mailbox data: Mailbox [%s]", mbox->mailbox);
+
+    if (array_is_created(&mbox->eventdata)) {
+        array_foreach(&mbox->eventdata, event) {
+            if ((*event)->event->event->mbox.debug_mbox != NULL) {
+                (*event)->event->event->mbox.debug_mbox(*event);
+            }
+        }
+    }
+}
+
+static void push_notification_driver_dlog_process_msg
+(struct push_notification_driver_txn *dtxn ATTR_UNUSED,
+ struct push_notification_txn_msg *msg)
+{
+    struct push_notification_txn_event *const *event;
+
+    i_debug("Called process_msg push_notification plugin hook.");
+
+    i_debug("Message data: Mailbox [%s], UID [%u], UIDVALIDITY [%u]",
+            msg->mailbox, msg->uid, msg->uid_validity);
+
+    if (array_is_created(&msg->eventdata)) {
+        array_foreach(&msg->eventdata, event) {
+            if ((*event)->event->event->msg.debug_msg != NULL) {
+                (*event)->event->event->msg.debug_msg(*event);
+            }
+        }
+    }
+}
+
+static void push_notification_driver_dlog_end_txn
+(struct push_notification_driver_txn *dtxn ATTR_UNUSED,
+ bool success ATTR_UNUSED)
+{
+    i_debug("Called end_txn push_notification plugin hook.");
+}
+
+static void push_notification_driver_dlog_deinit
+(struct push_notification_driver_user *duser ATTR_UNUSED)
+{
+    i_debug("Called deinit push_notification plugin hook.");
+}
+
+static void push_notification_driver_dlog_cleanup(void)
+{
+    i_debug("Called cleanup push_notification plugin hook.");
+}
+
+
+/* Driver definition */
+
+extern struct push_notification_driver push_notification_driver_dlog;
+
+struct push_notification_driver push_notification_driver_dlog = {
+    .name = "dlog",
+    .v = {
+        .init = push_notification_driver_dlog_init,
+        .begin_txn = push_notification_driver_dlog_begin_txn,
+        .process_mbox = push_notification_driver_dlog_process_mbox,
+        .process_msg = push_notification_driver_dlog_process_msg,
+        .end_txn = push_notification_driver_dlog_end_txn,
+        .deinit = push_notification_driver_dlog_deinit,
+        .cleanup = push_notification_driver_dlog_cleanup
+    }
+};
\ No newline at end of file
diff -r 3a942625aaa0 -r 1afdeb1cae62 src/plugins/push-notification/push-notification-driver-ox.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/push-notification/push-notification-driver-ox.c	Tue Sep 22 22:33:41 2015 -0600
@@ -0,0 +1,341 @@
+/* Copyright (c) 2015 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "hash.h"
+#include "http-client.h"
+#include "http-url.h"
+#include "ioloop.h"
+#include "istream.h"
+#include "json-parser.h"
+#include "mailbox-attribute.h"
+#include "mail-storage-private.h"
+#include "str.h"
+
+#include "push-notification-drivers.h"
+#include "push-notification-event-messagenew.h"
+#include "push-notification-events.h"
+#include "push-notification-txn-msg.h"
+
+
+#define OX_LOG_LABEL "OX Push Notification: "
+
+#define OX_METADATA_KEY \
+    MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER "vendor/vendor.dovecot/http-notify"
+
+/* Default values. */
+static const char *const default_events[] = { "MessageNew", NULL };
+static const char *const default_mboxes[] = { "INBOX", NULL };
+
+
+/* This is data that is shared by all plugin users. */
+struct push_notification_driver_ox_global {
+    struct http_client *http_client;
+    int refcount;
+};
+static struct push_notification_driver_ox_global *ox_global = NULL;
+
+/* This is data specific to an OX driver. */
+struct push_notification_driver_ox_config {
+    struct http_url *http_url;
+};
+
+/* This is data specific to an OX driver transaction. */
+struct push_notification_driver_ox_txn {
+    const char *user;
+};
+
+static void
+push_notification_driver_ox_init_global(struct mail_user *user)
+{
+    struct http_client_settings http_set;
+
+    if (ox_global->http_client == NULL) {
+        memset(&http_set, 0, sizeof(http_set));
+        http_set.debug = user->mail_debug;
+
+        ox_global->http_client = http_client_init(&http_set);
+    }
+}
+
+static int
+push_notification_driver_ox_init(struct push_notification_driver_config *config,
+                                 struct mail_user *user, pool_t pool,
+                                 void **context, const char **error_r)
+{
+    struct push_notification_driver_ox_config *dconfig;
+    const char *error, *url;
+
+    /* Valid config keys: url */
+    url = hash_table_lookup(config->config, (const char *)"url");
+    if (url == NULL) {
+        *error_r = OX_LOG_LABEL "Driver requires the url parameter";
+        return -1;
+    }
+
+    dconfig = p_new(pool, struct push_notification_driver_ox_config, 1);
+
+    if (http_url_parse(url, NULL, HTTP_URL_ALLOW_USERINFO_PART, pool,
+                       &dconfig->http_url, &error) < 0) {


More information about the dovecot-cvs mailing list