diff --git a/src/lib-sieve/plugins/variables/cmd-set.c b/src/lib-sieve/plugins/variables/cmd-set.c index 0d58a7ed3c00049de8d4916842b68fc2c5c611f3..ade0eb35844e4d0927d7fe4c2b33c3aa0845821e 100644 --- a/src/lib-sieve/plugins/variables/cmd-set.c +++ b/src/lib-sieve/plugins/variables/cmd-set.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include "lib.h" #include "str.h" #include "array.h" diff --git a/src/lib-sieve/plugins/variables/ext-variables-arguments.c b/src/lib-sieve/plugins/variables/ext-variables-arguments.c index d686b7de16918398d953ddd3c29562f252d7af7d..194382ec832dc8c5856185b245dcfce79eda9e7e 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-arguments.c +++ b/src/lib-sieve/plugins/variables/ext-variables-arguments.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include "lib.h" #include "str.h" #include "str-sanitize.h" @@ -92,15 +95,20 @@ static bool _sieve_variable_argument_activate varstr = str_c(variable); varend = PTR_OFFSET(varstr, str_len(variable)); nelements = ext_variable_name_parse(&vname, &varstr, varend); - + + /* Check whether name parsing succeeded */ if ( nelements < 0 || varstr != varend ) { + /* Parse failed */ sieve_command_validate_error(validator, cmd, "invalid variable name '%s'", str_sanitize(str_c(variable),80)); } else if ( nelements == 1 ) { + /* Normal (match) variable */ + const struct ext_variable_name *cur_element = array_idx(&vname, 0); if ( cur_element->num_variable < 0 ) { + /* Variable */ var = ext_variables_validator_get_variable (validator, str_c(cur_element->identifier), TRUE); @@ -114,6 +122,7 @@ static bool _sieve_variable_argument_activate result = TRUE; } } else { + /* Match value */ if ( !assignment ) { if ( cur_element->num_variable > SIEVE_VARIABLES_MAX_MATCH_INDEX ) { _ext_variables_match_index_error @@ -130,6 +139,8 @@ static bool _sieve_variable_argument_activate } } } else { + /* Namespace variable */ + const struct ext_variable_name *cur_element = array_idx(&vname, 0); @@ -288,6 +299,7 @@ static bool arg_variable_string_validate strstart = p; while ( result && p < strend ) { switch ( state ) { + /* Nothing found yet */ case ST_NONE: if ( *p == '$' ) { @@ -296,6 +308,7 @@ static bool arg_variable_string_validate } p++; break; + /* Got '$' */ case ST_OPEN: if ( *p == '{' ) { @@ -304,6 +317,7 @@ static bool arg_variable_string_validate } else state = ST_NONE; break; + /* Got '${' */ case ST_VARIABLE: nelements = ext_variable_name_parse(&substitution, &p, strend); @@ -314,6 +328,8 @@ static bool arg_variable_string_validate state = ST_CLOSE; break; + + /* Finished parsing name, expecting '}' */ case ST_CLOSE: if ( *p == '}' ) { struct sieve_ast_argument *strarg; @@ -405,8 +421,10 @@ static bool arg_variable_string_validate } } T_END; + /* Bail out early if substitution is invalid */ if ( !result ) return FALSE; + /* Check whether any substitutions were found */ if ( arglist == NULL ) { /* No substitutions in this string, pass it on to any other substution * extension. diff --git a/src/lib-sieve/plugins/variables/ext-variables-arguments.h b/src/lib-sieve/plugins/variables/ext-variables-arguments.h index beaf8ee65da6b8667d820458b5f9849a7d5d8672..ceb6692345700f4ff16dad2ba5223243808a4624 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-arguments.h +++ b/src/lib-sieve/plugins/variables/ext-variables-arguments.h @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #ifndef __EXT_VARIABLES_ARGUMENTS_H #define __EXT_VARIABLES_ARGUMENTS_H diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c index d1969ffee6a5fc7a9673d7e39ef87ad74a4b1bf3..cf8c04f934a68076633fedb7d00c88a99a2a379f 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.c +++ b/src/lib-sieve/plugins/variables/ext-variables-common.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include "lib.h" #include "hash.h" #include "str.h" @@ -21,27 +24,6 @@ #include "ext-variables-name.h" #include "ext-variables-modifiers.h" -/* - * Forward declarations - */ - -/* Core modifiers */ - -extern const struct ext_variables_set_modifier lower_modifier; -extern const struct ext_variables_set_modifier upper_modifier; -extern const struct ext_variables_set_modifier lowerfirst_modifier; -extern const struct ext_variables_set_modifier upperfirst_modifier; -extern const struct ext_variables_set_modifier quotewildcard_modifier; -extern const struct ext_variables_set_modifier length_modifier; - -const struct ext_variables_set_modifier *default_set_modifiers[] = { - &lower_modifier, &upper_modifier, &lowerfirst_modifier, &upperfirst_modifier, - "ewildcard_modifier, &length_modifier -}; - -const unsigned int default_set_modifiers_count = - N_ELEMENTS(default_set_modifiers); - /* * Variable scope */ @@ -209,8 +191,9 @@ struct sieve_variable * const *sieve_variable_scope_get_variables return array_get(&scope->variable_index, size_r); } - -/* Variable storage */ +/* + * Variable storage + */ struct sieve_variable_storage { pool_t pool; @@ -314,8 +297,6 @@ bool sieve_variable_assign return TRUE; } - - /* * AST Context */ @@ -401,7 +382,9 @@ bool sieve_ext_variables_is_active(struct sieve_validator *valdtr) return ( ext_variables_validator_context_get(valdtr) != NULL ); } -/* Interpreter context */ +/* + * Interpreter context + */ struct ext_variables_interpreter_context { struct sieve_variable_storage *local_storage; diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.h b/src/lib-sieve/plugins/variables/ext-variables-common.h index 13b6b8132589a45c9a72c84b82726c1f5c296634..6108abf5ec889fcc4655890686f067366ae7ade6 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-common.h +++ b/src/lib-sieve/plugins/variables/ext-variables-common.h @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #ifndef __EXT_VARIABLES_COMMON_H #define __EXT_VARIABLES_COMMON_H @@ -6,15 +9,36 @@ #include "sieve-ext-variables.h" -extern int ext_variables_my_id; +/* + * Extension + */ extern struct sieve_extension variables_extension; +/* + * Commands + */ + +extern const struct sieve_command cmd_set; +extern const struct sieve_command tst_string; + +/* + * Operations + */ + +extern const struct sieve_operation cmd_set_operation; +extern const struct sieve_operation tst_string_operation; + enum ext_variables_opcode { EXT_VARIABLES_OPERATION_SET, EXT_VARIABLES_OPERATION_STRING }; +/* + * Operands + */ + + enum ext_variables_operand { EXT_VARIABLES_OPERAND_VARIABLE, EXT_VARIABLES_OPERAND_MATCH_VALUE, @@ -22,7 +46,9 @@ enum ext_variables_operand { EXT_VARIABLES_OPERAND_MODIFIER }; -/* Context */ +/* + * Validator context + */ struct ext_variables_validator_context { struct sieve_validator_object_registry *modifiers; @@ -31,16 +57,26 @@ struct ext_variables_validator_context { }; void ext_variables_validator_initialize(struct sieve_validator *validator); -void ext_variables_interpreter_initialize(struct sieve_interpreter *interp); static inline struct ext_variables_validator_context * ext_variables_validator_context_get(struct sieve_validator *valdtr) { return (struct ext_variables_validator_context *) sieve_validator_extension_get_context(valdtr, &variables_extension); -} - -/* Variables */ +} + +struct sieve_variable *ext_variables_validator_get_variable + (struct sieve_validator *validator, const char *variable, bool declare); + +/* + * Interpreter context + */ + +void ext_variables_interpreter_initialize(struct sieve_interpreter *interp); + +/* + * Variable coding + */ void ext_variables_opr_variable_emit (struct sieve_binary *sbin, struct sieve_variable *var); @@ -56,11 +92,5 @@ void ext_variables_opr_variable_string_emit bool ext_variables_variable_assignment_activate (struct sieve_validator *validator, struct sieve_ast_argument *arg, struct sieve_command_context *cmd); - -struct sieve_variable *ext_variables_validator_get_variable -(struct sieve_validator *validator, const char *variable, bool declare); - -struct sieve_variable_storage *ext_variables_interpreter_get_storage - (struct sieve_interpreter *interp, const struct sieve_extension *ext); #endif /* __EXT_VARIABLES_COMMON_H */ diff --git a/src/lib-sieve/plugins/variables/ext-variables-limits.h b/src/lib-sieve/plugins/variables/ext-variables-limits.h index 5e9b227d4cc026e58cb18755a8b5f4ba94ebd9cb..abe07c8431fe1f3301a088823c31f2615ca4e664 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-limits.h +++ b/src/lib-sieve/plugins/variables/ext-variables-limits.h @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #ifndef __EXT_VARIABLES_LIMITS_H #define __EXT_VARIABLES_LIMITS_H diff --git a/src/lib-sieve/plugins/variables/ext-variables-modifiers.c b/src/lib-sieve/plugins/variables/ext-variables-modifiers.c index 72fd58c1c810cf4c9712f438c7c78f8256a5afd6..f56341aeaf1dbb6e77c5bf876648bcc4dd94fa18 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-modifiers.c +++ b/src/lib-sieve/plugins/variables/ext-variables-modifiers.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include "sieve-common.h" #include "sieve-commands.h" #include "sieve-code.h" @@ -19,6 +22,15 @@ extern const struct sieve_variables_modifier upperfirst_modifier; extern const struct sieve_variables_modifier quotewildcard_modifier; extern const struct sieve_variables_modifier length_modifier; +enum ext_variables_modifier_code { + EXT_VARIABLES_MODIFIER_LOWER, + EXT_VARIABLES_MODIFIER_UPPER, + EXT_VARIABLES_MODIFIER_LOWERFIRST, + EXT_VARIABLES_MODIFIER_UPPERFIRST, + EXT_VARIABLES_MODIFIER_QUOTEWILDCARD, + EXT_VARIABLES_MODIFIER_LENGTH +}; + const struct sieve_variables_modifier *ext_variables_core_modifiers[] = { &lower_modifier, &upper_modifier, @@ -32,7 +44,7 @@ const unsigned int ext_variables_core_modifiers_count = N_ELEMENTS(ext_variables_core_modifiers); /* - * Set modifier registry + * Modifier registry */ void sieve_variables_modifier_register @@ -69,7 +81,7 @@ void ext_variables_register_core_modifiers } /* - * Set modifier coding + * Modifier coding */ const struct sieve_operand_class ext_variables_modifier_operand_class = diff --git a/src/lib-sieve/plugins/variables/ext-variables-modifiers.h b/src/lib-sieve/plugins/variables/ext-variables-modifiers.h index c47db35b8855f016b70a194eb042df715210dbed..38f62f1feae78e80e9622d22feecb42720359ed8 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-modifiers.h +++ b/src/lib-sieve/plugins/variables/ext-variables-modifiers.h @@ -1,17 +1,15 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #ifndef __EXT_VARIABLES_MODIFIERS_H #define __EXT_VARIABLES_MODIFIERS_H #include "ext-variables-common.h" #include "sieve-ext-variables.h" -enum ext_variables_modifier_code { - EXT_VARIABLES_MODIFIER_LOWER, - EXT_VARIABLES_MODIFIER_UPPER, - EXT_VARIABLES_MODIFIER_LOWERFIRST, - EXT_VARIABLES_MODIFIER_UPPERFIRST, - EXT_VARIABLES_MODIFIER_QUOTEWILDCARD, - EXT_VARIABLES_MODIFIER_LENGTH -}; +/* + * Modifier registry + */ const struct sieve_variables_modifier *ext_variables_modifier_find (struct sieve_validator *validator, const char *identifier); diff --git a/src/lib-sieve/plugins/variables/ext-variables-name.c b/src/lib-sieve/plugins/variables/ext-variables-name.c index 2419913a1826d24eee7d14ff39eb8550c27d63b7..9a829c5b96a6ff7d2ec8120332e198f3bdfb7b67 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-name.c +++ b/src/lib-sieve/plugins/variables/ext-variables-name.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include "lib.h" #include "str.h" #include "array.h" diff --git a/src/lib-sieve/plugins/variables/ext-variables-name.h b/src/lib-sieve/plugins/variables/ext-variables-name.h index 7102b56cb973696bbe1a5f35a7a422222d58cf36..18e10ff83c23845fa725f1260ab78511f5027f92 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-name.h +++ b/src/lib-sieve/plugins/variables/ext-variables-name.h @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #ifndef __EXT_VARIABLES_NAME #define __EXT_VARIABLES_NAME @@ -32,13 +35,21 @@ #include "sieve-common.h" #include "ext-variables-common.h" - + +/* + * Types + */ + struct ext_variable_name { string_t *identifier; int num_variable; }; ARRAY_DEFINE_TYPE(ext_variable_name, struct ext_variable_name); + +/* + * Variable name parsing + */ int ext_variable_name_parse (ARRAY_TYPE(ext_variable_name) *vname, const char **str, const char *strend); diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.c b/src/lib-sieve/plugins/variables/ext-variables-operands.c index cc1d82bfa569d539b018a3e613a465247b8d7072..4799523b6a376d75b3ceb3977fe44507cf866473 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-operands.c +++ b/src/lib-sieve/plugins/variables/ext-variables-operands.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include "lib.h" #include "hash.h" #include "str.h" diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.h b/src/lib-sieve/plugins/variables/ext-variables-operands.h index 202866a0580d126f27af278413b60f9ce76f8225..aa3e5c1fbb21d158eba060f65b7a8be5e33b43d1 100644 --- a/src/lib-sieve/plugins/variables/ext-variables-operands.h +++ b/src/lib-sieve/plugins/variables/ext-variables-operands.h @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #ifndef __EXT_VARIABLES_OPERANDS_H #define __EXT_VARIABLES_OPERANDS_H diff --git a/src/lib-sieve/plugins/variables/ext-variables.c b/src/lib-sieve/plugins/variables/ext-variables.c index a4da1b35a35d1b2bbc531532aa6496723385cd5d..8a94a0364f951a2e0241bd02b8087c2632d89ea0 100644 --- a/src/lib-sieve/plugins/variables/ext-variables.c +++ b/src/lib-sieve/plugins/variables/ext-variables.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + /* Extension variables * ------------------- * @@ -30,28 +33,18 @@ #include "ext-variables-operands.h" #include "ext-variables-modifiers.h" -/* Forward declarations */ - -static bool ext_variables_load(int ext_id); -static bool ext_variables_validator_load(struct sieve_validator *validator); -static bool ext_variables_interpreter_load(struct sieve_interpreter *interp); - -/* Commands */ - -extern const struct sieve_command cmd_set; -extern const struct sieve_command tst_string; - -/* Operations */ - -extern const struct sieve_operation cmd_set_operation; -extern const struct sieve_operation tst_string_operation; +/* + * Operations + */ const struct sieve_operation *ext_variables_operations[] = { &cmd_set_operation, &tst_string_operation }; -/* Operands */ +/* + * Operands + */ const struct sieve_operand *ext_variables_operands[] = { &variable_operand, @@ -60,13 +53,19 @@ const struct sieve_operand *ext_variables_operands[] = { &modifier_operand }; -/* Extension definitions */ +/* + * Extension + */ -int ext_variables_my_id; +static bool ext_variables_load(int ext_id); +static bool ext_variables_validator_load(struct sieve_validator *validator); +static bool ext_variables_interpreter_load(struct sieve_interpreter *interp); + +static int ext_my_id; struct sieve_extension variables_extension = { "variables", - &ext_variables_my_id, + &ext_my_id, ext_variables_load, ext_variables_validator_load, NULL, @@ -78,12 +77,10 @@ struct sieve_extension variables_extension = { static bool ext_variables_load(int ext_id) { - ext_variables_my_id = ext_id; + ext_my_id = ext_id; return TRUE; } -/* Load extension into validator */ - static bool ext_variables_validator_load (struct sieve_validator *validator) { @@ -98,8 +95,6 @@ static bool ext_variables_validator_load return TRUE; } -/* Load extension into interpreter */ - static bool ext_variables_interpreter_load (struct sieve_interpreter *interp) { diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h index 8824c044be225246abe78cfed3bf5ac0805ad40c..f46f697defe165e80effa69068b178fdde4e3682 100644 --- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h +++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + /* * Public interface for other extensions to use */ @@ -64,7 +67,6 @@ unsigned int sieve_variable_scope_size struct sieve_variable * const *sieve_variable_scope_get_variables (struct sieve_variable_scope *scope, unsigned int *size_r); - /* * Variable storage */ @@ -102,13 +104,17 @@ void sieve_ext_variables_set_storage (struct sieve_interpreter *interp, struct sieve_variable_storage *storage, const struct sieve_extension *ext); -/* Variable arguments */ +/* + * Variable arguments + */ bool sieve_variable_argument_activate (struct sieve_validator *validator, struct sieve_command_context *cmd, struct sieve_ast_argument *arg, bool assignment); -/* Variable operands */ +/* + * Variable operands + */ extern const struct sieve_operand variable_operand; @@ -126,7 +132,9 @@ static inline bool sieve_operand_is_variable return ( operand != NULL && operand == &variable_operand ); } -/* Modifiers */ +/* + * Modifiers + */ struct sieve_variables_modifier { struct sieve_object object; @@ -140,6 +148,6 @@ struct sieve_variables_modifier { #define SIEVE_VARIABLES_DEFINE_MODIFIERS(OPS) SIEVE_EXT_DEFINE_OBJECTS(OPS) void sieve_variables_modifier_register -(struct sieve_validator *valdtr, const struct sieve_variables_modifier *smodf); + (struct sieve_validator *valdtr, const struct sieve_variables_modifier *smodf); #endif /* __SIEVE_EXT_VARIABLES_H */ diff --git a/src/lib-sieve/plugins/variables/tst-string.c b/src/lib-sieve/plugins/variables/tst-string.c index dfe4c8cb83521a5be4e80c299eeb3aad2e07bfa3..149c7c7527b409bdde25f47c9d7e96e0ee9ca73e 100644 --- a/src/lib-sieve/plugins/variables/tst-string.c +++ b/src/lib-sieve/plugins/variables/tst-string.c @@ -1,3 +1,6 @@ +/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file + */ + #include <stdio.h> #include "sieve-common.h"