]> source.dussan.org Git - rspamd.git/commitdiff
Add method rspamd_mempool:has_variable.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 21 Jul 2015 09:11:06 +0000 (10:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 21 Jul 2015 09:11:06 +0000 (10:11 +0100)
src/lua/lua_mempool.c

index b4f15e30078e1d171105b799d9db1ee1324fa651..8f2ad2f426c990dbee3265e0edfedab3f3e4bc2d 100644 (file)
@@ -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)
 {