dovecot-2.2-pigeonhole: lib-sieve: Added script metadata to bina...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Mar 14 17:22:45 UTC 2015


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/5506ad4315b9
changeset: 2012:5506ad4315b9
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Mar 14 18:20:22 2015 +0100
description:
lib-sieve: Added script metadata to binary dump output.

diffstat:

 src/lib-sieve/sieve-binary-dumper.c            |  24 ++++++++++++-
 src/lib-sieve/sieve-script-private.h           |   3 +
 src/lib-sieve/sieve-script.c                   |  44 ++++++++++++++++++++++++++
 src/lib-sieve/sieve-script.h                   |   4 ++
 src/lib-sieve/storage/dict/sieve-dict-script.c |  15 ++++++++
 src/lib-sieve/storage/ldap/sieve-ldap-script.c |  19 +++++++++++
 6 files changed, 106 insertions(+), 3 deletions(-)

diffs (238 lines):

diff -r 0226882e55e1 -r 5506ad4315b9 src/lib-sieve/sieve-binary-dumper.c
--- a/src/lib-sieve/sieve-binary-dumper.c	Sat Mar 14 15:52:15 2015 +0100
+++ b/src/lib-sieve/sieve-binary-dumper.c	Sat Mar 14 18:20:22 2015 +0100
@@ -10,6 +10,7 @@
 #include "sieve-common.h"
 #include "sieve-extensions.h"
 #include "sieve-dump.h"
+#include "sieve-script.h"
 
 #include "sieve-binary-private.h"
 
@@ -96,12 +97,17 @@
 (struct sieve_binary_dumper *dumper, struct ostream *stream, bool verbose)
 {
 	struct sieve_binary *sbin = dumper->dumpenv.sbin;
+	struct sieve_script *script = sieve_binary_script(sbin);
 	struct sieve_dumptime_env *denv = &(dumper->dumpenv);
+	struct sieve_binary_block *sblock;
+	bool success = TRUE;
+	sieve_size_t offset;
 	int count, i;
 
 	dumper->dumpenv.stream = stream;
 
 	/* Dump list of binary blocks */
+
 	if ( verbose ) {
 		count = sieve_binary_block_count(sbin);
 
@@ -117,6 +123,19 @@
 		}
 	}
 
+	/* Dump script metadata */
+
+	sieve_binary_dump_sectionf
+		(denv, "Script metadata (block: %d)", SBIN_SYSBLOCK_SCRIPT_DATA);
+	sblock = sieve_binary_block_get(sbin, SBIN_SYSBLOCK_SCRIPT_DATA);
+
+	T_BEGIN {
+		offset = 0;
+		success = sieve_script_binary_dump_metadata
+			(script, denv, sblock, &offset);
+	} T_END;
+	if ( !success ) return FALSE;
+
 	/* Dump list of used extensions */
 
 	count = sieve_binary_extensions_count(sbin);
@@ -128,8 +147,7 @@
 			const struct sieve_extension *ext = sieve_binary_extension_get_by_index
 				(sbin, i);
 
-			struct sieve_binary_block *sblock = sieve_binary_extension_get_block
-				(sbin, ext);
+			sblock = sieve_binary_extension_get_block(sbin, ext);
 
 			if ( sblock == NULL ) {
 				sieve_binary_dumpf(denv, "%3d: %s (id: %d)\n",
@@ -147,7 +165,7 @@
 	count = sieve_binary_extensions_count(sbin);
 	if ( count > 0 ) {
 		for ( i = 0; i < count; i++ ) {
-			bool success = TRUE;
+			success = TRUE;
 
 			T_BEGIN {
 				const struct sieve_extension *ext = sieve_binary_extension_get_by_index
diff -r 0226882e55e1 -r 5506ad4315b9 src/lib-sieve/sieve-script-private.h
--- a/src/lib-sieve/sieve-script-private.h	Sat Mar 14 15:52:15 2015 +0100
+++ b/src/lib-sieve/sieve-script-private.h	Sat Mar 14 18:20:22 2015 +0100
@@ -27,6 +27,9 @@
 			sieve_size_t *offset);
 	void (*binary_write_metadata)
 		(struct sieve_script *script, struct sieve_binary_block *sblock);
+	int (*binary_dump_metadata)
+		(struct sieve_script *script, struct sieve_dumptime_env *denv,
+			struct sieve_binary_block *sblock, sieve_size_t *offset);
 	struct sieve_binary *(*binary_load)
 		(struct sieve_script *script, enum sieve_error *error_r);
 	int (*binary_save)
diff -r 0226882e55e1 -r 5506ad4315b9 src/lib-sieve/sieve-script.c
--- a/src/lib-sieve/sieve-script.c	Sat Mar 14 15:52:15 2015 +0100
+++ b/src/lib-sieve/sieve-script.c	Sat Mar 14 18:20:22 2015 +0100
@@ -15,6 +15,7 @@
 #include "sieve-limits.h"
 #include "sieve-settings.h"
 #include "sieve-error.h"
+#include "sieve-dump.h"
 #include "sieve-binary.h"
 
 #include "sieve-storage-private.h"
@@ -415,6 +416,49 @@
 	script->v.binary_write_metadata(script, sblock);
 }
 
+bool sieve_script_binary_dump_metadata
+(struct sieve_script *script, struct sieve_dumptime_env *denv,
+	struct sieve_binary_block *sblock, sieve_size_t *offset)
+{
+	struct sieve_binary *sbin = sieve_binary_block_get_binary(sblock);
+	struct sieve_instance *svinst = sieve_binary_svinst(sbin);
+	string_t *storage_class, *location;
+	struct sieve_script *adhoc_script = NULL;
+	unsigned int version;
+	bool result = TRUE;
+
+	/* storage class */
+	if ( !sieve_binary_read_string(sblock, offset, &storage_class) )
+		return FALSE;
+	sieve_binary_dumpf(denv, "class = %s\n", str_c(storage_class));
+
+	/* version */
+	if ( !sieve_binary_read_unsigned(sblock, offset, &version) )
+		return FALSE;
+	sieve_binary_dumpf(denv, "class.version = %d\n", version);
+
+	/* location */
+	if ( !sieve_binary_read_string(sblock, offset, &location) )
+		return FALSE;
+	sieve_binary_dumpf(denv, "location = %s\n", str_c(location));
+	
+	if ( script == NULL ) {
+		script = adhoc_script = sieve_script_create
+			(svinst, str_c(location), NULL, NULL);
+	}
+
+	if ( script != NULL ) {
+		if ( script->v.binary_dump_metadata == NULL )
+			return TRUE;
+
+		result = script->v.binary_dump_metadata(script, denv, sblock, offset);
+	}
+
+	if ( adhoc_script != NULL )
+		sieve_script_unref(&adhoc_script);
+	return result;
+}
+
 struct sieve_binary *sieve_script_binary_load
 (struct sieve_script *script, enum sieve_error *error_r)
 {
diff -r 0226882e55e1 -r 5506ad4315b9 src/lib-sieve/sieve-script.h
--- a/src/lib-sieve/sieve-script.h	Sat Mar 14 15:52:15 2015 +0100
+++ b/src/lib-sieve/sieve-script.h	Sat Mar 14 18:20:22 2015 +0100
@@ -67,6 +67,10 @@
 		sieve_size_t *offset);
 void sieve_script_binary_write_metadata
 	(struct sieve_script *script, struct sieve_binary_block *sblock);
+bool sieve_script_binary_dump_metadata
+	(struct sieve_script *script, struct sieve_dumptime_env *denv,
+		struct sieve_binary_block *sblock, sieve_size_t *offset)
+		ATTR_NULL(1);
 
 struct sieve_binary *sieve_script_binary_load
 	(struct sieve_script *script, enum sieve_error *error_r);
diff -r 0226882e55e1 -r 5506ad4315b9 src/lib-sieve/storage/dict/sieve-dict-script.c
--- a/src/lib-sieve/storage/dict/sieve-dict-script.c	Sat Mar 14 15:52:15 2015 +0100
+++ b/src/lib-sieve/storage/dict/sieve-dict-script.c	Sat Mar 14 18:20:22 2015 +0100
@@ -9,6 +9,7 @@
 
 #include "sieve-common.h"
 #include "sieve-error.h"
+#include "sieve-dump.h"
 #include "sieve-binary.h"
 
 #include "sieve-dict-storage.h"
@@ -181,6 +182,19 @@
 	sieve_binary_emit_cstring(sblock, dscript->data_id);
 }
 
+static int sieve_dict_script_binary_dump_metadata
+(struct sieve_script *script ATTR_UNUSED, struct sieve_dumptime_env *denv,
+	struct sieve_binary_block *sblock, sieve_size_t *offset)
+{
+	string_t *data_id;
+
+	if ( !sieve_binary_read_string(sblock, offset, &data_id) )
+		return FALSE;
+	sieve_binary_dumpf(denv, "dict.data_id = %s\n", str_c(data_id));
+
+	return TRUE;
+}
+
 static const char * sieve_dict_script_get_binpath
 (struct sieve_dict_script *dscript)
 {
@@ -252,6 +266,7 @@
 
 		.binary_read_metadata =sieve_dict_script_binary_read_metadata,
 		.binary_write_metadata = sieve_dict_script_binary_write_metadata,
+		.binary_dump_metadata = sieve_dict_script_binary_dump_metadata,
 		.binary_load = sieve_dict_script_binary_load,
 		.binary_save = sieve_dict_script_binary_save,
 
diff -r 0226882e55e1 -r 5506ad4315b9 src/lib-sieve/storage/ldap/sieve-ldap-script.c
--- a/src/lib-sieve/storage/ldap/sieve-ldap-script.c	Sat Mar 14 15:52:15 2015 +0100
+++ b/src/lib-sieve/storage/ldap/sieve-ldap-script.c	Sat Mar 14 18:20:22 2015 +0100
@@ -13,6 +13,7 @@
 #include "strfuncs.h"
 
 #include "sieve-error.h"
+#include "sieve-dump.h"
 #include "sieve-binary.h"
 
 /*
@@ -208,6 +209,23 @@
 		sieve_binary_emit_cstring(sblock, lscript->modattr);
 }
 
+static int sieve_ldap_script_binary_dump_metadata
+(struct sieve_script *script ATTR_UNUSED, struct sieve_dumptime_env *denv,
+	struct sieve_binary_block *sblock, sieve_size_t *offset)
+{
+	string_t *dn, *modattr;
+
+	if ( !sieve_binary_read_string(sblock, offset, &dn) )
+		return FALSE;
+	sieve_binary_dumpf(denv, "ldap.dn = %s\n", str_c(dn));
+
+	if ( !sieve_binary_read_string(sblock, offset, &modattr) )
+		return FALSE;
+	sieve_binary_dumpf(denv, "ldap.mod_attr = %s\n", str_c(modattr));
+
+	return TRUE;
+}
+
 static const char *sieve_ldap_script_get_binpath
 (struct sieve_ldap_script *lscript)
 {
@@ -279,6 +297,7 @@
 
 		.binary_read_metadata = sieve_ldap_script_binary_read_metadata,
 		.binary_write_metadata = sieve_ldap_script_binary_write_metadata,
+		.binary_dump_metadata = sieve_ldap_script_binary_dump_metadata,
 		.binary_load = sieve_ldap_script_binary_load,
 		.binary_save = sieve_ldap_script_binary_save,
 


More information about the dovecot-cvs mailing list