24
* Testsuite string argument
24
* Testsuite string argument
27
27
static bool arg_testsuite_string_validate
28
(struct sieve_validator *validator, struct sieve_ast_argument **arg,
28
(struct sieve_validator *validator, struct sieve_ast_argument **arg,
29
29
struct sieve_command *context);
31
const struct sieve_argument_def testsuite_string_argument = {
34
arg_testsuite_string_validate,
31
const struct sieve_argument_def testsuite_string_argument = {
34
arg_testsuite_string_validate,
36
36
sieve_arg_catenated_string_generate,
39
39
static bool arg_testsuite_string_validate
40
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
40
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
41
41
struct sieve_command *cmd)
43
enum { ST_NONE, ST_OPEN, ST_SUBSTITUTION, ST_PARAM, ST_CLOSE } state =
43
enum { ST_NONE, ST_OPEN, ST_SUBSTITUTION, ST_PARAM, ST_CLOSE } state =
45
45
pool_t pool = sieve_ast_pool((*arg)->ast);
46
46
struct sieve_arg_catenated_string *catstr = NULL;
109
109
/* Finished parsing param, expecting '}' */
112
112
struct sieve_ast_argument *strarg;
114
/* We now know that the substitution is valid */
114
/* We now know that the substitution is valid */
116
116
if ( catstr == NULL ) {
117
117
catstr = sieve_arg_catenated_string_create(*arg);
120
/* Add the substring that is before the substitution to the
120
/* Add the substring that is before the substitution to the
121
121
* variable-string AST.
123
123
if ( substart > strstart ) {
124
124
string_t *newstr = str_new(pool, substart - strstart);
125
str_append_n(newstr, strstart, substart - strstart);
125
str_append_n(newstr, strstart, substart - strstart);
127
127
strarg = sieve_ast_argument_string_create_raw
128
128
((*arg)->ast, newstr, (*arg)->source_line);
129
129
sieve_arg_catenated_string_add_element(catstr, strarg);
131
131
/* Give other substitution extensions a chance to do their work */
132
132
if ( !sieve_validator_argument_activate_super
133
133
(valdtr, cmd, strarg, FALSE) ) {
139
139
strarg = testsuite_substitution_argument_create
140
(valdtr, (*arg)->ast, (*arg)->source_line, str_c(subs_name),
140
(valdtr, (*arg)->ast, (*arg)->source_line, str_c(subs_name),
141
141
str_c(subs_param));
143
143
if ( strarg != NULL )
144
144
sieve_arg_catenated_string_add_element(catstr, strarg);
146
sieve_argument_validate_error(valdtr, *arg,
146
sieve_argument_validate_error(valdtr, *arg,
147
147
"unknown testsuite substitution type '%s'", str_c(subs_name));
150
150
strstart = p + 1;
151
151
substart = strstart;
156
/* Finished, reset for the next substitution */
156
/* Finished, reset for the next substitution */
162
162
/* Bail out early if substitution is invalid */
163
163
if ( !result ) return FALSE;
165
165
/* Check whether any substitutions were found */
166
166
if ( catstr == NULL ) {
167
167
/* No substitutions in this string, pass it on to any other substution
170
170
return sieve_validator_argument_activate_super(valdtr, cmd, *arg, TRUE);
173
/* Add the final substring that comes after the last substitution to the
173
/* Add the final substring that comes after the last substitution to the
174
174
* variable-string AST.
176
176
if ( strend > strstart ) {
177
177
struct sieve_ast_argument *strarg;
178
178
string_t *newstr = str_new(pool, strend - strstart);
179
str_append_n(newstr, strstart, strend - strstart);
179
str_append_n(newstr, strstart, strend - strstart);
181
181
strarg = sieve_ast_argument_string_create_raw
182
182
((*arg)->ast, newstr, (*arg)->source_line);
183
183
sieve_arg_catenated_string_add_element(catstr, strarg);
185
/* Give other substitution extensions a chance to do their work */
185
/* Give other substitution extensions a chance to do their work */
186
186
if ( !sieve_validator_argument_activate_super
187
187
(valdtr, cmd, strarg, FALSE) )