From f85965a72957a9cf9d1c1a5643fc0b15fb274f9a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 10 Jun 2016 15:50:05 +0100 Subject: [PATCH] [Feature] Add more methods to init http message body --- src/libutil/http.c | 34 ++++++++++++++++++++++++++++++++++ src/libutil/http.h | 18 ++++++++++++++++++ 2 files changed, 52 insertions(+) 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 @@ -2038,6 +2038,40 @@ rspamd_http_message_set_body_from_fd (struct rspamd_http_message *msg, return TRUE; } +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 @@ -283,6 +283,24 @@ gboolean rspamd_http_message_set_body (struct rspamd_http_message *msg, 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 -- 2.39.5