summaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-05-06 13:41:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-05-06 13:41:08 +0100
commit654584a9b9510ec44cab149e6e2cd41108776886 (patch)
treecee85150ad82707254a810d4aebb4965981ff5da /src/libutil
parentf23b70f4d748e25e296c014fbbd2f6b062d451b9 (diff)
downloadrspamd-654584a9b9510ec44cab149e6e2cd41108776886.tar.gz
rspamd-654584a9b9510ec44cab149e6e2cd41108776886.zip
[Minor] Convert milter session to HTTP request
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/http.c50
-rw-r--r--src/libutil/http.h11
2 files changed, 57 insertions, 4 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c
index 24c5e730c..8331b2406 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -2789,9 +2789,10 @@ rspamd_http_message_set_peer_key (struct rspamd_http_message *msg,
}
void
-rspamd_http_message_add_header (struct rspamd_http_message *msg,
+rspamd_http_message_add_header_len (struct rspamd_http_message *msg,
const gchar *name,
- const gchar *value)
+ const gchar *value,
+ gsize len)
{
struct rspamd_http_header *hdr, *found = NULL;
guint nlen, vlen;
@@ -2799,7 +2800,7 @@ rspamd_http_message_add_header (struct rspamd_http_message *msg,
if (msg != NULL && name != NULL && value != NULL) {
hdr = g_slice_alloc (sizeof (struct rspamd_http_header));
nlen = strlen (name);
- vlen = strlen (value);
+ vlen = len;
hdr->combined = rspamd_fstring_sized_new (nlen + vlen + 4);
rspamd_printf_fstring (&hdr->combined, "%s: %s\r\n", name, value);
hdr->value = g_slice_alloc (sizeof (*hdr->value));
@@ -2821,6 +2822,49 @@ rspamd_http_message_add_header (struct rspamd_http_message *msg,
}
}
+void
+rspamd_http_message_add_header (struct rspamd_http_message *msg,
+ const gchar *name,
+ const gchar *value)
+{
+ if (value) {
+ rspamd_http_message_add_header_len (msg, name, value, strlen (value));
+ }
+}
+
+void
+rspamd_http_message_add_header_fstr (struct rspamd_http_message *msg,
+ const gchar *name,
+ rspamd_fstring_t *value)
+{
+ struct rspamd_http_header *hdr, *found = NULL;
+ guint nlen, vlen;
+
+ if (msg != NULL && name != NULL && value != NULL) {
+ hdr = g_slice_alloc (sizeof (struct rspamd_http_header));
+ nlen = strlen (name);
+ vlen = value->len;
+ hdr->combined = rspamd_fstring_sized_new (nlen + vlen + 4);
+ rspamd_printf_fstring (&hdr->combined, "%s: %V\r\n", name, value);
+ hdr->value = g_slice_alloc (sizeof (*hdr->value));
+ hdr->name = g_slice_alloc (sizeof (*hdr->name));
+ hdr->name->begin = hdr->combined->str;
+ hdr->name->len = nlen;
+ hdr->value->begin = hdr->combined->str + nlen + 2;
+ hdr->value->len = vlen;
+
+ HASH_FIND (hh, msg->headers, hdr->name->begin,
+ hdr->name->len, found);
+
+ if (found == NULL) {
+ HASH_ADD_KEYPTR (hh, msg->headers, hdr->name->begin,
+ hdr->name->len, hdr);
+ }
+
+ DL_APPEND (found, hdr);
+ }
+}
+
const rspamd_ftok_t *
rspamd_http_message_find_header (struct rspamd_http_message *msg,
const gchar *name)
diff --git a/src/libutil/http.h b/src/libutil/http.h
index 23d2fa3fa..8da1bf5e0 100644
--- a/src/libutil/http.h
+++ b/src/libutil/http.h
@@ -378,7 +378,7 @@ gboolean rspamd_http_message_append_body (struct rspamd_http_message *msg,
const gchar *data, gsize len);
/**
- * Append a header to reply
+ * Append a header to http message
* @param rep
* @param name
* @param value
@@ -387,6 +387,15 @@ void rspamd_http_message_add_header (struct rspamd_http_message *msg,
const gchar *name,
const gchar *value);
+void rspamd_http_message_add_header_len (struct rspamd_http_message *msg,
+ const gchar *name,
+ const gchar *value,
+ gsize len);
+
+void rspamd_http_message_add_header_fstr (struct rspamd_http_message *msg,
+ const gchar *name,
+ rspamd_fstring_t *value);
+
/**
* Search for a specified header in message
* @param msg message