summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/testsuite/testsuite-settings.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
commit0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch)
tree3f3789daa2f6db22da6e55e92bee0062a7d613fe /pigeonhole/src/testsuite/testsuite-settings.c
parentInitial commit. (diff)
downloaddovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz
dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/testsuite/testsuite-settings.c')
-rw-r--r--pigeonhole/src/testsuite/testsuite-settings.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/pigeonhole/src/testsuite/testsuite-settings.c b/pigeonhole/src/testsuite/testsuite-settings.c
new file mode 100644
index 0000000..9d3c872
--- /dev/null
+++ b/pigeonhole/src/testsuite/testsuite-settings.c
@@ -0,0 +1,96 @@
+/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "hash.h"
+#include "imem.h"
+#include "strfuncs.h"
+#include "mail-user.h"
+
+#include "sieve-common.h"
+
+#include "testsuite-common.h"
+#include "testsuite-mailstore.h"
+#include "testsuite-settings.h"
+
+struct testsuite_setting {
+ char *identifier;
+ char *value;
+};
+
+static HASH_TABLE(const char *, struct testsuite_setting *) settings;
+
+static const char *testsuite_setting_get
+ (void *context, const char *identifier);
+
+void testsuite_settings_init(void)
+{
+ hash_table_create(&settings, default_pool, 0, str_hash, strcmp);
+
+ sieve_tool_set_setting_callback(sieve_tool, testsuite_setting_get, NULL);
+}
+
+void testsuite_settings_deinit(void)
+{
+ struct hash_iterate_context *itx =
+ hash_table_iterate_init(settings);
+ const char *key;
+ struct testsuite_setting *setting;
+
+ while ( hash_table_iterate(itx, settings, &key, &setting) ) {
+ i_free(setting->identifier);
+ i_free(setting->value);
+ i_free(setting);
+ }
+
+ hash_table_iterate_deinit(&itx);
+
+ hash_table_destroy(&settings);
+}
+
+static const char *testsuite_setting_get
+(void *context ATTR_UNUSED, const char *identifier)
+{
+ struct testsuite_setting *setting;
+ struct mail_user *user;
+
+ setting = hash_table_lookup(settings, identifier);
+ if ( setting != NULL )
+ return setting->value;
+
+ user = testsuite_mailstore_get_user();
+ if ( user == NULL )
+ return NULL;
+ return mail_user_plugin_getenv(user, identifier);
+}
+
+void testsuite_setting_set(const char *identifier, const char *value)
+{
+ struct testsuite_setting *setting =
+ hash_table_lookup(settings, identifier);
+
+ if ( setting != NULL ) {
+ i_free(setting->value);
+ setting->value = i_strdup(value);
+ } else {
+ setting = i_new(struct testsuite_setting, 1);
+ setting->identifier = i_strdup(identifier);
+ setting->value = i_strdup(value);
+
+ hash_table_insert(settings, identifier, setting);
+ }
+}
+
+void testsuite_setting_unset(const char *identifier)
+{
+ struct testsuite_setting *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);
+ }
+}