aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_task.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-11 15:35:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-11 15:35:07 +0100
commit98f0a701b71191a7b0373b8dd511bcf5f409e440 (patch)
treee94d06ebaed1bdccaeb4e5613a5d2603a3e6c238 /src/lua/lua_task.c
parentf5051a01e8d0c622682f8a282b818ff3a31be01a (diff)
downloadrspamd-98f0a701b71191a7b0373b8dd511bcf5f409e440.tar.gz
rspamd-98f0a701b71191a7b0373b8dd511bcf5f409e440.zip
[Project] Finish rework of passthrough actions
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r--src/lua/lua_task.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 7f2711e19..a6b32b089 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1567,8 +1567,10 @@ lua_task_set_pre_result (lua_State * L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task (L, 1);
- gchar *action_str;
+ const gchar *message = NULL, *module = NULL;
+ gdouble score = NAN;
gint action = METRIC_ACTION_MAX;
+ guint priority = RSPAMD_PASSTHROUGH_NORMAL;
if (task != NULL) {
@@ -1584,26 +1586,38 @@ lua_task_set_pre_result (lua_State * L)
rspamd_action_from_str (lua_tostring (L, 2), &action);
}
- if (action < METRIC_ACTION_MAX && action >= METRIC_ACTION_REJECT) {
- /* We also need to set the default metric to that result */
+ if (lua_type (L, 3) == LUA_TSTRING) {
+ message = lua_tostring (L, 3);
- task->pre_result.action = action;
+ /* Keep compatibility here :( */
+ ucl_object_replace_key (task->messages,
+ ucl_object_fromstring (message), "smtp_message", 0,
+ false);
+ }
+ else {
+ message = "unknown reason";
+ }
- if (lua_gettop (L) >= 3) {
- action_str = rspamd_mempool_strdup (task->task_pool,
- luaL_checkstring (L, 3));
- task->pre_result.str = action_str;
- ucl_object_replace_key (task->messages,
- ucl_object_fromstring (action_str), "smtp_message", 0,
- false);
- }
- else {
- task->pre_result.str = "unknown";
- }
+ if (lua_type (L, 4) == LUA_TSTRING) {
+ module = lua_tostring (L, 4);
+ }
+ else {
+ module = "Unknown lua";
+ }
+
+ if (lua_type (L, 5) == LUA_TNUMBER) {
+ score = lua_tonumber (L, 5);
+ }
+
+ if (lua_type (L, 6) == LUA_TNUMBER) {
+ priority = lua_tonumber (L, 5);
+ }
+
+ if (action < METRIC_ACTION_MAX && action >= METRIC_ACTION_REJECT) {
- msg_info_task ("<%s>: set pre-result to %s: '%s'",
- task->message_id, rspamd_action_to_str (action),
- task->pre_result.str);
+ rspamd_add_passthrough_result (task, action, priority,
+ score, rspamd_mempool_strdup (task->task_pool, message),
+ rspamd_mempool_strdup (task->task_pool, module));
/* Don't classify or filter message if pre-filter sets results */
task->processed_stages |= (RSPAMD_TASK_STAGE_FILTERS |
@@ -1629,7 +1643,7 @@ lua_task_has_pre_result (lua_State * L)
struct rspamd_task *task = lua_check_task (L, 1);
if (task) {
- lua_pushboolean (L, task->pre_result.action != METRIC_ACTION_MAX);
+ lua_pushboolean (L, task->result->passthrough_result != NULL);
}
else {
return luaL_error (L, "invalid arguments");