~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101901

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/plugins/variables/ext-variables-common.c

  • Committer: Chuck Short
  • Date: 2010-01-21 20:21:25 UTC
  • mfrom: (4.1.11 squeeze)
  • Revision ID: zulcss@ubuntu.com-20100121202125-pme73o491kfwj5nc
* Merge from debian testing, remaining changes:
  + Add new binary pkg dovecot-postfix that integrates postfix and dovecot
    automatically: (LP: #164837)
  + debian/control:
    - add new binary with short description
    - set Architecture all for dovecot-postfix (LP: #329878)
  + debian/dovecot-postfix.postinst:
    - create initial certificate symlinks to snakeoil.
    - set up postfix with postconf to:
      - use Maildir/ as the default mailbox.
      - use dovecot as the sasl authentication server.
      - use dovecot LDA (deliver).
      - use tls for smtp{d} services.
    - fix certificates paths in postfix' main.cf
    - add reject_unauth_destination to postfix' recipient restrictions
    - add reject_unknown_sender_domain to postfix' sender restriction
    - rename configuration name on remove, delete on purge
    - restart dovecot after linking certificates
    - handle use case when postfix is unconfigurated
  + debian/dovecot-postfix.dirs: create backup directory for postfix's config
    configuration
  + restart postfix and dovecot.
  + debian/dovecot-postfix.postrm:
    - remove all dovecot related configuration from postfix.
    - restart postfix and dovecot.
  + debian/dovecot-common.init:
    - check if /etc/dovecot/dovecot-postfix.conf exists and use it
      as the configuration file if so.
  + debian/patches/warning-ubuntu-postfix.dpatch
    - add warning about dovecot-postfix.conf in dovecot default
      configuration file
  + debian/patches/dovecot-postfix.conf.diff:
    - Ubuntu server custom changes to the default dovecot configuration for
      better interfation with postfix.
    - enable sieve plugin.
    - Ubuntu server custom changes to the default dovecot configuration for
      better integration with postfix:
      - enable imap, pop3, imaps, pop3s and managesieve by default.
      - enable dovecot LDA (deliver).
      - enable SASL auth socket in postfix private directory
   + debian/rules:
     - copy, patch and install dovecot-postfix.conf in /etc/dovecot/.
     - build architecure independent packages too
   + Use Snakeoil SSL certificates by default.
     - debian/control: Depend on ssl-cert.
     - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert
       paths to snakeoil.
     - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
   + Add autopkgtest to debian/tests/*.
   + Fast TearDown: Update the lsb init header to not stop in level 6.
   + Add ufw integration:
     - Created debian/dovecot-common.ufw.profile.
     - debian/rules: install profile.
     - debian/control: suggest ufw.
   + debian/{control,rules}: enable PIE hardening.
   + dovecot-imapd, dovecot-pop3: Replaces dovecot-common (<< 1:1.1). (LP: #254721)
   + debian/control: Update Vcs-* headers.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
* New upstream release.
* debian/patches/gold-fix.patch: Removed. Fixed upstream.
* Moved libexec to lib corrections in dovecot-managesieve.patch and
  dovecot-managesieve-dist.patch to dovecot-example.patch
* debian/patches/dovecot-mboxlocking.patch: Regenerated to avoid FTBFS
  when quilt isn't installed.
* debian/patches/quota-mountpoint.patch: Removed. Not needed anymore.
* debian/patches/dovecot-quota.patch: Removed. Quotas aren't properly
  enabled unless mail_plugins = quota imap_quota.
* debian/patches/gold-fix.patch: Fixed configure script to build even
  with binutils-gold or --no-add-needed linker flag (Closes: #554306)
* debian/dovecot-common.init: fixed LSB headers. Thanks to Pascal Volk.
  (Closes: #558040)
* debian/changelog: added CVE references to previous changelog entry.
* debian/rules: checked up the build system. It's not fragile anymore.
  (Closes: 493803)
* debian/dovecot-common.postinst: Now invoking dpkg-reconfigure
  on dovecot-common is enough to generate new certificates
  if the previous ones were removed. (Closes: #545582)
* debian/rules: No longer install convert-tool in /usr/bin.
  It isn't an user utility and it should stay in /usr/lib/dovecot
  like all other similar tool.
* New upstream release. (Closes: #557601)
* [SECURITY] Fixes local information disclosure and denial of service.
  (see: http://www.dovecot.org/list/dovecot-news/2009-November/000143.html
  and CVE-2009-3897)
* Added myself to uploaders.
* Switched to the new source format "3.0 (quilt)":
  - removed dpatch from build-depends
  - removed debian/README.source because now we use only standard
    dpkg features
  - regenerated all patches
* Prepared to switch to multi-origin source:
  - recreated dovecot-libsieve.patch and dovecot-managesieve-dist.patch
    starting from the upstream tarball
  - removed all autotools related build-depends and build-conflict
  - renamed dovecot-libsieve and dovecot-managesieve directories
    to libsieve and managesieve.
* debian/rules: Moved the configuration of libsieve and managesieve from
  the build phase to the configuration phase
* Added dovecot-dbg package  with debugging symbols.  Thanks Stephan Bosch.
  (Closes: #554710)
* Fixed some stray libexec'isms in the default configuration.
* New upstream release.
* debian/dovecot-common.init:
  - use $CONF when starting the daemon. (Closes: #549944)
  - always output start/stop messages. (Closes: #523810)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
 
2
 */
 
3
 
 
4
#include "lib.h"
 
5
#include "hash.h"
 
6
#include "str.h"
 
7
#include "array.h"
 
8
 
 
9
#include "sieve-common.h"
 
10
 
 
11
#include "sieve-ast.h"
 
12
#include "sieve-binary.h"
 
13
#include "sieve-code.h"
 
14
#include "sieve-objects.h"
 
15
#include "sieve-match-types.h"
 
16
 
 
17
#include "sieve-commands.h"
 
18
#include "sieve-validator.h"
 
19
#include "sieve-generator.h"
 
20
#include "sieve-dump.h"
 
21
#include "sieve-interpreter.h"
 
22
 
 
23
#include "ext-variables-common.h"
 
24
#include "ext-variables-name.h"
 
25
#include "ext-variables-modifiers.h"
 
26
 
 
27
/*
 
28
 * Variable scope 
 
29
 */
 
30
 
 
31
struct sieve_variable_scope {
 
32
        pool_t pool;
 
33
        int refcount;
 
34
 
 
35
        struct sieve_variable *error_var;
 
36
 
 
37
        const struct sieve_extension *ext;
 
38
 
 
39
        struct hash_table *variables;
 
40
        ARRAY_DEFINE(variable_index, struct sieve_variable *);
 
41
};
 
42
 
 
43
struct sieve_variable_scope_iter {
 
44
        struct sieve_variable_scope *scope;
 
45
        struct hash_iterate_context *hctx;
 
46
};
 
47
 
 
48
struct sieve_variable_scope *sieve_variable_scope_create
 
49
        (const struct sieve_extension *ext) 
 
50
{
 
51
        struct sieve_variable_scope *scope;
 
52
        pool_t pool;
 
53
 
 
54
        pool = pool_alloconly_create("sieve_variable_scope", 4096);
 
55
        scope = p_new(pool, struct sieve_variable_scope, 1);
 
56
        scope->pool = pool;
 
57
        scope->refcount = 1;
 
58
 
 
59
        scope->ext = ext;
 
60
        scope->variables = hash_table_create
 
61
                (default_pool, pool, 0, strcase_hash, (hash_cmp_callback_t *)strcasecmp);
 
62
        p_array_init(&scope->variable_index, pool, 128);
 
63
                
 
64
        return scope;
 
65
}
 
66
 
 
67
void sieve_variable_scope_ref(struct sieve_variable_scope *scope)
 
68
{
 
69
        scope->refcount++;
 
70
}
 
71
 
 
72
void sieve_variable_scope_unref(struct sieve_variable_scope **scope)
 
73
{
 
74
        i_assert((*scope)->refcount > 0);
 
75
 
 
76
        if (--(*scope)->refcount != 0)
 
77
                return;
 
78
 
 
79
        hash_table_destroy(&(*scope)->variables);
 
80
 
 
81
        pool_unref(&(*scope)->pool);
 
82
    *scope = NULL;
 
83
}
 
84
 
 
85
pool_t sieve_variable_scope_pool(struct sieve_variable_scope *scope)
 
86
{
 
87
        return scope->pool;
 
88
}
 
89
 
 
90
struct sieve_variable *sieve_variable_scope_declare
 
91
(struct sieve_variable_scope *scope, const char *identifier)
 
92
{
 
93
        struct sieve_variable *new_var;
 
94
 
 
95
        new_var = p_new(scope->pool, struct sieve_variable, 1);
 
96
        new_var->ext = scope->ext;
 
97
 
 
98
        if ( array_count(&scope->variable_index) >= SIEVE_VARIABLES_MAX_SCOPE_SIZE ) {
 
99
                if ( scope->error_var == NULL ) {
 
100
                        new_var->identifier = "@ERROR@";
 
101
                        new_var->index = 0;
 
102
                        
 
103
                        scope->error_var = new_var;
 
104
                        return NULL;
 
105
                }
 
106
 
 
107
                return scope->error_var;
 
108
        }
 
109
        
 
110
        new_var->identifier = p_strdup(scope->pool, identifier);
 
111
        new_var->index = array_count(&scope->variable_index);
 
112
 
 
113
        hash_table_insert(scope->variables, (void *) new_var->identifier, (void *) new_var);
 
114
        array_append(&scope->variable_index, &new_var, 1);
 
115
        
 
116
        return new_var;
 
117
}
 
118
 
 
119
struct sieve_variable *sieve_variable_scope_get_variable
 
120
(struct sieve_variable_scope *scope, const char *identifier, bool declare)
 
121
{
 
122
        struct sieve_variable *var = 
 
123
                (struct sieve_variable *) hash_table_lookup(scope->variables, identifier);
 
124
 
 
125
        if ( var == NULL && declare ) {
 
126
                var = sieve_variable_scope_declare(scope, identifier);
 
127
        }
 
128
 
 
129
        return var;
 
130
}
 
131
 
 
132
struct sieve_variable *sieve_variable_scope_import
 
133
(struct sieve_variable_scope *scope, struct sieve_variable *var)
 
134
{
 
135
        struct sieve_variable *new_var = p_new(scope->pool, struct sieve_variable, 1);
 
136
        memcpy(new_var, var, sizeof(struct sieve_variable));
 
137
                
 
138
        hash_table_insert(scope->variables, (void *) new_var->identifier, (void *) new_var);
 
139
        
 
140
        /* Not entered into the index because it is an external variable 
 
141
         * (This can be done unlimited; only limited by the size of the external scope)
 
142
         */
 
143
 
 
144
        return new_var;
 
145
}
 
146
 
 
147
struct sieve_variable_scope_iter *sieve_variable_scope_iterate_init
 
148
(struct sieve_variable_scope *scope)
 
149
{
 
150
        struct sieve_variable_scope_iter *iter = t_new(struct sieve_variable_scope_iter, 1);
 
151
        iter->scope = scope;
 
152
        iter->hctx = hash_table_iterate_init(scope->variables);
 
153
 
 
154
        return iter;
 
155
}
 
156
 
 
157
bool sieve_variable_scope_iterate
 
158
(struct sieve_variable_scope_iter *iter, struct sieve_variable **var_r)
 
159
{
 
160
        void *key, *value;
 
161
 
 
162
        if ( !hash_table_iterate(iter->hctx, &key, &value) )
 
163
                return FALSE; 
 
164
        
 
165
        *var_r = (struct sieve_variable *) value;
 
166
        return TRUE;
 
167
}
 
168
 
 
169
void sieve_variable_scope_iterate_deinit
 
170
(struct sieve_variable_scope_iter **iter)
 
171
{
 
172
        hash_table_iterate_deinit(&(*iter)->hctx);
 
173
        *iter = NULL;
 
174
}
 
175
 
 
176
unsigned int sieve_variable_scope_declarations
 
177
(struct sieve_variable_scope *scope)
 
178
{
 
179
        return hash_table_count(scope->variables);
 
180
}
 
181
 
 
182
unsigned int sieve_variable_scope_size
 
183
(struct sieve_variable_scope *scope)
 
184
{
 
185
        return array_count(&scope->variable_index);
 
186
}
 
187
 
 
188
struct sieve_variable * const *sieve_variable_scope_get_variables
 
189
(struct sieve_variable_scope *scope, unsigned int *size_r)
 
190
{
 
191
        return array_get(&scope->variable_index, size_r);
 
192
}
 
193
 
 
194
struct sieve_variable *sieve_variable_scope_get_indexed
 
195
(struct sieve_variable_scope *scope, unsigned int index)
 
196
{
 
197
        struct sieve_variable * const *var;
 
198
        
 
199
        if ( index >= array_count(&scope->variable_index) ) 
 
200
                return NULL;
 
201
                
 
202
        var = array_idx(&scope->variable_index, index); 
 
203
        
 
204
        return *var;
 
205
}
 
206
 
 
207
/* 
 
208
 * Variable storage 
 
209
 */
 
210
 
 
211
struct sieve_variable_storage {
 
212
        pool_t pool;
 
213
        struct sieve_variable_scope *scope;
 
214
        unsigned int max_size;
 
215
        ARRAY_DEFINE(var_values, string_t *); 
 
216
};
 
217
 
 
218
struct sieve_variable_storage *sieve_variable_storage_create
 
219
(pool_t pool, struct sieve_variable_scope *scope, unsigned int max_size)
 
220
{
 
221
        struct sieve_variable_storage *storage;
 
222
        
 
223
        storage = p_new(pool, struct sieve_variable_storage, 1);
 
224
        storage->pool = pool;
 
225
        storage->scope = scope;
 
226
        
 
227
        if ( scope != NULL )
 
228
                storage->max_size = sieve_variable_scope_size(scope);
 
229
        else
 
230
                storage->max_size = max_size;
 
231
                
 
232
        p_array_init(&storage->var_values, pool, 4);
 
233
 
 
234
        return storage;
 
235
}
 
236
 
 
237
static inline bool sieve_variable_valid
 
238
(struct sieve_variable_storage *storage, unsigned int index)
 
239
{
 
240
        if ( storage->scope == NULL ) return TRUE;
 
241
 
 
242
        return ( index < storage->max_size );
 
243
}
 
244
 
 
245
bool sieve_variable_get_identifier
 
246
(struct sieve_variable_storage *storage, unsigned int index, const char **identifier)
 
247
{
 
248
        struct sieve_variable * const *var;
 
249
        *identifier = NULL;
 
250
 
 
251
        if ( storage->scope == NULL ) return TRUE;
 
252
 
 
253
        /* FIXME: direct invasion of the scope object is a bit ugly */
 
254
        if ( index >= array_count(&storage->scope->variable_index) )
 
255
                return FALSE;
 
256
 
 
257
        var = array_idx(&storage->scope->variable_index, index);
 
258
 
 
259
        if ( *var != NULL )
 
260
                *identifier = (*var)->identifier;
 
261
 
 
262
        return TRUE;
 
263
}
 
264
 
 
265
bool sieve_variable_get
 
266
(struct sieve_variable_storage *storage, unsigned int index, string_t **value)
 
267
{
 
268
        *value = NULL;
 
269
        
 
270
        if  ( index < array_count(&storage->var_values) ) {
 
271
                string_t * const *varent;
 
272
                        
 
273
                varent = array_idx(&storage->var_values, index);
 
274
                
 
275
                *value = *varent;
 
276
        } else if ( !sieve_variable_valid(storage, index) )
 
277
                return FALSE;
 
278
 
 
279
        return TRUE;
 
280
 
281
 
 
282
bool sieve_variable_get_modifiable
 
283
(struct sieve_variable_storage *storage, unsigned int index, string_t **value)
 
284
{
 
285
        string_t *dummy;
 
286
        
 
287
        if ( value == NULL ) value = &dummy;
 
288
        
 
289
        if ( !sieve_variable_get(storage, index, value) )
 
290
                return FALSE;
 
291
        
 
292
        if ( *value == NULL ) {
 
293
                *value = str_new(storage->pool, 256);
 
294
                array_idx_set(&storage->var_values, index, value);      
 
295
        }
 
296
 
 
297
        return TRUE; 
 
298
}
 
299
 
 
300
bool sieve_variable_assign
 
301
(struct sieve_variable_storage *storage, unsigned int index, 
 
302
        const string_t *value)
 
303
{
 
304
        string_t *varval;
 
305
        
 
306
        if ( !sieve_variable_get_modifiable(storage, index, &varval) ) 
 
307
                return FALSE;
 
308
 
 
309
        str_truncate(varval, 0);
 
310
        str_append_str(varval, value);
 
311
 
 
312
        /* Just a precaution, caller should prevent this in the first place */
 
313
        if ( str_len(varval) > SIEVE_VARIABLES_MAX_VARIABLE_SIZE )
 
314
                str_truncate(varval, SIEVE_VARIABLES_MAX_VARIABLE_SIZE);
 
315
 
 
316
        return TRUE;
 
317
}
 
318
 
 
319
/*
 
320
 * AST Context
 
321
 */
 
322
 
 
323
static void ext_variables_ast_free
 
324
(struct sieve_ast *ast ATTR_UNUSED, void *context)
 
325
{
 
326
        struct sieve_variable_scope *main_scope =
 
327
                (struct sieve_variable_scope *) context;
 
328
 
 
329
        /* Unreference main variable scope */
 
330
        sieve_variable_scope_unref(&main_scope);
 
331
}
 
332
 
 
333
static const struct sieve_ast_extension variables_ast_extension = {
 
334
    &variables_extension,
 
335
    ext_variables_ast_free
 
336
};
 
337
 
 
338
static struct sieve_variable_scope *ext_variables_create_main_scope
 
339
(struct sieve_ast *ast)
 
340
{
 
341
        struct sieve_variable_scope *scope;
 
342
 
 
343
        scope = sieve_variable_scope_create(NULL);
 
344
 
 
345
        sieve_ast_extension_register(ast, &variables_ast_extension, (void *) scope);
 
346
 
 
347
        return scope;
 
348
}
 
349
 
 
350
static struct sieve_variable_scope *ext_variables_ast_get_main_scope
 
351
(struct sieve_ast *ast)
 
352
{
 
353
        struct sieve_variable_scope *main_scope =
 
354
                (struct sieve_variable_scope *) sieve_ast_extension_get_context
 
355
                (ast, &variables_extension);
 
356
        
 
357
        return main_scope;
 
358
}
 
359
 
 
360
/*
 
361
 * Validator context 
 
362
 */
 
363
 
 
364
static struct ext_variables_validator_context *
 
365
ext_variables_validator_context_create(struct sieve_validator *valdtr)
 
366
{               
 
367
        pool_t pool = sieve_validator_pool(valdtr);
 
368
        struct ext_variables_validator_context *ctx;
 
369
        struct sieve_ast *ast = sieve_validator_ast(valdtr);
 
370
        
 
371
        ctx = p_new(pool, struct ext_variables_validator_context, 1);
 
372
        ctx->modifiers = sieve_validator_object_registry_create(valdtr);
 
373
        ctx->main_scope = ext_variables_create_main_scope(ast);
 
374
 
 
375
        sieve_validator_extension_set_context
 
376
                (valdtr, &variables_extension, (void *) ctx);
 
377
 
 
378
        return ctx;
 
379
}
 
380
 
 
381
struct ext_variables_validator_context *ext_variables_validator_context_get
 
382
(struct sieve_validator *valdtr)
 
383
{
 
384
        struct ext_variables_validator_context *ctx = 
 
385
                (struct ext_variables_validator_context *)
 
386
                sieve_validator_extension_get_context(valdtr, &variables_extension);
 
387
        
 
388
        if ( ctx == NULL ) {
 
389
                ctx = ext_variables_validator_context_create(valdtr);
 
390
        }
 
391
        
 
392
        return ctx;
 
393
}
 
394
 
 
395
void ext_variables_validator_initialize(struct sieve_validator *validator)
 
396
{
 
397
        struct ext_variables_validator_context *ctx;
 
398
        
 
399
        /* Create our context */
 
400
        ctx = ext_variables_validator_context_get(validator);
 
401
        
 
402
        ext_variables_register_core_modifiers(ctx);
 
403
        
 
404
        ctx->active = TRUE;
 
405
}
 
406
 
 
407
struct sieve_variable *ext_variables_validator_get_variable
 
408
(struct sieve_validator *validator, const char *variable, bool declare)
 
409
{
 
410
        struct ext_variables_validator_context *ctx = 
 
411
                ext_variables_validator_context_get(validator);
 
412
                
 
413
        return sieve_variable_scope_get_variable(ctx->main_scope, variable, declare);
 
414
}
 
415
 
 
416
struct sieve_variable_scope *sieve_ext_variables_get_main_scope
 
417
(struct sieve_validator *validator)
 
418
{
 
419
        struct ext_variables_validator_context *ctx = 
 
420
                ext_variables_validator_context_get(validator);
 
421
                
 
422
        return ctx->main_scope;
 
423
}
 
424
 
 
425
bool sieve_ext_variables_is_active(struct sieve_validator *valdtr)
 
426
{
 
427
        struct ext_variables_validator_context *ctx = 
 
428
                ext_variables_validator_context_get(valdtr);
 
429
                
 
430
        return ( ctx != NULL && ctx->active );
 
431
}
 
432
 
 
433
/*
 
434
 * Code generation
 
435
 */
 
436
 
 
437
bool ext_variables_generator_load(const struct sieve_codegen_env *cgenv)
 
438
{
 
439
        struct sieve_variable_scope *main_scope = 
 
440
                ext_variables_ast_get_main_scope(cgenv->ast);
 
441
        unsigned int count = sieve_variable_scope_size(main_scope);
 
442
        sieve_size_t jump;
 
443
 
 
444
        sieve_binary_emit_unsigned(cgenv->sbin, count);
 
445
 
 
446
        jump = sieve_binary_emit_offset(cgenv->sbin, 0);
 
447
 
 
448
        if ( count > 0 ) {
 
449
                unsigned int size, i;
 
450
                struct sieve_variable *const *vars = 
 
451
                        sieve_variable_scope_get_variables(main_scope, &size);
 
452
 
 
453
                for ( i = 0; i < size; i++ ) {                  
 
454
                        sieve_binary_emit_cstring(cgenv->sbin, vars[i]->identifier);
 
455
                }
 
456
        }
 
457
        
 
458
        sieve_binary_resolve_offset(cgenv->sbin, jump);
 
459
                
 
460
        return TRUE;
 
461
}
 
462
 
 
463
/* 
 
464
 * Interpreter context 
 
465
 */
 
466
 
 
467
struct ext_variables_interpreter_context {
 
468
        struct sieve_variable_storage *local_storage;
 
469
        ARRAY_DEFINE(ext_storages, struct sieve_variable_storage *);
 
470
};
 
471
 
 
472
static struct ext_variables_interpreter_context *
 
473
ext_variables_interpreter_context_create
 
474
(struct sieve_interpreter *interp, unsigned int max_size)
 
475
{               
 
476
        pool_t pool = sieve_interpreter_pool(interp);
 
477
        struct ext_variables_interpreter_context *ctx;
 
478
        
 
479
        ctx = p_new(pool, struct ext_variables_interpreter_context, 1);
 
480
        ctx->local_storage = sieve_variable_storage_create(pool, NULL, max_size);
 
481
        p_array_init(&ctx->ext_storages, pool, sieve_extensions_get_count());
 
482
 
 
483
        sieve_interpreter_extension_set_context
 
484
                (interp, &variables_extension, (void *) ctx);
 
485
 
 
486
        return ctx;
 
487
}
 
488
 
 
489
bool ext_variables_interpreter_load
 
490
        (const struct sieve_runtime_env *renv, sieve_size_t *address)
 
491
{
 
492
        struct ext_variables_interpreter_context *ctx;
 
493
        unsigned int scope_size;
 
494
        sieve_size_t pc;
 
495
        int end_offset;
 
496
                
 
497
        if ( !sieve_binary_read_unsigned(renv->sbin, address, &scope_size) ) {
 
498
                sieve_sys_error("variables: failed to read main scope size");
 
499
                return FALSE;
 
500
        }
 
501
 
 
502
        if ( scope_size > SIEVE_VARIABLES_MAX_SCOPE_SIZE ) {
 
503
                sieve_sys_error("variables: scope size exceeds the limit (%u > %u)", 
 
504
                        scope_size, SIEVE_VARIABLES_MAX_SCOPE_SIZE );
 
505
                return FALSE;
 
506
        }
 
507
        
 
508
        pc = *address;
 
509
        if ( !sieve_binary_read_offset(renv->sbin, address, &end_offset) )
 
510
                return NULL;
 
511
        *address = pc + end_offset;
 
512
        
 
513
        /* Create our context */
 
514
        ctx = ext_variables_interpreter_context_create(renv->interp, scope_size);
 
515
 
 
516
        /* Enable support for match values */
 
517
        (void) sieve_match_values_set_enabled(renv->interp, TRUE);
 
518
        
 
519
        return TRUE;
 
520
}
 
521
 
 
522
static inline struct ext_variables_interpreter_context *
 
523
ext_variables_interpreter_context_get(struct sieve_interpreter *interp)
 
524
{
 
525
        return (struct ext_variables_interpreter_context *)
 
526
                sieve_interpreter_extension_get_context(interp, &variables_extension);
 
527
}
 
528
 
 
529
struct sieve_variable_storage *sieve_ext_variables_get_storage
 
530
(struct sieve_interpreter *interp, const struct sieve_extension *ext)
 
531
{
 
532
        struct ext_variables_interpreter_context *ctx = 
 
533
                ext_variables_interpreter_context_get(interp);
 
534
        struct sieve_variable_storage * const *storage;
 
535
        int ext_id;
 
536
                
 
537
        if ( ext == NULL )
 
538
                return ctx->local_storage;
 
539
 
 
540
        ext_id = SIEVE_EXT_ID(ext);
 
541
        if ( ext_id >= (int) array_count(&ctx->ext_storages) ) {
 
542
                storage = NULL;
 
543
        } else {
 
544
                storage = array_idx(&ctx->ext_storages, ext_id);
 
545
        }
 
546
        
 
547
        if ( storage == NULL || *storage == NULL ) 
 
548
                return NULL;
 
549
        
 
550
        return *storage;
 
551
}
 
552
 
 
553
void sieve_ext_variables_set_storage
 
554
(struct sieve_interpreter *interp, struct sieve_variable_storage *storage,
 
555
        const struct sieve_extension *ext)
 
556
{
 
557
        struct ext_variables_interpreter_context *ctx = 
 
558
                ext_variables_interpreter_context_get(interp);
 
559
                
 
560
        if ( ctx == NULL || ext == NULL || storage == NULL )
 
561
                return;
 
562
                
 
563
        array_idx_set(&ctx->ext_storages, (unsigned int) SIEVE_EXT_ID(ext), &storage);
 
564
}
 
565
 
 
566
 
 
567