dovecot-2.0-pigeonhole: lib-sieve: implemented ihave extension.

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sun Jun 26 22:25:51 EEST 2011


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/d6c207acbc8d
changeset: 1506:d6c207acbc8d
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sun Jun 26 22:34:09 2011 +0200
description:
lib-sieve: implemented ihave extension.

diffstat:

 Makefile.am                                    |    1 +
 configure.in                                   |    1 +
 src/lib-sieve/Makefile.am                      |    1 +
 src/lib-sieve/cmd-require.c                    |    8 +-
 src/lib-sieve/plugins/Makefile.am              |    1 +
 src/lib-sieve/plugins/ihave/Makefile.am        |   18 ++
 src/lib-sieve/plugins/ihave/ext-ihave-binary.c |  242 ++++++++++++++++++++++++++++++
 src/lib-sieve/plugins/ihave/ext-ihave-binary.h |   36 ++++
 src/lib-sieve/plugins/ihave/ext-ihave-common.c |   52 ++++++
 src/lib-sieve/plugins/ihave/ext-ihave-common.h |   49 ++++++
 src/lib-sieve/plugins/ihave/ext-ihave.c        |   65 ++++++++
 src/lib-sieve/plugins/ihave/tst-ihave.c        |  154 +++++++++++++++++++
 src/lib-sieve/sieve-ast.c                      |   18 +-
 src/lib-sieve/sieve-ast.h                      |    4 +-
 src/lib-sieve/sieve-extensions.c               |    6 +-
 src/lib-sieve/sieve-extensions.h               |    6 +-
 src/lib-sieve/sieve-validator.c                |   99 ++++++------
 src/lib-sieve/sieve-validator.h                |    7 +-
 tests/extensions/ihave/execute.svtest          |   23 ++
 tests/extensions/ihave/execute/ihave.sieve     |    7 +
 20 files changed, 735 insertions(+), 63 deletions(-)

diffs (truncated from 1052 to 300 lines):

diff -r cf3b58e583ec -r d6c207acbc8d Makefile.am
--- a/Makefile.am	Sun Jun 26 17:07:53 2011 +0200
+++ b/Makefile.am	Sun Jun 26 22:34:09 2011 +0200
@@ -123,6 +123,7 @@
 	tests/extensions/spamvirustest/virustest.svtest \
 	tests/extensions/spamvirustest/spamtestplus.svtest \
 	tests/extensions/spamvirustest/errors.svtest \
+	tests/extensions/ihave/execute.svtest \
 	tests/extensions/vnd.dovecot/debug/execute.svtest \
 	tests/deprecated/notify/basic.svtest \
 	tests/deprecated/notify/mailto.svtest \
diff -r cf3b58e583ec -r d6c207acbc8d configure.in
--- a/configure.in	Sun Jun 26 17:07:53 2011 +0200
+++ b/configure.in	Sun Jun 26 22:34:09 2011 +0200
@@ -117,6 +117,7 @@
 src/lib-sieve/plugins/mailbox/Makefile
 src/lib-sieve/plugins/date/Makefile
 src/lib-sieve/plugins/spamvirustest/Makefile
+src/lib-sieve/plugins/ihave/Makefile
 src/lib-sieve/plugins/vnd.dovecot/Makefile
 src/lib-sieve/plugins/vnd.dovecot/debug/Makefile
 src/lib-sieve-tool/Makefile
diff -r cf3b58e583ec -r d6c207acbc8d src/lib-sieve/Makefile.am
--- a/src/lib-sieve/Makefile.am	Sun Jun 26 17:07:53 2011 +0200
+++ b/src/lib-sieve/Makefile.am	Sun Jun 26 22:34:09 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)/ihave/libsieve_ext_ihave.la \
 	$(extdir)/vnd.dovecot/debug/libsieve_ext_debug.la \
 	$(unfinished_plugins)
 
diff -r cf3b58e583ec -r d6c207acbc8d src/lib-sieve/cmd-require.c
--- a/src/lib-sieve/cmd-require.c	Sun Jun 26 17:07:53 2011 +0200
+++ b/src/lib-sieve/cmd-require.c	Sun Jun 26 22:34:09 2011 +0200
@@ -55,8 +55,8 @@
 	arg = cmd->first_positional;
 	if ( sieve_ast_argument_type(arg) == SAAT_STRING ) {
 		/* Single string */
-		const struct sieve_extension *ext = sieve_validator_extension_load
-			(valdtr, cmd, arg, sieve_ast_argument_str(arg));	
+		const struct sieve_extension *ext = sieve_validator_extension_load_by_name
+			(valdtr, cmd, arg, sieve_ast_argument_strc(arg));	
 
 		if ( ext == NULL ) result = FALSE;
 		
@@ -65,8 +65,8 @@
 		struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
 		
 		while ( stritem != NULL ) {
-			const struct sieve_extension *ext = sieve_validator_extension_load
-				(valdtr, cmd, stritem, sieve_ast_strlist_str(stritem));
+			const struct sieve_extension *ext = sieve_validator_extension_load_by_name
+				(valdtr, cmd, stritem, sieve_ast_strlist_strc(stritem));
 
 			if ( ext == NULL ) result = FALSE;
 	
diff -r cf3b58e583ec -r d6c207acbc8d src/lib-sieve/plugins/Makefile.am
--- a/src/lib-sieve/plugins/Makefile.am	Sun Jun 26 17:07:53 2011 +0200
+++ b/src/lib-sieve/plugins/Makefile.am	Sun Jun 26 22:34:09 2011 +0200
@@ -19,6 +19,7 @@
 	mailbox \
 	date \
 	spamvirustest \
+	ihave \
 	vnd.dovecot \
 	$(UNFINISHED)
 
diff -r cf3b58e583ec -r d6c207acbc8d src/lib-sieve/plugins/ihave/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/ihave/Makefile.am	Sun Jun 26 22:34:09 2011 +0200
@@ -0,0 +1,18 @@
+noinst_LTLIBRARIES = libsieve_ext_ihave.la
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/src/lib-sieve \
+	$(LIBDOVECOT_INCLUDE)
+
+tests = \
+	tst-ihave.c
+
+libsieve_ext_ihave_la_SOURCES = \
+	$(tests) \
+	ext-ihave-binary.c \
+	ext-ihave-common.c \
+	ext-ihave.c
+
+noinst_HEADERS = \
+	ext-ihave-binary.h \
+	ext-ihave-common.h
diff -r cf3b58e583ec -r d6c207acbc8d src/lib-sieve/plugins/ihave/ext-ihave-binary.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/ihave/ext-ihave-binary.c	Sun Jun 26 22:34:09 2011 +0200
@@ -0,0 +1,242 @@
+/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "str.h"
+
+#include "sieve-common.h"
+#include "sieve-extensions.h"
+#include "sieve-error.h"
+#include "sieve-script.h"
+#include "sieve-binary.h"
+#include "sieve-generator.h"
+#include "sieve-interpreter.h"
+#include "sieve-dump.h"
+
+#include "ext-ihave-common.h"
+#include "ext-ihave-binary.h"
+
+/*
+ * Forward declarations
+ */
+ 
+static bool ext_ihave_binary_save
+	(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+static bool ext_ihave_binary_open
+	(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+static bool ext_ihave_binary_up_to_date
+	(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+
+/* 
+ * Binary include extension
+ */
+ 
+const struct sieve_binary_extension ihave_binary_ext = {
+	&ihave_extension,
+	ext_ihave_binary_save,
+	ext_ihave_binary_open,
+	NULL,
+	ext_ihave_binary_up_to_date
+};
+
+/*
+ * Binary context management
+ */
+ 
+struct ext_ihave_binary_context {
+	struct sieve_binary *binary;
+	struct sieve_binary_block *block;
+	
+	ARRAY_DEFINE(missing_extensions, const char *);
+};
+
+static struct ext_ihave_binary_context *ext_ihave_binary_create_context
+(const struct sieve_extension *this_ext, struct sieve_binary *sbin)
+{
+	pool_t pool = sieve_binary_pool(sbin);
+	
+	struct ext_ihave_binary_context *ctx = 
+		p_new(pool, struct ext_ihave_binary_context, 1);
+	
+	ctx->binary = sbin;			
+	p_array_init(&ctx->missing_extensions, pool, 64);
+
+	sieve_binary_extension_set(sbin, this_ext, &ihave_binary_ext, ctx);
+	return ctx;
+}
+
+struct ext_ihave_binary_context *ext_ihave_binary_get_context
+(const struct sieve_extension *this_ext, struct sieve_binary *sbin)
+{	
+	struct ext_ihave_binary_context *ctx = (struct ext_ihave_binary_context *)
+		sieve_binary_extension_get_context(sbin, this_ext);
+	
+	if ( ctx == NULL )
+		ctx = ext_ihave_binary_create_context(this_ext, sbin);
+	
+	return ctx;
+}
+ 
+struct ext_ihave_binary_context *ext_ihave_binary_init
+(const struct sieve_extension *this_ext, struct sieve_binary *sbin, 
+	struct sieve_ast *ast)
+{
+	struct ext_ihave_ast_context *ast_ctx =
+		ext_ihave_get_ast_context(this_ext, ast);
+	struct ext_ihave_binary_context *binctx;
+	const char *const *exts;
+	unsigned int i, count;
+	
+	binctx = ext_ihave_binary_get_context(this_ext, sbin);
+
+	exts = array_get(&ast_ctx->missing_extensions, &count);
+
+	if ( count > 0 ) {
+		pool_t pool = sieve_binary_pool(sbin);
+
+		if ( binctx->block == NULL )
+			binctx->block = sieve_binary_extension_create_block(sbin, this_ext);
+	
+		for ( i = 0; i < count; i++ ) {
+			const char *ext_name = p_strdup(pool, exts[i]);
+
+			array_append(&binctx->missing_extensions, &ext_name, 1);
+		}
+	}	
+				
+	return binctx;
+}
+
+/*
+ * Binary extension
+ */
+
+static bool ext_ihave_binary_save
+(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context)
+{
+	struct ext_ihave_binary_context *binctx = 
+		(struct ext_ihave_binary_context *) context;
+	const char *const *exts;
+	unsigned int count, i;
+
+	exts = array_get(&binctx->missing_extensions, &count);
+
+	if ( binctx->block != NULL )
+		sieve_binary_block_clear(binctx->block);
+	
+	if ( count > 0 ) {
+		if ( binctx->block == NULL )
+			binctx->block = sieve_binary_extension_create_block(sbin, ext);
+
+		sieve_binary_emit_unsigned(binctx->block, count);
+
+		for ( i = 0; i < count; i++ ) {
+			sieve_binary_emit_cstring(binctx->block, exts[i]);
+		}
+	}
+	
+	return TRUE;
+}
+
+static bool ext_ihave_binary_open
+(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context)
+{
+	struct sieve_instance *svinst = ext->svinst;
+	struct ext_ihave_binary_context *binctx = 
+		(struct ext_ihave_binary_context *) context;
+	struct sieve_binary_block *sblock;
+	unsigned int i, count, block_id;
+	sieve_size_t offset;
+	
+	sblock = sieve_binary_extension_get_block(sbin, ext);
+
+	if ( sblock != NULL ) {
+		binctx->block = sblock;
+		block_id = sieve_binary_block_get_id(sblock);
+			
+		offset = 0;	
+		
+		/* Read number of missing extensions to read subsequently */
+		if ( !sieve_binary_read_unsigned(sblock, &offset, &count) ) {
+			sieve_sys_error(svinst, 
+				"ihave: failed to read missing extension count "
+				"from block %d of binary %s", block_id, sieve_binary_path(sbin));
+			return FALSE;
+		}
+		
+		/* Read dependencies */
+		for ( i = 0; i < count; i++ ) {
+			string_t *ext_name;
+			const char *name;
+		
+			if ( !sieve_binary_read_string(sblock, &offset, &ext_name) ) {
+				/* Binary is corrupt, recompile */
+				sieve_sys_error(svinst,
+					"ihave: failed to read missing extension name "
+					"from block %d of binary %s", block_id, sieve_binary_path(sbin)); 
+				return FALSE;
+			}
+
+			name = str_c(ext_name);
+			array_append(&binctx->missing_extensions, &name, 1);
+		}
+	}
+	
+	return TRUE;	
+}
+
+static bool ext_ihave_binary_up_to_date
+(const struct sieve_extension *ext, struct sieve_binary *sbin ATTR_UNUSED, 
+	void *context)
+{
+	struct ext_ihave_binary_context *binctx = 
+		(struct ext_ihave_binary_context *) context;
+	const char *const *exts;
+	unsigned int count, i;
+	
+	exts = array_get(&binctx->missing_extensions, &count);
+	for ( i = 0; i < count; i++ ) {
+		if ( sieve_extension_get_by_name(ext->svinst, exts[i]) != NULL )
+			return FALSE;
+	}
+	
+	return TRUE;
+}
+


More information about the dovecot-cvs mailing list