changeset 22327:dc47e908965f

Use connect server as FQDN for SASL auth except when it is an IP address. References #699.
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 26 Feb 2008 13:53:22 +0000
parents 63f102c210ad
children 5fd8b4b4c6bd
files ChangeLog.API libpurple/protocols/jabber/jabber.c libpurple/util.c libpurple/util.h
diffstat 4 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Mon Feb 25 15:24:49 2008 +0000
+++ b/ChangeLog.API	Tue Feb 26 13:53:22 2008 +0000
@@ -9,6 +9,7 @@
 		  purple_micro_version variables are exported by version.h,
 		  giving the version of libpurple in use at runtime.
 		* purple_util_set_current_song, purple_util_format_song_info
+		* purple_ip_address_is_valid
 		* Some accessor functions to the Roomlist API:
 			* purple_roomlist_get_fields
 			* purple_roomlist_room_get_type
--- a/libpurple/protocols/jabber/jabber.c	Mon Feb 25 15:24:49 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Tue Feb 26 13:53:22 2008 +0000
@@ -564,9 +564,16 @@
 			jabber_login_callback_ssl, jabber_ssl_connect_failure, js->certificate_CN, js->gc);
 }
 
-static void jabber_login_connect(JabberStream *js, const char *fqdn, const char *host, int port)
+static void jabber_login_connect(JabberStream *js, const char *domain, const char *host, int port)
 {
-	js->serverFQDN = g_strdup(fqdn);
+	/* host should be used in preference to domain to
+	 * allow SASL authentication to work with FQDN of the server,
+	 * but we use domain as fallback for when users enter IP address
+	 * in connect server */
+	if (purple_ip_address_is_valid(host))
+		js->serverFQDN = g_strdup(domain);
+	else
+		js->serverFQDN = g_strdup(host);
 
 	if (purple_proxy_connect(js->gc, js->gc->account, host,
 			port, jabber_login_callback, js->gc) == NULL)
--- a/libpurple/util.c	Mon Feb 25 15:24:49 2008 +0000
+++ b/libpurple/util.c	Tue Feb 26 13:53:22 2008 +0000
@@ -4129,6 +4129,17 @@
 	return ((c - domain) > 3 ? TRUE : FALSE);
 }
 
+gboolean
+purple_ip_address_is_valid(const char *ip)
+{
+	int c, o1, o2, o3, o4;
+	char end;
+	c = sscanf(ip, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, &end);
+	if (c > 4 || o1 < 0 || o1 > 255 || o2 < 0 || o2 > 255 || o3 < 0 || o3 > 255 || o4 < 0 || o4 > 255)
+		return FALSE;
+	return TRUE;
+}
+
 /* Stolen from gnome_uri_list_extract_uris */
 GList *
 purple_uri_list_extract_uris(const gchar *uri_list)
--- a/libpurple/util.h	Mon Feb 25 15:24:49 2008 +0000
+++ b/libpurple/util.h	Tue Feb 26 13:53:22 2008 +0000
@@ -1081,6 +1081,15 @@
 gboolean purple_email_is_valid(const char *address);
 
 /**
+ * Checks if the given IP address is a syntactically valid IPv4 address.
+ *
+ * @param address The IP address to validate.
+ *
+ * @return True if the IP address is syntactically correct.
+ */
+gboolean purple_ip_address_is_valid(const char *ip);
+
+/**
  * This function extracts a list of URIs from the a "text/uri-list"
  * string.  It was "borrowed" from gnome_uri_list_extract_uris
  *