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



commit 7ae5201e40147033323685e47219268ff491da05
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 3eb0fe5..3250fc3 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -406,10 +406,8 @@ socket_connect(struct addrinfo *h)
  * 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;
@@ -418,16 +416,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;
 
@@ -477,11 +473,19 @@ static gint
 stream_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]