diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-04 17:48:49 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-04 17:48:49 +0100 |
commit | 9c2d6348f6dadb178f8e8f3ae8a2f6919ac5f862 (patch) | |
tree | 55cece2cab3b24fc61d677a210425c9fbd15d316 /src/lua | |
parent | e212829fe63a44f070dd2f6d0f6704b0313d1647 (diff) | |
download | rspamd-9c2d6348f6dadb178f8e8f3ae8a2f6919ac5f862.tar.gz rspamd-9c2d6348f6dadb178f8e8f3ae8a2f6919ac5f862.zip |
[Minor] Lua_trie: Add support of flags for trie creation
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_trie.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c index bc90fef27..456610b1f 100644 --- a/src/lua/lua_trie.c +++ b/src/lua/lua_trie.c @@ -81,7 +81,7 @@ lua_trie_destroy (lua_State *L) } /*** - * function trie.create(patterns) + * function trie.create(patterns, [flags]) * Creates new trie data structure * @param {table} array of string patterns * @return {trie} new trie object @@ -93,9 +93,12 @@ lua_trie_create (lua_State *L) gint npat = 0, flags = RSPAMD_MULTIPATTERN_ICASE|RSPAMD_MULTIPATTERN_GLOB; GError *err = NULL; + if (lua_isnumber (L, 2)) { + flags = lua_tointeger (L, 2); + } + if (!lua_istable (L, 1)) { - msg_err ("lua trie expects array of patterns for now"); - lua_pushnil (L); + return luaL_error (L, "lua trie expects array of patterns for now"); } else { lua_pushvalue (L, 1); @@ -348,6 +351,24 @@ static gint lua_load_trie (lua_State *L) { lua_newtable (L); + + /* Flags */ + lua_pushstring (L, "flags"); + lua_newtable (L); + + lua_pushinteger (L, RSPAMD_MULTIPATTERN_GLOB); + lua_setfield (L, -2, "glob"); + lua_pushinteger (L, RSPAMD_MULTIPATTERN_RE); + lua_setfield (L, -2, "re"); + lua_pushinteger (L, RSPAMD_MULTIPATTERN_ICASE); + lua_setfield (L, -2, "icase"); + lua_pushinteger (L, RSPAMD_MULTIPATTERN_UTF8); + lua_setfield (L, -2, "utf8"); + lua_pushinteger (L, RSPAMD_MULTIPATTERN_TLD); + lua_setfield (L, -2, "tld"); + lua_settable (L, -3); + + /* Main content */ luaL_register (L, NULL, trielib_f); return 1; |