Browse Source

[Minor] Add function to inject urls into a task

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
da79576473
4 changed files with 38 additions and 3 deletions
  1. 2
    0
      src/lua/lua_common.h
  2. 32
    0
      src/lua/lua_task.c
  3. 1
    1
      src/lua/lua_url.c
  4. 3
    2
      src/plugins/lua/multimap.lua

+ 2
- 0
src/lua/lua_common.h View File

@@ -370,6 +370,8 @@ struct ev_loop *lua_check_ev_base (lua_State *L, gint pos);

struct rspamd_dns_resolver *lua_check_dns_resolver (lua_State *L, gint pos);

struct rspamd_lua_url *lua_check_url (lua_State * L, gint pos);

enum rspamd_lua_parse_arguments_flags {
RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0,
RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING,

+ 32
- 0
src/lua/lua_task.c View File

@@ -226,6 +226,12 @@ LUA_FUNCTION_DEF (task, get_urls);
* @return {boolean} true if a task has urls (urls or emails if `need_emails` is true)
*/
LUA_FUNCTION_DEF (task, has_urls);
/***
* @method task:inject_url(url)
* Inserts an url into a task (useful for redirected urls)
* @param {lua_url} url url to inject
*/
LUA_FUNCTION_DEF (task, inject_url);
/***
* @method task:get_content()
* Get raw content for the specified task
@@ -1092,6 +1098,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, append_message),
LUA_INTERFACE_DEF (task, has_urls),
LUA_INTERFACE_DEF (task, get_urls),
LUA_INTERFACE_DEF (task, inject_url),
LUA_INTERFACE_DEF (task, get_content),
LUA_INTERFACE_DEF (task, get_filename),
LUA_INTERFACE_DEF (task, get_rawbody),
@@ -2267,6 +2274,31 @@ lua_task_has_urls (lua_State * L)
return 1;
}

static gint
lua_task_inject_url (lua_State * L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task (L, 1);
struct rspamd_lua_url *url = lua_check_url (L, 2);

if (task && task->message && url && url->url) {
struct rspamd_url *existing;

if ((existing = g_hash_table_lookup (MESSAGE_FIELD (task, urls),
url->url)) == NULL) {
g_hash_table_insert (MESSAGE_FIELD (task, urls), url->url, url->url);
}
else {
existing->count ++;
}
}
else {
return luaL_error (L, "invalid arguments");
}

return 0;
}

static gint
lua_task_get_content (lua_State * L)
{

+ 1
- 1
src/lua/lua_url.c View File

@@ -102,7 +102,7 @@ static const struct luaL_reg urllib_f[] = {
{NULL, NULL}
};

static struct rspamd_lua_url *
struct rspamd_lua_url *
lua_check_url (lua_State * L, gint pos)
{
void *ud = rspamd_lua_check_udata (L, pos, "rspamd{url}");

+ 3
- 2
src/plugins/lua/multimap.lua View File

@@ -430,12 +430,13 @@ local function multimap_callback(task, rule)
local pre_filter = rule['prefilter']

local function match_element(r, value, callback)
lua_util.debugm(N, task, 'check value %s for multimap %s', value,
rule.symbol)
if not value then
return false
end

lua_util.debugm(N, task, 'check value %s for multimap %s', value,
rule.symbol)

local ret = false

if r['cdb'] then

Loading…
Cancel
Save