[evolution-data-server/camel-socks-proxy] Make socket_connect() in the TCP-SSL stream more generic



commit eace07d7b5356238449338436f9e7f5ee25764c5
Author: Federico Mena Quintero <federico novell com>
Date:   Wed May 26 18:58:31 2010 -0500

    Make socket_connect() in the TCP-SSL stream more generic
    
    This way we will be able to use it to connect to
    the SOCKS4 proxy itself.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-ssl.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index 62290c4..ef5d6a8 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -1118,8 +1118,8 @@ sockaddr_to_praddr(struct sockaddr *s, gint len, PRNetAddr *addr)
 	return -1;
 }
 
-static gint
-socket_connect(CamelTcpStream *stream, struct addrinfo *host)
+static PRFileDesc *
+socket_connect(CamelTcpStream *stream, struct addrinfo *host, gboolean possibly_use_ssl)
 {
 	CamelTcpStreamSSL *ssl = CAMEL_TCP_STREAM_SSL (stream);
 	PRNetAddr netaddr;
@@ -1127,16 +1127,16 @@ socket_connect(CamelTcpStream *stream, struct addrinfo *host)
 
 	if (sockaddr_to_praddr(host->ai_addr, host->ai_addrlen, &netaddr) != 0) {
 		errno = EINVAL;
-		return -1;
+		return NULL;
 	}
 
 	fd = PR_OpenTCPSocket(netaddr.raw.family);
 	if (fd == NULL) {
 		set_errno (PR_GetError ());
-		return -1;
+		return NULL;
 	}
 
-	if (ssl->priv->ssl_mode) {
+	if (possibly_use_ssl && ssl->priv->ssl_mode) {
 		PRFileDesc *ssl_fd;
 
 		ssl_fd = enable_ssl (ssl, fd);
@@ -1149,7 +1149,7 @@ socket_connect(CamelTcpStream *stream, struct addrinfo *host)
 			PR_Close (fd);
 			errno = errnosave;
 
-			return -1;
+			return NULL;
 		}
 
 		fd = ssl_fd;
@@ -1199,26 +1199,27 @@ socket_connect(CamelTcpStream *stream, struct addrinfo *host)
 			errnosave = errno;
 			PR_Shutdown (fd, PR_SHUTDOWN_BOTH);
 			PR_Close (fd);
-			ssl->priv->sockfd = NULL;
 			errno = errnosave;
 
-			return -1;
+			return NULL;
 		}
 
 		errno = 0;
 	}
 
-	ssl->priv->sockfd = fd;
-
-	return 0;
+	return fd;
 }
 
 static gint
 stream_connect(CamelTcpStream *stream, struct addrinfo *host)
 {
+	CamelTcpStreamSSL *ssl = CAMEL_TCP_STREAM_SSL (stream);
+
 	while (host) {
-		if (socket_connect(stream, host) == 0)
+		ssl->priv->sockfd = socket_connect (stream, host, TRUE);
+		if (ssl->priv->sockfd)
 			return 0;
+
 		host = host->ai_next;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]