From 4e05a6383e6f3a84e265bcda03cb2a71c6941919 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan.bosch@open-xchange.com> Date: Wed, 21 Aug 2024 20:34:56 +0200 Subject: [PATCH] lib-sieve: variables extension: Rename settings to better match Dovecot conventions Also rename associated variables and functions. --- .../plugins/enotify/vmodf-encodeurl.c | 12 ++--- .../plugins/include/ext-include-variables.c | 4 +- .../variables/ext-variables-arguments.c | 2 +- .../plugins/variables/ext-variables-common.c | 52 +++++++++---------- .../plugins/variables/ext-variables-limits.h | 4 +- .../variables/ext-variables-modifiers.c | 22 ++++---- .../variables/ext-variables-operands.c | 4 +- .../variables/ext-variables-settings.c | 21 ++++---- .../variables/ext-variables-settings.h | 4 +- .../plugins/variables/sieve-ext-variables.h | 6 +-- tests/extensions/enotify/encodeurl.svtest | 4 +- 11 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c b/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c index 801f882a2..0c97771c7 100644 --- a/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c +++ b/src/lib-sieve/plugins/enotify/vmodf-encodeurl.c @@ -68,8 +68,8 @@ static bool mod_encodeurl_modify(const struct sieve_variables_modifier *modf, string_t *in, string_t **result) { - size_t max_var_size = - sieve_variables_get_max_variable_size(modf->var_ext); + size_t max_val_size = + sieve_variables_get_max_value_size(modf->var_ext); const unsigned char *p, *poff, *pend; size_t new_size; @@ -80,8 +80,8 @@ mod_encodeurl_modify(const struct sieve_variables_modifier *modf, /* allocate new string */ new_size = str_len(in) + 32; - if (new_size > max_var_size) - new_size = max_var_size; + if (new_size > max_val_size) + new_size = max_val_size; *result = t_str_new(new_size + 1); /* escape string */ @@ -95,7 +95,7 @@ mod_encodeurl_modify(const struct sieve_variables_modifier *modf, str_append_data(*result, poff, p - poff); poff = p; - if (str_len(*result) + 3 * n > max_var_size) + if (str_len(*result) + 3 * n > max_val_size) break; str_printfa(*result, "%%%02X", *p); @@ -106,7 +106,7 @@ mod_encodeurl_modify(const struct sieve_variables_modifier *modf, } poff++; - } else if ((str_len(*result) + (p - poff) + 1) > max_var_size) { + } else if ((str_len(*result) + (p - poff) + 1) > max_val_size) { break; } p++; diff --git a/src/lib-sieve/plugins/include/ext-include-variables.c b/src/lib-sieve/plugins/include/ext-include-variables.c index f873205c8..8b2c04057 100644 --- a/src/lib-sieve/plugins/include/ext-include-variables.c +++ b/src/lib-sieve/plugins/include/ext-include-variables.c @@ -58,7 +58,7 @@ ext_include_variable_import_global(struct sieve_validator *valdtr, valdtr, cmd, "declaration of new global variable '%s' exceeds the limit " "(max variables: %u)", variable, - sieve_variables_get_max_scope_size(extctx->var_ext)); + sieve_variables_get_max_scope_count(extctx->var_ext)); return NULL; } @@ -225,7 +225,7 @@ vnspc_global_variables_validate(struct sieve_validator *valdtr, valdtr, arg, "(implicit) declaration of new global variable '%s' " "exceeds the limit (max variables: %u)", variable, - sieve_variables_get_max_scope_size(extctx->var_ext)); + sieve_variables_get_max_scope_count(extctx->var_ext)); return FALSE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-arguments.c b/src/lib-sieve/plugins/variables/ext-variables-arguments.c index 6b12e9358..2a77d7c0b 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-arguments.c +++ b/src/lib-sieve/plugins/variables/ext-variables-arguments.c @@ -53,7 +53,7 @@ ext_variables_variable_argument_activate(const struct sieve_extension *var_ext, valdtr, arg, "(implicit) declaration of new variable '%s' exceeds the limit " "(max variables: %u)", variable, - sieve_variables_get_max_scope_size(var_ext)); + sieve_variables_get_max_scope_count(var_ext)); return FALSE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c index a33efc9d3..65d34edf8 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.c +++ b/src/lib-sieve/plugins/variables/ext-variables-common.c @@ -30,21 +30,21 @@ */ unsigned int -sieve_variables_get_max_scope_size(const struct sieve_extension *var_ext) +sieve_variables_get_max_scope_count(const struct sieve_extension *var_ext) { const struct ext_variables_context *extctx = ext_variables_get_context(var_ext); - return extctx->set->max_scope_size; + return extctx->set->max_scope_count; } -size_t sieve_variables_get_max_variable_size( +size_t sieve_variables_get_max_value_size( const struct sieve_extension *var_ext) { const struct ext_variables_context *extctx = ext_variables_get_context(var_ext); - return extctx->set->max_variable_size; + return extctx->set->max_value_size; } /* @@ -111,7 +111,7 @@ struct sieve_variable_scope { struct sieve_variable_scope_binary { struct sieve_variable_scope *scope; - unsigned int size; + unsigned int count; struct sieve_binary_block *sblock; sieve_size_t address; }; @@ -175,15 +175,15 @@ struct sieve_variable * sieve_variable_scope_declare(struct sieve_variable_scope *scope, const char *identifier) { - unsigned int max_scope_size; + unsigned int max_scope_count; struct sieve_variable *var; var = hash_table_lookup(scope->variables, identifier); if (var != NULL) return var; - max_scope_size = sieve_variables_get_max_scope_size(scope->var_ext); - if (array_count(&scope->variable_index) >= max_scope_size) { + max_scope_count = sieve_variables_get_max_scope_count(scope->var_ext); + if (array_count(&scope->variable_index) >= max_scope_count) { if (scope->error_var == NULL) { var = p_new(scope->pool, struct sieve_variable, 1); var->identifier = "@ERROR@"; @@ -377,25 +377,25 @@ sieve_variable_scope_binary_read(struct sieve_instance *svinst, { struct sieve_variable_scope *scope; struct sieve_variable_scope_binary *scpbin; - unsigned int scope_size, max_scope_size; + unsigned int scope_count, max_scope_count; const char *ext_name = (ext == NULL ? "variables" : sieve_extension_name(ext)); sieve_size_t pc; sieve_offset_t end_offset; /* Read scope size */ - if (!sieve_binary_read_unsigned(sblock, address, &scope_size)) { + if (!sieve_binary_read_unsigned(sblock, address, &scope_count)) { e_error(svinst->event, "%s: " - "variable scope: failed to read size", ext_name); + "variable scope: failed to read count", ext_name); return NULL; } /* Check size limit */ - max_scope_size = sieve_variables_get_max_scope_size(var_ext); - if (scope_size > max_scope_size) { + max_scope_count = sieve_variables_get_max_scope_count(var_ext); + if (scope_count > max_scope_count) { e_error(svinst->event, "%s: " - "variable scope: size exceeds the limit (%u > %u)", - ext_name, scope_size, max_scope_size); + "variable scope: count exceeds the limit (%u > %u)", + ext_name, scope_count, max_scope_count); return NULL; } @@ -411,7 +411,7 @@ sieve_variable_scope_binary_read(struct sieve_instance *svinst, scope = sieve_variable_scope_create(svinst, var_ext, ext); scpbin = sieve_variable_scope_binary_create(scope); - scpbin->size = scope_size; + scpbin->count = scope_count; scpbin->sblock = sblock; scpbin->address = *address; @@ -433,7 +433,7 @@ sieve_variable_scope_binary_get(struct sieve_variable_scope_binary *scpbin) sieve_size_t *address = &scpbin->address; /* Read scope itself */ - for (i = 0; i < scpbin->size; i++) { + for (i = 0; i < scpbin->count; i++) { struct sieve_variable *var; string_t *identifier; @@ -459,11 +459,11 @@ sieve_variable_scope_binary_get(struct sieve_variable_scope_binary *scpbin) } unsigned int -sieve_variable_scope_binary_get_size( +sieve_variable_scope_binary_get_count( struct sieve_variable_scope_binary *scpbin) { if (scpbin->sblock != NULL) - return scpbin->size; + return scpbin->count; return array_count(&scpbin->scope->variable_index); } @@ -477,7 +477,7 @@ struct sieve_variable_storage { const struct sieve_extension *var_ext; struct sieve_variable_scope *scope; struct sieve_variable_scope_binary *scope_bin; - unsigned int max_size; + unsigned int max_count; ARRAY(string_t *) var_values; }; @@ -494,7 +494,7 @@ sieve_variable_storage_create(const struct sieve_extension *var_ext, storage->scope_bin = scpbin; storage->scope = NULL; - storage->max_size = sieve_variable_scope_binary_get_size(scpbin); + storage->max_count = sieve_variable_scope_binary_get_count(scpbin); p_array_init(&storage->var_values, pool, 4); @@ -508,7 +508,7 @@ sieve_variable_valid(struct sieve_variable_storage *storage, if (storage->scope_bin == NULL) return TRUE; - return (index < storage->max_size); + return (index < storage->max_count); } bool sieve_variable_get_identifier(struct sieve_variable_storage *storage, @@ -605,8 +605,8 @@ bool sieve_variable_assign(struct sieve_variable_storage *storage, str_append_str(varval, value); /* Just a precaution, caller should prevent this in the first place */ - if (str_len(varval) > extctx->set->max_variable_size) - str_truncate_utf8(varval, extctx->set->max_variable_size); + if (str_len(varval) > extctx->set->max_value_size) + str_truncate_utf8(varval, extctx->set->max_value_size); return TRUE; } @@ -625,8 +625,8 @@ bool sieve_variable_assign_cstr(struct sieve_variable_storage *storage, str_append(varval, value); /* Just a precaution, caller should prevent this in the first place */ - if (str_len(varval) > extctx->set->max_variable_size) - str_truncate_utf8(varval, extctx->set->max_variable_size); + if (str_len(varval) > extctx->set->max_value_size) + str_truncate_utf8(varval, extctx->set->max_value_size); return TRUE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-limits.h b/src/lib-sieve/plugins/variables/ext-variables-limits.h index c525c176e..4153d393b 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-limits.h +++ b/src/lib-sieve/plugins/variables/ext-variables-limits.h @@ -21,8 +21,8 @@ * as a syntax error, which SHOULD be discovered at compile-time. */ -#define EXT_VARIABLES_REQUIRED_MAX_SCOPE_SIZE 128 -#define EXT_VARIABLES_REQUIRED_MAX_VARIABLE_SIZE 4000 +#define EXT_VARIABLES_REQUIRED_MAX_SCOPE_COUNT 128 +#define EXT_VARIABLES_REQUIRED_MAX_VALUE_SIZE 4000 #define EXT_VARIABLES_MAX_VARIABLE_NAME_LEN 64 #define EXT_VARIABLES_MAX_NAMESPACE_ELEMENTS 10 diff --git a/src/lib-sieve/plugins/variables/ext-variables-modifiers.c b/src/lib-sieve/plugins/variables/ext-variables-modifiers.c index b48c8ce9a..b470e1f77 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-modifiers.c +++ b/src/lib-sieve/plugins/variables/ext-variables-modifiers.c @@ -286,8 +286,8 @@ static bool mod_quotewildcard_modify(const struct sieve_variables_modifier *modf, string_t *in, string_t **result) { - size_t max_var_size = - sieve_variables_get_max_variable_size(modf->var_ext); + size_t max_val_size = + sieve_variables_get_max_value_size(modf->var_ext); const unsigned char *p, *poff, *pend; size_t new_size; @@ -299,8 +299,8 @@ mod_quotewildcard_modify(const struct sieve_variables_modifier *modf, /* Allocate new string */ new_size = str_len(in) + 16; - if (new_size > max_var_size) - new_size = max_var_size; + if (new_size > max_val_size) + new_size = max_val_size; *result = t_str_new(new_size + 1); /* Escape string */ @@ -314,11 +314,11 @@ mod_quotewildcard_modify(const struct sieve_variables_modifier *modf, str_append_data(*result, poff, p - poff); poff = p; - if (str_len(*result) + 2 > max_var_size) + if (str_len(*result) + 2 > max_val_size) break; str_append_c(*result, '\\'); - } else if ((str_len(*result) + (p - poff) + n) > max_var_size) { + } else if ((str_len(*result) + (p - poff) + n) > max_val_size) { break; } if (p + n > pend) { @@ -545,13 +545,13 @@ int sieve_variables_modifiers_apply( unsigned int i, modf_count; /* Hold value within limits */ - if (str_len(*value) > extctx->set->max_variable_size) { + if (str_len(*value) > extctx->set->max_value_size) { /* assume variable originates from code, so copy it first */ string_t *new_value = - t_str_new(extctx->set->max_variable_size+3); + t_str_new(extctx->set->max_value_size+3); str_append_str(new_value, *value); *value = new_value; - str_truncate_utf8(*value, extctx->set->max_variable_size); + str_truncate_utf8(*value, extctx->set->max_value_size); } if (!array_is_created(modifiers)) @@ -581,9 +581,9 @@ int sieve_variables_modifiers_apply( str_sanitize(str_c(new_value), 256)); /* Hold value within limits */ - if (str_len(*value) > extctx->set->max_variable_size) { + if (str_len(*value) > extctx->set->max_value_size) { str_truncate_utf8( - *value, extctx->set->max_variable_size); + *value, extctx->set->max_value_size); } } } diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.c b/src/lib-sieve/plugins/variables/ext-variables-operands.c index 1f2a46b27..67c5b8df6 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-operands.c +++ b/src/lib-sieve/plugins/variables/ext-variables-operands.c @@ -279,9 +279,9 @@ opr_match_value_read(const struct sieve_runtime_env *renv, if (*str_r == NULL) *str_r = t_str_new(0); else if (str_len(*str_r) > - extctx->set->max_variable_size) { + extctx->set->max_value_size) { str_truncate_utf8( - *str_r, extctx->set->max_variable_size); + *str_r, extctx->set->max_value_size); } } return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/plugins/variables/ext-variables-settings.c b/src/lib-sieve/plugins/variables/ext-variables-settings.c index c2615b357..1f5fe2818 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-settings.c +++ b/src/lib-sieve/plugins/variables/ext-variables-settings.c @@ -19,15 +19,15 @@ ext_variables_settings_check(void *_set, pool_t pool ATTR_UNUSED, struct ext_variables_settings) static const struct setting_define ext_variables_setting_defines[] = { - DEF(UINT, max_scope_size), - DEF(SIZE, max_variable_size), + DEF(UINT, max_scope_count), + DEF(SIZE, max_value_size), SETTING_DEFINE_LIST_END, }; static const struct ext_variables_settings ext_variables_default_settings = { - .max_scope_size = 255, - .max_variable_size = (4 * 1024), + .max_scope_count = 255, + .max_value_size = (4 * 1024), }; const struct setting_parser_info ext_variables_setting_parser_info = { @@ -50,21 +50,20 @@ ext_variables_settings_check(void *_set, pool_t pool ATTR_UNUSED, { struct ext_variables_settings *set = _set; - if (set->max_scope_size < EXT_VARIABLES_REQUIRED_MAX_SCOPE_SIZE) { + if (set->max_scope_count < EXT_VARIABLES_REQUIRED_MAX_SCOPE_COUNT) { *error_r = t_strdup_printf( - "Setting sieve_variables_max_scope_size " + "Setting sieve_variables_max_scope_count " "is lower than required by standards " - "(>= %llu items)", - (unsigned long long) - EXT_VARIABLES_REQUIRED_MAX_SCOPE_SIZE); + "(>= %u items)", + EXT_VARIABLES_REQUIRED_MAX_SCOPE_COUNT); return FALSE; } - if (set->max_variable_size < EXT_VARIABLES_REQUIRED_MAX_VARIABLE_SIZE) { + if (set->max_value_size < EXT_VARIABLES_REQUIRED_MAX_VALUE_SIZE) { *error_r = t_strdup_printf( "Setting sieve_variables_max_variable_size " "is lower than required by standards " "(>= %zu bytes)", - (size_t)EXT_VARIABLES_REQUIRED_MAX_VARIABLE_SIZE); + (size_t)EXT_VARIABLES_REQUIRED_MAX_VALUE_SIZE); return FALSE; } diff --git a/src/lib-sieve/plugins/variables/ext-variables-settings.h b/src/lib-sieve/plugins/variables/ext-variables-settings.h index 4ba9eae9f..42510c52e 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-settings.h +++ b/src/lib-sieve/plugins/variables/ext-variables-settings.h @@ -5,9 +5,9 @@ struct ext_variables_settings { pool_t pool; /* Maximum number of variables (in a scope) */ - unsigned int max_scope_size; + unsigned int max_scope_count; /* Maximum size of variable value */ - size_t max_variable_size; + size_t max_value_size; }; extern const struct setting_parser_info ext_variables_setting_parser_info; diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h index 4f9fa1df3..b2f12b4fc 100644 --- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h +++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h @@ -16,8 +16,8 @@ */ unsigned int -sieve_variables_get_max_scope_size(const struct sieve_extension *var_ext); -size_t sieve_variables_get_max_variable_size( +sieve_variables_get_max_scope_count(const struct sieve_extension *var_ext); +size_t sieve_variables_get_max_value_size( const struct sieve_extension *var_ext); /* @@ -110,7 +110,7 @@ sieve_variable_scope_binary_read(struct sieve_instance *svinst, struct sieve_variable_scope * sieve_variable_scope_binary_get(struct sieve_variable_scope_binary *scpbin); unsigned int -sieve_variable_scope_binary_get_size( +sieve_variable_scope_binary_get_count( struct sieve_variable_scope_binary *scpbin); /* diff --git a/tests/extensions/enotify/encodeurl.svtest b/tests/extensions/enotify/encodeurl.svtest index d334dd366..3c3c0980b 100644 --- a/tests/extensions/enotify/encodeurl.svtest +++ b/tests/extensions/enotify/encodeurl.svtest @@ -19,7 +19,7 @@ test ":encodeurl simple" { * :encodeurl variable size limit */ -test_config_set "sieve_variables_max_variable_size" "4000"; +test_config_set "sieve_variables_max_value_size" "4000"; test_config_reload :extension "variables"; set "a" text: @@ -230,7 +230,7 @@ test ":encodeurl variable size limit" { * :encodeurl variable size limit UTF-8 */ -test_config_set "sieve_variables_max_variable_size" "4000"; +test_config_set "sieve_variables_max_value_size" "4000"; test_config_reload :extension "variables"; set "a" text: -- GitLab