From 13bca4d57ff47c1e4d028aeb680b7d68e9b22341 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Sat, 2 Jan 2010 19:06:03 +0100 Subject: [PATCH] Adjusted tag parameter validation API. --- src/lib-sieve/plugins/body/tst-body.c | 5 +---- src/lib-sieve/plugins/date/tst-date.c | 2 +- src/lib-sieve/plugins/enotify/cmd-notify.c | 6 +++-- src/lib-sieve/plugins/imap4flags/tag-flags.c | 2 +- src/lib-sieve/plugins/notify/cmd-notify.c | 6 +++-- src/lib-sieve/plugins/vacation/cmd-vacation.c | 6 ++--- src/lib-sieve/sieve-validator.c | 22 +++++++++++++------ src/lib-sieve/sieve-validator.h | 3 ++- src/testsuite/cmd-test-message.c | 2 +- src/testsuite/tst-test-error.c | 2 +- src/testsuite/tst-test-result.c | 2 +- 11 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/lib-sieve/plugins/body/tst-body.c b/src/lib-sieve/plugins/body/tst-body.c index 8ef566087..3a9e058c6 100644 --- a/src/lib-sieve/plugins/body/tst-body.c +++ b/src/lib-sieve/plugins/body/tst-body.c @@ -154,13 +154,10 @@ static bool tag_body_transform_validate * :content <content-types: string-list> */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_STRING_LIST) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { return FALSE; } - if ( !sieve_validator_argument_activate(valdtr, cmd, *arg, FALSE) ) - return FALSE; - /* Assign tag parameters */ tag->parameters = *arg; *arg = sieve_ast_arguments_detach(*arg,1); diff --git a/src/lib-sieve/plugins/date/tst-date.c b/src/lib-sieve/plugins/date/tst-date.c index c2bbd65cc..30d519034 100644 --- a/src/lib-sieve/plugins/date/tst-date.c +++ b/src/lib-sieve/plugins/date/tst-date.c @@ -173,7 +173,7 @@ static bool tag_zone_validate * :zone <time-zone: string> */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_STRING) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) { return FALSE; } diff --git a/src/lib-sieve/plugins/enotify/cmd-notify.c b/src/lib-sieve/plugins/enotify/cmd-notify.c index e0f9afcaa..5b325f822 100644 --- a/src/lib-sieve/plugins/enotify/cmd-notify.c +++ b/src/lib-sieve/plugins/enotify/cmd-notify.c @@ -180,7 +180,8 @@ static bool cmd_notify_validate_string_tag * :from <string> * :message <string> */ - if ( !sieve_validate_tag_parameter(valdtr, cmd, tag, *arg, SAAT_STRING) ) + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) return FALSE; if ( sieve_argument_is(tag, notify_from_tag) ) { @@ -213,7 +214,8 @@ static bool cmd_notify_validate_stringlist_tag /* Check syntax: * :options string-list */ - if ( !sieve_validate_tag_parameter(valdtr, cmd, tag, *arg, SAAT_STRING_LIST) ) + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) return FALSE; /* Assign context */ diff --git a/src/lib-sieve/plugins/imap4flags/tag-flags.c b/src/lib-sieve/plugins/imap4flags/tag-flags.c index 837baaa45..026faf0b6 100644 --- a/src/lib-sieve/plugins/imap4flags/tag-flags.c +++ b/src/lib-sieve/plugins/imap4flags/tag-flags.c @@ -128,7 +128,7 @@ static bool tag_flags_validate * :flags <list-of-flags: string-list> */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_STRING_LIST) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { return FALSE; } diff --git a/src/lib-sieve/plugins/notify/cmd-notify.c b/src/lib-sieve/plugins/notify/cmd-notify.c index 5592cce3c..d7d31742f 100644 --- a/src/lib-sieve/plugins/notify/cmd-notify.c +++ b/src/lib-sieve/plugins/notify/cmd-notify.c @@ -192,7 +192,8 @@ static bool cmd_notify_validate_string_tag * :method <string> * :message <string> */ - if ( !sieve_validate_tag_parameter(valdtr, cmd, tag, *arg, SAAT_STRING) ) + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) return FALSE; if ( sieve_argument_is(tag, notify_method_tag) ) { @@ -231,7 +232,8 @@ static bool cmd_notify_validate_stringlist_tag /* Check syntax: * :options string-list */ - if ( !sieve_validate_tag_parameter(valdtr, cmd, tag, *arg, SAAT_STRING_LIST) ) + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) return FALSE; /* Assign context */ diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c index b56188446..255f4173d 100644 --- a/src/lib-sieve/plugins/vacation/cmd-vacation.c +++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c @@ -242,7 +242,7 @@ static bool cmd_vacation_validate_number_tag * :days number */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_NUMBER) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_NUMBER, FALSE) ) { return FALSE; } @@ -274,7 +274,7 @@ static bool cmd_vacation_validate_string_tag * :handle string */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_STRING) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) { return FALSE; } @@ -332,7 +332,7 @@ static bool cmd_vacation_validate_stringlist_tag * :addresses string-list */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_STRING_LIST) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { return FALSE; } diff --git a/src/lib-sieve/sieve-validator.c b/src/lib-sieve/sieve-validator.c index e385ec118..642e34e1b 100644 --- a/src/lib-sieve/sieve-validator.c +++ b/src/lib-sieve/sieve-validator.c @@ -803,14 +803,18 @@ bool sieve_validate_positional_argument bool sieve_validate_tag_parameter (struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *tag, struct sieve_ast_argument *param, - enum sieve_ast_argument_type req_type) + const char *arg_name, unsigned int arg_pos, + enum sieve_ast_argument_type req_type, bool constant) { if ( param == NULL ) { + const char *position = ( arg_pos == 0 ? "" : + t_strdup_printf(" %d (%s)", arg_pos, arg_name) ); + sieve_argument_validate_error(valdtr, tag, - "the :%s tag for the %s %s requires %s as parameter, " - "but no more arguments were found", sieve_ast_argument_tag(tag), + "the :%s tag for the %s %s requires %s as parameter %s, " + "but no parameters were found", sieve_ast_argument_tag(tag), sieve_command_identifier(cmd), sieve_command_type_name(cmd), - sieve_ast_argument_type_name(req_type)); + sieve_ast_argument_type_name(req_type), position); return FALSE; } @@ -818,15 +822,19 @@ bool sieve_validate_tag_parameter (sieve_ast_argument_type(param) != SAAT_STRING || req_type != SAAT_STRING_LIST) ) { + const char *position = ( arg_pos == 0 ? "" : + t_strdup_printf(" %d (%s)", arg_pos, arg_name) ); + sieve_argument_validate_error(valdtr, param, - "the :%s tag for the %s %s requires %s as parameter, " + "the :%s tag for the %s %s requires %s as parameter%s, " "but %s was found", sieve_ast_argument_tag(tag), sieve_command_identifier(cmd), sieve_command_type_name(cmd), - sieve_ast_argument_type_name(req_type), sieve_ast_argument_name(param)); + sieve_ast_argument_type_name(req_type), position, + sieve_ast_argument_name(param)); return FALSE; } - if ( !sieve_validator_argument_activate(valdtr, cmd, param, FALSE) ) + if ( !sieve_validator_argument_activate(valdtr, cmd, param, constant) ) return FALSE; param->argument->id_code = tag->argument->id_code; diff --git a/src/lib-sieve/sieve-validator.h b/src/lib-sieve/sieve-validator.h index 5e34b2525..a1cf1fc8a 100644 --- a/src/lib-sieve/sieve-validator.h +++ b/src/lib-sieve/sieve-validator.h @@ -114,7 +114,8 @@ bool sieve_validator_argument_activate bool sieve_validate_tag_parameter (struct sieve_validator *valdtr, struct sieve_command *cmd, struct sieve_ast_argument *tag, struct sieve_ast_argument *param, - enum sieve_ast_argument_type req_type); + const char *arg_name, unsigned int arg_pos, + enum sieve_ast_argument_type req_type, bool constant); /* * Extension support diff --git a/src/testsuite/cmd-test-message.c b/src/testsuite/cmd-test-message.c index 2cd19a899..c1dbbcc86 100644 --- a/src/testsuite/cmd-test-message.c +++ b/src/testsuite/cmd-test-message.c @@ -193,7 +193,7 @@ static bool cmd_test_message_validate_folder_tag * :folder string */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_STRING) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) { return FALSE; } diff --git a/src/testsuite/tst-test-error.c b/src/testsuite/tst-test-error.c index c393b622b..f5ae3b3c7 100644 --- a/src/testsuite/tst-test-error.c +++ b/src/testsuite/tst-test-error.c @@ -102,7 +102,7 @@ static bool tst_test_error_validate_index_tag * :index number */ if ( !sieve_validate_tag_parameter - (valdtr, cmd, tag, *arg, SAAT_NUMBER) ) { + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_NUMBER, FALSE) ) { return FALSE; } diff --git a/src/testsuite/tst-test-result.c b/src/testsuite/tst-test-result.c index 0d4eededc..d09e87df1 100644 --- a/src/testsuite/tst-test-result.c +++ b/src/testsuite/tst-test-result.c @@ -107,7 +107,7 @@ static bool tst_test_result_validate_index_tag * :index number */ if ( !sieve_validate_tag_parameter - (validator, cmd, tag, *arg, SAAT_NUMBER) ) { + (validator, cmd, tag, *arg, NULL, 0, SAAT_NUMBER, FALSE) ) { return FALSE; } -- GitLab