changeset 31205:b39a2bd81566

Small changes to how we format oscar screen names. We now 1. Don't attempt to format a screen name 2. Unless it's @aim.com (or possibly other AOL-owned domains), in which case we strip off the domain and format the basename only Hopefully fixes #13043, fixes #12376, fixes #11740
author Mark Doliner <mark@kingant.net>
date Mon, 14 Feb 2011 03:51:05 +0000
parents f1874b08b3f9
children 38ba52f4bb96 64587c6084e3
files libpurple/protocols/oscar/oscar.c libpurple/protocols/oscar/oscarcommon.h
diffstat 2 files changed, 48 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/oscar.c	Mon Feb 14 03:10:09 2011 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Mon Feb 14 03:51:05 2011 +0000
@@ -2828,6 +2828,52 @@
 	return 1;
 }
 
+static void oscar_format_username(PurpleConnection *gc, const char *new_display_name)
+{
+	OscarData *od;
+	const char *old_display_name, *username;
+	char *tmp, *at_sign;
+
+	old_display_name = purple_connection_get_display_name(gc);
+	if (old_display_name && strchr(old_display_name, '@')) {
+		purple_debug_info("oscar", "Cowardly refusing to attempt to format "
+				"screen name because the current formatting according to "
+				"the server (%s) appears to be an email address\n",
+				old_display_name);
+		return;
+	}
+
+	username = purple_account_get_username(purple_connection_get_account(gc));
+	if (oscar_util_name_compare(username, new_display_name)) {
+		purple_notify_error(gc, NULL, _("The new formatting is invalid."),
+						  _("Username formatting can change only capitalization and whitespace."));
+		return;
+	}
+
+	tmp = g_strdup(new_display_name);
+
+	/*
+	 * If our local username is an email address then strip off the domain.
+	 * This allows formatting to work if the user entered their username as
+	 * 'something@aim.com' or possibly other AOL-owned domains.
+	 */
+	at_sign = strchr(tmp, '@');
+	if (at_sign)
+		at_sign[0] = '\0';
+
+	od = purple_connection_get_protocol_data(gc);
+	if (!flap_connection_getbytype(od, SNAC_FAMILY_ADMIN)) {
+		/* We don't have a connection to an "admin" server.  Make one. */
+		od->setnick = TRUE;
+		g_free(od->newformatting);
+		od->newformatting = tmp;
+		aim_srv_requestnew(od, SNAC_FAMILY_ADMIN);
+	} else {
+		aim_admin_setnick(od, flap_connection_getbytype(od, SNAC_FAMILY_ADMIN), tmp);
+		g_free(tmp);
+	}
+}
+
 static int purple_bosrights(OscarData *od, FlapConnection *conn, FlapFrame *fr, ...) {
 	PurpleConnection *gc;
 	PurpleAccount *account;
@@ -2860,12 +2906,13 @@
 		serv_set_info(gc, purple_account_get_user_info(account));
 
 	username = purple_account_get_username(account);
-	if (!od->icq && strcmp(username, purple_connection_get_display_name(gc)) != 0)
+	if (!od->icq && strcmp(username, purple_connection_get_display_name(gc)) != 0) {
 		/*
 		 * Format the username for AIM accounts if it's different
 		 * than what's currently set.
 		 */
 		oscar_format_username(gc, username);
+	}
 
 	/* Set our available message based on the current status */
 	status = purple_account_get_active_status(account);
@@ -5196,23 +5243,6 @@
 						gc);
 }
 
-void oscar_format_username(PurpleConnection *gc, const char *nick) {
-	OscarData *od = purple_connection_get_protocol_data(gc);
-	if (!oscar_util_name_compare(purple_account_get_username(purple_connection_get_account(gc)), nick)) {
-		if (!flap_connection_getbytype(od, SNAC_FAMILY_ADMIN)) {
-			od->setnick = TRUE;
-			g_free(od->newformatting);
-			od->newformatting = g_strdup(nick);
-			aim_srv_requestnew(od, SNAC_FAMILY_ADMIN);
-		} else {
-			aim_admin_setnick(od, flap_connection_getbytype(od, SNAC_FAMILY_ADMIN), nick);
-		}
-	} else {
-		purple_notify_error(gc, NULL, _("The new formatting is invalid."),
-						  _("Username formatting can change only capitalization and whitespace."));
-	}
-}
-
 static void oscar_confirm_account(PurplePluginAction *action)
 {
 	PurpleConnection *gc;
--- a/libpurple/protocols/oscar/oscarcommon.h	Mon Feb 14 03:10:09 2011 +0000
+++ b/libpurple/protocols/oscar/oscarcommon.h	Mon Feb 14 03:51:05 2011 +0000
@@ -102,6 +102,5 @@
 void oscar_send_file(PurpleConnection *gc, const char *who, const char *file);
 PurpleXfer *oscar_new_xfer(PurpleConnection *gc, const char *who);
 gboolean oscar_offline_message(const PurpleBuddy *buddy);
-void oscar_format_username(PurpleConnection *gc, const char *nick);
 GList *oscar_actions(PurplePlugin *plugin, gpointer context);
 void oscar_init(PurplePlugin *plugin, gboolean is_icq);