dovecot-2.2-pigeonhole: LDA Sieve plugin: Changed error handling...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Wed Apr 22 19:44:54 UTC 2015


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/c9c16230501e
changeset: 2037:c9c16230501e
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed Apr 22 21:36:29 2015 +0200
description:
LDA Sieve plugin: Changed error handling so that each action log message can have up-to-date time stamps.
This change matches a change in LDA that is aimed at logging timing statistics.

diffstat:

 src/lib-sieve/plugins/enotify/cmd-notify.c |   2 +-
 src/lib-sieve/sieve-result.c               |  61 +++---------------
 src/lib-sieve/sieve-result.h               |  15 +--
 src/lib-sieve/sieve-types.h                |   3 -
 src/lib-sieve/sieve.c                      |  64 ++++++++----------
 src/lib-sieve/sieve.h                      |  18 +++--
 src/plugins/lda-sieve/Makefile.am          |   2 +
 src/plugins/lda-sieve/lda-sieve-log.c      |  97 ++++++++++++++++++++++++++++++
 src/plugins/lda-sieve/lda-sieve-log.h      |  11 +++
 src/plugins/lda-sieve/lda-sieve-plugin.c   |  52 +++++++++++----
 src/sieve-tools/sieve-filter.c             |  10 ++-
 src/sieve-tools/sieve-test.c               |  31 ++++++---
 src/testsuite/testsuite-result.c           |   7 +-
 src/testsuite/testsuite-script.c           |   4 +-
 14 files changed, 241 insertions(+), 136 deletions(-)

diffs (truncated from 868 to 300 lines):

diff -r 2ebd3bd76e1e -r c9c16230501e src/lib-sieve/plugins/enotify/cmd-notify.c
--- a/src/lib-sieve/plugins/enotify/cmd-notify.c	Sat Mar 28 10:49:23 2015 +0100
+++ b/src/lib-sieve/plugins/enotify/cmd-notify.c	Wed Apr 22 21:36:29 2015 +0200
@@ -523,7 +523,7 @@
 	nenv.svinst = renv->svinst;
 	nenv.method = nact->method;
 	nenv.ehandler = sieve_prefix_ehandler_create
-		(sieve_result_get_error_handler(renv->result), act->location, "notify");
+		(renv->ehandler, act->location, "notify");
 
 	result = nmth_def->action_check_duplicates(&nenv, nact, nact_other);
 
diff -r 2ebd3bd76e1e -r c9c16230501e src/lib-sieve/sieve-result.c
--- a/src/lib-sieve/sieve-result.c	Sat Mar 28 10:49:23 2015 +0100
+++ b/src/lib-sieve/sieve-result.c	Wed Apr 22 21:36:29 2015 +0200
@@ -26,12 +26,6 @@
 #include <stdio.h>
 
 /*
- * Defaults
- */
-
-#define DEFAULT_ACTION_LOG_FORMAT "msgid=%m: %$"
-
-/*
  * Types
  */
 
@@ -79,8 +73,6 @@
 	/* Context data for extensions */
 	ARRAY(void *) ext_contexts;
 
-	struct sieve_error_handler *ehandler;
-
 	struct sieve_action_exec_env action_env;
 
 	struct sieve_action keep_action;
@@ -100,7 +92,7 @@
 
 struct sieve_result *sieve_result_create
 (struct sieve_instance *svinst, const struct sieve_message_data *msgdata,
-	const struct sieve_script_env *senv, struct sieve_error_handler *ehandler)
+	const struct sieve_script_env *senv)
 {
 	pool_t pool;
 	struct sieve_result *result;
@@ -113,10 +105,6 @@
 
 	p_array_init(&result->ext_contexts, pool, 4);
 
-	if ( ehandler != NULL )
-		sieve_error_handler_ref(ehandler);
-	result->ehandler = ehandler;
-
 	result->action_env.svinst = svinst;
 	result->action_env.result = result;
 	result->action_env.scriptenv = senv;
@@ -153,9 +141,6 @@
 	if ( hash_table_is_created((*result)->action_contexts) )
         hash_table_destroy(&(*result)->action_contexts);
 
-	if ( (*result)->ehandler != NULL )
-		sieve_error_handler_unref(&(*result)->ehandler);
-
 	if ( (*result)->action_env.ehandler != NULL )
 		sieve_error_handler_unref(&(*result)->action_env.ehandler);
 
@@ -173,11 +158,6 @@
  * Getters/Setters
  */
 
-struct sieve_error_handler *sieve_result_get_error_handler
-(struct sieve_result *result)
-{
-	return result->ehandler;
-}
 const struct sieve_script_env *sieve_result_get_script_env
 (struct sieve_result *result)
 {
@@ -196,16 +176,6 @@
 	return result->action_env.msgctx;
 }
 
-void sieve_result_set_error_handler
-(struct sieve_result *result, struct sieve_error_handler *ehandler)
-{
-	if ( result->ehandler != ehandler ) {
-		sieve_error_handler_ref(ehandler);
-		sieve_error_handler_unref(&result->ehandler);
-		result->ehandler = ehandler;
-	}
-}
-
 /*
  * Extension support
  */
@@ -939,27 +909,15 @@
  * Result execution
  */
 
-static void _sieve_result_prepare_execution(struct sieve_result *result)
+static void _sieve_result_prepare_execution(struct sieve_result *result,
+	struct sieve_error_handler *ehandler)
 {
-	const struct sieve_message_data *msgdata = result->action_env.msgdata;
 	const struct sieve_script_env *senv = result->action_env.scriptenv;
-	const struct var_expand_table *tab;
 
-	tab = mail_deliver_get_log_var_expand_table(msgdata->mail, NULL);
+	result->action_env.ehandler = ehandler;
 	result->action_env.exec_status =
 		( senv->exec_status == NULL ?
 			t_new(struct sieve_exec_status, 1) : senv->exec_status );
-
-	if ( result->action_env.ehandler != NULL )
-		sieve_error_handler_unref(&result->action_env.ehandler);
-
-	if ( senv->action_log_format != NULL ) {
-		result->action_env.ehandler = sieve_varexpand_ehandler_create
-			(result->ehandler, senv->action_log_format, tab);
-	} else {
-		result->action_env.ehandler = sieve_varexpand_ehandler_create
-            (result->ehandler, DEFAULT_ACTION_LOG_FORMAT, tab);
-	}
 }
 
 static int _sieve_result_implicit_keep
@@ -1072,9 +1030,10 @@
 }
 
 int sieve_result_implicit_keep
-(struct sieve_result *result)
+(struct sieve_result *result,
+	struct sieve_error_handler *ehandler)
 {
-	_sieve_result_prepare_execution(result);
+	_sieve_result_prepare_execution(result, ehandler);
 
 	return _sieve_result_implicit_keep(result, TRUE);
 }
@@ -1357,7 +1316,8 @@
 }
 
 int sieve_result_execute
-(struct sieve_result *result, bool *keep)
+(struct sieve_result *result, bool *keep,
+	struct sieve_error_handler *ehandler)
 {
 	int status = SIEVE_EXEC_OK, result_status;
 	struct sieve_result_action *first_action, *last_action;
@@ -1368,7 +1328,7 @@
 
 	/* Prepare environment */
 
-	_sieve_result_prepare_execution(result);
+	_sieve_result_prepare_execution(result, ehandler);
 
 	/* Make notice of this attempt */
 
@@ -1424,6 +1384,7 @@
 	sieve_result_transaction_finish
 		(result, first_action, status);
 
+	result->action_env.ehandler = NULL;
 	return result_status;
 }
 
diff -r 2ebd3bd76e1e -r c9c16230501e src/lib-sieve/sieve-result.h
--- a/src/lib-sieve/sieve-result.h	Sat Mar 28 10:49:23 2015 +0100
+++ b/src/lib-sieve/sieve-result.h	Wed Apr 22 21:36:29 2015 +0200
@@ -21,8 +21,7 @@
 
 struct sieve_result *sieve_result_create
 	(struct sieve_instance *svinst, const struct sieve_message_data *msgdata,
-		const struct sieve_script_env *senv,
-		struct sieve_error_handler *ehandler);
+		const struct sieve_script_env *senv);
 
 void sieve_result_ref(struct sieve_result *result);
 
@@ -34,11 +33,6 @@
  * Getters/Setters
  */
 
-struct sieve_error_handler *sieve_result_get_error_handler
-	(struct sieve_result *result);
-void sieve_result_set_error_handler
-	(struct sieve_result *result, struct sieve_error_handler *ehandler);
-
 const struct sieve_script_env *sieve_result_get_script_env
 	(struct sieve_result *result);
 const struct sieve_message_data *sieve_result_get_message_data
@@ -148,11 +142,14 @@
  * Result execution
  */
 
-int sieve_result_implicit_keep(struct sieve_result *result);
+int sieve_result_implicit_keep(struct sieve_result *result,
+	struct sieve_error_handler *ehandler);
 
 void sieve_result_mark_executed(struct sieve_result *result);
 
-int sieve_result_execute(struct sieve_result *result, bool *keep);
+int sieve_result_execute
+	(struct sieve_result *result, bool *keep,
+		struct sieve_error_handler *ehandler);
 
 bool sieve_result_executed(struct sieve_result *result);
 
diff -r 2ebd3bd76e1e -r c9c16230501e src/lib-sieve/sieve-types.h
--- a/src/lib-sieve/sieve-types.h	Sat Mar 28 10:49:23 2015 +0100
+++ b/src/lib-sieve/sieve-types.h	Wed Apr 22 21:36:29 2015 +0200
@@ -173,9 +173,6 @@
  */
 
 struct sieve_script_env {
-	/* Logging related */
-	const char *action_log_format;
-
 	/* Mail-related */
 	struct mail_user *user;
 	const char *default_mailbox;
diff -r 2ebd3bd76e1e -r c9c16230501e src/lib-sieve/sieve.c
--- a/src/lib-sieve/sieve.c	Sat Mar 28 10:49:23 2015 +0100
+++ b/src/lib-sieve/sieve.c	Wed Apr 22 21:36:29 2015 +0200
@@ -333,11 +333,9 @@
 		memset(senv->exec_status, 0, sizeof(*senv->exec_status));
 
 	/* Create result object */
-	if ( *result == NULL )
+	if ( *result == NULL ) {
 		*result = sieve_result_create
-			(sieve_binary_svinst(sbin), msgdata, senv, ehandler);
-	else {
-		sieve_result_set_error_handler(*result, ehandler);
+			(sieve_binary_svinst(sbin), msgdata, senv);
 	}
 
 	/* Run the interpreter */
@@ -539,7 +537,9 @@
 
 int sieve_execute
 (struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
-	const struct sieve_script_env *senv, struct sieve_error_handler *ehandler,
+	const struct sieve_script_env *senv,
+	struct sieve_error_handler *exec_ehandler,
+	struct sieve_error_handler *action_ehandler,
 	enum sieve_runtime_flags flags, bool *keep)
 {
 	struct sieve_result *result = NULL;
@@ -548,7 +548,7 @@
 	if ( keep != NULL ) *keep = FALSE;
 
 	/* Run the script */
-	ret = sieve_run(sbin, &result, msgdata, senv, ehandler, flags);
+	ret = sieve_run(sbin, &result, msgdata, senv, exec_ehandler, flags);
 
 	/* Evaluate status and execute the result:
 	 *   Strange situations, e.g. currupt binaries, must be handled by the caller.
@@ -557,10 +557,11 @@
 	 */
 	if ( ret > 0 ) {
 		/* Execute result */
-		ret = sieve_result_execute(result, keep);
+		ret = sieve_result_execute(result, keep, action_ehandler);
 	} else if ( ret == SIEVE_EXEC_FAILURE ) {
 		/* Perform implicit keep if script failed with a normal runtime error */
-		switch ( sieve_result_implicit_keep(result) ) {
+		switch ( sieve_result_implicit_keep
+			(result, action_ehandler) ) {
 		case SIEVE_EXEC_OK:
 			if ( keep != NULL ) *keep = TRUE;
 			break;
@@ -604,7 +605,7 @@
 	struct sieve_result *result;
 	struct sieve_multiscript *mscript;
 
-	result = sieve_result_create(svinst, msgdata, senv, NULL);
+	result = sieve_result_create(svinst, msgdata, senv);
 	pool = sieve_result_pool(result);
 
 	sieve_result_set_keep_action(result, NULL, NULL);
@@ -634,11 +635,8 @@
 }
 
 static void sieve_multiscript_test
-(struct sieve_multiscript *mscript, struct sieve_error_handler *ehandler,
-	bool *keep)
+(struct sieve_multiscript *mscript, bool *keep)
 {
-	sieve_result_set_error_handler(mscript->result, ehandler);
-
 	if ( mscript->status > 0 ) {
 		mscript->status = sieve_result_print
 			(mscript->result, mscript->scriptenv, mscript->teststream, keep);
@@ -653,12 +651,10 @@
 (struct sieve_multiscript *mscript, struct sieve_error_handler *ehandler,
 	bool *keep)
 {
-	sieve_result_set_error_handler(mscript->result, ehandler);


More information about the dovecot-cvs mailing list