dovecot-1.2-sieve: Adjusted tag parameter validation API.

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sun Jan 3 00:43:39 EET 2010


details:   http://hg.rename-it.nl/dovecot-1.2-sieve/rev/5bf4bbe87004
changeset: 1177:5bf4bbe87004
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Jan 02 19:06:03 2010 +0100
description:
Adjusted tag parameter validation API.

diffstat:

 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(-)

diffs (216 lines):

diff -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/plugins/body/tst-body.c
--- a/src/lib-sieve/plugins/body/tst-body.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/plugins/body/tst-body.c	Sat Jan 02 19:06:03 2010 +0100
@@ -154,13 +154,10 @@
 		 *   :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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/plugins/date/tst-date.c
--- a/src/lib-sieve/plugins/date/tst-date.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/plugins/date/tst-date.c	Sat Jan 02 19:06:03 2010 +0100
@@ -173,7 +173,7 @@
 		 *   :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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/plugins/enotify/cmd-notify.c
--- a/src/lib-sieve/plugins/enotify/cmd-notify.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/plugins/enotify/cmd-notify.c	Sat Jan 02 19:06:03 2010 +0100
@@ -180,7 +180,8 @@
 	 *   :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 @@
 	/* 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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/plugins/imap4flags/tag-flags.c
--- a/src/lib-sieve/plugins/imap4flags/tag-flags.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/plugins/imap4flags/tag-flags.c	Sat Jan 02 19:06:03 2010 +0100
@@ -128,7 +128,7 @@
 	 *   :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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/plugins/notify/cmd-notify.c
--- a/src/lib-sieve/plugins/notify/cmd-notify.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/plugins/notify/cmd-notify.c	Sat Jan 02 19:06:03 2010 +0100
@@ -191,7 +191,8 @@
 	 *   :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) ) {
@@ -230,7 +231,8 @@
 	/* 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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c	Sat Jan 02 19:06:03 2010 +0100
@@ -241,7 +241,7 @@
 	 *   :days number
 	 */
 	if ( !sieve_validate_tag_parameter
-		(valdtr, cmd, tag, *arg, SAAT_NUMBER) ) {
+		(valdtr, cmd, tag, *arg, NULL, 0, SAAT_NUMBER, FALSE) ) {
 		return FALSE;
 	}
 
@@ -273,7 +273,7 @@
 	 *   :handle string
 	 */
 	if ( !sieve_validate_tag_parameter
-		(valdtr, cmd, tag, *arg, SAAT_STRING) ) {
+		(valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) {
 		return FALSE;
 	}
 
@@ -331,7 +331,7 @@
 	 *   :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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/sieve-validator.c
--- a/src/lib-sieve/sieve-validator.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/sieve-validator.c	Sat Jan 02 19:06:03 2010 +0100
@@ -803,14 +803,18 @@
 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 @@
 		(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 -r 67975d95239b -r 5bf4bbe87004 src/lib-sieve/sieve-validator.h
--- a/src/lib-sieve/sieve-validator.h	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/lib-sieve/sieve-validator.h	Sat Jan 02 19:06:03 2010 +0100
@@ -114,7 +114,8 @@
 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 -r 67975d95239b -r 5bf4bbe87004 src/testsuite/cmd-test-message.c
--- a/src/testsuite/cmd-test-message.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/testsuite/cmd-test-message.c	Sat Jan 02 19:06:03 2010 +0100
@@ -193,7 +193,7 @@
 	 *   :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 -r 67975d95239b -r 5bf4bbe87004 src/testsuite/tst-test-error.c
--- a/src/testsuite/tst-test-error.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/testsuite/tst-test-error.c	Sat Jan 02 19:06:03 2010 +0100
@@ -102,7 +102,7 @@
 	 *   :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 -r 67975d95239b -r 5bf4bbe87004 src/testsuite/tst-test-result.c
--- a/src/testsuite/tst-test-result.c	Sat Jan 02 02:48:54 2010 +0100
+++ b/src/testsuite/tst-test-result.c	Sat Jan 02 19:06:03 2010 +0100
@@ -107,7 +107,7 @@
 	 *   :index number
 	 */
 	if ( !sieve_validate_tag_parameter
-		(validator, cmd, tag, *arg, SAAT_NUMBER) ) {
+		(validator, cmd, tag, *arg, NULL, 0, SAAT_NUMBER, FALSE) ) {
 		return FALSE;
 	}
 


More information about the dovecot-cvs mailing list