diff options
-rw-r--r-- | src/libmime/filter.c | 4 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 28 | ||||
-rw-r--r-- | src/libserver/dns.c | 1 | ||||
-rw-r--r-- | src/libutil/uthash_strcase.h | 3 | ||||
-rw-r--r-- | src/lua/lua_task.c | 6 |
5 files changed, 34 insertions, 8 deletions
diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 46a0e5b92..ea9b500c9 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -499,7 +499,7 @@ rspamd_check_action_metric (struct rspamd_task *task) /* We are not certain about the results during processing */ if (mres->passthrough_result == NULL) { - for (i = 0; i < mres->nactions; i++) { + for (i = mres->nactions - 1; i >= 0; i--) { action_lim = &mres->actions_limits[i]; sc = action_lim->cur_limit; @@ -517,7 +517,7 @@ rspamd_check_action_metric (struct rspamd_task *task) } } - if (set_action && selected_action == NULL) { + if (selected_action == NULL) { selected_action = noaction->action; } } diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 26bf4e4b0..d4b4e9075 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -153,7 +153,8 @@ rspamd_config_new (enum rspamd_config_init_flags flags) action->flags |= RSPAMD_ACTION_HAM; } - HASH_ADD_STR (cfg->actions, name, action); + HASH_ADD_KEYPTR (hh, cfg->actions, + action->name, strlen (action->name), action); } /* Disable timeout */ @@ -1952,8 +1953,6 @@ rspamd_config_action_from_ucl (struct rspamd_config *cfg, act->action_type = METRIC_ACTION_CUSTOM; } - rspamd_actions_sort (cfg); - return TRUE; } @@ -1963,6 +1962,7 @@ rspamd_config_set_action_score (struct rspamd_config *cfg, const ucl_object_t *obj) { struct rspamd_action *act; + enum rspamd_action_type std_act; const ucl_object_t *elt; guint priority = ucl_object_get_priority (obj), obj_type; @@ -1979,6 +1979,17 @@ rspamd_config_set_action_score (struct rspamd_config *cfg, } } + /* Here are dragons: + * We have `canonical` name for actions, such as `soft reject` and + * configuration names for actions (used to be more convenient), such + * as `soft_reject`. Unfortunately, we must have heuristic for this + * variance of names. + */ + + if (rspamd_action_from_str (action_name, (gint *)&std_act)) { + action_name = rspamd_action_to_str (std_act); + } + HASH_FIND_STR (cfg->actions, action_name, act); if (act) { @@ -1992,7 +2003,12 @@ rspamd_config_set_action_score (struct rspamd_config *cfg, act->priority, priority, act->threshold); - return rspamd_config_action_from_ucl (cfg, act, obj, priority); + if (rspamd_config_action_from_ucl (cfg, act, obj, priority)) { + rspamd_actions_sort (cfg); + } + else { + return FALSE; + } } else { msg_info_config ("action %s has been already registered with " @@ -2008,7 +2024,9 @@ rspamd_config_set_action_score (struct rspamd_config *cfg, act->name = rspamd_mempool_strdup (cfg->cfg_pool, action_name); if (rspamd_config_action_from_ucl (cfg, act, obj, priority)) { - HASH_ADD_STR (cfg->actions, name, act); + HASH_ADD_KEYPTR (hh, cfg->actions, + act->name, strlen (act->name), act); + rspamd_actions_sort (cfg); } else { return FALSE; diff --git a/src/libserver/dns.c b/src/libserver/dns.c index 17b84884a..7ad266c2f 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -20,7 +20,6 @@ #include "dns.h" #include "rspamd.h" #include "utlist.h" -#include "uthash.h" #include "rdns_event.h" #include "unix-std.h" diff --git a/src/libutil/uthash_strcase.h b/src/libutil/uthash_strcase.h index 77c807630..fba97d9b1 100644 --- a/src/libutil/uthash_strcase.h +++ b/src/libutil/uthash_strcase.h @@ -16,6 +16,9 @@ #ifndef UTHASH_STRCASE_H_ #define UTHASH_STRCASE_H_ +#ifdef UTHASH_H +#error Invalid include order: uthash is already included +#endif /* Utils for uthash tuning */ #ifndef HASH_CASELESS diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 5728b3342..e8746f2bd 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1673,6 +1673,12 @@ lua_task_set_pre_result (lua_State * L) } if (action == NULL) { + struct rspamd_action *tmp; + + HASH_ITER (hh, task->cfg->actions, action, tmp) { + msg_err ("known action: %s = %f", action->name, action->threshold); + } + return luaL_error (L, "unknown action %s", lua_tostring (L, 2)); } |