aboutsummaryrefslogtreecommitdiffstats
path: root/src/log_helper.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-09-12 16:15:12 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-09-12 16:15:12 +0100
commit50c9bd3d0977aa0f017a739bbd8fe07e1995de4d (patch)
tree5429b8d8710d33d0c474a0410ea41e7d153bf5ce /src/log_helper.c
parentc6c2de9a05c4c4749b6ea5d376b61480b4784457 (diff)
downloadrspamd-50c9bd3d0977aa0f017a739bbd8fe07e1995de4d.tar.gz
rspamd-50c9bd3d0977aa0f017a739bbd8fe07e1995de4d.zip
[Feature] Allow to pass extra data from plugins to log helper
Diffstat (limited to 'src/log_helper.c')
-rw-r--r--src/log_helper.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/log_helper.c b/src/log_helper.c
index a118f1181..995420a41 100644
--- a/src/log_helper.c
+++ b/src/log_helper.c
@@ -77,7 +77,7 @@ rspamd_log_helper_read (gint fd, short what, gpointer ud)
struct log_helper_ctx *ctx = ud;
guchar buf[1024];
gssize r;
- guint32 n, i;
+ guint32 n, i, nextra;
struct rspamd_protocol_log_message_sum *sm;
struct rspamd_worker_lua_script *sc;
struct rspamd_config **pcfg;
@@ -86,10 +86,12 @@ rspamd_log_helper_read (gint fd, short what, gpointer ud)
if (r >= (gssize)sizeof (struct rspamd_protocol_log_message_sum)) {
memcpy (&n, buf, sizeof (n));
+ memcpy (&nextra, buf + sizeof (n), sizeof (nextra));
- if (n != (r - sizeof (*sm)) / sizeof (struct rspamd_protocol_log_symbol_result)) {
+ if (n + nextra !=
+ (r - sizeof (*sm)) / sizeof (struct rspamd_protocol_log_symbol_result)) {
msg_warn ("cannot read data from log pipe: bad length: %d elements "
- "announced but %d available", n,
+ "announced but %d available", n + nextra,
(r - sizeof (*sm)) /
sizeof (struct rspamd_protocol_log_symbol_result));
}
@@ -118,7 +120,18 @@ rspamd_log_helper_read (gint fd, short what, gpointer ud)
rspamd_lua_setclass (ctx->L, "rspamd{config}", -1);
lua_pushnumber (ctx->L, sm->settings_id);
- if (lua_pcall (ctx->L, 5, 0, 0) != 0) {
+ lua_createtable (ctx->L, nextra, 0);
+ for (i = 0; i < nextra; i ++) {
+ lua_createtable (ctx->L, 2, 0);
+ lua_pushnumber (ctx->L, sm->results[i + n].id);
+ lua_rawseti (ctx->L, -2, 1);
+ lua_pushnumber (ctx->L, sm->results[i + n].score);
+ lua_rawseti (ctx->L, -2, 2);
+
+ lua_rawseti (ctx->L, -2, (i + 1));
+ }
+
+ if (lua_pcall (ctx->L, 6, 0, 0) != 0) {
msg_err ("error executing log handler code: %s",
lua_tostring (ctx->L, -1));
lua_pop (ctx->L, 1);