]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Allow to change log tag from HTTP request
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 3 Aug 2024 16:11:04 +0000 (17:11 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 3 Aug 2024 16:11:04 +0000 (17:11 +0100)
src/libserver/protocol.c
src/libserver/protocol_internal.h

index db83b0bfb9099f6e69408acd00c0f08d5afc62bc..ee21929130e4093a1419d9e0780ff02a344522fe 100644 (file)
@@ -660,9 +660,9 @@ rspamd_protocol_handle_headers(struct rspamd_task *task,
                IF_HEADER(USER_HEADER)
                {
                        /*
-                                        * We must ignore User header in case of spamc, as SA has
-                                        * different meaning of this header
-                                        */
+                                                                * We must ignore User header in case of spamc, as SA has
+                                                                * different meaning of this header
+                                                                */
                        msg_debug_protocol("read user header, value: %T", hv_tok);
                        if (!RSPAMD_TASK_IS_SPAMC(task)) {
                                task->auth_user = rspamd_mempool_ftokdup(task->task_pool,
@@ -708,6 +708,15 @@ rspamd_protocol_handle_headers(struct rspamd_task *task,
                                task->flags |= RSPAMD_TASK_FLAG_NO_LOG;
                        }
                }
+               IF_HEADER(LOG_TAG_HEADER)
+               {
+                       msg_debug_protocol("read log-tag header, value: %T", hv_tok);
+                       /* Ensure that a tag is valid */
+                       if (rspamd_fast_utf8_validate(hv_tok->begin, hv_tok->len) == 0) {
+                               memcpy(task->task_pool->tag.uid, hv_tok->begin,
+                                          MIN(hv_tok->len, sizeof(task->task_pool->tag.uid)));
+                       }
+               }
                break;
        case 'm':
        case 'M':
@@ -752,9 +761,9 @@ rspamd_protocol_handle_headers(struct rspamd_task *task,
        default:
                msg_debug_protocol("generic header: %T", hn_tok);
                break;
-                       }
+                               }
 
-                       rspamd_task_add_request_header (task, hn_tok, hv_tok);
+                               rspamd_task_add_request_header (task, hn_tok, hv_tok);
 }
 }); /* End of kh_foreach_value */
 
index 7a70ccef0cc10ad596608d826c1f898493481945..e55e548518d431fa0e21a5b56dc2f3a8abb8f65f 100644 (file)
@@ -78,6 +78,7 @@ extern "C" {
 #define HOSTNAME_HEADER "Hostname"
 #define DELIVER_TO_HEADER "Deliver-To"
 #define NO_LOG_HEADER "Log"
+#define LOG_TAG_HEADER "Log-Tag"
 #define MLEN_HEADER "Message-Length"
 #define USER_AGENT_HEADER "User-Agent"
 #define MTA_TAG_HEADER "MTA-Tag"