From d81034d28436deb41b750f7daaefc39e4fe66e6b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 6 May 2016 16:50:52 +0100 Subject: [PATCH] [Feature] Add method to copy message from http connection --- src/libutil/http.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/libutil/http.h | 8 +++++++ 2 files changed, 60 insertions(+) diff --git a/src/libutil/http.c b/src/libutil/http.c index 30e02d7e0..d15c7d99b 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -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) { diff --git a/src/libutil/http.h b/src/libutil/http.h index 36158586d..9793e577b 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -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 -- 2.39.5