summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-03 16:49:25 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-03 16:55:30 +0000
commitc976b6fdac8ddb967bf1a8004b2fb66cdc4d10c7 (patch)
tree40ef833be374050c0378efc86cb780cfe786105b /src
parent9e1d92559fcea7243a197726575474d6a49ad927 (diff)
downloadrspamd-c976b6fdac8ddb967bf1a8004b2fb66cdc4d10c7.tar.gz
rspamd-c976b6fdac8ddb967bf1a8004b2fb66cdc4d10c7.zip
[Minor] Rework plugins state to allow future extensions
Diffstat (limited to 'src')
-rw-r--r--src/libserver/cfg_utils.c22
-rw-r--r--src/lua/lua_common.c23
-rw-r--r--src/lua/lua_common.h5
3 files changed, 22 insertions, 28 deletions
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 25ef943b9..78992f984 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1383,12 +1383,11 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
while (cur) {
/* Perform modules configuring */
- mod_ctx = NULL;
mod_ctx = g_hash_table_lookup (cfg->c_modules, cur->data);
if (mod_ctx) {
mod = mod_ctx->mod;
- mod_ctx->enabled = TRUE;
+ mod_ctx->enabled = rspamd_config_is_module_enabled (cfg, mod->name);
if (reconfig) {
(void)mod->module_reconfig_func (cfg);
@@ -1530,9 +1529,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
if (g_hash_table_lookup (cfg->explicit_modules, module_name) != NULL) {
/* Always load module */
- rspamd_table_push_global_elt (L,
- rspamd_modules_state_global,
- "enabled", module_name);
+ rspamd_plugins_table_push_elt (L, "enabled", module_name);
return TRUE;
}
@@ -1554,8 +1551,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
if (!found) {
msg_info_config ("internal module %s is disable in `filters` line",
module_name);
- rspamd_table_push_global_elt (L,
- rspamd_modules_state_global,
+ rspamd_plugins_table_push_elt (L,
"disabled_explicitly", module_name);
return FALSE;
@@ -1565,9 +1561,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
conf = ucl_object_lookup (cfg->rcl_obj, module_name);
if (conf == NULL) {
- rspamd_table_push_global_elt (L,
- rspamd_modules_state_global,
- "disabled_unconfigured", module_name);
+ rspamd_plugins_table_push_elt (L, "disabled_unconfigured", module_name);
msg_info_config ("%s module %s is enabled but has not been configured",
is_c ? "internal" : "lua", module_name);
@@ -1582,8 +1576,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
if (enabled && ucl_object_type (enabled) == UCL_BOOLEAN) {
if (!ucl_object_toboolean (enabled)) {
- rspamd_table_push_global_elt (L,
- rspamd_modules_state_global,
+ rspamd_plugins_table_push_elt (L,
"disabled_explicitly", module_name);
msg_info_config ("%s module %s is disabled in the configuration",
@@ -1598,8 +1591,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
if (gr) {
if (gr->disabled) {
- rspamd_table_push_global_elt (L,
- rspamd_modules_state_global,
+ rspamd_plugins_table_push_elt (L,
"disabled_explicitly", module_name);
msg_info_config ("%s module %s is disabled in the configuration as "
"its group has been disabled",
@@ -1609,6 +1601,8 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
}
}
+ rspamd_plugins_table_push_elt (L, "enabled", module_name);
+
return TRUE;
}
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
*/