ソースを参照

[Minor] Lua_trie: Add support of flags for trie creation

tags/2.0
Vsevolod Stakhov 4年前
コミット
9c2d6348f6
2個のファイルの変更25行の追加4行の削除
  1. 1
    1
      src/libutil/multipattern.h
  2. 24
    3
      src/lua/lua_trie.c

+ 1
- 1
src/libutil/multipattern.h ファイルの表示

@@ -36,7 +36,7 @@ enum rspamd_multipattern_flags {
RSPAMD_MULTIPATTERN_UTF8 = (1 << 1),
RSPAMD_MULTIPATTERN_TLD = (1 << 2),
/* Not supported by acism */
RSPAMD_MULTIPATTERN_GLOB = (1 << 3),
RSPAMD_MULTIPATTERN_GLOB = (1 << 3),
RSPAMD_MULTIPATTERN_RE = (1 << 4),
};


+ 24
- 3
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;

読み込み中…
キャンセル
保存