diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-04-21 12:43:48 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-04-21 12:43:48 +0100 |
commit | e1ed8edbcc2f61bc59269441bb23c4148a0eca21 (patch) | |
tree | 8762831b3386c7ab8fe73de00ce82b58f4658aab /src/lua | |
parent | 7301151c6d6351e0bfe32947e153571f6ba8c22b (diff) | |
download | rspamd-e1ed8edbcc2f61bc59269441bb23c4148a0eca21.tar.gz rspamd-e1ed8edbcc2f61bc59269441bb23c4148a0eca21.zip |
[Minor] Add multiple regexp maps support in lua
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.h | 1 | ||||
-rw-r--r-- | src/lua/lua_map.c | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 20edff778..394798fb8 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -94,6 +94,7 @@ enum rspamd_lua_map_type { RSPAMD_LUA_MAP_SET, RSPAMD_LUA_MAP_HASH, RSPAMD_LUA_MAP_REGEXP, + RSPAMD_LUA_MAP_REGEXP_MULTIPLE, RSPAMD_LUA_MAP_CALLBACK }; diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index c8130ede8..3e292f4d3 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -476,6 +476,21 @@ lua_config_add_map (lua_State *L) return 1; } } + else if (strcmp (type, "regexp_multi") == 0) { + map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map)); + map->data.re_map = NULL; + map->type = RSPAMD_LUA_MAP_REGEXP_MULTIPLE; + + if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description, + rspamd_regexp_list_read_multiple, + rspamd_regexp_list_fin, + (void **) &map->data.re_map)) == NULL) { + lua_pushnil (L); + ucl_object_unref (map_obj); + + return 1; + } + } else { ret = luaL_error (L, "invalid arguments: unknown type '%s'", type); ucl_object_unref (map_obj); @@ -615,6 +630,31 @@ lua_map_get_key (lua_State * L) } } } + else if (map->type == RSPAMD_LUA_MAP_REGEXP_MULTIPLE) { + GPtrArray *ar; + guint i; + const gchar *val; + + key = lua_map_process_string_key (L, 2, &len); + + if (key && map->data.re_map) { + ar = rspamd_match_regexp_map_all (map->data.re_map, key, + len); + + if (ar) { + lua_createtable (L, ar->len, 0); + + PTR_ARRAY_FOREACH (ar, i, val) { + lua_pushstring (L, val); + lua_rawseti (L, -2, i + 1); + } + + g_ptr_array_free (ar, TRUE); + + return 1; + } + } + } else if (map->type == RSPAMD_LUA_MAP_HASH) { /* key-value map */ key = lua_map_process_string_key (L, 2, &len); |