diff options
-rw-r--r-- | src/libserver/symcache/symcache_c.cxx | 42 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_internal.hxx | 12 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_item.cxx | 24 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_item.hxx | 2 | ||||
-rw-r--r-- | src/lua/lua_config.c | 33 |
5 files changed, 74 insertions, 39 deletions
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index df75bf2c8..abedba23f 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -221,20 +221,51 @@ rspamd_symcache_item_name (struct rspamd_symcache_item *item) } gint -rspamd_symcache_item_flags (struct rspamd_symcache_item *item) +rspamd_symcache_item_flags(struct rspamd_symcache_item *item) { auto *real_item = C_API_SYMCACHE_ITEM(item); return real_item->get_flags(); } +guint +rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache, + const gchar *symbol) +{ + auto *real_cache = C_API_SYMCACHE(cache); + + auto *sym = real_cache->get_item_by_name(symbol, false); + + if (sym) { + return sym->get_flags(); + } + + return 0; +} + const struct rspamd_symcache_item_stat * -rspamd_symcache_item_stat (struct rspamd_symcache_item *item) +rspamd_symcache_item_stat(struct rspamd_symcache_item *item) { auto *real_item = C_API_SYMCACHE_ITEM(item); return real_item->st; } void +rspamd_symcache_get_symbol_details(struct rspamd_symcache *cache, + const gchar *symbol, + ucl_object_t *this_sym_ucl) +{ + auto *real_cache = C_API_SYMCACHE(cache); + + auto *sym = real_cache->get_item_by_name(symbol, false); + + if (sym) { + ucl_object_insert_key (this_sym_ucl, + ucl_object_fromstring(sym->get_type_str()), + "type", strlen("type"), false); + } +} + +void rspamd_symcache_foreach(struct rspamd_symcache *cache, void (*func) (struct rspamd_symcache_item *item, gpointer /* userdata */), gpointer ud) @@ -246,9 +277,10 @@ rspamd_symcache_foreach(struct rspamd_symcache *cache, }); } -void rspamd_symcache_disable_all_symbols (struct rspamd_task *task, - struct rspamd_symcache *_cache, - guint skip_mask) +void +rspamd_symcache_disable_all_symbols(struct rspamd_task *task, + struct rspamd_symcache *_cache, + guint skip_mask) { auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime); diff --git a/src/libserver/symcache/symcache_internal.hxx b/src/libserver/symcache/symcache_internal.hxx index 2c3bfe739..8a7e44e62 100644 --- a/src/libserver/symcache/symcache_internal.hxx +++ b/src/libserver/symcache/symcache_internal.hxx @@ -80,12 +80,23 @@ struct symcache_header { struct cache_item; using cache_item_ptr = std::shared_ptr<cache_item>; +/** + * This structure is intended to keep the current ordering for all symbols + * It is designed to be shared among all tasks and keep references to the real + * symbols. + * If some symbol has been added or removed to the symbol cache, it will not affect + * the current order, and it will only be regenerated for the subsequent tasks. + * This allows safe and no copy sharing and keeping track of all symbols in the + * cache runtime. + */ struct order_generation { + /* All items ordered */ std::vector<cache_item_ptr> d; /* Mapping from symbol name to the position in the order array */ robin_hood::unordered_flat_map<std::string_view, unsigned int> by_symbol; /* Mapping from symbol id to the position in the order array */ robin_hood::unordered_flat_map<unsigned int, unsigned int> by_cache_id; + /* It matches cache->generation_id; if not, a fresh ordering is required */ unsigned int generation_id; explicit order_generation(std::size_t nelts, unsigned id) : generation_id(id) { @@ -100,7 +111,6 @@ struct order_generation { using order_generation_ptr = std::shared_ptr<order_generation>; - struct delayed_cache_dependency { std::string from; std::string to; diff --git a/src/libserver/symcache/symcache_item.cxx b/src/libserver/symcache/symcache_item.cxx index b25fc991f..0ca080ac0 100644 --- a/src/libserver/symcache/symcache_item.cxx +++ b/src/libserver/symcache/symcache_item.cxx @@ -203,6 +203,30 @@ auto cache_item::update_counters_check_peak(lua_State *L, return ret; } +auto cache_item::get_type_str() const -> const char * +{ + switch(type) { + case symcache_item_type::CONNFILTER: + return "connfilter"; + case symcache_item_type::FILTER: + return "filter"; + case symcache_item_type::IDEMPOTENT: + return "idempotent"; + case symcache_item_type::PREFILTER: + return "prefilter"; + case symcache_item_type::POSTFILTER: + return "postfilter"; + case symcache_item_type::COMPOSITE: + return "composite"; + case symcache_item_type::CLASSIFIER: + return "classifier"; + case symcache_item_type::VIRTUAL: + return "virtual"; + } + + RSPAMD_UNREACHABLE; +} + auto virtual_item::get_parent(const symcache &cache) const -> const cache_item * { if (parent) { diff --git a/src/libserver/symcache/symcache_item.hxx b/src/libserver/symcache/symcache_item.hxx index 23347a8ec..18a46d317 100644 --- a/src/libserver/symcache/symcache_item.hxx +++ b/src/libserver/symcache/symcache_item.hxx @@ -260,6 +260,8 @@ public: return type; } + auto get_type_str() const -> const char*; + auto get_name() const -> const std::string & { return symbol; diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 8c19671f1..8f7854347 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -869,7 +869,6 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, register_dependency), LUA_INTERFACE_DEF (config, register_settings_id), LUA_INTERFACE_DEF (config, get_symbol_flags), - LUA_INTERFACE_DEF (config, add_symbol_flags), LUA_INTERFACE_DEF (config, set_metric_symbol), {"set_symbol", lua_config_set_metric_symbol}, LUA_INTERFACE_DEF (config, set_metric_action), @@ -1986,38 +1985,6 @@ lua_config_get_symbol_flags (lua_State *L) } static gint -lua_config_add_symbol_flags (lua_State *L) -{ - struct rspamd_config *cfg = lua_check_config (L, 1); - const gchar *name = luaL_checkstring (L, 2); - guint flags, new_flags = 0; - - if (cfg && name && lua_istable (L, 3)) { - - for (lua_pushnil (L); lua_next (L, 3); lua_pop (L, 1)) { - new_flags |= lua_parse_symbol_flags (lua_tostring (L, -1)); - } - - flags = rspamd_symcache_get_symbol_flags (cfg->cache, - name); - - if (flags != 0) { - rspamd_symcache_add_symbol_flags (cfg->cache, name, new_flags); - /* Push old flags */ - lua_push_symbol_flags (L, flags, LUA_SYMOPT_FLAG_CREATE_ARRAY); - } - else { - lua_pushnil (L); - } - } - else { - return luaL_error (L, "invalid arguments"); - } - - return 1; -} - -static gint lua_config_register_symbol (lua_State * L) { LUA_TRACE_POINT; |