aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_config.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-01-14 09:47:05 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-01-14 09:47:05 +0000
commit96986ba7f75858395a35c87305427b16eca96547 (patch)
treecb8836a0ffbfee1871bb85ac7bc708b1fea2d511 /src/lua/lua_config.c
parent60107a1f7d79df078c8528618c026858092d2d46 (diff)
downloadrspamd-96986ba7f75858395a35c87305427b16eca96547.tar.gz
rspamd-96986ba7f75858395a35c87305427b16eca96547.zip
[Project] More steps to flexible actions
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r--src/lua/lua_config.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 513c2da93..0b9811272 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -2127,9 +2127,10 @@ lua_config_set_metric_action (lua_State * L)
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *name = NULL;
- double weight;
+ double threshold = NAN;
GError *err = NULL;
gdouble priority = 0.0;
+ ucl_object_t *obj_tbl = NULL;
if (cfg) {
@@ -2137,7 +2138,7 @@ lua_config_set_metric_action (lua_State * L)
if (!rspamd_lua_parse_table_arguments (L, 2, &err,
"*action=S;score=N;"
"priority=N",
- &name, &weight,
+ &name, &threshold,
&priority)) {
msg_err_config ("bad arguments: %e", err);
g_error_free (err);
@@ -2145,12 +2146,36 @@ lua_config_set_metric_action (lua_State * L)
return 0;
}
}
+ else if (lua_type (L, 2) == LUA_TSTRING && lua_type (L, 3) == LUA_TTABLE) {
+ name = lua_tostring (L, 2);
+ obj_tbl = ucl_object_lua_import (L, 3);
+
+ if (obj_tbl) {
+ if (name) {
+ rspamd_config_set_action_score (cfg, name, obj_tbl);
+ ucl_object_unref (obj_tbl);
+ }
+ else {
+ ucl_object_unref (obj_tbl);
+ return luaL_error (L, "invalid first argument, action name expected");
+ }
+ }
+ else {
+ return luaL_error (L, "invalid second argument, table expected");
+ }
+ }
else {
return luaL_error (L, "invalid arguments, table expected");
}
- if (name != NULL && weight != 0) {
- rspamd_config_set_action_score (cfg, name, weight, (guint)priority);
+ if (name != NULL && !isnan (threshold) && threshold != 0) {
+ obj_tbl = ucl_object_typed_new (UCL_OBJECT);
+ ucl_object_insert_key (obj_tbl, ucl_object_fromdouble (threshold),
+ "score", 0, false);
+ ucl_object_insert_key (obj_tbl, ucl_object_fromdouble (priority),
+ "priority", 0, false);
+ rspamd_config_set_action_score (cfg, name, obj_tbl);
+ ucl_object_unref (obj_tbl);
}
}
else {
@@ -2166,12 +2191,14 @@ lua_config_get_metric_action (lua_State * L)
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *act_name = luaL_checkstring (L, 2);
- gint act = 0;
+ struct rspamd_action *act;
if (cfg && act_name) {
- if (rspamd_action_from_str (act_name, &act)) {
- if (!isnan (cfg->actions[act].threshold)) {
- lua_pushnumber (L, cfg->actions[act].threshold);
+ act = rspamd_config_get_action (cfg, act_name);
+
+ if (act) {
+ if (!isnan (act->threshold)) {
+ lua_pushnumber (L, act->threshold);
}
else {
lua_pushnil (L);