]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Make rspamd protocol messages useful
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 2 Nov 2016 13:38:57 +0000 (13:38 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 2 Nov 2016 13:38:57 +0000 (13:38 +0000)
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.

src/libmime/message.c
src/libserver/protocol.c
src/libserver/task.c
src/libserver/task.h
src/lua/lua_task.c
src/plugins/spf.c

index 7fc22d1ef43ba7b85644054427f3a85b12ee993b..d9296964be9f3f9fd48a9f244a54af82cbe00b34 100644 (file)
@@ -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;
index 95490ea4c039f6c78a2a907e60e0d21cf0d62dfc..e4a042610278ef61a2aabd7720ca770085c392df 100644 (file)
@@ -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) {
index 6b92593de481e06f659b61e4ed8fec07b22def15..b9fca4d4af10fba6c07ef72704cd629fd34292e7 100644 (file)
@@ -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);
index 915d58aa364591349ba1f36adaec5afe0d01d80e..f46e09379b384a948fad53c4d311e0b20052c95a 100644 (file)
@@ -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                                           */
index e686876f7b587020a482b6e91f1b319142049afa..dcbdfc9e1ca3d20af36dc969cd119836abd21709 100644 (file)
@@ -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");
index 613c7a189222cafc0354c7f3843f43166cbe4bf1..98ca09c371ced95df70782ca3a5aec4708274e31 100644 (file)
@@ -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;
        }