summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-18 13:28:53 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-18 13:28:53 +0000
commitcc632bdee66a9d4232ff446c2c963d377c5fc350 (patch)
tree932c921e351bf530c5abc270c69b205eb49f78f4
parentb582a1219d8b2b1e817359cf64fafd3b32ff72a9 (diff)
downloadrspamd-cc632bdee66a9d4232ff446c2c963d377c5fc350.tar.gz
rspamd-cc632bdee66a9d4232ff446c2c963d377c5fc350.zip
[Minor] Allow to take ownership on rspamd_text
-rw-r--r--src/lua/lua_task.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 96cab157b..3460aebcb 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -906,12 +906,14 @@ LUA_FUNCTION_DEF (text, len);
LUA_FUNCTION_DEF (text, str);
LUA_FUNCTION_DEF (text, ptr);
LUA_FUNCTION_DEF (text, save_in_file);
+LUA_FUNCTION_DEF (text, take_ownership);
LUA_FUNCTION_DEF (text, gc);
static const struct luaL_reg textlib_m[] = {
LUA_INTERFACE_DEF (text, len),
LUA_INTERFACE_DEF (text, str),
LUA_INTERFACE_DEF (text, ptr),
+ LUA_INTERFACE_DEF (text, take_ownership),
LUA_INTERFACE_DEF (text, save_in_file),
{"__len", lua_text_len},
{"__tostring", lua_text_str},
@@ -4198,6 +4200,32 @@ lua_text_ptr (lua_State *L)
}
static gint
+lua_text_take_ownership (lua_State *L)
+{
+ struct rspamd_lua_text *t = lua_check_text (L, 1);
+ gchar *dest;
+
+ if (t != NULL) {
+ if (t->flags & RSPAMD_TEXT_FLAG_OWN) {
+ /* We already own it */
+ lua_pushboolean (L, true);
+ }
+ else {
+ dest = g_malloc (t->len);
+ memcpy (dest, t->start, t->len);
+ t->start = dest;
+ t->flags |= RSPAMD_TEXT_FLAG_OWN;
+ lua_pushboolean (L, true);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_text_save_in_file (lua_State *L)
{
struct rspamd_lua_text *t = lua_check_text (L, 1);