dovecot-2.0-pigeonhole: Sieve plugin: simplified system error ha...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sun Sep 5 16:12:00 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/fb765ed84e0e
changeset: 1409:fb765ed84e0e
user: Stephan Bosch <stephan at rename-it.nl>
date: Sun Sep 05 15:11:13 2010 +0200
description:
Sieve plugin: simplified system error handling.
diffstat:
src/lib-sieve/sieve-error.c | 87 ++++++++++++++++++----------
src/lib-sieve/sieve-error.h | 6 +-
src/plugins/lda-sieve/Makefile.am | 2 -
src/plugins/lda-sieve/lda-sieve-log.c | 95 -------------------------------
src/plugins/lda-sieve/lda-sieve-log.h | 14 ----
src/plugins/lda-sieve/lda-sieve-plugin.c | 25 +++++---
6 files changed, 73 insertions(+), 156 deletions(-)
diffs (truncated from 376 to 300 lines):
diff -r 0dc3cce72225 -r fb765ed84e0e src/lib-sieve/sieve-error.c
--- a/src/lib-sieve/sieve-error.c Sun Sep 05 14:24:19 2010 +0200
+++ b/src/lib-sieve/sieve-error.c Sun Sep 05 15:11:13 2010 +0200
@@ -53,7 +53,7 @@
void sieve_errors_init(struct sieve_instance *svinst)
{
- svinst->system_ehandler = sieve_master_ehandler_create(svinst, 0);
+ svinst->system_ehandler = sieve_master_ehandler_create(svinst, NULL, 0);
}
void sieve_errors_deinit(struct sieve_instance *svinst)
@@ -259,6 +259,12 @@
sieve_error_handler_ref(ehandler);
}
+struct sieve_error_handler *sieve_system_ehandler_get
+(struct sieve_instance *svinst)
+{
+ return svinst->system_ehandler;
+}
+
/*
* User errors
*/
@@ -581,15 +587,42 @@
* - Output errors directly to Dovecot master log
*/
+struct sieve_master_ehandler {
+ struct sieve_error_handler handler;
+
+ const char *prefix;
+};
+
+typedef void (*master_log_func_t)(const char *fmt, ...) ATTR_FORMAT(1, 2);
+
+static void sieve_master_vlog
+(struct sieve_error_handler *_ehandler, master_log_func_t log_func,
+ const char *location, const char *fmt, va_list args)
+{
+ struct sieve_master_ehandler *ehandler =
+ (struct sieve_master_ehandler *) _ehandler;
+ string_t *str;
+
+ str = t_str_new(256);
+ if ( ehandler->prefix != NULL)
+ str_printfa(str, "%s: ", ehandler->prefix);
+
+ str_append(str, "sieve: ");
+
+ if ( location != NULL && *location != '\0' )
+ str_printfa(str, "%s: ", location);
+
+ str_vprintfa(str, fmt, args);
+
+ log_func("%s", str_c(str));
+}
+
static void sieve_master_verror
-(struct sieve_error_handler *ehandler ATTR_UNUSED,
+(struct sieve_error_handler *ehandler,
unsigned int flags ATTR_UNUSED, const char *location, const char *fmt,
va_list args)
{
- if ( location == NULL || *location == '\0' )
- i_error("sieve: %s", t_strdup_vprintf(fmt, args));
- else
- i_error("sieve: %s: %s", location, t_strdup_vprintf(fmt, args));
+ sieve_master_vlog(ehandler, i_error, location, fmt, args);
}
static void sieve_master_vwarning
@@ -597,10 +630,7 @@
unsigned int flags ATTR_UNUSED, const char *location, const char *fmt,
va_list args)
{
- if ( location == NULL || *location == '\0' )
- i_warning("sieve: %s", t_strdup_vprintf(fmt, args));
- else
- i_warning("sieve: %s: %s", location, t_strdup_vprintf(fmt, args));
+ sieve_master_vlog(ehandler, i_warning, location, fmt, args);
}
static void sieve_master_vinfo
@@ -608,10 +638,7 @@
unsigned int flags ATTR_UNUSED, const char *location, const char *fmt,
va_list args)
{
- if ( location == NULL || *location == '\0' )
- i_info("sieve: %s", t_strdup_vprintf(fmt, args));
- else
- i_info("sieve: %s: %s", location, t_strdup_vprintf(fmt, args));
+ sieve_master_vlog(ehandler, i_info, location, fmt, args);
}
static void sieve_master_vdebug
@@ -619,32 +646,28 @@
unsigned int flags ATTR_UNUSED, const char *location, const char *fmt,
va_list args)
{
- if ( location == NULL || *location == '\0' )
- i_debug("sieve: %s", t_strdup_vprintf(fmt, args));
- else
- i_debug("sieve: %s: %s", location, t_strdup_vprintf(fmt, args));
+ sieve_master_vlog(ehandler, i_debug, location, fmt, args);
}
struct sieve_error_handler *sieve_master_ehandler_create
-(struct sieve_instance *svinst, unsigned int max_errors)
+(struct sieve_instance *svinst, const char *prefix, unsigned int max_errors)
{
pool_t pool;
- struct sieve_error_handler *ehandler;
+ struct sieve_master_ehandler *ehandler;
- /* Pool is not strictly necessary, but other handler types will need
- * a pool, so this one will have one too.
- */
- pool = pool_alloconly_create
- ("master_error_handler", sizeof(struct sieve_error_handler));
- ehandler = p_new(pool, struct sieve_error_handler, 1);
- sieve_error_handler_init(ehandler, svinst, pool, max_errors);
+ pool = pool_alloconly_create("master_error_handler", 256);
+ ehandler = p_new(pool, struct sieve_master_ehandler, 1);
+ sieve_error_handler_init(&ehandler->handler, svinst, pool, max_errors);
- ehandler->verror = sieve_master_verror;
- ehandler->vwarning = sieve_master_vwarning;
- ehandler->vinfo = sieve_master_vinfo;
- ehandler->vdebug = sieve_master_vdebug;
+ ehandler->handler.verror = sieve_master_verror;
+ ehandler->handler.vwarning = sieve_master_vwarning;
+ ehandler->handler.vinfo = sieve_master_vinfo;
+ ehandler->handler.vdebug = sieve_master_vdebug;
- return ehandler;
+ if ( prefix != NULL )
+ ehandler->prefix = p_strdup(pool, prefix);
+
+ return &ehandler->handler;
}
/*
diff -r 0dc3cce72225 -r fb765ed84e0e src/lib-sieve/sieve-error.h
--- a/src/lib-sieve/sieve-error.h Sun Sep 05 14:24:19 2010 +0200
+++ b/src/lib-sieve/sieve-error.h Sun Sep 05 15:11:13 2010 +0200
@@ -54,6 +54,8 @@
void sieve_system_ehandler_set
(struct sieve_error_handler *ehandler);
+struct sieve_error_handler *sieve_system_ehandler_get
+ (struct sieve_instance *svinst);
/*
* Global (user+system) errors
@@ -131,8 +133,6 @@
(struct sieve_error_handler *ehandler, bool enable);
void sieve_error_handler_accept_debuglog
(struct sieve_error_handler *ehandler, bool enable);
-void sieve_error_handler_copy_masterlog
- (struct sieve_error_handler *ehandler, bool enable);
/*
* Error handler statistics
@@ -158,7 +158,7 @@
/* Write errors to dovecot master log */
struct sieve_error_handler *sieve_master_ehandler_create
- (struct sieve_instance *svinst, unsigned int max_errors);
+ (struct sieve_instance *svinst, const char *prefix, unsigned int max_errors);
/* Write errors to stderr */
struct sieve_error_handler *sieve_stderr_ehandler_create
diff -r 0dc3cce72225 -r fb765ed84e0e src/plugins/lda-sieve/Makefile.am
--- a/src/plugins/lda-sieve/Makefile.am Sun Sep 05 14:24:19 2010 +0200
+++ b/src/plugins/lda-sieve/Makefile.am Sun Sep 05 15:11:13 2010 +0200
@@ -12,9 +12,7 @@
$(top_builddir)/src/lib-sieve/libdovecot-sieve.la
lib90_sieve_plugin_la_SOURCES = \
- lda-sieve-log.c \
lda-sieve-plugin.c
noinst_HEADERS = \
- lda-sieve-log.h \
lda-sieve-plugin.h
diff -r 0dc3cce72225 -r fb765ed84e0e src/plugins/lda-sieve/lda-sieve-log.c
--- a/src/plugins/lda-sieve/lda-sieve-log.c Sun Sep 05 14:24:19 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-/* Copyright (c) 2002-2010 Pigeonhole authors, see the included COPYING file
- */
-
-#include "lib.h"
-#include "str.h"
-#include "ostream.h"
-#include "mail-deliver.h"
-
-#include "sieve-common.h"
-#include "sieve-script.h"
-#include "sieve-error-private.h"
-
-#include "lda-sieve-log.h"
-
-/*
- * Deliver log error handler
- */
-
-struct lda_sieve_log_ehandler {
- struct sieve_error_handler handler;
-
- struct mail_deliver_context *mdctx;
-};
-
-typedef void (*log_func_t)(const char *fmt, ...) ATTR_FORMAT(1, 2);
-
-static void lda_sieve_vlog
-(struct sieve_error_handler *_ehandler, log_func_t log_func,
- const char *location, const char *fmt, va_list args)
-{
- struct lda_sieve_log_ehandler *ehandler =
- (struct lda_sieve_log_ehandler *) _ehandler;
- struct mail_deliver_context *mdctx = ehandler->mdctx;
- string_t *str;
-
- str = t_str_new(256);
- if ( mdctx->session_id != NULL)
- str_printfa(str, "%s: ", mdctx->session_id);
-
- str_append(str, "sieve: ");
-
- if ( location != NULL && *location != '\0' )
- str_printfa(str, "%s: ", location);
-
- str_vprintfa(str, fmt, args);
-
- log_func("%s", str_c(str));
-}
-
-static void lda_sieve_log_verror
-(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED,
- const char *location, const char *fmt, va_list args)
-{
- lda_sieve_vlog(ehandler, i_error, location, fmt, args);
-}
-static void lda_sieve_log_vwarning
-(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED,
- const char *location, const char *fmt, va_list args)
-{
- lda_sieve_vlog(ehandler, i_warning, location, fmt, args);
-}
-static void lda_sieve_log_vinfo
-(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED,
- const char *location, const char *fmt, va_list args)
-{
- lda_sieve_vlog(ehandler, i_info, location, fmt, args);
-}
-
-static void lda_sieve_log_vdebug
-(struct sieve_error_handler *ehandler, unsigned int flags ATTR_UNUSED,
- const char *location, const char *fmt, va_list args)
-{
- lda_sieve_vlog(ehandler, i_debug, location, fmt, args);
-}
-
-struct sieve_error_handler *lda_sieve_log_ehandler_create
-(struct sieve_instance *svinst, struct mail_deliver_context *mdctx,
- unsigned int max_errors)
-{
- pool_t pool;
- struct lda_sieve_log_ehandler *ehandler;
-
- pool = pool_alloconly_create("lda_sieve_log_error_handler", 256);
- ehandler = p_new(pool, struct lda_sieve_log_ehandler, 1);
- ehandler->mdctx = mdctx;
-
- sieve_error_handler_init(&ehandler->handler, svinst, pool, max_errors);
-
- ehandler->handler.verror = lda_sieve_log_verror;
- ehandler->handler.vwarning = lda_sieve_log_vwarning;
- ehandler->handler.vinfo = lda_sieve_log_vinfo;
- ehandler->handler.vdebug = lda_sieve_log_vdebug;
-
- return &(ehandler->handler);
-}
diff -r 0dc3cce72225 -r fb765ed84e0e src/plugins/lda-sieve/lda-sieve-log.h
--- a/src/plugins/lda-sieve/lda-sieve-log.h Sun Sep 05 14:24:19 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-/* Copyright (c) 2002-2010 Pigeonhole authors, see the included COPYING file
- */
-
-#ifndef __LDA_SIEVE_LOG
-#define __LDA_SIEVE_LOG
-
-#include "lib.h"
-#include "mail-deliver.h"
-
-struct sieve_error_handler *lda_sieve_log_ehandler_create
More information about the dovecot-cvs
mailing list