1 #ifndef SIEVE_COMMON_H
2 #define SIEVE_COMMON_H
3 
4 #include "lib.h"
5 
6 #include "sieve.h"
7 
8 #include <sys/types.h>
9 
10 /*
11  * Types
12  */
13 
14 typedef size_t sieve_size_t;
15 typedef uint32_t sieve_offset_t;
16 typedef uint64_t sieve_number_t;
17 
18 #define SIEVE_MAX_NUMBER ((sieve_number_t)-1)
19 #define SIEVE_PRI_NUMBER PRIu64
20 
21 /*
22  * Forward declarations
23  */
24 
25 /* sieve-error.h */
26 struct sieve_error_handler;
27 
28 /* sieve-ast.h */
29 enum sieve_ast_argument_type;
30 
31 struct sieve_ast;
32 struct sieve_ast_node;
33 struct sieve_ast_argument;
34 
35 /* sieve-commands.h */
36 struct sieve_argument;
37 struct sieve_argument_def;
38 struct sieve_command;
39 struct sieve_command_def;
40 struct sieve_command_context;
41 struct sieve_command_registration;
42 
43 /* sieve-stringlist.h */
44 struct sieve_stringlist;
45 
46 /* sieve-code.h */
47 struct sieve_operation_extension;
48 
49 /* sieve-lexer.h */
50 struct sieve_lexer;
51 
52 /* sieve-parser.h */
53 struct sieve_parser;
54 
55 /* sieve-validator.h */
56 struct sieve_validator;
57 
58 /* sieve-generator.h */
59 struct sieve_jumplist;
60 struct sieve_generator;
61 struct sieve_codegen_env;
62 
63 /* sieve-runtime.h */
64 struct sieve_runtime_env;
65 
66 /* sieve-interpreter.h */
67 struct sieve_interpreter;
68 
69 /* sieve-dump.h */
70 struct sieve_dumptime_env;
71 
72 /* sieve-binary-dumper.h */
73 struct sieve_binary_dumper;
74 
75 /* sieve-code-dumper.h */
76 struct sieve_code_dumper;
77 
78 /* sieve-extension.h */
79 struct sieve_extension;
80 struct sieve_extension_def;
81 struct sieve_extension_objects;
82 
83 /* sieve-code.h */
84 struct sieve_operand;
85 struct sieve_operand_def;
86 struct sieve_operand_class;
87 struct sieve_operation;
88 struct sieve_coded_stringlist;
89 
90 /* sieve-binary.h */
91 struct sieve_binary;
92 struct sieve_binary_block;
93 struct sieve_binary_debug_writer;
94 struct sieve_binary_debug_reader;
95 
96 /* sieve-execute.h */
97 struct sieve_execute;
98 
99 /* sieve-objects.h */
100 struct sieve_object_def;
101 struct sieve_object;
102 
103 /* sieve-comparator.h */
104 struct sieve_comparator;
105 
106 /* sieve-match-types.h */
107 struct sieve_match_type;
108 
109 /* sieve-match.h */
110 struct sieve_match_context;
111 
112 /* sieve-address.h */
113 struct sieve_address_list;
114 
115 /* sieve-address-parts.h */
116 struct sieve_address_part_def;
117 struct sieve_address_part;
118 
119 /* sieve-result.h */
120 struct sieve_result;
121 struct sieve_side_effects_list;
122 struct sieve_result_print_env;
123 
124 /* sieve-actions.h */
125 struct sieve_action_exec_env;
126 struct sieve_action;
127 struct sieve_action_def;
128 struct sieve_side_effect;
129 struct sieve_side_effect_def;
130 
131 /* sieve-script.h */
132 struct sieve_script;
133 struct sieve_script_sequence;
134 
135 /* sieve-storage.h */
136 struct sieve_storage_class_registry;
137 struct sieve_storage;
138 
139 /* sieve-message.h */
140 struct sieve_message_context;
141 struct sieve_message_override;
142 struct sieve_message_override_def;
143 
144 /* sieve-plugins.h */
145 struct sieve_plugin;
146 
147 /* sieve.c */
148 struct sieve_ast *sieve_parse
149 	(struct sieve_script *script, struct sieve_error_handler *ehandler,
150 		enum sieve_error *error_r);
151 bool sieve_validate
152 	(struct sieve_ast *ast, struct sieve_error_handler *ehandler,
153 		enum sieve_compile_flags flags, enum sieve_error *error_r);
154 
155 /*
156  * Parent category
157  */
158 
159 extern struct event_category event_category_sieve;
160 
161 /*
162  * Sieve engine instance
163  */
164 
165 #include "sieve-address-source.h"
166 
167 struct sieve_instance {
168 	/* Main engine pool */
169 	pool_t pool;
170 
171 	/* System environment */
172 	const char *hostname;
173 	const char *domainname;
174 	const char *base_dir;
175 	const char *temp_dir;
176 
177 	/* User environment */
178 	const char *username;
179 	const char *home_dir;
180 
181 	/* Flags */
182 	enum sieve_flag flags;
183 
184 	/* Callbacks */
185 	const struct sieve_callbacks *callbacks;
186 	void *context;
187 
188 	/* Logging, events, and debug */
189 	struct event *event;
190 	bool debug;
191 
192 	/* Extension registry */
193 	struct sieve_extension_registry *ext_reg;
194 
195 	/* Storage class registry */
196 	struct sieve_storage_class_registry *storage_reg;
197 
198 	/* Plugin modules */
199 	struct sieve_plugin *plugins;
200 	enum sieve_env_location env_location;
201 	enum sieve_delivery_phase delivery_phase;
202 
203 	/* Settings */
204 	size_t max_script_size;
205 	unsigned int max_actions;
206 	unsigned int max_redirects;
207 	unsigned int max_cpu_time_secs;
208 	unsigned int resource_usage_timeout_secs;
209 	const struct smtp_address *user_email, *user_email_implicit;
210 	struct sieve_address_source redirect_from;
211 	unsigned int redirect_duplicate_period;
212 };
213 
214 /*
215  * Script trace log
216  */
217 
218 void sieve_trace_log_write_line
219 	(struct sieve_trace_log *trace_log, const string_t *line)
220 	ATTR_NULL(2);
221 
222 /*
223  * User e-mail address
224  */
225 
226 const struct smtp_address *sieve_get_user_email
227 	(struct sieve_instance *svinst);
228 
229 /*
230  * Postmaster address
231  */
232 
233 const struct message_address *
234 sieve_get_postmaster(const struct sieve_script_env *senv);
235 const struct smtp_address *
236 sieve_get_postmaster_smtp(const struct sieve_script_env *senv);
237 const char *
238 sieve_get_postmaster_address(const struct sieve_script_env *senv);
239 
240 #endif
241