[evolution-patches] 67898, port number fallback for broken installations




not much to it

--
Michael Zucchi <notzed ximian com>
"born to die, live to work, it's all downhill from here"
Novell's Evolution and Free Software Developer
Index: camel/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.2251.2.17
diff -u -3 -r1.2251.2.17 ChangeLog
--- camel/ChangeLog	12 Oct 2004 02:01:22 -0000	1.2251.2.17
+++ camel/ChangeLog	12 Oct 2004 04:01:04 -0000
@@ -1,3 +1,16 @@
+2004-10-12  Not Zed  <NotZed Ximian com>
+
+	** See bug #67898 and probably others.
+
+	* providers/imapp/camel-imapp-store.c (connect_to_server):
+	* providers/pop3/camel-pop3-store.c (connect_to_server): 
+	* providers/imap4/camel-imap4-store.c (connect_to_server_wrapper): 
+	* providers/imap/camel-imap-store.c (connect_to_server): 
+	* providers/nntp/camel-nntp-store.c (connect_to_server): 
+	* providers/smtp/camel-smtp-transport.c (connect_to_server):
+	Fallback to hard-coded port number if the name lookup fails and no
+	port was supplied.
+
 2004-10-11  Not Zed  <NotZed Ximian com>
 
 	** See bug #67211.
Index: camel/providers/imap/camel-imap-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/imap/camel-imap-store.c,v
retrieving revision 1.300.2.3
diff -u -3 -r1.300.2.3 camel-imap-store.c
--- camel/providers/imap/camel-imap-store.c	27 Sep 2004 18:59:32 -0000	1.300.2.3
+++ camel/providers/imap/camel-imap-store.c	12 Oct 2004 04:01:05 -0000
@@ -68,8 +68,8 @@
 #define d(x) 
 
 /* Specified in RFC 2060 */
-#define IMAP_PORT 143
-#define SIMAP_PORT 993
+#define IMAP_PORT "143"
+#define IMAPS_PORT "993"
 
 static CamelDiscoStoreClass *parent_class = NULL;
 
@@ -526,27 +526,34 @@
 	char *buf;
 	struct addrinfo *ai, hints = { 0 };
 	char *serv;
+	const char *port = NULL;
 
 	/* FIXME: this connect stuff is duplicated everywhere */
 
 	if (service->url->port) {
 		serv = g_alloca(16);
 		sprintf(serv, "%d", service->url->port);
-	} else
+	} else {
 		serv = "imap";
+		port = IMAP_PORT;
+	}
 	
 	if (ssl_mode != USE_SSL_NEVER) {
 #ifdef HAVE_SSL
 		if (try_starttls) {
 			tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
 		} else {
-			if (service->url->port == 0)
+			if (service->url->port == 0) {
 				serv = "imaps";
+				port = IMAPS_PORT;
+			}
 			tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
 		}
 #else
-		if (!try_starttls && service->url->port == 0)
+		if (!try_starttls && service->url->port == 0) {
 			serv = "imaps";
+			port = IMAPS_PORT;
+		}
 		
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 				      _("Could not connect to %s (port %s): %s"),
@@ -560,6 +567,10 @@
 
 	hints.ai_socktype = SOCK_STREAM;
 	ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+	if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) {
+		camel_exception_clear(ex);
+		ai = camel_getaddrinfo(service->url->host, port, &hints, ex);
+	}
 	if (ai == NULL) {
 		camel_object_unref(tcp_stream);
 		return FALSE;
Index: camel/providers/imap4/camel-imap4-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/imap4/camel-imap4-store.c,v
retrieving revision 1.22.2.3
diff -u -3 -r1.22.2.3 camel-imap4-store.c
--- camel/providers/imap4/camel-imap4-store.c	28 Sep 2004 14:44:59 -0000	1.22.2.3
+++ camel/providers/imap4/camel-imap4-store.c	12 Oct 2004 04:01:06 -0000
@@ -275,13 +275,14 @@
 static struct {
 	char *value;
 	char *serv;
+	char *port;
 	int mode;
 } ssl_options[] = {
-	{ "",              "imaps", MODE_SSL   },  /* really old (1.x) */
-	{ "always",        "imaps", MODE_SSL   },
-	{ "when-possible", "imap",  MODE_TLS   },
-	{ "never",         "imap",  MODE_CLEAR },
-	{ NULL,            "imap",  MODE_CLEAR },
+	{ "",              "imaps", "993", MODE_SSL   },  /* really old (1.x) */
+	{ "always",        "imaps", "993", MODE_SSL   },
+	{ "when-possible", "imap",  "143", MODE_TLS   },
+	{ "never",         "imap",  "143", MODE_CLEAR },
+	{ NULL,            "imap",  "143", MODE_CLEAR },
 };
 
 static gboolean
@@ -292,27 +293,36 @@
 	const char *ssl_mode;
 	int mode, ret, i;
 	char *serv;
-	
+	const char *port;
+
 	if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) {
 		for (i = 0; ssl_options[i].value; i++)
 			if (!strcmp (ssl_options[i].value, ssl_mode))
 				break;
 		mode = ssl_options[i].mode;
 		serv = ssl_options[i].serv;
+		port = ssl_options[i].port;
 	} else {
 		mode = MODE_CLEAR;
 		serv = "imap";
+		port = "143";
 	}
 	
 	if (service->url->port) {
 		serv = g_alloca (16);
 		sprintf (serv, "%d", service->url->port);
+		port = NULL;
 	}
 	
 	memset (&hints, 0, sizeof (hints));
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_family = PF_UNSPEC;
-	if (!(ai = camel_getaddrinfo (service->url->host, serv, &hints, ex)))
+	ai = camel_getaddrinfo (service->url->host, serv, &hints, ex);
+	if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) {
+		camel_exception_clear (ex);
+		ai = camel_getaddrinfo (service->url->host, port, &hints, ex);
+	}
+	if (ai == NULL)
 		return FALSE;
 	
 	ret = connect_to_server (engine, ai, mode, ex);
Index: camel/providers/imapp/camel-imapp-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/imapp/camel-imapp-store.c,v
retrieving revision 1.10.16.1
diff -u -3 -r1.10.16.1 camel-imapp-store.c
--- camel/providers/imapp/camel-imapp-store.c	23 Sep 2004 04:12:29 -0000	1.10.16.1
+++ camel/providers/imapp/camel-imapp-store.c	12 Oct 2004 04:01:06 -0000
@@ -195,6 +195,7 @@
 	ex = camel_exception_new();
 	CAMEL_TRY {
 		char *serv;
+		const char *port = NULL;
 		struct addrinfo *ai, hints = { 0 };
 
 		/* parent class connect initialization */
@@ -205,16 +206,20 @@
 		if (service->url->port) {
 			serv = g_alloca(16);
 			sprintf(serv, "%d", service->url->port);
-		} else
+		} else {
 			serv = "imap";
+			port = "143";
+		}
 
 #ifdef HAVE_SSL	
 		if (camel_url_get_param (service->url, "use_ssl")) {
 			if (try_starttls)
 				tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
 			else {
-				if (service->url->port == 0)
+				if (service->url->port == 0) {
 					serv = "imaps";
+					port = "993";
+				}
 				tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
 			}
 		} else {
@@ -226,6 +231,11 @@
 
 		hints.ai_socktype = SOCK_STREAM;
 		ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+		if (ex->id && ex->id != CAMEL_EXCEPTION_USER_CANCEL && port != NULL) {
+			camel_exception_clear(ex);
+			ai = camel_getaddrinfo(service->url->host, port, &hints, ex);
+		}
+
 		if (ex->id)
 			camel_exception_throw_ex(ex);
 	
Index: camel/providers/nntp/camel-nntp-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/nntp/camel-nntp-store.c,v
retrieving revision 1.65.14.7
diff -u -3 -r1.65.14.7 camel-nntp-store.c
--- camel/providers/nntp/camel-nntp-store.c	11 Oct 2004 01:37:41 -0000	1.65.14.7
+++ camel/providers/nntp/camel-nntp-store.c	12 Oct 2004 04:01:06 -0000
@@ -57,8 +57,8 @@
 extern int camel_verbose_debug;
 #define dd(x) (camel_verbose_debug?(x):0)
 
-#define NNTP_PORT  119
-#define NNTPS_PORT 563
+#define NNTP_PORT  "119"
+#define NNTPS_PORT "563"
 
 #define DUMP_EXTENSIONS
 
@@ -166,6 +166,7 @@
 	char *path;
 	struct addrinfo *ai, hints = { 0 };
 	char *serv;
+	const char *port = NULL;
 	
 	CAMEL_SERVICE_LOCK(store, connect_lock);
 
@@ -186,13 +187,17 @@
 	if (service->url->port) {
 		serv = g_alloca(16);
 		sprintf(serv, "%d", service->url->port);
-	} else
+	} else {
 		serv = "nntp";
+		port = NNTP_PORT;
+	}
 	
 #ifdef HAVE_SSL
 	if (ssl_mode != USE_SSL_NEVER) {
-		if (service->url->port == 0)
+		if (service->url->port == 0) {
 			serv = "nntps";
+			port = NNTPS_PORT;
+		}
 		tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3);
 	} else {
 		tcp_stream = camel_tcp_stream_raw_new ();
@@ -203,6 +208,10 @@
 
 	hints.ai_socktype = SOCK_STREAM;
 	ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+	if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) {
+		camel_exception_clear(ex);
+		ai = camel_getaddrinfo(service->url->host, port, &hints, ex);
+	}
 	if (ai == NULL) {
 		camel_object_unref(tcp_stream);
 		goto fail;
Index: camel/providers/pop3/camel-pop3-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/pop3/camel-pop3-store.c,v
retrieving revision 1.106.14.4
diff -u -3 -r1.106.14.4 camel-pop3-store.c
--- camel/providers/pop3/camel-pop3-store.c	27 Sep 2004 18:59:32 -0000	1.106.14.4
+++ camel/providers/pop3/camel-pop3-store.c	12 Oct 2004 04:01:06 -0000
@@ -153,26 +153,33 @@
 	int ret;
 	struct addrinfo *ai, hints = { 0 };
 	char *serv;
+	const char *port = NULL;
 
 	if (service->url->port) {
 		serv = g_alloca(16);
 		sprintf(serv, "%d", service->url->port);
-	} else
+	} else {
 		serv = "pop3";
+		port = "110";
+	}
 		
 	if (ssl_mode != USE_SSL_NEVER) {
 #ifdef HAVE_SSL
 		if (try_starttls) {
 			tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
 		} else {
-			if (service->url->port == 0)
+			if (service->url->port == 0) {
 				serv = "pop3s";
+				port = "995";
+			}
 			tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
 		}
 #else
-		if (!try_starttls && service->url->port == 0)
+		if (!try_starttls && service->url->port == 0) {
 			serv = "pop3s";
-		
+			port = "995";
+		}
+
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 				      _("Could not connect to %s (port %s): %s"),
 				      service->url->host, serv,
@@ -186,6 +193,10 @@
 
 	hints.ai_socktype = SOCK_STREAM;
 	ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+	if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) {
+		camel_exception_clear(ex);
+		ai = camel_getaddrinfo(service->url->host, port, &hints, ex);
+	}
 	if (ai == NULL) {
 		camel_object_unref(tcp_stream);
 		return FALSE;
Index: camel/providers/smtp/camel-smtp-transport.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/smtp/camel-smtp-transport.c,v
retrieving revision 1.157.14.3
diff -u -3 -r1.157.14.3 camel-smtp-transport.c
--- camel/providers/smtp/camel-smtp-transport.c	27 Sep 2004 18:59:32 -0000	1.157.14.3
+++ camel/providers/smtp/camel-smtp-transport.c	12 Oct 2004 04:01:07 -0000
@@ -240,6 +240,7 @@
 	int ret;
 	struct addrinfo *ai, hints = { 0 };
 	char *serv;
+	const char *port = NULL;
 	
 	if (!CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex))
 		return FALSE;
@@ -251,21 +252,27 @@
 	if (service->url->port) {
 		serv = g_alloca(16);
 		sprintf(serv, "%d", service->url->port);
-	} else
+	} else {
 		serv = "smtp";
+		port = "25";
+	}
 	
 	if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL) {
 #ifdef HAVE_SSL
 		if (try_starttls) {
 			tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
 		} else {
-			if (service->url->port == 0)
+			if (service->url->port == 0) {
 				serv = "smtps";
+				port = "465";
+			}
 			tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
 		}
 #else
-		if (!try_starttls && service->url->port == 0)
+		if (!try_starttls && service->url->port == 0) {
 			serv = "smtps";
+			port = "465";
+		}
 		
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 				      _("Could not connect to %s (port %s): %s"),
@@ -280,6 +287,11 @@
 
 	hints.ai_socktype = SOCK_STREAM;
 	ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+	/* fallback to numerical port if the system is misconfigured */
+	if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) {
+		camel_exception_clear(ex);
+		ai = camel_getaddrinfo(service->url->host, port, &hints, ex);
+	}
 	if (ai == NULL) {
 		camel_object_unref(tcp_stream);
 		return FALSE;


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