]> source.dussan.org Git - rspamd.git/commitdiff
Save all HTTP headers as request headers.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 May 2015 15:30:56 +0000 (16:30 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 May 2015 15:30:56 +0000 (16:30 +0100)
src/libserver/protocol.c

index f5380081e779dd9fdbcf7759f98b87e88117e043..a0c824bc97e7a839bef52424bdfcfaf9e3ae7a72 100644 (file)
@@ -253,63 +253,67 @@ gboolean
 rspamd_protocol_handle_headers (struct rspamd_task *task,
        struct rspamd_http_message *msg)
 {
-       gchar *headern, *tmp;
+       gchar *headern;
+       GString *hn, *hv;
        gboolean res = TRUE, validh, fl, has_ip = FALSE;
        gsize hlen;
        struct rspamd_http_header *h;
 
        LL_FOREACH (msg->headers, h)
        {
-               headern = h->name->str;
-               hlen = h->name->len;
+               hn = g_string_new_len (h->name->str, h->name->len);
+               hv = g_string_new_len (h->value->str, h->value->len);
+               headern = hn->str;
+               hlen = hn->len;
                validh = TRUE;
 
+               g_hash_table_insert (task->request_headers, hn, hv);
+
                switch (headern[0]) {
                case 'd':
                case 'D':
                        if (g_ascii_strncasecmp (headern, DELIVER_TO_HEADER, hlen) == 0) {
-                               task->deliver_to = rspamd_protocol_escape_braces (task, h->value);
+                               task->deliver_to = rspamd_protocol_escape_braces (task, hv);
                                debug_task ("read deliver-to header, value: %s",
                                        task->deliver_to);
                        }
                        else {
-                               debug_task ("wrong header: %v", h->name);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'h':
                case 'H':
                        if (g_ascii_strncasecmp (headern, HELO_HEADER, hlen) == 0) {
-                               task->helo = rspamd_protocol_header_dup (task, h->value);
+                               task->helo = hv->str;
                                debug_task ("read helo header, value: %s", task->helo);
                        }
                        else if (g_ascii_strncasecmp (headern, HOSTNAME_HEADER, hlen) == 0) {
-                               task->hostname = rspamd_protocol_header_dup (task, h->value);
+                               task->hostname = hv->str;
                                debug_task ("read hostname header, value: %s", task->hostname);
                        }
                        else {
-                               debug_task ("wrong header: %v", h->value);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'f':
                case 'F':
                        if (g_ascii_strncasecmp (headern, FROM_HEADER, hlen) == 0) {
-                               if (!rspamd_task_add_sender (task,
-                                               rspamd_protocol_header_dup (task, h->value))) {
-                                       msg_err ("bad from header: '%v'", h->value);
+                               if (!rspamd_task_add_sender (task, hv->str)) {
+                                       msg_err ("bad from header: '%v'", hv);
                                        validh = FALSE;
                                }
                        }
                        else {
-                               debug_task ("wrong header: %v", h->value);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'j':
                case 'J':
                        if (g_ascii_strncasecmp (headern, JSON_HEADER, hlen) == 0) {
-                               fl = rspamd_config_parse_flag (h->value->str, h->value->len);
+                               fl = rspamd_config_parse_flag (hv->str, hv->len);
                                if (fl) {
                                        task->flags |= RSPAMD_TASK_FLAG_JSON;
                                }
@@ -318,58 +322,55 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                }
                        }
                        else {
-                               debug_task ("wrong header: %v", h->value);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'q':
                case 'Q':
                        if (g_ascii_strncasecmp (headern, QUEUE_ID_HEADER, hlen) == 0) {
-                               task->queue_id = rspamd_protocol_header_dup (task, h->value);
+                               task->queue_id = hv->str;
                                debug_task ("read queue_id header, value: %s", task->queue_id);
                        }
                        else {
-                               debug_task ("wrong header: %v", h->name);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'r':
                case 'R':
                        if (g_ascii_strncasecmp (headern, RCPT_HEADER, hlen) == 0) {
-                               if (!rspamd_task_add_recipient (task,
-                                               rspamd_protocol_header_dup (task, h->value))) {
+                               if (!rspamd_task_add_recipient (task, hv->str)) {
                                        msg_err ("bad from header: '%v'", h->value);
                                        validh = FALSE;
                                }
-                               debug_task ("read rcpt header, value: %v", h->value);
+                               debug_task ("read rcpt header, value: %v", hv);
                        }
                        else {
-                               debug_task ("wrong header: %v", h->name);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'i':
                case 'I':
                        if (g_ascii_strncasecmp (headern, IP_ADDR_HEADER, hlen) == 0) {
-                               tmp = rspamd_protocol_header_dup (task, h->value);
-
-                               if (!rspamd_parse_inet_address (&task->from_addr, tmp)) {
-                                       msg_err ("bad ip header: '%s'", tmp);
+                               if (!rspamd_parse_inet_address (&task->from_addr, hv->str)) {
+                                       msg_err ("bad ip header: '%v'", hv);
                                        return FALSE;
                                }
-                               debug_task ("read IP header, value: %s", tmp);
+                               debug_task ("read IP header, value: %v", hv);
                                has_ip = TRUE;
                        }
                        else {
-                               debug_task ("wrong header: %v", h->name);
+                               debug_task ("wrong header: %v", hn);
                                validh = FALSE;
                        }
                        break;
                case 'p':
                case 'P':
                        if (g_ascii_strncasecmp (headern, PASS_HEADER, hlen) == 0) {
-                               if (h->value->len == sizeof ("all") - 1 &&
-                                       g_ascii_strncasecmp (h->value->str, "all", h->value->len) == 0) {
+                               if (hv->len == sizeof ("all") - 1 &&
+                                       g_ascii_strncasecmp (hv->str, "all", hv->len) == 0) {
                                        task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
                                        debug_task ("pass all filters");
                                }
@@ -381,7 +382,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 's':
                case 'S':
                        if (g_ascii_strncasecmp (headern, SUBJECT_HEADER, hlen) == 0) {
-                               task->subject = rspamd_protocol_header_dup (task, h->value);
+                               task->subject = hv->str;
                        }
                        else {
                                validh = FALSE;
@@ -390,12 +391,12 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'u':
                case 'U':
                        if (g_ascii_strncasecmp (headern, USER_HEADER, hlen) == 0) {
-                               task->user = rspamd_protocol_header_dup (task, h->value);
+                               task->user = hv->str;
                        }
                        if (g_ascii_strncasecmp (headern, URLS_HEADER, hlen) == 0) {
                                if (h->value->len == sizeof ("extended") - 1 &&
-                                               g_ascii_strncasecmp (h->value->str, "extended",
-                                                               h->value->len) == 0) {
+                                               g_ascii_strncasecmp (hv->str, "extended",
+                                                               hv->len) == 0) {
                                        task->flags |= RSPAMD_TASK_FLAG_EXT_URLS;
                                        debug_task ("extended urls information");
                                }
@@ -407,7 +408,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'l':
                case 'L':
                        if (g_ascii_strncasecmp (headern, NO_LOG_HEADER, hlen) == 0) {
-                               if (g_ascii_strncasecmp (h->value->str, "no", h->value->len) == 0) {
+                               if (g_ascii_strncasecmp (hv->str, "no", hv->len) == 0) {
                                        task->flags |= RSPAMD_TASK_FLAG_NO_LOG;
                                }
                        }
@@ -418,10 +419,10 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'm':
                case 'M':
                        if (g_ascii_strncasecmp (headern, MLEN_HEADER, hlen) == 0) {
-                               task->message_len = strtoul (h->value->str, NULL, 10);
+                               task->message_len = strtoul (hv->str, NULL, 10);
 
                                if (task->message_len == 0) {
-                                       msg_err ("Invalid message length header: %v", h->value);
+                                       msg_err ("Invalid message length header: %v", hv);
                                        validh = FALSE;
                                }
                                else {
@@ -433,7 +434,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                        }
                        break;
                default:
-                       debug_task ("unknown header: %v", h->name);
+                       debug_task ("unknown header: %v", hn);
                        validh = FALSE;
                        break;
                }