}
}
+bool
+rspamd_symcache_add_symbol_augmentation(struct rspamd_symcache *cache,
+ int sym_id, const char *augmentation)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+ auto log_tag = [&]() { return real_cache->log_tag(); };
+
+ if (augmentation == nullptr) {
+ msg_err_cache("null augmentation is not allowed for item %d", sym_id);
+ return false;
+ }
+
+
+ auto *item = real_cache->get_item_by_id_mut(sym_id, false);
+
+ if (item == nullptr) {
+ msg_err_cache("item %d is not found", sym_id);
+ return false;
+ }
+
+ return item->add_augmentation(*real_cache, augmentation);
+}
+
void
rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, gint cbref)
{
return ret.get();
}
+auto symcache::get_item_by_id_mut(int id, bool resolve_parent) const -> cache_item *
+{
+ if (id < 0 || id >= items_by_id.size()) {
+ msg_err_cache("internal error: requested item with id %d, when we have just %d items in the cache",
+ id, (int) items_by_id.size());
+ return nullptr;
+ }
+
+ auto &ret = items_by_id[id];
+
+ if (!ret) {
+ msg_err_cache("internal error: requested item with id %d but it is empty; qed",
+ id);
+ return nullptr;
+ }
+
+ if (resolve_parent && ret->is_virtual()) {
+ return (cache_item *)ret->get_parent(*this);
+ }
+
+ return ret.get();
+}
+
auto symcache::get_item_by_name(std::string_view name, bool resolve_parent) const -> const cache_item *
{
auto it = items_by_symbol.find(name);
allowed_ids, forbidden_ids,
FALSE);
- if (!isnan (score) || group) {
- if (one_shot) {
- nshots = 1;
- }
+ if (ret != -1) {
+ if (!isnan(score) || group) {
+ if (one_shot) {
+ nshots = 1;
+ }
- rspamd_config_add_symbol (cfg, name,
- score, description, group, flags,
- 0, nshots);
+ rspamd_config_add_symbol(cfg, name,
+ score, description, group, flags,
+ 0, nshots);
- lua_pushstring (L, "groups");
- lua_gettable (L, 2);
+ lua_pushstring(L, "groups");
+ lua_gettable(L, 2);
- if (lua_istable (L, -1)) {
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- if (lua_isstring (L, -1)) {
- rspamd_config_add_symbol_group (cfg, name,
- lua_tostring (L, -1));
- }
- else {
- return luaL_error (L, "invalid groups element");
+ if (lua_istable (L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); lua_pop (L, 1)) {
+ if (lua_isstring(L, -1)) {
+ rspamd_config_add_symbol_group(cfg, name,
+ lua_tostring (L, -1));
+ }
+ else {
+ return luaL_error(L, "invalid groups element");
+ }
}
}
+
+ lua_pop (L, 1);
+ }
+
+ lua_pushstring (L, "augmentations");
+ lua_gettable (L, 2);
+
+ if (lua_type (L, -1) == LUA_TTABLE) {
+
+ for (lua_pushnil (L); lua_next (L, 2); lua_pop (L, 1)) {
+ rspamd_symcache_add_symbol_augmentation(cfg->cache, ret,
+ lua_tostring(L, -1));
+ }
}
- lua_pop (L, 1);
+ lua_pop (L, 1); /* Table itself */
}
}
else {
g_assert (name != NULL);
rspamd_symcache_add_condition_delayed (cfg->cache,
name, L, condref);
+
}
else {
lua_pop (L, 1);
}
+
+ /* Check for augmentations */
+ lua_pushstring (L, "augmentations");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TTABLE) {
+
+ for (lua_pushnil(L); lua_next(L, 2); lua_pop (L, 1)) {
+ rspamd_symcache_add_symbol_augmentation(cfg->cache, id,
+ lua_tostring(L, -1));
+ }
+ }
+
+ lua_pop (L, 1);
}
/*