]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix conditions operations
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 12:09:42 +0000 (13:09 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 12:09:42 +0000 (13:09 +0100)
src/libserver/symcache/symcache_impl.cxx
src/libserver/symcache/symcache_item.cxx
src/libserver/symcache/symcache_item.hxx

index 25918ce1d051e36aea6dec94299504d02eeaf8f5..fb274e08013a046afe91b66cf53f452785ef4414 100644 (file)
@@ -35,10 +35,12 @@ auto symcache::init() -> bool
        reload_time = cfg->cache_reload_time;
 
        if (cfg->cache_filename != nullptr) {
+               msg_debug_cache("loading symcache saved data from %s", cfg->cache_filename);
                res = load_items();
        }
 
        /* Deal with the delayed dependencies */
+       msg_debug_cache("resolving delayed dependencies: %d in list", (int)delayed_deps->size());
        for (const auto &delayed_dep: *delayed_deps) {
                auto virt_item = get_item_by_name(delayed_dep.from, false);
                auto real_item = get_item_by_name(delayed_dep.from, true);
@@ -64,6 +66,7 @@ auto symcache::init() -> bool
 
 
        /* Deal with the delayed conditions */
+       msg_debug_cache("resolving delayed conditions: %d in list", (int)delayed_conditions->size());
        for (const auto &delayed_cond: *delayed_conditions) {
                auto it = get_item_by_name_mut(delayed_cond.sym, true);
 
@@ -80,10 +83,13 @@ auto symcache::init() -> bool
                                                delayed_cond.sym.c_str());
                                g_abort();
                        }
+
+                       msg_debug_cache("added a condition to the symbol %s", it->symbol.c_str());
                }
        }
        delayed_conditions.reset();
 
+       msg_debug_cache("process dependencies");
        for (auto &it: items_by_id) {
                it->process_deps(*this);
        }
@@ -110,7 +116,7 @@ auto symcache::init() -> bool
                return 1;
        };
 
-
+       msg_debug_cache("sorting stuff");
        std::stable_sort(std::begin(connfilters), std::end(connfilters), prefilters_cmp);
        std::stable_sort(std::begin(prefilters), std::end(prefilters), prefilters_cmp);
        std::stable_sort(std::begin(postfilters), std::end(postfilters), postfilters_cmp);
@@ -120,6 +126,7 @@ auto symcache::init() -> bool
 
        /* Connect metric symbols with symcache symbols */
        if (cfg->symbols) {
+               msg_debug_cache("connect metrics");
                g_hash_table_foreach(cfg->symbols,
                                symcache::metric_connect_cb,
                                (void *) this);
index e918d5b2c8b42f89696104fa306805341b4d5781..70c1921bbc3dc581303c28402480fde31608c8b0 100644 (file)
@@ -472,14 +472,11 @@ auto item_condition::check(std::string_view sym_name, struct rspamd_task *task)
        if (cb != -1 && L != nullptr) {
                auto ret = false;
 
-               lua_rawgeti(L, LUA_REGISTRYINDEX, cb);
-
                lua_pushcfunction (L, &rspamd_lua_traceback);
                auto err_idx = lua_gettop(L);
 
-               auto **ptask = (struct rspamd_task **) lua_newuserdata(L, sizeof(struct rspamd_task *));
-               rspamd_lua_setclass(L, "rspamd{task}", -1);
-               *ptask = task;
+               lua_rawgeti(L, LUA_REGISTRYINDEX, cb);
+               rspamd_lua_task_push(L, task);
 
                if (lua_pcall(L, 1, 1, err_idx) != 0) {
                        msg_info_task("call to condition for %s failed: %s",
index 1d0cd7e35641c33b34da36fdfe90400038f153a8..89c00ded5572e020a2cfbd6ff74b1a7303d01d9d 100644 (file)
@@ -85,11 +85,21 @@ auto item_type_from_c(enum rspamd_symbol_type type) -> tl::expected<std::pair<sy
 
 struct item_condition {
 private:
-       lua_State *L;
-       int cb;
+       lua_State *L = nullptr;
+       int cb = -1;
 public:
-       item_condition(lua_State *_L, int _cb) : L(_L), cb(_cb) {}
-       virtual ~item_condition();
+       explicit item_condition(lua_State *L_, int cb_) noexcept : L(L_), cb(cb_) {}
+       item_condition(item_condition &&other) noexcept {
+               *this = std::move(other);
+       }
+       /* Make it move only */
+       item_condition(const item_condition &) = delete;
+       item_condition& operator=(item_condition &&other) noexcept {
+               std::swap(other.L, L);
+               std::swap(other.cb, cb);
+               return *this;
+       }
+       ~item_condition();
 
        auto check(std::string_view sym_name, struct rspamd_task *task) const -> bool;
 };