aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-27 09:32:24 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-27 09:32:24 +0000
commit0b3f5dcc9a8f6bebb0e18a58904e8946b378108a (patch)
tree72009b267302cba3011702c06056e2bd8e1b1177 /src
parenteb5f3f58722c839adec4865faaf12848cddadf9f (diff)
downloadrspamd-0b3f5dcc9a8f6bebb0e18a58904e8946b378108a.tar.gz
rspamd-0b3f5dcc9a8f6bebb0e18a58904e8946b378108a.zip
[Minor] Lua_text: Add concat method
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_text.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index 72ca66956..5bbcfb96e 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -202,6 +202,7 @@ LUA_FUNCTION_DEF (text, hex);
LUA_FUNCTION_DEF (text, gc);
LUA_FUNCTION_DEF (text, eq);
LUA_FUNCTION_DEF (text, lt);
+LUA_FUNCTION_DEF (text, concat);
static const struct luaL_reg textlib_f[] = {
LUA_INTERFACE_DEF (text, fromstring),
@@ -238,6 +239,7 @@ static const struct luaL_reg textlib_m[] = {
{"__gc", lua_text_gc},
{"__eq", lua_text_eq},
{"__lt", lua_text_lt},
+ {"__concat", lua_text_concat},
{NULL, NULL}
};
@@ -262,8 +264,14 @@ lua_check_text_or_string (lua_State * L, gint pos)
else if (pos_type == LUA_TSTRING) {
/* Fake static lua_text */
static struct rspamd_lua_text fake_text;
+ gsize len;
- fake_text.start = lua_tolstring (L, pos, &fake_text.len);
+ fake_text.start = lua_tolstring (L, pos, &len);
+ if (len >= G_MAXUINT) {
+ return NULL;
+ }
+
+ fake_text.len = len;
fake_text.flags = RSPAMD_TEXT_FLAG_FAKE;
return &fake_text;
@@ -1134,7 +1142,7 @@ static gint
lua_text_eq (lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_text *t1 = lua_check_text (L, 1),
+ struct rspamd_lua_text *t1 = lua_check_text_or_string (L, 1),
*t2 = lua_check_text_or_string (L, 2);
if (t1->len == t2->len) {
@@ -1151,7 +1159,7 @@ static gint
lua_text_lt (lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_text *t1 = lua_check_text (L, 1),
+ struct rspamd_lua_text *t1 = lua_check_text_or_string (L, 1),
*t2 = lua_check_text_or_string (L, 2);
if (t1 && t2) {
@@ -1167,6 +1175,24 @@ lua_text_lt (lua_State *L)
}
static gint
+lua_text_concat (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_text *t1 = lua_check_text_or_string (L, 1),
+ *t2 = lua_check_text_or_string (L, 2);
+
+ if (t1 && t2) {
+ struct rspamd_lua_text *final;
+
+ final = lua_new_text (L, NULL, t1->len + t2->len, TRUE);
+ memcpy ((void *)final->start, t1->start, t1->len);
+ memcpy ((void *)(final->start + t1->len), t2->start, t2->len);
+ }
+
+ return 1;
+}
+
+static gint
lua_text_wipe (lua_State *L)
{
LUA_TRACE_POINT;