aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/mime_headers.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-13 11:24:04 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-13 11:24:04 +0100
commitf8b94440fdc5cdde583832ab1daabd7ef84f3831 (patch)
tree979b66e6a7b61e5dddb7d94c6d84c66203309948 /src/libmime/mime_headers.c
parentf1e9625920e4e9add168e30c0441a4312b23c890 (diff)
downloadrspamd-f8b94440fdc5cdde583832ab1daabd7ef84f3831.tar.gz
rspamd-f8b94440fdc5cdde583832ab1daabd7ef84f3831.zip
[Rework] Use opaque structure to store a table of mime headers
Diffstat (limited to 'src/libmime/mime_headers.c')
-rw-r--r--src/libmime/mime_headers.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index 7c6c02709..085dd3313 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -23,8 +23,14 @@
#include "libutil/util.h"
#include <unicode/utf8.h>
-__KHASH_IMPL (rspamd_mime_headers_htb, static inline, gchar *,
- struct rspamd_mime_header *, 1, rspamd_strcase_hash, rspamd_strcase_equal);
+KHASH_INIT (rspamd_mime_headers_htb, gchar *,
+ struct rspamd_mime_header *, 1,
+ rspamd_strcase_hash, rspamd_strcase_equal);
+
+struct rspamd_mime_headers_table {
+ khash_t(rspamd_mime_headers_htb) htb;
+ ref_entry_t ref;
+};
static void
rspamd_mime_header_check_special (struct rspamd_task *task,
@@ -177,7 +183,7 @@ rspamd_mime_header_add (struct rspamd_task *task,
/* Convert raw headers to a list of struct raw_header * */
void
rspamd_mime_headers_process (struct rspamd_task *task,
- khash_t(rspamd_mime_headers_htb) *target,
+ struct rspamd_mime_headers_table *target,
struct rspamd_mime_header **order_ptr,
const gchar *in, gsize len,
gboolean check_newlines)
@@ -392,7 +398,7 @@ rspamd_mime_headers_process (struct rspamd_task *task,
/* We also validate utf8 and replace all non-valid utf8 chars */
rspamd_mime_charset_utf_enforce (nh->decoded, strlen (nh->decoded));
nh->order = norder ++;
- rspamd_mime_header_add (task, target, order_ptr, nh, check_newlines);
+ rspamd_mime_header_add (task, &target->htb, order_ptr, nh, check_newlines);
nh = NULL;
state = 0;
break;
@@ -402,7 +408,7 @@ rspamd_mime_headers_process (struct rspamd_task *task,
nh->decoded = "";
nh->raw_len = p - nh->raw_value;
nh->order = norder ++;
- rspamd_mime_header_add (task, target, order_ptr, nh, check_newlines);
+ rspamd_mime_header_add (task, &target->htb, order_ptr, nh, check_newlines);
nh = NULL;
state = 0;
break;
@@ -1599,10 +1605,11 @@ rspamd_smtp_received_parse (struct rspamd_task *task,
}
struct rspamd_mime_header *
-rspamd_message_get_header_from_hash (khash_t(rspamd_mime_headers_htb) *htb,
+rspamd_message_get_header_from_hash (struct rspamd_mime_headers_table *headers,
const gchar *field)
{
khiter_t k;
+ khash_t(rspamd_mime_headers_htb) *htb = &headers->htb;
if (htb) {
k = kh_get (rspamd_mime_headers_htb, htb, (gchar *) field);
@@ -1621,18 +1628,43 @@ struct rspamd_mime_header *
rspamd_message_get_header_array (struct rspamd_task *task,
const gchar *field)
{
- return rspamd_message_get_header_from_hash (MESSAGE_FIELD_CHECK (task, raw_headers),
+ return rspamd_message_get_header_from_hash (
+ MESSAGE_FIELD_CHECK (task, raw_headers),
field);
}
+static void
+rspamd_message_headers_dtor (struct rspamd_mime_headers_table *hdrs)
+{
+ if (hdrs) {
+ kfree (hdrs->htb.keys);
+ kfree (hdrs->htb.vals);
+ kfree (hdrs->htb.flags);
+ g_free (hdrs);
+ }
+}
+
+struct rspamd_mime_headers_table *
+rspamd_message_headers_ref (struct rspamd_mime_headers_table *hdrs)
+{
+ REF_RETAIN (hdrs);
+
+ return hdrs;
+}
+
void
-rspamd_message_headers_destroy (khash_t(rspamd_mime_headers_htb) *htb)
+rspamd_message_headers_unref (struct rspamd_mime_headers_table *hdrs)
{
- kh_destroy (rspamd_mime_headers_htb, htb);
+ REF_RELEASE (hdrs);
}
-khash_t(rspamd_mime_headers_htb) *
+struct rspamd_mime_headers_table *
rspamd_message_headers_new (void)
{
- return kh_init (rspamd_mime_headers_htb);
+ struct rspamd_mime_headers_table *nhdrs;
+
+ nhdrs = g_malloc0 (sizeof (*nhdrs));
+ REF_INIT_RETAIN (nhdrs, rspamd_message_headers_dtor);
+
+ return nhdrs;
} \ No newline at end of file