[evolution-data-server/camel-socks-proxy-master] Add new GError codes for SOCKS proxies - CamelProxyError



commit 9d67949a95671862e1390dd8c4116f60ef714694
Author: Federico Mena Quintero <federico novell com>
Date:   Thu Jul 22 15:09:32 2010 -0500

    Add new GError codes for SOCKS proxies - CamelProxyError
    
    We differentiate between "the proxy does not support our protocol"
    and "the proxy does not support our authentication type".
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 camel/camel-tcp-stream-raw.c |   27 +++++++++++++++++++++++----
 camel/camel-tcp-stream-raw.h |   14 ++++++++++++++
 2 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c
index 532b5b7..e1594ec 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -781,10 +781,16 @@ socks5_initiate_and_request_authentication (CamelTcpStreamRaw *raw, PRFileDesc *
 		return FALSE;
 	}
 
-	if (!(reply[0] == 5		/* server supports SOCKS5 */
-	      && reply[1] == 0)) {	/* and it grants us no authentication (see request[2]) */
-		errno = ECONNREFUSED;
-		d (g_print ("  proxy replied with code %d %d\n", reply[0], reply[1]));
+	if (reply[0] != 5) {		/* server supports SOCKS5 */
+		g_set_error (error, CAMEL_PROXY_ERROR, CAMEL_PROXY_ERROR_PROXY_NOT_SUPPORTED,
+			     _("The proxy host does not support SOCKS5"));
+		return FALSE;
+	}
+
+	if (reply[1] != 0) {		/* and it grants us no authentication (see request[2]) */
+		g_set_error (error, CAMEL_PROXY_ERROR, CAMEL_PROXY_ERROR_CANT_AUTHENTICATE
+			     _("Could not find a suitable authentication type: code 0x%x"),
+			     reply[1]);
 		return FALSE;
 	}
 
@@ -1186,6 +1192,19 @@ camel_tcp_stream_raw_init (CamelTcpStreamRaw *stream)
 	priv->sockfd = NULL;
 }
 
+GQuark
+camel_proxy_error_quark (void)
+{
+	static GQuark quark = 0;
+
+	if (G_UNLIKELY (quark == 0)) {
+		const gchar *string = "camel-proxy-error-quark";
+		quark = g_quark_from_static_string (string);
+	}
+
+	return quark;
+}
+
 /**
  * camel_tcp_stream_raw_new:
  *
diff --git a/camel/camel-tcp-stream-raw.h b/camel/camel-tcp-stream-raw.h
index f87a638..9f73ac1 100644
--- a/camel/camel-tcp-stream-raw.h
+++ b/camel/camel-tcp-stream-raw.h
@@ -50,6 +50,8 @@
 
 G_BEGIN_DECLS
 
+#define CAMEL_PROXY_ERROR (camel_proxy_error_quark ())
+
 typedef struct _CamelTcpStreamRaw CamelTcpStreamRaw;
 typedef struct _CamelTcpStreamRawClass CamelTcpStreamRawClass;
 
@@ -63,6 +65,18 @@ struct _CamelTcpStreamRawClass {
 	CamelTcpStreamClass parent_class;
 };
 
+/**
+ * CamelProxyError:
+ *
+ * Since: 3.0
+ */
+typedef enum {
+	CAMEL_PROXY_ERROR_PROXY_NOT_SUPPORTED,
+	CAMEL_PROXY_ERROR_CANT_AUTHENTICATE
+} CamelProxyError;
+
+GQuark camel_proxy_error_quark (void) G_GNUC_CONST;
+
 GType camel_tcp_stream_raw_get_type (void);
 
 /* public methods */



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