dovecot-2.0-pigeonhole: Added debug mode to the Sieve engine.

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Fri May 14 23:57:12 EEST 2010


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/6c9d1a295517
changeset: 1286:6c9d1a295517
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri May 14 22:57:06 2010 +0200
description:
Added debug mode to the Sieve engine.

diffstat:

 doc/man/sieve-test.1                       |  10 +++-
 src/lib-sieve-tool/sieve-tool.c            |   4 +-
 src/lib-sieve-tool/sieve-tool.h            |   2 +-
 src/lib-sieve/sieve-common.h               |   3 +
 src/lib-sieve/sieve.c                      |  36 ++++++++++++++---
 src/lib-sieve/sieve.h                      |   2 +-
 src/managesieve/managesieve-capabilities.c |   2 +-
 src/managesieve/managesieve-client.c       |   2 +-
 src/plugins/lda-sieve/lda-sieve-plugin.c   |  16 ++++---
 src/sieve-tools/sieve-filter.c             |  56 ++++++++++++++-------------
 src/sieve-tools/sieve-test.c               |  11 +++--
 src/sieve-tools/sievec.c                   |   2 +-
 src/sieve-tools/sieved.c                   |   2 +-
 src/testsuite/testsuite.c                  |  20 ++++++----
 14 files changed, 104 insertions(+), 64 deletions(-)

diffs (truncated from 491 to 300 lines):

diff -r 8791594d478e -r 6c9d1a295517 doc/man/sieve-test.1
--- a/doc/man/sieve-test.1	Fri May 14 14:35:19 2010 +0200
+++ b/doc/man/sieve-test.1	Fri May 14 22:57:06 2010 +0200
@@ -3,7 +3,8 @@
 sieve\-test \- Sieve script tester for the Dovecot secure IMAP server
 .SH SYNOPSIS
 sieve\-test
-[\fB\-c\fR] 
+[\fB\-C\fR]
+[\fB\-D\fR]
 [\fB\-d\fR \fIdump\-file\fR]
 [\fB\-e\fR]
 [\fB\-f\fR \fIenvelope\-sender\fR]
@@ -39,17 +40,20 @@
 containing the e\-mail message to filter. 
 
 Note that this tool looks for a pre\-compiled binary file with a \fI.svbin\fP extension and 
-with basename and path identical to the specified script. Use the \fB\-c\fP option to disable this
+with basename and path identical to the specified script. Use the \fB\-C\fP option to disable this
 behavior by forcing the script to be compiled into a new binary.  
 .SH OPTIONS
 .TP 
-\fB\-c\fP
+\fB\-C\fP
 Force compilation. By default, the compiled binary is stored on disk. When this binary is found
 during the next execution of \fBsieve\-test\fP and its modification time is more recent than the
 script file, it is used and the script is not compiled again. This option forces the script to be
 compiled, thus ignoring any present binary. Refer to \fBsievec\fP(1) for more information about 
 Sieve compilation.
 .TP
+\fB\-D\fP
+Enable Sieve debugging.
+.TP
 \fB\-d\fP \fIdump\-file\fP
 Causes a dump of the generated code to be written to the specified file. This is identical to the
 dump produced by \fBsieved\fR(1). Using '\-' as filename causes the dump to be written to \fBstdout\fP.
diff -r 8791594d478e -r 6c9d1a295517 src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c	Fri May 14 14:35:19 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.c	Fri May 14 22:57:06 2010 +0200
@@ -95,11 +95,11 @@
 	}
 }
 
-void sieve_tool_sieve_init(const struct sieve_environment *env)
+void sieve_tool_sieve_init(const struct sieve_environment *env, bool debug)
 {
 	if ( env == NULL ) env = &sieve_tool_sieve_env;
 
-	if ( (sieve_instance=sieve_init(env, NULL)) == NULL )
+	if ( (sieve_instance=sieve_init(env, NULL, debug)) == NULL )
 		i_fatal("failed to initialize sieve implementation\n");
 }
 
diff -r 8791594d478e -r 6c9d1a295517 src/lib-sieve-tool/sieve-tool.h
--- a/src/lib-sieve-tool/sieve-tool.h	Fri May 14 14:35:19 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.h	Fri May 14 22:57:06 2010 +0200
@@ -24,7 +24,7 @@
  */
 
 void sieve_tool_init(bool init_lib);
-void sieve_tool_sieve_init(const struct sieve_environment *env);
+void sieve_tool_sieve_init(const struct sieve_environment *env, bool debug);
 void sieve_tool_deinit(void);
 
 /*
diff -r 8791594d478e -r 6c9d1a295517 src/lib-sieve/sieve-common.h
--- a/src/lib-sieve/sieve-common.h	Fri May 14 14:35:19 2010 +0200
+++ b/src/lib-sieve/sieve-common.h	Fri May 14 22:57:06 2010 +0200
@@ -149,6 +149,9 @@
 	const struct sieve_environment *env;
 	void *context;
 
+	/* Engine debug */
+	bool debug;
+
 	/* Extension registry */
 	struct sieve_extension_registry *ext_reg;
 
diff -r 8791594d478e -r 6c9d1a295517 src/lib-sieve/sieve.c
--- a/src/lib-sieve/sieve.c	Fri May 14 14:35:19 2010 +0200
+++ b/src/lib-sieve/sieve.c	Fri May 14 22:57:06 2010 +0200
@@ -40,7 +40,7 @@
  */
 
 struct sieve_instance *sieve_init
-(const struct sieve_environment *env, void *context)
+(const struct sieve_environment *env, void *context, bool debug)
 {
 	struct sieve_instance *svinst;
 	unsigned long long int uint_setting;
@@ -53,6 +53,7 @@
 	svinst->pool = pool;
 	svinst->env = env;
 	svinst->context = context;
+	svinst->debug = debug;
 
 	/* Read limits from configuration */
 
@@ -215,6 +216,10 @@
 	sbin = sieve_compile_script(script, ehandler);
 	
 	sieve_script_unref(&script);
+
+	if ( svinst->debug && sbin != NULL ) {
+		sieve_sys_debug("script file %s successfully compiled", script_path);
+	}
 	
 	return sbin;
 }
@@ -266,7 +271,7 @@
 {
 	struct sieve_script *script;
 	struct sieve_binary *sbin;
-	const char *binpath;
+	const char *bin_path;
 	
 	/* First open the scriptfile itself */
 	script = sieve_script_create
@@ -279,15 +284,19 @@
 
 	T_BEGIN {
 		/* Then try to open the matching binary */
-		binpath = sieve_script_binpath(script);	
-		sbin = sieve_binary_open(svinst, binpath, script);
+		bin_path = sieve_script_binpath(script);	
+		sbin = sieve_binary_open(svinst, bin_path, script);
 	
 		if (sbin != NULL) {
 			/* Ok, it exists; now let's see if it is up to date */
 			if ( !sieve_binary_up_to_date(sbin) ) {
 				/* Not up to date */
+				if ( svinst->debug )
+					sieve_sys_debug("script binary %s is not up-to-date", bin_path);
+
 				sieve_binary_unref(&sbin);
 				sbin = NULL;
+
 			} else if ( !sieve_binary_load(sbin) ) {
 				/* Failed to load */
 				sieve_binary_unref(&sbin);
@@ -298,12 +307,25 @@
 		/* If the binary does not exist, is not up-to-date or fails to load, we need
 		 * to (re-)compile.
 		 */
-		if ( sbin == NULL ) {	
+		if ( sbin != NULL ) {
+			if ( svinst->debug )
+				sieve_sys_debug("script binary %s successfully loaded", bin_path);
+			
+		} else {	
 			sbin = sieve_compile_script(script, ehandler);
 
 			/* Save the binary if compile was successful */
-			if ( sbin != NULL ) 
-				(void) sieve_binary_save(sbin, binpath);	
+			if ( sbin != NULL ) {
+				if ( svinst->debug )
+					sieve_sys_debug("script %s successfully compiled", script_path);
+
+				if ( sieve_binary_save(sbin, bin_path) ) {
+					if ( svinst->debug ) {
+						sieve_sys_debug
+							("compiled script saved as binary file %s", bin_path);
+					}
+				}
+			}
 		}
 	} T_END;
 	
diff -r 8791594d478e -r 6c9d1a295517 src/lib-sieve/sieve.h
--- a/src/lib-sieve/sieve.h	Fri May 14 14:35:19 2010 +0200
+++ b/src/lib-sieve/sieve.h	Fri May 14 22:57:06 2010 +0200
@@ -22,7 +22,7 @@
  *   is used.
  */
 struct sieve_instance *sieve_init
-	(const struct sieve_environment *env, void *context);
+	(const struct sieve_environment *env, void *context, bool debug);
 
 /* sieve_deinit():
  *   Frees all memory allocated by the sieve engine. 
diff -r 8791594d478e -r 6c9d1a295517 src/managesieve/managesieve-capabilities.c
--- a/src/managesieve/managesieve-capabilities.c	Fri May 14 14:35:19 2010 +0200
+++ b/src/managesieve/managesieve-capabilities.c	Fri May 14 22:57:06 2010 +0200
@@ -130,7 +130,7 @@
 
 	/* Initialize Sieve engine */
 
-	svinst = sieve_init(&sieve_env, (void *) global_plugin_settings);
+	svinst = sieve_init(&sieve_env, (void *) global_plugin_settings, FALSE);
 
 	extensions = plugin_settings_get(global_plugin_settings, "sieve_extensions");
 	if ( extensions != NULL ) {
diff -r 8791594d478e -r 6c9d1a295517 src/managesieve/managesieve-client.c
--- a/src/managesieve/managesieve-client.c	Fri May 14 14:35:19 2010 +0200
+++ b/src/managesieve/managesieve-client.c	Fri May 14 22:57:06 2010 +0200
@@ -122,7 +122,7 @@
 
 	/* Initialize Sieve instance */
 
-	svinst = sieve_init(&managesieve_sieve_env, (void *) user);
+	svinst = sieve_init(&managesieve_sieve_env, (void *) user, set->mail_debug);
 
 	extensions = mail_user_plugin_getenv(user, "sieve_extensions");
 	if ( extensions != NULL ) {
diff -r 8791594d478e -r 6c9d1a295517 src/plugins/lda-sieve/lda-sieve-plugin.c
--- a/src/plugins/lda-sieve/lda-sieve-plugin.c	Fri May 14 14:35:19 2010 +0200
+++ b/src/plugins/lda-sieve/lda-sieve-plugin.c	Fri May 14 22:57:06 2010 +0200
@@ -520,12 +520,13 @@
 	struct sieve_script_env scriptenv;
 	struct sieve_exec_status estatus;
 	const char *extensions = NULL;
+	bool debug = mdctx->dest_user->mail_debug;
 	int ret = 0;
 
 	*storage_r = NULL;
 
 	/* Initialize Sieve engine */
-	svinst = sieve_init(&lda_sieve_env, mdctx->dest_user);
+	svinst = sieve_init(&lda_sieve_env, mdctx->dest_user, debug);
 	
 	extensions = mail_user_plugin_getenv
 		(mdctx->dest_user, "sieve_extensions");
@@ -626,7 +627,6 @@
 
 	/* Clean up */
 
-
 	if ( srctx.user_ehandler != NULL )
 		sieve_error_handler_unref(&srctx.user_ehandler);
 
@@ -662,8 +662,8 @@
 
 			switch ( errno ) {
 			case ENOENT:
-				if (getenv("DEBUG") != NULL)
-					sieve_sys_info("user's script path %s doesn't exist "
+				if ( debug )
+					sieve_sys_debug("user's script path %s doesn't exist "
 						"(using global script path in stead)", user_script);
 				break;
 			case EACCES:
@@ -712,12 +712,14 @@
 
 			scriptfiles = array_get(&scripts_before, &count);
 			for ( i = 0; i < count; i ++ ) {
-				sieve_sys_debug("executed before user's script(%d): %s", i+1, scriptfiles[i]);				
+				sieve_sys_debug("executed before user's script(%d): %s", 
+					i+1, scriptfiles[i]);				
 			}
 
 			scriptfiles = array_get(&scripts_after, &count);
 			for ( i = 0; i < count; i ++ ) {
-				sieve_sys_debug("executed after user's script(%d): %s", i+1, scriptfiles[i]);				
+				sieve_sys_debug("executed after user's script(%d): %s", 
+					i+1, scriptfiles[i]);				
 			}
 		}
 	
@@ -738,7 +740,7 @@
 			/* Run the script(s) */
 				
 			ret = lda_sieve_run
-                (mdctx, user_script, default_script, &scripts_before, &scripts_after, 
+				(mdctx, user_script, default_script, &scripts_before, &scripts_after, 
 					storage_r);
 		}
 
diff -r 8791594d478e -r 6c9d1a295517 src/sieve-tools/sieve-filter.c
--- a/src/sieve-tools/sieve-filter.c	Fri May 14 14:35:19 2010 +0200
+++ b/src/sieve-tools/sieve-filter.c	Fri May 14 22:57:06 2010 +0200
@@ -221,39 +221,39 @@
 
 int main(int argc, char **argv) 
 {
-    enum mail_storage_service_flags service_flags = 0;
-    struct mail_storage_service_ctx *storage_service;
-    struct mail_storage_service_user *service_user;
-    struct mail_storage_service_input service_input;
-    struct mail_user *mail_user_dovecot = NULL;
+	enum mail_storage_service_flags service_flags = 0;
+	struct mail_storage_service_ctx *storage_service;
+	struct mail_storage_service_user *service_user;
+	struct mail_storage_service_input service_input;
+	struct mail_user *mail_user_dovecot = NULL;
 	struct mail_user *mail_user = NULL;
-    ARRAY_TYPE (const_string) plugins;
+	ARRAY_TYPE (const_string) plugins;
 	const char *scriptfile, *recipient, *sender, *extensions,
-		*src_mailbox, *dst_mailbox, *src_mailstore, *dst_mailstore; 
-    const char *user, *home, *errstr;
-    struct mail_namespace_settings ns_set;
+	*src_mailbox, *dst_mailbox, *src_mailstore, *dst_mailstore; 
+	const char *user, *home, *errstr;
+	struct mail_namespace_settings ns_set;
 	struct mail_namespace *src_ns = NULL, *dst_ns = NULL;
 	struct mail_storage *dst_storage, *src_storage;
-    struct sieve_binary *main_sbin;
-    struct sieve_script_env scriptenv;
-    struct sieve_error_handler *ehandler;


More information about the dovecot-cvs mailing list