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;
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);
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",
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 *