From: Vsevolod Stakhov Date: Wed, 2 Nov 2016 13:38:57 +0000 (+0000) Subject: [Rework] Make rspamd protocol messages useful X-Git-Tag: 1.4.0~139 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a1bdb1f4f56ea6b3877e9c9d030d085728f0d566;p=rspamd.git [Rework] Make rspamd protocol messages useful Each message is now represented by a string and category, so messages in metric is an UCL object of the following format: { "category": "string" } The significant category is `smtp_message` which should be used by rmilter to send a custom SMTP reply to a client. --- diff --git a/src/libmime/message.c b/src/libmime/message.c index 7fc22d1ef..d9296964b 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1052,6 +1052,9 @@ process_text_part (struct rspamd_task *task, task->pre_result.action = METRIC_ACTION_REJECT; task->pre_result.str = "Gtube pattern"; + ucl_object_insert_key (task->messages, + ucl_object_fromstring ("Gtube pattern"), "smtp_message", 0, + false); rspamd_task_insert_result (task, GTUBE_SYMBOL, 0, NULL); return; diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 95490ea4c..e4a042610 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -1014,10 +1014,8 @@ rspamd_protocol_write_ucl (struct rspamd_task *task) ucl_object_insert_key (top, obj, h, 0, false); } - if (task->messages != NULL) { - ucl_object_insert_key (top, rspamd_str_list_ucl ( - task->messages), "messages", 0, false); - } + ucl_object_insert_key (top, ucl_object_ref (task->messages), + "messages", 0, false); if (task->cfg->log_urls || (task->flags & RSPAMD_TASK_FLAG_EXT_URLS)) { if (g_hash_table_size (task->urls) > 0) { diff --git a/src/libserver/task.c b/src/libserver/task.c index 6b92593de..b9fca4d4a 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -128,6 +128,7 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg) new_task->pre_result.action = METRIC_ACTION_MAX; new_task->message_id = new_task->queue_id = "undef"; + new_task->messages = ucl_object_typed_new (UCL_OBJECT); return new_task; } @@ -233,9 +234,7 @@ rspamd_task_free (struct rspamd_task *task) rspamd_email_address_unref (task->from_envelope); } - if (task->messages) { - g_list_free (task->messages); - } + ucl_object_unref (task->messages); if (task->http_conn != NULL) { rspamd_http_connection_reset (task->http_conn); diff --git a/src/libserver/task.h b/src/libserver/task.h index 915d58aa3..f46e09379 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -163,7 +163,7 @@ struct rspamd_task { struct rspamd_email_address *from_envelope; enum rspamd_newlines_type nlines_type; /**< type of newlines (detected on most of headers */ - GList *messages; /**< list of messages that would be reported */ + ucl_object_t *messages; /**< list of messages that would be reported */ struct rspamd_re_runtime *re_rt; /**< regexp runtime */ GPtrArray *stat_runtimes; /**< backend runtime */ struct rspamd_config *cfg; /**< pointer to config object */ diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index e686876f7..dcbdfc9e1 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1093,7 +1093,9 @@ lua_task_set_pre_result (lua_State * L) action_str = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3)); task->pre_result.str = action_str; - task->messages = g_list_prepend (task->messages, action_str); + ucl_object_insert_key (task->messages, + ucl_object_fromstring (action_str), "smtp_message", 0, + false); } else { task->pre_result.str = "unknown"; @@ -1123,12 +1125,19 @@ static gint lua_task_append_message (lua_State * L) { struct rspamd_task *task = lua_check_task (L, 1); - gchar *message; + const gchar *message = luaL_checkstring (L, 2), *category; if (task != NULL) { - message= rspamd_mempool_strdup (task->task_pool, - luaL_checkstring (L, 2)); - task->messages = g_list_prepend (task->messages, message); + if (lua_type (L, 3) == LUA_TSTRING) { + category = luaL_checkstring (L, 3); + } + else { + category = "unknown"; + } + + ucl_object_insert_key (task->messages, + ucl_object_fromstring (message), category, 0, + true); } else { return luaL_error (L, "invalid arguments"); diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 613c7a189..98ca09c37 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -465,7 +465,10 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr, spf_symbol, 1, opts); - task->messages = g_list_prepend (task->messages, (gpointer)spf_message); + ucl_object_insert_key (task->messages, + ucl_object_fromstring (spf_message), "spf", 0, + false); + return TRUE; }