diff libpurple/account.c @ 27402:87586d7bdbbd

Migrate Yahoo! JAPAN accounts to the new prpl (in theory). This also adds new API, purple_account_remove_setting. I'm amazed no one had wanted this yet.
author John Bailey <rekkanoryo@rekkanoryo.org>
date Mon, 06 Jul 2009 05:48:30 +0000
parents 627d23bfdb05
children 76a13febd641
line wrap: on
line diff
--- a/libpurple/account.c	Mon Jul 06 00:16:00 2009 +0000
+++ b/libpurple/account.c	Mon Jul 06 05:48:30 2009 +0000
@@ -481,6 +481,35 @@
 /*********************************************************************
  * Reading from disk                                                 *
  *********************************************************************/
+static void
+migrate_yahoo_japan(PurpleAccount *account)
+{
+	/* detect a Yahoo! JAPAN account that existed prior to 2.6.0 and convert it
+	 * to use the new prpl-yahoojp.  Also remove the account-specific settings
+	 * we no longer need */
+
+	if(purple_strequal(purple_account_get_protocol_id(account), "prpl-yahoo")) {
+		if(purple_account_get_bool(account, "yahoojp", FALSE)) {
+			const char *serverjp = purple_account_get_string(account, "serverjp", NULL);
+			const char *xferjp_host = purple_account_get_string(account, "xferjp_host", NULL);
+
+			g_return_if_fail(serverjp != NULL);
+			g_return_if_fail(xferjp_host != NULL);
+
+			purple_account_set_string(account, "server", serverjp);
+			purple_account_set_string(account, "xfer_host", xferjp_host);
+
+			purple_account_set_protocol_id(account, "prpl-yahoojp");
+		}
+
+		/* these should always be nuked */
+		purple_account_remove_setting(account, "serverjp");
+		purple_account_remove_setting(account, "xferjp_host");
+
+	}
+
+	return;
+}
 
 static void
 parse_settings(xmlnode *node, PurpleAccount *account)
@@ -545,6 +574,10 @@
 
 		g_free(data);
 	}
+
+	/* we do this here because we need access to account settings to determine
+	 * if we can/should migrate an old Yahoo! JAPAN account */
+	migrate_yahoo_japan(account);
 }
 
 static GList *
@@ -1725,6 +1758,15 @@
 }
 
 void
+purple_account_remove_setting(PurpleAccount *account, const char *setting)
+{
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(setting != NULL);
+
+	g_hash_table_remove(account->settings, setting);
+}
+
+void
 purple_account_set_int(PurpleAccount *account, const char *name, int value)
 {
 	PurpleAccountSetting *setting;