commit ca1b2e4: [Fix] Distinguish dynamic and static items
Vsevolod Stakhov
vsevolod at rspamd.com
Wed May 11 21:07:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-05-11 22:06:09 +0100
URL: https://github.com/rspamd/rspamd/commit/ca1b2e4c3983f94f25fa00ecfac78431e6ccd155 (HEAD -> master)
[Fix] Distinguish dynamic and static items
---
src/libserver/rspamd_symcache.h | 10 ++++++++--
src/libserver/symcache/symcache_c.cxx | 33 +++++++++++++++++++++++++++++++++
src/lua/lua_http.c | 3 ++-
src/lua/lua_tcp.c | 2 +-
src/lua/lua_udp.c | 3 ++-
5 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h
index d1a9c41fe..99158fbc3 100644
--- a/src/libserver/rspamd_symcache.h
+++ b/src/libserver/rspamd_symcache.h
@@ -484,13 +484,19 @@ gboolean rspamd_symcache_is_item_allowed (struct rspamd_task *task,
* @param item
* @return
*/
-gint rspamd_symcache_item_flags (struct rspamd_symcache_item *item);
+gint rspamd_symcache_dyn_item_flags (struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item);
+gint rspamd_symcache_item_flags(struct rspamd_symcache_item *item);
+
/**
* Returns cache item name
* @param item
* @return
*/
-const gchar* rspamd_symcache_item_name (struct rspamd_symcache_item *item);
+const gchar* rspamd_symcache_dyn_item_name (struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item);
+const gchar * rspamd_symcache_item_name(struct rspamd_symcache_item *item);
+
/**
* Returns the current item stat
* @param item
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx
index f67078b62..fafc89d19 100644
--- a/src/libserver/symcache/symcache_c.cxx
+++ b/src/libserver/symcache/symcache_c.cxx
@@ -251,6 +251,39 @@ rspamd_symcache_item_flags(struct rspamd_symcache_item *item)
return real_item->get_flags();
}
+
+const gchar*
+rspamd_symcache_dyn_item_name (struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item)
+{
+ auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
+ auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(dyn_item);
+
+ if (cache_runtime == nullptr || real_dyn_item == nullptr) {
+ return nullptr;
+ }
+
+ auto static_item = cache_runtime->get_item_by_dynamic_item(real_dyn_item);
+
+ return static_item->get_name().c_str();
+}
+
+gint
+rspamd_symcache_item_flags(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item)
+{
+ auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
+ auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(dyn_item);
+
+ if (cache_runtime == nullptr || real_dyn_item == nullptr) {
+ return 0;
+ }
+
+ auto static_item = cache_runtime->get_item_by_dynamic_item(real_dyn_item);
+
+ return static_item->get_flags();
+}
+
guint
rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache,
const gchar *symbol)
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index 1d6c32798..1fb5732f8 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -446,7 +446,8 @@ lua_http_make_connection (struct lua_http_cbdata *cbd)
if (cbd->item) {
rspamd_session_add_event_full (cbd->session,
(event_finalizer_t) lua_http_fin, cbd,
- M, rspamd_symcache_item_name (cbd->item));
+ M,
+ rspamd_symcache_dyn_item_name (cbd->task, cbd->item));
}
else {
rspamd_session_add_event (cbd->session,
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index 851e1511d..e1024ee36 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -1233,7 +1233,7 @@ lua_tcp_register_event (struct lua_tcp_cbdata *cbd)
if (cbd->item) {
cbd->async_ev = rspamd_session_add_event_full (cbd->session, fin, cbd, M,
- rspamd_symcache_item_name (cbd->item));
+ rspamd_symcache_dyn_item_name (cbd->task, cbd->item));
}
else {
cbd->async_ev = rspamd_session_add_event (cbd->session, fin, cbd, M);
diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c
index b976f9adf..b9e283062 100644
--- a/src/lua/lua_udp.c
+++ b/src/lua/lua_udp.c
@@ -238,7 +238,8 @@ lua_udp_maybe_register_event (struct lua_udp_cbdata *cbd)
if (cbd->s && !cbd->async_ev) {
if (cbd->item) {
cbd->async_ev = rspamd_session_add_event_full (cbd->s, lua_udp_cbd_fin,
- cbd, M, rspamd_symcache_item_name (cbd->item));
+ cbd, M,
+ rspamd_symcache_dyn_item_name (cbd->task, cbd->item));
}
else {
cbd->async_ev = rspamd_session_add_event (cbd->s, lua_udp_cbd_fin,
More information about the Commits
mailing list