commit 6321d90: [Feature] Support more hyperscan flags

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Sep 24 08:28:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-24 09:20:05 +0100
URL: https://github.com/rspamd/rspamd/commit/6321d90514ddfb14aface7b2ddb954a4d4fb0414

[Feature] Support more hyperscan flags

---
 src/libutil/multipattern.c | 10 ++++++++++
 src/libutil/multipattern.h |  3 +++
 src/lua/lua_trie.c         |  6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c
index 7e812a0bd..363cd800f 100644
--- a/src/libutil/multipattern.c
+++ b/src/libutil/multipattern.c
@@ -332,6 +332,16 @@ rspamd_multipattern_add_pattern_len (struct rspamd_multipattern *mp,
 		if (mp->flags & RSPAMD_MULTIPATTERN_UTF8) {
 			fl |= HS_FLAG_UTF8|HS_FLAG_UCP;
 		}
+		if (mp->flags & RSPAMD_MULTIPATTERN_DOTALL) {
+			fl |= HS_FLAG_DOTALL;
+		}
+		if (mp->flags & RSPAMD_MULTIPATTERN_SINGLEMATCH) {
+			fl |= HS_FLAG_SINGLEMATCH;
+			fl &= ~HS_FLAG_SOM_LEFTMOST; /* According to hyperscan docs */
+		}
+		if (mp->flags & RSPAMD_MULTIPATTERN_NO_START) {
+			fl &= ~HS_FLAG_SOM_LEFTMOST;
+		}
 
 		g_array_append_val (mp->hs_flags, fl);
 		np = rspamd_multipattern_pattern_filter (pattern, patlen, flags, &dlen);
diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h
index 1eac4cf9a..03183bd48 100644
--- a/src/libutil/multipattern.h
+++ b/src/libutil/multipattern.h
@@ -38,6 +38,9 @@ enum rspamd_multipattern_flags {
 	/* Not supported by acism */
 	RSPAMD_MULTIPATTERN_GLOB = (1 << 3),
 	RSPAMD_MULTIPATTERN_RE = (1 << 4),
+	RSPAMD_MULTIPATTERN_DOTALL = (1 << 5),
+	RSPAMD_MULTIPATTERN_SINGLEMATCH = (1 << 6),
+	RSPAMD_MULTIPATTERN_NO_START = (1 << 7),
 };
 
 struct rspamd_multipattern;
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c
index 58a669832..a1b0de118 100644
--- a/src/lua/lua_trie.c
+++ b/src/lua/lua_trie.c
@@ -430,6 +430,12 @@ lua_load_trie (lua_State *L)
 	lua_setfield (L, -2, "utf8");
 	lua_pushinteger (L, RSPAMD_MULTIPATTERN_TLD);
 	lua_setfield (L, -2, "tld");
+	lua_pushinteger (L, RSPAMD_MULTIPATTERN_DOTALL);
+	lua_setfield (L, -2, "dot_all");
+	lua_pushinteger (L, RSPAMD_MULTIPATTERN_SINGLEMATCH);
+	lua_setfield (L, -2, "single_match");
+	lua_pushinteger (L, RSPAMD_MULTIPATTERN_NO_START);
+	lua_setfield (L, -2, "no_start");
 	lua_settable (L, -3);
 
 	/* Main content */


More information about the Commits mailing list