]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add more methods to init http message body
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 10 Jun 2016 14:50:05 +0000 (15:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 10 Jun 2016 14:50:05 +0000 (15:50 +0100)
src/libutil/http.c
src/libutil/http.h

index 718ef818d4c5fadf024a36bff64a642319106224..5417110d992569de050335f0d8a6bfc189073906 100644 (file)
@@ -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)
index bb5f8d8a750cb33a35c2c8b120785fd152329817..ab71f619b9937d6e694e0d555467900c06074781 100644 (file)
@@ -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