From: Vsevolod Stakhov Date: Mon, 20 Jan 2020 12:35:39 +0000 (+0000) Subject: [Minor] Lua_text: Support patterns X-Git-Tag: 2.3~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0099c72784972169ae1bd37b5e4b3b5dc7b0d02f;p=rspamd.git [Minor] Lua_text: Support patterns --- 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;