From: Vsevolod Stakhov Date: Tue, 15 Dec 2015 00:19:34 +0000 (+0000) Subject: Fix calling of lua from rspamadm X-Git-Tag: 1.1.0~300 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fc03163fa5d8eb36491124c65998f090f35586e2;p=rspamd.git Fix calling of lua from rspamadm --- diff --git a/src/rspamadm/fuzzy_stat.lua b/src/rspamadm/fuzzy_stat.lua new file mode 100644 index 000000000..5bc49d114 --- /dev/null +++ b/src/rspamadm/fuzzy_stat.lua @@ -0,0 +1,75 @@ +--Res here is the table of the following args: +--workers: { +-- pid: { +-- data: { +-- key_id: { +-- matched: +-- scanned: +-- added: +-- removed: +-- errors: +-- last_ips: { +-- ip: { +-- matched: +-- scanned +-- added: +-- removed: +-- } +-- } +-- } +-- } +-- } +--} + +local function add_data(target, src) + for k,v in pairs(src) do + if k ~= 'ips' then + if target[k] then + target[k] = target[k] + v + else + target[k] = v + end + else + if target['ips'] then + add_data(target['ips'], v) + else + target['ips'] = {} + add_data(target['ips'], v) + end + end + end +end + +return function(args, res) + local res_keys = {} + local res_ips = {} + + local wrk = res['workers'] + + if wrk then + for i,pr in pairs(wrk) do + -- processes cycle + if pr['data'] then + for k,elts in pairs(pr['data']) do + -- keys cycle + if not res_keys[k] then + res_keys[k] = {} + end + add_data(res_keys[k], elts) + + if elts['ips'] then + for ip,v in pairs(elts['ips']) do + if not res_ips[ip] then + res_ips[ip] = {} + end + add_data(res_ips[ip], v) + end + end + end + end + end + end + + +end + diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index ac12359e1..735f1299d 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -226,6 +226,9 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, lua_pushcfunction (L, &rspamd_lua_traceback); err_idx = lua_gettop (L); + /* Push function */ + lua_rawgeti (L, LUA_REGISTRYINDEX, cb_idx); + /* Push argv */ lua_newtable (L); @@ -237,9 +240,9 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, /* Push results */ ucl_object_push_lua (L, res, TRUE); - if (lua_pcall (L, 1, 0, err_idx) != 0) { + if (lua_pcall (L, 2, 0, err_idx) != 0) { tb = lua_touserdata (L, -1); - msg_err ("call to user extraction script failed: %v", tb); + msg_err ("call to adm lua script failed: %v", tb); g_string_free (tb, TRUE); lua_pop (L, 1); @@ -249,6 +252,8 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv, /* error function */ lua_pop (L, 1); + luaL_unref (L, LUA_REGISTRYINDEX, cb_idx); + return TRUE; }