summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h
blob: fd8b57474712a0781fe31d820e8c0316b96bcf05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef SIEVE_EXT_ENOTIFY_H
#define SIEVE_EXT_ENOTIFY_H

#include "lib.h"
#include "compat.h"
#include <stdarg.h>

#include "sieve-common.h"
#include "sieve-error.h"

/*
 * Forward declarations
 */

struct sieve_enotify_method;
struct sieve_enotify_env;
struct sieve_enotify_action;
struct sieve_enotify_print_env;
struct sieve_enotify_exec_env;

/*
 * Notify method definition
 */

struct sieve_enotify_method_def {
	const char *identifier;

	/* Registration */
	bool (*load)
		(const struct sieve_enotify_method *nmth, void **context);
	void (*unload)
		(const struct sieve_enotify_method *nmth);

	/* Validation */
	bool (*compile_check_uri)
		(const struct sieve_enotify_env *nenv, const char *uri,
			const char *uri_body);
	bool (*compile_check_message)
		(const struct sieve_enotify_env *nenv, string_t *message);
	bool (*compile_check_from)
		(const struct sieve_enotify_env *nenv, string_t *from);
	bool (*compile_check_option)
		(const struct sieve_enotify_env *nenv, const char *option,
			const char *value);

	/* Runtime */
	bool (*runtime_check_uri)
		(const struct sieve_enotify_env *nenv, const char *uri,
			const char *uri_body);
	const char *(*runtime_get_method_capability)
		(const struct sieve_enotify_env *nenv, const char *uri,
			const char *uri_body, const char *capability);
	bool (*runtime_check_operands)
		(const struct sieve_enotify_env *nenv, const char *uri,
			const char *uri_body, string_t *message, string_t *from,
			pool_t context_pool, void **method_context);
	bool (*runtime_set_option)
		(const struct sieve_enotify_env *nenv, void *method_context,
			const char *option, const char *value);

	/* Action duplicates */
	int (*action_check_duplicates)
		(const struct sieve_enotify_env *nenv,
			const struct sieve_enotify_action *nact,
			const struct sieve_enotify_action *nact_other);

	/* Action print */
	void (*action_print)
		(const struct sieve_enotify_print_env *penv,
			const struct sieve_enotify_action *nact);

	/* Action execution
     (returns 0 if all is ok and -1 for temporary error)
	 */
	int (*action_execute)
		(const struct sieve_enotify_exec_env *nenv,
			const struct sieve_enotify_action *nact);
};

/*
 * Notify method instance
 */

struct sieve_enotify_method {
	const struct sieve_enotify_method_def *def;
	int id;

	struct sieve_instance *svinst;
	void *context;
};

const struct sieve_enotify_method *sieve_enotify_method_register
	(struct sieve_instance *svinst,
		const struct sieve_enotify_method_def *nmth_def);
void  sieve_enotify_method_unregister
	(const struct sieve_enotify_method *nmth);

/*
 * Notify method environment
 */

struct sieve_enotify_env {
	struct sieve_instance *svinst;

	const struct sieve_enotify_method *method;

	struct sieve_error_handler *ehandler;
	const char *location;
	struct event *event;
};

/*
 * Notify method printing
 */

void sieve_enotify_method_printf
	(const struct sieve_enotify_print_env *penv, const char *fmt, ...)
		ATTR_FORMAT(2, 3);

/*
 * Notify execution environment
 */

struct sieve_enotify_exec_env {
	struct sieve_instance *svinst;
	enum sieve_execute_flags flags;

	const struct sieve_enotify_method *method;

	const struct sieve_script_env *scriptenv;
	const struct sieve_message_data *msgdata;
	struct sieve_message_context *msgctx;

	struct sieve_error_handler *ehandler;
	const char *location;
	struct event *event;
};

struct event_passthrough *
sieve_enotify_create_finish_event(const struct sieve_enotify_exec_env *nenv);

/*
 * Notify action
 */

struct sieve_enotify_action {
	const struct sieve_enotify_method *method;
	void *method_context;

	sieve_number_t importance;
	const char *message;
	const char *from;
};

/*
 * Error handling
 */

#define sieve_enotify_error(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_ERROR, (ENV)->location, 0, __VA_ARGS__ )
#define sieve_enotify_warning(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_WARNING, \
			(ENV)->location, 0, __VA_ARGS__ )
#define sieve_enotify_info(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_INFO, \
			(ENV)->location, 0, __VA_ARGS__ )
#define sieve_enotify_critical(ENV, ...) \
	sieve_critical((ENV)->svinst, (ENV)->ehandler, NULL, __VA_ARGS__ )

#define sieve_enotify_global_error(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_ERROR, (ENV)->location, \
			SIEVE_ERROR_FLAG_GLOBAL, __VA_ARGS__ )
#define sieve_enotify_global_warning(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_WARNING, (ENV)->location, \
			SIEVE_ERROR_FLAG_GLOBAL, __VA_ARGS__ )
#define sieve_enotify_global_info(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_INFO, (ENV)->location, \
			SIEVE_ERROR_FLAG_GLOBAL, __VA_ARGS__ )

#define sieve_enotify_event_log(ENV, EVENT, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (EVENT), \
			LOG_TYPE_INFO, (ENV)->location, \
			SIEVE_ERROR_FLAG_GLOBAL, __VA_ARGS__ )

#define sieve_enotify_global_log_error(ENV, ...) \
	sieve_event_log((ENV)->svinst, (ENV)->ehandler, (ENV)->event, \
			LOG_TYPE_ERROR, (ENV)->location, \
			(SIEVE_ERROR_FLAG_GLOBAL | \
			 SIEVE_ERROR_FLAG_GLOBAL_MAX_INFO), __VA_ARGS__ )
#endif