diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_map.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index f0520dead..2d2a098d2 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -94,6 +94,20 @@ LUA_FUNCTION_DEF (map, get_uri); */ LUA_FUNCTION_DEF (map, get_stats); +/*** + * @method map:get_data_digest() + * Get data digest for specific map + * @return {string} 64 bit number represented as string (due to Lua limitations) + */ +LUA_FUNCTION_DEF (map, get_data_digest); + +/*** + * @method map:get_nelts() + * Get number of elements for specific map + * @return {number} number of elements in the map + */ +LUA_FUNCTION_DEF (map, get_nelts); + static const struct luaL_reg maplib_m[] = { LUA_INTERFACE_DEF (map, get_key), LUA_INTERFACE_DEF (map, is_signed), @@ -103,6 +117,8 @@ static const struct luaL_reg maplib_m[] = { LUA_INTERFACE_DEF (map, set_callback), LUA_INTERFACE_DEF (map, get_uri), LUA_INTERFACE_DEF (map, get_stats), + LUA_INTERFACE_DEF (map, get_data_digest), + LUA_INTERFACE_DEF (map, get_nelts), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -868,6 +884,38 @@ lua_map_get_stats (lua_State * L) return 1; } +static gint +lua_map_get_data_digest (lua_State * L) +{ + struct rspamd_lua_map *map = lua_check_map (L, 1); + gchar numbuf[64]; + + if (map != NULL) { + rspamd_snprintf (numbuf, sizeof (numbuf), "%uL", map->map->digest); + lua_pushstring (L, numbuf); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +static gint +lua_map_get_nelts (lua_State * L) +{ + struct rspamd_lua_map *map = lua_check_map (L, 1); + + if (map != NULL) { + lua_pushnumber (L, map->map->nelts); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static int lua_map_is_signed (lua_State *L) { |