aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-10 21:39:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-10 21:39:27 +0000
commit552834325062f9743715824dea168063dff20c4d (patch)
tree275fe3cde3a0d0a09318a735d6a84a3751a299b0
parentc2cbcd8d98ae8e1b8d1ef06bc6dc53f77ac3bd16 (diff)
downloadrspamd-552834325062f9743715824dea168063dff20c4d.tar.gz
rspamd-552834325062f9743715824dea168063dff20c4d.zip
Add task:has_urls method
-rw-r--r--src/lua/lua_task.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 2eaeb221d..3731b059e 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -114,8 +114,9 @@ end
*/
LUA_FUNCTION_DEF (task, set_pre_result);
/***
- * @method task:get_urls()
+ * @method task:get_urls([need_emails])
* Get all URLs found in a message.
+ * @param {boolean} need_emails if `true` then reutrn also email urls
* @return {table rspamd_url} list of all urls found
@example
local function phishing_cb(task)
@@ -133,6 +134,13 @@ end
*/
LUA_FUNCTION_DEF (task, get_urls);
/***
+ * @method task:has_urls([need_emails])
+ * Returns 'true' if a task has urls listed
+ * @param {boolean} need_emails if `true` then reutrn also email 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:get_content()
* Get raw content for the specified task
* @return {string} the data contained in the task
@@ -546,6 +554,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_ev_base),
LUA_INTERFACE_DEF (task, insert_result),
LUA_INTERFACE_DEF (task, set_pre_result),
+ LUA_INTERFACE_DEF (task, has_urls),
LUA_INTERFACE_DEF (task, get_urls),
LUA_INTERFACE_DEF (task, get_content),
LUA_INTERFACE_DEF (task, get_emails),
@@ -887,12 +896,22 @@ lua_task_get_urls (lua_State * L)
{
struct rspamd_task *task = lua_check_task (L, 1);
struct lua_tree_cb_data cb;
+ gboolean need_emails = FALSE;
if (task) {
+ if (lua_gettop (L) >= 2) {
+ need_emails = lua_toboolean (L, 2);
+ }
+
lua_newtable (L);
cb.i = 1;
cb.L = L;
g_hash_table_foreach (task->urls, lua_tree_url_callback, &cb);
+
+ if (need_emails) {
+ g_hash_table_foreach (task->emails, lua_tree_url_callback, &cb);
+ }
+
return 1;
}
@@ -901,6 +920,31 @@ lua_task_get_urls (lua_State * L)
}
static gint
+lua_task_has_urls (lua_State * L)
+{
+ struct rspamd_task *task = lua_check_task (L, 1);
+ gboolean need_emails = FALSE, ret = FALSE;
+
+ if (task) {
+ if (lua_gettop (L) >= 2) {
+ need_emails = lua_toboolean (L, 2);
+ }
+
+ if (g_hash_table_size (task->urls) > 0) {
+ ret = TRUE;
+ }
+
+ if (need_emails && g_hash_table_size (task->emails) > 0) {
+ ret = TRUE;
+ }
+ }
+
+ lua_pushboolean (L, ret);
+
+ return 1;
+}
+
+static gint
lua_task_get_content (lua_State * L)
{
struct rspamd_task *task = lua_check_task (L, 1);