diff options
-rw-r--r-- | src/libserver/dns.c | 2 | ||||
-rw-r--r-- | src/libserver/rspamd_symcache.h | 19 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_c.cxx | 45 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_item.hxx | 7 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_runtime.cxx | 18 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_runtime.hxx | 10 | ||||
-rw-r--r-- | src/lua/lua_config.c | 6 | ||||
-rw-r--r-- | src/lua/lua_dns.c | 2 | ||||
-rw-r--r-- | src/lua/lua_dns_resolver.c | 4 | ||||
-rw-r--r-- | src/lua/lua_http.c | 4 | ||||
-rw-r--r-- | src/lua/lua_redis.c | 4 | ||||
-rw-r--r-- | src/lua/lua_spf.c | 2 | ||||
-rw-r--r-- | src/lua/lua_task.c | 2 | ||||
-rw-r--r-- | src/lua/lua_tcp.c | 2 | ||||
-rw-r--r-- | src/lua/lua_udp.c | 2 | ||||
-rw-r--r-- | src/plugins/chartable.c | 8 | ||||
-rw-r--r-- | src/plugins/dkim_check.c | 8 | ||||
-rw-r--r-- | src/plugins/fuzzy_check.c | 6 | ||||
-rw-r--r-- | src/plugins/regexp.c | 4 |
19 files changed, 89 insertions, 66 deletions
diff --git a/src/libserver/dns.c b/src/libserver/dns.c index eb694a74d..c25f5f29a 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -57,7 +57,7 @@ struct rspamd_dns_request_ud { gpointer ud; rspamd_mempool_t *pool; struct rspamd_task *task; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rdns_request *req; struct rdns_reply *reply; }; diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h index e47ea3edd..d1a9c41fe 100644 --- a/src/libserver/rspamd_symcache.h +++ b/src/libserver/rspamd_symcache.h @@ -31,11 +31,12 @@ struct rspamd_task; struct rspamd_config; struct rspamd_symcache; struct rspamd_worker; +struct rspamd_symcache_dynamic_item; struct rspamd_symcache_item; struct rspamd_config_settings_elt; typedef void (*symbol_func_t) (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, gpointer user_data); enum rspamd_symbol_type { @@ -219,7 +220,7 @@ void* rspamd_symcache_start_refresh (struct rspamd_symcache *cache, * @param cache * @param symbol */ -void rspamd_symcache_inc_frequency (struct rspamd_symcache *cache, +void rspamd_symcache_inc_frequency (struct rspamd_symcache *_cache, struct rspamd_symcache_item *item); /** @@ -333,7 +334,7 @@ void rspamd_symcache_foreach (struct rspamd_symcache *cache, * @param task * @return */ -struct rspamd_symcache_item *rspamd_symcache_get_cur_item (struct rspamd_task *task); +struct rspamd_symcache_dynamic_item *rspamd_symcache_get_cur_item (struct rspamd_task *task); /** * Replaces the current item being processed. @@ -342,21 +343,21 @@ struct rspamd_symcache_item *rspamd_symcache_get_cur_item (struct rspamd_task *t * @param item * @return */ -struct rspamd_symcache_item *rspamd_symcache_set_cur_item (struct rspamd_task *task, - struct rspamd_symcache_item *item); +struct rspamd_symcache_dynamic_item *rspamd_symcache_set_cur_item (struct rspamd_task *task, + struct rspamd_symcache_dynamic_item *item); /** * Finalize the current async element potentially calling its deps */ void rspamd_symcache_finalize_item (struct rspamd_task *task, - struct rspamd_symcache_item *item); + struct rspamd_symcache_dynamic_item *item); /* * Increase number of async events pending for an item */ guint rspamd_symcache_item_async_inc_full (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, const gchar *subsystem, const gchar *loc); @@ -367,7 +368,7 @@ guint rspamd_symcache_item_async_inc_full (struct rspamd_task *task, * Decrease number of async events pending for an item, asserts if no events pending */ guint rspamd_symcache_item_async_dec_full (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, const gchar *subsystem, const gchar *loc); @@ -382,7 +383,7 @@ guint rspamd_symcache_item_async_dec_full (struct rspamd_task *task, * @return */ gboolean rspamd_symcache_item_async_dec_check_full (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, const gchar *subsystem, const gchar *loc); diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index baec74622..f8e4389f5 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -26,6 +26,7 @@ #define C_API_SYMCACHE(ptr) (reinterpret_cast<rspamd::symcache::symcache *>(ptr)) #define C_API_SYMCACHE_RUNTIME(ptr) (reinterpret_cast<rspamd::symcache::symcache_runtime *>(ptr)) #define C_API_SYMCACHE_ITEM(ptr) (reinterpret_cast<rspamd::symcache::cache_item *>(ptr)) +#define C_API_SYMCACHE_DYN_ITEM(ptr) (reinterpret_cast<rspamd::symcache::cache_dynamic_item *>(ptr)) void rspamd_symcache_destroy(struct rspamd_symcache *cache) @@ -466,7 +467,7 @@ rspamd_symcache_is_symbol_enabled(struct rspamd_task *task, return cache_runtime->is_symbol_enabled(task, *real_cache, symbol); } -struct rspamd_symcache_item * +struct rspamd_symcache_dynamic_item * rspamd_symcache_get_cur_item(struct rspamd_task *task) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); @@ -475,20 +476,20 @@ rspamd_symcache_get_cur_item(struct rspamd_task *task) return nullptr; } - return (struct rspamd_symcache_item *) cache_runtime->get_cur_item(); + return (struct rspamd_symcache_dynamic_item *) cache_runtime->get_cur_item(); } -struct rspamd_symcache_item * -rspamd_symcache_set_cur_item(struct rspamd_task *task, struct rspamd_symcache_item *item) +struct rspamd_symcache_dynamic_item * +rspamd_symcache_set_cur_item(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); - auto *real_item = C_API_SYMCACHE_ITEM(item); + auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item); - if (!cache_runtime || !real_item) { + if (!cache_runtime || !real_dyn_item) { return nullptr; } - return (struct rspamd_symcache_item *) cache_runtime->set_cur_item(real_item); + return (struct rspamd_symcache_dynamic_item *) cache_runtime->set_cur_item(real_dyn_item); } void @@ -504,44 +505,44 @@ rspamd_symcache_enable_profile(struct rspamd_task *task) guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, const gchar *subsystem, const gchar *loc) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); - auto *real_item = C_API_SYMCACHE_ITEM(item); + auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item); - auto *dyn_item = cache_runtime->get_dynamic_item(real_item->id, true); + auto *static_item = cache_runtime->get_item_by_dynamic_item(real_dyn_item); msg_debug_cache_task("increase async events counter for %s(%d) = %d + 1; " "subsystem %s (%s)", - real_item->symbol.c_str(), real_item->id, - dyn_item->async_events, subsystem, loc); + static_item->symbol.c_str(), static_item->id, + real_dyn_item->async_events, subsystem, loc); - return ++dyn_item->async_events; + return ++real_dyn_item->async_events; } guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, const gchar *subsystem, const gchar *loc) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); - auto *real_item = C_API_SYMCACHE_ITEM(item); + auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item); - auto *dyn_item = cache_runtime->get_dynamic_item(real_item->id, true); + auto *static_item = cache_runtime->get_item_by_dynamic_item(real_dyn_item); msg_debug_cache_task("increase async events counter for %s(%d) = %d + 1; " "subsystem %s (%s)", - real_item->symbol.c_str(), real_item->id, - dyn_item->async_events, subsystem, loc); - g_assert(dyn_item->async_events > 0); + static_item->symbol.c_str(), static_item->id, + real_dyn_item->async_events, subsystem, loc); + g_assert(real_dyn_item->async_events > 0); - return --dyn_item->async_events; + return --real_dyn_item->async_events; } gboolean rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, const gchar *subsystem, const gchar *loc) { @@ -605,7 +606,7 @@ rspamd_symcache_process_symbols(struct rspamd_task *task, void rspamd_symcache_finalize_item(struct rspamd_task *task, - struct rspamd_symcache_item *item) + struct rspamd_symcache_dynamic_item *item) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); auto *real_item = C_API_SYMCACHE_ITEM(item); diff --git a/src/libserver/symcache/symcache_item.hxx b/src/libserver/symcache/symcache_item.hxx index 89c00ded5..40e2d67c1 100644 --- a/src/libserver/symcache/symcache_item.hxx +++ b/src/libserver/symcache/symcache_item.hxx @@ -31,6 +31,7 @@ #include "symcache_id_list.hxx" #include "contrib/expected/expected.hpp" #include "contrib/libev/ev.h" +#include "symcache_runtime.hxx" namespace rspamd::symcache { @@ -119,7 +120,7 @@ public: conditions.emplace_back(L, cbref); } - auto call(struct rspamd_task *task, struct rspamd_symcache_item *item) const -> void + auto call(struct rspamd_task *task, struct rspamd_symcache_dynamic_item *item) const -> void { func(task, item, user_data); } @@ -369,11 +370,11 @@ public: return false; } - auto call(struct rspamd_task *task) const -> void { + auto call(struct rspamd_task *task, cache_dynamic_item *dyn_item) const -> void { if (std::holds_alternative<normal_item>(specific)) { const auto &filter_data = std::get<normal_item>(specific); - filter_data.call(task, (struct rspamd_symcache_item *)this); + filter_data.call(task, (struct rspamd_symcache_dynamic_item *)dyn_item); } } diff --git a/src/libserver/symcache/symcache_runtime.cxx b/src/libserver/symcache/symcache_runtime.cxx index b433213ed..2d941c0ed 100644 --- a/src/libserver/symcache/symcache_runtime.cxx +++ b/src/libserver/symcache/symcache_runtime.cxx @@ -514,10 +514,10 @@ symcache_runtime::process_symbol(struct rspamd_task *task, symcache &cache, cach profile_start) * 1e3; } dyn_item->async_events = 0; - cur_item = item; + cur_item = dyn_item; items_inflight++; /* Callback now must finalize itself */ - item->call(task); + item->call(task, dyn_item); cur_item = nullptr; if (items_inflight == 0) { @@ -829,5 +829,19 @@ auto symcache_runtime::process_item_rdeps(struct rspamd_task *task, cache_item * } } +auto +symcache_runtime::get_item_by_dynamic_item(cache_dynamic_item *dyn_item) const -> cache_item * +{ + auto idx = dyn_item - dynamic_items; + + if (idx >= 0 && idx < order->size()) { + return order->d[idx].get(); + } + + msg_err("internal error: invalid index to get: %d", (int)idx); + + return nullptr; +} + } diff --git a/src/libserver/symcache/symcache_runtime.hxx b/src/libserver/symcache/symcache_runtime.hxx index 1d77bfd4a..678dc42a6 100644 --- a/src/libserver/symcache/symcache_runtime.hxx +++ b/src/libserver/symcache/symcache_runtime.hxx @@ -56,7 +56,7 @@ class symcache_runtime { struct ::rspamd_scan_result *rs; - struct cache_item *cur_item; + struct cache_dynamic_item *cur_item; order_generation_ptr order; /* Cache of the last items to speed up lookups */ mutable std::pair<int, int> last_id_mappings[8]; @@ -146,7 +146,7 @@ public: * @param item * @return */ - auto set_cur_item(cache_item *item) -> auto { + auto set_cur_item(cache_dynamic_item *item) -> auto { std::swap(item, cur_item); return item; } @@ -169,6 +169,12 @@ public: auto get_dynamic_item(int id, bool save_in_cache) const -> cache_dynamic_item *; /** + * Returns static cache item by dynamic cache item + * @return + */ + auto get_item_by_dynamic_item(cache_dynamic_item *) const -> cache_item *; + + /** * Process symbols in the cache * @param task * @param cache diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 4a238d45e..747f7b51e 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1180,7 +1180,7 @@ struct lua_callback_data { /* Dynamic data */ gint stack_level; gint order; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; }; /* @@ -1214,7 +1214,7 @@ rspamd_compare_order_func (gconstpointer a, gconstpointer b) static void lua_metric_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, gpointer ud) { struct lua_callback_data *cd = ud; @@ -1350,7 +1350,7 @@ static void lua_metric_symbol_callback_error (struct thread_entry *thread_entry, static void lua_metric_symbol_callback_coro (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, gpointer ud) { struct lua_callback_data *cd = ud; diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index fe9951e89..79ec72f94 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -31,7 +31,7 @@ struct lua_rspamd_dns_cbdata { struct thread_entry *thread; struct rspamd_task *task; struct rspamd_dns_resolver *resolver; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; }; diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c index c3bd4cacf..8827cb1c1 100644 --- a/src/lua/lua_dns_resolver.c +++ b/src/lua/lua_dns_resolver.c @@ -87,7 +87,7 @@ struct lua_dns_cbdata { gint cbref; gchar *to_resolve; gchar *user_str; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; }; @@ -358,7 +358,7 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_task *task = NULL; GError *err = NULL; gboolean forced = FALSE; - struct rspamd_symcache_item *item = NULL; + struct rspamd_symcache_dynamic_item *item = NULL; /* Check arguments */ if (!rspamd_lua_parse_table_arguments (L, first, &err, diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 51fe1f272..1d6c32798 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -65,7 +65,7 @@ static const struct luaL_reg httplib_m[] = { struct lua_http_cbdata { struct rspamd_http_connection *conn; struct rspamd_async_session *session; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_http_message *msg; struct ev_loop *event_loop; struct rspamd_config *cfg; @@ -484,7 +484,7 @@ static void lua_http_dns_handler (struct rdns_reply *reply, gpointer ud) { struct lua_http_cbdata *cbd = (struct lua_http_cbdata *)ud; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_task *task; task = cbd->task; diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 0ec2fa74e..71463d350 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -96,7 +96,7 @@ struct lua_redis_request_specific_userdata; struct lua_redis_userdata { redisAsyncContext *ctx; struct rspamd_task *task; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; struct ev_loop *event_loop; struct rspamd_config *cfg; @@ -150,7 +150,7 @@ struct lua_redis_ctx { struct lua_redis_result { gboolean is_error; gint result_ref; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; struct rspamd_task *task; struct lua_redis_request_specific_userdata *sp_ud; diff --git a/src/lua/lua_spf.c b/src/lua/lua_spf.c index a55b511be..f6ce4905e 100644 --- a/src/lua/lua_spf.c +++ b/src/lua/lua_spf.c @@ -55,7 +55,7 @@ static luaL_reg rspamd_spf_record_m[] = { struct rspamd_lua_spf_cbdata { struct rspamd_task *task; lua_State *L; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; gint cbref; ref_entry_t ref; }; diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 2b811f4a7..4ec8c90d6 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -4990,7 +4990,7 @@ struct tokens_foreach_cbdata { }; static void -tokens_foreach_cb (struct rspamd_symcache_item *item, gpointer ud) +tokens_foreach_cb (struct rspamd_symcache_dynamic_item *item, gpointer ud) { struct tokens_foreach_cbdata *cbd = ud; struct rspamd_symbol_result *s; diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 635aa885d..851e1511d 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -339,7 +339,7 @@ struct lua_tcp_cbdata { struct lua_tcp_dtor *dtors; ref_entry_t ref; struct rspamd_task *task; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct thread_entry *thread; struct rspamd_config *cfg; struct rspamd_ssl_connection *ssl_conn; diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c index 4f5696a94..b976f9adf 100644 --- a/src/lua/lua_udp.c +++ b/src/lua/lua_udp.c @@ -66,7 +66,7 @@ struct lua_udp_cbdata { struct rspamd_task *task; rspamd_mempool_t *pool; rspamd_inet_addr_t *addr; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct rspamd_async_session *s; struct iovec *iov; lua_State *L; diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c index 7b99e9c7a..7f05d10d6 100644 --- a/src/plugins/chartable.c +++ b/src/plugins/chartable.c @@ -87,10 +87,10 @@ chartable_get_context (struct rspamd_config *cfg) } static void chartable_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused); static void chartable_url_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused); gint @@ -640,7 +640,7 @@ rspamd_chartable_process_part (struct rspamd_task *task, static void chartable_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused) { guint i; @@ -710,7 +710,7 @@ chartable_symbol_callback (struct rspamd_task *task, static void chartable_url_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused) { /* XXX: TODO: unbreak module once URLs unicode project is over */ diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 039cdf718..be069a023 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -96,15 +96,15 @@ struct dkim_check_result { struct rspamd_dkim_check_result *res; gdouble mult_allow; gdouble mult_deny; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct dkim_check_result *next, *prev, *first; }; static void dkim_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused); static void dkim_sign_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused); static gint lua_dkim_sign_handler (lua_State *L); @@ -1125,7 +1125,7 @@ dkim_module_key_handler (rspamd_dkim_key_t *key, static void dkim_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused) { rspamd_dkim_context_t *ctx; diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 01e6aa189..864187cc7 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -132,7 +132,7 @@ struct fuzzy_client_session { GPtrArray *commands; GPtrArray *results; struct rspamd_task *task; - struct rspamd_symcache_item *item; + struct rspamd_symcache_dynamic_item *item; struct upstream *server; struct fuzzy_rule *rule; struct ev_loop *event_loop; @@ -181,7 +181,7 @@ struct fuzzy_cmd_io { static const char *default_headers = "Subject,Content-Type,Reply-To,X-Mailer"; static void fuzzy_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused); /* Initialization */ @@ -3218,7 +3218,7 @@ register_fuzzy_client_call (struct rspamd_task *task, /* This callback is called when we check message in fuzzy hashes storage */ static void fuzzy_symbol_callback (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *unused) { struct fuzzy_rule *rule; diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 9dde6cddb..02de2a064 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -40,7 +40,7 @@ struct regexp_ctx { }; static void process_regexp_item (struct rspamd_task *task, - struct rspamd_symcache_item *item, + struct rspamd_symcache_dynamic_item *item, void *user_data); @@ -530,7 +530,7 @@ rspamd_lua_call_expression_func (struct ucl_lua_funcdata *lua_data, static void process_regexp_item (struct rspamd_task *task, - struct rspamd_symcache_item *symcache_item, + struct rspamd_symcache_dynamic_item *symcache_item, void *user_data) { struct regexp_module_item *item = user_data; |