From: Vsevolod Stakhov Date: Fri, 10 Jun 2016 14:50:05 +0000 (+0100) Subject: [Feature] Add more methods to init http message body X-Git-Tag: 1.3.0~379^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f85965a72957a9cf9d1c1a5643fc0b15fb274f9a;p=thirdparty%2Frspamd.git [Feature] Add more methods to init http message body --- diff --git a/src/libutil/http.c b/src/libutil/http.c index 718ef818d4..5417110d99 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 bb5f8d8a75..ab71f619b9 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