35
35
(const struct sieve_dumptime_env *denv, const struct sieve_operand *operand,
36
36
sieve_size_t *address, const char *field_name);
38
const struct sieve_opr_string_interface variable_interface = {
38
const struct sieve_opr_string_interface variable_interface = {
40
40
opr_variable_read_value
43
const struct sieve_operand_def variable_operand = {
43
const struct sieve_operand_def variable_operand = {
46
46
EXT_VARIABLES_OPERAND_VARIABLE,
48
48
&variable_interface
51
51
void sieve_variables_opr_variable_emit
52
(struct sieve_binary *sbin, const struct sieve_extension *var_ext,
53
struct sieve_variable *var)
52
(struct sieve_binary *sbin, const struct sieve_extension *var_ext,
53
struct sieve_variable *var)
55
55
if ( var->ext == NULL ) {
56
56
/* Default variable storage */
58
58
(void) sieve_binary_emit_byte(sbin, 0); /* Default */
59
59
(void) sieve_binary_emit_unsigned(sbin, var->index);
63
63
(void) sieve_operand_emit(sbin, var_ext, &variable_operand);
64
64
(void) sieve_binary_emit_extension(sbin, var->ext, 1); /* Extension */
68
68
static bool opr_variable_dump
69
69
(const struct sieve_dumptime_env *denv, const struct sieve_operand *operand,
70
sieve_size_t *address, const char *field_name)
70
sieve_size_t *address, const char *field_name)
72
72
const struct sieve_extension *this_ext = operand->ext;
73
73
unsigned int index = 0;
78
78
if ( !sieve_binary_read_extension(denv->sbin, address, &code, &ext) )
81
81
if ( !sieve_binary_read_unsigned(denv->sbin, address, &index) )
84
84
identifier = ext_variables_dump_get_identifier(this_ext, denv, ext, index);
85
85
identifier = identifier == NULL ? "??" : identifier;
88
if ( field_name != NULL )
89
sieve_code_dumpf(denv, "%s: VAR ${%s} (%ld)",
88
if ( field_name != NULL )
89
sieve_code_dumpf(denv, "%s: VAR ${%s} (%ld)",
90
90
field_name, identifier, (long) index);
92
sieve_code_dumpf(denv, "VAR ${%s} (%ld)",
92
sieve_code_dumpf(denv, "VAR ${%s} (%ld)",
93
93
identifier, (long) index);
95
if ( field_name != NULL )
96
sieve_code_dumpf(denv, "%s: VAR [%s] ${%s} (%ld)",
95
if ( field_name != NULL )
96
sieve_code_dumpf(denv, "%s: VAR [%s] ${%s} (%ld)",
97
97
field_name, sieve_extension_name(ext), identifier, (long) index);
99
sieve_code_dumpf(denv, "VAR [%s] ${%s} (%ld)",
99
sieve_code_dumpf(denv, "VAR [%s] ${%s} (%ld)",
100
100
sieve_extension_name(ext), identifier, (long) index);
105
105
static bool opr_variable_read_value
106
106
(const struct sieve_runtime_env *renv, const struct sieve_operand *operand,
107
107
sieve_size_t *address, string_t **str)
109
109
const struct sieve_extension *this_ext = operand->ext;
110
110
const struct sieve_extension *ext;
111
111
unsigned int code = 1; /* Initially set to offset value */
112
112
struct sieve_variable_storage *storage;
113
113
unsigned int index = 0;
115
115
if ( !sieve_binary_read_extension(renv->sbin, address, &code, &ext) )
118
118
storage = sieve_ext_variables_get_storage(this_ext, renv->interp, ext);
119
if ( storage == NULL )
119
if ( storage == NULL )
122
122
if (sieve_binary_read_unsigned(renv->sbin, address, &index) ) {
123
/* Parameter str can be NULL if we are requested to only skip and not
123
/* Parameter str can be NULL if we are requested to only skip and not
124
124
* actually read the argument.
126
126
if ( str != NULL ) {
127
127
if ( !sieve_variable_get(storage, index, str) )
130
130
if ( *str == NULL ) *str = t_str_new(0);
138
138
bool sieve_variable_operand_read_data
139
(const struct sieve_runtime_env *renv, const struct sieve_operand *operand,
140
sieve_size_t *address, struct sieve_variable_storage **storage,
139
(const struct sieve_runtime_env *renv, const struct sieve_operand *operand,
140
sieve_size_t *address, struct sieve_variable_storage **storage,
141
141
unsigned int *var_index)
143
143
const struct sieve_extension *ext;
151
151
if ( !sieve_binary_read_extension(renv->sbin, address, &code, &ext) )
154
154
*storage = sieve_ext_variables_get_storage(operand->ext, renv->interp, ext);
155
if ( *storage == NULL )
155
if ( *storage == NULL )
158
158
if ( !sieve_binary_read_unsigned(renv->sbin, address, &idx) )
161
161
*var_index = idx;
165
165
bool sieve_variable_operand_read
166
(const struct sieve_runtime_env *renv, sieve_size_t *address,
166
(const struct sieve_runtime_env *renv, sieve_size_t *address,
167
167
struct sieve_variable_storage **storage, unsigned int *var_index)
169
169
struct sieve_operand operand;
174
174
return sieve_variable_operand_read_data
175
175
(renv, &operand, address, storage, var_index);
179
* Match value operand
179
* Match value operand
182
182
static bool opr_match_value_read
186
186
(const struct sieve_dumptime_env *denv, const struct sieve_operand *operand,
187
187
sieve_size_t *address, const char *field_name);
189
const struct sieve_opr_string_interface match_value_interface = {
189
const struct sieve_opr_string_interface match_value_interface = {
190
190
opr_match_value_dump,
191
191
opr_match_value_read
194
const struct sieve_operand_def match_value_operand = {
196
&variables_extension,
194
const struct sieve_operand_def match_value_operand = {
196
&variables_extension,
197
197
EXT_VARIABLES_OPERAND_MATCH_VALUE,
199
199
&match_value_interface
202
202
void sieve_variables_opr_match_value_emit
203
(struct sieve_binary *sbin, const struct sieve_extension *var_ext,
203
(struct sieve_binary *sbin, const struct sieve_extension *var_ext,
206
206
(void) sieve_operand_emit(sbin, var_ext, &match_value_operand);
207
207
(void) sieve_binary_emit_unsigned(sbin, index);
210
210
static bool opr_match_value_dump
211
211
(const struct sieve_dumptime_env *denv,
212
212
const struct sieve_operand *operand ATTR_UNUSED,
213
sieve_size_t *address, const char *field_name)
213
sieve_size_t *address, const char *field_name)
215
215
unsigned int index = 0;
217
217
if (sieve_binary_read_unsigned(denv->sbin, address, &index) ) {
218
218
if ( field_name != NULL )
230
230
static bool opr_match_value_read
231
(const struct sieve_runtime_env *renv,
231
(const struct sieve_runtime_env *renv,
232
232
const struct sieve_operand *operand ATTR_UNUSED,
233
233
sieve_size_t *address, string_t **str)
235
235
unsigned int index = 0;
237
237
if (sieve_binary_read_unsigned(renv->sbin, address, &index) ) {
238
/* Parameter str can be NULL if we are requested to only skip and not
238
/* Parameter str can be NULL if we are requested to only skip and not
239
239
* actually read the argument.
241
241
if ( str != NULL ) {
242
242
sieve_match_values_get(renv->interp, index, str);
245
245
*str = t_str_new(0);
246
else if ( str_len(*str) > EXT_VARIABLES_MAX_VARIABLE_SIZE )
246
else if ( str_len(*str) > EXT_VARIABLES_MAX_VARIABLE_SIZE )
247
247
str_truncate(*str, EXT_VARIABLES_MAX_VARIABLE_SIZE);