]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add ability to remove variables from memory pools.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 2 Sep 2015 14:46:29 +0000 (15:46 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 2 Sep 2015 14:46:29 +0000 (15:46 +0100)
src/libutil/mem_pool.c
src/libutil/mem_pool.h
src/lua/lua_mempool.c

index 6e148a0c3ebdf949c98f9fc0b9bf3496c551a1df..8070e1c2bd5c687e9d17a9c354100a5a5296bf24 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012, Vsevolod Stakhov
+ * Copyright (c) 2009-2015, Vsevolod Stakhov
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -887,7 +887,10 @@ rspamd_mempool_get_variable (rspamd_mempool_t *pool, const gchar *name)
        return g_hash_table_lookup (pool->variables, name);
 }
 
-
-/*
- * vi:ts=4
- */
+void
+rspamd_mempool_remove_variable (rspamd_mempool_t *pool, const gchar *name)
+{
+       if (pool->variables != NULL) {
+               g_hash_table_remove (pool->variables, name);
+       }
+}
index 42df3014872bfdab0d305bb90042911b419acda4..3b0e976666ff4dc6e35703818f0e35d7aaede34a 100644 (file)
@@ -321,5 +321,12 @@ void rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name,
 gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool,
        const gchar *name);
 
+/**
+ * Removes variable from memory pool
+ * @param pool memory pool object
+ * @param name name of variable
+ */
+void rspamd_mempool_remove_variable (rspamd_mempool_t *pool,
+               const gchar *name);
 
 #endif
index 1a7b227428e8207edc9a8df23810805be48b5905..65c8e4f1203cf3a07598e3b69859020152fad91e 100644 (file)
@@ -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)
 {