struct metric_result *mres;
GHashTableIter it;
gpointer k, v;
+ struct symbol *sym;
gint id, i;
gsize sz;
mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
if (mres) {
- sz = sizeof (*ls) + sizeof (guint32) *
+ sz = sizeof (*ls) +
+ sizeof (struct rspamd_protocol_log_symbol_result) *
g_hash_table_size (mres->symbols);
ls = g_slice_alloc (sz);
+ ls->score = mres->score;
+ ls->required_score = mres->actions_limits[METRIC_ACTION_REJECT];
ls->nresults = g_hash_table_size (mres->symbols);
g_hash_table_iter_init (&it, mres->symbols);
while (g_hash_table_iter_next (&it, &k, &v)) {
id = rspamd_symbols_cache_find_symbol (task->cfg->cache,
k);
+ sym = v;
if (id >= 0) {
- ls->results[i] = id;
+ ls->results[i].id = id;
+ ls->results[i].score = sym->score;
}
else {
- ls->results[i] = -1;
+ ls->results[i].id = -1;
+ ls->results[i].score = 0.0;
}
i ++;
}
else {
sz = sizeof (*ls);
- ls = g_slice_alloc (sz);
+ ls = g_slice_alloc0 (sz);
ls->nresults = 0;
}
if (r >= (gssize)sizeof (struct rspamd_protocol_log_message_sum)) {
memcpy (&n, buf, sizeof (n));
- if (n != (r - sizeof (guint32)) / sizeof (guint32)) {
+ if (n != (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,
- (r - sizeof (guint32)) / sizeof (guint32));
+ (r - sizeof (*sm)) /
+ sizeof (struct rspamd_protocol_log_symbol_result));
}
else {
sm = g_malloc (r);
DL_FOREACH (ctx->scripts, sc) {
lua_rawgeti (ctx->L, LUA_REGISTRYINDEX, sc->cbref);
+ lua_pushnumber (ctx->L, sm->score);
+ lua_pushnumber (ctx->L, sm->required_score);
lua_createtable (ctx->L, n, 0);
for (i = 0; i < n; i ++) {
- lua_pushnumber (ctx->L, sm->results[i]);
+ lua_createtable (ctx->L, 2, 0);
+ lua_pushnumber (ctx->L, sm->results[i].id);
+ lua_rawseti (ctx->L, -2, 1);
+ lua_pushnumber (ctx->L, sm->results[i].score);
+ lua_rawseti (ctx->L, -2, 2);
+
lua_rawseti (ctx->L, -2, (i + 1));
}
*pcfg = ctx->cfg;
rspamd_lua_setclass (ctx->L, "rspamd{config}", -1);
- if (lua_pcall (ctx->L, 2, 0, 0) != 0) {
+ if (lua_pcall (ctx->L, 4, 0, 0) != 0) {
msg_err ("error executing log handler code: %s",
lua_tostring (ctx->L, -1));
lua_pop (ctx->L, 1);