diff options
-rw-r--r-- | src/libserver/cfg_file.h | 15 | ||||
-rw-r--r-- | src/libserver/cfg_file_private.h | 38 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 4 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 29 | ||||
-rw-r--r-- | src/lua/lua_config.c | 13 |
5 files changed, 53 insertions, 46 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 3a8094585..1a30d3889 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -279,19 +279,8 @@ enum rspamd_action_flags { RSPAMD_ACTION_HAM = (1u << 2), }; -struct UT_hash_handle; -/** - * Action config definition - */ -struct rspamd_action { - enum rspamd_action_type action; - enum rspamd_action_flags flags; - guint priority; - gint lua_handler_ref; /* If special handling is needed */ - gdouble threshold; - gchar *name; - struct UT_hash_handle hh; /* Index by name */ -}; + +struct rspamd_action; struct rspamd_config_post_load_script { gint cbref; diff --git a/src/libserver/cfg_file_private.h b/src/libserver/cfg_file_private.h new file mode 100644 index 000000000..03f735efe --- /dev/null +++ b/src/libserver/cfg_file_private.h @@ -0,0 +1,38 @@ +/*- + * Copyright 2019 Vsevolod Stakhov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RSPAMD_CFG_FILE_PRIVATE_H +#define RSPAMD_CFG_FILE_PRIVATE_H + +#include "cfg_file.h" +#include "../../contrib/mumhash/mum.h" +#define HASH_CASELESS +#include "uthash_strcase.h" + +/** + * Action config definition + */ +struct rspamd_action { + enum rspamd_action_type action; + enum rspamd_action_flags flags; + guint priority; + gint lua_handler_ref; /* If special handling is needed */ + gdouble threshold; + gchar *name; + struct UT_hash_handle hh; /* Index by name */ +}; + +#endif diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index bb807d932..c03af9c71 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -15,9 +15,7 @@ */ #include "cfg_rcl.h" #include "rspamd.h" -#include "../../contrib/mumhash/mum.h" -#define HASH_CASELESS -#include "uthash_strcase.h" +#include "cfg_file_private.h" #include "utlist.h" #include "cfg_file.h" #include "lua/lua_common.h" diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 5e3193cba..eda78277d 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -17,9 +17,7 @@ #include "cfg_file.h" #include "rspamd.h" -#include "../../contrib/mumhash/mum.h" -#define HASH_CASELESS -#include "uthash_strcase.h" +#include "cfg_file_private.h" #include "filter.h" #include "lua/lua_common.h" #include "lua/lua_thread_pool.h" @@ -848,29 +846,10 @@ rspamd_config_post_load (struct rspamd_config *cfg, /* Validate cache */ if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { /* Check for actions sanity */ - int i, prev_act = 0; - gdouble prev_score = NAN; gboolean seen_controller = FALSE; GList *cur; struct rspamd_worker_conf *wcf; - for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i ++) { - if (!isnan (prev_score) && !isnan (cfg->actions[i].threshold)) { - if (prev_score <= isnan (cfg->actions[i].threshold)) { - msg_warn_config ("incorrect metrics scores: action %s" - " has lower score: %.2f than action %s: %.2f", - rspamd_action_to_str (prev_act), prev_score, - rspamd_action_to_str (i), cfg->actions[i].threshold); - ret = FALSE; - } - } - - if (!isnan (cfg->actions[i].threshold)) { - prev_score = cfg->actions[i].score; - prev_act = i; - } - } - cur = cfg->workers; while (cur) { wcf = cur->data; @@ -1034,8 +1013,6 @@ rspamd_config_new_statfile (struct rspamd_config *cfg, void rspamd_config_init_metric (struct rspamd_config *cfg) { - int i; - cfg->grow_factor = 1.0; cfg->symbols = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); cfg->groups = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); @@ -2195,6 +2172,8 @@ rspamd_action_to_str (enum rspamd_action_type action) return "no action"; case METRIC_ACTION_MAX: return "invalid max action"; + case METRIC_ACTION_CUSTOM: + return "custom"; } return "unknown action"; @@ -2218,6 +2197,8 @@ rspamd_action_to_str_alt (enum rspamd_action_type action) return "no action"; case METRIC_ACTION_MAX: return "invalid max action"; + case METRIC_ACTION_CUSTOM: + return "custom"; } return "unknown action"; diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 0b9811272..1b7eaaa4d 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -17,6 +17,7 @@ #include "libmime/message.h" #include "libutil/expression.h" #include "libserver/composites.h" +#include "libserver/cfg_file_private.h" #include "libmime/lang_detection.h" #include "lua/lua_map.h" #include "lua/lua_thread_pool.h" @@ -2220,15 +2221,15 @@ lua_config_get_all_actions (lua_State * L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config (L, 1); - gint act = 0; + struct rspamd_action *act, *tmp; if (cfg) { - lua_newtable (L); + lua_createtable (L, 0, HASH_COUNT (cfg->actions)); - for (act = METRIC_ACTION_REJECT; act < METRIC_ACTION_MAX; act ++) { - if (!isnan (cfg->actions[act].threshold)) { - lua_pushstring (L, rspamd_action_to_str (act)); - lua_pushnumber (L, cfg->actions[act].threshold); + HASH_ITER (hh, cfg->actions, act, tmp) { + if (!isnan (act->threshold)) { + lua_pushstring (L, act->name); + lua_pushnumber (L, act->threshold); lua_settable (L, -3); } } |