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

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Sep 4 20:49:07 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-04 17:48:49 +0100
URL: https://github.com/rspamd/rspamd/commit/9c2d6348f6dadb178f8e8f3ae8a2f6919ac5f862

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

---
 src/libutil/multipattern.h |  2 +-
 src/lua/lua_trie.c         | 27 ++++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h
index 959b13455..1eac4cf9a 100644
--- a/src/libutil/multipattern.h
+++ b/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),
 };
 
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;


More information about the Commits mailing list