From: Vsevolod Stakhov Date: Thu, 4 Aug 2016 15:00:14 +0000 (+0100) Subject: [Fix] Restore multiple values in headers processing X-Git-Tag: 1.3.2~47 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=de16089822abd364dbe73b1f7ebd45dd185934b4;p=rspamd.git [Fix] Restore multiple values in headers processing --- diff --git a/src/libutil/http.c b/src/libutil/http.c index 931ed5ed8..7e5da1b12 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -521,6 +521,8 @@ static void rspamd_http_finish_header (struct rspamd_http_connection *conn, struct rspamd_http_connection_private *priv) { + struct rspamd_http_header *hdr; + priv->header->combined = rspamd_fstring_append (priv->header->combined, "\r\n", 2); priv->header->value->len = priv->header->combined->len - @@ -528,8 +530,18 @@ rspamd_http_finish_header (struct rspamd_http_connection *conn, priv->header->value->begin = priv->header->combined->str + priv->header->name->len + 2; priv->header->name->begin = priv->header->combined->str; - HASH_ADD_KEYPTR (hh, priv->msg->headers, priv->header->name->begin, - priv->header->name->len, priv->header); + + HASH_FIND (hh, priv->msg->headers, priv->header->name->begin, + priv->header->name->len, hdr); + + if (hdr) { + DL_APPEND (priv->msg->headers, priv->header); + } + else { + HASH_ADD_KEYPTR (hh, priv->msg->headers, priv->header->name->begin, + priv->header->name->len, priv->header); + } + rspamd_http_check_special_header (conn, priv); } @@ -2632,6 +2644,33 @@ rspamd_http_message_find_header (struct rspamd_http_message *msg, return res; } +GPtrArray* +rspamd_http_message_find_header_multiple ( + struct rspamd_http_message *msg, + const gchar *name) +{ + GPtrArray *res = NULL; + struct rspamd_http_header *hdr, *cur; + + guint slen = strlen (name); + + if (msg != NULL) { + HASH_FIND (hh, msg->headers, name, slen, hdr); + + if (hdr) { + res = g_ptr_array_sized_new (4); + + LL_FOREACH (hdr, cur) { + g_ptr_array_add (res, cur->value); + } + } + } + + + return res; +} + + gboolean rspamd_http_message_remove_header (struct rspamd_http_message *msg, const gchar *name) diff --git a/src/libutil/http.h b/src/libutil/http.h index 9dc6302c9..399141e60 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -375,6 +375,16 @@ const rspamd_ftok_t * rspamd_http_message_find_header ( struct rspamd_http_message *msg, const gchar *name); +/** + * Search for a header that has multiple values + * @param msg + * @param name + * @return list of rspamd_ftok_t * with values + */ +GPtrArray* rspamd_http_message_find_header_multiple ( + struct rspamd_http_message *msg, + const gchar *name); + /** * Remove specific header from a message * @param msg diff --git a/src/libutil/http_private.h b/src/libutil/http_private.h index 49575c03c..1433e37e4 100644 --- a/src/libutil/http_private.h +++ b/src/libutil/http_private.h @@ -30,6 +30,7 @@ struct rspamd_http_header { rspamd_ftok_t *value; rspamd_fstring_t *combined; UT_hash_handle hh; + struct rspamd_http_header *prev, *next; }; /**