From c976b6fdac8ddb967bf1a8004b2fb66cdc4d10c7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 3 Dec 2017 16:49:25 +0000 Subject: [Minor] Rework plugins state to allow future extensions --- src/lua/lua_common.c | 23 ++++++++++++----------- src/lua/lua_common.h | 5 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/lua') diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index f6fc36aa6..1b4f3e8c7 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -49,6 +49,8 @@ const luaL_reg worker_reg[] = { {NULL, NULL} }; +static const char rspamd_modules_state_global[] = "rspamd_plugins_state"; + static GQuark lua_error_quark (void) { @@ -467,18 +469,17 @@ rspamd_free_lua_locked (struct lua_locked_state *st) g_free (st); } + void -rspamd_table_push_global_elt (lua_State *L, const gchar *global_name, - const gchar *field_name, const gchar *new_elt) +rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name, + const gchar *new_elt) { - gsize last; - - lua_getglobal (L, global_name); + lua_getglobal (L, rspamd_modules_state_global); lua_pushstring (L, field_name); lua_gettable (L, -2); - last = lua_rawlen (L, -1); lua_pushstring (L, new_elt); - lua_rawseti (L, -2, last + 1); + lua_newtable (L); + lua_settable (L, -3); lua_pop (L, 2); /* Global + element */ } @@ -513,8 +514,8 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) lua_tostring (L, -1)); lua_pop (L, 1); /* Error function */ - rspamd_table_push_global_elt (L, rspamd_modules_state_global, - "disabled_failed", module->name); + rspamd_plugins_table_push_elt (L, "disabled_failed", + module->name); cur = g_list_next (cur); continue; @@ -535,8 +536,8 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) g_string_free (tb, TRUE); lua_pop (L, 2); /* Result and error function */ - rspamd_table_push_global_elt (L, rspamd_modules_state_global, - "disabled_failed", module->name); + rspamd_plugins_table_push_elt (L, "disabled_failed", + module->name); cur = g_list_next (cur); continue; diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 1bc1e0bdf..1cbbd9bd2 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -48,7 +48,6 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods) #define LUA_INTERFACE_DEF(class, name) { # name, lua_ ## class ## _ ## name } extern const luaL_reg null_reg[]; -static const char rspamd_modules_state_global[] = "rspamd_plugins_state"; #define RSPAMD_LUA_API_VERSION 12 @@ -169,8 +168,8 @@ lua_State *rspamd_lua_init (void); * @param new_elt */ void -rspamd_table_push_global_elt (lua_State *L, const gchar *global_name, - const gchar *field_name, const gchar *new_elt); +rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name, + const gchar *new_elt); /** * Load and initialize lua plugins */ -- cgit v1.2.3