File: sieve-extensions.h

package info (click to toggle)
dovecot 1:2.2.13-12~deb8u4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 38,792 kB
  • sloc: ansic: 341,472; sh: 16,920; makefile: 5,393; cpp: 1,474; perl: 265; xml: 44; python: 34; pascal: 27
file content (180 lines) | stat: -rw-r--r-- 4,953 bytes parent folder | download | duplicates (3)
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
/* Copyright (c) 2002-2013 Pigeonhole authors, see the included COPYING file
 */

#ifndef __SIEVE_EXTENSIONS_H
#define __SIEVE_EXTENSIONS_H

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

/*
 * Per-extension object registry
 */

struct sieve_extension_objects {
	const void *objects;
	unsigned int count;
};

/*
 * Extension definition
 */

struct sieve_extension_def {
	const char *name;

	/* Version */
	unsigned int version;

	/* Registration */
	bool (*load)(const struct sieve_extension *ext, void **context);
	void (*unload)(const struct sieve_extension *ext);

	/* Compilation */
	bool (*validator_load)
		(const struct sieve_extension *ext, struct sieve_validator *validator);
	bool (*generator_load)
		(const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv);
	bool (*interpreter_load)
		(const struct sieve_extension *ext, const struct sieve_runtime_env *renv,
			sieve_size_t *address);
	bool (*binary_load)
		(const struct sieve_extension *ext, struct sieve_binary *binary);

	/* Code dump */
	bool (*binary_dump)
		(const struct sieve_extension *ext, struct sieve_dumptime_env *denv);
	bool (*code_dump)
		(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv,
			sieve_size_t *address);

	/* Objects */
	struct sieve_extension_objects operations;
	struct sieve_extension_objects operands;
};

/* Defining opcodes and operands */

#define SIEVE_EXT_DEFINE_NO_OBJECTS \
	{ NULL, 0 }
#define SIEVE_EXT_DEFINE_OBJECT(OBJ) \
	{ &OBJ, 1 }
#define SIEVE_EXT_DEFINE_OBJECTS(OBJS) \
	{ OBJS, N_ELEMENTS(OBJS) }

#define SIEVE_EXT_GET_OBJECTS_COUNT(ext, field) \
	ext->field->count;

#define SIEVE_EXT_DEFINE_NO_OPERATIONS \
	.operations = SIEVE_EXT_DEFINE_NO_OBJECTS
#define SIEVE_EXT_DEFINE_OPERATION(OP) \
	.operations = SIEVE_EXT_DEFINE_OBJECT(OP)
#define SIEVE_EXT_DEFINE_OPERATIONS(OPS) \
	.operations = SIEVE_EXT_DEFINE_OBJECTS(OPS)

#define SIEVE_EXT_DEFINE_NO_OPERANDS \
	.operands = SIEVE_EXT_DEFINE_NO_OBJECTS
#define SIEVE_EXT_DEFINE_OPERAND(OP) \
	.operands = SIEVE_EXT_DEFINE_OBJECT(OP)
#define SIEVE_EXT_DEFINE_OPERANDS(OPS) \
	.operands = SIEVE_EXT_DEFINE_OBJECTS(OPS)

/*
 * Extension instance
 */

struct sieve_extension {
	const struct sieve_extension_def *def;
	int id;

	struct sieve_instance *svinst;
	void *context;

	unsigned int required:1;
	unsigned int loaded:1;
	unsigned int enabled:1;
	unsigned int dummy:1;
	unsigned int global:1;
};

#define sieve_extension_is(ext, definition) \
	( (ext)->def == &(definition) )
#define sieve_extension_name(ext) \
	((ext)->def->name)
#define sieve_extension_name_is(ext, _name) \
	( strcmp((ext)->def->name, (_name)) == 0 )
#define sieve_extension_version(ext) \
	((ext)->def->version)
#define sieve_extension_version_is(ext, _version) \
	((ext)->def->version == (_version))

/*
 * Extensions init/deinit
 */

bool sieve_extensions_init(struct sieve_instance *svinst);
void sieve_extensions_configure(struct sieve_instance *svinst);
void sieve_extensions_deinit(struct sieve_instance *svinst);

/*
 * Pre-loaded extensions
 */

const struct sieve_extension *const *sieve_extensions_get_preloaded
	(struct sieve_instance *svinst, unsigned int *count_r);

/*
 * Extension registry
 */

const struct sieve_extension *sieve_extension_register
	(struct sieve_instance *svinst, const struct sieve_extension_def *extension,
		bool load);
const struct sieve_extension *sieve_extension_require
	(struct sieve_instance *svinst, const struct sieve_extension_def *extension,
		bool load);
bool sieve_extension_reload(const struct sieve_extension *ext);

void sieve_extension_unregister(const struct sieve_extension *ext);

int sieve_extensions_get_count(struct sieve_instance *svinst);

const struct sieve_extension *sieve_extension_get_by_id
	(struct sieve_instance *svinst, unsigned int ext_id);
const struct sieve_extension *sieve_extension_get_by_name
	(struct sieve_instance *svinst, const char *name);

const char *sieve_extensions_get_string
	(struct sieve_instance *svinst);
void sieve_extensions_set_string
	(struct sieve_instance *svinst, const char *ext_string, bool global);

const struct sieve_extension *sieve_get_match_type_extension
	(struct sieve_instance *svinst);
const struct sieve_extension *sieve_get_comparator_extension
	(struct sieve_instance *svinst);
const struct sieve_extension *sieve_get_address_part_extension
	(struct sieve_instance *svinst);

void sieve_enable_debug_extension(struct sieve_instance *svinst);

/*
 * Capability registries
 */

struct sieve_extension_capabilities {
	const char *name;

	const char *(*get_string)(const struct sieve_extension *ext);
};

void sieve_extension_capabilities_register
	(const struct sieve_extension *ext,
		const struct sieve_extension_capabilities *cap);
void sieve_extension_capabilities_unregister
	(const struct sieve_extension *ext);

const char *sieve_extension_capabilities_get_string
	(struct sieve_instance *svinst, const char *cap_name);

#endif /* __SIEVE_EXTENSIONS_H */