]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Move action definition to avoid uthash pollution
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Jan 2019 09:58:18 +0000 (09:58 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Jan 2019 09:58:18 +0000 (09:58 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_file_private.h [new file with mode: 0644]
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/lua/lua_config.c

index 3a809458506ba1603d9a3fc2e1bf5f6fdee7df91..1a30d3889a8c5106e2b3857d6d5d0efe6b3dba08 100644 (file)
@@ -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 (file)
index 0000000..03f735e
--- /dev/null
@@ -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
index bb807d932a6ea0924ff62e0ed4fdd030efc13043..c03af9c71cfe561d951d18fba2193755f08fbdff 100644 (file)
@@ -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"
index 5e3193cba9786140cb689a8dfee917bd48ae82eb..eda78277dc23c8afa2d357eecea205c68abc03ae 100644 (file)
@@ -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";
index 0b9811272fe1c634a97dd113aa06c3f392f01445..1b7eaaa4d1f1fa0000424e25ac439a41da2bd30e 100644 (file)
@@ -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);
                        }
                }