return "unknown action";
}
-static double
-get_specific_action_score (struct rspamd_task *task,
- const ucl_object_t *metric,
- struct metric_action *action)
-{
- const ucl_object_t *act, *sact;
- const gchar *act_name;
- double score;
-
- if (metric) {
- act = ucl_object_lookup (metric, "actions");
- if (act) {
- act_name = rspamd_action_to_str (action->action);
- sact = ucl_object_lookup (act, act_name);
- if (sact != NULL && ucl_object_todouble_safe (sact, &score)) {
- msg_debug_task ("found override score %.2f for action %s in settings",
- score, act_name);
- return score;
- }
- }
- }
-
- return action->score;
-}
-
-gint
-rspamd_check_action_metric (struct rspamd_task *task,
- double score, double *rscore, struct metric *metric)
+enum rspamd_metric_action
+rspamd_check_action_metric (struct rspamd_task *task, struct metric_result *mres)
{
struct metric_action *action, *selected_action = NULL;
double max_score = 0;
- const ucl_object_t *ms = NULL;
int i;
- if (task->settings) {
- ms = ucl_object_lookup (task->settings, metric->name);
- }
-
for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) {
double sc;
- action = &metric->actions[i];
- sc = get_specific_action_score (task, ms, action);
+ action = &mres->metric->actions[i];
+ sc = mres->actions_limits[i];
if (isnan (sc)) {
continue;
}
- if (score >= sc && sc > max_score) {
+ if (mres->score >= sc && sc > max_score) {
selected_action = action;
max_score = sc;
}
-
- if (rscore != NULL && i == METRIC_ACTION_REJECT) {
- *rscore = sc;
- }
}
if (selected_action) {
/*
* Get action for specific metric
*/
-gint rspamd_check_action_metric (struct rspamd_task *task,
- double score,
- double *rscore,
- struct metric *metric);
+enum rspamd_metric_action rspamd_check_action_metric (struct rspamd_task *task,
+ struct metric_result *mres);
#endif
const gchar *subject;
m = mres->metric;
- mres->action = rspamd_check_action_metric (task, mres->score,
- &mres->actions_limits[METRIC_ACTION_REJECT], m);
+ mres->action = rspamd_check_action_metric (task, mres);
action = mres->action;
is_spam = (action < METRIC_ACTION_GREYLIST);
const struct rspamd_re_cache_stat *restat;
gpointer h, v;
ucl_object_t *top = NULL;
- gdouble required_score;
gint action;
/* Write custom headers */
/* Update stat for default metric */
metric_res = g_hash_table_lookup (task->results, DEFAULT_METRIC);
if (metric_res != NULL) {
- action = rspamd_check_action_metric (task, metric_res->score, &required_score,
- metric_res->metric);
+ action = rspamd_check_action_metric (task, metric_res);
if (action <= METRIC_ACTION_NOACTION) {
#ifndef HAVE_ATOMIC_BUILTINS
task->worker->srv->stat->actions_stat[action]++;
}
else {
row->score = metric_res->score;
- row->action = rspamd_check_action_metric (task, metric_res->score,
- &row->required_score,
- metric_res->metric);
+ row->action = rspamd_check_action_metric (task, metric_res);
cbdata.pos = row->symbols;
cbdata.remain = sizeof (row->symbols);
g_hash_table_foreach (metric_res->symbols,
mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
if (mres) {
- mres->action = rspamd_check_action_metric (task,
- mres->score,
- &mres->actions_limits[METRIC_ACTION_REJECT],
- mres->metric);
+ mres->action = rspamd_check_action_metric (task, mres);
if (mres->action == METRIC_ACTION_REJECT) {
task->flags |= RSPAMD_TASK_FLAG_LEARN_SPAM;
{
struct rspamd_task *task = lua_check_task (L, 1);
ucl_object_t *settings;
+ const ucl_object_t *act, *elt, *metric_elt;
+ struct metric_result *mres;
+ guint i;
settings = ucl_object_lua_import (L, 2);
+
if (settings != NULL && task != NULL) {
task->settings = settings;
+
+ metric_elt = ucl_object_lookup (settings, DEFAULT_METRIC);
+
+ if (metric_elt) {
+ act = ucl_object_lookup (metric_elt, "actions");
+
+ if (act) {
+ /* Adjust desired actions */
+ mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+
+ if (mres == NULL) {
+ mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
+ }
+
+ for (i = 0; i < METRIC_ACTION_MAX; i++) {
+ elt = ucl_object_lookup (act, rspamd_action_to_str (i));
+
+ if (elt) {
+ mres->actions_limits[i] = ucl_object_todouble (elt);
+ msg_debug_task ("adjusted action %s to %.2f",
+ ucl_object_key (elt), mres->actions_limits[i]);
+ }
+ }
+ }
+ }
}
else {
return luaL_error (L, "invalid arguments");
if (task && metric_name) {
if ((metric_res =
g_hash_table_lookup (task->results, metric_name)) != NULL) {
- action = rspamd_check_action_metric (task, metric_res->score,
- NULL,
- metric_res->metric);
+ action = rspamd_check_action_metric (task, metric_res);
lua_pushstring (L, rspamd_action_to_str (action));
}
else {