dovecot-2.0-pigeonhole: Error handling: now only the topmost par...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Jan 16 00:07:40 EET 2010


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/175dc1553ced
changeset: 1207:175dc1553ced
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri Jan 15 18:36:43 2010 +0100
description:
Error handling: now only the topmost parent error handler will copy to the master log.

diffstat:

 src/lib-sieve/sieve-error-private.h |   16 +++-
 src/lib-sieve/sieve-error.c         |  119 ++++++++++++++++++++-------------------
 2 files changed, 71 insertions(+), 64 deletions(-)

diffs (truncated from 333 to 300 lines):

diff -r feb84a163026 -r 175dc1553ced src/lib-sieve/sieve-error-private.h
--- a/src/lib-sieve/sieve-error-private.h	Fri Jan 15 16:58:53 2010 +0100
+++ b/src/lib-sieve/sieve-error-private.h	Fri Jan 15 18:36:43 2010 +0100
@@ -14,6 +14,8 @@
 	pool_t pool;
 	int refcount;
 
+	struct sieve_error_handler *parent;
+
 	unsigned int max_errors;
 
 	unsigned int errors;
@@ -52,7 +54,7 @@
 (struct sieve_error_handler *ehandler, const char *location, 
 	const char *fmt, va_list args)
 {
-	if ( sieve_errors_more_allowed(ehandler) ) {
+	if ( ehandler->parent != NULL || sieve_errors_more_allowed(ehandler) ) {
 		if ( ehandler->verror != NULL )
 			ehandler->verror(ehandler, location, fmt, args);
 		
@@ -76,16 +78,20 @@
 (struct sieve_error_handler *ehandler, const char *location, 
 	const char *fmt, va_list args)
 {
-	if ( ehandler->log_info && ehandler->vinfo != NULL )	
-		ehandler->vinfo(ehandler, location, fmt, args);
+	if ( ehandler->parent != NULL || ehandler->log_info ) {
+		if ( ehandler->vinfo != NULL )	
+			ehandler->vinfo(ehandler, location, fmt, args);
+	}
 }
 
 static inline void sieve_direct_vdebug
 (struct sieve_error_handler *ehandler, const char *location, 
 	const char *fmt, va_list args)
 {
-	if ( ehandler->log_info && ehandler->vdebug != NULL )	
-		ehandler->vdebug(ehandler, location, fmt, args);
+	if ( ehandler->parent != NULL || ehandler->log_info ) {
+		if ( ehandler->vdebug != NULL )	
+			ehandler->vdebug(ehandler, location, fmt, args);
+	}
 }
 
 static inline void sieve_direct_error
diff -r feb84a163026 -r 175dc1553ced src/lib-sieve/sieve-error.c
--- a/src/lib-sieve/sieve-error.c	Fri Jan 15 16:58:53 2010 +0100
+++ b/src/lib-sieve/sieve-error.c	Fri Jan 15 18:36:43 2010 +0100
@@ -69,7 +69,7 @@
 {
 	if ( ehandler == NULL ) return;
 	
-	if ( ehandler->log_master )
+	if ( ehandler->parent == NULL && ehandler->log_master )
 		sieve_vcopy_master(location, sieve_verror, fmt, args);
 
 	sieve_direct_verror(ehandler, location, fmt, args);
@@ -81,7 +81,7 @@
 {
 	if ( ehandler == NULL ) return;
 
-	if ( ehandler->log_master )
+	if ( ehandler->parent == NULL && ehandler->log_master )
 		sieve_vcopy_master(location, sieve_vwarning, fmt, args);
 
 	sieve_direct_vwarning(ehandler, location, fmt, args);
@@ -93,7 +93,7 @@
 {
 	if ( ehandler == NULL ) return;
 
-	if ( ehandler->log_master )
+	if ( ehandler->parent == NULL && ehandler->log_master )
 		sieve_vcopy_master(location, sieve_vinfo, fmt, args);
 
 	sieve_direct_vinfo(ehandler, location, fmt, args);
@@ -105,7 +105,7 @@
 {
 	if ( ehandler == NULL ) return;
 
-	if ( ehandler->log_master )
+	if ( ehandler->parent == NULL && ehandler->log_master )
 		sieve_vcopy_master(location, sieve_vdebug, fmt, args);
 
 	sieve_direct_vdebug(ehandler, location, fmt, args);
@@ -223,21 +223,30 @@
  */
 
 void sieve_error_handler_accept_infolog
-	(struct sieve_error_handler *ehandler, bool enable)
+(struct sieve_error_handler *ehandler, bool enable)
 {
-	ehandler->log_info = enable;	
+	while ( ehandler != NULL ) {
+		ehandler->log_info = enable;
+		ehandler = ehandler->parent;
+	}
 }
 
 void sieve_error_handler_accept_debuglog
-	(struct sieve_error_handler *ehandler, bool enable)
+(struct sieve_error_handler *ehandler, bool enable)
 {
-	ehandler->log_debug = enable;
+	while ( ehandler != NULL ) {
+		ehandler->log_debug = enable;
+		ehandler = ehandler->parent;
+	}
 }
 
 void sieve_error_handler_copy_masterlog
-	(struct sieve_error_handler *ehandler, bool enable)
+(struct sieve_error_handler *ehandler, bool enable)
 {
-	ehandler->log_master = enable;
+	while ( ehandler != NULL ) {
+		ehandler->log_master = enable;
+		ehandler = ehandler->parent;
+	}
 }
 
 /*
@@ -262,6 +271,9 @@
 
 	sieve_error_handler_init(ehandler, pool, parent->max_errors);
 
+	ehandler->parent = parent;
+	sieve_error_handler_ref(parent);
+
 	ehandler->log_master = parent->log_master;
 	ehandler->log_info = parent->log_info;
 	ehandler->log_debug = parent->log_debug;
@@ -283,6 +295,9 @@
 	if (--(*ehandler)->refcount != 0)
         	return;
 
+	if ( (*ehandler)->parent != NULL ) 
+		sieve_error_handler_unref(&(*ehandler)->parent);
+
 	if ( (*ehandler)->free != NULL )
 		(*ehandler)->free(*ehandler);
 
@@ -376,7 +391,7 @@
 }
 
 struct sieve_error_handler _sieve_system_ehandler_object = {
-	NULL, 0, 0, 0, 0,
+	NULL, 0, NULL, 0, 0, 0,
 	FALSE,
 	TRUE,
 	TRUE,
@@ -829,13 +844,13 @@
 static void sieve_prefix_verror
 (struct sieve_error_handler *_ehandler, const char *location,
 	const char *fmt, va_list args) 
-{
-	struct sieve_prefix_ehandler *ehandler =
-		(struct sieve_prefix_ehandler *) _ehandler;
-	
-	if ( ehandler->parent == NULL ) return;
+{	
+    struct sieve_prefix_ehandler *ehandler =
+        (struct sieve_prefix_ehandler *) _ehandler;
 
-	sieve_direct_error(ehandler->parent, ehandler->location, "%s",
+	if ( _ehandler->parent == NULL ) return;
+
+	sieve_error(_ehandler->parent, ehandler->location, "%s",
 		_prefix_message(ehandler, location, fmt, args)); 
 }
 
@@ -843,12 +858,12 @@
 (struct sieve_error_handler *_ehandler, const char *location,
 	const char *fmt, va_list args) 
 {
-	struct sieve_prefix_ehandler *ehandler =
-		(struct sieve_prefix_ehandler *) _ehandler;
+    struct sieve_prefix_ehandler *ehandler =
+        (struct sieve_prefix_ehandler *) _ehandler;
 
-	if ( ehandler->parent == NULL ) return;
+	if ( _ehandler->parent == NULL ) return;
 
-	sieve_direct_warning(ehandler->parent, ehandler->location, "%s",
+	sieve_warning(_ehandler->parent, ehandler->location, "%s",
 		_prefix_message(ehandler, location, fmt, args)); 
 }
 
@@ -856,12 +871,12 @@
 (struct sieve_error_handler *_ehandler, const char *location,
 	const char *fmt, va_list args) 
 {
-	struct sieve_prefix_ehandler *ehandler =
-		(struct sieve_prefix_ehandler *) _ehandler;
+    struct sieve_prefix_ehandler *ehandler =
+        (struct sieve_prefix_ehandler *) _ehandler;
 
-	if ( ehandler->parent == NULL ) return;
+	if ( _ehandler->parent == NULL ) return;
 
-	sieve_direct_info(ehandler->parent, ehandler->location, "%s",
+	sieve_direct_info(_ehandler->parent, ehandler->location, "%s",
 		_prefix_message(ehandler, location, fmt, args)); 
 }
 
@@ -869,12 +884,12 @@
 (struct sieve_error_handler *_ehandler, const char *location,
 	const char *fmt, va_list args) 
 {
-	struct sieve_prefix_ehandler *ehandler =
-		(struct sieve_prefix_ehandler *) _ehandler;
+    struct sieve_prefix_ehandler *ehandler =
+        (struct sieve_prefix_ehandler *) _ehandler;
 
-	if ( ehandler->parent == NULL ) return;
+	if ( _ehandler->parent == NULL ) return;
 
-	sieve_direct_debug(ehandler->parent, ehandler->location, "%s",
+	sieve_direct_debug(_ehandler->parent, ehandler->location, "%s",
 		_prefix_message(ehandler, location, fmt, args)); 
 }
 
@@ -889,12 +904,11 @@
 
 	pool = pool_alloconly_create("sieve_prefix_error_handler", 256);	
 	ehandler = p_new(pool, struct sieve_prefix_ehandler, 1);
-	ehandler->parent = parent;
+	sieve_error_handler_init_from_parent(&ehandler->handler, pool, parent);
+
 	ehandler->location = p_strdup(pool, location);
 	ehandler->prefix = p_strdup(pool, prefix);
 
-	sieve_error_handler_init_from_parent(&ehandler->handler, pool, parent);
-
 	ehandler->handler.verror = sieve_prefix_verror;
 	ehandler->handler.vwarning = sieve_prefix_vwarning;
 	ehandler->handler.vinfo = sieve_prefix_vinfo;
@@ -913,16 +927,16 @@
 struct sieve_varexpand_ehandler {
 	struct sieve_error_handler handler;
 
-	struct sieve_error_handler *parent;
-
 	const char *format;
 	ARRAY_DEFINE(table, struct var_expand_table);
 };
 
 static const char *_expand_message
-(struct sieve_varexpand_ehandler *ehandler,
+(struct sieve_error_handler *_ehandler,
 	const char *location, const char *fmt, va_list args) 
 {
+    struct sieve_varexpand_ehandler *ehandler =
+        (struct sieve_varexpand_ehandler *) _ehandler;
 	unsigned int count;
 	struct var_expand_table *table = array_get_modifiable(&ehandler->table, &count);
 	string_t *str = t_str_new(256);
@@ -938,51 +952,39 @@
 }
 
 static void sieve_varexpand_verror
-(struct sieve_error_handler *_ehandler, const char *location,
+(struct sieve_error_handler *ehandler, const char *location,
 	const char *fmt, va_list args) 
-{
-	struct sieve_varexpand_ehandler *ehandler =
-		(struct sieve_varexpand_ehandler *) _ehandler;
+{	
+	if ( ehandler->parent == NULL ) return;
 
-	if ( ehandler->parent == NULL ) return;
-	
-	sieve_direct_error(ehandler->parent, location, "%s",
+	sieve_error(ehandler->parent, location, "%s",
 		_expand_message(ehandler, location, fmt, args)); 
 }
 
 static void sieve_varexpand_vwarning
-(struct sieve_error_handler *_ehandler, const char *location,
+(struct sieve_error_handler *ehandler, const char *location,
 	const char *fmt, va_list args) 
 {
-	struct sieve_varexpand_ehandler *ehandler =
-		(struct sieve_varexpand_ehandler *) _ehandler;
-
 	if ( ehandler->parent == NULL ) return;
 
-	sieve_direct_warning(ehandler->parent, location, "%s",
+	sieve_warning(ehandler->parent, location, "%s",
 		_expand_message(ehandler, location, fmt, args)); 
 }
 
 static void sieve_varexpand_vinfo
-(struct sieve_error_handler *_ehandler, const char *location,
+(struct sieve_error_handler *ehandler, const char *location,
 	const char *fmt, va_list args) 
 {
-	struct sieve_varexpand_ehandler *ehandler =
-		(struct sieve_varexpand_ehandler *) _ehandler;
-


More information about the dovecot-cvs mailing list