From bb516b454ff9842c214e5cb77d984f7fd0ea2da7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 14 Aug 2023 15:00:01 +0100 Subject: [Rework] More abstractions to hide C++ internals --- src/lua/lua_config.c | 31 +++++++++++++++++-------------- src/lua/lua_task.c | 16 ++++------------ 2 files changed, 21 insertions(+), 26 deletions(-) (limited to 'src/lua') 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! */ -- cgit v1.2.3