aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mempool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-21 10:11:06 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-21 10:11:06 +0100
commit083400719fb463a0fa1e753a7431b738f26a2238 (patch)
tree2ea134ee0bae68addfd8c2e653e9a4746339e4d5 /src/lua/lua_mempool.c
parent5368d1f1a8358351a62380f6ddcce1fe1a6edead (diff)
downloadrspamd-083400719fb463a0fa1e753a7431b738f26a2238.tar.gz
rspamd-083400719fb463a0fa1e753a7431b738f26a2238.zip
Add method rspamd_mempool:has_variable.
Diffstat (limited to 'src/lua/lua_mempool.c')
-rw-r--r--src/lua/lua_mempool.c26
1 files changed, 26 insertions, 0 deletions
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)
{