diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-02 15:46:29 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-02 15:46:29 +0100 |
commit | 24bafd7640395e5d0df8e919771580b1755dec8e (patch) | |
tree | f5dfca2e4b004458b9be7238ea2b89a9715d7b27 /src/lua | |
parent | d24b87d24c4e6c363a00a6590f5b2cf387efda20 (diff) | |
download | rspamd-24bafd7640395e5d0df8e919771580b1755dec8e.tar.gz rspamd-24bafd7640395e5d0df8e919771580b1755dec8e.zip |
Add ability to remove variables from memory pools.
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_mempool.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index 1a7b22742..65c8e4f12 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -100,6 +100,14 @@ LUA_FUNCTION_DEF (mempool, get_variable); */ LUA_FUNCTION_DEF (mempool, has_variable); +/*** + * @method mempool:delete_variable(name) + * Removes the specified variable `name` from the memory pool + * @param {string} name variable's name to remove + * @return {boolean} `true` if variable exists and has been removed + */ +LUA_FUNCTION_DEF (mempool, delete_variable); + static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, add_destructor), LUA_INTERFACE_DEF (mempool, stat), @@ -107,6 +115,7 @@ static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, set_variable), LUA_INTERFACE_DEF (mempool, get_variable), LUA_INTERFACE_DEF (mempool, has_variable), + LUA_INTERFACE_DEF (mempool, delete_variable), LUA_INTERFACE_DEF (mempool, delete), {"destroy", lua_mempool_delete}, {"__tostring", rspamd_lua_class_tostring}, @@ -417,6 +426,26 @@ lua_mempool_has_variable (lua_State *L) return 1; } +static int +lua_mempool_delete_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; + + rspamd_mempool_remove_variable (mempool, var); + } + } + + lua_pushboolean (L, ret); + + return 1; +} + static gint lua_load_mempool (lua_State * L) { |