From 43e1519cc6fd76c240edd3960e341715c7b56751 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Tue, 12 Jan 2010 11:47:18 +0100
Subject: [PATCH] Variables extension: removed public dependency on
 ext-variables-limits.h.

---
 .../plugins/include/ext-include-variables.c   |  8 ++++----
 src/lib-sieve/plugins/variables/cmd-set.c     |  9 +++++----
 .../variables/ext-variables-arguments.c       |  6 +++---
 .../plugins/variables/ext-variables-common.c  | 20 ++++++++++++++-----
 .../plugins/variables/ext-variables-limits.h  | 10 +++++-----
 .../plugins/variables/ext-variables-name.c    |  4 ++--
 .../variables/ext-variables-operands.c        |  5 +++--
 .../plugins/variables/sieve-ext-variables.h   |  6 +++++-
 8 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/src/lib-sieve/plugins/include/ext-include-variables.c b/src/lib-sieve/plugins/include/ext-include-variables.c
index 53847f512..4ef36dae5 100644
--- a/src/lib-sieve/plugins/include/ext-include-variables.c
+++ b/src/lib-sieve/plugins/include/ext-include-variables.c
@@ -46,7 +46,7 @@ struct sieve_variable *ext_include_variable_import_global
 		sieve_command_validate_error(valdtr, cmd,
 			"declaration of new global variable '%s' exceeds the limit "
 			"(max variables: %u)", 
-			variable, SIEVE_VARIABLES_MAX_SCOPE_SIZE);
+			variable, sieve_variables_get_max_scope_size());
 		return NULL;
 	}
 	
@@ -107,10 +107,10 @@ bool ext_include_variables_load
 		return FALSE;
 	}
 
-	if ( count > SIEVE_VARIABLES_MAX_SCOPE_SIZE ) {
+	if ( count > sieve_variables_get_max_scope_size() ) {
 		sieve_sys_error("include: global variable scope size of binary %s "
 			"exceeds the limit (%u > %u)", sieve_binary_path(sbin),
-			count, SIEVE_VARIABLES_MAX_SCOPE_SIZE );
+			count, sieve_variables_get_max_scope_size() );
 		return FALSE;
 	}
 
@@ -228,7 +228,7 @@ bool vnspc_global_variables_validate
 		sieve_argument_validate_error(valdtr, arg, 
 			"(implicit) declaration of new global variable '%s' exceeds the limit "
 			"(max variables: %u)", variable, 
-			SIEVE_VARIABLES_MAX_SCOPE_SIZE);
+			sieve_variables_get_max_scope_size());
 		return FALSE;
 	}
 	
diff --git a/src/lib-sieve/plugins/variables/cmd-set.c b/src/lib-sieve/plugins/variables/cmd-set.c
index a123367e2..5476be283 100644
--- a/src/lib-sieve/plugins/variables/cmd-set.c
+++ b/src/lib-sieve/plugins/variables/cmd-set.c
@@ -19,6 +19,7 @@
 #include "sieve-dump.h"
 
 #include "ext-variables-common.h"
+#include "ext-variables-limits.h"
 #include "ext-variables-modifiers.h"
 
 /* 
@@ -316,8 +317,8 @@ static int cmd_set_operation_execute
 	sieve_runtime_trace(renv, "SET action");
 
 	/* Hold value within limits */
-	if ( str_len(value) > SIEVE_VARIABLES_MAX_VARIABLE_SIZE )
-		str_truncate(value, SIEVE_VARIABLES_MAX_VARIABLE_SIZE);
+	if ( str_len(value) > EXT_VARIABLES_MAX_VARIABLE_SIZE )
+		str_truncate(value, EXT_VARIABLES_MAX_VARIABLE_SIZE);
 
 	T_BEGIN {
 		/* Apply modifiers if necessary (sorted during code generation already) */
@@ -346,8 +347,8 @@ static int cmd_set_operation_execute
 						break;
 
 					/* Hold value within limits */
-					if ( str_len(value) > SIEVE_VARIABLES_MAX_VARIABLE_SIZE )
-						str_truncate(value, SIEVE_VARIABLES_MAX_VARIABLE_SIZE);
+					if ( str_len(value) > EXT_VARIABLES_MAX_VARIABLE_SIZE )
+						str_truncate(value, EXT_VARIABLES_MAX_VARIABLE_SIZE);
 				}
 			}
 		}	
diff --git a/src/lib-sieve/plugins/variables/ext-variables-arguments.c b/src/lib-sieve/plugins/variables/ext-variables-arguments.c
index 49c9c8594..70f91eac0 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-arguments.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-arguments.c
@@ -48,7 +48,7 @@ static bool ext_variables_variable_argument_activate
 		sieve_argument_validate_error(valdtr, arg, 
 			"(implicit) declaration of new variable '%s' exceeds the limit "
 			"(max variables: %u)", variable, 
-			SIEVE_VARIABLES_MAX_SCOPE_SIZE);
+			EXT_VARIABLES_MAX_SCOPE_SIZE);
 		return FALSE;
 	}
 	
@@ -114,10 +114,10 @@ static bool ext_variables_match_value_argument_activate
 		return FALSE;
 	}
 
-	if ( index > SIEVE_VARIABLES_MAX_MATCH_INDEX ) {
+	if ( index > EXT_VARIABLES_MAX_MATCH_INDEX ) {
 		sieve_argument_validate_error(valdtr, arg, 
 			"match value index %u out of range (max: %u)", index, 
-			SIEVE_VARIABLES_MAX_MATCH_INDEX);
+			EXT_VARIABLES_MAX_MATCH_INDEX);
 		return FALSE;
 	} 
 
diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c
index 040412e54..051612c98 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-common.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-common.c
@@ -21,9 +21,19 @@
 #include "sieve-interpreter.h"
 
 #include "ext-variables-common.h"
+#include "ext-variables-limits.h"
 #include "ext-variables-name.h"
 #include "ext-variables-modifiers.h"
 
+/*
+ * Limits
+ */
+
+unsigned int sieve_variables_get_max_scope_size(void)
+{ 
+	return EXT_VARIABLES_MAX_SCOPE_SIZE;
+}
+
 /*
  * Variable scope 
  */
@@ -95,7 +105,7 @@ struct sieve_variable *sieve_variable_scope_declare
 	new_var = p_new(scope->pool, struct sieve_variable, 1);
 	new_var->ext = scope->ext;
 
-	if ( array_count(&scope->variable_index) >= SIEVE_VARIABLES_MAX_SCOPE_SIZE ) {
+	if ( array_count(&scope->variable_index) >= EXT_VARIABLES_MAX_SCOPE_SIZE ) {
 		if ( scope->error_var == NULL ) {
 			new_var->identifier = "@ERROR@";
 			new_var->index = 0;
@@ -311,8 +321,8 @@ bool sieve_variable_assign
 	str_append_str(varval, value);
 
 	/* Just a precaution, caller should prevent this in the first place */
-	if ( str_len(varval) > SIEVE_VARIABLES_MAX_VARIABLE_SIZE )
-		str_truncate(varval, SIEVE_VARIABLES_MAX_VARIABLE_SIZE);
+	if ( str_len(varval) > EXT_VARIABLES_MAX_VARIABLE_SIZE )
+		str_truncate(varval, EXT_VARIABLES_MAX_VARIABLE_SIZE);
 
 	return TRUE;
 }
@@ -510,9 +520,9 @@ bool ext_variables_interpreter_load
 		return FALSE;
 	}
 
-	if ( scope_size > SIEVE_VARIABLES_MAX_SCOPE_SIZE ) {
+	if ( scope_size > EXT_VARIABLES_MAX_SCOPE_SIZE ) {
 		sieve_sys_error("variables: scope size exceeds the limit (%u > %u)", 
-			scope_size, SIEVE_VARIABLES_MAX_SCOPE_SIZE );
+			scope_size, EXT_VARIABLES_MAX_SCOPE_SIZE );
 		return FALSE;
 	}
 	
diff --git a/src/lib-sieve/plugins/variables/ext-variables-limits.h b/src/lib-sieve/plugins/variables/ext-variables-limits.h
index 341300ec3..e1b09a17c 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-limits.h
+++ b/src/lib-sieve/plugins/variables/ext-variables-limits.h
@@ -24,11 +24,11 @@
  *  as a syntax error, which SHOULD be discovered at compile-time.
  */
 
-#define SIEVE_VARIABLES_MAX_SCOPE_SIZE              255
-#define SIEVE_VARIABLES_MAX_VARIABLE_NAME_LEN       64
-#define SIEVE_VARIABLES_MAX_VARIABLE_SIZE           (4 * 1024)
-#define SIEVE_VARIABLES_MAX_NAMESPACE_ELEMENTS      4
+#define EXT_VARIABLES_MAX_SCOPE_SIZE              255
+#define EXT_VARIABLES_MAX_VARIABLE_NAME_LEN       64
+#define EXT_VARIABLES_MAX_VARIABLE_SIZE           (4 * 1024)
+#define EXT_VARIABLES_MAX_NAMESPACE_ELEMENTS      4
 
-#define SIEVE_VARIABLES_MAX_MATCH_INDEX             SIEVE_MAX_MATCH_VALUES
+#define EXT_VARIABLES_MAX_MATCH_INDEX             SIEVE_MAX_MATCH_VALUES
 
 #endif /* __EXT_VARIABLES_LIMITS_H */
diff --git a/src/lib-sieve/plugins/variables/ext-variables-name.c b/src/lib-sieve/plugins/variables/ext-variables-name.c
index 16a166241..2c2d5cf35 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-name.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-name.c
@@ -26,7 +26,7 @@ int ext_variable_name_parse
 
 		/* Acquire current position in the array */
 
-		if ( array_count(vname) >= SIEVE_VARIABLES_MAX_NAMESPACE_ELEMENTS )
+		if ( array_count(vname) >= EXT_VARIABLES_MAX_NAMESPACE_ELEMENTS )
 			return -1;
 
 		cur_element = array_append_space(vname);
@@ -42,7 +42,7 @@ int ext_variable_name_parse
 			p++;
 		
 			while ( p < strend && (*p == '_' || i_isalnum(*p)) ) {
-				if ( str_len(cur_ident) >= SIEVE_VARIABLES_MAX_VARIABLE_NAME_LEN )
+				if ( str_len(cur_ident) >= EXT_VARIABLES_MAX_VARIABLE_NAME_LEN )
 					return -1;
 				str_append_c(cur_ident, *p);
 				p++;
diff --git a/src/lib-sieve/plugins/variables/ext-variables-operands.c b/src/lib-sieve/plugins/variables/ext-variables-operands.c
index 127527049..a3f790414 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-operands.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-operands.c
@@ -19,6 +19,7 @@
 #include "sieve-interpreter.h"
 
 #include "ext-variables-common.h"
+#include "ext-variables-limits.h"
 #include "ext-variables-name.h"
 #include "ext-variables-dump.h"
 #include "ext-variables-operands.h"
@@ -242,8 +243,8 @@ static bool opr_match_value_read
 		
 			if ( *str == NULL ) 
 				*str = t_str_new(0);
-			else if ( str_len(*str) > SIEVE_VARIABLES_MAX_VARIABLE_SIZE ) 
-				str_truncate(*str, SIEVE_VARIABLES_MAX_VARIABLE_SIZE);
+			else if ( str_len(*str) > EXT_VARIABLES_MAX_VARIABLE_SIZE ) 
+				str_truncate(*str, EXT_VARIABLES_MAX_VARIABLE_SIZE);
 		}
 		return TRUE;
 	}
diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h
index 64c83d946..1fefc202c 100644
--- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h
+++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h
@@ -13,7 +13,11 @@
 #include "sieve-objects.h"
 #include "sieve-code.h"
 
-#include "ext-variables-limits.h"
+/*
+ * Limits
+ */
+
+unsigned int sieve_variables_get_max_scope_size(void);
 
 /*
  * Variable extension
-- 
GitLab