Coverage Report

Created: 2026-09-14 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/plugins/variables/sieve-ext-variables.h
Line
Count
Source
1
#ifndef SIEVE_EXT_VARIABLES_H
2
#define SIEVE_EXT_VARIABLES_H
3
4
#include "lib.h"
5
6
#include "sieve-common.h"
7
#include "sieve-extensions.h"
8
#include "sieve-objects.h"
9
#include "sieve-code.h"
10
11
/* Public interface for other extensions to use
12
 */
13
14
/*
15
 * Limits
16
 */
17
18
unsigned int
19
sieve_variables_get_max_scope_count(const struct sieve_extension *var_ext);
20
size_t sieve_variables_get_max_value_size(
21
  const struct sieve_extension *var_ext);
22
23
/*
24
 * Variable extension
25
 */
26
27
/* FIXME: this is not suitable for future plugin support */
28
29
extern const struct sieve_extension_def variables_extension;
30
31
static inline int
32
sieve_ext_variables_get_extension(struct sieve_instance *svinst,
33
          const struct sieve_extension **ext_r)
34
0
{
35
0
  return sieve_extension_register(svinst, &variables_extension, FALSE,
36
0
          ext_r);
37
0
}
Unexecuted instantiation: testsuite-variables.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-imap4flags.c:sieve_ext_variables_get_extension
Unexecuted instantiation: tag-flags.c:sieve_ext_variables_get_extension
Unexecuted instantiation: tst-hasflag.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-include.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-namespaces.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables.c:sieve_ext_variables_get_extension
Unexecuted instantiation: tst-string.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-enotify.c:sieve_ext_variables_get_extension
Unexecuted instantiation: tst-notify-method-capability.c:sieve_ext_variables_get_extension
Unexecuted instantiation: tst-valid-notify-method.c:sieve_ext_variables_get_extension
Unexecuted instantiation: vmodf-encodeurl.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-extracttext.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-vnd-environment.c:sieve_ext_variables_get_extension
Unexecuted instantiation: cmd-flag.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-imap4flags-common.c:sieve_ext_variables_get_extension
Unexecuted instantiation: cmd-global.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-include-binary.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-include-common.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-include-variables.c:sieve_ext_variables_get_extension
Unexecuted instantiation: cmd-set.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-arguments.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-common.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-dump.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-modifiers.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-name.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-variables-operands.c:sieve_ext_variables_get_extension
Unexecuted instantiation: cmd-notify.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-enotify-common.c:sieve_ext_variables_get_extension
Unexecuted instantiation: cmd-extracttext.c:sieve_ext_variables_get_extension
Unexecuted instantiation: ext-vnd-environment-variables.c:sieve_ext_variables_get_extension
38
39
/*
40
 * Variable name
41
 */
42
43
struct sieve_variable_name {
44
  string_t *identifier;
45
  int num_variable;
46
};
47
48
ARRAY_DEFINE_TYPE(sieve_variable_name, struct sieve_variable_name);
49
50
bool sieve_variable_identifier_is_valid(const char *identifier);
51
52
/*
53
 * Variable scope
54
 */
55
56
struct sieve_variable {
57
  const char *identifier;
58
  unsigned int index;
59
60
  const struct sieve_extension *ext;
61
  void *context;
62
};
63
64
struct sieve_variable_scope;
65
66
struct sieve_variable_scope *
67
sieve_variable_scope_create(struct sieve_instance *svinst,
68
          const struct sieve_extension *var_ext,
69
          const struct sieve_extension *ext);
70
void sieve_variable_scope_ref(struct sieve_variable_scope *scope);
71
void sieve_variable_scope_unref(struct sieve_variable_scope **scope);
72
pool_t sieve_variable_scope_pool(struct sieve_variable_scope *scope);
73
74
struct sieve_variable *
75
sieve_variable_scope_declare(struct sieve_variable_scope *scope,
76
           const char *identifier);
77
struct sieve_variable *
78
sieve_variable_scope_import(struct sieve_variable_scope *scope,
79
          struct sieve_variable *var);
80
struct sieve_variable *
81
sieve_variable_scope_get_variable(struct sieve_variable_scope *scope,
82
          const char *identifier);
83
struct sieve_variable *
84
sieve_variable_scope_get_indexed(struct sieve_variable_scope *scope,
85
         unsigned int index);
86
87
/* Binary */
88
89
struct sieve_variable_scope_binary *
90
sieve_variable_scope_binary_create(struct sieve_variable_scope *scope);
91
92
void sieve_variable_scope_binary_ref(
93
  struct sieve_variable_scope_binary *scpbin);
94
void sieve_variable_scope_binary_unref(
95
  struct sieve_variable_scope_binary **scpbin);
96
97
struct sieve_variable_scope *
98
sieve_variable_scope_binary_dump(struct sieve_instance *svinst,
99
         const struct sieve_extension *var_ext,
100
         const struct sieve_extension *ext,
101
         const struct sieve_dumptime_env *denv,
102
         sieve_size_t *address);
103
struct sieve_variable_scope_binary *
104
sieve_variable_scope_binary_read(struct sieve_instance *svinst,
105
         const struct sieve_extension *var_ext,
106
         const struct sieve_extension *ext,
107
         struct sieve_binary_block *sblock,
108
         sieve_size_t *address);
109
110
struct sieve_variable_scope *
111
sieve_variable_scope_binary_get(struct sieve_variable_scope_binary *scpbin);
112
unsigned int
113
sieve_variable_scope_binary_get_count(
114
  struct sieve_variable_scope_binary *scpbin);
115
116
/*
117
 * Variable namespaces
118
 */
119
120
struct sieve_variables_namespace;
121
122
struct sieve_variables_namespace_def {
123
  struct sieve_object_def obj_def;
124
125
  bool (*validate)(struct sieve_validator *valdtr,
126
       const struct sieve_variables_namespace *nspc,
127
       struct sieve_ast_argument *arg,
128
       struct sieve_command *cmd,
129
       ARRAY_TYPE(sieve_variable_name) *var_name,
130
       void **var_data, bool assignment);
131
  bool (*generate)(const struct sieve_codegen_env *cgenv,
132
       const struct sieve_variables_namespace *nspc,
133
       struct sieve_ast_argument *arg,
134
       struct sieve_command *cmd, void *var_data);
135
136
  bool (*dump_variable)(const struct sieve_dumptime_env *denv,
137
            const struct sieve_variables_namespace *nspc,
138
            const struct sieve_operand *oprnd,
139
            sieve_size_t *address);
140
  int (*read_variable)(const struct sieve_runtime_env *renv,
141
           const struct sieve_variables_namespace *nspc,
142
           const struct sieve_operand *oprnd,
143
           sieve_size_t *address, string_t **str);
144
};
145
146
#define SIEVE_VARIABLES_DEFINE_NAMESPACE(OP) SIEVE_EXT_DEFINE_OBJECT(OP)
147
#define SIEVE_VARIABLES_DEFINE_NAMESPACES(OPS) SIEVE_EXT_DEFINE_OBJECTS(OPS)
148
149
struct sieve_variables_namespace {
150
  struct sieve_object object;
151
152
  const struct sieve_variables_namespace_def *def;
153
};
154
155
void sieve_variables_namespace_register(
156
  const struct sieve_extension *var_ext, struct sieve_validator *valdtr,
157
  const struct sieve_extension *ext,
158
  const struct sieve_variables_namespace_def *nspc_def);
159
160
extern const struct sieve_operand_class sieve_variables_namespace_operand_class;
161
162
void sieve_variables_opr_namespace_variable_emit(
163
  struct sieve_binary_block *sblock,
164
  const struct sieve_extension *var_ext,
165
  const struct sieve_extension *ext,
166
  const struct sieve_variables_namespace_def *nspc_def);
167
168
/* Iteration over all declared variables */
169
170
struct sieve_variable_scope_iter;
171
172
struct sieve_variable_scope_iter *
173
sieve_variable_scope_iterate_init(struct sieve_variable_scope *scope);
174
bool sieve_variable_scope_iterate(struct sieve_variable_scope_iter *iter,
175
          struct sieve_variable **var_r);
176
void sieve_variable_scope_iterate_deinit(
177
  struct sieve_variable_scope_iter **iter);
178
179
/* Statistics */
180
181
unsigned int
182
sieve_variable_scope_declarations(struct sieve_variable_scope *scope);
183
unsigned int sieve_variable_scope_size(struct sieve_variable_scope *scope);
184
185
/* Get all native variables */
186
187
struct sieve_variable *const *
188
sieve_variable_scope_get_variables(struct sieve_variable_scope *scope,
189
           unsigned int *size_r);
190
191
/*
192
 * Variable storage
193
 */
194
195
struct sieve_variable_storage;
196
197
struct sieve_variable_storage *
198
sieve_variable_storage_create(const struct sieve_extension *var_ext,
199
            pool_t pool,
200
            struct sieve_variable_scope_binary *scpbin);
201
bool sieve_variable_get(struct sieve_variable_storage *storage,
202
      unsigned int index, string_t **value);
203
bool sieve_variable_get_modifiable(struct sieve_variable_storage *storage,
204
           unsigned int index, string_t **value);
205
bool sieve_variable_assign(struct sieve_variable_storage *storage,
206
         unsigned int index, const string_t *value);
207
bool sieve_variable_assign_cstr(struct sieve_variable_storage *storage,
208
        unsigned int index, const char *value);
209
bool sieve_variable_get_identifier(struct sieve_variable_storage *storage,
210
           unsigned int index, const char **identifier);
211
const char *sieve_variable_get_varid(struct sieve_variable_storage *storage,
212
             unsigned int index);
213
214
/*
215
 * Variables access
216
 */
217
218
bool sieve_ext_variables_is_active(const struct sieve_extension *var_ext,
219
           struct sieve_validator *valdtr);
220
221
struct sieve_variable_scope *
222
sieve_ext_variables_get_local_scope(const struct sieve_extension *var_ext,
223
            struct sieve_validator *valdtr);
224
225
/* Runtime */
226
227
static inline const char *
228
sieve_ext_variables_get_varid(const struct sieve_extension *ext,
229
            unsigned int index)
230
0
{
231
0
  if (ext == NULL)
232
0
    return t_strdup_printf("%ld", (long)index);
233
234
0
  return t_strdup_printf("%s:%ld", sieve_extension_name(ext),
235
0
             (long)index);
236
0
}
Unexecuted instantiation: testsuite-variables.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-imap4flags.c:sieve_ext_variables_get_varid
Unexecuted instantiation: tag-flags.c:sieve_ext_variables_get_varid
Unexecuted instantiation: tst-hasflag.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-include.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-namespaces.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables.c:sieve_ext_variables_get_varid
Unexecuted instantiation: tst-string.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-enotify.c:sieve_ext_variables_get_varid
Unexecuted instantiation: tst-notify-method-capability.c:sieve_ext_variables_get_varid
Unexecuted instantiation: tst-valid-notify-method.c:sieve_ext_variables_get_varid
Unexecuted instantiation: vmodf-encodeurl.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-extracttext.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-vnd-environment.c:sieve_ext_variables_get_varid
Unexecuted instantiation: cmd-flag.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-imap4flags-common.c:sieve_ext_variables_get_varid
Unexecuted instantiation: cmd-global.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-include-binary.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-include-common.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-include-variables.c:sieve_ext_variables_get_varid
Unexecuted instantiation: cmd-set.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-arguments.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-common.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-dump.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-modifiers.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-name.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-variables-operands.c:sieve_ext_variables_get_varid
Unexecuted instantiation: cmd-notify.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-enotify-common.c:sieve_ext_variables_get_varid
Unexecuted instantiation: cmd-extracttext.c:sieve_ext_variables_get_varid
Unexecuted instantiation: ext-vnd-environment-variables.c:sieve_ext_variables_get_varid
237
238
struct sieve_variable_storage *
239
sieve_ext_variables_runtime_get_storage(const struct sieve_extension *var_ext,
240
          const struct sieve_runtime_env *renv,
241
          const struct sieve_extension *ext);
242
void sieve_ext_variables_runtime_set_storage(
243
  const struct sieve_extension *var_ext,
244
  const struct sieve_runtime_env *renv, const struct sieve_extension *ext,
245
  struct sieve_variable_storage *storage);
246
247
const char *
248
sieve_ext_variables_runtime_get_identifier(
249
  const struct sieve_extension *var_ext,
250
  const struct sieve_runtime_env *renv, const struct sieve_extension *ext,
251
  unsigned int index);
252
253
/*
254
 * Variable arguments
255
 */
256
257
bool sieve_variable_argument_activate(const struct sieve_extension *var_ext,
258
              const struct sieve_extension *this_ext,
259
              struct sieve_validator *valdtr,
260
              struct sieve_command *cmd,
261
              struct sieve_ast_argument *arg,
262
              bool assignment);
263
264
/*
265
 * Variable operands
266
 */
267
268
extern const struct sieve_operand_def variable_operand;
269
270
void sieve_variables_opr_variable_emit(struct sieve_binary_block *sblock,
271
               const struct sieve_extension *var_ext,
272
               struct sieve_variable *var);
273
void sieve_variables_opr_match_value_emit(struct sieve_binary_block *sblock,
274
            const struct sieve_extension *var_ext,
275
            unsigned int index);
276
277
int sieve_variable_operand_read_data(const struct sieve_runtime_env *renv,
278
             struct sieve_operand *operand,
279
             sieve_size_t *address,
280
             const char *field_name,
281
             struct sieve_variable_storage **storage_r,
282
             unsigned int *var_index_r);
283
int sieve_variable_operand_read(const struct sieve_runtime_env *renv,
284
        sieve_size_t *address, const char *field_name,
285
        struct sieve_variable_storage **storage_r,
286
        unsigned int *var_index_r);
287
288
static inline bool
289
sieve_operand_is_variable(const struct sieve_operand *operand)
290
0
{
291
0
  return (operand != NULL && operand->def != NULL &&
292
0
    operand->def == &variable_operand);
293
0
}
Unexecuted instantiation: testsuite-variables.c:sieve_operand_is_variable
Unexecuted instantiation: ext-imap4flags.c:sieve_operand_is_variable
Unexecuted instantiation: tag-flags.c:sieve_operand_is_variable
Unexecuted instantiation: tst-hasflag.c:sieve_operand_is_variable
Unexecuted instantiation: ext-include.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-namespaces.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables.c:sieve_operand_is_variable
Unexecuted instantiation: tst-string.c:sieve_operand_is_variable
Unexecuted instantiation: ext-enotify.c:sieve_operand_is_variable
Unexecuted instantiation: tst-notify-method-capability.c:sieve_operand_is_variable
Unexecuted instantiation: tst-valid-notify-method.c:sieve_operand_is_variable
Unexecuted instantiation: vmodf-encodeurl.c:sieve_operand_is_variable
Unexecuted instantiation: ext-extracttext.c:sieve_operand_is_variable
Unexecuted instantiation: ext-vnd-environment.c:sieve_operand_is_variable
Unexecuted instantiation: cmd-flag.c:sieve_operand_is_variable
Unexecuted instantiation: ext-imap4flags-common.c:sieve_operand_is_variable
Unexecuted instantiation: cmd-global.c:sieve_operand_is_variable
Unexecuted instantiation: ext-include-binary.c:sieve_operand_is_variable
Unexecuted instantiation: ext-include-common.c:sieve_operand_is_variable
Unexecuted instantiation: ext-include-variables.c:sieve_operand_is_variable
Unexecuted instantiation: cmd-set.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-arguments.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-common.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-dump.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-modifiers.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-name.c:sieve_operand_is_variable
Unexecuted instantiation: ext-variables-operands.c:sieve_operand_is_variable
Unexecuted instantiation: cmd-notify.c:sieve_operand_is_variable
Unexecuted instantiation: ext-enotify-common.c:sieve_operand_is_variable
Unexecuted instantiation: cmd-extracttext.c:sieve_operand_is_variable
Unexecuted instantiation: ext-vnd-environment-variables.c:sieve_operand_is_variable
294
295
/*
296
 * Modifiers
297
 */
298
299
/* Definition */
300
301
struct sieve_variables_modifier;
302
303
struct sieve_variables_modifier_def {
304
  struct sieve_object_def obj_def;
305
306
  unsigned int precedence;
307
308
  bool (*modify)(const struct sieve_variables_modifier *modf,
309
           string_t *in, string_t **result);
310
};
311
312
struct sieve_variables_modifier {
313
  struct sieve_object object;
314
  const struct sieve_extension *var_ext;
315
316
  const struct sieve_variables_modifier_def *def;
317
};
318
319
#define SIEVE_VARIABLES_DEFINE_MODIFIER(OP) SIEVE_EXT_DEFINE_OBJECT(OP)
320
#define SIEVE_VARIABLES_DEFINE_MODIFIERS(OPS) SIEVE_EXT_DEFINE_OBJECTS(OPS)
321
322
#define sieve_variables_modifier_name(smodf) \
323
0
  ((smodf)->object.def->identifier)
324
325
ARRAY_DEFINE_TYPE(sieve_variables_modifier,
326
  struct sieve_variables_modifier);
327
328
/* Registry */
329
330
void sieve_variables_modifier_register(
331
  const struct sieve_extension *var_ext, struct sieve_validator *valdtr,
332
  const struct sieve_extension *ext,
333
  const struct sieve_variables_modifier_def *smodf);
334
335
/* Tagged argument */
336
337
void sieve_variables_modifiers_link_tag(
338
  struct sieve_validator *valdtr, const struct sieve_extension *var_ext,
339
  struct sieve_command_registration *cmd_reg);
340
341
bool sieve_variables_modifiers_validate(
342
  struct sieve_validator *valdtr, struct sieve_command *cmd,
343
  ARRAY_TYPE(sieve_variables_modifier) *modifiers);
344
345
bool sieve_variables_modifiers_generate(
346
  const struct sieve_codegen_env *cgenv,
347
  ARRAY_TYPE(sieve_variables_modifier) *modifiers);
348
349
/* Coding */
350
351
extern const struct sieve_operand_class
352
  sieve_variables_modifier_operand_class;
353
354
bool sieve_variables_modifiers_code_dump(const struct sieve_dumptime_env *denv,
355
           sieve_size_t *address);
356
int sieve_variables_modifiers_code_read(
357
  const struct sieve_runtime_env *renv,
358
  const struct sieve_extension *var_ext, sieve_size_t *address,
359
  ARRAY_TYPE(sieve_variables_modifier) *modifiers);
360
361
/* Application */
362
363
int sieve_variables_modifiers_apply(
364
  const struct sieve_runtime_env *renv,
365
  const struct sieve_extension *var_ext,
366
  ARRAY_TYPE(sieve_variables_modifier) *modifiers, string_t **value);
367
368
/*
369
 * Code dumping
370
 */
371
372
void sieve_ext_variables_dump_set_scope(const struct sieve_extension *var_ext,
373
          const struct sieve_dumptime_env *denv,
374
          const struct sieve_extension *ext,
375
          struct sieve_variable_scope *scope);
376
377
#endif