From 84a76bc874c278da6fc2c442d61d2f42914626c0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 7 Mar 2016 12:32:03 +0000 Subject: [PATCH] [Feature] Add map:is_signed method --- src/lua/lua_map.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index ee9695c51..fe8f6a836 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -26,11 +26,30 @@ * @module rspamd_map */ -/* Radix tree */ +/*** + * @method map:get_key(in) + * Variable method for different types of maps: + * + * - For hash maps it returns boolean and accepts string + * - For kv maps it returns string (or nil) and accepts string + * - For radix maps it returns boolean and accepts IP address (as object, string or number) + * + * @param {vary} in input to check + * @return {bool|string} if a value is found then this function returns string or `True` if not - then it returns `nil` or `False` + */ LUA_FUNCTION_DEF (map, get_key); + +/*** + * @method map:is_signed() + * Returns `True` if a map is signed + * @return {bool} signed value + */ +LUA_FUNCTION_DEF (map, is_signed); + static const struct luaL_reg maplib_m[] = { LUA_INTERFACE_DEF (map, get_key), + LUA_INTERFACE_DEF (map, is_signed), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -429,6 +448,27 @@ lua_map_get_key (lua_State * L) return 1; } +static int +lua_map_is_signed (lua_State *L) +{ + struct rspamd_lua_map *map = lua_check_map (L); + gboolean ret = FALSE; + + if (map != NULL) { + if (map->map) { + if (map->map->is_signed) { + ret = TRUE; + } + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + lua_pushboolean (L, ret); + return 1; +} + void luaopen_map (lua_State * L) { -- 2.39.5