diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-08-20 14:11:58 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-08-20 14:11:58 +0100 |
commit | 5ac509220ed1874a7dd2fe244d1b8e6f39febf06 (patch) | |
tree | f0e7dc53c767bcfc507f9038b4a77b30aad7c9bb /src | |
parent | 8114d4956eb1f862f9eead17ade6838edba1a2bf (diff) | |
download | rspamd-5ac509220ed1874a7dd2fe244d1b8e6f39febf06.tar.gz rspamd-5ac509220ed1874a7dd2fe244d1b8e6f39febf06.zip |
Add HTTP_CLIENT_SIMPLE option.
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/http.c | 36 | ||||
-rw-r--r-- | src/libutil/http.h | 7 |
2 files changed, 33 insertions, 10 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c index 3cfc433e1..1a36e6142 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -28,6 +28,8 @@ #include "printf.h" #include "logger.h" +#include <limits.h> + struct rspamd_http_connection_private { GString *buf; gboolean new_header; @@ -550,6 +552,18 @@ rspamd_http_on_message_complete (http_parser * parser) } static void +rspamd_http_simple_client_helper (struct rspamd_http_connection *conn) +{ + struct event_base *base; + + base = event_get_base (&conn->priv->ev); + rspamd_http_connection_reset (conn); + /* Plan read message */ + rspamd_http_connection_read_message (conn, conn->ud, conn->fd, + conn->priv->ptv, base); +} + +static void rspamd_http_write_helper (struct rspamd_http_connection *conn) { struct rspamd_http_connection_private *priv; @@ -562,10 +576,7 @@ rspamd_http_write_helper (struct rspamd_http_connection *conn) priv = conn->priv; if (priv->wr_pos == priv->wr_total) { - rspamd_http_connection_ref (conn); - conn->finish_handler (conn, priv->msg); - rspamd_http_connection_unref (conn); - return; + goto call_finish_handler; } start = &priv->out[0]; @@ -603,14 +614,25 @@ rspamd_http_write_helper (struct rspamd_http_connection *conn) } if (priv->wr_pos >= priv->wr_total) { + goto call_finish_handler; + } + else { + /* Want to write more */ + event_add (&priv->ev, priv->ptv); + } + + return; + +call_finish_handler: + if ((conn->opts & RSPAMD_HTTP_CLIENT_SIMPLE) == 0) { rspamd_http_connection_ref (conn); conn->finish_handler (conn, priv->msg); conn->finished = TRUE; rspamd_http_connection_unref (conn); } else { - /* Want to write more */ - event_add (&priv->ev, priv->ptv); + /* Plan read message */ + rspamd_http_simple_client_helper (conn); } } @@ -685,7 +707,7 @@ struct rspamd_http_connection * rspamd_http_connection_new (rspamd_http_body_handler_t body_handler, rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, - enum rspamd_http_options opts, + unsigned opts, enum rspamd_http_connection_type type) { struct rspamd_http_connection *new; diff --git a/src/libutil/http.h b/src/libutil/http.h index c6a142e3b..eefadee18 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -67,7 +67,8 @@ struct rspamd_http_message { * Options for HTTP connection */ enum rspamd_http_options { - RSPAMD_HTTP_BODY_PARTIAL = 0x1 //!< RSPAMD_HTTP_BODY_PARTIAL + RSPAMD_HTTP_BODY_PARTIAL = 0x1, /**< Call body handler on all body data portions */ + RSPAMD_HTTP_CLIENT_SIMPLE = 0x2 /**< Read HTTP client reply automatically */ }; struct rspamd_http_connection_private; @@ -104,7 +105,7 @@ struct rspamd_http_connection { rspamd_http_error_handler_t error_handler; rspamd_http_finish_handler_t finish_handler; gpointer ud; - enum rspamd_http_options opts; + unsigned opts; enum rspamd_http_connection_type type; gboolean finished; gint fd; @@ -140,7 +141,7 @@ struct rspamd_http_connection * rspamd_http_connection_new ( rspamd_http_body_handler_t body_handler, rspamd_http_error_handler_t error_handler, rspamd_http_finish_handler_t finish_handler, - enum rspamd_http_options opts, + unsigned opts, enum rspamd_http_connection_type type); /** |