1
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
7
#include "sieve-common.h"
8
#include "sieve-dump.h"
9
#include "sieve-binary.h"
10
#include "sieve-code.h"
12
#include "ext-variables-common.h"
13
#include "ext-variables-dump.h"
16
* Code dumper extension
19
static void ext_variables_code_dumper_free
20
(struct sieve_code_dumper *dumper, void *context);
22
const struct sieve_code_dumper_extension variables_dump_extension = {
24
ext_variables_code_dumper_free
31
struct ext_variables_dump_context {
32
struct sieve_variable_scope *main_scope;
33
ARRAY_DEFINE(ext_scopes, struct sieve_variable_scope *);
36
static void ext_variables_code_dumper_free
37
(struct sieve_code_dumper *dumper ATTR_UNUSED, void *context)
39
struct ext_variables_dump_context *dctx =
40
(struct ext_variables_dump_context *) context;
42
if ( dctx == NULL || dctx->main_scope == NULL )
45
sieve_variable_scope_unref(&dctx->main_scope);
48
static struct ext_variables_dump_context *ext_variables_dump_get_context
49
(const struct sieve_dumptime_env *denv)
51
struct sieve_code_dumper *dumper = denv->cdumper;
52
struct ext_variables_dump_context *dctx = sieve_dump_extension_get_context
53
(dumper, &variables_extension);
57
/* Create dumper context */
58
pool = sieve_code_dumper_pool(dumper);
59
dctx = p_new(pool, struct ext_variables_dump_context, 1);
60
p_array_init(&dctx->ext_scopes, pool, sieve_extensions_get_count());
62
sieve_dump_extension_set_context(dumper, &variables_extension, dctx);
68
bool ext_variables_code_dump
69
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
71
struct ext_variables_dump_context *dctx;
72
struct sieve_variable_scope *main_scope;
73
unsigned int i, scope_size;
77
sieve_code_mark(denv);
78
if ( !sieve_binary_read_unsigned(denv->sbin, address, &scope_size) )
82
if ( !sieve_binary_read_offset(denv->sbin, address, &end_offset) )
85
main_scope = sieve_variable_scope_create(NULL);
87
sieve_code_dumpf(denv, "SCOPE [%u] (end: %08x)",
88
scope_size, (unsigned int) (pc + end_offset));
90
/* Read main variable scope */
92
for ( i = 0; i < scope_size; i++ ) {
95
sieve_code_mark(denv);
96
if (!sieve_binary_read_string(denv->sbin, address, &identifier) ) {
100
sieve_code_dumpf(denv, "%3d: '%s'", i, str_c(identifier));
102
(void) sieve_variable_scope_declare(main_scope, str_c(identifier));
105
dctx = ext_variables_dump_get_context(denv);
106
dctx->main_scope = main_scope;
115
void sieve_ext_variables_dump_set_scope
116
(const struct sieve_dumptime_env *denv, const struct sieve_extension *ext,
117
struct sieve_variable_scope *scope)
119
struct ext_variables_dump_context *dctx = ext_variables_dump_get_context(denv);
121
array_idx_set(&dctx->ext_scopes, (unsigned int) SIEVE_EXT_ID(ext), &scope);
125
* Variable identifier dump
128
const char *ext_variables_dump_get_identifier
129
(const struct sieve_dumptime_env *denv, const struct sieve_extension *ext,
132
struct ext_variables_dump_context *dctx = ext_variables_dump_get_context(denv);
133
struct sieve_variable_scope *scope;
134
struct sieve_variable *var;
137
scope = dctx->main_scope;
139
struct sieve_variable_scope *const *ext_scope;
140
int ext_id = SIEVE_EXT_ID(ext);
142
if ( ext_id < 0 || ext_id >= (int) array_count(&dctx->ext_scopes) )
145
ext_scope = array_idx(&dctx->ext_scopes, (unsigned int) ext_id);
152
var = sieve_variable_scope_get_indexed(scope, index);
154
return var->identifier;