From 6127ac70f8fbc1ff6b3167c212ff7995748c6af6 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Sun, 28 Sep 2008 21:24:25 +0200 Subject: [PATCH] Variables: added identifier dump support for main scope. --- .../plugins/variables/ext-variables-common.c | 23 ++++++++++++---- .../plugins/variables/ext-variables-common.h | 2 +- .../plugins/variables/ext-variables-dump.c | 26 ++++++++++++++++++- .../plugins/variables/ext-variables-dump.h | 7 +++++ .../variables/ext-variables-operands.c | 21 ++++++++++----- .../plugins/variables/ext-variables.c | 2 +- .../plugins/variables/sieve-ext-variables.h | 2 ++ src/lib-sieve/sieve-code-dumper.c | 2 +- src/lib-sieve/sieve-code-dumper.h | 2 +- 9 files changed, 70 insertions(+), 17 deletions(-) diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c index ffb52a1ae..faaa08dab 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 935558b02..ea7e6c5e7 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 27305e6c4..8c5cf9427 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 3533deb19..e5fe6c27d 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 7b303999f..109d2bbf0 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 12b9bee61..4110cbd32 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 b85b21056..7d6b067a5 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 d6e375570..c3d3825f4 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 d8cf50dab..8906f9e9d 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 */ -- GitLab