1 #ifndef EXT_INCLUDE_COMMON_H
2 #define EXT_INCLUDE_COMMON_H
3
4 #include "lib.h"
5 #include "hash.h"
6
7 #include "sieve-common.h"
8 #include "sieve-extensions.h"
9
10 /*
11 * Forward declarations
12 */
13
14 struct ext_include_script_info;
15 struct ext_include_binary_context;
16
17 /*
18 * Types
19 */
20
21 enum ext_include_flags { // stored in one byte
22 EXT_INCLUDE_FLAG_ONCE = 0x01,
23 EXT_INCLUDE_FLAG_OPTIONAL = 0x02,
24 EXT_INCLUDE_FLAG_MISSING_AT_UPLOAD = 0x04
25 };
26
27 enum ext_include_script_location {
28 EXT_INCLUDE_LOCATION_PERSONAL,
29 EXT_INCLUDE_LOCATION_GLOBAL,
30 EXT_INCLUDE_LOCATION_INVALID
31 };
32
33 static inline const char *
ext_include_script_location_name(enum ext_include_script_location location)34 ext_include_script_location_name(enum ext_include_script_location location)
35 {
36 switch (location) {
37 case EXT_INCLUDE_LOCATION_PERSONAL:
38 return "personal";
39 case EXT_INCLUDE_LOCATION_GLOBAL:
40 return "global";
41 default:
42 break;
43 }
44
45 return "[INVALID LOCATION]";
46 }
47
48
49 /*
50 * Extension
51 */
52
53 extern const struct sieve_extension_def include_extension;
54 extern const struct sieve_binary_extension include_binary_ext;
55
56 bool ext_include_load(const struct sieve_extension *ext, void **context);
57 void ext_include_unload(const struct sieve_extension *ext);
58
59 /*
60 * Commands
61 */
62
63 extern const struct sieve_command_def cmd_include;
64 extern const struct sieve_command_def cmd_return;
65 extern const struct sieve_command_def cmd_global;
66
67 /* DEPRICATED */
68 extern const struct sieve_command_def cmd_import;
69 extern const struct sieve_command_def cmd_export;
70
71 /*
72 * Operations
73 */
74
75 enum ext_include_opcode {
76 EXT_INCLUDE_OPERATION_INCLUDE,
77 EXT_INCLUDE_OPERATION_RETURN,
78 EXT_INCLUDE_OPERATION_GLOBAL
79 };
80
81 extern const struct sieve_operation_def include_operation;
82 extern const struct sieve_operation_def return_operation;
83 extern const struct sieve_operation_def global_operation;
84
85 /*
86 * Script access
87 */
88
89 struct sieve_storage *
90 ext_include_get_script_storage(const struct sieve_extension *ext,
91 enum ext_include_script_location location,
92 const char *script_name,
93 enum sieve_error *error_r);
94 /*
95 * Context
96 */
97
98 /* Extension context */
99
100 struct ext_include_context {
101 /* Extension dependencies */
102 const struct sieve_extension *var_ext;
103
104 /* Configuration */
105 char *global_location;
106
107 struct sieve_storage *global_storage;
108 struct sieve_storage *personal_storage;
109
110 unsigned int max_nesting_depth;
111 unsigned int max_includes;
112 };
113
114 static inline struct ext_include_context *
ext_include_get_context(const struct sieve_extension * ext)115 ext_include_get_context(const struct sieve_extension *ext)
116 {
117 return (struct ext_include_context *) ext->context;
118 }
119
120 /* AST Context */
121
122 struct ext_include_ast_context {
123 struct sieve_variable_scope *global_vars;
124
125 ARRAY(struct sieve_script *) included_scripts;
126 };
127
128 struct ext_include_ast_context *
129 ext_include_create_ast_context(const struct sieve_extension *this_ext,
130 struct sieve_ast *ast, struct sieve_ast *parent);
131 struct ext_include_ast_context *
132 ext_include_get_ast_context(const struct sieve_extension *this_ext,
133 struct sieve_ast *ast);
134
135 void ext_include_ast_link_included_script(
136 const struct sieve_extension *this_ext, struct sieve_ast *ast,
137 struct sieve_script *script);
138
139 bool ext_include_validator_have_variables(
140 const struct sieve_extension *this_ext, struct sieve_validator *valdtr);
141
142 /* Generator context */
143
144 void ext_include_register_generator_context(
145 const struct sieve_extension *this_ext,
146 const struct sieve_codegen_env *cgenv);
147
148 int ext_include_generate_include(
149 const struct sieve_codegen_env *cgenv, struct sieve_command *cmd,
150 enum ext_include_script_location location, enum ext_include_flags flags,
151 struct sieve_script *script,
152 const struct ext_include_script_info **included_r);
153
154 /* Interpreter context */
155
156 void ext_include_interpreter_context_init(
157 const struct sieve_extension *this_ext,
158 struct sieve_interpreter *interp);
159
160 int ext_include_execute_include(const struct sieve_runtime_env *renv,
161 unsigned int block_id,
162 enum ext_include_flags flags);
163 void ext_include_execute_return(const struct sieve_runtime_env *renv);
164
165 struct sieve_variable_storage *
166 ext_include_interpreter_get_global_variables(
167 const struct sieve_extension *this_ext,
168 struct sieve_interpreter *interp);
169
170 #endif
171