[evolution-data-server/camel-socks-proxy-master] Try SOCKS5, then SOCKS4



commit 191d108c2fa9a689a6e0ab11338ef74b46d3d6c0
Author: Federico Mena Quintero <federico novell com>
Date:   Thu Jul 22 16:02:40 2010 -0500

    Try SOCKS5, then SOCKS4
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-raw.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c
index 1317a12..a423af9 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -664,7 +664,8 @@ out:
 
 /* Returns the FD of a socket, already connected to and validated by the SOCKS4
  * proxy that is configured in the stream.  Otherwise returns NULL.  Assumes that
- * a proxy *is* configured with camel_tcp_stream_set_socks_proxy().
+ * a proxy *is* configured with camel_tcp_stream_set_socks_proxy().  Only tries the first
+ * connect_addr; if you want to traverse all the addrinfos, call this function for each of them.
  */
 static PRFileDesc *
 connect_to_socks4_proxy (CamelTcpStreamRaw *raw, const gchar *proxy_host, gint proxy_port, struct addrinfo *connect_addr, GError **error)
@@ -999,6 +1000,24 @@ tcp_stream_raw_connect (CamelTcpStream *stream,
 	const gchar *proxy_host;
 	gint proxy_port;
 
+	camel_tcp_stream_peek_socks_proxy (stream, &proxy_host, &proxy_port);
+
+	if (proxy_host) {
+		/* First, try SOCKS5, which does name resolution itself */
+
+		my_error = NULL;
+		priv->sockfd = connect_to_socks5_proxy (raw, proxy_host, proxy_port, host, service, fallback_port, &my_error);
+		if (priv->sockfd)
+			return 0;
+		else if (g_error_matches (my_error, CAMEL_PROXY_ERROR, CAMEL_PROXY_ERROR_CANT_AUTHENTICATE)
+			 || !g_error_matches (my_error, CAMEL_PROXY_ERROR, CAMEL_PROXY_ERROR_PROXY_NOT_SUPPORTED)) {
+			g_propagate_error (error, my_error);
+			return -1;
+		}
+	}
+
+	/* Second, do name resolution ourselves and try SOCKS4 or a normal connection */
+
 	memset (&hints, 0, sizeof (hints));
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_family = PF_UNSPEC;
@@ -1018,8 +1037,6 @@ tcp_stream_raw_connect (CamelTcpStream *stream,
 		return -1;
 	}
 
-	camel_tcp_stream_peek_socks_proxy (stream, &proxy_host, &proxy_port);
-
 	ai = addr;
 
 	while (ai) {



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