Skip to content
Snippets Groups Projects
Commit 6127ac70 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Variables: added identifier dump support for main scope.

parent cf568449
No related branches found
No related tags found
No related merge requests found
......@@ -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
*/
......
......@@ -13,7 +13,7 @@
* Extension
*/
extern struct sieve_extension variables_extension;
extern const struct sieve_extension variables_extension;
/*
* Commands
......
......@@ -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;
}
......@@ -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 */
......@@ -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;
}
......
......@@ -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,
......
......@@ -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 */
......
......@@ -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;
......
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.