commit 3a1974c: [Rework] Another iteration of HTTP interfaces rework

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Mar 18 16:21:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-03-18 12:00:00 +0000
URL: https://github.com/rspamd/rspamd/commit/3a1974cf17f235b7bbb98de714fe0210ddb2c596

[Rework] Another iteration of HTTP interfaces rework

---
 src/client/rspamdclient.c      |   5 +-
 src/fuzzy_storage.c            |  10 +--
 src/libserver/rspamd_control.c |   5 +-
 src/libutil/http_connection.c  | 119 ++++++++++++++++++++---------
 src/libutil/http_connection.h  |  63 ++++++++++++++--
 src/libutil/http_router.c      |   5 +-
 src/libutil/map.c              | 168 +++++++++++++++++++----------------------
 src/libutil/map_private.h      |   1 -
 src/lua/lua_http.c             |  16 +---
 src/plugins/surbl.c            |  21 ++----
 src/rspamadm/control.c         |  14 +---
 src/rspamd_proxy.c             |  15 ++--
 src/worker.c                   |   5 +-
 13 files changed, 247 insertions(+), 200 deletions(-)

diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c
index a2ff85458..5f831ee64 100644
--- a/src/client/rspamdclient.c
+++ b/src/client/rspamdclient.c
@@ -255,13 +255,12 @@ rspamd_client_init (struct rspamd_http_context *http_ctx,
 	conn->ev_base = ev_base;
 	conn->fd = fd;
 	conn->req_sent = FALSE;
-	conn->http_conn = rspamd_http_connection_new (http_ctx,
-			fd,
+	conn->http_conn = rspamd_http_connection_new_client_socket (http_ctx,
 			rspamd_client_body_handler,
 			rspamd_client_error_handler,
 			rspamd_client_finish_handler,
 			0,
-			RSPAMD_HTTP_CLIENT);
+			fd);
 
 	conn->server_name = g_string_new (name);
 	if (port != 0) {
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 2054633ad..96fb09c2b 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -618,14 +618,13 @@ rspamd_fuzzy_send_update_mirror (struct rspamd_fuzzy_storage_ctx *ctx,
 	msg = rspamd_http_new_message (HTTP_REQUEST);
 	rspamd_printf_fstring (&msg->url, "/update_v1/%s", m->name);
 
-	conn->http_conn = rspamd_http_connection_new (
+	conn->http_conn = rspamd_http_connection_new_client_socket (
 			ctx->http_ctx,
-			conn->sock,
 			NULL,
 			fuzzy_mirror_error_handler,
 			fuzzy_mirror_finish_handler,
 			RSPAMD_HTTP_CLIENT_SIMPLE,
-			RSPAMD_HTTP_CLIENT);
+			conn->sock);
 
 	rspamd_http_connection_set_key (conn->http_conn,
 			ctx->sync_keypair);
@@ -1992,14 +1991,13 @@ accept_fuzzy_mirror_socket (gint fd, short what, void *arg)
 	session->name = rspamd_inet_address_to_string (addr);
 	rspamd_random_hex (session->uid, sizeof (session->uid) - 1);
 	session->uid[sizeof (session->uid) - 1] = '\0';
-	http_conn = rspamd_http_connection_new (
+	http_conn = rspamd_http_connection_new_server (
 			ctx->http_ctx,
 			nfd,
 			NULL,
 			rspamd_fuzzy_mirror_error_handler,
 			rspamd_fuzzy_mirror_finish_handler,
-			0,
-			RSPAMD_HTTP_SERVER);
+			0);
 
 	rspamd_http_connection_set_key (http_conn, ctx->sync_keypair);
 	session->ctx = ctx;
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 149ad4245..12d37cdbc 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -518,13 +518,12 @@ rspamd_control_process_client_socket (struct rspamd_main *rspamd_main,
 	session = g_malloc0 (sizeof (*session));
 
 	session->fd = fd;
-	session->conn = rspamd_http_connection_new (rspamd_main->http_ctx,
+	session->conn = rspamd_http_connection_new_server (rspamd_main->http_ctx,
 			fd,
 			NULL,
 			rspamd_control_error_handler,
 			rspamd_control_finish_handler,
-			0,
-			RSPAMD_HTTP_SERVER);
+			0);
 	session->rspamd_main = rspamd_main;
 	session->addr = addr;
 	rspamd_http_connection_read_message (session->conn, session,
diff --git a/src/libutil/http_connection.c b/src/libutil/http_connection.c
index 42b934d2a..417784789 100644
--- a/src/libutil/http_connection.c
+++ b/src/libutil/http_connection.c
@@ -1077,14 +1077,12 @@ rspamd_http_parser_reset (struct rspamd_http_connection *conn)
 }
 
 struct rspamd_http_connection *
-rspamd_http_connection_new (
-		struct rspamd_http_context *ctx,
-		gint fd,
-		rspamd_http_body_handler_t body_handler,
-		rspamd_http_error_handler_t error_handler,
-		rspamd_http_finish_handler_t finish_handler,
-		unsigned opts,
-		enum rspamd_http_connection_type type)
+rspamd_http_connection_new_server (struct rspamd_http_context *ctx,
+								   gint fd,
+								   rspamd_http_body_handler_t body_handler,
+								   rspamd_http_error_handler_t error_handler,
+								   rspamd_http_finish_handler_t finish_handler,
+								   unsigned opts)
 {
 	struct rspamd_http_connection *conn;
 	struct rspamd_http_connection_private *priv;
@@ -1095,7 +1093,7 @@ rspamd_http_connection_new (
 
 	conn = g_malloc0 (sizeof (struct rspamd_http_connection));
 	conn->opts = opts;
-	conn->type = type;
+	conn->type = RSPAMD_HTTP_SERVER;
 	conn->body_handler = body_handler;
 	conn->error_handler = error_handler;
 	conn->finish_handler = finish_handler;
@@ -1112,14 +1110,49 @@ rspamd_http_connection_new (
 	conn->priv = priv;
 	priv->ctx = ctx;
 
-	if (conn->type == RSPAMD_HTTP_CLIENT) {
-		priv->cache = ctx->client_kp_cache;
-		if (ctx->client_kp) {
-			priv->local_key = rspamd_keypair_ref (ctx->client_kp);
-		}
+	priv->cache = ctx->server_kp_cache;
+
+	rspamd_http_parser_reset (conn);
+	priv->parser.data = conn;
+
+	return conn;
+}
+
+struct rspamd_http_connection *
+rspamd_http_connection_new_client_socket (struct rspamd_http_context *ctx,
+								   rspamd_http_body_handler_t body_handler,
+								   rspamd_http_error_handler_t error_handler,
+								   rspamd_http_finish_handler_t finish_handler,
+								   unsigned opts,
+								   gint fd)
+{
+	struct rspamd_http_connection *conn;
+	struct rspamd_http_connection_private *priv;
+
+	g_assert (error_handler != NULL && finish_handler == NULL);
+
+	conn = g_malloc0 (sizeof (struct rspamd_http_connection));
+	conn->opts = opts;
+	conn->type = RSPAMD_HTTP_CLIENT;
+	conn->body_handler = body_handler;
+	conn->error_handler = error_handler;
+	conn->finish_handler = finish_handler;
+	conn->fd = fd;
+	conn->ref = 1;
+	conn->finished = FALSE;
+
+	/* Init priv */
+	if (ctx == NULL) {
+		ctx = rspamd_http_context_default ();
 	}
-	else {
-		priv->cache = ctx->server_kp_cache;
+
+	priv = g_malloc0 (sizeof (struct rspamd_http_connection_private));
+	conn->priv = priv;
+	priv->ctx = ctx;
+
+	priv->cache = ctx->client_kp_cache;
+	if (ctx->client_kp) {
+		priv->local_key = rspamd_keypair_ref (ctx->client_kp);
 	}
 
 	rspamd_http_parser_reset (conn);
@@ -1128,16 +1161,42 @@ rspamd_http_connection_new (
 	return conn;
 }
 
+struct rspamd_http_connection *
+rspamd_http_connection_new_client (struct rspamd_http_context *ctx,
+								   rspamd_http_body_handler_t body_handler,
+								   rspamd_http_error_handler_t error_handler,
+								   rspamd_http_finish_handler_t finish_handler,
+								   unsigned opts,
+								   rspamd_inet_addr_t *addr)
+{
+	gint fd;
+
+	if (error_handler == NULL || finish_handler == NULL) {
+		return NULL;
+	}
+
+	fd = rspamd_inet_address_connect (addr, SOCK_STREAM, TRUE);
+
+	if (fd == -1) {
+		msg_info ("cannot connect to %s: %s", rspamd_inet_address_to_string (addr),
+				strerror (errno));
+		return NULL;
+	}
+
+	return rspamd_http_connection_new_client_socket (ctx,
+			body_handler, error_handler, finish_handler,
+			opts | RSPAMD_HTTP_OWN_SOCKET, fd);
+}
+
 struct rspamd_http_connection *
 rspamd_http_connection_new_keepalive (struct rspamd_http_context *ctx,
-		rspamd_http_body_handler_t body_handler,
-		rspamd_http_error_handler_t error_handler,
-		rspamd_http_finish_handler_t finish_handler,
-		rspamd_inet_addr_t *addr,
-		const gchar *host)
+									  rspamd_http_body_handler_t body_handler,
+									  rspamd_http_error_handler_t error_handler,
+									  rspamd_http_finish_handler_t finish_handler,
+									  rspamd_inet_addr_t *addr,
+									  const gchar *host)
 {
 	struct rspamd_http_connection *conn;
-	gint fd;
 
 	if (error_handler == NULL || finish_handler == NULL) {
 		return NULL;
@@ -1153,18 +1212,10 @@ rspamd_http_connection_new_keepalive (struct rspamd_http_context *ctx,
 		return conn;
 	}
 
-	fd = rspamd_inet_address_connect (addr, SOCK_STREAM, TRUE);
-
-	if (fd == -1) {
-		msg_info ("cannot connect to %s: %s", rspamd_inet_address_to_string (addr),
-				host);
-		return NULL;
-	}
-
-	conn = rspamd_http_connection_new (ctx, fd, body_handler, error_handler,
-			finish_handler,
+	conn = rspamd_http_connection_new_client (ctx,
+			body_handler, error_handler, finish_handler,
 			RSPAMD_HTTP_CLIENT_SIMPLE|RSPAMD_HTTP_CLIENT_KEEP_ALIVE,
-			RSPAMD_HTTP_CLIENT);
+			addr);
 
 	if (conn) {
 		rspamd_http_context_prepare_keepalive (ctx, conn, addr, host);
@@ -1387,7 +1438,7 @@ rspamd_http_connection_free (struct rspamd_http_connection *conn)
 		g_free (priv);
 	}
 
-	if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
+	if (conn->opts & RSPAMD_HTTP_OWN_SOCKET) {
 		/* Fd is owned by a connection */
 		close (conn->fd);
 	}
diff --git a/src/libutil/http_connection.h b/src/libutil/http_connection.h
index a327eec0d..da354ac41 100644
--- a/src/libutil/http_connection.h
+++ b/src/libutil/http_connection.h
@@ -85,6 +85,7 @@ enum rspamd_http_options {
 	RSPAMD_HTTP_CLIENT_SHARED = 1u << 3, /**< Store reply in shared memory */
 	RSPAMD_HTTP_REQUIRE_ENCRYPTION = 1u << 4,
 	RSPAMD_HTTP_CLIENT_KEEP_ALIVE = 1u << 5,
+	RSPAMD_HTTP_OWN_SOCKET = 1u << 6,
 };
 
 typedef int (*rspamd_http_body_handler_t) (struct rspamd_http_connection *conn,
@@ -118,20 +119,33 @@ struct rspamd_http_connection {
 };
 
 /**
- * Create new http connection
- * @param handler_t handler_t for body
- * @param opts options
- * @return new connection structure
+ * Creates a new HTTP server connection from an opened FD returned by accept function
+ * @param ctx
+ * @param fd
+ * @param body_handler
+ * @param error_handler
+ * @param finish_handler
+ * @param opts
+ * @return
  */
-struct rspamd_http_connection *rspamd_http_connection_new (
+struct rspamd_http_connection *rspamd_http_connection_new_server (
 		struct rspamd_http_context *ctx,
 		gint fd,
 		rspamd_http_body_handler_t body_handler,
 		rspamd_http_error_handler_t error_handler,
 		rspamd_http_finish_handler_t finish_handler,
-		unsigned opts,
-		enum rspamd_http_connection_type type);
+		unsigned opts);
 
+/**
+ * Creates or reuses a new keepalive client connection identified by hostname and inet_addr
+ * @param ctx
+ * @param body_handler
+ * @param error_handler
+ * @param finish_handler
+ * @param addr
+ * @param host
+ * @return
+ */
 struct rspamd_http_connection *rspamd_http_connection_new_keepalive (
 		struct rspamd_http_context *ctx,
 		rspamd_http_body_handler_t body_handler,
@@ -140,6 +154,41 @@ struct rspamd_http_connection *rspamd_http_connection_new_keepalive (
 		rspamd_inet_addr_t *addr,
 		const gchar *host);
 
+/**
+ * Creates an ordinary connection using the address specified (if proxy is not set)
+ * @param ctx
+ * @param body_handler
+ * @param error_handler
+ * @param finish_handler
+ * @param opts
+ * @param addr
+ * @return
+ */
+struct rspamd_http_connection *rspamd_http_connection_new_client (
+		struct rspamd_http_context *ctx,
+		rspamd_http_body_handler_t body_handler,
+		rspamd_http_error_handler_t error_handler,
+		rspamd_http_finish_handler_t finish_handler,
+		unsigned opts,
+		rspamd_inet_addr_t *addr);
+
+/**
+ * Creates an ordinary client connection using ready file descriptor (ignores proxy)
+ * @param ctx
+ * @param body_handler
+ * @param error_handler
+ * @param finish_handler
+ * @param opts
+ * @param addr
+ * @return
+ */
+struct rspamd_http_connection *rspamd_http_connection_new_client_socket (
+		struct rspamd_http_context *ctx,
+		rspamd_http_body_handler_t body_handler,
+		rspamd_http_error_handler_t error_handler,
+		rspamd_http_finish_handler_t finish_handler,
+		unsigned opts,
+		gint fd);
 
 /**
  * Set key pointed by an opaque pointer
diff --git a/src/libutil/http_router.c b/src/libutil/http_router.c
index 570d3d5c6..ec0eeb7b4 100644
--- a/src/libutil/http_router.c
+++ b/src/libutil/http_router.c
@@ -506,13 +506,12 @@ rspamd_http_router_handle_socket (struct rspamd_http_connection_router *router,
 	conn->ud = ud;
 	conn->is_reply = FALSE;
 
-	conn->conn = rspamd_http_connection_new (router->ctx,
+	conn->conn = rspamd_http_connection_new_server (router->ctx,
 			fd,
 			NULL,
 			rspamd_http_router_error_handler,
 			rspamd_http_router_finish_handler,
-			0,
-			RSPAMD_HTTP_SERVER);
+			0);
 
 	if (router->key) {
 		rspamd_http_connection_set_key (conn->conn, router->key);
diff --git a/src/libutil/map.c b/src/libutil/map.c
index 0f7ff4f48..fc414ab00 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -75,76 +75,62 @@ write_http_request (struct http_callback_data *cbd)
 	struct rspamd_map *map;
 
 	map = cbd->map;
+	msg = rspamd_http_new_message (HTTP_REQUEST);
 
-	if (cbd->fd != -1) {
-		close (cbd->fd);
+	if (cbd->bk->protocol == MAP_PROTO_HTTPS) {
+		msg->flags |= RSPAMD_HTTP_FLAG_SSL;
 	}
 
-	cbd->fd = rspamd_inet_address_connect (cbd->addr, SOCK_STREAM, TRUE);
-
-	if (cbd->fd != -1) {
-		msg = rspamd_http_new_message (HTTP_REQUEST);
-
-		if (cbd->bk->protocol == MAP_PROTO_HTTPS) {
-			msg->flags |= RSPAMD_HTTP_FLAG_SSL;
-		}
+	if (cbd->check) {
+		msg->method = HTTP_HEAD;
+	}
 
-		if (cbd->check) {
-			msg->method = HTTP_HEAD;
-		}
+	if (cbd->stage == map_load_file) {
+		msg->url = rspamd_fstring_append (msg->url,
+				cbd->data->path, strlen (cbd->data->path));
 
-		if (cbd->stage == map_load_file) {
-			msg->url = rspamd_fstring_append (msg->url,
-					cbd->data->path, strlen (cbd->data->path));
-
-			if (cbd->check && cbd->stage == map_load_file) {
-				if (cbd->data->last_modified != 0) {
-					rspamd_http_date_format (datebuf, sizeof (datebuf),
-							cbd->data->last_modified);
-					rspamd_http_message_add_header (msg, "If-Modified-Since",
-							datebuf);
-				}
-				if (cbd->data->etag) {
-					rspamd_http_message_add_header_len (msg, "If-None-Match",
-							cbd->data->etag->str, cbd->data->etag->len);
-				}
+		if (cbd->check && cbd->stage == map_load_file) {
+			if (cbd->data->last_modified != 0) {
+				rspamd_http_date_format (datebuf, sizeof (datebuf),
+						cbd->data->last_modified);
+				rspamd_http_message_add_header (msg, "If-Modified-Since",
+						datebuf);
+			}
+			if (cbd->data->etag) {
+				rspamd_http_message_add_header_len (msg, "If-None-Match",
+						cbd->data->etag->str, cbd->data->etag->len);
 			}
 		}
-		else if (cbd->stage == map_load_pubkey) {
-			msg->url = rspamd_fstring_append (msg->url,
-					cbd->data->path, strlen (cbd->data->path));
-			msg->url = rspamd_fstring_append (msg->url, ".pub", 4);
-		}
-		else if (cbd->stage == map_load_signature) {
-			msg->url = rspamd_fstring_append (msg->url,
-					cbd->data->path, strlen (cbd->data->path));
-			msg->url = rspamd_fstring_append (msg->url, ".sig", 4);
-		}
-		else {
-			g_assert_not_reached ();
-		}
-
-		msg->url = rspamd_fstring_append (msg->url, cbd->data->rest,
-					strlen (cbd->data->rest));
-
-		if (cbd->data->userinfo) {
-			rspamd_http_message_add_header (msg, "Authorization",
-					cbd->data->userinfo);
-		}
-
-		MAP_RETAIN (cbd, "http_callback_data");
-		rspamd_http_connection_write_message (cbd->conn,
-				msg,
-				cbd->data->host,
-				NULL,
-				cbd,
-				&cbd->tv);
+	}
+	else if (cbd->stage == map_load_pubkey) {
+		msg->url = rspamd_fstring_append (msg->url,
+				cbd->data->path, strlen (cbd->data->path));
+		msg->url = rspamd_fstring_append (msg->url, ".pub", 4);
+	}
+	else if (cbd->stage == map_load_signature) {
+		msg->url = rspamd_fstring_append (msg->url,
+				cbd->data->path, strlen (cbd->data->path));
+		msg->url = rspamd_fstring_append (msg->url, ".sig", 4);
 	}
 	else {
-		msg_err_map ("cannot connect to %s: %s", cbd->data->host,
-				strerror (errno));
-		cbd->periodic->errored = TRUE;
+		g_assert_not_reached ();
 	}
+
+	msg->url = rspamd_fstring_append (msg->url, cbd->data->rest,
+			strlen (cbd->data->rest));
+
+	if (cbd->data->userinfo) {
+		rspamd_http_message_add_header (msg, "Authorization",
+				cbd->data->userinfo);
+	}
+
+	MAP_RETAIN (cbd, "http_callback_data");
+	rspamd_http_connection_write_message (cbd->conn,
+			msg,
+			cbd->data->host,
+			NULL,
+			cbd,
+			&cbd->tv);
 }
 
 static gboolean
@@ -282,10 +268,6 @@ free_http_cbdata_common (struct http_callback_data *cbd, gboolean plan_new)
 		cbd->conn = NULL;
 	}
 
-	if (cbd->fd != -1) {
-		close (cbd->fd);
-	}
-
 	if (cbd->addr) {
 		rspamd_inet_address_free (cbd->addr);
 	}
@@ -517,7 +499,13 @@ http_map_finish (struct rspamd_http_connection *conn,
 					}
 				}
 
-				rspamd_http_connection_reset (cbd->conn);
+				rspamd_http_connection_unref (cbd->conn);
+				cbd->conn = rspamd_http_connection_new_client (NULL,
+						NULL,
+						http_map_error,
+						http_map_finish,
+						RSPAMD_HTTP_CLIENT_SIMPLE|RSPAMD_HTTP_CLIENT_SHARED,
+						cbd->addr);
 				write_http_request (cbd);
 				MAP_RELEASE (cbd, "http_callback_data");
 
@@ -563,7 +551,13 @@ http_map_finish (struct rspamd_http_connection *conn,
 			}
 
 			cbd->stage = map_load_signature;
-			rspamd_http_connection_reset (cbd->conn);
+			rspamd_http_connection_unref (cbd->conn);
+			cbd->conn = rspamd_http_connection_new_client (NULL,
+					NULL,
+					http_map_error,
+					http_map_finish,
+					RSPAMD_HTTP_CLIENT_SIMPLE|RSPAMD_HTTP_CLIENT_SHARED,
+					cbd->addr);
 			write_http_request (cbd);
 			MAP_RELEASE (cbd, "http_callback_data");
 
@@ -1264,20 +1258,15 @@ rspamd_map_dns_callback (struct rdns_reply *reply, void *arg)
 
 			if (cbd->addr != NULL) {
 				rspamd_inet_address_set_port (cbd->addr, cbd->data->port);
-				/* Try to open a socket */
-				cbd->fd = rspamd_inet_address_connect (cbd->addr, SOCK_STREAM,
-						TRUE);
-
-				if (cbd->fd != -1) {
+				cbd->conn = rspamd_http_connection_new_client (NULL,
+						NULL,
+						http_map_error,
+						http_map_finish,
+						flags,
+						cbd->addr);
+
+				if (cbd->conn != NULL) {
 					cbd->stage = map_load_file;
-					cbd->conn = rspamd_http_connection_new (NULL,
-							cbd->fd,
-							NULL,
-							http_map_error,
-							http_map_finish,
-							flags,
-							RSPAMD_HTTP_CLIENT);
-
 					write_http_request (cbd);
 				}
 				else {
@@ -1623,7 +1612,6 @@ check:
 	cbd->ev_base = map->ev_base;
 	cbd->map = map;
 	cbd->data = data;
-	cbd->fd = -1;
 	cbd->check = check;
 	cbd->periodic = periodic;
 	MAP_RETAIN (periodic, "periodic");
@@ -1638,20 +1626,16 @@ check:
 	/* Send both A and AAAA requests */
 	if (rspamd_parse_inet_address (&cbd->addr, data->host, strlen (data->host))) {
 		rspamd_inet_address_set_port (cbd->addr, cbd->data->port);
-		cbd->fd = rspamd_inet_address_connect (cbd->addr, SOCK_STREAM,
-				TRUE);
+		cbd->conn = rspamd_http_connection_new_client (
+				NULL,
+				NULL,
+				http_map_error,
+				http_map_finish,
+				flags,
+				cbd->addr);
 
-		if (cbd->fd != -1) {
+		if (cbd->conn != NULL) {
 			cbd->stage = map_load_file;
-			cbd->conn = rspamd_http_connection_new (
-					NULL,
-					cbd->fd,
-					NULL,
-					http_map_error,
-					http_map_finish,
-					flags,
-					RSPAMD_HTTP_CLIENT);
-
 			write_http_request (cbd);
 			MAP_RELEASE (cbd, "http_callback_data");
 		}
diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h
index 68415d0e0..b32f0e390 100644
--- a/src/libutil/map_private.h
+++ b/src/libutil/map_private.h
@@ -200,7 +200,6 @@ struct http_callback_data {
 	gsize pubkey_len;
 
 	enum rspamd_map_http_stage stage;
-	gint fd;
 	struct timeval tv;
 
 	ref_entry_t ref;
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index e518e6dab..19cf8f2c9 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -368,8 +368,6 @@ lua_http_resume_handler (struct rspamd_http_connection *conn,
 static gboolean
 lua_http_make_connection (struct lua_http_cbdata *cbd)
 {
-	int fd;
-
 	rspamd_inet_address_set_port (cbd->addr, cbd->msg->port);
 
 	if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_KEEP_ALIVE) {
@@ -384,22 +382,14 @@ lua_http_make_connection (struct lua_http_cbdata *cbd)
 				cbd->host);
 	}
 	else {
-		fd = rspamd_inet_address_connect (cbd->addr, SOCK_STREAM, TRUE);
-
-		if (fd == -1) {
-			msg_info ("cannot connect to %V", cbd->msg->host);
-			return FALSE;
-		}
-
-		cbd->fd = fd;
-		cbd->conn = rspamd_http_connection_new (
+		cbd->fd = -1;
+		cbd->conn = rspamd_http_connection_new_client (
 				NULL, /* Default context */
-				fd,
 				NULL,
 				lua_http_error_handler,
 				lua_http_finish_handler,
 				RSPAMD_HTTP_CLIENT_SIMPLE,
-				RSPAMD_HTTP_CLIENT);
+				cbd->addr);
 	}
 
 	if (cbd->conn) {
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index d2632cb81..63a7dd544 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -125,7 +125,6 @@ struct redirector_param {
 	GHashTable *tree;
 	struct suffix_item *suffix;
 	struct rspamd_symcache_item *item;
-	gint sock;
 	guint redirector_requests;
 };
 
@@ -1689,7 +1688,6 @@ free_redirector_session (void *ud)
 	}
 
 	rspamd_http_connection_unref (param->conn);
-	close (param->sock);
 }
 
 static void
@@ -1780,7 +1778,6 @@ static void
 register_redirector_call (struct rspamd_url *url, struct rspamd_task *task,
 	const gchar *rule)
 {
-	gint s = -1;
 	struct redirector_param *param;
 	struct timeval *timeout;
 	struct upstream *selected;
@@ -1793,11 +1790,15 @@ register_redirector_call (struct rspamd_url *url, struct rspamd_task *task,
*** OUTPUT TRUNCATED, 155 LINES SKIPPED ***


More information about the Commits mailing list