aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-02 15:46:29 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-02 15:46:29 +0100
commit24bafd7640395e5d0df8e919771580b1755dec8e (patch)
treef5dfca2e4b004458b9be7238ea2b89a9715d7b27
parentd24b87d24c4e6c363a00a6590f5b2cf387efda20 (diff)
downloadrspamd-24bafd7640395e5d0df8e919771580b1755dec8e.tar.gz
rspamd-24bafd7640395e5d0df8e919771580b1755dec8e.zip
Add ability to remove variables from memory pools.
-rw-r--r--src/libutil/mem_pool.c13
-rw-r--r--src/libutil/mem_pool.h7
-rw-r--r--src/lua/lua_mempool.c29
3 files changed, 44 insertions, 5 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index 6e148a0c3..8070e1c2b 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -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);
+ }
+}
diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h
index 42df30148..3b0e97666 100644
--- a/src/libutil/mem_pool.h
+++ b/src/libutil/mem_pool.h
@@ -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
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)
{