aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-05-14 13:20:44 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-05-14 13:20:44 +0100
commit3134f3e191c9eda77a05e655be0ac54542746387 (patch)
treeac7b3faee172e74bca0defec86b390a918a9d202 /src/lua
parentce9f332830db017758e523b195f4f3d671c59630 (diff)
downloadrspamd-3134f3e191c9eda77a05e655be0ac54542746387.tar.gz
rspamd-3134f3e191c9eda77a05e655be0ac54542746387.zip
[Feature] Allow augmentations set in Lua API
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_config.c66
1 files changed, 48 insertions, 18 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 747f7b51e..b2333eab1 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -2050,31 +2050,46 @@ lua_config_register_symbol (lua_State * L)
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 {
@@ -2751,10 +2766,25 @@ lua_config_newindex (lua_State *L)
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);
}
/*