[evolution-data-server/camel-socks-proxy] Debugging code for the SSL stream



commit 12faeaa54fc97f7fb96a662447e0dceec26f1ab8
Author: Federico Mena Quintero <federico novell com>
Date:   Wed Jun 2 13:32:38 2010 -0500

    Debugging code for the SSL stream
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-ssl.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index d013e96..fb697bf 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -62,6 +62,8 @@
 #include "camel-stream-fs.h"
 #include "camel-tcp-stream-ssl.h"
 
+#define d(x)
+
 #define IO_TIMEOUT (PR_TicksPerSecond() * 4 * 60)
 #define CONNECT_TIMEOUT (PR_TicksPerSecond () * 4 * 60)
 
@@ -1246,17 +1248,22 @@ connect_to_socks4_proxy (CamelTcpStreamSSL *ssl, const gchar *proxy_host, gint p
 
 	g_assert (proxy_host != NULL);
 
+	d (g_print ("SSL: connecting to SOCKS4 proxy %s:%d {\n  resolving proxy host\n", proxy_host, proxy_port));
+
 	sprintf (serv, "%d", proxy_port);
 
 	memset (&hints, 0, sizeof (hints));
 	hints.ai_socktype = SOCK_STREAM;
-	
+
 	ai = camel_getaddrinfo (proxy_host, serv, &hints, NULL);  /* NULL-CamelException */
 	if (!ai) {
 		errno = EHOSTUNREACH; /* FIXME: this is not an accurate error; we should translate the CamelException to an errno */
+		d (g_print ("  camel_getaddrinfo() for the proxy failed\n}\n"));
 		return NULL;
 	}
 
+	d (g_print ("  creating socket and connecting\n"));
+
 	fd = socket_connect (CAMEL_TCP_STREAM (ssl), ai, FALSE);
 	save_errno = errno;
 
@@ -1264,6 +1271,7 @@ connect_to_socks4_proxy (CamelTcpStreamSSL *ssl, const gchar *proxy_host, gint p
 
 	if (!fd) {
 		errno = save_errno;
+		d (g_print ("  could not connect: %d\n", errno));
 		goto error;
 	}
 
@@ -1276,26 +1284,38 @@ connect_to_socks4_proxy (CamelTcpStreamSSL *ssl, const gchar *proxy_host, gint p
 	memcpy (request + 4, &sin->sin_addr.s_addr, 4);	/* address in network byte order */
 	request[8] = 0x00;				/* terminator */
 
-	if (write_to_prfd (fd, request, sizeof (request)) != sizeof (request))
+	d (g_print ("  writing SOCKS4 request to connect to actual host\n"));
+	if (write_to_prfd (fd, request, sizeof (request)) != sizeof (request)) {
+		d (g_print ("  failed: %d\n", errno));
 		goto error;
+	}
 
-	if (read_from_prfd (fd, reply, sizeof (reply)) != sizeof (reply))
+	d (g_print ("  reading SOCKS4 reply\n"));
+	if (read_from_prfd (fd, reply, sizeof (reply)) != sizeof (reply)) {
+		d (g_print ("  failed: %d\n", errno));
 		goto error;
+	}
 
 	if (!(reply[0] == 0		/* first byte of reply is 0 */
 	      && reply[1] == 90)) {	/* 90 means "request granted" */
 		errno = ECONNREFUSED;
+		d (g_print ("  proxy replied with code %d\n", reply[1]));
 		goto error;
 	}
 
 	/* We are now proxied we are ready to send "normal" data through the socket */
 
 	if (ssl->priv->ssl_mode) {
+		d (g_print ("  enabling SSL\n"));
 		fd = enable_ssl_or_close_fd (ssl, fd);
-		if (!fd)
+		if (!fd) {
+			d (g_print ("  could not enable SSL\n"));
 			goto error;
+		}
 	}
 
+	d (g_print ("  success\n"));
+
 	goto out;
 
 error:
@@ -1307,8 +1327,12 @@ error:
 		fd = NULL;
 	}
 
+	d (g_print ("  returning errno %d\n", errno));
+
 out:
 
+	d (g_print ("}\n"));
+
 	return fd;
 }
 



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