dovecot-2.0-pigeonhole: Made vnd.dovecot.debug extension availab...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Mon Jun 6 17:59:44 EEST 2011


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/9d328e6732ff
changeset: 1500:9d328e6732ff
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Jun 06 16:59:39 2011 +0200
description:
Made vnd.dovecot.debug extension available to the LDA plugin instead of only the command line tools.

diffstat:

 Makefile.am                                                |    1 +
 configure.in                                               |    3 +-
 doc/man/sieve-test.1.in                                    |   40 +++--
 src/lib-sieve/Makefile.am                                  |    1 +
 src/lib-sieve/plugins/Makefile.am                          |    1 +
 src/lib-sieve/plugins/vnd.dovecot/Makefile.am              |    3 +
 src/lib-sieve/plugins/vnd.dovecot/debug/Makefile.am        |   15 ++
 src/lib-sieve/plugins/vnd.dovecot/debug/cmd-debug-log.c    |  130 ++++++++++++++++++
 src/lib-sieve/plugins/vnd.dovecot/debug/ext-debug-common.h |   25 +++
 src/lib-sieve/plugins/vnd.dovecot/debug/ext-debug.c        |   77 +++++++++++
 src/lib-sieve/sieve-extensions.c                           |   29 ++-
 src/lib-sieve/sieve-extensions.h                           |    2 +
 src/sieve-tools/Makefile.am                                |    5 +-
 src/sieve-tools/debug/Makefile.am                          |   16 --
 src/sieve-tools/debug/cmd-debug-print.c                    |  130 ------------------
 src/sieve-tools/debug/ext-debug-common.h                   |   21 ---
 src/sieve-tools/debug/ext-debug.c                          |   56 --------
 src/sieve-tools/debug/sieve-ext-debug.h                    |   13 -
 src/sieve-tools/sieve-dump.c                               |    8 +-
 src/sieve-tools/sieve-filter.c                             |    6 +-
 src/sieve-tools/sieve-test.c                               |    6 +-
 src/sieve-tools/sievec.c                                   |    6 +-
 src/testsuite/testsuite-log.c                              |   18 +-
 tests/extensions/vnd.dovecot/debug/execute.svtest          |    6 +
 24 files changed, 324 insertions(+), 294 deletions(-)

diffs (truncated from 928 to 300 lines):

diff -r 560057691dac -r 9d328e6732ff Makefile.am
--- a/Makefile.am	Wed May 11 19:26:57 2011 +0200
+++ b/Makefile.am	Mon Jun 06 16:59:39 2011 +0200
@@ -123,6 +123,7 @@
 	tests/extensions/spamvirustest/virustest.svtest \
 	tests/extensions/spamvirustest/spamtestplus.svtest \
 	tests/extensions/spamvirustest/errors.svtest \
+	tests/extensions/vnd.dovecot/debug/execute.svtest \
 	tests/deprecated/notify/basic.svtest \
 	tests/deprecated/notify/mailto.svtest \
 	tests/deprecated/notify/errors.svtest \
diff -r 560057691dac -r 9d328e6732ff configure.in
--- a/configure.in	Wed May 11 19:26:57 2011 +0200
+++ b/configure.in	Mon Jun 06 16:59:39 2011 +0200
@@ -117,13 +117,14 @@
 src/lib-sieve/plugins/mailbox/Makefile
 src/lib-sieve/plugins/date/Makefile
 src/lib-sieve/plugins/spamvirustest/Makefile
+src/lib-sieve/plugins/vnd.dovecot/Makefile
+src/lib-sieve/plugins/vnd.dovecot/debug/Makefile
 src/lib-sieve-tool/Makefile
 src/lib-sievestorage/Makefile
 src/lib-managesieve/Makefile
 src/plugins/Makefile
 src/plugins/lda-sieve/Makefile
 src/sieve-tools/Makefile
-src/sieve-tools/debug/Makefile
 src/managesieve/Makefile
 src/managesieve-login/Makefile
 src/testsuite/Makefile
diff -r 560057691dac -r 9d328e6732ff doc/man/sieve-test.1.in
--- a/doc/man/sieve-test.1.in	Wed May 11 19:26:57 2011 +0200
+++ b/doc/man/sieve-test.1.in	Mon Jun 06 16:59:39 2011 +0200
@@ -1,5 +1,5 @@
 .\" Copyright (c) 2010-2011 Pigeonhole authors, see the included COPYING file
-.TH "SIEVE\-TEST" 1 "2011-02-23" "Pigeonhole for Dovecot v2.0" "Pigeonhole"
+.TH "SIEVE\-TEST" 1 "2011-06-06" "Pigeonhole for Dovecot v2.0" "Pigeonhole"
 .SH NAME
 sieve\-test \- Pigeonhole\(aqs Sieve script tester
 .\"------------------------------------------------------------------------
@@ -125,10 +125,10 @@
 .SH USAGE
 .SS RUNTIME TRACE DEBUGGING
 .PP
-Using the \fB\-t\fP option, the \fBsieve\-test\fP tool can be configured to print
-detailed trace information on the Sieve script execution to a file or standard
-output. For example, the encountered commands, the performed tests and the
-matched values can be printed.
+Using the \fB\-t\fP option, the \fBsieve\-test\fP tool can be configured to
+print detailed trace information on the Sieve script execution to a file or
+standard output. For example, the encountered commands, the performed tests and
+the matched values can be printed.
 .PP
 The runtime trace can be configured using the \fB\-T\fP option, which can be
 specified multiple times. It can be used as follows:
@@ -165,10 +165,9 @@
 .\"------------------------------------------------------------------------
 .SS DEBUG SIEVE EXTENSION
 .PP
-To improve script debugging, the Sieve command line tools such as
-\fBsieve\-test\fP support a custom Sieve language extension called
-\(aqvnd.dovecot.debug\(aq. It adds the \fBdebug_print\fP command that allows
-printing debug messages to \fBstdout\fP.
+To improve script debugging, this Sieve implementation supports a custom Sieve 
+language extension called \(aqvnd.dovecot.debug\(aq. It adds the \fBdebug_log\fP
+command that allows logging debug messages.
 .PP
 Example:
 .PP
@@ -176,18 +175,21 @@
 .PP
 if header :contains \(dqsubject\(dq \(dqhello\(dq {
 .PP
-  debug_print \(dqSubject header contains hello!\(dq;
+  debug_log \(dqSubject header contains hello!\(dq;
 .PP
 }
 .PP
-Other tools like \fBsievec\fP and \fBsieve\-dump\fP also recognize the
-vnd.dovecot.debug extension. In contrast, the actual Sieve plugin for the
-Dovecot LDA (\fBdovecot\-lda\fR(1)) does not allow the use of the debug
-extension. So, keep in mind that scripts and compiled binaries that refer to de
-debug extension will fail to be run by the Sieve plugin itself.
-.PP
-Note that it is not necessary to enable nor possible to disable the availability
-of the debug extension with the \fB\-x\fP option.
+Tools such as \fBsieve\-test\fP, \fBsievec\fP and \fBsieve\-dump\fP have support
+for the vnd.dovecot.debug extension enabled by default and it is not necessary
+to enable nor possible to disable the availability of the debug extension with
+the \fB\-x\fP option. The logged messages are written to \fBstdout\fP in this
+case.
+
+In contrast, for the actual Sieve plugin for the Dovecot LDA
+(\fBdovecot\-lda\fR(1)) the vnd.dovecot.debug extension needs to be enabled 
+explicitly using the \fIsieve_extensions\fP setting. The messages are then
+logged to the user's private script log file. If used in a global script, the
+messages are logged through the default Dovecot logging facility.
 .\"------------------------------------------------------------------------
 .SH "EXIT STATUS"
 .B sieve\-test
@@ -218,4 +220,4 @@
 .BR dovecot\-lda (1),
 .BR sieve\-dump (1),
 .BR sievec (1),
-.BR pigeonhole (7)
\ No newline at end of file
+.BR pigeonhole (7)
diff -r 560057691dac -r 9d328e6732ff src/lib-sieve/Makefile.am
--- a/src/lib-sieve/Makefile.am	Wed May 11 19:26:57 2011 +0200
+++ b/src/lib-sieve/Makefile.am	Mon Jun 06 16:59:39 2011 +0200
@@ -63,6 +63,7 @@
 	$(extdir)/mailbox/libsieve_ext_mailbox.la \
 	$(extdir)/date/libsieve_ext_date.la \
 	$(extdir)/spamvirustest/libsieve_ext_spamvirustest.la \
+	$(extdir)/vnd.dovecot/debug/libsieve_ext_debug.la \
 	$(unfinished_plugins)
 
 libdovecot_sieve_la_DEPENDENCIES = $(plugins)
diff -r 560057691dac -r 9d328e6732ff src/lib-sieve/plugins/Makefile.am
--- a/src/lib-sieve/plugins/Makefile.am	Wed May 11 19:26:57 2011 +0200
+++ b/src/lib-sieve/plugins/Makefile.am	Mon Jun 06 16:59:39 2011 +0200
@@ -19,6 +19,7 @@
 	mailbox \
 	date \
 	spamvirustest \
+	vnd.dovecot \
 	$(UNFINISHED)
 
 
diff -r 560057691dac -r 9d328e6732ff src/lib-sieve/plugins/vnd.dovecot/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/vnd.dovecot/Makefile.am	Mon Jun 06 16:59:39 2011 +0200
@@ -0,0 +1,3 @@
+SUBDIRS = debug
+
+
diff -r 560057691dac -r 9d328e6732ff src/lib-sieve/plugins/vnd.dovecot/debug/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/vnd.dovecot/debug/Makefile.am	Mon Jun 06 16:59:39 2011 +0200
@@ -0,0 +1,15 @@
+noinst_LTLIBRARIES = libsieve_ext_debug.la
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/src/lib-sieve \
+	$(LIBDOVECOT_INCLUDE)
+
+commands = \
+	cmd-debug-log.c
+
+libsieve_ext_debug_la_SOURCES = \
+	$(commands) \
+	ext-debug.c
+
+noinst_HEADERS = \
+	ext-debug-common.h
diff -r 560057691dac -r 9d328e6732ff src/lib-sieve/plugins/vnd.dovecot/debug/cmd-debug-log.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/vnd.dovecot/debug/cmd-debug-log.c	Mon Jun 06 16:59:39 2011 +0200
@@ -0,0 +1,130 @@
+/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "str-sanitize.h"
+
+#include "sieve-extensions.h"
+#include "sieve-commands.h"
+#include "sieve-code.h"
+
+#include "sieve-validator.h"
+#include "sieve-generator.h"
+#include "sieve-binary.h"
+#include "sieve-interpreter.h"
+#include "sieve-dump.h"
+
+#include "ext-debug-common.h"
+
+/*
+ * Debug_log command
+ *
+ * Syntax
+ *   debug_log <message: string>
+ */
+
+static bool cmd_debug_log_validate
+	(struct sieve_validator *valdtr, struct sieve_command *tst);
+static bool cmd_debug_log_generate
+	(const struct sieve_codegen_env *cgenv,	struct sieve_command *ctx);
+
+const struct sieve_command_def debug_log_command = {
+	"debug_log",
+	SCT_COMMAND,
+	1, 0, FALSE, FALSE,
+	NULL, NULL,
+	cmd_debug_log_validate,
+	cmd_debug_log_generate,
+	NULL
+};
+
+/*
+ * Body operation
+ */
+
+static bool cmd_debug_log_operation_dump
+	(const struct sieve_dumptime_env *denv, sieve_size_t *address);
+static int cmd_debug_log_operation_execute
+	(const struct sieve_runtime_env *renv, sieve_size_t *address);
+
+const struct sieve_operation_def debug_log_operation = {
+	"debug_log",
+	&debug_extension,
+	0,
+	cmd_debug_log_operation_dump,
+	cmd_debug_log_operation_execute
+};
+
+/*
+ * Validation
+ */
+
+static bool cmd_debug_log_validate
+(struct sieve_validator *valdtr, struct sieve_command *tst)
+{
+	struct sieve_ast_argument *arg = tst->first_positional;
+
+	if ( !sieve_validate_positional_argument
+		(valdtr, tst, arg, "message", 1, SAAT_STRING) ) {
+		return FALSE;
+	}
+
+	return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
+}
+
+/*
+ * Code generation
+ */
+
+static bool cmd_debug_log_generate
+(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
+{
+	(void)sieve_operation_emit(cgenv->sblock, cmd->ext, &debug_log_operation);
+
+	/* Generate arguments */
+	return sieve_generate_arguments(cgenv, cmd, NULL);
+}
+
+/*
+ * Code dump
+ */
+
+static bool cmd_debug_log_operation_dump
+(const struct sieve_dumptime_env *denv, sieve_size_t *address)
+{
+	sieve_code_dumpf(denv, "DEBUG_LOG");
+	sieve_code_descend(denv);
+
+	return sieve_opr_string_dump(denv, address, "key list");
+}
+
+/*
+ * Interpretation
+ */
+
+static int cmd_debug_log_operation_execute
+(const struct sieve_runtime_env *renv, sieve_size_t *address)
+{
+	string_t *message;
+	int ret;
+
+	/*
+	 * Read operands
+	 */
+
+	/* Read message */
+
+	if ( (ret=sieve_opr_string_read(renv, address, "message", &message)) <= 0 )
+		return ret;
+
+	/*
+	 * Perform operation
+	 */
+
+	sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "debug_log \"%s\"",
+		str_sanitize(str_c(message), 80));
+
+	sieve_runtime_log(renv, NULL, "DEBUG: %s", str_c(message));
+
+	return SIEVE_EXEC_OK;
+}
diff -r 560057691dac -r 9d328e6732ff src/lib-sieve/plugins/vnd.dovecot/debug/ext-debug-common.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/vnd.dovecot/debug/ext-debug-common.h	Mon Jun 06 16:59:39 2011 +0200
@@ -0,0 +1,25 @@
+/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
+ */
+
+#ifndef __EXT_DEBUG_COMMON_H
+#define __EXT_DEBUG_COMMON_H
+
+/*


More information about the dovecot-cvs mailing list