]> source.dussan.org Git - rspamd.git/commitdiff
Add HTTP_CLIENT_SIMPLE option.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Aug 2014 13:11:58 +0000 (14:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Aug 2014 13:11:58 +0000 (14:11 +0100)
src/libutil/http.c
src/libutil/http.h

index 3cfc433e112729f5b88f7f8545d7ef57880c0b8f..1a36e614216205fdea61d0316f30c9a4ca57efef 100644 (file)
@@ -28,6 +28,8 @@
 #include "printf.h"
 #include "logger.h"
 
+#include <limits.h>
+
 struct rspamd_http_connection_private {
        GString *buf;
        gboolean new_header;
@@ -549,6 +551,18 @@ rspamd_http_on_message_complete (http_parser * parser)
        return ret;
 }
 
+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)
 {
@@ -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;
index c6a142e3bb6d081ec19c357cfaff584c067bdb87..eefadee18f529e08d4ba0743666b63b462f8e767 100644 (file)
@@ -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);
 
 /**