summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-19 16:17:09 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-19 16:17:09 +0100
commitcd90ae359bbfacd6d0f15bf701e35ee6c9ed54eb (patch)
treedb230ea90da81a2a3d58fb674af34d7cf35676a3
parent52a9a2eed69bed33764a2eb66715711ea660fbeb (diff)
downloadrspamd-cd90ae359bbfacd6d0f15bf701e35ee6c9ed54eb.tar.gz
rspamd-cd90ae359bbfacd6d0f15bf701e35ee6c9ed54eb.zip
[Minor] Allow to initialise stat ctx via Lua API
-rw-r--r--lualib/rspamadm/mime.lua1
-rw-r--r--src/libstat/stat_config.c28
-rw-r--r--src/lua/lua_config.c6
3 files changed, 24 insertions, 11 deletions
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua
index 8caea60ed..37a7d66de 100644
--- a/lualib/rspamadm/mime.lua
+++ b/lualib/rspamadm/mime.lua
@@ -161,6 +161,7 @@ end
local function stat_handler(opts)
load_config(opts)
rspamd_url.init(rspamd_config:get_tld_path())
+ rspamd_config:init_subsystem('langdet,stat') -- Needed to gen stat tokens
local task = load_task(opts)
if opts.meta then
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c
index f5483b3ca..904be726d 100644
--- a/src/libstat/stat_config.c
+++ b/src/libstat/stat_config.c
@@ -475,17 +475,23 @@ rspamd_stat_ctx_register_async (rspamd_stat_async_handler handler,
elt->ud = d;
elt->timeout = timeout;
/* Enabled by default */
- elt->enabled = TRUE;
-
- event_set (&elt->timer_ev, -1, EV_TIMEOUT, rspamd_async_elt_on_timer, elt);
- event_base_set (st_ctx->ev_base, &elt->timer_ev);
- /*
- * First we set timeval to zero as we want cb to be executed as
- * fast as possible
- */
- elt->tv.tv_sec = 0;
- elt->tv.tv_usec = 0;
- event_add (&elt->timer_ev, &elt->tv);
+
+
+ if (st_ctx->ev_base) {
+ elt->enabled = TRUE;
+ event_set (&elt->timer_ev, -1, EV_TIMEOUT, rspamd_async_elt_on_timer, elt);
+ event_base_set (st_ctx->ev_base, &elt->timer_ev);
+ /*
+ * First we set timeval to zero as we want cb to be executed as
+ * fast as possible
+ */
+ elt->tv.tv_sec = 0;
+ elt->tv.tv_usec = 0;
+ event_add (&elt->timer_ev, &elt->tv);
+ }
+ else {
+ elt->enabled = FALSE;
+ }
g_queue_push_tail (st_ctx->async_elts, elt);
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 82f67542a..84062d46b 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -3450,6 +3450,12 @@ lua_config_init_subsystem (lua_State *L)
else if (strcmp (parts[i], "langdet") == 0) {
cfg->lang_det = rspamd_language_detector_init (cfg);
}
+ else if (strcmp (parts[i], "stat") == 0) {
+ rspamd_stat_init (cfg, NULL);
+ }
+ else {
+ return luaL_error (L, "invalid param: %s", parts[i]);
+ }
}
}
else {