commit 3e32e48: [Feature] Support rspamd_text in selector regexps
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Nov 25 16:42:06 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-11-25 16:38:39 +0000
URL: https://github.com/rspamd/rspamd/commit/3e32e48591025b0a1aae869b7c8dc697f06b738d
[Feature] Support rspamd_text in selector regexps
---
src/libserver/re_cache.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 40a44cde8..594b60b53 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -937,19 +937,24 @@ rspamd_re_cache_process_selector (struct rspamd_task *task,
lua_tostring (L, -1));
}
else {
+ struct rspamd_lua_text *txt;
gsize slen;
const gchar *sel_data;
if (lua_type (L, -1) == LUA_TSTRING) {
- sel_data = lua_tolstring (L, -1, &slen);
- *n = 1;
- *svec = g_malloc (sizeof (guchar *));
- *lenvec = g_malloc (sizeof (guint));
- (*svec)[0] = g_malloc (slen);
- memcpy ((*svec)[0], sel_data, slen);
- (*lenvec)[0] = slen;
-
- result = TRUE;
+ txt = lua_check_text_or_string (L, -1);
+
+ if (txt) {
+ sel_data = txt->start;
+ slen = txt->len;
+ *n = 1;
+ *svec = g_malloc (sizeof (guchar *));
+ *lenvec = g_malloc (sizeof (guint));
+ (*svec)[0] = g_malloc (slen);
+ memcpy ((*svec)[0], sel_data, slen);
+ (*lenvec)[0] = slen;
+ result = TRUE;
+ }
}
else {
*n = rspamd_lua_table_size (L, -1);
@@ -961,7 +966,16 @@ rspamd_re_cache_process_selector (struct rspamd_task *task,
for (guint i = 0; i < *n; i ++) {
lua_rawgeti (L, -1, i + 1);
- sel_data = lua_tolstring (L, -1, &slen);
+ txt = lua_check_text_or_string (L, -1);
+ if (txt) {
+ sel_data = txt->start;
+ slen = txt->len;
+ }
+ else {
+ sel_data = "";
+ slen = 0;
+ }
+
(*svec)[i] = g_malloc (slen);
memcpy ((*svec)[i], sel_data, slen);
(*lenvec)[i] = slen;
More information about the Commits
mailing list