From 22b7f005f6fb3403512968d319a3967d8fa40034 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 18 Oct 2011 16:20:09 +0300 Subject: [PATCH] Add initialization for kvstorages after configuration. --- src/kvstorage_config.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/kvstorage_config.c b/src/kvstorage_config.c index 70c9ee182..1fb158ec6 100644 --- a/src/kvstorage_config.c +++ b/src/kvstorage_config.c @@ -25,6 +25,8 @@ #include "main.h" #include "cfg_xml.h" +#define LRU_QUEUES 32 + /* Global hash of storages indexed by id */ GHashTable *storages = NULL; /* Last used id for explicit numbering */ @@ -59,9 +61,46 @@ kvstorage_config_destroy (gpointer k) g_free (kconf->name); } + if (kconf->storage) { + rspamd_kv_storage_destroy (kconf->storage); + } + g_free (kconf); } +/* Init kvstorage */ +static void +kvstorage_init_callback (const gpointer key, const gpointer value, gpointer unused) +{ + struct kvstorage_config *kconf = value; + struct rspamd_kv_cache *cache; + struct rspamd_kv_backend *backend; + struct rspamd_kv_expire *expire; + + switch (kconf->cache.type) { + case KVSTORAGE_TYPE_CACHE_HASH: + cache = rspamd_kv_hash_new (); + break; + case KVSTORAGE_TYPE_CACHE_RADIX: + cache = rspamd_kv_radix_new (); + break; + } + + switch (kconf->backend.type) { + case KVSTORAGE_TYPE_BACKEND_NULL: + backend = NULL; + break; + } + + switch (kconf->expire.type) { + case KVSTORAGE_TYPE_EXPIRE_LRU: + expire = rspamd_lru_expire_new (LRU_QUEUES); + break; + } + + kconf->storage = rspamd_kv_storage_new (kconf->id, kconf->name, cache, backend, expire, + kconf->cache.max_elements, kconf->cache.max_memory); +} /* XML parse callbacks */ /* Called for open tags */ @@ -175,6 +214,7 @@ void kvstorage_xml_end_element (GMarkupParseContext *context, g_hash_table_insert (storages, &kv_parser->current_storage->id, kv_parser->current_storage); kv_parser->state = KVSTORAGE_STATE_INIT; g_markup_parse_context_pop (context); + g_hash_table_foreach (storages, kvstorage_init_callback, NULL); return; } if (*error == NULL) { -- 2.39.5