From 083400719fb463a0fa1e753a7431b738f26a2238 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 21 Jul 2015 10:11:06 +0100 Subject: [PATCH] Add method rspamd_mempool:has_variable. --- src/lua/lua_mempool.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index b4f15e300..8f2ad2f42 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -92,6 +92,13 @@ LUA_FUNCTION_DEF (mempool, set_variable); * @return {variable list} list of variables extracted (but **not** a table) */ LUA_FUNCTION_DEF (mempool, get_variable); +/*** + * @method mempool:has_variable(name) + * Checks if the specified variable `name` exists in the memory pool + * @param {string} name variable's name to get + * @return {boolean} `true` if variable exists and `false` otherwise + */ +LUA_FUNCTION_DEF (mempool, has_variable); static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, add_destructor), @@ -99,6 +106,7 @@ static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, suggest_size), LUA_INTERFACE_DEF (mempool, set_variable), LUA_INTERFACE_DEF (mempool, get_variable), + LUA_INTERFACE_DEF (mempool, has_variable), LUA_INTERFACE_DEF (mempool, delete), {"destroy", lua_mempool_delete}, {"__tostring", rspamd_lua_class_tostring}, @@ -392,6 +400,24 @@ lua_mempool_get_variable (lua_State *L) return 1; } +static int +lua_mempool_has_variable (lua_State *L) +{ + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); + const gchar *var = luaL_checkstring (L, 2); + gboolean ret = FALSE; + + if (mempool && var) { + if (rspamd_mempool_get_variable (mempool, var) != NULL) { + ret = TRUE; + } + } + + lua_pushboolean (L, ret); + + return 1; +} + static gint lua_load_mempool (lua_State * L) { -- 2.39.5