diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-10 14:17:13 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-10 14:17:13 +0100 |
commit | 2672f82d536eeed406c6c9882d972ac24e458cf3 (patch) | |
tree | 58fb436176632fe616d04e37116a7dc16002fb77 /src/libutil/http.h | |
parent | bad0ee381608c99a22c7b0e3146d6372c22736f9 (diff) | |
download | rspamd-2672f82d536eeed406c6c9882d972ac24e458cf3.tar.gz rspamd-2672f82d536eeed406c6c9882d972ac24e458cf3.zip |
[Rework] Rework HTTP code
- Restructure body storage
- Make abstract API to manage body of HTTP messages
- Implement messages with body in shared memory
- Avoid copying when serving files
- Allow to share content between messages
Diffstat (limited to 'src/libutil/http.h')
-rw-r--r-- | src/libutil/http.h | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/src/libutil/http.h b/src/libutil/http.h index d9fb73b82..1d4e0f886 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -47,7 +47,15 @@ struct rspamd_http_header { /** * Legacy spamc protocol */ -#define RSPAMD_HTTP_FLAG_SPAMC 1 << 1 +#define RSPAMD_HTTP_FLAG_SPAMC (1 << 0) +/** + * Store body of the message in a shared memory segment + */ +#define RSPAMD_HTTP_FLAG_SHMEM (1 << 2) +/** + * Store body of the message in an immutable shared memory segment + */ +#define RSPAMD_HTTP_FLAG_SHMEM_IMMUTABLE (1 << 3) /** * HTTP message structure, used for requests and replies @@ -57,8 +65,25 @@ struct rspamd_http_message { rspamd_fstring_t *host; rspamd_fstring_t *status; struct rspamd_http_header *headers; - rspamd_fstring_t *body; - rspamd_ftok_t body_buf; + + struct _rspamd_body_buf_s { + /* Data start */ + const gchar *begin; + /* Data len */ + gsize len; + /* Data buffer (used to write data inside) */ + gchar *str; + + /* Internal storage */ + union _rspamd_storage_u { + rspamd_fstring_t *normal; + struct { + gchar *shm_name; + gint shm_fd; + } shared; + } c; + } body_buf; + struct rspamd_cryptobox_pubkey *peer_key; time_t date; time_t last_modified; @@ -277,6 +302,44 @@ struct rspamd_http_message * rspamd_http_new_message (enum http_parser_type type struct rspamd_http_message* rspamd_http_message_from_url (const gchar *url); /** + * Returns body for a message + * @param msg + * @param blen pointer where to save body length + * @return pointer to body start + */ +const gchar *rspamd_http_message_get_body (struct rspamd_http_message *msg, + gsize *blen); + +/** + * Set message's body from the string + * @param msg + * @param data + * @param len + * @return TRUE if a message's body has been set + */ +gboolean rspamd_http_message_set_body (struct rspamd_http_message *msg, + const gchar *data, gsize len); + +/** + * Maps fd as message's body + * @param msg + * @param fd + * @return TRUE if a message's body has been set + */ +gboolean rspamd_http_message_set_body_from_fd (struct rspamd_http_message *msg, + gint fd); + +/** + * Appends data to message's body + * @param msg + * @param data + * @param len + * @return TRUE if a message's body has been set + */ +gboolean rspamd_http_message_append_body (struct rspamd_http_message *msg, + const gchar *data, gsize len); + +/** * Append a header to reply * @param rep * @param name |