summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-06 15:17:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-06 18:23:44 +0100
commiteaef907b98ae5ceb72ef2806211ce433704a2fc6 (patch)
tree38517307a8841a59544a98f9f94bc84910a0dcbd
parent422bf8b8f4208191ad9818a8b0890721ae4d5cf2 (diff)
downloadrspamd-eaef907b98ae5ceb72ef2806211ce433704a2fc6.tar.gz
rspamd-eaef907b98ae5ceb72ef2806211ce433704a2fc6.zip
[Project] Implement symbols insertion in multiple results mode
-rw-r--r--src/libmime/scan_result.c71
1 files changed, 53 insertions, 18 deletions
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index a8fa38450..44c481e67 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -184,12 +184,12 @@ rspamd_check_group_score (struct rspamd_task *task,
static struct rspamd_symbol_result *
insert_metric_result (struct rspamd_task *task,
- const gchar *symbol,
- double weight,
- const gchar *opt,
- enum rspamd_symbol_insert_flags flags)
+ const gchar *symbol,
+ double weight,
+ const gchar *opt,
+ struct rspamd_scan_result *metric_res,
+ enum rspamd_symbol_insert_flags flags)
{
- struct rspamd_scan_result *metric_res;
struct rspamd_symbol_result *s = NULL;
gdouble final_score, *gr_score = NULL, next_gf = 1.0, diff;
struct rspamd_symbol *sdef;
@@ -201,8 +201,6 @@ insert_metric_result (struct rspamd_task *task,
gboolean single = !!(flags & RSPAMD_SYMBOL_INSERT_SINGLE);
gchar *sym_cpy;
- metric_res = task->result;
-
if (!isfinite (weight)) {
msg_warn_task ("detected %s score for symbol %s, replace it with zero",
isnan (weight) ? "NaN" : "infinity", symbol);
@@ -482,7 +480,8 @@ rspamd_task_insert_result_full (struct rspamd_task *task,
const gchar *opt,
enum rspamd_symbol_insert_flags flags)
{
- struct rspamd_symbol_result *s = NULL;
+ struct rspamd_symbol_result *s = NULL, *ret = NULL;
+ struct rspamd_scan_result *mres;
if (task->processed_stages & (RSPAMD_TASK_STAGE_IDEMPOTENT >> 1)) {
msg_err_task ("cannot insert symbol %s on idempotent phase",
@@ -491,19 +490,55 @@ rspamd_task_insert_result_full (struct rspamd_task *task,
return NULL;
}
- /* Insert symbol to default metric */
- s = insert_metric_result (task,
- symbol,
- weight,
- opt,
- flags);
+ DL_FOREACH (task->result, mres) {
+ if (mres->symbol_cbref != -1) {
+ /* Check if we can insert this symbol to this symbol result */
+ GError *err = NULL;
+ lua_State *L = (lua_State *)task->cfg->lua_state;
+
+ if (!rspamd_lua_universal_pcall (L, mres->symbol_cbref,
+ G_STRLOC, 1, "uss", &err,
+ "rspamd{task}", task, symbol, mres->name ? mres->name : "default")) {
+ msg_warn_task ("cannot call for symbol_cbref for result %s: %e",
+ mres->name ? mres->name : "default", err);
+ g_error_free (err);
+
+ continue;
+ }
+ else {
+ if (!lua_toboolean (L, -1)) {
+ /* Skip symbol */
+ msg_debug_metric ("skip symbol %s for result %s due to Lua return value",
+ symbol, mres->name);
+ lua_pop (L, 1); /* Remove result */
+
+ continue;
+ }
+
+ lua_pop (L, 1); /* Remove result */
+ }
+ }
- /* Process cache item */
- if (s && task->cfg->cache && s->sym) {
- rspamd_symcache_inc_frequency (task->cfg->cache, s->sym->cache_item);
+ s = insert_metric_result (task,
+ symbol,
+ weight,
+ opt,
+ mres,
+ flags);
+
+ if (mres->name == NULL) {
+ /* Default result */
+ ret = s;
+
+ /* Process cache item */
+ if (s && task->cfg->cache && s->sym) {
+ rspamd_symcache_inc_frequency (task->cfg->cache,
+ s->sym->cache_item);
+ }
+ }
}
- return s;
+ return ret;
}
static gchar *