From 1a10419a6e63e3b4e526dfdb8c52a7e2ff0f37dd Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Mon, 14 Jul 2008 12:55:35 +0200
Subject: [PATCH] Previous change in extension interface for implicit side
 effect support broke include extension.

---
 src/lib-sieve/ext-encoded-character.c         |  2 +-
 src/lib-sieve/ext-envelope.c                  |  2 +-
 src/lib-sieve/ext-fileinto.c                  |  2 +-
 src/lib-sieve/ext-reject.c                    |  2 +-
 src/lib-sieve/plugins/body/ext-body.c         |  2 +-
 .../ext-cmp-i-ascii-numeric.c                 |  3 +--
 src/lib-sieve/plugins/copy/ext-copy.c         |  3 +--
 .../plugins/imapflags/ext-imapflags.c         |  2 +-
 .../plugins/include/ext-include-common.c      | 11 +++++-----
 .../plugins/include/ext-include-common.h      |  2 +-
 src/lib-sieve/plugins/include/ext-include.c   | 11 +++++-----
 src/lib-sieve/plugins/regex/ext-regex.c       |  3 +--
 .../plugins/relational/ext-relational.c       |  3 +--
 .../plugins/subaddress/ext-subaddress.c       |  3 +--
 src/lib-sieve/plugins/vacation/ext-vacation.c |  2 +-
 .../plugins/variables/ext-variables.c         | 11 +++++-----
 src/lib-sieve/sieve-actions.c                 |  2 +-
 src/lib-sieve/sieve-address-parts.c           |  3 +--
 src/lib-sieve/sieve-comparators.c             |  3 +--
 src/lib-sieve/sieve-extensions.c              |  8 ++++----
 src/lib-sieve/sieve-extensions.h              |  1 +
 src/lib-sieve/sieve-interpreter.c             | 20 +++++++++++++++++++
 src/lib-sieve/sieve-match-types.c             |  3 +--
 src/testsuite/ext-testsuite.c                 |  2 +-
 24 files changed, 61 insertions(+), 45 deletions(-)

diff --git a/src/lib-sieve/ext-encoded-character.c b/src/lib-sieve/ext-encoded-character.c
index 3c5c7aa48..d23a59a7d 100644
--- a/src/lib-sieve/ext-encoded-character.c
+++ b/src/lib-sieve/ext-encoded-character.c
@@ -28,7 +28,7 @@ struct sieve_extension encoded_character_extension = {
 	"encoded-character", 
 	ext_encoded_character_load,
 	ext_encoded_character_validator_load, 
-	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
 	SIEVE_EXT_DEFINE_NO_OPERANDS
 };
diff --git a/src/lib-sieve/ext-envelope.c b/src/lib-sieve/ext-envelope.c
index 4da197ff6..035288e51 100644
--- a/src/lib-sieve/ext-envelope.c
+++ b/src/lib-sieve/ext-envelope.c
@@ -54,7 +54,7 @@ const struct sieve_extension envelope_extension = {
 	"envelope", 
 	ext_envelope_load,
 	ext_envelope_validator_load, 
-	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_OPERATION(envelope_operation), 
 	SIEVE_EXT_DEFINE_NO_OPERANDS 
 };
diff --git a/src/lib-sieve/ext-fileinto.c b/src/lib-sieve/ext-fileinto.c
index ff8f4ecfd..0f88ed512 100644
--- a/src/lib-sieve/ext-fileinto.c
+++ b/src/lib-sieve/ext-fileinto.c
@@ -48,7 +48,7 @@ const struct sieve_extension fileinto_extension = {
 	"fileinto", 
 	ext_fileinto_load,
 	ext_fileinto_validator_load, 
-	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_OPERATION(fileinto_operation), 
 	SIEVE_EXT_DEFINE_NO_OPERANDS	
 };
diff --git a/src/lib-sieve/ext-reject.c b/src/lib-sieve/ext-reject.c
index f64c992fe..bd044cbbc 100644
--- a/src/lib-sieve/ext-reject.c
+++ b/src/lib-sieve/ext-reject.c
@@ -54,7 +54,7 @@ struct sieve_extension reject_extension = {
 	"reject", 
 	ext_reject_load,
 	ext_reject_validator_load, 
-	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_OPERATION(reject_operation), 
 	SIEVE_EXT_DEFINE_NO_OPERANDS
 };
diff --git a/src/lib-sieve/plugins/body/ext-body.c b/src/lib-sieve/plugins/body/ext-body.c
index c64a75beb..1b6d218ac 100644
--- a/src/lib-sieve/plugins/body/ext-body.c
+++ b/src/lib-sieve/plugins/body/ext-body.c
@@ -66,7 +66,7 @@ const struct sieve_extension body_extension = {
 	"body", 
 	ext_body_load,
 	ext_body_validator_load, 
-	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_OPERATION(body_operation), 
 	SIEVE_EXT_DEFINE_NO_OPERANDS
 };
diff --git a/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c b/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c
index ff70366ac..5ccd18c9e 100644
--- a/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c
+++ b/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c
@@ -33,8 +33,7 @@ const struct sieve_extension comparator_i_ascii_numeric_extension = {
 	"comparator-i;ascii-numeric", 
 	ext_cmp_i_ascii_numeric_load,
 	ext_cmp_i_ascii_numeric_validator_load,
-	NULL, 
-	NULL,
+	NULL, NULL, NULL,
 	ext_cmp_i_ascii_numeric_binary_load,  
 	NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
diff --git a/src/lib-sieve/plugins/copy/ext-copy.c b/src/lib-sieve/plugins/copy/ext-copy.c
index ce4faa81b..a7e659dee 100644
--- a/src/lib-sieve/plugins/copy/ext-copy.c
+++ b/src/lib-sieve/plugins/copy/ext-copy.c
@@ -35,8 +35,7 @@ const struct sieve_extension copy_extension = {
 	"copy", 
 	ext_copy_load,
 	ext_copy_validator_load, 
-	NULL, 
-	NULL,
+	NULL, NULL, NULL,
 	ext_copy_binary_load, 
 	NULL, 
 	SIEVE_EXT_DEFINE_NO_OPERATIONS,
diff --git a/src/lib-sieve/plugins/imapflags/ext-imapflags.c b/src/lib-sieve/plugins/imapflags/ext-imapflags.c
index 8dcfcd4e8..7fa2c3f6f 100644
--- a/src/lib-sieve/plugins/imapflags/ext-imapflags.c
+++ b/src/lib-sieve/plugins/imapflags/ext-imapflags.c
@@ -59,7 +59,7 @@ const struct sieve_extension imapflags_extension = {
 	"imap4flags", 
 	ext_imapflags_load,
 	ext_imapflags_validator_load, 
-	NULL, 
+	NULL, NULL,
 	ext_imapflags_runtime_load, 
 	ext_imapflags_binary_load,
 	NULL,
diff --git a/src/lib-sieve/plugins/include/ext-include-common.c b/src/lib-sieve/plugins/include/ext-include-common.c
index 6b1c4ccd3..c32890662 100644
--- a/src/lib-sieve/plugins/include/ext-include-common.c
+++ b/src/lib-sieve/plugins/include/ext-include-common.c
@@ -167,18 +167,19 @@ static inline struct ext_include_interpreter_context *
 	return ctx;
 }
 
-void ext_include_runtime_context_init
-(const struct sieve_runtime_env *renv)
+void ext_include_interpreter_context_init
+(struct sieve_interpreter *interp)
 {
 	struct ext_include_interpreter_context *ctx = 
-		ext_include_get_interpreter_context(renv->interp);
+		ext_include_get_interpreter_context(interp);
+	struct sieve_script *script = sieve_interpreter_script(interp);
 	
 	if ( ctx == NULL ) {
 		ctx = ext_include_create_interpreter_context
-			(renv->interp, NULL, renv->script, SBIN_SYSBLOCK_MAIN_PROGRAM);
+			(interp, NULL, script, SBIN_SYSBLOCK_MAIN_PROGRAM);
 		
 		sieve_interpreter_extension_set_context
-			(renv->interp, ext_include_my_id, (void *) ctx);		
+			(interp, ext_include_my_id, (void *) ctx);		
 	}
 }
 
diff --git a/src/lib-sieve/plugins/include/ext-include-common.h b/src/lib-sieve/plugins/include/ext-include-common.h
index 35a2b8094..2845de5bf 100644
--- a/src/lib-sieve/plugins/include/ext-include-common.h
+++ b/src/lib-sieve/plugins/include/ext-include-common.h
@@ -55,7 +55,7 @@ bool ext_include_generate_include
 
 /* Interpreter */
 
-void ext_include_runtime_context_init(const struct sieve_runtime_env *renv);
+void ext_include_interpreter_context_init(struct sieve_interpreter *interp);
 
 bool ext_include_execute_include
 	(const struct sieve_runtime_env *renv, unsigned int block_id);
diff --git a/src/lib-sieve/plugins/include/ext-include.c b/src/lib-sieve/plugins/include/ext-include.c
index d9eb0cfb3..4592de588 100644
--- a/src/lib-sieve/plugins/include/ext-include.c
+++ b/src/lib-sieve/plugins/include/ext-include.c
@@ -33,7 +33,7 @@ static bool ext_include_load(int ext_id);
 static bool ext_include_validator_load(struct sieve_validator *validator);
 static bool ext_include_generator_load(struct sieve_generator *gentr);
 static bool ext_include_binary_load(struct sieve_binary *sbin);
-static bool ext_include_runtime_load(const struct sieve_runtime_env *renv);
+static bool ext_include_interpreter_load(struct sieve_interpreter *interp);
 
 /* Operations */
 
@@ -54,7 +54,8 @@ const struct sieve_extension include_extension = {
 	ext_include_load,
 	ext_include_validator_load, 
 	ext_include_generator_load,
-	ext_include_runtime_load, 
+	ext_include_interpreter_load, 
+	NULL,
 	ext_include_binary_load, 
 	ext_include_binary_dump,
 	SIEVE_EXT_DEFINE_OPERATIONS(ext_include_operations),
@@ -92,10 +93,10 @@ static bool ext_include_generator_load(struct sieve_generator *gentr)
 
 /* Load extension into interpreter */
 
-static bool ext_include_runtime_load
-(const struct sieve_runtime_env *renv)
+static bool ext_include_interpreter_load
+(struct sieve_interpreter *interp)
 {
-	ext_include_runtime_context_init(renv);
+	ext_include_interpreter_context_init(interp);
 	
 	return TRUE;
 }
diff --git a/src/lib-sieve/plugins/regex/ext-regex.c b/src/lib-sieve/plugins/regex/ext-regex.c
index 28ce14413..e3fb99bce 100644
--- a/src/lib-sieve/plugins/regex/ext-regex.c
+++ b/src/lib-sieve/plugins/regex/ext-regex.c
@@ -51,8 +51,7 @@ const struct sieve_extension regex_extension = {
 	"regex", 
 	ext_regex_load,
 	ext_regex_validator_load,
-	NULL, 
-	NULL,
+	NULL, NULL, NULL,
 	ext_regex_binary_load,
 	NULL,  
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
diff --git a/src/lib-sieve/plugins/relational/ext-relational.c b/src/lib-sieve/plugins/relational/ext-relational.c
index fdecfe5e9..220c5e578 100644
--- a/src/lib-sieve/plugins/relational/ext-relational.c
+++ b/src/lib-sieve/plugins/relational/ext-relational.c
@@ -48,8 +48,7 @@ const struct sieve_extension relational_extension = {
 	"relational", 
 	ext_relational_load,
 	ext_relational_validator_load,
-	NULL, 
-	NULL,
+	NULL, NULL, NULL,
 	ext_relational_binary_load,  
 	NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
diff --git a/src/lib-sieve/plugins/subaddress/ext-subaddress.c b/src/lib-sieve/plugins/subaddress/ext-subaddress.c
index 8a3851136..369eb54d6 100644
--- a/src/lib-sieve/plugins/subaddress/ext-subaddress.c
+++ b/src/lib-sieve/plugins/subaddress/ext-subaddress.c
@@ -41,8 +41,7 @@ const struct sieve_extension subaddress_extension = {
 	"subaddress", 
 	ext_subaddress_load,
 	ext_subaddress_validator_load,
-	NULL,
-	NULL,
+	NULL, NULL, NULL,
 	ext_subaddress_binary_load,
 	NULL,  
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
diff --git a/src/lib-sieve/plugins/vacation/ext-vacation.c b/src/lib-sieve/plugins/vacation/ext-vacation.c
index d3f7cf64d..dad01342c 100644
--- a/src/lib-sieve/plugins/vacation/ext-vacation.c
+++ b/src/lib-sieve/plugins/vacation/ext-vacation.c
@@ -39,7 +39,7 @@ const struct sieve_extension vacation_extension = {
 	"vacation", 
 	ext_vacation_load,
 	ext_vacation_validator_load, 
-	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_OPERATION(vacation_operation),
 	SIEVE_EXT_DEFINE_NO_OPERANDS
 };
diff --git a/src/lib-sieve/plugins/variables/ext-variables.c b/src/lib-sieve/plugins/variables/ext-variables.c
index 4edfa9b6d..a147e4211 100644
--- a/src/lib-sieve/plugins/variables/ext-variables.c
+++ b/src/lib-sieve/plugins/variables/ext-variables.c
@@ -36,7 +36,7 @@
 static bool ext_variables_load(int ext_id);
 static bool ext_variables_validator_load(struct sieve_validator *validator);
 static bool ext_variables_binary_load(struct sieve_binary *sbin);
-static bool ext_variables_runtime_load(const struct sieve_runtime_env *renv);
+static bool ext_variables_interpreter_load(struct sieve_interpreter *interp);
 
 /* Commands */
 
@@ -70,7 +70,8 @@ struct sieve_extension variables_extension = {
 	ext_variables_load,
 	ext_variables_validator_load, 
 	NULL, 
-	ext_variables_runtime_load, 
+	ext_variables_interpreter_load,
+	NULL, 
 	ext_variables_binary_load,
 	NULL,
 	SIEVE_EXT_DEFINE_OPERATIONS(ext_variables_operations), 
@@ -111,10 +112,10 @@ static bool ext_variables_binary_load
 
 /* Load extension into interpreter */
 
-static bool ext_variables_runtime_load
-	(const struct sieve_runtime_env *renv)
+static bool ext_variables_interpreter_load
+	(struct sieve_interpreter *interp)
 {
-	ext_variables_interpreter_initialize(renv->interp);
+	ext_variables_interpreter_initialize(interp);
 
 	return TRUE;
 }
diff --git a/src/lib-sieve/sieve-actions.c b/src/lib-sieve/sieve-actions.c
index 844f9760d..c5cb0f7e7 100644
--- a/src/lib-sieve/sieve-actions.c
+++ b/src/lib-sieve/sieve-actions.c
@@ -43,7 +43,7 @@ static bool seffect_binary_load(struct sieve_binary *sbin);
 const struct sieve_extension side_effects_extension = {
 	"@side-effects",
 	seffect_extension_load,
-	NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL,
 	seffect_binary_load,
 	NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, /* Opcode is hardcoded */
diff --git a/src/lib-sieve/sieve-address-parts.c b/src/lib-sieve/sieve-address-parts.c
index 9d72a66f4..e52b07a7d 100644
--- a/src/lib-sieve/sieve-address-parts.c
+++ b/src/lib-sieve/sieve-address-parts.c
@@ -58,8 +58,7 @@ const struct sieve_extension address_part_extension = {
 	"@address-parts",
 	addrp_extension_load,
 	addrp_validator_load,
-	NULL,
-	NULL, 
+	NULL, NULL, NULL, 
 	addrp_binary_load,
 	NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS,
diff --git a/src/lib-sieve/sieve-comparators.c b/src/lib-sieve/sieve-comparators.c
index 198840bf3..ae49a4399 100644
--- a/src/lib-sieve/sieve-comparators.c
+++ b/src/lib-sieve/sieve-comparators.c
@@ -69,8 +69,7 @@ const struct sieve_extension comparator_extension = {
 	"@comparators",
 	cmp_extension_load,
 	cmp_validator_load,
-	NULL, 
-	NULL,
+	NULL, NULL, NULL,
 	cmp_binary_load,
 	NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS,
diff --git a/src/lib-sieve/sieve-extensions.c b/src/lib-sieve/sieve-extensions.c
index c349db5dc..f86b6e67e 100644
--- a/src/lib-sieve/sieve-extensions.c
+++ b/src/lib-sieve/sieve-extensions.c
@@ -30,14 +30,14 @@ const unsigned int sieve_preloaded_extensions_count =
 
 static const struct sieve_extension comparator_i_octet_extension = {
 	"comparator-i;octet",
-	NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
 	SIEVE_EXT_DEFINE_NO_OPERANDS
 };
 
 static const struct sieve_extension comparator_i_ascii_casemap_extension = {
 	"comparator-i;ascii-casemap",
-	NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS, 
 	SIEVE_EXT_DEFINE_NO_OPERANDS
 };
@@ -202,8 +202,8 @@ static bool _list_extension(const struct sieve_extension *ext)
 	if ( *ext->name == '@' ) return FALSE;
 
 	if ( ext->validator_load == NULL && ext->generator_load == NULL &&
-		ext->binary_load == NULL && ext->runtime_load == NULL &&
-		ext->load == NULL && 
+		ext->binary_load == NULL && ext->interpreter_load == NULL &&
+		ext->runtime_load == NULL && ext->load == NULL &&
 		ext->operations.count == 0 && ext->operands.count == 0 ) {
 		return FALSE;
 	}
diff --git a/src/lib-sieve/sieve-extensions.h b/src/lib-sieve/sieve-extensions.h
index 0f5bff415..d60dc9067 100644
--- a/src/lib-sieve/sieve-extensions.h
+++ b/src/lib-sieve/sieve-extensions.h
@@ -20,6 +20,7 @@ struct sieve_extension {
 
 	bool (*validator_load)(struct sieve_validator *validator);	
 	bool (*generator_load)(struct sieve_generator *generator);
+	bool (*interpreter_load)(struct sieve_interpreter *interpreter);
 	
 	bool (*runtime_load)(const struct sieve_runtime_env *renv);
 	
diff --git a/src/lib-sieve/sieve-interpreter.c b/src/lib-sieve/sieve-interpreter.c
index 067a5b56c..15e3b43d9 100644
--- a/src/lib-sieve/sieve-interpreter.c
+++ b/src/lib-sieve/sieve-interpreter.c
@@ -48,6 +48,9 @@ struct sieve_interpreter {
 struct sieve_interpreter *sieve_interpreter_create
 (struct sieve_binary *sbin, struct sieve_error_handler *ehandler) 
 {
+	unsigned int i;
+	int idx;
+
 	pool_t pool;
 	struct sieve_interpreter *interp;
 	
@@ -66,6 +69,23 @@ struct sieve_interpreter *sieve_interpreter_create
 	interp->pc = 0;
 
 	p_array_init(&interp->ext_contexts, pool, 4);
+
+	/* Pre-load core language features implemented as 'extensions' */
+	for ( i = 0; i < sieve_preloaded_extensions_count; i++ ) {
+		const struct sieve_extension *ext = sieve_preloaded_extensions[i];
+		
+		if ( ext->interpreter_load != NULL )
+			(void)ext->interpreter_load(interp);		
+	}
+
+	/* Load other extensions listed in the binary */
+	for ( idx = 0; idx < sieve_binary_extensions_count(sbin); idx++ ) {
+		const struct sieve_extension *ext = 
+			sieve_binary_extension_get_by_index(sbin, idx, NULL);
+		
+		if ( ext->interpreter_load != NULL )
+			ext->interpreter_load(interp);
+	}
 	
 	return interp;
 }
diff --git a/src/lib-sieve/sieve-match-types.c b/src/lib-sieve/sieve-match-types.c
index 8a710e4c3..437dbb26a 100644
--- a/src/lib-sieve/sieve-match-types.c
+++ b/src/lib-sieve/sieve-match-types.c
@@ -55,8 +55,7 @@ const struct sieve_extension match_type_extension = {
 	"@match-types",
 	mtch_extension_load,
 	mtch_validator_load,
-	NULL,
-	NULL,
+	NULL, NULL, NULL,
 	mtch_binary_load,
 	NULL,
 	SIEVE_EXT_DEFINE_NO_OPERATIONS,
diff --git a/src/testsuite/ext-testsuite.c b/src/testsuite/ext-testsuite.c
index 7bccc2a33..bc2ccaec4 100644
--- a/src/testsuite/ext-testsuite.c
+++ b/src/testsuite/ext-testsuite.c
@@ -62,7 +62,7 @@ const struct sieve_extension testsuite_extension = {
 	ext_testsuite_load,
 	ext_testsuite_validator_load,
 	ext_testsuite_generator_load,
-	NULL,
+	NULL, NULL,
 	ext_testsuite_binary_load, 
 	NULL, 
 	SIEVE_EXT_DEFINE_OPERATIONS(testsuite_operations),
-- 
GitLab