bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#ifndef PUSH_NOTIFICATION_DRIVERS_H
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#define PUSH_NOTIFICATION_DRIVERS_H
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "mail-user.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-triggers.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct mail_user;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_txn;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_user;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_txn_mbox;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_txn_msg;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M SlusarzHASH_TABLE_DEFINE_TYPE(push_notification_config, const char *, const char *);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M SlusarzHASH_TABLE_DEFINE_TYPE(push_notification_msgs, void *,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_msg *);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_vfuncs {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Init driver. Config (from plugin configuration) is parsed once (no
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz * user variable substitutions). Return 0 on success, or -1 if this
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz * driver should be disabled (or on error). */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz int (*init)(struct push_notification_driver_config *config,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct mail_user *user, pool_t pool, void **context,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char **error_r);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Called at the beginning of a notification transaction. Return TRUE on
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz * success, or FALSE if this driver should be ignored for this
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz * transaction. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz bool (*begin_txn)(struct push_notification_driver_txn *dtxn);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Called once for every mailbox processed. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void (*process_mbox)(struct push_notification_driver_txn *dtxn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_mbox *mbox);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Called once for every message processed. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void (*process_msg)(struct push_notification_driver_txn *dtxn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_msg *msg);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Called at the end of a successful notification transaction. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void (*end_txn)(struct push_notification_driver_txn *dtxn, bool success);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Called when plugin is deinitialized. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void (*deinit)(struct push_notification_driver_user *duser);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Called to cleanup any global resources used in plugin. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void (*cleanup)(void);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *name;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_driver_vfuncs v;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_config {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz HASH_TABLE_TYPE(push_notification_config) config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *raw_config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_user {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const struct push_notification_driver *driver;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void *context;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_driver_txn {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const struct push_notification_driver_user *duser;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn *ptxn;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Transaction context. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void *context;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
e7e9ca33af09b6ab77633bcafe27d751adf09c93Michael Slusarzstruct push_notification_driver_list {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz ARRAY(struct push_notification_driver_user *) drivers;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
e7e9ca33af09b6ab77633bcafe27d751adf09c93Michael Slusarzstruct push_notification_user {
e7e9ca33af09b6ab77633bcafe27d751adf09c93Michael Slusarz union mail_user_module_context module_ctx;
e7e9ca33af09b6ab77633bcafe27d751adf09c93Michael Slusarz struct push_notification_driver_list *driverlist;
e7e9ca33af09b6ab77633bcafe27d751adf09c93Michael Slusarz};
e7e9ca33af09b6ab77633bcafe27d751adf09c93Michael Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_trigger_ctx {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *name;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz void *context;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_txn {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz pool_t pool;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct mailbox *mbox;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct mail_user *muser;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_user *puser;
f6fb60c7dcfc88895c8c45514c3fc424d3126336Michael Slusarz bool initialized;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz enum push_notification_event_trigger trigger;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_trigger_ctx *trigger_ctx;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz ARRAY(struct push_notification_driver_txn *) drivers;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz ARRAY(struct push_notification_event_config *) events;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Used with mailbox events. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_mbox *mbox_txn;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Used with mailbox events. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz HASH_TABLE_TYPE(push_notification_msgs) messages;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Private (used with message events). */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct mailbox_transaction_context *t;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz};
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzint
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_driver_init(struct mail_user *user, const char *config_in,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz pool_t pool,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_driver_user **duser_r);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzvoid push_notification_driver_cleanup_all(void);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzvoid ATTR_FORMAT(3, 4)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_driver_debug(const char *label, struct mail_user *user,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *fmt, ...);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzvoid push_notification_driver_register
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz(const struct push_notification_driver *driver);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzvoid push_notification_driver_unregister
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz(const struct push_notification_driver *driver);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#endif /* PUSH_NOTIFICATION_DRIVERS_H */