Browse Source

[Feature] Add method to copy message from http connection

tags/1.3.0
Vsevolod Stakhov 8 years ago
parent
commit
d81034d284
2 changed files with 60 additions and 0 deletions
  1. 52
    0
      src/libutil/http.c
  2. 8
    0
      src/libutil/http.h

+ 52
- 0
src/libutil/http.c View 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)
{

+ 8
- 0
src/libutil/http.h View 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

Loading…
Cancel
Save