diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c index ffb52a1ae1bb25ed014cd4d267563c45744c552a..faaa08dabbde2b0e4df221ce10f49de59becfde3 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.c +++ b/src/lib-sieve/plugins/variables/ext-variables-common.c @@ -66,15 +66,15 @@ struct sieve_variable_scope *sieve_variable_scope_create void sieve_variable_scope_ref(struct sieve_variable_scope *scope) { - scope->refcount++; + scope->refcount++; } void sieve_variable_scope_unref(struct sieve_variable_scope **scope) { - i_assert((*scope)->refcount > 0); + i_assert((*scope)->refcount > 0); - if (--(*scope)->refcount != 0) - return; + if (--(*scope)->refcount != 0) + return; hash_destroy(&(*scope)->variables); @@ -182,7 +182,7 @@ unsigned int sieve_variable_scope_declarations unsigned int sieve_variable_scope_size (struct sieve_variable_scope *scope) { - return array_count(&scope->variable_index); + return array_count(&scope->variable_index); } struct sieve_variable * const *sieve_variable_scope_get_variables @@ -191,6 +191,19 @@ struct sieve_variable * const *sieve_variable_scope_get_variables return array_get(&scope->variable_index, size_r); } +struct sieve_variable *sieve_variable_scope_get_indexed +(struct sieve_variable_scope *scope, unsigned int index) +{ + struct sieve_variable * const *var; + + if ( index >= array_count(&scope->variable_index) ) + return NULL; + + var = array_idx(&scope->variable_index, index); + + return *var; +} + /* * Variable storage */ diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.h b/src/lib-sieve/plugins/variables/ext-variables-common.h index 935558b0287b8e1674e437b84ec9417a6ce9a7d8..ea7e6c5e75cbc417c4e741d4dbe69bf3ebf2ad44 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.h +++ b/src/lib-sieve/plugins/variables/ext-variables-common.h @@ -13,7 +13,7 @@ * Extension */ -extern struct sieve_extension variables_extension; +extern const struct sieve_extension variables_extension; /* * Commands diff --git a/src/lib-sieve/plugins/variables/ext-variables-dump.c b/src/lib-sieve/plugins/variables/ext-variables-dump.c index 27305e6c4e927945139e9759df5f8876318f058b..8c5cf9427876c55a18d0e355aa564193336be0b3 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-dump.c +++ b/src/lib-sieve/plugins/variables/ext-variables-dump.c @@ -38,6 +38,7 @@ bool ext_variables_code_dump if ( !sieve_binary_read_offset(denv->sbin, address, &end_offset) ) return FALSE; + /* FIXME: MEMLEAK!! Scope is never unreferenced */ main_scope = sieve_variable_scope_create(NULL); sieve_code_dumpf(denv, "SCOPE [%u] (end: %08x)", @@ -54,10 +55,13 @@ bool ext_variables_code_dump } sieve_code_dumpf(denv, "%3d: '%s'", i, str_c(identifier)); + + (void) sieve_variable_scope_declare(main_scope, str_c(identifier)); } /* Create dumper context */ - dctx = p_new(sieve_code_dumper_pool(dumper), struct ext_variables_dump_context, 1); + dctx = p_new(sieve_code_dumper_pool(dumper), + struct ext_variables_dump_context, 1); dctx->main_scope = main_scope; sieve_dump_extension_set_context(dumper, &variables_extension, dctx); @@ -65,4 +69,24 @@ bool ext_variables_code_dump return TRUE; } +/* + * Variable identifier dump + */ + +const char *ext_variables_dump_get_identifier +(const struct sieve_dumptime_env *denv, const struct sieve_extension *ext, + unsigned int index) +{ + struct sieve_code_dumper *dumper = denv->cdumper; + struct ext_variables_dump_context *dctx = sieve_dump_extension_get_context + (dumper, &variables_extension); + struct sieve_variable *var; + + if ( ext != NULL ) + return NULL; + + var = sieve_variable_scope_get_indexed(dctx->main_scope, index); + + return var->identifier; +} diff --git a/src/lib-sieve/plugins/variables/ext-variables-dump.h b/src/lib-sieve/plugins/variables/ext-variables-dump.h index 3533deb1969956ed09b77c17f5d43d47464dcbf4..e5fe6c27db4bfe1af0a3f3a0ce3dc852ec6ba398 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-dump.h +++ b/src/lib-sieve/plugins/variables/ext-variables-dump.h @@ -13,5 +13,12 @@ bool ext_variables_code_dump (const struct sieve_dumptime_env *denv, sieve_size_t *address); +/* + * Variable identifier dump + */ + +const char *ext_variables_dump_get_identifier +(const struct sieve_dumptime_env *denv, const struct sieve_extension *ext, + unsigned int index); #endif /* __EXT_VARIABLES_DUMP_H */ diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.c b/src/lib-sieve/plugins/variables/ext-variables-operands.c index 7b303999fed62e627dce32b2a693fd50c62bcc26..109d2bbf083afe4ba7f7734b2566603cfb98b79e 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-operands.c +++ b/src/lib-sieve/plugins/variables/ext-variables-operands.c @@ -21,6 +21,7 @@ #include "ext-variables-common.h" #include "ext-variables-name.h" +#include "ext-variables-dump.h" /* * Variable operand @@ -68,6 +69,7 @@ static bool opr_variable_dump unsigned int index = 0; const struct sieve_extension *ext; unsigned int code = 1; /* Initially set to offset value */ + const char *identifier; if ( !sieve_binary_read_extension(denv->sbin, address, &code, &ext) ) return FALSE; @@ -75,18 +77,23 @@ static bool opr_variable_dump if ( !sieve_binary_read_unsigned(denv->sbin, address, &index) ) return FALSE; - if ( ext == NULL ) { + identifier = ext_variables_dump_get_identifier(denv, ext, index); + identifier = identifier == NULL ? "??" : identifier; + + if ( ext == NULL ) { if ( field_name != NULL ) - sieve_code_dumpf(denv, "%s: VAR %ld", field_name, (long) index); + sieve_code_dumpf(denv, "%s: VAR ${%s} (%ld)", + field_name, identifier, (long) index); else - sieve_code_dumpf(denv, "VAR %ld", (long) index); + sieve_code_dumpf(denv, "VAR ${%s} (%ld)", + identifier, (long) index); } else { if ( field_name != NULL ) - sieve_code_dumpf(denv, "%s: VAR [%s] %ld", - field_name, ext->name, (long) index); + sieve_code_dumpf(denv, "%s: VAR [%s] ${%s} (%ld)", + field_name, ext->name, identifier, (long) index); else - sieve_code_dumpf(denv, "VAR [%s] %ld", - ext->name, (long) index); + sieve_code_dumpf(denv, "VAR [%s] ${%s} (%ld)", + ext->name, identifier, (long) index); } return TRUE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables.c b/src/lib-sieve/plugins/variables/ext-variables.c index 12b9bee610989ddb4ad77c817e96313b81a92531..4110cbd329cde0ae979864b9d3ec264ad7d2c259 100644 --- a/src/lib-sieve/plugins/variables/ext-variables.c +++ b/src/lib-sieve/plugins/variables/ext-variables.c @@ -63,7 +63,7 @@ static bool ext_variables_validator_load(struct sieve_validator *validator); static int ext_my_id; -struct sieve_extension variables_extension = { +const struct sieve_extension variables_extension = { "variables", &ext_my_id, ext_variables_load, diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h index b85b210568374758f7cdc5ba22e3934c6d586f61..7d6b067a53917824a95b4277085e5cc6c255f1c1 100644 --- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h +++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h @@ -43,6 +43,8 @@ struct sieve_variable *sieve_variable_scope_import (struct sieve_variable_scope *scope, struct sieve_variable *var); struct sieve_variable *sieve_variable_scope_get_variable (struct sieve_variable_scope *scope, const char *identifier, bool create); +struct sieve_variable *sieve_variable_scope_get_indexed + (struct sieve_variable_scope *scope, unsigned int index); /* Iteration over all declared variables */ diff --git a/src/lib-sieve/sieve-code-dumper.c b/src/lib-sieve/sieve-code-dumper.c index d6e375570756d9ec8e4098f8f63b0151d255fdf3..c3d3825f4d775a982fc77be76a53db17a6ea81f5 100644 --- a/src/lib-sieve/sieve-code-dumper.c +++ b/src/lib-sieve/sieve-code-dumper.c @@ -76,7 +76,7 @@ void sieve_dump_extension_set_context array_idx_set(&dumper->ext_contexts, (unsigned int) *ext->id, &context); } -const void *sieve_dump_extension_get_context +void *sieve_dump_extension_get_context (struct sieve_code_dumper *dumper, const struct sieve_extension *ext) { int ext_id = *ext->id; diff --git a/src/lib-sieve/sieve-code-dumper.h b/src/lib-sieve/sieve-code-dumper.h index d8cf50dab4d0bb5f117aea78d35040ba25c300f9..8906f9e9d6a4907b6cdcde10d43afd0ddf1ffabc 100644 --- a/src/lib-sieve/sieve-code-dumper.h +++ b/src/lib-sieve/sieve-code-dumper.h @@ -17,7 +17,7 @@ pool_t sieve_code_dumper_pool void sieve_dump_extension_set_context (struct sieve_code_dumper *dumper, const struct sieve_extension *ext, void *context); -const void *sieve_dump_extension_get_context +void *sieve_dump_extension_get_context (struct sieve_code_dumper *dumper, const struct sieve_extension *ext); /* Dump functions */