]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add method to copy message from http connection
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 May 2016 15:50:52 +0000 (16:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 May 2016 15:50:52 +0000 (16:50 +0100)
src/libutil/http.c
src/libutil/http.h

index 30e02d7e056b53cd5bee36891b0040e47e19d056..d15c7d99baa9f55c5d34b694451e691f3e1b5c9b 100644 (file)
@@ -1177,6 +1177,58 @@ rspamd_http_connection_steal_msg (struct rspamd_http_connection *conn)
        return msg;
 }
 
+struct rspamd_http_message *
+rspamd_http_connection_copy_msg (struct rspamd_http_connection *conn)
+{
+       struct rspamd_http_connection_private *priv;
+       struct rspamd_http_message *new_msg, *msg;
+       struct rspamd_http_header *hdr, *nhdr;
+
+       priv = conn->priv;
+       msg = priv->msg;
+
+       new_msg = rspamd_http_new_message (msg->type);
+
+       if (msg->body) {
+               new_msg->body = rspamd_fstring_new_init (msg->body->str,
+                               msg->body->len);
+       }
+
+       if (msg->url) {
+               new_msg->url = rspamd_fstring_new_init (msg->url->str,
+                               msg->url->len);
+       }
+
+       if (msg->host) {
+               new_msg->host = rspamd_fstring_new_init (msg->host->str,
+                               msg->host->len);
+       }
+
+       new_msg->method = msg->method;
+       new_msg->port = msg->port;
+       new_msg->date = msg->date;
+       new_msg->flags = msg->flags;
+       new_msg->last_modified = msg->last_modified;
+
+       LL_FOREACH (msg->headers, hdr) {
+               nhdr = g_slice_alloc (sizeof (struct rspamd_http_header));
+               nhdr->name = g_slice_alloc (sizeof (*nhdr->name));
+               nhdr->value = g_slice_alloc (sizeof (*nhdr->value));
+               nhdr->combined = rspamd_fstring_new_init (hdr->combined->str,
+                               hdr->combined->len);
+               nhdr->name->begin = nhdr->combined->str +
+                               (hdr->name->begin - hdr->combined->str);
+               nhdr->name->len = hdr->name->len;
+               nhdr->value->begin = nhdr->combined->str +
+                               (hdr->value->begin - hdr->combined->str);
+               nhdr->value->len = hdr->value->len;
+
+               DL_APPEND (new_msg->headers, nhdr);
+       }
+
+       return new_msg;
+}
+
 void
 rspamd_http_connection_free (struct rspamd_http_connection *conn)
 {
index 36158586dc7a89091ca13385deb1359333e9038b..9793e577bbdbfb4adde979de8b984312b9303816 100644 (file)
@@ -246,6 +246,14 @@ void rspamd_http_connection_reset (struct rspamd_http_connection *conn);
 struct rspamd_http_message * rspamd_http_connection_steal_msg (
                struct rspamd_http_connection *conn);
 
+/**
+ * Copy the current message from a connection to deal with separately
+ * @param conn
+ * @return
+ */
+struct rspamd_http_message * rspamd_http_connection_copy_msg (
+               struct rspamd_http_connection *conn);
+
 /**
  * Create new HTTP message
  * @param type request or response