]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Add resolving version of radix map helper
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Apr 2018 14:57:20 +0000 (15:57 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Apr 2018 14:57:20 +0000 (15:57 +0100)
src/libserver/cfg_utils.c
src/libutil/map_helpers.c
src/libutil/map_helpers.h

index 69dc3577e4930619c529a2c81da5b43b2a6567b9..1a2f473e7254b548329eee0c359dbf545324ca39 100644 (file)
@@ -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);
index dbbe70e84a70482e250f82118e893d48c1036ea8..7bb442a9792636e7ee0fa89b6a12268165632410 100644 (file)
@@ -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)
 {
index b6bf81cdcf911252622113e2343d2642a78ac6a0..bd933fbf293a33daaef7cf208bb148f9f01c17b9 100644 (file)
@@ -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