--- /dev/null
+--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
+
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);
/* 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);
/* error function */
lua_pop (L, 1);
+ luaL_unref (L, LUA_REGISTRYINDEX, cb_idx);
+
return TRUE;
}