summaryrefslogtreecommitdiffstats
path: root/src/rspamadm
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-15 00:19:34 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-15 00:19:34 +0000
commitfc03163fa5d8eb36491124c65998f090f35586e2 (patch)
tree5ccb0b08dc93e6e3e3769023291e4eb5eab718c6 /src/rspamadm
parentd10258807cdfb85ccf103959b50d954d08ddb3cc (diff)
downloadrspamd-fc03163fa5d8eb36491124c65998f090f35586e2.tar.gz
rspamd-fc03163fa5d8eb36491124c65998f090f35586e2.zip
Fix calling of lua from rspamadm
Diffstat (limited to 'src/rspamadm')
-rw-r--r--src/rspamadm/fuzzy_stat.lua75
-rw-r--r--src/rspamadm/rspamadm.c9
2 files changed, 82 insertions, 2 deletions
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;
}