aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-08-14 15:00:01 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-08-14 15:00:01 +0100
commitbb516b454ff9842c214e5cb77d984f7fd0ea2da7 (patch)
treee7d45399a61201b961996c9de8827beb83bfae66 /src/lua
parent2778ec22a2ff4c81c7adcae657d39db08749851d (diff)
downloadrspamd-bb516b454ff9842c214e5cb77d984f7fd0ea2da7.tar.gz
rspamd-bb516b454ff9842c214e5cb77d984f7fd0ea2da7.zip
[Rework] More abstractions to hide C++ internals
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_config.c31
-rw-r--r--src/lua/lua_task.c16
2 files changed, 21 insertions, 26 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index d36245247..3342d18bd 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -2581,24 +2581,27 @@ lua_config_get_metric_action(lua_State *L)
return 1;
}
+static void
+lua_config_actions_cb(struct rspamd_action *act, void *cbd)
+{
+ lua_State *L = (lua_State *) cbd;
+
+ if (!isnan(act->threshold)) {
+ lua_pushstring(L, act->name);
+ lua_pushnumber(L, act->threshold);
+ lua_settable(L, -3);
+ }
+}
+
static gint
lua_config_get_all_actions(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- struct rspamd_action *act, *tmp;
if (cfg) {
- lua_createtable(L, 0, HASH_COUNT(cfg->actions));
-
- HASH_ITER(hh, cfg->actions, act, tmp)
- {
- if (!isnan(act->threshold)) {
- lua_pushstring(L, act->name);
- lua_pushnumber(L, act->threshold);
- lua_settable(L, -3);
- }
- }
+ lua_createtable(L, 0, rspamd_config_actions_size(cfg));
+ rspamd_config_actions_foreach(cfg, lua_config_actions_cb, L);
}
else {
return luaL_error(L, "invalid arguments, rspamd_config expected");
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 4fb6fe347..8b909f6de 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -2313,14 +2313,6 @@ lua_task_set_pre_result(lua_State *L)
action = rspamd_config_get_action(task->cfg, act_str);
if (action == NULL) {
- struct rspamd_action *tmp;
-
- HASH_ITER(hh, task->cfg->actions, action, tmp)
- {
- msg_err_task("known defined action: %s = %f",
- action->name, action->threshold);
- }
-
return luaL_error(L, "unknown action %s", act_str);
}
@@ -5730,7 +5722,7 @@ lua_task_set_settings(lua_State *L)
if (!isnan(act_score)) {
struct rspamd_action *new_act;
- HASH_FIND_STR(task->cfg->actions, act_name, new_act);
+ new_act = rspamd_config_get_action(task->cfg, act_name);
if (new_act == NULL) {
/* New action! */