From ae507162d1db0917a4c0bb2767a16df625b8c613 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 3 Jan 2010 22:24:33 +0100
Subject: [PATCH] Testsuite: added support for removed settings.

---
 src/testsuite/cmd-test-config.c    | 74 +++++++++++++++++++++++++++++-
 src/testsuite/ext-testsuite.c      |  1 +
 src/testsuite/testsuite-common.h   |  2 +
 src/testsuite/testsuite-settings.c | 14 ++++++
 src/testsuite/testsuite-settings.h |  1 +
 5 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/src/testsuite/cmd-test-config.c b/src/testsuite/cmd-test-config.c
index 62e595c22..9ba9f2fa2 100644
--- a/src/testsuite/cmd-test-config.c
+++ b/src/testsuite/cmd-test-config.c
@@ -19,7 +19,8 @@
  *
  * Syntax:   
  *   test_config (
- *     :set <setting: string> <value: string> / 
+ *     :set <setting: string> <value: string> /
+ *     :unset <setting: string> /  
  *     :reload [<extension: string>] )
  */
 
@@ -58,6 +59,21 @@ const struct sieve_operation_def test_config_set_operation = {
 	cmd_test_config_set_operation_execute 
 };
 
+/* Test_message_unset operation */
+
+static bool cmd_test_config_unset_operation_dump
+	(const struct sieve_dumptime_env *denv, sieve_size_t *address);
+static int cmd_test_config_unset_operation_execute
+	(const struct sieve_runtime_env *renv, sieve_size_t *address);
+
+const struct sieve_operation_def test_config_unset_operation = { 
+	"TEST_CONFIG_UNSET",
+	&testsuite_extension, 
+	TESTSUITE_OPERATION_TEST_CONFIG_UNSET,
+	cmd_test_config_unset_operation_dump, 
+	cmd_test_config_unset_operation_execute 
+};
+
 /* Test_message_mailbox operation */
 
 static bool cmd_test_config_reload_operation_dump
@@ -79,12 +95,14 @@ const struct sieve_operation_def test_config_reload_operation = {
 
 enum cmd_test_config_action {
 	CONFIG_ACTION_SET,
+	CONFIG_ACTION_UNSET,
 	CONFIG_ACTION_RELOAD,
 	CONFIG_ACTION_LAST
 };
 
 const struct sieve_operation_def *test_config_operations[] = {
 	&test_config_set_operation,
+	&test_config_unset_operation,
 	&test_config_reload_operation
 };
  
@@ -124,6 +142,8 @@ static bool tag_action_is_instance_of
 
 	if ( strcmp(identifier, "set") == 0 )
 		action = CONFIG_ACTION_SET;
+	else if ( strcmp(identifier, "unset") == 0 )
+		action = CONFIG_ACTION_UNSET;
 	else if ( strcmp(identifier, "reload") == 0 )
 		action = CONFIG_ACTION_RELOAD;
 	else 
@@ -181,6 +201,20 @@ static bool tag_action_validate
 		/* Detach parameters */
 		*arg = sieve_ast_arguments_detach(tag->parameters,2);
 		break;
+	case CONFIG_ACTION_UNSET:
+		/* Check syntax:
+		 *   :unset <setting: string>
+		 */
+		if ( !sieve_validate_tag_parameter
+			(valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, TRUE) ) {
+			return FALSE;
+		}
+
+		/* Detach parameter */
+		tag->parameters = *arg;
+		*arg = sieve_ast_arguments_detach(*arg,1);
+		break;
+
 	case CONFIG_ACTION_RELOAD:
 		/* Check syntax:
 		 *   :reload <extension: string>
@@ -253,6 +287,17 @@ static bool cmd_test_config_set_operation_dump
 		sieve_opr_string_dump(denv, address, "value");
 }
 
+static bool cmd_test_config_unset_operation_dump
+(const struct sieve_dumptime_env *denv, sieve_size_t *address)
+{
+	sieve_code_dumpf(denv, "TEST_CONFIG_UNSET:");
+	
+	sieve_code_descend(denv);
+
+	return 
+		sieve_opr_string_dump(denv, address, "setting");
+}
+
 static bool cmd_test_config_reload_operation_dump
 (const struct sieve_dumptime_env *denv, sieve_size_t *address)
 {
@@ -278,7 +323,7 @@ static int cmd_test_config_set_operation_execute
 	 * Read operands 
 	 */
 
-	/* Settings */
+	/* Setting */
 
 	if ( !sieve_opr_string_read(renv, address, &setting) ) {
 		sieve_runtime_trace_error(renv, "invalid setting operand");
@@ -304,6 +349,31 @@ static int cmd_test_config_set_operation_execute
 	return SIEVE_EXEC_OK;
 }
 
+static int cmd_test_config_unset_operation_execute
+(const struct sieve_runtime_env *renv, sieve_size_t *address)
+{
+	string_t *setting;
+
+	/* 
+	 * Read operands 
+	 */
+
+	if ( !sieve_opr_string_read(renv, address, &setting) ) {
+		sieve_runtime_trace_error(renv, "invalid setting operand");
+		return SIEVE_EXEC_BIN_CORRUPT;
+	}
+
+	/*
+	 * Perform operation
+	 */
+		
+	sieve_runtime_trace(renv, "TEST_CONFIG_UNSET %s", str_c(setting));
+
+	testsuite_setting_unset(str_c(setting));
+
+	return SIEVE_EXEC_OK;
+}
+
 static int cmd_test_config_reload_operation_execute
 (const struct sieve_runtime_env *renv, sieve_size_t *address)
 {
diff --git a/src/testsuite/ext-testsuite.c b/src/testsuite/ext-testsuite.c
index 73e75169b..25cf909c3 100644
--- a/src/testsuite/ext-testsuite.c
+++ b/src/testsuite/ext-testsuite.c
@@ -56,6 +56,7 @@ const struct sieve_operation_def *testsuite_operations[] = {
 	&test_finish_operation,
 	&test_fail_operation,
 	&test_config_set_operation,
+	&test_config_unset_operation,
 	&test_config_reload_operation,
 	&test_set_operation,
 	&test_script_compile_operation,
diff --git a/src/testsuite/testsuite-common.h b/src/testsuite/testsuite-common.h
index cde5f5521..778747363 100644
--- a/src/testsuite/testsuite-common.h
+++ b/src/testsuite/testsuite-common.h
@@ -77,6 +77,7 @@ enum testsuite_operation_code {
 	TESTSUITE_OPERATION_TEST_FINISH,
 	TESTSUITE_OPERATION_TEST_FAIL,
 	TESTSUITE_OPERATION_TEST_CONFIG_SET,
+	TESTSUITE_OPERATION_TEST_CONFIG_UNSET,
 	TESTSUITE_OPERATION_TEST_CONFIG_RELOAD,
 	TESTSUITE_OPERATION_TEST_SET,
 	TESTSUITE_OPERATION_TEST_SCRIPT_COMPILE,
@@ -99,6 +100,7 @@ extern const struct sieve_operation_def test_operation;
 extern const struct sieve_operation_def test_finish_operation;
 extern const struct sieve_operation_def test_fail_operation;
 extern const struct sieve_operation_def test_config_set_operation;
+extern const struct sieve_operation_def test_config_unset_operation;
 extern const struct sieve_operation_def test_config_reload_operation;
 extern const struct sieve_operation_def test_set_operation;
 extern const struct sieve_operation_def test_script_compile_operation;
diff --git a/src/testsuite/testsuite-settings.c b/src/testsuite/testsuite-settings.c
index ee3f2afe2..3d928fc3d 100644
--- a/src/testsuite/testsuite-settings.c
+++ b/src/testsuite/testsuite-settings.c
@@ -73,3 +73,17 @@ void testsuite_setting_set(const char *identifier, const char *value)
 		hash_table_insert(settings, (void *) identifier, (void *) setting);
 	}
 }
+
+void testsuite_setting_unset(const char *identifier)
+{
+	struct testsuite_setting *setting = (struct testsuite_setting *) 
+		hash_table_lookup(settings, identifier);
+
+	if ( setting != NULL ) {
+		i_free(setting->identifier);
+		i_free(setting->value);
+		i_free(setting);
+	}
+
+	hash_table_remove(settings, identifier);
+}
diff --git a/src/testsuite/testsuite-settings.h b/src/testsuite/testsuite-settings.h
index 364443b2f..badf95bad 100644
--- a/src/testsuite/testsuite-settings.h
+++ b/src/testsuite/testsuite-settings.h
@@ -11,5 +11,6 @@ void testsuite_settings_deinit(void);
 
 const char *testsuite_setting_get(void *context, const char *identifier);
 void testsuite_setting_set(const char *identifier, const char *value);
+void testsuite_setting_unset(const char *identifier);
 
 #endif /* __TESTSUITE_SETTINGS_H */
-- 
GitLab