diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-01-20 12:35:39 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-01-20 12:35:39 +0000 |
commit | 0099c72784972169ae1bd37b5e4b3b5dc7b0d02f (patch) | |
tree | dd3f8400f37040c1fc870a682d45df436b619743 /src/lua/lua_text.c | |
parent | 3ce6cb69dd9a1995511e618590a388034cf8da14 (diff) | |
download | rspamd-0099c72784972169ae1bd37b5e4b3b5dc7b0d02f.tar.gz rspamd-0099c72784972169ae1bd37b5e4b3b5dc7b0d02f.zip |
[Minor] Lua_text: Support patterns
Diffstat (limited to 'src/lua/lua_text.c')
-rw-r--r-- | src/lua/lua_text.c | 48 |
1 files changed, 48 insertions, 0 deletions
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; |