]> source.dussan.org Git - rspamd.git/commitdiff
Preserve keys inside HTTP session.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 30 Jan 2015 18:25:37 +0000 (18:25 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 30 Jan 2015 18:25:37 +0000 (18:25 +0000)
src/libutil/http.c
src/libutil/http.h

index dc4774c2fc0e6835192364171fac59118e327906..914ee6d6a2859af3d04d549b455de812df673eee 100644 (file)
@@ -48,6 +48,7 @@ struct rspamd_http_connection_private {
        } *buf;
        gboolean new_header;
        gboolean encrypted;
+       gpointer peer_key;
        struct rspamd_http_keypair *local_key;
        struct rspamd_http_header *header;
        struct http_parser parser;
@@ -557,6 +558,7 @@ rspamd_http_on_headers_complete (http_parser * parser)
                priv->msg->body = g_string_sized_new (BUFSIZ);
        }
 
+       priv->msg->body_buf.str = priv->msg->body->str;
        priv->msg->method = parser->method;
        priv->msg->code = parser->status_code;
 
@@ -618,6 +620,9 @@ rspamd_http_on_message_complete (http_parser * parser)
                        m += crypto_box_ZEROBYTES;
                        dec_len -= crypto_box_ZEROBYTES;
 
+                       priv->msg->body->str = m;
+                       priv->msg->body->len = dec_len;
+
                        rspamd_http_connection_ref (conn);
                        ret = conn->body_handler (conn,
                                        priv->msg,
@@ -898,6 +903,9 @@ rspamd_http_connection_reset (struct rspamd_http_connection *conn)
 
        /* Clear request */
        if (msg != NULL) {
+               if (msg->peer_key) {
+                       priv->peer_key = msg->peer_key;
+               }
                rspamd_http_message_free (msg);
                priv->msg = NULL;
        }
@@ -945,6 +953,11 @@ rspamd_http_connection_read_message (struct rspamd_http_connection *conn,
                conn->type == RSPAMD_HTTP_SERVER ? HTTP_REQUEST : HTTP_RESPONSE);
        priv->msg = req;
 
+       if (priv->peer_key) {
+               priv->msg->peer_key = priv->peer_key;
+               priv->encrypted = TRUE;
+       }
+
        if (timeout == NULL) {
                priv->ptv = NULL;
        }
@@ -1191,6 +1204,7 @@ rspamd_http_new_message (enum http_parser_type type)
        new->headers = NULL;
        new->date = 0;
        new->body = NULL;
+       memset (&new->body_buf, 0, sizeof (new->body_buf));
        new->status = NULL;
        new->host = NULL;
        new->port = 80;
@@ -1261,7 +1275,8 @@ rspamd_http_message_free (struct rspamd_http_message *msg)
                g_slice_free1 (sizeof (struct rspamd_http_header), hdr);
        }
        if (msg->body != NULL) {
-               g_string_free (msg->body, TRUE);
+               g_string_free (msg->body, FALSE);
+               g_free (msg->body_buf.str);
        }
        if (msg->url != NULL) {
                g_string_free (msg->url, TRUE);
index c290d803ccf75da6a85150ab2ecf8faacfc53539..59ac5ef2056414580836f0ff3512a6d598122358 100644 (file)
@@ -58,6 +58,7 @@ struct rspamd_http_message {
        GString *status;
        struct rspamd_http_header *headers;
        GString *body;
+       GString body_buf;
        gpointer peer_key;
        enum http_parser_type type;
        time_t date;