aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat/stat_process.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-04 16:49:44 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-04 16:49:44 +0100
commite737e9942cc0c0cbd18dcbc9a1feb0a4b1c48a11 (patch)
treeba2ee3b7d49e603476dbe15e52d4a8c93c30474b /src/libstat/stat_process.c
parent90f44e8ee59515936df340d5bace8ce68f515870 (diff)
downloadrspamd-e737e9942cc0c0cbd18dcbc9a1feb0a4b1c48a11.tar.gz
rspamd-e737e9942cc0c0cbd18dcbc9a1feb0a4b1c48a11.zip
[Rework] Set token data as uint64_t instead of chars array
Diffstat (limited to 'src/libstat/stat_process.c')
-rw-r--r--src/libstat/stat_process.c93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 6e4287abe..356b53807 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -176,50 +176,55 @@ rspamd_stat_tokenize_parts_metadata (struct rspamd_stat_ctx *st_ctx,
if (lua_type (L, -1) == LUA_TTABLE) {
lua_pushstring (L, "stat_metatokens");
- lua_gettable (L, -1);
-
- if (lua_type (L, -1) == LUA_TFUNCTION) {
- struct rspamd_task **ptask;
-
- ptask = lua_newuserdata (L, sizeof (*ptask));
- rspamd_lua_setclass (L, "rspamd{task}", -1);
- *ptask = task;
-
- if (lua_pcall (L, 1, 1, 0) != 0) {
- msg_err_task ("stat_metatokens failed: %s",
- lua_tostring (L, -1));
- lua_pop (L, 1);
- }
- else {
- /* 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;
-
- if (lua_isnumber (L, -1)) {
- gdouble num = lua_tonumber (L, -1);
- guint8 *pnum = rspamd_mempool_alloc (task->task_pool,
- sizeof (num));
-
- msg_debug_task ("got metatoken number: %.2f", num);
- memcpy (pnum, &num, sizeof (num));
- elt.begin = (gchar *) pnum;
- elt.len = sizeof (num);
- g_array_append_val (ar, elt);
- }
- else 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 metatoken string: %*s",
- (gint)tlen, str);
- elt.begin = (gchar *)pstr;
- elt.len = tlen;
- g_array_append_val (ar, elt);
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TTABLE) {
+ lua_pushstring (L, "callback");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TFUNCTION) {
+ struct rspamd_task **ptask;
+
+ ptask = lua_newuserdata (L, sizeof (*ptask));
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
+ *ptask = task;
+
+ if (lua_pcall (L, 1, 1, 0) != 0) {
+ msg_err_task ("stat_metatokens failed: %s",
+ lua_tostring (L, -1));
+ lua_pop (L, 1);
+ } else {
+ /* 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;
+
+ if (lua_isnumber (L, -1)) {
+ gdouble num = lua_tonumber (L, -1);
+ guint8 *pnum = rspamd_mempool_alloc (
+ task->task_pool,
+ sizeof (num));
+
+ msg_debug_task ("got metatoken number: %.2f", num);
+ memcpy (pnum, &num, sizeof (num));
+ elt.begin = (gchar *) pnum;
+ elt.len = sizeof (num);
+ g_array_append_val (ar, elt);
+ } else 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 metatoken string: %*s",
+ (gint) tlen, str);
+ elt.begin = (gchar *) pstr;
+ elt.len = tlen;
+ g_array_append_val (ar, elt);
+ }
}
}
}