const ucl_object_t *conf, *enabled;
GList *cur;
struct rspamd_symbols_group *gr;
-
+ lua_State *L = cfg->lua_state;
if (g_hash_table_lookup (cfg->c_modules, module_name)) {
is_c = TRUE;
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);
+
return TRUE;
}
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,
+ "disabled_explicitly", module_name);
return FALSE;
}
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);
+
msg_info_config ("%s module %s is enabled but has not been configured",
is_c ? "internal" : "lua", module_name);
if (enabled && ucl_object_type (enabled) == UCL_BOOLEAN) {
if (!ucl_object_toboolean (enabled)) {
+ rspamd_table_push_global_elt (L,
+ rspamd_modules_state_global,
+ "disabled_explicitly", module_name);
+
msg_info_config ("%s module %s is disabled in the configuration",
is_c ? "internal" : "lua", module_name);
return FALSE;
if (gr) {
if (gr->disabled) {
+ rspamd_table_push_global_elt (L,
+ rspamd_modules_state_global,
+ "disabled_explicitly", module_name);
msg_info_config ("%s module %s is disabled in the configuration as "
"its group has been disabled",
is_c ? "internal" : "lua", module_name);
+
return FALSE;
}
}
{NULL, NULL}
};
-static const char rspamd_modules_state_global[] = "rspamd_plugins_state";
-
static GQuark
lua_error_quark (void)
{
lua_pcall (L, 1, 0, 0);
lua_pop (L, 1); /* math table */
+ /* Modules state */
+ lua_newtable (L);
+ /*
+ * rspamd_plugins_state = {
+ * enabled = {},
+ * disabled_unconfigured = {},
+ * disabled_redis = {},
+ * disabled_explicitly = {},
+ * disabled_failed = {},
+ * }
+ */
+#define ADD_TABLE(name) do { \
+ lua_pushstring (L, #name); \
+ lua_newtable (L); \
+ lua_settable (L, -3); \
+} while (0)
+
+ ADD_TABLE (enabled);
+ ADD_TABLE (disabled_unconfigured);
+ ADD_TABLE (disabled_redis);
+ ADD_TABLE (disabled_explicitly);
+ ADD_TABLE (disabled_failed);
+
+#undef ADD_TABLE
+ lua_setglobal (L, rspamd_modules_state_global);
+
return L;
}
return new;
}
-
/**
* Free locked state structure
*/
g_free (st);
}
-static void
+void
rspamd_table_push_global_elt (lua_State *L, const gchar *global_name,
const gchar *field_name, const gchar *new_elt)
{
GString *tb;
gint err_idx;
- lua_newtable (L);
- /*
- * rspamd_plugins_state = {
- * enabled = {},
- * disabled_unconfigured = {},
- * disabled_redis = {},
- * disabled_explicitly = {},
- * disabled_failed = {},
- * }
- */
-#define ADD_TABLE(name) do { \
- lua_pushstring (L, #name); \
- lua_newtable (L); \
- lua_settable (L, -3); \
-} while (0)
-
- ADD_TABLE (enabled);
- ADD_TABLE (disabled_unconfigured);
- ADD_TABLE (disabled_redis);
- ADD_TABLE (disabled_explicitly);
- ADD_TABLE (disabled_failed);
-
-#undef ADD_TABLE
- lua_setglobal (L, rspamd_modules_state_global);
-
cur = g_list_first (cfg->script_modules);
while (cur) {
if (module->path) {
if (!force_load) {
if (!rspamd_config_is_module_enabled (cfg, module->name)) {
- rspamd_table_push_global_elt (L,
- rspamd_modules_state_global,
- "disabled_explicitly", module->name);
cur = g_list_next (cur);
continue;
}
#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
*/
lua_State *rspamd_lua_init (void);
+
+/**
+ * Sets field in a global variable
+ * @param L
+ * @param global_name
+ * @param field_name
+ * @param new_elt
+ */
+void
+rspamd_table_push_global_elt (lua_State *L, const gchar *global_name,
+ const gchar *field_name, const gchar *new_elt);
/**
* Load and initialize lua plugins
*/