diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-04-23 17:17:49 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-04-23 17:17:49 +0100 |
commit | 585b2533219a21972200acbeb11289ec83ffe946 (patch) | |
tree | 6ad8bd4f45590c0d577ba9e98f6ed2d281f9049b | |
parent | 60403ad3baecbd5af0603c0b73c0bae7fe249600 (diff) | |
download | rspamd-585b2533219a21972200acbeb11289ec83ffe946.tar.gz rspamd-585b2533219a21972200acbeb11289ec83ffe946.zip |
[Project] Adopt lua maps
-rw-r--r-- | src/libserver/cfg_rcl.c | 16 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.h | 14 | ||||
-rw-r--r-- | src/libutil/map_helpers.c | 2 | ||||
-rw-r--r-- | src/libutil/map_helpers.h | 2 | ||||
-rw-r--r-- | src/lua/lua_common.h | 6 | ||||
-rw-r--r-- | src/lua/lua_map.c | 25 |
6 files changed, 18 insertions, 47 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 6019d7c7d..349bc5cf2 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -3197,22 +3197,6 @@ rspamd_rcl_parse_struct_ucl (rspamd_mempool_t *pool, return TRUE; } -gboolean -rspamd_rcl_parse_struct_iplist (rspamd_mempool_t *pool, - const ucl_object_t *obj, - gpointer ud, - struct rspamd_rcl_section *section, - GError **err) -{ - struct rspamd_rcl_struct_parser *pd = ud; - radix_compressed_t **target; - - target = (radix_compressed_t **)(((gchar *)pd->user_struct) + pd->offset); - - return rspamd_config_radix_from_ucl (pd->cfg, obj, - ucl_object_key (obj), target, err); -} - gboolean rspamd_rcl_parse_struct_boolean (rspamd_mempool_t *pool, diff --git a/src/libserver/cfg_rcl.h b/src/libserver/cfg_rcl.h index 51b348e9c..c1d958efc 100644 --- a/src/libserver/cfg_rcl.h +++ b/src/libserver/cfg_rcl.h @@ -347,20 +347,6 @@ gboolean rspamd_rcl_parse_struct_ucl (rspamd_mempool_t *pool, struct rspamd_rcl_section *section, GError **err); -/** - * Parse IP list or map, accepts radix_tree_t ** as an argument - * @param cfg config pointer - * @param obj object to parse - * @param ud struct_parser structure (flags mean the exact structure used) - * @param section the current section - * @param err error pointer - * @return TRUE if a value has been successfully parsed - */ -gboolean rspamd_rcl_parse_struct_iplist (rspamd_mempool_t *pool, - const ucl_object_t *obj, - gpointer ud, - struct rspamd_rcl_section *section, - GError **err); /** * Utility functions diff --git a/src/libutil/map_helpers.c b/src/libutil/map_helpers.c index 69cb6a4ef..b22b430c6 100644 --- a/src/libutil/map_helpers.c +++ b/src/libutil/map_helpers.c @@ -1020,7 +1020,7 @@ rspamd_match_hs_multiple_handler (unsigned int id, unsigned long long from, } #endif -gconstpointer +GPtrArray* rspamd_match_regexp_map_all (struct rspamd_regexp_map_helper *map, const gchar *in, gsize len) { diff --git a/src/libutil/map_helpers.h b/src/libutil/map_helpers.h index 3d9c40bd1..b6bf81cdc 100644 --- a/src/libutil/map_helpers.h +++ b/src/libutil/map_helpers.h @@ -117,7 +117,7 @@ gconstpointer rspamd_match_regexp_map_single (struct rspamd_regexp_map_helper *m * @param len * @return */ -gconstpointer rspamd_match_regexp_map_all (struct rspamd_regexp_map_helper *map, +GPtrArray* rspamd_match_regexp_map_all (struct rspamd_regexp_map_helper *map, const gchar *in, gsize len); /** diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 310a5504c..b07bf0729 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -104,10 +104,10 @@ struct rspamd_lua_map { guint flags; union { - struct radix_tree_compressed *radix; - GHashTable *hash; + struct rspamd_radix_map_helper *radix; + struct rspamd_hash_map_helper *hash; + struct rspamd_regexp_map_helper *re_map; struct lua_map_callback_data *cbdata; - struct rspamd_regexp_map *re_map; } data; }; diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 7325dbf0e..8ac41bef4 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -16,6 +16,7 @@ #include "lua_common.h" #include "libutil/map.h" +#include "libutil/map_helpers.h" #include "libutil/map_private.h" #include "contrib/libucl/lua_ucl.h" @@ -279,8 +280,8 @@ lua_config_add_hash_map (lua_State *L) map->type = RSPAMD_LUA_MAP_SET; if ((m = rspamd_map_add (cfg, map_line, description, - rspamd_hosts_read, - rspamd_hosts_fin, + rspamd_kv_list_read, + rspamd_kv_list_fin, (void **)&map->data.hash)) == NULL) { msg_warn_config ("invalid set map %s", map_line); lua_pushnil (L); @@ -478,8 +479,8 @@ lua_config_add_map (lua_State *L) map->type = RSPAMD_LUA_MAP_SET; if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description, - rspamd_hosts_read, - rspamd_hosts_fin, + rspamd_kv_list_read, + rspamd_kv_list_fin, (void **)&map->data.hash)) == NULL) { lua_pushnil (L); ucl_object_unref (map_obj); @@ -608,7 +609,7 @@ static gint lua_map_get_key (lua_State * L) { struct rspamd_lua_map *map = lua_check_map (L, 1); - radix_compressed_t *radix; + struct rspamd_radix_map_helper *radix; struct rspamd_lua_ip *addr = NULL; const gchar *key, *value = NULL; gpointer ud; @@ -652,11 +653,11 @@ lua_map_get_key (lua_State * L) } if (radix) { - guintptr p = 0; + gconstpointer p = NULL; if (addr != NULL) { - if ((p = radix_find_compressed_addr (radix, addr->addr)) - != RADIX_NO_VALUE) { + if ((p = rspamd_match_radix_map_addr (radix, addr->addr)) + != NULL) { ret = TRUE; } else { @@ -664,8 +665,8 @@ lua_map_get_key (lua_State * L) } } else if (key_num != 0) { - if ((p = radix_find_compressed (radix, - (guint8 *)&key_num, sizeof (key_num))) != RADIX_NO_VALUE) { + if ((p = rspamd_match_radix_map (radix, + (guint8 *)&key_num, sizeof (key_num))) != NULL) { ret = TRUE; } else { @@ -685,7 +686,7 @@ lua_map_get_key (lua_State * L) key = lua_map_process_string_key (L, 2, &len); if (key && map->data.hash) { - ret = g_hash_table_lookup (map->data.hash, key) != NULL; + ret = rspamd_match_hash_map (map->data.hash, key) != NULL; } } else if (map->type == RSPAMD_LUA_MAP_REGEXP) { @@ -731,7 +732,7 @@ lua_map_get_key (lua_State * L) key = lua_map_process_string_key (L, 2, &len); if (key && map->data.hash) { - value = g_hash_table_lookup (map->data.hash, key); + value = rspamd_match_hash_map (map->data.hash, key); } if (value) { |