From 7bce09dd48c1c493159c10c9694df1437327bd20 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 18 Jul 2018 12:40:43 +0100 Subject: [PATCH] [Fix] Fix legacy history handling in the controller Issue: #2348 --- src/controller.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/controller.c b/src/controller.c index c786c138e..25774f267 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1351,7 +1351,7 @@ rspamd_controller_handle_legacy_history ( struct roll_history_row *row, *copied_rows; guint i, rows_proc, row_num; struct tm tm; - gchar timebuf[32]; + gchar timebuf[32], **syms; ucl_object_t *top, *obj; top = ucl_object_typed_new (UCL_ARRAY); @@ -1405,15 +1405,34 @@ rspamd_controller_handle_legacy_history ( ucl_object_fromdouble (0.0), "required_score", 0, false); } - ucl_object_insert_key (obj, ucl_object_fromstring ( - row->symbols), "symbols", 0, false); - ucl_object_insert_key (obj, ucl_object_fromint ( - row->len), "size", 0, false); - ucl_object_insert_key (obj, ucl_object_fromdouble ( - row->scan_time), "scan_time", 0, false); + syms = g_strsplit_set (row->symbols, ",", -1); + + if (syms) { + guint nelts = g_strv_length (syms); + ucl_object_t *syms_obj = ucl_object_typed_new (UCL_OBJECT); + ucl_object_reserve (syms_obj, nelts); + + for (guint j = 0; j < nelts; j++) { + ucl_object_t *cur = ucl_object_typed_new (UCL_OBJECT); + + ucl_object_insert_key (cur, ucl_object_fromdouble (0.0), + "score", 0, false); + ucl_object_insert_key (syms_obj, cur, syms[j], 0, true); + } + + ucl_object_insert_key (obj, syms_obj, "symbols", 0, false); + g_strfreev (syms); + } + + ucl_object_insert_key (obj, ucl_object_fromint (row->len), + "size", 0, false); + ucl_object_insert_key (obj, + ucl_object_fromdouble (row->scan_time), + "scan_time", 0, false); + if (row->user[0] != '\0') { - ucl_object_insert_key (obj, ucl_object_fromstring ( - row->user), "user", 0, false); + ucl_object_insert_key (obj, ucl_object_fromstring (row->user), + "user", 0, false); } if (row->from_addr[0] != '\0') { ucl_object_insert_key (obj, ucl_object_fromstring ( -- 2.39.5