1 /* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
2 
3 #ifndef PUSH_NOTIFICATION_EVENTS_H
4 #define PUSH_NOTIFICATION_EVENTS_H
5 
6 #include "mail-types.h"
7 
8 struct mail;
9 struct mailbox;
10 struct push_notification_event_config;
11 struct push_notification_driver_txn;
12 struct push_notification_txn;
13 struct push_notification_txn_event;
14 struct push_notification_txn_mbox;
15 struct push_notification_txn_msg;
16 
17 struct push_notification_event_vfuncs_init {
18 	/* Return the default config for an event (or NULL if config is
19 	   required). */
20 	void *(*default_config)(void);
21 };
22 
23 struct push_notification_event_vfuncs_mbox {
24 	/* Output debug information about a message event. */
25 	void (*debug_mbox)(struct push_notification_txn_event *event);
26 	/* Called when message data is about to be free'd. */
27 	void (*free_mbox)(struct push_notification_txn_event *event);
28 };
29 
30 struct push_notification_event_vfuncs_mbox_triggers {
31 	/* Mailbox event: create mailbox. */
32 	void (*create)(struct push_notification_txn *ptxn,
33 		       struct push_notification_event_config *ec,
34 		       struct push_notification_txn_mbox *mbox);
35 	/* Mailbox event: delete mailbox. */
36 	void (*delete)(struct push_notification_txn *ptxn,
37 		       struct push_notification_event_config *ec,
38 		       struct push_notification_txn_mbox *mbox);
39 	/* Mailbox event: rename mailbox. */
40 	void (*rename)(struct push_notification_txn *ptxn,
41 		       struct push_notification_event_config *ec,
42 		       struct push_notification_txn_mbox *mbox,
43 		       struct mailbox *old);
44 	/* Mailbox event: subscribe mailbox. */
45 	void (*subscribe)(struct push_notification_txn *ptxn,
46 			  struct push_notification_event_config *ec,
47 			  struct push_notification_txn_mbox *mbox);
48 	/* Mailbox event: unsubscribe mailbox. */
49 	void (*unsubscribe)(struct push_notification_txn *ptxn,
50 			    struct push_notification_event_config *ec,
51 			    struct push_notification_txn_mbox *mbox);
52 };
53 
54 struct push_notification_event_vfuncs_msg {
55 	/* Output debug information about a message event. */
56 	void (*debug_msg)(struct push_notification_txn_event *event);
57 	/* Called when message data is about to be free'd. */
58 	void (*free_msg)(struct push_notification_txn_event *event);
59 };
60 
61 struct push_notification_event_vfuncs_msg_triggers {
62 	/* Message event: save message (from MTA). */
63 	void (*save)(struct push_notification_txn *ptxn,
64 		     struct push_notification_event_config *ec,
65 		     struct push_notification_txn_msg *msg,
66 		     struct mail *mail);
67 	/* Message event: append message (from MUA). */
68 	void (*append)(struct push_notification_txn *ptxn,
69 		       struct push_notification_event_config *ec,
70 		       struct push_notification_txn_msg *msg,
71 		       struct mail *mail);
72 	/* Message event: expunge message. */
73 	void (*expunge)(struct push_notification_txn *ptxn,
74 			struct push_notification_event_config *ec,
75 			struct push_notification_txn_msg *msg);
76 	/* Message event: flag change. */
77 	void (*flagchange)(struct push_notification_txn *ptxn,
78 			   struct push_notification_event_config *ec,
79 			   struct push_notification_txn_msg *msg,
80 			   struct mail *mail, enum mail_flags old_flags);
81 	/* Message event: keyword change. */
82 	void (*keywordchange)(struct push_notification_txn *ptxn,
83 			      struct push_notification_event_config *ec,
84 			      struct push_notification_txn_msg *msg,
85 			      struct mail *mail,
86 			      const char *const *old_keywords);
87 };
88 
89 struct push_notification_event_config {
90 	const struct push_notification_event *event;
91 	void *config;
92 };
93 
94 struct push_notification_event {
95 	const char *name;
96 	struct push_notification_event_vfuncs_init init;
97 	struct push_notification_event_vfuncs_mbox mbox;
98 	struct push_notification_event_vfuncs_mbox_triggers mbox_triggers;
99 	struct push_notification_event_vfuncs_msg msg;
100 	struct push_notification_event_vfuncs_msg_triggers msg_triggers;
101 };
102 
103 struct push_notification_txn_event {
104 	struct push_notification_event_config *event;
105 	void *data;
106 };
107 
108 ARRAY_DEFINE_TYPE(push_notification_event,
109 		  const struct push_notification_event *);
110 extern ARRAY_TYPE(push_notification_event) push_notification_events;
111 
112 ARRAY_TYPE(push_notification_event) *push_notification_get_events(void);
113 
114 
115 void push_notification_event_init(struct push_notification_driver_txn *dtxn,
116 				  const char *event_name, void *config);
117 
118 void push_notification_event_register(
119 	const struct push_notification_event *event);
120 void push_notification_event_unregister(
121 	const struct push_notification_event *event);
122 
123 #endif
124 
125