commit c211ce5: [Minor] Add delayed condition method

Vsevolod Stakhov vsevolod at rspamd.com
Sat Apr 30 19:21:26 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-04-13 22:07:28 +0100
URL: https://github.com/rspamd/rspamd/commit/c211ce57b9b3a7ddac08bc996ad3ca6a6ee28dac

[Minor] Add delayed condition method

---
 src/libserver/symcache/symcache_c.cxx        | 11 +++++++++++
 src/libserver/symcache/symcache_impl.cxx     |  4 ++++
 src/libserver/symcache/symcache_internal.hxx | 10 ++++++++++
 3 files changed, 25 insertions(+)

diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx
index 8ba991f53..c61b17340 100644
--- a/src/libserver/symcache/symcache_c.cxx
+++ b/src/libserver/symcache/symcache_c.cxx
@@ -82,4 +82,15 @@ rspamd_symcache_set_peak_callback (struct rspamd_symcache *cache, gint cbref)
 	auto *real_cache = C_API_SYMCACHE(cache);
 
 	real_cache->set_peak_cb(cbref);
+}
+
+gboolean
+rspamd_symcache_add_condition_delayed (struct rspamd_symcache *cache,
+									   const gchar *sym, lua_State *L, gint cbref)
+{
+	auto *real_cache = C_API_SYMCACHE(cache);
+
+	real_cache->add_delayed_condition(sym, cbref);
+
+	return TRUE;
 }
\ No newline at end of file
diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx
index 92cd6f3fb..2123508e6 100644
--- a/src/libserver/symcache/symcache_impl.cxx
+++ b/src/libserver/symcache/symcache_impl.cxx
@@ -646,6 +646,10 @@ auto symcache::set_peak_cb(int cbref) -> void
 	msg_info_cache("registered peak callback");
 }
 
+auto symcache::add_delayed_condition(std::string_view sym, int cbref) -> void
+{
+	delayed_conditions->emplace_back(sym, cbref, (lua_State *)cfg->lua_state);
+}
 
 auto cache_item::get_parent(const symcache &cache) const -> const cache_item *
 {
diff --git a/src/libserver/symcache/symcache_internal.hxx b/src/libserver/symcache/symcache_internal.hxx
index 77f48de19..e967bbe83 100644
--- a/src/libserver/symcache/symcache_internal.hxx
+++ b/src/libserver/symcache/symcache_internal.hxx
@@ -345,6 +345,9 @@ struct delayed_cache_condition {
 	std::string sym;
 	int cbref;
 	lua_State *L;
+public:
+	delayed_cache_condition(std::string_view _sym, int _cbref, lua_State *_L) :
+		sym(_sym), cbref(_cbref), L(_L) {}
 };
 
 class symcache {
@@ -499,6 +502,13 @@ public:
 	 * @param cbref
 	 */
 	auto set_peak_cb(int cbref) -> void;
+
+	/**
+	 * Add a delayed condition for a symbol that might not be registered yet
+	 * @param sym
+	 * @param cbref
+	 */
+	auto add_delayed_condition(std::string_view sym, int cbref) -> void;
 };
 
 /*


More information about the Commits mailing list