From f7ae127f7bd0565ebcfcfd1322820d861a05b209 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sat, 16 Aug 2008 20:12:08 +0200
Subject: [PATCH] Finished code cleanup of the sieve library itself.

---
 src/lib-sieve/mcht-contains.c        |   3 +
 src/lib-sieve/mcht-is.c              |   4 +-
 src/lib-sieve/mcht-matches.c         |   3 +
 src/lib-sieve/sieve-result.c         |  38 +++--
 src/lib-sieve/sieve-result.h         |  39 ++++-
 src/lib-sieve/sieve-script-private.h |  31 ++--
 src/lib-sieve/sieve-script.c         |  81 ++++++----
 src/lib-sieve/sieve-script.h         |  31 +++-
 src/lib-sieve/sieve-types.h          |  23 ++-
 src/lib-sieve/sieve-validator.c      | 223 ++++++++++++++++++---------
 src/lib-sieve/sieve-validator.h      |  58 +++++--
 11 files changed, 374 insertions(+), 160 deletions(-)

diff --git a/src/lib-sieve/mcht-contains.c b/src/lib-sieve/mcht-contains.c
index dc4174d0d..cb47fbc8f 100644
--- a/src/lib-sieve/mcht-contains.c
+++ b/src/lib-sieve/mcht-contains.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file 
+ */
+
 /* Match-type ':contains' 
  */
 
diff --git a/src/lib-sieve/mcht-is.c b/src/lib-sieve/mcht-is.c
index dd64df659..dcfa35f90 100644
--- a/src/lib-sieve/mcht-is.c
+++ b/src/lib-sieve/mcht-is.c
@@ -1,5 +1,7 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file 
+ */
+ 
 /* Match-type ':is': 
- *
  */
 
 #include "lib.h"
diff --git a/src/lib-sieve/mcht-matches.c b/src/lib-sieve/mcht-matches.c
index fd565ada7..5c86673df 100644
--- a/src/lib-sieve/mcht-matches.c
+++ b/src/lib-sieve/mcht-matches.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file 
+ */
+ 
 /* Match-type ':matches' 
  */
 
diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c
index af948c21d..22bd23609 100644
--- a/src/lib-sieve/sieve-result.c
+++ b/src/lib-sieve/sieve-result.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+ 
 #include "lib.h"
 #include "mempool.h"
 #include "ostream.h"
@@ -16,7 +19,7 @@
 #include <stdio.h>
 
 /*
- *
+ * Types
  */
 
 struct sieve_result_action {
@@ -51,6 +54,10 @@ struct sieve_result_implicit_side_effects {
 	struct sieve_side_effects_list *seffects;
 };
 
+/*
+ * Result object
+ */
+
 struct sieve_result {
 	pool_t pool;
 	int refcount;
@@ -119,6 +126,10 @@ pool_t sieve_result_pool(struct sieve_result *result)
 	return result->pool;
 }
 
+/*
+ * Extension support
+ */
+
 void sieve_result_extension_set_context
 (struct sieve_result *result, const struct sieve_extension *ext, void *context)
 {
@@ -139,7 +150,9 @@ const void *sieve_result_extension_get_context
 	return *ctx;
 }
 
-/* Logging of result */
+/* 
+ * Error handling 
+ */
 
 static const char *_get_location(const struct sieve_action_exec_env *aenv)
 {
@@ -177,7 +190,9 @@ void sieve_result_log
 	va_end(args);
 }
 
-/* Result composition */
+/* 
+ * Result composition 
+ */
 
 void sieve_result_add_implicit_side_effect
 (struct sieve_result *result, const struct sieve_action *to_action, 
@@ -407,6 +422,10 @@ bool sieve_result_print
 	return TRUE;
 }
 
+/*
+ * Result execution
+ */
+
 bool sieve_result_implicit_keep
 	(struct sieve_result *result, bool rollback)
 {	
@@ -492,8 +511,8 @@ int sieve_result_execute
 	result->action_env.scriptenv = senv;
 	
 	/* 
-     * Transaction start 
-     */
+	 * Transaction start 
+   */
 	
 	rac = result->first_action;
 	while ( success && rac != NULL ) {
@@ -508,8 +527,8 @@ int sieve_result_execute
 	}
 	
 	/* 
-     * Transaction execute 
-     */
+	 * Transaction execute 
+	 */
 	
 	last_attempted = rac;
 	rac = result->first_action;
@@ -550,8 +569,8 @@ int sieve_result_execute
 	}
 	
 	/* 
-     * Transaction commit/rollback 
-     */
+	 * Transaction commit/rollback 
+	 */
 
 	commit_ok = success;
 	rac = result->first_action;
@@ -625,6 +644,7 @@ int sieve_result_execute
 /*
  * Side effects list
  */
+ 
 struct sieve_side_effects_list *sieve_side_effects_list_create
 	(struct sieve_result *result)
 {
diff --git a/src/lib-sieve/sieve-result.h b/src/lib-sieve/sieve-result.h
index a5efe2d03..9d3ad4aea 100644
--- a/src/lib-sieve/sieve-result.h
+++ b/src/lib-sieve/sieve-result.h
@@ -1,25 +1,42 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #ifndef __SIEVE_RESULT_H
 #define __SIEVE_RESULT_H
 
 #include "sieve-common.h"
 
-struct sieve_result;
-struct sieve_result_action;
+/*
+ * Types
+ */
+ 
 struct sieve_side_effects_list;
 
+/*
+ * Result object
+ */
+
+struct sieve_result;
+
 struct sieve_result *sieve_result_create
 	(struct sieve_error_handler *ehandler);
 void sieve_result_ref(struct sieve_result *result); 
 void sieve_result_unref(struct sieve_result **result); 
 pool_t sieve_result_pool(struct sieve_result *result);
 
+/*
+ * Extension support
+ */
+
 void sieve_result_extension_set_context
 	(struct sieve_result *result, const struct sieve_extension *ext,
 		void *context);
 const void *sieve_result_extension_get_context
 	(struct sieve_result *result, const struct sieve_extension *ext); 
 
-/* Printing */
+/* 
+ * Result printing 
+ */
 
 struct sieve_result_print_env {
 	struct sieve_result *result;
@@ -35,7 +52,9 @@ void sieve_result_seffect_printf
 
 bool sieve_result_print(struct sieve_result *result, struct ostream *stream);
 
-/* Error handling */
+/* 
+ * Error handling 
+ */
 
 void sieve_result_log
 	(const struct sieve_action_exec_env *aenv, const char *fmt, ...)
@@ -47,6 +66,10 @@ void sieve_result_error
 	(const struct sieve_action_exec_env *aenv, const char *fmt, ...)
 		ATTR_FORMAT(2, 3);
 
+/*
+ * Result composition
+ */
+ 
 void sieve_result_add_implicit_side_effect
 (struct sieve_result *result, const struct sieve_action *to_action, 
 	const struct sieve_side_effect *seffect, void *context);
@@ -56,6 +79,10 @@ int sieve_result_add_action
 	const struct sieve_action *action, struct sieve_side_effects_list *seffects,
 	unsigned int source_line, void *context);
 
+/*
+ * Result execution
+ */
+ 
 bool sieve_result_implicit_keep
     (struct sieve_result *result, bool rollback);
 
@@ -63,6 +90,10 @@ int sieve_result_execute
 	(struct sieve_result *result, const struct sieve_message_data *msgdata,
 		const struct sieve_script_env *senv);
 		
+/*
+ * Side effects list
+ */
+ 
 struct sieve_side_effects_list *sieve_side_effects_list_create
 	(struct sieve_result *result);
 void sieve_side_effects_list_add
diff --git a/src/lib-sieve/sieve-script-private.h b/src/lib-sieve/sieve-script-private.h
index f5c1a53fd..bac21f4f2 100644
--- a/src/lib-sieve/sieve-script-private.h
+++ b/src/lib-sieve/sieve-script-private.h
@@ -1,28 +1,35 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #ifndef __SIEVE_SCRIPT_PRIVATE_H
 #define __SIEVE_SCRIPT_PRIVATE_H
 
 #include "sieve-script.h"
 
+/*
+ * Script object
+ */
+
 struct sieve_script {
-    pool_t pool;
-    unsigned int refcount;
+	pool_t pool;
+	unsigned int refcount;
 
-    struct stat st;
+	struct stat st;
 	struct stat lnk_st;
 	time_t mtime;
 
-    struct sieve_error_handler *ehandler;
+	struct sieve_error_handler *ehandler;
 
-    /* Parameters */
-    const char *name;
+	/* Parameters */
+	const char *name;
 	const char *basename;
-    const char *filename;
-    const char *dirpath;
-    const char *path;
+	const char *filename;
+	const char *dirpath;
+	const char *path;
 
-    /* Stream */
-    int fd; /* FIXME: we could use the stream's autoclose facility */
-    struct istream *stream;
+	/* Stream */
+	int fd; /* FIXME: we could use the stream's autoclose facility */
+	struct istream *stream;
 };
 
 struct sieve_script *sieve_script_init
diff --git a/src/lib-sieve/sieve-script.c b/src/lib-sieve/sieve-script.c
index 89d1cb986..f3d7cc128 100644
--- a/src/lib-sieve/sieve-script.c
+++ b/src/lib-sieve/sieve-script.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #include "lib.h"
 #include "compat.h"
 #include "istream.h"
@@ -11,8 +14,16 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+/*
+ * Configuration
+ */
+ 
 #define SIEVE_READ_BLOCK_SIZE (1024*8)
 
+/*
+ * Filename to name/name to filename
+ */
+
 static inline const char *_sieve_scriptfile_get_basename(const char *filename)
 {
 	const char *ext;
@@ -37,7 +48,10 @@ static inline const char *_sieve_scriptfile_from_name(const char *name)
     return name;
 }
 
-/* Script object */
+/* 
+ * Script object 
+ */
+ 
 struct sieve_script *sieve_script_init
 (struct sieve_script *script, const char *path, const char *name, 
 	struct sieve_error_handler *ehandler, bool *exists_r)
@@ -178,7 +192,38 @@ void sieve_script_unref(struct sieve_script **script)
 	*script = NULL;
 }
 
-/* Stream manageement */
+/* 
+ * Accessors 
+ */
+
+const char *sieve_script_name(struct sieve_script *script)
+{
+	return script->name;
+}
+
+const char *sieve_script_filename(struct sieve_script *script)
+{
+	return script->filename;
+}
+
+const char *sieve_script_path(struct sieve_script *script)
+{
+	return script->path;
+}
+
+const char *sieve_script_dirpath(struct sieve_script *script)
+{
+	return script->dirpath;
+}
+
+const char *sieve_script_binpath(struct sieve_script *script)
+{
+	return t_strconcat(script->dirpath, "/", script->basename, ".svbin", NULL);
+}
+
+/* 
+ * Stream manageement 
+ */
 
 struct istream *sieve_script_open
 (struct sieve_script *script, bool *deleted_r)
@@ -243,7 +288,9 @@ uoff_t sieve_script_get_size(struct sieve_script *script)
 	return script->st.st_size;
 }
 
-/* Comparison */
+/* 
+ * Comparison 
+ */
 
 int sieve_script_cmp
 (struct sieve_script *script1, struct sieve_script *script2)
@@ -261,31 +308,3 @@ bool sieve_script_older
 {
 	return ( script->st.st_mtime < time && script->lnk_st.st_mtime < time );
 }
-
-/* Accessors */
-
-const char *sieve_script_name(struct sieve_script *script)
-{
-	return script->name;
-}
-
-const char *sieve_script_filename(struct sieve_script *script)
-{
-	return script->filename;
-}
-
-const char *sieve_script_path(struct sieve_script *script)
-{
-	return script->path;
-}
-
-const char *sieve_script_dirpath(struct sieve_script *script)
-{
-	return script->dirpath;
-}
-
-const char *sieve_script_binpath(struct sieve_script *script)
-{
-	return t_strconcat(script->dirpath, "/", script->basename, ".svbin", NULL);
-}
-
diff --git a/src/lib-sieve/sieve-script.h b/src/lib-sieve/sieve-script.h
index c484c46cd..e49744e2b 100644
--- a/src/lib-sieve/sieve-script.h
+++ b/src/lib-sieve/sieve-script.h
@@ -1,8 +1,15 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #ifndef __SIEVE_SCRIPT_H
 #define __SIEVE_SCRIPT_H
 
 #include "sieve-common.h"
 
+/*
+ * Sieve script object
+ */
+
 struct sieve_script;
 
 struct sieve_script *sieve_script_create
@@ -16,13 +23,29 @@ struct sieve_script *sieve_script_create_in_directory
 void sieve_script_ref(struct sieve_script *script);
 void sieve_script_unref(struct sieve_script **script);
 
-/* Stream management */
+/*
+ * Accessors
+ */
+ 
+const char *sieve_script_name(struct sieve_script *script);
+const char *sieve_script_filename(struct sieve_script *script);
+const char *sieve_script_path(struct sieve_script *script);
+const char *sieve_script_binpath(struct sieve_script *script);
+const char *sieve_script_dirpath(struct sieve_script *script);
+
+/* 
+ * Stream management 
+ */
 
 struct istream *sieve_script_open(struct sieve_script *script, bool *deleted_r);
 void sieve_script_close(struct sieve_script *script);
 
 uoff_t sieve_script_get_size(struct sieve_script *script);
 
+/*
+ * Comparison
+ */
+ 
 int sieve_script_cmp
 	(struct sieve_script *script1, struct sieve_script *script2);
 unsigned int sieve_script_hash(struct sieve_script *script);
@@ -34,10 +57,4 @@ static inline bool sieve_script_equals
 	return ( sieve_script_cmp(script1, script2) == 0 );
 }
 
-const char *sieve_script_name(struct sieve_script *script);
-const char *sieve_script_filename(struct sieve_script *script);
-const char *sieve_script_path(struct sieve_script *script);
-const char *sieve_script_binpath(struct sieve_script *script);
-const char *sieve_script_dirpath(struct sieve_script *script);
-
 #endif /* __SIEVE_SCRIPT_H */
diff --git a/src/lib-sieve/sieve-types.h b/src/lib-sieve/sieve-types.h
index b8e95d49b..6b6d1c085 100644
--- a/src/lib-sieve/sieve-types.h
+++ b/src/lib-sieve/sieve-types.h
@@ -14,10 +14,18 @@
 /* Enable runtime trace functionality */
 #define SIEVE_RUNTIME_TRACE
 
+/*
+ * Forward declarations
+ */
+
 struct sieve_script;
 struct sieve_binary;
 
-/* The mail message + envelope data */
+/* 
+ * Message data
+ *
+ * - The mail message + envelope data 
+ */
 
 struct sieve_message_data {
 	struct mail *mail;
@@ -27,7 +35,11 @@ struct sieve_message_data {
 	const char *id;
 };
 
-/* Environment for currently executing script */
+/* 
+ * Script environment
+ *
+ * - Environment for currently executing script 
+ */
 
 struct sieve_script_env {
 	/* Mail-related */
@@ -47,9 +59,10 @@ struct sieve_script_env {
 	bool (*smtp_close)(void *handle);
 	
 	/* Interface for marking and checking duplicates */
-	int (*duplicate_check)(const void *id, size_t id_size, const char *user);
-	void (*duplicate_mark)(const void *id, size_t id_size,
-                    const char *user, time_t time);
+	int (*duplicate_check)
+		(const void *id, size_t id_size, const char *user);
+	void (*duplicate_mark)
+		(const void *id, size_t id_size, const char *user, time_t time);
 };	
 
 /*
diff --git a/src/lib-sieve/sieve-validator.c b/src/lib-sieve/sieve-validator.c
index db033b2bb..f6497aa7f 100644
--- a/src/lib-sieve/sieve-validator.c
+++ b/src/lib-sieve/sieve-validator.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"
@@ -16,12 +19,47 @@
 #include "sieve-comparators.h"
 #include "sieve-address-parts.h"
 
+/*
+ * Forward declarations
+ */
+ 
+static void sieve_validator_register_core_commands
+	(struct sieve_validator *validator);
+static void sieve_validator_register_core_tests
+	(struct sieve_validator *validator);
+	
+/*
+ * Types
+ */
+ 
+/* Tag registration */
+
+struct sieve_tag_registration {
+	const struct sieve_argument *tag;
+	const char *identifier;	
+	int id_code;
+};
+
+/* Command registration */
+
+struct sieve_command_registration {
+	const struct sieve_command *command;
+	
+	ARRAY_DEFINE(normal_tags, struct sieve_tag_registration *); 
+	ARRAY_DEFINE(instanced_tags, struct sieve_tag_registration *); 
+	ARRAY_DEFINE(persistent_tags, struct sieve_tag_registration *); 
+};
+ 
+/* Default (literal) arguments */
+
 struct sieve_default_argument {
 	const struct sieve_argument *argument;
 	struct sieve_default_argument *overrides;
 };
 
-/* Extensions to the validator */
+/* 
+ * Validator extension
+ */
 
 struct sieve_validator_extension_reg {
 	const struct sieve_validator_extension *val_ext;
@@ -29,7 +67,7 @@ struct sieve_validator_extension_reg {
 };
 
 /* 
- * Context/Semantics checker implementation 
+ * Validator
  */
 
 struct sieve_validator {
@@ -55,12 +93,9 @@ struct sieve_validator {
 	bool current_defarg_constant;
 };
 
-/* Predeclared statics */
-
-static void sieve_validator_register_core_commands(struct sieve_validator *validator);
-static void sieve_validator_register_core_tests(struct sieve_validator *validator);
-
-/* Error management */
+/* 
+ * Error handling 
+ */
 
 void sieve_validator_warning
 (struct sieve_validator *validator, struct sieve_ast_node *node, 
@@ -95,10 +130,12 @@ void sieve_validator_critical
 	va_end(args);
 }
 
-/* Validator object */
+/* 
+ * Validator object 
+ */
 
 struct sieve_validator *sieve_validator_create
-	(struct sieve_ast *ast, struct sieve_error_handler *ehandler) 
+(struct sieve_ast *ast, struct sieve_error_handler *ehandler) 
 {
 	unsigned int i;
 	pool_t pool;
@@ -167,44 +204,41 @@ void sieve_validator_free(struct sieve_validator **validator)
 	*validator = NULL;
 }
 
+/*
+ * Accessors
+ */
+
 pool_t sieve_validator_pool(struct sieve_validator *validator)
 {
 	return validator->pool;
 }
 
 struct sieve_error_handler *sieve_validator_error_handler
-	(struct sieve_validator *validator)
+(struct sieve_validator *validator)
 {
 	return validator->ehandler;
 }
 
 struct sieve_ast *sieve_validator_ast
-	(struct sieve_validator *validator)
+(struct sieve_validator *validator)
 {
 	return validator->ast;
 }
 
 struct sieve_script *sieve_validator_script
-	(struct sieve_validator *validator)
+(struct sieve_validator *validator)
 {
 	return validator->script;
 }
 
-/* Command registry */
-
-struct sieve_tag_registration;
+/* 
+ * Command registry 
+ */
 
-struct sieve_command_registration {
-	const struct sieve_command *command;
-	
-	ARRAY_DEFINE(normal_tags, struct sieve_tag_registration *); 
-	ARRAY_DEFINE(instanced_tags, struct sieve_tag_registration *); 
-	ARRAY_DEFINE(persistent_tags, struct sieve_tag_registration *); 
-};
+/* Dummy command object to mark unknown commands in the registry */
 
-/* Dummy function */
 static bool _cmd_unknown_validate
-	(struct sieve_validator *validator ATTR_UNUSED, 
+(struct sieve_validator *validator ATTR_UNUSED, 
 	struct sieve_command_context *cmd ATTR_UNUSED) 
 {
 	i_unreached();
@@ -216,7 +250,10 @@ static const struct sieve_command unknown_command = {
 	NULL, NULL, _cmd_unknown_validate, NULL, NULL 
 };
 
-static void sieve_validator_register_core_tests(struct sieve_validator *validator) 
+/* Registration of the core commands of the language */
+
+static void sieve_validator_register_core_tests
+(struct sieve_validator *validator) 
 {
 	unsigned int i;
 	
@@ -225,7 +262,8 @@ static void sieve_validator_register_core_tests(struct sieve_validator *validato
 	}
 }
 
-static void sieve_validator_register_core_commands(struct sieve_validator *validator) 
+static void sieve_validator_register_core_commands
+(struct sieve_validator *validator) 
 {
 	unsigned int i;
 	
@@ -234,14 +272,18 @@ static void sieve_validator_register_core_commands(struct sieve_validator *valid
 	}
 }
 
-static struct sieve_command_registration *sieve_validator_find_command_registration
-		(struct sieve_validator *validator, const char *command) 
+/* Registry functions */
+
+static struct sieve_command_registration *
+sieve_validator_find_command_registration
+(struct sieve_validator *validator, const char *command) 
 {
-	return (struct sieve_command_registration *) hash_lookup(validator->commands, command);
+	return (struct sieve_command_registration *) 
+		hash_lookup(validator->commands, command);
 }
 
 static struct sieve_command_registration *_sieve_validator_register_command
-	(struct sieve_validator *validator, const struct sieve_command *command,
+(struct sieve_validator *validator, const struct sieve_command *command,
 	const char *identifier) 
 {
 	struct sieve_command_registration *record = 
@@ -253,7 +295,7 @@ static struct sieve_command_registration *_sieve_validator_register_command
 }
 
 void sieve_validator_register_command
-	(struct sieve_validator *validator, const struct sieve_command *command) 
+(struct sieve_validator *validator, const struct sieve_command *command) 
 {
 	struct sieve_command_registration *cmd_reg =
 		sieve_validator_find_command_registration(validator, command->identifier);
@@ -269,7 +311,7 @@ void sieve_validator_register_command
 }
 
 static void sieve_validator_register_unknown_command
-	(struct sieve_validator *validator, const char *command) 
+(struct sieve_validator *validator, const char *command) 
 {
 	(void)_sieve_validator_register_command(validator, &unknown_command, command);		
 }
@@ -283,16 +325,14 @@ const struct sieve_command *sieve_validator_find_command
   return ( record == NULL ? NULL : record->command );
 }
 
-/* Per-command tag/argument registry */
+/* 
+ * Per-command tagged argument registry 
+ */
 
-struct sieve_tag_registration {
-	const struct sieve_argument *tag;
-	const char *identifier;	
-	int id_code;
-};
+/* Dummy argument object to mark unknown arguments in the registry */
 
 static bool _unknown_tag_validate
-	(struct sieve_validator *validator ATTR_UNUSED, 
+(struct sieve_validator *validator ATTR_UNUSED, 
 	struct sieve_ast_argument **arg ATTR_UNUSED, 
 	struct sieve_command_context *tst ATTR_UNUSED)
 {
@@ -307,6 +347,8 @@ static const struct sieve_argument _unknown_tag = {
 	NULL, NULL 
 };
 
+/* Registry functions */
+
 static void _sieve_validator_register_tag
 (struct sieve_validator *validator, struct sieve_command_registration *cmd_reg, 
 	const struct sieve_argument *tag, const char *identifier, int id_code) 
@@ -368,7 +410,7 @@ void sieve_validator_register_external_tag
 }
 
 void sieve_validator_register_tag
-	(struct sieve_validator *validator, struct sieve_command_registration *cmd_reg, 
+(struct sieve_validator *validator, struct sieve_command_registration *cmd_reg, 
 	const struct sieve_argument *tag, int id_code) 
 {
 	if ( tag->is_instance_of == NULL )
@@ -436,11 +478,13 @@ static const struct sieve_argument *sieve_validator_find_tag
 	return NULL;
 }
 
-/* Extension support */
+/* 
+ * Extension support 
+ */
 
 const struct sieve_extension *sieve_validator_extension_load
-	(struct sieve_validator *validator, struct sieve_command_context *cmd, 
-		string_t *ext_name) 
+(struct sieve_validator *validator, struct sieve_command_context *cmd, 
+	string_t *ext_name) 
 {
 	const struct sieve_extension *ext;
 	const char *name = str_c(ext_name);
@@ -507,7 +551,9 @@ void *sieve_validator_extension_get_context
 	return reg->context;
 }
 
-/* Argument Validation API */
+/* 
+ * Overriding the default literal arguments
+ */
 
 void sieve_validator_argument_override
 (struct sieve_validator *validator, enum sieve_argument_type type, 
@@ -576,6 +622,10 @@ bool sieve_validator_argument_activate_super
 		(validator, cmd, defarg, arg);
 }
 
+/* 
+ * Argument Validation API 
+ */
+
 bool sieve_validator_argument_activate
 (struct sieve_validator *validator, struct sieve_command_context *cmd, 
 	struct sieve_ast_argument *arg, bool constant)
@@ -608,7 +658,7 @@ bool sieve_validator_argument_activate
 }
 
 bool sieve_validate_positional_argument
-	(struct sieve_validator *validator, struct sieve_command_context *cmd,
+(struct sieve_validator *validator, struct sieve_command_context *cmd,
 	struct sieve_ast_argument *arg, const char *arg_name, unsigned int arg_pos,
 	enum sieve_ast_argument_type req_type)
 {
@@ -628,7 +678,7 @@ bool sieve_validate_positional_argument
 }
 
 bool sieve_validate_tag_parameter
-	(struct sieve_validator *validator, struct sieve_command_context *cmd,
+(struct sieve_validator *validator, struct sieve_command_context *cmd,
 	struct sieve_ast_argument *tag, struct sieve_ast_argument *param,
 	enum sieve_ast_argument_type req_type)
 {
@@ -649,7 +699,9 @@ bool sieve_validate_tag_parameter
 	return sieve_validator_argument_activate(validator, cmd, param, FALSE);
 }
 
-/* Test validation API */
+/* 
+ * Command argument validation 
+ */
 
 static bool sieve_validate_command_arguments
 (struct sieve_validator *validator, struct sieve_command_context *cmd) 
@@ -791,7 +843,9 @@ static bool sieve_validate_arguments_context
 	return TRUE;
 }
  
-/* Command Validation API */ 
+/* 
+ * Command Validation API 
+ */ 
                  
 static bool sieve_validate_command_subtests
 (struct sieve_validator *validator, struct sieve_command_context *cmd, 
@@ -801,36 +855,48 @@ static bool sieve_validate_command_subtests
 	
 	case 0:
 	 	if ( sieve_ast_test_count(cmd->ast_node) > 0 ) {
-			sieve_command_validate_error
-				( validator, cmd, "the %s %s accepts no sub-tests, but tests are specified anyway", 
-					cmd->command->identifier, sieve_command_type_name(cmd->command) );
+			sieve_command_validate_error(validator, cmd, 
+				"the %s %s accepts no sub-tests, but tests are specified anyway", 
+				cmd->command->identifier, sieve_command_type_name(cmd->command));
+			
 			return FALSE;
 		}
 		break;
 	case 1:
 		if ( sieve_ast_test_count(cmd->ast_node) == 0 ) {
-			sieve_command_validate_error
-				( validator, cmd, "the %s %s requires one sub-test, but none is specified", 
-					cmd->command->identifier, sieve_command_type_name(cmd->command) );
+			sieve_command_validate_error(validator, cmd, 
+				"the %s %s requires one sub-test, but none is specified", 
+				cmd->command->identifier, sieve_command_type_name(cmd->command));
+				
 			return FALSE;
-		} else if ( sieve_ast_test_count(cmd->ast_node) > 1 || cmd->ast_node->test_list ) {
-			sieve_command_validate_error
-				( validator, cmd, "the %s %s requires one sub-test, but a list of tests is specified", 
-					cmd->command->identifier, sieve_command_type_name(cmd->command) );
+			
+		} else if ( sieve_ast_test_count(cmd->ast_node) > 1 || 
+			cmd->ast_node->test_list ) {
+			
+			sieve_command_validate_error(validator, cmd, 
+				"the %s %s requires one sub-test, but a list of tests is specified", 
+				cmd->command->identifier, sieve_command_type_name(cmd->command));
+				
 			return FALSE;
 		}
 		break;
 		
 	default:
 		if ( sieve_ast_test_count(cmd->ast_node) == 0 ) {
-			sieve_command_validate_error
-				( validator, cmd, "the %s %s requires a list of sub-tests, but none is specified", 
-					cmd->command->identifier, sieve_command_type_name(cmd->command) );
+			sieve_command_validate_error(validator, cmd, 
+				"the %s %s requires a list of sub-tests, but none is specified", 
+				cmd->command->identifier, sieve_command_type_name(cmd->command));
+			
 			return FALSE;
-		} else if ( sieve_ast_test_count(cmd->ast_node) == 1 && !cmd->ast_node->test_list ) {
-			sieve_command_validate_error
-				( validator, cmd, "the %s %s requires a list of sub-tests, but a single test is specified", 
-					cmd->command->identifier, sieve_command_type_name(cmd->command) );
+			
+		} else if ( sieve_ast_test_count(cmd->ast_node) == 1 && 
+			!cmd->ast_node->test_list ) {
+			
+			sieve_command_validate_error(validator, cmd, 
+				"the %s %s requires a list of sub-tests, "
+				"but a single test is specified", 
+				cmd->command->identifier, sieve_command_type_name(cmd->command) );
+			
 			return FALSE;
 		}
 		break;		
@@ -847,24 +913,27 @@ static bool sieve_validate_command_block
 	
 	if ( block_required ) {
 		if ( !cmd->ast_node->block ) {
-			sieve_command_validate_error
-				( validator, cmd, 
-					"the %s command requires a command block, but it is missing", 
-					cmd->command->identifier );
+			sieve_command_validate_error(validator, cmd, 
+				"the %s command requires a command block, but it is missing", 
+				cmd->command->identifier);
+			
 			return FALSE;
 		}
 	} else if ( !block_allowed && cmd->ast_node->block ) {
-		sieve_command_validate_error
-				( validator, cmd, 
-					"the %s command does not accept a command block, but one is specified anyway", 
-					cmd->command->identifier );
+		sieve_command_validate_error(validator, cmd, 
+			"the %s command does not accept a command block, "
+			"but one is specified anyway", 
+			cmd->command->identifier );
+		
 		return FALSE;
 	}
 	
 	return TRUE;
 } 
 
-/* AST Validation */
+/* 
+ * AST Validation 
+ */
 
 static bool sieve_validate_test_list
 	(struct sieve_validator *validator, struct sieve_ast_node *test_list); 
@@ -874,7 +943,7 @@ static bool sieve_validate_command
 	(struct sieve_validator *validator, struct sieve_ast_node *cmd_node);
 	
 static bool sieve_validate_command
-	(struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node) 
+(struct sieve_validator *valdtr, struct sieve_ast_node *cmd_node) 
 {
 	enum sieve_ast_type ast_type = sieve_ast_node_type(cmd_node);
 	bool result = TRUE;
@@ -969,7 +1038,7 @@ static bool sieve_validate_command
 }
 
 static bool sieve_validate_test_list
-	(struct sieve_validator *valdtr, struct sieve_ast_node *test_list) 
+(struct sieve_validator *valdtr, struct sieve_ast_node *test_list) 
 {
 	bool result = TRUE;
 	struct sieve_ast_node *test;
diff --git a/src/lib-sieve/sieve-validator.h b/src/lib-sieve/sieve-validator.h
index 2a9304f50..041336c7f 100644
--- a/src/lib-sieve/sieve-validator.h
+++ b/src/lib-sieve/sieve-validator.h
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file 
+ */
+ 
 #ifndef __SIEVE_VALIDATOR_H
 #define __SIEVE_VALIDATOR_H
 
@@ -5,6 +8,10 @@
 
 #include "sieve-common.h"
 
+/*
+ * Types
+ */
+
 enum sieve_argument_type {
 	SAT_NUMBER,
 	SAT_CONST_STRING,
@@ -14,14 +21,25 @@ enum sieve_argument_type {
 	SAT_COUNT
 };
 
-struct sieve_validator;
 struct sieve_command_registration;
 
+/*
+ * Validator
+ */
+ 
+struct sieve_validator;
+
 struct sieve_validator *sieve_validator_create
 	(struct sieve_ast *ast, struct sieve_error_handler *ehandler);
 void sieve_validator_free(struct sieve_validator **validator);
 pool_t sieve_validator_pool(struct sieve_validator *validator);
 
+bool sieve_validator_run(struct sieve_validator *validator);
+
+/*
+ * Accessors
+ */
+ 
 struct sieve_error_handler *sieve_validator_error_handler
 	(struct sieve_validator *validator);
 struct sieve_ast *sieve_validator_ast
@@ -29,7 +47,9 @@ struct sieve_ast *sieve_validator_ast
 struct sieve_script *sieve_validator_script
 	(struct sieve_validator *validator);
 
-bool sieve_validator_run(struct sieve_validator *validator);
+/*
+ * Error handling
+ */
 
 void sieve_validator_warning
 	(struct sieve_validator *validator, struct sieve_ast_node *node, 
@@ -41,9 +61,10 @@ void sieve_validator_critical
 	(struct sieve_validator *validator, struct sieve_ast_node *node, 
 		const char *fmt, ...) ATTR_FORMAT(3, 4);
 		
-/* Command Programmers Interface */
-
-/* Command/Test registration */
+/* 
+ * Command/Test registry
+ */
+ 
 void sieve_validator_register_command
 	(struct sieve_validator *validator, const struct sieve_command *command);
 const struct sieve_command *sieve_validator_find_command
@@ -53,7 +74,10 @@ void sieve_validator_register_external_tag
 	(struct sieve_validator *validator, const struct sieve_argument *tag, 
 		const char *command, int id_code);
 
-/* Argument registration */
+/* 
+ * Per-command tagged argument registry
+ */
+
 void sieve_validator_register_tag
 	(struct sieve_validator *validator, 
 		struct sieve_command_registration *cmd_reg, 
@@ -61,8 +85,21 @@ void sieve_validator_register_tag
 void sieve_validator_register_persistent_tag
 	(struct sieve_validator *validator, const struct sieve_argument *tag, 
 		const char *command);
+	
+/*
+ * Overriding the default literal arguments
+ */	
+ 
+void sieve_validator_argument_override
+(struct sieve_validator *validator, enum sieve_argument_type type, 
+	const struct sieve_argument *argument);
+bool sieve_validator_argument_activate_super
+(struct sieve_validator *validator, struct sieve_command_context *cmd, 
+	struct sieve_ast_argument *arg, bool constant);
 		
-/* Argument validation */
+/* 
+ * Argument validation API
+ */
 
 bool sieve_validate_positional_argument
 	(struct sieve_validator *validator, struct sieve_command_context *cmd,
@@ -77,13 +114,6 @@ bool sieve_validate_tag_parameter
 	struct sieve_ast_argument *tag, struct sieve_ast_argument *param,
 	enum sieve_ast_argument_type req_type);
 	
-void sieve_validator_argument_override
-(struct sieve_validator *validator, enum sieve_argument_type type, 
-	const struct sieve_argument *argument);
-bool sieve_validator_argument_activate_super
-(struct sieve_validator *validator, struct sieve_command_context *cmd, 
-	struct sieve_ast_argument *arg, bool constant);
-
 /* 
  * Extension support
  */
-- 
GitLab