im.pidgin.cpw.resiak.disconnectreason: f1958c10b582e5770433cb10ebd82f4a8938c59c

resiak at soc.pidgin.im resiak at soc.pidgin.im
Sat Nov 3 07:13:25 EDT 2007


-----------------------------------------------------------------
Revision: f1958c10b582e5770433cb10ebd82f4a8938c59c
Ancestor: 748134ee3d2f37c378ea8c48921f62a55b9089fd
Author: resiak at soc.pidgin.im
Date: 2007-11-03T00:23:01
Branch: im.pidgin.cpw.resiak.disconnectreason

Modified files:
        libpurple/account.c

ChangeLog: 

Save accounts' current errors to accounts.xml, and restore them at startup.

-------------- next part --------------
============================================================
--- libpurple/account.c	2293762939a2fdde5be8e59379b68bc8f3d2c2d4
+++ libpurple/account.c	cf4ce0a31f97b3add206a100676e73c4edba7a9f
@@ -85,6 +85,9 @@ static GList *handles = NULL;
 
 static GList *handles = NULL;
 
+static void set_current_error(PurpleAccount *account,
+	PurpleConnectionErrorInfo *new_err);
+
 /*********************************************************************
  * Writing to disk                                                   *
  *********************************************************************/
@@ -318,8 +321,32 @@ static xmlnode *
 }
 
 static xmlnode *
+current_error_to_xmlnode(PurpleConnectionErrorInfo *err)
+{
+	xmlnode *node, *child;
+	char type_str[3];
+
+	node = xmlnode_new("current_error");
+
+	if(err == NULL)
+		return node;
+
+	child = xmlnode_new_child(node, "type");
+	snprintf(type_str, sizeof(type_str), "%u", err->type);
+	xmlnode_insert_data(child, type_str, -1);
+
+	child = xmlnode_new_child(node, "description");
+	if(err->description)
+		xmlnode_insert_data(child, err->description, -1);
+
+	return node;
+}
+
+static xmlnode *
 account_to_xmlnode(PurpleAccount *account)
 {
+	PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
 	xmlnode *node, *child;
 	const char *tmp;
 	PurplePresence *presence;
@@ -376,6 +403,9 @@ account_to_xmlnode(PurpleAccount *accoun
 		xmlnode_insert_child(node, child);
 	}
 
+	child = current_error_to_xmlnode(priv->current_error);
+	xmlnode_insert_child(node, child);
+
 	return node;
 }
 
@@ -680,6 +710,42 @@ parse_proxy_info(xmlnode *node, PurpleAc
 	purple_account_set_proxy_info(account, proxy_info);
 }
 
+static void
+parse_current_error(xmlnode *node, PurpleAccount *account)
+{
+	guint type;
+	char *type_str = NULL, *description = NULL;
+	xmlnode *child;
+	PurpleConnectionErrorInfo *current_error = NULL;
+
+	child = xmlnode_get_child(node, "type");
+	if (child == NULL || (type_str = xmlnode_get_data(child)) == NULL)
+		return;
+	type = atoi(type_str);
+	g_free(type_str);
+
+	if (type > PURPLE_CONNECTION_ERROR_OTHER_ERROR)
+	{
+		purple_debug_error("account",
+			"Invalid PurpleConnectionError value %d found when "
+			"loading account information for %s\n",
+			type, purple_account_get_username(account));
+		type = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
+	}
+
+	child = xmlnode_get_child(node, "description");
+	if (child)
+		description = xmlnode_get_data(child);
+	if (description == NULL)
+		description = g_strdup("");
+
+	current_error = g_new0(PurpleConnectionErrorInfo, 1);
+	current_error->type = type;
+	current_error->description = description;
+
+	set_current_error(account, current_error);
+}
+
 static PurpleAccount *
 parse_account(xmlnode *node)
 {
@@ -789,6 +855,13 @@ parse_account(xmlnode *node)
 		parse_proxy_info(child, ret);
 	}
 
+	/* Read current error */
+	child = xmlnode_get_child(node, "current_error");
+	if (child != NULL)
+	{
+		parse_current_error(child, ret);
+	}
+
 	return ret;
 }
 
@@ -2253,6 +2326,7 @@ set_current_error(PurpleAccount *account
 	purple_signal_emit(purple_accounts_get_handle(),
 	                   "account-error-changed",
 	                   account, old_err, new_err);
+	schedule_accounts_save();
 
 	if(old_err)
 		g_free(old_err->description);


More information about the Commits mailing list