]> source.dussan.org Git - rspamd.git/commitdiff
Use rspamd{text} for storing task content.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2015 21:39:37 +0000 (22:39 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Apr 2015 21:39:37 +0000 (22:39 +0100)
src/lua/lua_common.h
src/lua/lua_regexp.c
src/lua/lua_task.c

index 07ed77c145af07779511152c2e009a10e1349ed0..9299bd6510e3db06329acd6abb9f39b2e9411eb8 100644 (file)
@@ -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
  */
index ba5281299ae2e0a5c1e42c5a149577325fae46c4..fa7389537416824c69f8ea1c522ad43835ae1eec 100644 (file)
@@ -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);
index 13fe9042e394993f396c0a16103283b53df1f40b..08470fcade35d517faccf9ea50e2047a1d91b2af 100644 (file)
@@ -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;
        }