From 830eff6a124fbcfc7d9cedd781b2ae261388503b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 14 Dec 2015 14:47:46 +0000 Subject: [PATCH] Add support for fuzzystat command --- src/libserver/rspamd_control.c | 34 ++++++++++++++++++++++++++++++++++ src/libserver/rspamd_control.h | 7 +++++++ 2 files changed, 41 insertions(+) diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index d1eed7d24..90f1c27b6 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -95,6 +95,13 @@ static const struct rspamd_control_cmd_match { }, .type = RSPAMD_CONTROL_RECOMPILE }, + { + .name = { + .begin = "/fuzzystat", + .len = sizeof ("/fuzzystat") - 1 + }, + .type = RSPAMD_CONTROL_FUZZY_STAT + }, }; void @@ -171,6 +178,7 @@ rspamd_control_write_reply (struct rspamd_control_session *session) struct rspamd_control_reply_elt *elt; gchar tmpbuf[64]; gdouble total_utime = 0, total_systime = 0; + struct ucl_parser *parser; guint total_conns = 0; rep = ucl_object_typed_new (UCL_OBJECT); @@ -214,10 +222,35 @@ rspamd_control_write_reply (struct rspamd_control_session *session) ucl_object_insert_key (cur, ucl_object_fromint ( elt->reply.reply.reresolve.status), "status", 0, false); break; + case RSPAMD_CONTROL_FUZZY_STAT: + if (elt->attached_fd != -1) { + /* We have some data to parse */ + parser = ucl_parser_new (0); + ucl_object_insert_key (cur, ucl_object_fromint ( + elt->reply.reply.fuzzy_stat.status), "status", 0, false); + + if (ucl_parser_add_fd (parser, elt->attached_fd)) { + ucl_object_insert_key (cur, ucl_parser_get_object (parser), + "data", 0, false); + ucl_parser_free (parser); + } + else { + ucl_object_insert_key (cur, ucl_object_fromstring ( + ucl_parser_get_error (parser)), "error", 0, false); + + ucl_parser_free (parser); + } + } + break; default: break; } + if (elt->attached_fd != -1) { + close (elt->attached_fd); + elt->attached_fd = -1; + } + ucl_object_insert_key (workers, cur, tmpbuf, 0, true); } @@ -444,6 +477,7 @@ rspamd_control_default_cmd_handler (gint fd, case RSPAMD_CONTROL_RELOAD: case RSPAMD_CONTROL_RECOMPILE: case RSPAMD_CONTROL_HYPERSCAN_LOADED: + case RSPAMD_CONTROL_FUZZY_STAT: break; case RSPAMD_CONTROL_RERESOLVE: if (cd->worker->srv->cfg) { diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h index 4ae836925..2f864fd5a 100644 --- a/src/libserver/rspamd_control.h +++ b/src/libserver/rspamd_control.h @@ -37,6 +37,7 @@ enum rspamd_control_type { RSPAMD_CONTROL_RERESOLVE, RSPAMD_CONTROL_RECOMPILE, RSPAMD_CONTROL_HYPERSCAN_LOADED, + RSPAMD_CONTROL_FUZZY_STAT, RSPAMD_CONTROL_MAX }; @@ -63,6 +64,9 @@ struct rspamd_control_command { struct { gpointer cache_dir; } hs_loaded; + struct { + guint unused; + } fuzzy_stat; } cmd; }; @@ -88,6 +92,9 @@ struct rspamd_control_reply { struct { guint status; } hs_loaded; + struct { + guint status; + } fuzzy_stat; } reply; }; -- 2.39.5