diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-04-26 17:20:47 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-04-26 17:20:47 +0100 |
commit | 147df4300a76d4865f62cea0f3c9e33c2e8d34b0 (patch) | |
tree | 43ff02fe78ec9275a633c2d4d66efb03d377008d /src | |
parent | 5cf3888a94c98f617a2287cd5e92139abcc85f64 (diff) | |
download | rspamd-147df4300a76d4865f62cea0f3c9e33c2e8d34b0.tar.gz rspamd-147df4300a76d4865f62cea0f3c9e33c2e8d34b0.zip |
[Feature] Implement map statistics function for lua API
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_map.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 7f5195d8e..f0520dead 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -831,6 +831,43 @@ lua_map_get_key (lua_State * L) return 1; } +static gboolean +lua_map_traverse_cb (gconstpointer key, + gconstpointer value, gsize hits, gpointer ud) +{ + lua_State *L = (lua_State *)ud; + + lua_pushstring (L, key); + lua_pushnumber (L, hits); + lua_settable (L, -3); + + return TRUE; +} + +static gint +lua_map_get_stats (lua_State * L) +{ + struct rspamd_lua_map *map = lua_check_map (L, 1); + gboolean do_reset = FALSE; + + if (map != NULL) { + if (lua_isboolean (L, 2)) { + do_reset = lua_toboolean (L, 2); + } + + lua_createtable (L, 0, map->map->nelts); + + if (map->map->traverse_function) { + rspamd_map_traverse (map->map, lua_map_traverse_cb, L, do_reset); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static int lua_map_is_signed (lua_State *L) { |