Browse Source

[Project] Various fixes for lua_content project

tags/2.3
Vsevolod Stakhov 4 years ago
parent
commit
074033b9aa
4 changed files with 25 additions and 10 deletions
  1. 11
    5
      src/libmime/message.c
  2. 8
    2
      src/lua/lua_common.c
  3. 1
    0
      src/lua/lua_mimepart.c
  4. 5
    3
      test/functional/cases/102_multimap.robot

+ 11
- 5
src/libmime/message.c View File

@@ -1315,7 +1315,7 @@ rspamd_message_process (struct rspamd_task *task)
guint tw, *ptw, dw;
struct rspamd_mime_part *part;
lua_State *L = NULL;
gint magic_func_pos = -1, content_func_pos = -1, old_top = -1;
gint magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1;

if (task->cfg) {
L = task->cfg->lua_state;
@@ -1343,11 +1343,15 @@ rspamd_message_process (struct rspamd_task *task)
msg_err_task ("cannot require lua_content.maybe_process_mime_part");
}

funcs_top = lua_gettop (L);

PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
if (magic_func_pos != -1 && part->parsed_data.len > 0) {
struct rspamd_mime_part **pmime;
struct rspamd_task **ptask;

lua_pushcfunction (L, &rspamd_lua_traceback);
gint err_idx = lua_gettop (L);
lua_pushvalue (L, magic_func_pos);
pmime = lua_newuserdata (L, sizeof (struct rspamd_mime_part *));
rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
@@ -1356,7 +1360,7 @@ rspamd_message_process (struct rspamd_task *task)
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;

if (lua_pcall (L, 2, 2, 0) != 0) {
if (lua_pcall (L, 2, 2, err_idx) != 0) {
msg_err_task ("cannot detect type: %s", lua_tostring (L, -1));
}
else {
@@ -1396,7 +1400,7 @@ rspamd_message_process (struct rspamd_task *task)
}
}

lua_settop (L, magic_func_pos);
lua_settop (L, funcs_top);
}

/* Now detect content */
@@ -1404,6 +1408,8 @@ rspamd_message_process (struct rspamd_task *task)
struct rspamd_mime_part **pmime;
struct rspamd_task **ptask;

lua_pushcfunction (L, &rspamd_lua_traceback);
gint err_idx = lua_gettop (L);
lua_pushvalue (L, content_func_pos);
pmime = lua_newuserdata (L, sizeof (struct rspamd_mime_part *));
rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
@@ -1412,11 +1418,11 @@ rspamd_message_process (struct rspamd_task *task)
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;

if (lua_pcall (L, 2, 2, 0) != 0) {
if (lua_pcall (L, 2, 0, err_idx) != 0) {
msg_err_task ("cannot detect content: %s", lua_tostring (L, -1));
}

lua_settop (L, magic_func_pos);
lua_settop (L, funcs_top);
}

if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {

+ 8
- 2
src/lua/lua_common.c View File

@@ -1829,8 +1829,14 @@ rspamd_lua_get_traceback_string (lua_State *L, luaL_Buffer *buf)
{
const gchar *msg = lua_tostring (L, -1);

luaL_addstring (buf, msg);
lua_pop (L, 1); /* Error string */
if (msg) {
luaL_addstring (buf, msg);
lua_pop (L, 1); /* Error string */
}
else {
luaL_addstring (buf, "unknown error");
}

luaL_addstring (buf, "; trace:");
rspamd_lua_traceback_string (L, buf);
}

+ 1
- 0
src/lua/lua_mimepart.c View File

@@ -2106,6 +2106,7 @@ lua_mimepart_set_specific (lua_State * L)
luaL_unref (L, LUA_REGISTRYINDEX, part->specific.lua_specific.cbref);
}
else {
part->part_type = RSPAMD_MIME_PART_CUSTOM_LUA;
lua_pushnil (L);
}


+ 5
- 3
test/functional/cases/102_multimap.robot View File

@@ -25,6 +25,10 @@ ${FREEMAIL_CC} ${TESTDIR}/messages/freemailcc.eml
${URL_ICS} ${TESTDIR}/messages/ics.eml

*** Test Cases ***
URL_ICS
${result} = Scan Message With Rspamc ${URL_ICS}
Check Rspamc ${result} Urls: ["test.com"]

MAP - DNSBL HIT
${result} = Scan Message With Rspamc ${MESSAGE} -i 127.0.0.2
Check Rspamc ${result} DNSBL_MAP
@@ -327,9 +331,7 @@ FREEMAIL_CC
${result} = Scan Message With Rspamc ${FREEMAIL_CC}
Check Rspamc ${result} FREEMAIL_CC (19.00)[test.com, test1.com, test2.com, test3.com, test4.com, test5.com, test6.com, test7.com, test8.com, test9.com, test10.com, test11.com, test12.com, test13.com, test14.com]

URL_ICS
${result} = Scan Message With Rspamc ${URL_ICS}
Check Rspamc ${result} Urls: ["test.com"]


*** Keywords ***
Multimap Setup

Loading…
Cancel
Save