21
21
#include "ext-include-binary.h"
22
22
#include "ext-include-variables.h"
25
25
* Variable import-export
28
28
struct sieve_variable *ext_include_variable_import_global
29
(struct sieve_validator *valdtr, struct sieve_command *cmd,
29
(struct sieve_validator *valdtr, struct sieve_command *cmd,
30
30
const char *variable)
32
32
const struct sieve_extension *this_ext = cmd->ext;
33
33
struct sieve_ast *ast = cmd->ast_node->ast;
34
struct ext_include_ast_context *ctx =
34
struct ext_include_ast_context *ctx =
35
35
ext_include_get_ast_context(this_ext, ast);
36
36
struct ext_include_context *ectx = ext_include_get_context(this_ext);
37
37
struct sieve_variable_scope *local_scope;
38
38
struct sieve_variable_scope *global_scope = ctx->global_vars;
39
39
struct sieve_variable *global_var = NULL, *local_var;
41
/* Sanity safeguard */
41
/* Sanity safeguard */
42
42
i_assert ( ctx->global_vars != NULL );
44
44
if ( !sieve_variable_identifier_is_valid(variable) ) {
54
54
if ( global_var == NULL ) {
55
55
sieve_command_validate_error(valdtr, cmd,
56
56
"declaration of new global variable '%s' exceeds the limit "
57
"(max variables: %u)",
57
"(max variables: %u)",
58
58
variable, sieve_variables_get_max_scope_size());
62
62
/* Import the global variable into the local script scope */
63
63
local_scope = sieve_ext_variables_get_local_scope(ectx->var_ext, valdtr);
152
152
bool vnspc_global_variables_validate
153
153
(struct sieve_validator *valdtr, const struct sieve_variables_namespace *nspc,
154
struct sieve_ast_argument *arg, struct sieve_command *cmd,
155
ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data,
154
struct sieve_ast_argument *arg, struct sieve_command *cmd,
155
ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data,
156
156
bool assignment);
157
157
bool vnspc_global_variables_generate
158
(const struct sieve_codegen_env *cgenv,
158
(const struct sieve_codegen_env *cgenv,
159
159
const struct sieve_variables_namespace *nspc,
160
160
struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data);
162
162
static const struct sieve_variables_namespace_def global_variables_namespace = {
163
163
SIEVE_OBJECT("global", NULL, 0),
164
vnspc_global_variables_validate,
164
vnspc_global_variables_validate,
165
165
vnspc_global_variables_generate,
170
170
bool vnspc_global_variables_validate
171
(struct sieve_validator *valdtr,
171
(struct sieve_validator *valdtr,
172
172
const struct sieve_variables_namespace *nspc, struct sieve_ast_argument *arg,
173
struct sieve_command *cmd ATTR_UNUSED,
174
ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data,
173
struct sieve_command *cmd ATTR_UNUSED,
174
ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data,
175
175
bool assignment ATTR_UNUSED)
177
177
const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc);
178
178
struct sieve_ast *ast = arg->ast;
179
struct ext_include_ast_context *ctx =
179
struct ext_include_ast_context *ctx =
180
180
ext_include_get_ast_context(this_ext, ast);
181
181
struct sieve_variable *var = NULL;
182
182
const struct sieve_variable_name *name_element;
183
183
const char *variable;
185
/* Sanity safeguard */
185
/* Sanity safeguard */
186
186
i_assert ( ctx->global_vars != NULL );
188
188
/* Check variable name */
190
190
if ( array_count(var_name) != 2 ) {
191
sieve_argument_validate_error(valdtr, arg,
191
sieve_argument_validate_error(valdtr, arg,
192
192
"invalid variable name within global namespace: "
193
193
"encountered sub-namespace");
197
197
name_element = array_idx(var_name, 1);
198
198
if ( name_element->num_variable >= 0 ) {
199
sieve_argument_validate_error(valdtr, arg,
199
sieve_argument_validate_error(valdtr, arg,
200
200
"invalid variable name within global namespace: "
201
201
"encountered numeric variable name");
205
205
variable = str_c(name_element->identifier);
207
207
/* Get/Declare the variable in the global scope */
209
209
var = sieve_variable_scope_get_variable(ctx->global_vars, variable, TRUE);
211
211
if ( var == NULL ) {
212
sieve_argument_validate_error(valdtr, arg,
212
sieve_argument_validate_error(valdtr, arg,
213
213
"(implicit) declaration of new global variable '%s' exceeds the limit "
214
"(max variables: %u)", variable,
214
"(max variables: %u)", variable,
215
215
sieve_variables_get_max_scope_size());
219
219
*var_data = (void *) var;
224
224
bool vnspc_global_variables_generate
225
(const struct sieve_codegen_env *cgenv,
226
const struct sieve_variables_namespace *nspc,
227
struct sieve_ast_argument *arg ATTR_UNUSED,
225
(const struct sieve_codegen_env *cgenv,
226
const struct sieve_variables_namespace *nspc,
227
struct sieve_ast_argument *arg ATTR_UNUSED,
228
228
struct sieve_command *cmd ATTR_UNUSED, void *var_data)
230
230
const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc);
231
231
struct ext_include_context *ectx = ext_include_get_context(this_ext);
232
232
struct sieve_variable *var = (struct sieve_variable *) var_data;
234
234
sieve_variables_opr_variable_emit(cgenv->sblock, ectx->var_ext, var);