diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-04-07 21:22:34 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-04-07 21:22:34 +0100 |
commit | e9418b12ff5cab4c366af3751906f5e95ba3df7a (patch) | |
tree | f83defcc32c8d172d536986d92df9a00a25a9227 | |
parent | e7c1a6a9a153a5832fd7748927961949b63728cb (diff) | |
download | rspamd-e9418b12ff5cab4c366af3751906f5e95ba3df7a.tar.gz rspamd-e9418b12ff5cab4c366af3751906f5e95ba3df7a.zip |
[Project] Rework scan result functions to support shadow results
-rw-r--r-- | src/libmime/mime_expressions.c | 2 | ||||
-rw-r--r-- | src/libmime/scan_result.c | 30 | ||||
-rw-r--r-- | src/libmime/scan_result.h | 8 | ||||
-rw-r--r-- | src/libserver/composites.c | 12 | ||||
-rw-r--r-- | src/libserver/roll_history.c | 2 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 2 | ||||
-rw-r--r-- | src/lua/lua_task.c | 10 |
7 files changed, 37 insertions, 29 deletions
diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index a0c499882..6ff656cdb 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -2328,7 +2328,7 @@ rspamd_has_symbol_expr (struct rspamd_task *task, symbol_str = (const gchar *)sym_arg->data; - if (rspamd_task_find_symbol_result (task, symbol_str)) { + if (rspamd_task_find_symbol_result (task, symbol_str, NULL)) { return TRUE; } diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c index a27c3b0b2..1af2905e7 100644 --- a/src/libmime/scan_result.c +++ b/src/libmime/scan_result.c @@ -847,19 +847,22 @@ rspamd_check_action_metric (struct rspamd_task *task, return noaction->action; } -struct rspamd_symbol_result* -rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym) +struct rspamd_symbol_result * +rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym, + struct rspamd_scan_result *result) { struct rspamd_symbol_result *res = NULL; khiter_t k; + if (result == NULL) { + /* Use default result */ + result = task->result; + } - if (task->result) { - k = kh_get (rspamd_symbols_hash, task->result->symbols, sym); + k = kh_get (rspamd_symbols_hash, result->symbols, sym); - if (k != kh_end (task->result->symbols)) { - res = &kh_value (task->result->symbols, k); - } + if (k != kh_end (result->symbols)) { + res = &kh_value (result->symbols, k); } return res; @@ -867,14 +870,19 @@ rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym) void rspamd_task_symbol_result_foreach (struct rspamd_task *task, - GHFunc func, - gpointer ud) + struct rspamd_scan_result *result, GHFunc func, + gpointer ud) { const gchar *kk; struct rspamd_symbol_result res; - if (func && task->result) { - kh_foreach (task->result->symbols, kk, res, { + if (result == NULL) { + /* Use default result */ + result = task->result; + } + + if (func) { + kh_foreach (result->symbols, kk, res, { func ((gpointer)kk, (gpointer)&res, ud); }); } diff --git a/src/libmime/scan_result.h b/src/libmime/scan_result.h index cdd6fe38b..fd3b8f896 100644 --- a/src/libmime/scan_result.h +++ b/src/libmime/scan_result.h @@ -159,8 +159,9 @@ gboolean rspamd_task_add_result_option (struct rspamd_task *task, * @param sym * @return */ -struct rspamd_symbol_result *rspamd_task_find_symbol_result ( - struct rspamd_task *task, const char *sym); +struct rspamd_symbol_result * +rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym, + struct rspamd_scan_result *result); /** * Compatibility function to iterate on symbols hash @@ -168,8 +169,7 @@ struct rspamd_symbol_result *rspamd_task_find_symbol_result ( * @param func * @param ud */ -void rspamd_task_symbol_result_foreach (struct rspamd_task *task, - GHFunc func, +void rspamd_task_symbol_result_foreach (struct rspamd_task *task, struct rspamd_scan_result *result, GHFunc func, gpointer ud); /** diff --git a/src/libserver/composites.c b/src/libserver/composites.c index 22fe45818..c35ba2431 100644 --- a/src/libserver/composites.c +++ b/src/libserver/composites.c @@ -201,7 +201,7 @@ rspamd_composite_process_single_symbol (struct composites_data *cd, struct rspamd_composite *ncomp; struct rspamd_task *task = cd->task; - if ((ms = rspamd_task_find_symbol_result (cd->task, sym)) == NULL) { + if ((ms = rspamd_task_find_symbol_result (cd->task, sym, NULL)) == NULL) { msg_debug_composites ("not found symbol %s in composite %s", sym, cd->composite->sym); if ((ncomp = @@ -225,14 +225,14 @@ rspamd_composite_process_single_symbol (struct composites_data *cd, cd->composite = saved; clrbit (cd->checked, cd->composite->id * 2); - ms = rspamd_task_find_symbol_result (cd->task, sym); + ms = rspamd_task_find_symbol_result (cd->task, sym, NULL); } else { /* * XXX: in case of cyclic references this would return 0 */ if (isset (cd->checked, ncomp->id * 2 + 1)) { - ms = rspamd_task_find_symbol_result (cd->task, sym); + ms = rspamd_task_find_symbol_result (cd->task, sym, NULL); } } } @@ -396,7 +396,7 @@ rspamd_composite_expr_process (void *ud, 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 = rspamd_task_find_symbol_result (cd->task, sym); + ms = rspamd_task_find_symbol_result (cd->task, sym, NULL); } if (ms) { @@ -563,7 +563,7 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) clrbit (cd->checked, comp->id * 2 + 1); } else { - if (rspamd_task_find_symbol_result (cd->task, key) != NULL) { + if (rspamd_task_find_symbol_result (cd->task, key, NULL) != NULL) { /* Already set, no need to check */ msg_debug_composites ("composite %s is already in metric " "in composites bitfield", cd->composite->sym); @@ -652,7 +652,7 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data) } } - ms = rspamd_task_find_symbol_result (task, rd->sym); + ms = rspamd_task_find_symbol_result (task, rd->sym, NULL); if (has_valid_op && ms && !(ms->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) { diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c index a0197a32c..6add06e62 100644 --- a/src/libserver/roll_history.c +++ b/src/libserver/roll_history.c @@ -165,7 +165,7 @@ 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); - rspamd_task_symbol_result_foreach (task, + rspamd_task_symbol_result_foreach (task, NULL, roll_history_symbols_callback, &cbdata); if (cbdata.remain > 0) { diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index fc42cd875..93287dc68 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -881,7 +881,7 @@ rspamd_stat_has_classifier_symbols (struct rspamd_task *task, id = g_array_index (cl->statfiles_ids, gint, i); st = g_ptr_array_index (st_ctx->statfiles, id); - if (rspamd_task_find_symbol_result (task, st->stcf->symbol)) { + if (rspamd_task_find_symbol_result (task, st->stcf->symbol, NULL)) { if (is_spam == !!st->stcf->is_spam) { msg_debug_bayes ("do not autolearn %s as symbol %s is already " "added", is_spam ? "spam" : "ham", st->stcf->symbol); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index ce15813ac..2d6257443 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1986,7 +1986,7 @@ lua_task_adjust_result (lua_State * L) metric_res = task->result; if (metric_res) { - s = rspamd_task_find_symbol_result (task, symbol_name); + s = rspamd_task_find_symbol_result (task, symbol_name, NULL); } else { return luaL_error (L, "no metric result"); @@ -4383,7 +4383,7 @@ lua_push_symbol_result (lua_State *L, metric_res = task->result; if (metric_res) { - s = rspamd_task_find_symbol_result (task, symbol); + s = rspamd_task_find_symbol_result (task, symbol, NULL); } } else { @@ -4493,7 +4493,7 @@ lua_task_has_symbol (lua_State *L) symbol = luaL_checkstring (L, 2); if (task && symbol) { - found = (rspamd_task_find_symbol_result (task, symbol) != NULL); + found = (rspamd_task_find_symbol_result (task, symbol, NULL) != NULL); lua_pushboolean (L, found); } else { @@ -4724,7 +4724,7 @@ tokens_foreach_cb (struct rspamd_symcache_item *item, gpointer ud) return; } - if ((s = rspamd_task_find_symbol_result (cbd->task, sym)) != NULL) { + if ((s = rspamd_task_find_symbol_result (cbd->task, sym, NULL)) != NULL) { if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) { lua_pushnumber (cbd->L, 0.0); } @@ -4801,7 +4801,7 @@ lua_task_process_ann_tokens (lua_State *L) * * That would lead to N_results lookups which is usually MUCH smaller */ - sres = rspamd_task_find_symbol_result (task, sym); + sres = rspamd_task_find_symbol_result (task, sym, NULL); if (sres && !(sres->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) { |