summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-28 14:54:47 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-28 14:54:47 +0100
commit8a2e6e8817ffbc32032b03885e4c2004590d1dc8 (patch)
tree952aa87ab4929021af8ee1b54053930f8c2117ab
parentdec86ca07dcd95d2eba47aaa946f1e95acfc9f57 (diff)
downloadrspamd-8a2e6e8817ffbc32032b03885e4c2004590d1dc8.tar.gz
rspamd-8a2e6e8817ffbc32032b03885e4c2004590d1dc8.zip
[Minor] Add missing helper methods
-rw-r--r--src/lua/lua_map.c48
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)
{