aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-17 17:01:59 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-17 17:02:45 +0100
commitbe3414a88cc7dbd8b34f24b4121ccab5fc9aff7c (patch)
tree6fb8f489345398c7b8d00230601b4b7b1d7d7179 /src/lua
parentf4acd9ba6f492526a2364c814c8a4704b7f8f8ce (diff)
downloadrspamd-be3414a88cc7dbd8b34f24b4121ccab5fc9aff7c.tar.gz
rspamd-be3414a88cc7dbd8b34f24b4121ccab5fc9aff7c.zip
[Feature] Execute on_load scripts with ev_base ready
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.c32
-rw-r--r--src/lua/lua_common.h9
2 files changed, 41 insertions, 0 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 0b19f49ae..efe4f45cf 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -16,6 +16,7 @@
#include "lua_common.h"
#include "lua/global_functions.lua.h"
#include "lptree.h"
+#include "utlist.h"
/* Lua module init function */
#define MODULE_INIT_FUNC "module_init"
@@ -1136,3 +1137,34 @@ lua_check_ev_base (lua_State * L, gint pos)
luaL_argcheck (L, ud != NULL, pos, "'event_base' expected");
return ud ? *((struct event_base **)ud) : NULL;
}
+
+gboolean
+rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg,
+ struct event_base *ev_base)
+{
+ struct rspamd_config_post_load_script *sc;
+ struct rspamd_config **pcfg;
+ struct event_base **pev_base;
+
+ /* Execute post load scripts */
+ LL_FOREACH (cfg->on_load, sc) {
+ lua_rawgeti (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
+ pcfg = lua_newuserdata (cfg->lua_state, sizeof (*pcfg));
+ *pcfg = cfg;
+ rspamd_lua_setclass (cfg->lua_state, "rspamd{config}", -1);
+
+ pev_base = lua_newuserdata (cfg->lua_state, sizeof (*pev_base));
+ *pev_base = ev_base;
+ rspamd_lua_setclass (cfg->lua_state, "rspamd{ev_base}", -1);
+
+ if (lua_pcall (cfg->lua_state, 2, 0, 0) != 0) {
+ msg_err_config ("error executing post load code: %s",
+ lua_tostring (cfg->lua_state, -1));
+ lua_pop (cfg->lua_state, 1);
+
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index de6965414..ae0376328 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -364,5 +364,14 @@ void lua_call_finish_script (lua_State *L, struct
rspamd_config_post_load_script *sc,
struct rspamd_task *task);
+/**
+ * Run post-load operations
+ * @param L
+ * @param cfg
+ * @param ev_base
+ */
+gboolean rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg,
+ struct event_base *ev_base);
+
#endif /* WITH_LUA */
#endif /* RSPAMD_LUA_H */