summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-13 17:30:41 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-13 17:31:29 +0100
commit6982f0ab13c551ea880315ee05dcc29479644eaa (patch)
treee98f576731fd4b0a290bc3eb0f028fa755cc252c
parent5d46e29fcac899483e6b2f3d0790e4c8915411c7 (diff)
downloadrspamd-6982f0ab13c551ea880315ee05dcc29479644eaa.tar.gz
rspamd-6982f0ab13c551ea880315ee05dcc29479644eaa.zip
[Feature] Implement HTTPS client
-rw-r--r--src/libutil/http.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c
index b4a1692cc..7196c9221 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -898,16 +898,23 @@ rspamd_http_write_helper (struct rspamd_http_connection *conn)
#ifdef MSG_NOSIGNAL
flags = MSG_NOSIGNAL;
#endif
- r = sendmsg (conn->fd, &msg, flags);
+
+ if (priv->ssl) {
+ r = rspamd_ssl_writev (priv->ssl, msg.msg_iov, msg.msg_iovlen);
+ }
+ else {
+ r = sendmsg (conn->fd, &msg, flags);
+ }
if (r == -1) {
- err =
- g_error_new (HTTP_ERROR, errno, "IO write error: %s", strerror (
- errno));
- rspamd_http_connection_ref (conn);
- conn->error_handler (conn, err);
- rspamd_http_connection_unref (conn);
- g_error_free (err);
+ if (!priv->ssl) {
+ err = g_error_new (HTTP_ERROR, errno, "IO write error: %s", strerror (errno));
+ rspamd_http_connection_ref (conn);
+ conn->error_handler (conn, err);
+ rspamd_http_connection_unref (conn);
+ g_error_free (err);
+ }
+
return;
}
else {
@@ -948,7 +955,13 @@ rspamd_http_try_read (gint fd,
rspamd_fstring_t *buf;
buf = priv->buf->data;
- r = read (fd, buf->str, buf->allocated);
+
+ if (priv->ssl) {
+ r = rspamd_ssl_read (priv->ssl, buf->str, buf->allocated);
+ }
+ else {
+ r = read (fd, buf->str, buf->allocated);
+ }
if (r <= 0) {
return r;
@@ -1020,12 +1033,14 @@ rspamd_http_event_handler (int fd, short what, gpointer ud)
return;
}
else {
- err = g_error_new (HTTP_ERROR,
- errno,
- "IO read error: %s",
- strerror (errno));
- conn->error_handler (conn, err);
- g_error_free (err);
+ if (!priv->ssl) {
+ err = g_error_new (HTTP_ERROR,
+ errno,
+ "IO read error: %s",
+ strerror (errno));
+ conn->error_handler (conn, err);
+ g_error_free (err);
+ }
REF_RELEASE (pbuf);
rspamd_http_connection_unref (conn);
@@ -1178,11 +1193,6 @@ rspamd_http_connection_reset (struct rspamd_http_connection *conn)
priv->out = NULL;
}
- if (priv->ssl) {
- rspamd_ssl_connection_free (priv->ssl);
- priv->ssl = NULL;
- }
-
priv->flags |= RSPAMD_HTTP_CONN_FLAG_RESETED;
}
@@ -1325,6 +1335,11 @@ rspamd_http_connection_free (struct rspamd_http_connection *conn)
if (priv != NULL) {
rspamd_http_connection_reset (conn);
+ if (priv->ssl) {
+ rspamd_ssl_connection_free (priv->ssl);
+ priv->ssl = NULL;
+ }
+
if (priv->local_key) {
rspamd_keypair_unref (priv->local_key);
}
@@ -1948,6 +1963,11 @@ rspamd_http_connection_write_message_common (struct rspamd_http_connection *conn
return;
}
else {
+ if (priv->ssl) {
+ /* Cleanup the existing connection */
+ rspamd_ssl_connection_free (priv->ssl);
+ }
+
priv->ssl = rspamd_ssl_connection_new (priv->ssl_ctx, base);
g_assert (priv->ssl != NULL);