commit 0099c72: [Minor] Lua_text: Support patterns
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Jan 20 13:07:11 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-01-20 12:35:39 +0000
URL: https://github.com/rspamd/rspamd/commit/0099c72784972169ae1bd37b5e4b3b5dc7b0d02f
[Minor] Lua_text: Support patterns
---
src/lua/lua_text.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index 69fd9c529..e10c34581 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -942,6 +942,54 @@ lua_text_exclude_chars (lua_State *L)
/* Fill pattern bitset */
memset (byteset, 0, sizeof byteset);
+
+ while (patlen > 0) {
+ if (*pat == '%') {
+ pat ++;
+ patlen --;
+
+ if (patlen > 0) {
+ /*
+ * This stuff assumes little endian, but GSIZE_FROM_LE should
+ * deal with proper conversion
+ */
+ switch (*pat) {
+ case '%':
+ BITOP (byteset, *(guchar *) pat, |=);
+ break;
+ case 's':
+ /* "\r\n\t\f " */
+ byteset[0] |= GSIZE_FROM_LE (0x100003600);
+ break;
+ case 'n':
+ /* newlines: "\r\n" */
+ byteset[0] |= GSIZE_FROM_LE (0x2400);
+ break;
+ case '8':
+ /* 8 bit characters */
+ byteset[2] |= GSIZE_FROM_LE (0xffffffffffffffffLLU);
+ byteset[3] |= GSIZE_FROM_LE (0xffffffffffffffffLLU);
+ break;
+ case 'c':
+ /* Non printable (control) characters */
+ byteset[0] |= GSIZE_FROM_LE (0xffffffff);
+ /* Del character */
+ byteset[1] |= GSIZE_FROM_LE (0x8000000000000000);
+ break;
+ }
+ }
+ else {
+ /* Last '%' */
+ BITOP (byteset, (guchar)'%', |=);
+ }
+ }
+ else {
+ BITOP (byteset, *(guchar *)pat, |=);
+ }
+
+ pat ++;
+ patlen --;
+ }
for (; patlen > 0 && BITOP (byteset, *(guchar *)pat, |=); pat++, patlen --);
p = t->start;
More information about the Commits
mailing list