dovecot-1.2-sieve: Backported addition of debug error handler fu...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Jan 12 01:07:31 EET 2010
details: http://hg.rename-it.nl/dovecot-1.2-sieve/rev/dbd1fc78eb6b
changeset: 1198:dbd1fc78eb6b
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Jan 12 00:07:21 2010 +0100
description:
Backported addition of debug error handler functions from implementation for Dovecot v2.0.
diffstat:
src/lib-sieve/sieve-error-private.h | 27 ++++-
src/lib-sieve/sieve-error.c | 242 +++++++++++++++++++++++++---------------
src/lib-sieve/sieve-error.h | 13 +-
3 files changed, 187 insertions(+), 95 deletions(-)
diffs (truncated from 553 to 300 lines):
diff -r b6c5359c5c6f -r dbd1fc78eb6b src/lib-sieve/sieve-error-private.h
--- a/src/lib-sieve/sieve-error-private.h Mon Jan 11 19:03:37 2010 +0100
+++ b/src/lib-sieve/sieve-error-private.h Tue Jan 12 00:07:21 2010 +0100
@@ -19,18 +19,20 @@
unsigned int errors;
unsigned int warnings;
- /* Should we copy log to i_error, i_warning and i_info? */
+ /* Should we copy log to i_error, i_warning, i_info and i_debug? */
bool log_master;
- /* Should the errorhandler handle or discard info log?
+ /* Should the errorhandler handle or discard info/debug log?
* (This does not influence the previous setting)
*/
bool log_info;
+ bool log_debug;
sieve_error_vfunc_t verror;
sieve_error_vfunc_t vwarning;
sieve_error_vfunc_t vinfo;
-
+ sieve_error_vfunc_t vdebug;
+
void (*free)
(struct sieve_error_handler *ehandler);
};
@@ -74,6 +76,14 @@
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);
+}
+
static inline void sieve_direct_error
(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, ...)
@@ -110,6 +120,17 @@
va_end(args);
}
+static inline void sieve_direct_debug
+(struct sieve_error_handler *ehandler, const char *location,
+ const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ sieve_direct_vdebug(ehandler, location, fmt, args);
+
+ va_end(args);
+}
#endif /* __SIEVE_ERROR_PRIVATE_H */
diff -r b6c5359c5c6f -r dbd1fc78eb6b src/lib-sieve/sieve-error.c
--- a/src/lib-sieve/sieve-error.c Mon Jan 11 19:03:37 2010 +0100
+++ b/src/lib-sieve/sieve-error.c Tue Jan 12 00:07:21 2010 +0100
@@ -52,22 +52,25 @@
* Main error functions
*/
+static void sieve_vcopy_master
+(const char *location, sieve_error_vfunc_t error_vfunc,
+ const char *fmt, va_list args)
+{
+ va_list args_copy;
+
+ VA_COPY(args_copy, args);
+
+ error_vfunc(_sieve_system_ehandler, location, fmt, args_copy);
+}
+
void sieve_verror
(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
if ( ehandler == NULL ) return;
- if ( ehandler->log_master ) {
- va_list args_copy;
-
- VA_COPY(args_copy, args);
-
- if ( location == NULL || *location == '\0' )
- sieve_sys_error("%s", t_strdup_vprintf(fmt, args_copy));
- else
- sieve_sys_error("%s: %s", location, t_strdup_vprintf(fmt, args_copy));
- }
+ if ( ehandler->log_master )
+ sieve_vcopy_master(location, sieve_verror, fmt, args);
sieve_direct_verror(ehandler, location, fmt, args);
}
@@ -78,17 +81,9 @@
{
if ( ehandler == NULL ) return;
- if ( ehandler->log_master ) {
- va_list args_copy;
+ if ( ehandler->log_master )
+ sieve_vcopy_master(location, sieve_vwarning, fmt, args);
- VA_COPY(args_copy, args);
-
- if ( location == NULL || *location == '\0' )
- sieve_sys_warning("%s", t_strdup_vprintf(fmt, args_copy));
- else
- sieve_sys_warning("%s: %s", location, t_strdup_vprintf(fmt, args_copy));
- }
-
sieve_direct_vwarning(ehandler, location, fmt, args);
}
@@ -98,19 +93,22 @@
{
if ( ehandler == NULL ) return;
- if ( ehandler->log_master ) {
- va_list args_copy;
+ if ( ehandler->log_master )
+ sieve_vcopy_master(location, sieve_vinfo, fmt, args);
- VA_COPY(args_copy, args);
+ sieve_direct_vinfo(ehandler, location, fmt, args);
+}
+void sieve_vdebug
+ (struct sieve_error_handler *ehandler, const char *location,
+ const char *fmt, va_list args)
+{
+ if ( ehandler == NULL ) return;
- if ( location == NULL || *location == '\0' )
- sieve_sys_info("%s", t_strdup_vprintf(fmt, args_copy));
- else
- sieve_sys_info("%s: %s", location, t_strdup_vprintf(fmt, args_copy));
- }
+ if ( ehandler->log_master )
+ sieve_vcopy_master(location, sieve_vdebug, fmt, args);
- sieve_direct_vinfo(ehandler, location, fmt, args);
+ sieve_direct_vdebug(ehandler, location, fmt, args);
}
void sieve_vcritical
@@ -170,6 +168,18 @@
va_end(args);
}
+void sieve_debug
+(struct sieve_error_handler *ehandler, const char *location,
+ const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ T_BEGIN { sieve_vdebug(ehandler, location, fmt, args); } T_END;
+
+ va_end(args);
+}
+
void sieve_critical
(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, ...)
@@ -218,6 +228,12 @@
ehandler->log_info = enable;
}
+void sieve_error_handler_accept_debuglog
+ (struct sieve_error_handler *ehandler, bool enable)
+{
+ ehandler->log_debug = enable;
+}
+
void sieve_error_handler_copy_masterlog
(struct sieve_error_handler *ehandler, bool enable)
{
@@ -318,9 +334,9 @@
{
pool_t pool;
struct sieve_error_handler *ehandler;
-
- /* Pool is not strictly necessary, but other handler types will need a pool,
- * so this one will have one too.
+
+ /* 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));
@@ -330,17 +346,20 @@
ehandler->verror = sieve_master_verror;
ehandler->vwarning = sieve_master_vwarning;
ehandler->vinfo = sieve_master_vinfo;
-
- return ehandler;
+ ehandler->vdebug = sieve_master_vinfo;
+
+ return ehandler;
}
struct sieve_error_handler _sieve_system_ehandler_object = {
NULL, 0, 0, 0, 0,
FALSE,
TRUE,
+ TRUE,
sieve_master_verror,
sieve_master_vwarning,
sieve_master_vinfo,
+ sieve_master_vinfo,
NULL
};
@@ -365,44 +384,52 @@
* - Output errors directly to stderror
*/
+static void sieve_stderr_vmessage
+(struct sieve_error_handler *ehandler ATTR_UNUSED, const char *prefix,
+ const char *location, const char *fmt, va_list args)
+{
+ if ( location == NULL || *location == '\0' )
+ fprintf(stderr, "%s: %s.\n", prefix, t_strdup_vprintf(fmt, args));
+ else
+ fprintf(stderr, "%s: %s: %s.\n", location, prefix, t_strdup_vprintf(fmt, args));
+}
+
static void sieve_stderr_verror
-(struct sieve_error_handler *ehandler ATTR_UNUSED, const char *location,
+(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
- if ( location == NULL || *location == '\0' )
- fprintf(stderr, "error: %s.\n", t_strdup_vprintf(fmt, args));
- else
- fprintf(stderr, "%s: error: %s.\n", location, t_strdup_vprintf(fmt, args));
+ sieve_stderr_vmessage(ehandler, "error", location, fmt, args);
}
static void sieve_stderr_vwarning
-(struct sieve_error_handler *ehandler ATTR_UNUSED, const char *location,
+(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
- if ( location == NULL || *location == '\0' )
- fprintf(stderr, "warning: %s.\n", t_strdup_vprintf(fmt, args));
- else
- fprintf(stderr, "%s: warning: %s.\n", location, t_strdup_vprintf(fmt, args));
+ sieve_stderr_vmessage(ehandler, "warning", location, fmt, args);
}
static void sieve_stderr_vinfo
-(struct sieve_error_handler *ehandler ATTR_UNUSED, const char *location,
+(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
- if ( location == NULL || *location == '\0' )
- fprintf(stderr, "info: %s.\n", t_strdup_vprintf(fmt, args));
- else
- fprintf(stderr, "%s: info: %s.\n", location, t_strdup_vprintf(fmt, args));
+ sieve_stderr_vmessage(ehandler, "info", location, fmt, args);
+}
+
+static void sieve_stderr_vdebug
+(struct sieve_error_handler *ehandler, const char *location,
+ const char *fmt, va_list args)
+{
+ sieve_stderr_vmessage(ehandler, "debug", location, fmt, args);
}
struct sieve_error_handler *sieve_stderr_ehandler_create
-(unsigned int max_errors)
+(unsigned int max_errors)
{
pool_t pool;
struct sieve_error_handler *ehandler;
-
- /* Pool is not strictly necessary, but other handler types will need a pool,
- * so this one will have one too.
+
+ /* Pool is not strictly necessary, but other handler types will need
+ * a pool, so this one will have one too.
*/
pool = pool_alloconly_create
("stderr_error_handler", sizeof(struct sieve_error_handler));
@@ -412,8 +439,9 @@
ehandler->verror = sieve_stderr_verror;
ehandler->vwarning = sieve_stderr_vwarning;
ehandler->vinfo = sieve_stderr_vinfo;
-
- return ehandler;
+ ehandler->vdebug = sieve_stderr_vdebug;
+
+ return ehandler;
More information about the dovecot-cvs
mailing list