]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to initialise stat ctx via Lua API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 19 Jun 2018 15:17:09 +0000 (16:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 19 Jun 2018 15:17:09 +0000 (16:17 +0100)
lualib/rspamadm/mime.lua
src/libstat/stat_config.c
src/lua/lua_config.c

index 8caea60ed79bbdf9fb404b016906a71432f73eb9..37a7d66deed43c53a9c72a9a457be71e85d224e9 100644 (file)
@@ -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
index f5483b3ca7a7338b41bd4e2db157289dc3e50ff0..904be726d61b57069321ef6303b7b3af73e909b7 100644 (file)
@@ -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);
 
index 82f67542a9e1bed4ae647b85c8a9aa35d35c7e88..84062d46bc71ffca44ec2af3e57eef5cee316ea3 100644 (file)
@@ -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 {