summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-07 22:39:37 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-07 22:39:37 +0100
commitf29ecb6a74cd7aea7c67682b5b6172c4094253dd (patch)
treeee86889dff5d06de6b6cdc4dbc4980af540e6b12
parentcdd553cc27cc230662025663e353a9a7c8ce5e8a (diff)
downloadrspamd-f29ecb6a74cd7aea7c67682b5b6172c4094253dd.tar.gz
rspamd-f29ecb6a74cd7aea7c67682b5b6172c4094253dd.zip
Use rspamd{text} for storing task content.
-rw-r--r--src/lua/lua_common.h23
-rw-r--r--src/lua/lua_regexp.c16
-rw-r--r--src/lua/lua_task.c14
3 files changed, 35 insertions, 18 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 07ed77c14..9299bd651 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -55,6 +55,19 @@ struct lua_locked_state {
rspamd_mutex_t *m;
};
+/**
+ * Lua IP address structure
+ */
+struct rspamd_lua_ip {
+ rspamd_inet_addr_t *addr;
+};
+
+struct rspamd_lua_text {
+ const gchar *start;
+ gsize len;
+};
+
+
/* Common utility functions */
/**
@@ -132,6 +145,8 @@ void rspamd_lua_task_push (lua_State *L, struct rspamd_task *task);
*/
struct rspamd_lua_ip * lua_check_ip (lua_State * L, gint pos);
+struct rspamd_lua_text * lua_check_text (lua_State * L, gint pos);
+
/**
* Check for task at the specified position
*/
@@ -146,14 +161,6 @@ void rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str);
* Create type error
*/
int rspamd_lua_typerror (lua_State *L, int narg, const char *tname);
-
-/**
- * Lua IP address structure
- */
-struct rspamd_lua_ip {
- rspamd_inet_addr_t *addr;
-};
-
/**
* Open libraries functions
*/
diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index ba5281299..fa7389537 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -285,12 +285,22 @@ static int
lua_regexp_match (lua_State *L)
{
struct rspamd_lua_regexp *re = lua_check_regexp (L);
- const gchar *data;
- gsize len;
+ struct rspamd_lua_text *t;
+ const gchar *data = NULL;
+ gsize len = 0;
gboolean raw = FALSE;
if (re) {
- data = luaL_checklstring (L, 2, &len);
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ data = luaL_checklstring (L, 2, &len);
+ }
+ else if (lua_type (L, 2) == LUA_TUSERDATA) {
+ t = lua_check_text (L, 2);
+ if (t != NULL) {
+ data = t->start;
+ len = t->len;
+ }
+ }
if (lua_gettop (L) == 3) {
raw = lua_toboolean (L, 3);
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 13fe9042e..08470fcad 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -684,11 +684,6 @@ static const struct luaL_reg urllib_m[] = {
};
/* Blob methods */
-struct rspamd_lua_text {
- const gchar *start;
- gsize len;
-};
-
LUA_FUNCTION_DEF (text, len);
LUA_FUNCTION_DEF (text, str);
@@ -740,7 +735,7 @@ lua_check_url (lua_State * L)
return ud ? *((struct rspamd_url **)ud) : NULL;
}
-static struct rspamd_lua_text *
+struct rspamd_lua_text *
lua_check_text (lua_State * L, gint pos)
{
void *ud = luaL_checkudata (L, pos, "rspamd{text}");
@@ -1016,9 +1011,14 @@ static gint
lua_task_get_content (lua_State * L)
{
struct rspamd_task *task = lua_check_task (L, 1);
+ struct rspamd_lua_text *t;
if (task) {
- lua_pushlstring (L, task->msg.start, task->msg.len);
+ t = lua_newuserdata (L, sizeof (*t));
+ rspamd_lua_setclass (L, "rspamd{text}", -1);
+ t->len = task->msg.len;
+ t->start = task->msg.start;
+
return 1;
}