aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-13 18:01:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-13 18:01:07 +0100
commit5e5686b00c7191c71819345b9a778bc7a5cd47e2 (patch)
treebf9da67716baef2c05b5bdd84704d2452dce610c /src/libstat
parent23d9a026aa817ebce23cd28cb50be559e6f85896 (diff)
downloadrspamd-5e5686b00c7191c71819345b9a778bc7a5cd47e2.tar.gz
rspamd-5e5686b00c7191c71819345b9a778bc7a5cd47e2.zip
[Feature] Allow to add unigramm metatokens from Lua
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/stat_process.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 0272c8fb7..f5c19e664 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -203,7 +203,8 @@ rspamd_stat_tokenize_parts_metadata (struct rspamd_stat_ctx *st_ctx,
/* Iterate over table of tables */
for (lua_pushnil (L); lua_next (L, -2);
lua_pop (L, 1)) {
- elt.flags |= RSPAMD_STAT_TOKEN_FLAG_LUA_META;
+ elt.flags = RSPAMD_STAT_TOKEN_FLAG_META|
+ RSPAMD_STAT_TOKEN_FLAG_LUA_META;
if (lua_isnumber (L, -1)) {
gdouble num = lua_tonumber (L, -1);
@@ -233,6 +234,30 @@ rspamd_stat_tokenize_parts_metadata (struct rspamd_stat_ctx *st_ctx,
elt.len = tlen;
g_array_append_val (ar, elt);
}
+ else if (lua_istable (L, -1)) {
+ /* Treat that as unigramms */
+ for (lua_pushnil (L); lua_next (L, -2);
+ lua_pop (L, 1)) {
+ if (lua_isstring (L, -1)) {
+ const gchar *str;
+ gsize tlen;
+
+ str = lua_tolstring (L, -1, &tlen);
+ guint8 *pstr = rspamd_mempool_alloc (
+ task->task_pool,
+ tlen);
+ memcpy (pstr, str, tlen);
+
+ msg_debug_task ("got unigramm "
+ "metatoken string: %*s",
+ (gint) tlen, str);
+ elt.begin = (gchar *) pstr;
+ elt.len = tlen;
+ elt.flags |= RSPAMD_STAT_TOKEN_FLAG_UNIGRAM;
+ g_array_append_val (ar, elt);
+ }
+ }
+ }
}
}
}