From e24042e2857bc7ced2b59bacec193d7b8c6139af Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Mon, 25 Aug 2008 12:28:52 +0200
Subject: [PATCH] Finished code cleanup for now.

---
 TODO                              |  1 -
 src/testsuite/cmd-test-fail.c     |  3 ++
 src/testsuite/cmd-test-set.c      |  3 ++
 src/testsuite/cmd-test.c          |  3 ++
 src/testsuite/ext-testsuite.c     | 56 ++++++++++++++-----------------
 src/testsuite/mail-raw.c          | 16 ++++++---
 src/testsuite/mail-raw.h          |  3 ++
 src/testsuite/namespaces.c        |  3 +-
 src/testsuite/namespaces.h        |  7 +++-
 src/testsuite/testsuite-common.c  |  3 ++
 src/testsuite/testsuite-common.h  | 56 +++++++++++++++++++++++++------
 src/testsuite/testsuite-objects.c |  3 ++
 src/testsuite/testsuite-objects.h | 27 +++++++++++----
 src/testsuite/testsuite.c         |  7 +++-
 src/testsuite/tst-test-compile.c  | 15 +++++++--
 src/testsuite/tst-test-error.c    |  7 +++-
 16 files changed, 155 insertions(+), 58 deletions(-)

diff --git a/TODO b/TODO
index df4b7d2ab..d1931f652 100644
--- a/TODO
+++ b/TODO
@@ -8,7 +8,6 @@ Next (in order of descending priority/precedence):
 	  MUST win.
 	- 'If an address is not syntactically valid, then it will not be matched
 	  by tests specifying ":localpart" or ":domain"'.
-* Code cleanup 
 * Full security review. Enforce limits on number of created objects, script 
   size, execution time, etc...
 	- Make (configurable) limit on the number of redirects
diff --git a/src/testsuite/cmd-test-fail.c b/src/testsuite/cmd-test-fail.c
index 8eefab67b..b46326954 100644
--- a/src/testsuite/cmd-test-fail.c
+++ b/src/testsuite/cmd-test-fail.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-validator.h"
diff --git a/src/testsuite/cmd-test-set.c b/src/testsuite/cmd-test-set.c
index d0dd1dfe3..ee4e7a977 100644
--- a/src/testsuite/cmd-test-set.c
+++ b/src/testsuite/cmd-test-set.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #include "lib.h"
 #include "ioloop.h"
 #include "str-sanitize.h"
diff --git a/src/testsuite/cmd-test.c b/src/testsuite/cmd-test.c
index f41c55ab1..15041ddd1 100644
--- a/src/testsuite/cmd-test.c
+++ b/src/testsuite/cmd-test.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-validator.h"
diff --git a/src/testsuite/ext-testsuite.c b/src/testsuite/ext-testsuite.c
index fc240ddd0..8978d8620 100644
--- a/src/testsuite/ext-testsuite.c
+++ b/src/testsuite/ext-testsuite.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 /* Extension testsuite
  * -------------------
  *
@@ -43,25 +46,9 @@
 
 #include "testsuite-common.h"
 
-/* Forward declarations */
-
-static bool ext_testsuite_load(int ext_id);
-static bool ext_testsuite_validator_load(struct sieve_validator *valdtr);
-static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv);
-static bool ext_testsuite_binary_load(struct sieve_binary *sbin);
-
-/* Commands */
-
-extern const struct sieve_command cmd_test;
-extern const struct sieve_command cmd_test_fail;
-extern const struct sieve_command cmd_test_set;
-
-/* Tests */
-
-extern const struct sieve_command tst_test_compile;
-extern const struct sieve_command tst_test_error;
-
-/* Operations */
+/* 
+ * Operations 
+ */
 
 const struct sieve_operation *testsuite_operations[] = { 
 	&test_operation, 
@@ -72,18 +59,31 @@ const struct sieve_operation *testsuite_operations[] = {
 	&test_error_operation
 };
 
-/* Operands */
+/* 
+ * Operands 
+ */
 
 const struct sieve_operand *testsuite_operands[] =
     { &testsuite_object_operand };
     
-/* Extension definitions */
+/* 
+ * Extension
+ */
+
+/* Forward declarations */
+
+static bool ext_testsuite_load(int ext_id);
+static bool ext_testsuite_validator_load(struct sieve_validator *valdtr);
+static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv);
+static bool ext_testsuite_binary_load(struct sieve_binary *sbin);
 
-int ext_testsuite_my_id;
+/* Extension object */
+
+static int ext_my_id;
 
 const struct sieve_extension testsuite_extension = { 
 	"vnd.dovecot.testsuite", 
-	&ext_testsuite_my_id,
+	&ext_my_id,
 	ext_testsuite_load,
 	ext_testsuite_validator_load,
 	ext_testsuite_generator_load,
@@ -94,15 +94,15 @@ const struct sieve_extension testsuite_extension = {
 	SIEVE_EXT_DEFINE_OPERAND(testsuite_object_operand)
 };
 
+/* Extension implementation */
+
 static bool ext_testsuite_load(int ext_id)
 {
-	ext_testsuite_my_id = ext_id;
+	ext_my_id = ext_id;
 
 	return TRUE;
 }
 
-/* Load extension into validator */
-
 static bool ext_testsuite_validator_load(struct sieve_validator *valdtr)
 {
 	sieve_validator_register_command(valdtr, &cmd_test);
@@ -115,15 +115,11 @@ static bool ext_testsuite_validator_load(struct sieve_validator *valdtr)
 	return testsuite_validator_context_initialize(valdtr);
 }
 
-/* Load extension into generator */
-
 static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv)
 {
 	return testsuite_generator_context_initialize(cgenv->gentr);
 }
 
-/* Load extension into binary */
-
 static bool ext_testsuite_binary_load(struct sieve_binary *sbin ATTR_UNUSED)
 {
 	return TRUE;
diff --git a/src/testsuite/mail-raw.c b/src/testsuite/mail-raw.c
index 50c1689c7..a1ed1ec56 100644
--- a/src/testsuite/mail-raw.c
+++ b/src/testsuite/mail-raw.c
@@ -1,10 +1,10 @@
-/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
 
 /* This file was gratefully stolen from dovecot/src/deliver/deliver.c and altered
  * to suit our needs. So, this contains lots and lots of duplicated code. 
- * The sieve_test program needs to read an email message from stdin and it needs 
- * to build a struct mail (to be fed to the sieve library). Deliver does something
- * similar already, so that source was a basis for this test binary. 
+ * FIXME: As a matter of fact a similar file is located at src/sieve-bin/mail-raw.c
+ *        These must be merged.
  */
 
 #include "lib.h"
@@ -27,12 +27,20 @@
 #include <fcntl.h>
 #include <pwd.h>
 
+/*
+ * Configuration
+ */
+
 #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON"
 
 /* After buffer grows larger than this, create a temporary file to /tmp
    where to read the mail. */
 #define MAIL_MAX_MEMORY_BUFFER (1024*128)
 
+/*
+ * Implementation
+ */
+
 static struct mail_namespace *raw_ns;
 
 void mail_raw_init(const char *user) 
diff --git a/src/testsuite/mail-raw.h b/src/testsuite/mail-raw.h
index 73ed48b91..c401208e5 100644
--- a/src/testsuite/mail-raw.h
+++ b/src/testsuite/mail-raw.h
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #ifndef __MAIL_RAW_H
 #define __MAIL_RAW_H
 
diff --git a/src/testsuite/namespaces.c b/src/testsuite/namespaces.c
index f032b3e85..e1565c459 100644
--- a/src/testsuite/namespaces.c
+++ b/src/testsuite/namespaces.c
@@ -1,4 +1,5 @@
-/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
 
 #include "lib.h"
 #include "istream.h"
diff --git a/src/testsuite/namespaces.h b/src/testsuite/namespaces.h
index 81e9fc030..c89016712 100644
--- a/src/testsuite/namespaces.h
+++ b/src/testsuite/namespaces.h
@@ -1,7 +1,12 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
+/* FIXME: Duplicated */
+
 #ifndef __NAMESPACES_H
 #define __NAMESPACES_H
 
 void namespaces_init(void);
 void namespaces_deinit(void);
 
-#endif /* __MAIL_RAW_H */
+#endif /* __NAMESPACES_H */
diff --git a/src/testsuite/testsuite-common.c b/src/testsuite/testsuite-common.c
index d14cf8fad..0b670f4dd 100644
--- a/src/testsuite/testsuite-common.c
+++ b/src/testsuite/testsuite-common.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #include "lib.h"
 #include "str.h"
 #include "string.h"
diff --git a/src/testsuite/testsuite-common.h b/src/testsuite/testsuite-common.h
index c371e5c83..16eee76c6 100644
--- a/src/testsuite/testsuite-common.h
+++ b/src/testsuite/testsuite-common.h
@@ -1,11 +1,18 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #ifndef __TESTSUITE_COMMON_H
 #define __TESTSUITE_COMMON_H
 
-extern const struct sieve_extension testsuite_extension;
+/*
+ * Extension
+ */
 
-extern int ext_testsuite_my_id;
+extern const struct sieve_extension testsuite_extension;
 
-/* Testsuite message environment */
+/* 
+ * Testsuite message environment 
+ */
 
 extern struct sieve_message_data testsuite_msgdata;
 
@@ -19,7 +26,9 @@ void testsuite_envelope_set_sender(const char *value);
 void testsuite_envelope_set_recipient(const char *value);
 void testsuite_envelope_set_auth_user(const char *value);
 
-/* Testsuite validator context */
+/* 
+ * Validator context 
+ */
 
 struct testsuite_validator_context {
 	struct sieve_validator_object_registry *object_registrations;
@@ -29,7 +38,9 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr);
 struct testsuite_validator_context *testsuite_validator_context_get
 	(struct sieve_validator *valdtr);
 
-/* Testsuite generator context */
+/* 
+ * Generator context 
+ */
 
 struct testsuite_generator_context {
 	struct sieve_jumplist *exit_jumps;
@@ -37,7 +48,24 @@ struct testsuite_generator_context {
 
 bool testsuite_generator_context_initialize(struct sieve_generator *gentr);
 
-/* Testsuite operations */
+/*
+ * Commands
+ */
+
+extern const struct sieve_command cmd_test;
+extern const struct sieve_command cmd_test_fail;
+extern const struct sieve_command cmd_test_set;
+
+/*
+ * Tests
+ */
+
+extern const struct sieve_command tst_test_compile;
+extern const struct sieve_command tst_test_error;
+
+/* 
+ * Operations 
+ */
 
 enum testsuite_operation_code {
 	TESTSUITE_OPERATION_TEST,
@@ -55,7 +83,9 @@ extern const struct sieve_operation test_set_operation;
 extern const struct sieve_operation test_compile_operation;
 extern const struct sieve_operation test_error_operation;
 
-/* Testsuite operands */
+/* 
+ * Operands 
+ */
 
 extern const struct sieve_operand testsuite_object_operand;
 
@@ -63,7 +93,9 @@ enum testsuite_operand_code {
 	TESTSUITE_OPERAND_OBJECT
 };
 
-/* Test context */
+/* 
+ * Test context 
+ */
 
 void testsuite_test_start(string_t *name);
 void testsuite_test_fail(string_t *reason);
@@ -72,14 +104,18 @@ void testsuite_test_succeed(string_t *reason);
 void testsuite_testcase_fail(const char *reason);
 int testsuite_testcase_result(void);
 
-/* Tested script environment */
+/* 
+ * Tested script environment 
+ */
 
 bool testsuite_script_compile(const char *script_path);
 
 void testsuite_script_get_error_init(void);
 const char *testsuite_script_get_error_next(bool location);
 
-/* Testsuite init/deinit */
+/* 
+ * Testsuite init/deinit 
+ */
 
 void testsuite_init(void);
 void testsuite_deinit(void);
diff --git a/src/testsuite/testsuite-objects.c b/src/testsuite/testsuite-objects.c
index 4e002603f..eb91d0966 100644
--- a/src/testsuite/testsuite-objects.c
+++ b/src/testsuite/testsuite-objects.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #include "lib.h"
 #include "string.h"
 #include "ostream.h"
diff --git a/src/testsuite/testsuite-objects.h b/src/testsuite/testsuite-objects.h
index 0512ea370..6a0fc122e 100644
--- a/src/testsuite/testsuite-objects.h
+++ b/src/testsuite/testsuite-objects.h
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #ifndef __TESTSUITE_OBJECTS_H
 #define __TESTSUITE_OBJECTS_H
 
@@ -6,7 +9,9 @@
 
 #include "testsuite-common.h"
 
-/* Testsuite object operand */
+/* 
+ * Testsuite object operand 
+ */
 
 struct testsuite_object_operand_interface {
 	struct sieve_extension_obj_registry testsuite_objects;
@@ -14,7 +19,9 @@ struct testsuite_object_operand_interface {
 
 extern const struct sieve_operand_class testsuite_object_oprclass;
 
-/* Testsuite object access */
+/* 
+ * Testsuite object access 
+ */
 
 struct testsuite_object {
 	struct sieve_object object;
@@ -26,7 +33,9 @@ struct testsuite_object {
 	string_t *(*get_member)(const struct sieve_runtime_env *renv, int id);
 };
 
-/* Testsuite object registration */
+/* 
+ * Testsuite object registration 
+ */
 
 const struct testsuite_object *testsuite_object_find
 	(struct sieve_validator *valdtr, const char *identifier);
@@ -35,13 +44,17 @@ void testsuite_object_register
 void testsuite_register_core_objects
 	(struct testsuite_validator_context *ctx);
 		
-/* Testsuite object argument */		
+/* 
+ * Testsuite object argument 
+ */		
 	
 bool testsuite_object_argument_activate
 	(struct sieve_validator *valdtr, struct sieve_ast_argument *arg,
 		struct sieve_command_context *cmd);		
 		
-/* Testsuite object code */
+/* 
+ * Testsuite object code 
+ */
 
 const struct testsuite_object *testsuite_object_read
   (struct sieve_binary *sbin, sieve_size_t *address);
@@ -52,7 +65,9 @@ const char *testsuite_object_member_name
 bool testsuite_object_dump
 	(const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
-/* Testsuite core objects */
+/* 
+ * Testsuite core objects 
+ */
 
 extern const struct testsuite_object message_testsuite_object;
 extern const struct testsuite_object envelope_testsuite_object;
diff --git a/src/testsuite/testsuite.c b/src/testsuite/testsuite.c
index 20e055573..eb12d91a6 100644
--- a/src/testsuite/testsuite.c
+++ b/src/testsuite/testsuite.c
@@ -1,4 +1,5 @@
-/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
 
 #include "lib.h"
 #include "lib-signals.h"
@@ -26,6 +27,10 @@
 #include <fcntl.h>
 #include <pwd.h>
 
+/*
+ * Configuration
+ */
+
 #define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail"
 #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON"
 
diff --git a/src/testsuite/tst-test-compile.c b/src/testsuite/tst-test-compile.c
index 9dbcbb4ae..ae9f72108 100644
--- a/src/testsuite/tst-test-compile.c
+++ b/src/testsuite/tst-test-compile.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #include "sieve-common.h"
 #include "sieve-script.h"
 #include "sieve-commands.h"
@@ -33,7 +36,9 @@ const struct sieve_command tst_test_compile = {
 	NULL 
 };
 
-/* Test_compile operation */
+/* 
+ * Operation 
+ */
 
 static bool tst_test_compile_operation_dump
 	(const struct sieve_operation *op,
@@ -50,7 +55,9 @@ const struct sieve_operation test_compile_operation = {
 	tst_test_compile_operation_execute 
 };
 
-/* Validation */
+/* 
+ * Validation 
+ */
 
 static bool tst_test_compile_validate
 (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command_context *tst) 
@@ -65,7 +72,9 @@ static bool tst_test_compile_validate
 	return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
 }
 
-/* Code generation */
+/* 
+ * Code generation 
+ */
 
 static inline struct testsuite_generator_context *
 	_get_generator_context(struct sieve_generator *gentr)
diff --git a/src/testsuite/tst-test-error.c b/src/testsuite/tst-test-error.c
index 8dbce7352..bf842a6a7 100644
--- a/src/testsuite/tst-test-error.c
+++ b/src/testsuite/tst-test-error.c
@@ -1,3 +1,6 @@
+/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
+ */
+
 #include "sieve-common.h"
 #include "sieve-error.h"
 #include "sieve-script.h"
@@ -39,7 +42,9 @@ const struct sieve_command tst_test_error = {
 	NULL 
 };
 
-/* Test_error operation */
+/* 
+ * Operation 
+ */
 
 static bool tst_test_error_operation_dump
 	(const struct sieve_operation *op,
-- 
GitLab