Browse Source

[Feature] Extend log structure

tags/1.2.3
Vsevolod Stakhov 8 years ago
parent
commit
5cb2fe9654
3 changed files with 30 additions and 9 deletions
  1. 11
    4
      src/libserver/protocol.c
  2. 7
    1
      src/libserver/protocol.h
  3. 12
    4
      src/log_helper.c

+ 11
- 4
src/libserver/protocol.c View File

@@ -1061,6 +1061,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_worker_ctx *ctx,
struct metric_result *mres;
GHashTableIter it;
gpointer k, v;
struct symbol *sym;
gint id, i;
gsize sz;

@@ -1071,9 +1072,12 @@ rspamd_protocol_write_log_pipe (struct rspamd_worker_ctx *ctx,
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);
@@ -1082,12 +1086,15 @@ rspamd_protocol_write_log_pipe (struct rspamd_worker_ctx *ctx,
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 ++;
@@ -1095,7 +1102,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_worker_ctx *ctx,
}
else {
sz = sizeof (*ls);
ls = g_slice_alloc (sz);
ls = g_slice_alloc0 (sz);
ls->nresults = 0;
}


+ 7
- 1
src/libserver/protocol.h View File

@@ -18,9 +18,15 @@
#define RSPAMD_LENGTH_ERROR RSPAMD_BASE_ERROR + 4
#define RSPAMD_STATFILE_ERROR RSPAMD_BASE_ERROR + 5

struct rspamd_protocol_log_symbol_result {
guint32 id;
gdouble score;
};
struct rspamd_protocol_log_message_sum {
guint32 nresults;
guint32 results[];
gdouble score;
gdouble required_score;
struct rspamd_protocol_log_symbol_result results[];
};

struct metric;

+ 12
- 4
src/log_helper.c View File

@@ -87,10 +87,11 @@ 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));

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);
@@ -98,10 +99,17 @@ rspamd_log_helper_read (gint fd, short what, gpointer ud)

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));
}

@@ -109,7 +117,7 @@ rspamd_log_helper_read (gint fd, short what, gpointer ud)
*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);

Loading…
Cancel
Save