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;
--- /dev/null
+/*-
+ * 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
*/
#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"
#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"
/* 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;
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);
return "no action";
case METRIC_ACTION_MAX:
return "invalid max action";
+ case METRIC_ACTION_CUSTOM:
+ return "custom";
}
return "unknown action";
return "no action";
case METRIC_ACTION_MAX:
return "invalid max action";
+ case METRIC_ACTION_CUSTOM:
+ return "custom";
}
return "unknown action";
#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"
{
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);
}
}