aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-10 15:50:05 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-10 15:50:05 +0100
commitf85965a72957a9cf9d1c1a5643fc0b15fb274f9a (patch)
tree6cdc7bdaac61f0343584aa76b75f840d17ab15bc
parent328703c09e3a22f7df01010aca1a21b167735504 (diff)
downloadrspamd-f85965a72957a9cf9d1c1a5643fc0b15fb274f9a.tar.gz
rspamd-f85965a72957a9cf9d1c1a5643fc0b15fb274f9a.zip
[Feature] Add more methods to init http message body
-rw-r--r--src/libutil/http.c34
-rw-r--r--src/libutil/http.h18
2 files changed, 52 insertions, 0 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c
index 718ef818d..5417110d9 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -2039,6 +2039,40 @@ rspamd_http_message_set_body_from_fd (struct rspamd_http_message *msg,
}
gboolean
+rspamd_http_message_set_body_from_fstring_steal (struct rspamd_http_message *msg,
+ rspamd_fstring_t *fstr)
+{
+ union _rspamd_storage_u *storage;
+
+ storage = &msg->body_buf.c;
+ msg->flags &= ~(RSPAMD_HTTP_FLAG_SHMEM|RSPAMD_HTTP_FLAG_SHMEM_IMMUTABLE);
+
+ storage->normal = fstr;
+ msg->body_buf.str = fstr->str;
+ msg->body_buf.begin = msg->body_buf.str;
+ msg->body_buf.len = fstr->len;
+
+ return TRUE;
+}
+
+gboolean
+rspamd_http_message_set_body_from_fstring_copy (struct rspamd_http_message *msg,
+ const rspamd_fstring_t *fstr)
+{
+ union _rspamd_storage_u *storage;
+
+ storage = &msg->body_buf.c;
+ msg->flags &= ~(RSPAMD_HTTP_FLAG_SHMEM|RSPAMD_HTTP_FLAG_SHMEM_IMMUTABLE);
+
+ storage->normal = rspamd_fstring_new_init (fstr->str, fstr->len);
+ msg->body_buf.str = storage->normal->str;
+ msg->body_buf.begin = msg->body_buf.str;
+ msg->body_buf.len = storage->normal->len;
+
+ return TRUE;
+}
+
+gboolean
rspamd_http_message_append_body (struct rspamd_http_message *msg,
const gchar *data, gsize len)
{
diff --git a/src/libutil/http.h b/src/libutil/http.h
index bb5f8d8a7..ab71f619b 100644
--- a/src/libutil/http.h
+++ b/src/libutil/http.h
@@ -284,6 +284,24 @@ gboolean rspamd_http_message_set_body_from_fd (struct rspamd_http_message *msg,
gint fd);
/**
+ * Uses rspamd_fstring_t as message's body, string is consumed by this operation
+ * @param msg
+ * @param fstr
+ * @return TRUE if a message's body has been set
+ */
+gboolean rspamd_http_message_set_body_from_fstring_steal (struct rspamd_http_message *msg,
+ rspamd_fstring_t *fstr);
+
+/**
+ * Uses rspamd_fstring_t as message's body, string is copied by this operation
+ * @param msg
+ * @param fstr
+ * @return TRUE if a message's body has been set
+ */
+gboolean rspamd_http_message_set_body_from_fstring_copy (struct rspamd_http_message *msg,
+ const rspamd_fstring_t *fstr);
+
+/**
* Appends data to message's body
* @param msg
* @param data