diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-07-24 19:01:40 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-07-24 19:01:40 +0100 |
commit | a281d6a475ceb0e7553db38a2e74656aed3a8988 (patch) | |
tree | 42a7229500ece227ec7d39d467952548e1bba7f6 /src/libserver | |
parent | 03bba7bf399390e13c6f871794d24d0de885277e (diff) | |
download | rspamd-a281d6a475ceb0e7553db38a2e74656aed3a8988.tar.gz rspamd-a281d6a475ceb0e7553db38a2e74656aed3a8988.zip |
[Project] Adopt functions
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/composites.c | 10 | ||||
-rw-r--r-- | src/libserver/protocol.c | 23 | ||||
-rw-r--r-- | src/libserver/roll_history.c | 6 | ||||
-rw-r--r-- | src/libserver/task.c | 13 |
4 files changed, 19 insertions, 33 deletions
diff --git a/src/libserver/composites.c b/src/libserver/composites.c index f7c31bb20..88dc51bd2 100644 --- a/src/libserver/composites.c +++ b/src/libserver/composites.c @@ -120,7 +120,7 @@ rspamd_composite_process_single_symbol (struct composites_data *cd, struct rspamd_composite *ncomp; struct rspamd_task *task = cd->task; - if ((ms = g_hash_table_lookup (cd->metric_res->symbols, sym)) == NULL) { + if ((ms = rspamd_task_find_symbol_result (cd->task, sym)) == NULL) { msg_debug_composites ("not found symbol %s in composite %s", sym, cd->composite->sym); if ((ncomp = @@ -144,14 +144,14 @@ rspamd_composite_process_single_symbol (struct composites_data *cd, cd->composite = saved; clrbit (cd->checked, cd->composite->id * 2); - ms = g_hash_table_lookup (cd->metric_res->symbols, sym); + ms = rspamd_task_find_symbol_result (cd->task, sym); } else { /* * XXX: in case of cyclic references this would return 0 */ if (isset (cd->checked, ncomp->id * 2 + 1)) { - ms = g_hash_table_lookup (cd->metric_res->symbols, sym); + ms = rspamd_task_find_symbol_result (cd->task, sym); } } } @@ -190,7 +190,7 @@ rspamd_composite_expr_process (gpointer input, rspamd_expression_atom_t *atom) if (isset (cd->checked, cd->composite->id * 2)) { /* We have already checked this composite, so just return its value */ if (isset (cd->checked, cd->composite->id * 2 + 1)) { - ms = g_hash_table_lookup (cd->metric_res->symbols, sym); + ms = rspamd_task_find_symbol_result (cd->task, sym); } if (ms) { @@ -334,7 +334,7 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) clrbit (cd->checked, comp->id * 2 + 1); } else { - if (g_hash_table_lookup (cd->metric_res->symbols, key) != NULL) { + if (rspamd_task_find_symbol_result (cd->task, key) != NULL) { /* Already set, no need to check */ msg_debug_composites ("composite %s is already in metric " "in composites bitfield", cd->composite->sym); diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 0e4f9cb0c..c83451058 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -912,12 +912,10 @@ static ucl_object_t * rspamd_metric_result_ucl (struct rspamd_task *task, struct rspamd_metric_result *mres, ucl_object_t *top) { - GHashTableIter hiter; struct rspamd_symbol_result *sym; gboolean is_spam; enum rspamd_action_type action = METRIC_ACTION_NOACTION; ucl_object_t *obj = NULL, *sobj; - gpointer h, v; const gchar *subject; action = rspamd_check_action_metric (task, mres); @@ -966,15 +964,12 @@ rspamd_metric_result_ucl (struct rspamd_task *task, obj = ucl_object_typed_new (UCL_OBJECT); } - g_hash_table_iter_init (&hiter, mres->symbols); - - while (g_hash_table_iter_next (&hiter, &h, &v)) { - sym = (struct rspamd_symbol_result *)v; + kh_foreach_value_ptr (mres->symbols, sym, { if (!(sym->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) { sobj = rspamd_metric_symbol_ucl (task, sym); - ucl_object_insert_key (obj, sobj, h, 0, false); + ucl_object_insert_key (obj, sobj, sym->name, 0, false); } - } + }); if (task->cmd == CMD_CHECK_V2) { ucl_object_insert_key (top, obj, "symbols", 0, false); @@ -1405,8 +1400,6 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task) struct rspamd_protocol_log_message_sum *ls; lua_State *L = task->cfg->lua_state; struct rspamd_metric_result *mres; - GHashTableIter it; - gpointer k, v; struct rspamd_symbol_result *sym; gint id, i; guint32 *sid, n = 0, nextra = 0; @@ -1551,7 +1544,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task) mres = task->result; if (mres) { - n = g_hash_table_size (mres->symbols); + n = kh_size (mres->symbols); sz = sizeof (*ls) + sizeof (struct rspamd_protocol_log_symbol_result) * (n + nextra); @@ -1574,13 +1567,11 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task) ls->nresults = n; ls->nextra = nextra; - g_hash_table_iter_init (&it, mres->symbols); i = 0; - while (g_hash_table_iter_next (&it, &k, &v)) { + kh_foreach_value_ptr (mres->symbols, sym, { id = rspamd_symbols_cache_find_symbol (task->cfg->cache, - k); - sym = v; + sym->name); if (id >= 0) { ls->results[i].id = id; @@ -1592,7 +1583,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task) } i ++; - } + }); memcpy (&ls->results[n], extra->data, nextra * sizeof (er)); } diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c index 6dbd4d338..3df597816 100644 --- a/src/libserver/roll_history.c +++ b/src/libserver/roll_history.c @@ -159,9 +159,9 @@ rspamd_roll_history_update (struct roll_history *history, row->required_score = rspamd_task_get_required_score (task, metric_res); cbdata.pos = row->symbols; cbdata.remain = sizeof (row->symbols); - g_hash_table_foreach (metric_res->symbols, - roll_history_symbols_callback, - &cbdata); + rspamd_task_symbol_result_foreach (task, + roll_history_symbols_callback, + &cbdata); if (cbdata.remain > 0) { /* Remove last whitespace and comma */ *cbdata.pos-- = '\0'; diff --git a/src/libserver/task.c b/src/libserver/task.c index d881c6897..437bc4829 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -1045,9 +1045,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task, static gchar scorebuf[32]; rspamd_ftok_t res = {.begin = NULL, .len = 0}; struct rspamd_metric_result *mres; - GHashTableIter it; gboolean first = TRUE; - gpointer k, v; rspamd_fstring_t *symbuf; struct rspamd_symbol_result *sym; GPtrArray *sorted_symbols; @@ -1083,16 +1081,13 @@ rspamd_task_log_metric_res (struct rspamd_task *task, break; case RSPAMD_LOG_SYMBOLS: symbuf = rspamd_fstring_sized_new (128); - g_hash_table_iter_init (&it, mres->symbols); - sorted_symbols = g_ptr_array_sized_new (g_hash_table_size (mres->symbols)); - - while (g_hash_table_iter_next (&it, &k, &v)) { - sym = v; + sorted_symbols = g_ptr_array_sized_new (kh_size (mres->symbols)); + kh_foreach_value_ptr (mres->symbols, sym, { if (!(sym->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) { - g_ptr_array_add (sorted_symbols, v); + g_ptr_array_add (sorted_symbols, (gpointer)sym); } - } + }); g_ptr_array_sort (sorted_symbols, rspamd_task_compare_log_sym); |