From 7448425afed57c354987d1a340cb58e45d24d9d5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 24 Apr 2018 15:57:20 +0100 Subject: [PATCH] [Fix] Add resolving version of radix map helper --- src/libserver/cfg_utils.c | 4 ++-- src/libutil/map_helpers.c | 28 ++++++++++++++++++++++++++++ src/libutil/map_helpers.h | 8 ++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 69dc3577e..1a2f473e7 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -1798,7 +1798,7 @@ rspamd_config_radix_from_ucl (struct rspamd_config *cfg, else { /* Just a list */ *target = rspamd_map_helper_new_radix (NULL); - rspamd_map_helper_insert_radix (*target, str, ""); + rspamd_map_helper_insert_radix_resolve (*target, str, ""); } break; case UCL_OBJECT: @@ -1822,7 +1822,7 @@ rspamd_config_radix_from_ucl (struct rspamd_config *cfg, *target = rspamd_map_helper_new_radix (NULL); } - rspamd_map_helper_insert_radix (*target, str, ""); + rspamd_map_helper_insert_radix_resolve (*target, str, ""); } ucl_object_iterate_free (it); diff --git a/src/libutil/map_helpers.c b/src/libutil/map_helpers.c index dbbe70e84..7bb442a97 100644 --- a/src/libutil/map_helpers.c +++ b/src/libutil/map_helpers.c @@ -443,6 +443,34 @@ rspamd_map_helper_insert_radix (gpointer st, gconstpointer key, gconstpointer va rspamd_radix_add_iplist (key, ",", r->trie, val, FALSE); } +void +rspamd_map_helper_insert_radix_resolve (gpointer st, gconstpointer key, gconstpointer value) +{ + struct rspamd_radix_map_helper *r = (struct rspamd_radix_map_helper *)st; + struct rspamd_map_helper_value *val; + gsize vlen; + khiter_t k; + gconstpointer nk; + gint res; + + vlen = strlen (value); + val = rspamd_mempool_alloc0 (r->pool, sizeof (*val) + + vlen + 1); + memcpy (val->value, value, vlen); + + k = kh_get (rspamd_map_hash, r->htb, key); + + if (k == kh_end (r->htb)) { + nk = rspamd_mempool_strdup (r->pool, key); + k = kh_put (rspamd_map_hash, r->htb, nk, &res); + } + + nk = kh_key (r->htb, k); + val->key = nk; + kh_value (r->htb, k) = val; + rspamd_radix_add_iplist (key, ",", r->trie, val, TRUE); +} + void rspamd_map_helper_insert_hash (gpointer st, gconstpointer key, gconstpointer value) { diff --git a/src/libutil/map_helpers.h b/src/libutil/map_helpers.h index b6bf81cdc..bd933fbf2 100644 --- a/src/libutil/map_helpers.h +++ b/src/libutil/map_helpers.h @@ -156,6 +156,14 @@ struct rspamd_radix_map_helper *rspamd_map_helper_new_radix (struct rspamd_map * * @param value */ void rspamd_map_helper_insert_radix (gpointer st, gconstpointer key, gconstpointer value); +/** + * Inserts new value into radix map performing synchronous resolving + * @param st + * @param key + * @param value + */ +void rspamd_map_helper_insert_radix_resolve (gpointer st, gconstpointer key, + gconstpointer value); /** * Destroys radix map helper * @param r -- 2.39.5