summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-29 13:43:12 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-29 13:43:12 +0100
commit90d7f1dbbdfcb85da133808d4c1b9d71c5eb757d (patch)
treea6607f31a6383bd8ee9dbea4bbab79f97d4ddd77
parent7dc4e31c777d83ae2de2fdceaaaa2088ec675a23 (diff)
downloadrspamd-90d7f1dbbdfcb85da133808d4c1b9d71c5eb757d.tar.gz
rspamd-90d7f1dbbdfcb85da133808d4c1b9d71c5eb757d.zip
[Feature] Allow to store strings in radix maps
-rw-r--r--src/lua/lua_map.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c
index ba7d49149..796c74e14 100644
--- a/src/lua/lua_map.c
+++ b/src/lua/lua_map.c
@@ -412,7 +412,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
}
- else if (strcmp (type, "map") == 0) {
+ else if (strcmp (type, "map") == 0 || strcmp (type, "hash") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
map->data.hash = g_hash_table_new (rspamd_strcase_hash,
rspamd_strcase_equal);
@@ -537,18 +537,33 @@ lua_map_get_key (lua_State * L)
}
if (radix) {
+ guintptr p = 0;
+
if (addr != NULL) {
- if (radix_find_compressed_addr (radix, addr->addr)
+ if ((p = radix_find_compressed_addr (radix, addr->addr))
!= RADIX_NO_VALUE) {
ret = TRUE;
}
+ else {
+ p = 0;
+ }
}
else if (key_num != 0) {
- if (radix_find_compressed (radix, (guint8 *)&key_num, sizeof (key_num))
- != RADIX_NO_VALUE) {
+ if ((p = radix_find_compressed (radix,
+ (guint8 *)&key_num, sizeof (key_num))) != RADIX_NO_VALUE) {
ret = TRUE;
}
+ else {
+ p = 0;
+ }
}
+
+ value = (const char *)p;
+ }
+
+ if (ret) {
+ lua_pushstring (L, value);
+ return 1;
}
}
else if (map->type == RSPAMD_LUA_MAP_SET) {