[evolution-data-server] TcpRaw: Connect via a SOCKS4 proxy if available



commit e74339407f1c4282638d033a5f815953de60be72
Author: Federico Mena Quintero <federico novell com>
Date:   Wed May 26 14:38:33 2010 -0500

    TcpRaw: Connect via a SOCKS4 proxy if available
    
    We will deal with SSL streams later.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-raw.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c
index 2058afe..8612778 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -378,10 +378,8 @@ tcp_stream_raw_close (CamelStream *stream)
  * a proxy *is* configured with camel_tcp_stream_set_socks_proxy().
  */
 static gint
-connect_to_socks4_proxy (CamelTcpStreamRaw *raw, struct addrinfo *connect_addr)
+connect_to_socks4_proxy (const gchar *proxy_host, gint proxy_port, struct addrinfo *connect_addr)
 {
-	const gchar *host;
-	gint port;
 	struct addrinfo *ai, hints;
 	gchar serv[16];
 	gint fd;
@@ -390,16 +388,14 @@ connect_to_socks4_proxy (CamelTcpStreamRaw *raw, struct addrinfo *connect_addr)
 	guint32 network_address;
 	gchar reply[8];
 
-	camel_tcp_stream_peek_socks_proxy (CAMEL_TCP_STREAM (raw), &host, &port);
+	g_assert (proxy_host != NULL);
 
-	g_assert (host != NULL);
-
-	sprintf (serv, "%d", port);
+	sprintf (serv, "%d", proxy_port);
 
 	memset (&hints, 0, sizeof (hints));
 	hints.ai_socktype = SOCK_STREAM;
 
-	ai = camel_getaddrinfo (host, serv, &hints, NULL);
+	ai = camel_getaddrinfo (proxy_host, serv, &hints, NULL);
 	if (!ai)
 		return -1;
 
@@ -450,11 +446,19 @@ tcp_stream_raw_connect (CamelTcpStream *stream,
                         struct addrinfo *host)
 {
 	CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+	const gchar *proxy_host;
+	gint proxy_port;
 
 	g_return_val_if_fail (host != NULL, -1);
 
+	camel_tcp_stream_peek_socks_proxy (stream, &proxy_host, &proxy_port);
+
 	while (host) {
-		raw->sockfd = socket_connect(host);
+		if (proxy_host)
+			raw->sockfd = connect_to_socks4_proxy (proxy_host, proxy_port, host);
+		else
+			raw->sockfd = socket_connect (host);
+
 		if (raw->sockfd != -1)
 			return 0;
 



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