changeset 27367:cbd67b8bf3ca

merge of '1bbd08b1b4f931fa4318c1042033c441a36397ee' and '60b8637e2af27d99451c148fe737ebf48ac8c901'
author Paul Aurich <paul@darkrain42.org>
date Sat, 04 Jul 2009 05:17:11 +0000
parents c3b1711991fc (diff) 77dfed554b2b (current diff)
children 2a5c906e1104 d4c6d2c6fb03
files
diffstat 4 files changed, 89 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/oscar.c	Sat Jul 04 03:08:10 2009 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Sat Jul 04 05:17:11 2009 +0000
@@ -1882,7 +1882,7 @@
 		switch (info->errorcode) {
 		case 0x01:
 			/* Unregistered username */
-			purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_INVALID_USERNAME, _("Invalid username."));
+			purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_INVALID_USERNAME, _("Username does not exist"));
 			break;
 		case 0x05:
 			/* Incorrect password */
@@ -1917,7 +1917,7 @@
 			purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, _("You have been connecting and disconnecting too frequently. Wait a minute and try again. If you continue to try, you will need to wait even longer."));
 			break;
 		default:
-			purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Authentication failed"));
+			purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Unknown reason"));
 			break;
 		}
 		purple_debug_info("oscar", "Login Error Code 0x%04hx\n", info->errorcode);
--- a/libpurple/protocols/yahoo/yahoo.c	Sat Jul 04 03:08:10 2009 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Sat Jul 04 05:17:11 2009 +0000
@@ -1681,7 +1681,7 @@
 #if GLIB_CHECK_VERSION(2,6,0)
 		totalelements = g_strv_length(split_data);
 #else
-		while (split_data[++totalelements] != NULL);	
+		while (split_data[++totalelements] != NULL);
 #endif
 		if (totalelements >= 4) {
 			response_no = strtol(split_data[0], NULL, 10);
@@ -1767,9 +1767,11 @@
 #if GLIB_CHECK_VERSION(2,6,0)
 		totalelements = g_strv_length(split_data);
 #else
-		while (split_data[++totalelements] != NULL);	
+		while (split_data[++totalelements] != NULL);
 #endif
-		if(totalelements >= 2) {
+		if(totalelements == 1)
+			response_no = strtol(split_data[0], NULL, 10);
+		else if(totalelements >= 2) {
 			response_no = strtol(split_data[0], NULL, 10);
 			token = g_strdup(split_data[1] + strlen("ymsgr="));
 		}
@@ -1789,6 +1791,9 @@
 					break;
 				case 1212:
 					/* Password incorrect */
+					/* Set password to NULL. Avoids account locking. Brings dialog to enter password if clicked on Re-enable account */
+					if (purple_account_get_remember_password(purple_connection_get_account(gc)))
+						purple_account_set_password(purple_connection_get_account(gc), NULL);
 					error_reason = g_strdup(_("Incorrect Password"));
 					error = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
 					break;
--- a/libpurple/util.c	Sat Jul 04 03:08:10 2009 +0000
+++ b/libpurple/util.c	Sat Jul 04 05:17:11 2009 +0000
@@ -2399,30 +2399,32 @@
 	return g_string_free(ret, FALSE);
 }
 
-char *
-purple_unescape_html(const char *html) {
-	if (html != NULL) {
-		const char *c = html;
-		GString *ret = g_string_new("");
-		while (*c) {
-			int len;
-			const char *ent;
-
-			if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
-				ret = g_string_append(ret, ent);
-				c += len;
-			} else if (!strncmp(c, "<br>", 4)) {
-				ret = g_string_append_c(ret, '\n');
-				c += 4;
-			} else {
-				ret = g_string_append_c(ret, *c);
-				c++;
-			}
+char *purple_unescape_html(const char *html)
+{
+	GString *ret;
+	const char *c = html;
+
+	if (html == NULL)
+		return NULL;
+
+	ret = g_string_new("");
+	while (*c) {
+		int len;
+		const char *ent;
+
+		if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
+			g_string_append(ret, ent);
+			c += len;
+		} else if (!strncmp(c, "<br>", 4)) {
+			g_string_append_c(ret, '\n');
+			c += 4;
+		} else {
+			g_string_append_c(ret, *c);
+			c++;
 		}
-		return g_string_free(ret, FALSE);
 	}
 
-	return NULL;
+	return g_string_free(ret, FALSE);
 }
 
 char *
@@ -3812,7 +3814,10 @@
 		}
 
 		/* Advance to the start of the data */
-		s = strstr(s, "\r\n") + 2;
+		s = strstr(s, "\r\n");
+		if (s == NULL)
+			break;
+		s += 2;
 
 		if (s + sz > data + *len) {
 			purple_debug_error("util", "Error processing chunked data: "
--- a/pidgin/gtkprefs.c	Sat Jul 04 03:08:10 2009 +0000
+++ b/pidgin/gtkprefs.c	Sat Jul 04 05:17:11 2009 +0000
@@ -28,6 +28,7 @@
 #include "pidgin.h"
 
 #include "debug.h"
+#include "nat-pmp.h"
 #include "notify.h"
 #include "prefs.h"
 #include "proxy.h"
@@ -36,7 +37,9 @@
 #include "savedstatuses.h"
 #include "sound.h"
 #include "sound-theme.h"
+#include "stun.h"
 #include "theme-manager.h"
+#include "upnp.h"
 #include "util.h"
 #include "network.h"
 
@@ -114,7 +117,7 @@
 
 	val = purple_prefs_get_int(key);
 
-	adjust = gtk_adjustment_new(val, min, max, 1, 1, 1);
+	adjust = gtk_adjustment_new(val, min, max, 1, 1, 0);
 	spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
 	g_object_set_data(G_OBJECT(spin), "val", (char *)key);
 	if (max < 10000)
@@ -1636,82 +1639,31 @@
 	return ret;
 }
 
-/* This isn't a very strict check, but should give the user a clue. */
-static gboolean
-verify_ip_address(const gchar *text)
-{
-	char *tmp;
-	long octet;
-
-	if (!text && !isdigit(*text))
-		return FALSE;
-
-	tmp = NULL;
-	octet = strtol(text, &tmp, 10);
-	if (octet < 0 || octet > 255)
-		return FALSE;
-
-	if (!tmp || *tmp != '.')
-		return FALSE;
-
-	text = tmp + 1;
-	if (!isdigit(*text))
-		return FALSE;
-
-	tmp = NULL;
-	octet = strtol(text, &tmp, 10);
-	if (octet < 0 || octet > 255)
-		return FALSE;
-
-	if (!tmp || *tmp != '.')
-		return FALSE;
-
-	text = tmp + 1;
-	if (!isdigit(*text))
-		return FALSE;
-
-	tmp = NULL;
-	octet = strtol(text, &tmp, 10);
-	if (octet < 0 || octet > 255)
-		return FALSE;
-
-	text = tmp + 1;
-	if (!isdigit(*text))
-		return FALSE;
-
-	tmp = NULL;
-	octet = strtol(text, &tmp, 10);
-	if (octet < 0 || octet > 255)
-		return FALSE;
-
-	if (!tmp || *tmp != '\0')
-		return FALSE;
-
-	return TRUE;
-}
-
 static void
 network_ip_changed(GtkEntry *entry, gpointer data)
 {
 	const gchar *text = gtk_entry_get_text(entry);
 	GdkColor color;
 
-	if (verify_ip_address(text))
-	{
-		color.red = 0xAFFF;
-		color.green = 0xFFFF;
-		color.blue = 0xAFFF;
-
-		purple_network_set_public_ip(text);
+	if (text && *text) {
+		if (purple_ip_address_is_valid(text)) {
+			color.red = 0xAFFF;
+			color.green = 0xFFFF;
+			color.blue = 0xAFFF;
+
+			purple_network_set_public_ip(text);
+		} else {
+			color.red = 0xFFFF;
+			color.green = 0xAFFF;
+			color.blue = 0xAFFF;
+		}
+
+		gtk_widget_modify_base(GTK_WIDGET(entry), GTK_STATE_NORMAL, &color);
+
+	} else {
+		purple_network_set_public_ip("");
+		gtk_widget_modify_base(GTK_WIDGET(entry), GTK_STATE_NORMAL, NULL);
 	}
-	else
-	{
-		color.red = 0xFFFF;
-		color.green = 0xAFFF;
-		color.blue = 0xAFFF;
-	}
-
-	gtk_widget_modify_base(GTK_WIDGET(entry), GTK_STATE_NORMAL, &color);
 }
 
 static gboolean
@@ -1798,6 +1750,9 @@
 	GtkWidget *proxy_button = NULL, *browser_button = NULL;
 	GtkSizeGroup *sg;
 	PurpleProxyInfo *proxy_info = NULL;
+	const char *ip;
+	PurpleStunNatDiscovery *stun;
+	char *auto_ip_text;
 
 	ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE);
 	gtk_container_set_border_width (GTK_CONTAINER (ret), PIDGIN_HIG_BORDER);
@@ -1828,8 +1783,30 @@
 	gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
 	gtk_container_add(GTK_CONTAINER(hbox), label);
 
-	auto_ip_checkbox = pidgin_prefs_checkbox(_("_Autodetect IP address"),
-			"/purple/network/auto_ip", vbox);
+	/* purple_network_get_my_ip will return the IP that was set by the user with
+	   purple_network_set_public_ip, so make a lookup for the auto-detected IP
+	   ourselves. */
+
+	/* Check if STUN discovery was already done */
+	stun = purple_stun_discover(NULL);
+	if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) {
+		ip = stun->publicip;
+	} else {
+		/* Attempt to get the IP from a NAT device using UPnP */
+		ip = purple_upnp_get_public_ip();
+		if (ip == NULL) {
+			/* Attempt to get the IP from a NAT device using NAT-PMP */
+			ip = purple_pmp_get_public_ip();
+			if (ip == NULL) {
+				/* Just fetch the IP of the local system */
+				ip = purple_network_get_local_system_ip(-1);
+			}
+		}
+	}
+
+	auto_ip_text = g_strdup_printf(_("Use _automatically detected IP address: %s"), ip);
+	auto_ip_checkbox = pidgin_prefs_checkbox(auto_ip_text, "/purple/network/auto_ip", vbox);
+	g_free(auto_ip_text);
 
 	table = gtk_table_new(2, 2, FALSE);
 	gtk_container_set_border_width(GTK_CONTAINER(table), 0);
@@ -1848,16 +1825,9 @@
 	g_signal_connect(G_OBJECT(entry), "changed",
 					 G_CALLBACK(network_ip_changed), NULL);
 
-	/*
-	 * TODO: This could be better by showing the autodeteced
-	 * IP separately from the user-specified IP.
-	 */
-	if (purple_network_get_my_ip(-1) != NULL)
-		gtk_entry_set_text(GTK_ENTRY(entry),
-		                   purple_network_get_my_ip(-1));
-
-	pidgin_set_accessible_label (entry, label);
-
+	gtk_entry_set_text(GTK_ENTRY(entry), purple_network_get_public_ip());
+
+	pidgin_set_accessible_label(entry, label);
 
 	if (purple_prefs_get_bool("/purple/network/auto_ip")) {
 		gtk_widget_set_sensitive(GTK_WIDGET(table), FALSE);