Add new GError codes for SOCKS proxies - CamelProxyError
authorFederico Mena Quintero <federico@novell.com>
Thu, 22 Jul 2010 20:09:32 +0000 (15:09 -0500)
committerFederico Mena Quintero <federico@novell.com>
Wed, 28 Jul 2010 21:41:06 +0000 (16:41 -0500)
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
camel/camel-tcp-stream-raw.h

index 532b5b7..e1594ec 100644 (file)
@@ -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:
  *
index f87a638..9f73ac1 100644 (file)
@@ -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 */