From: Vsevolod Stakhov Date: Tue, 19 Jun 2018 15:17:09 +0000 (+0100) Subject: [Minor] Allow to initialise stat ctx via Lua API X-Git-Tag: 1.7.7~83 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cd90ae359bbfacd6d0f15bf701e35ee6c9ed54eb;p=rspamd.git [Minor] Allow to initialise stat ctx via Lua API --- 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 {