]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_text: Support patterns
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 20 Jan 2020 12:35:39 +0000 (12:35 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 20 Jan 2020 12:35:39 +0000 (12:35 +0000)
src/lua/lua_text.c

index 69fd9c52921bf9456d8416602595e784c5c63c2b..e10c34581ac35b24a2ef88d8042815be2e457ce7 100644 (file)
@@ -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;