changeset 24522:692c34bf98d8

Handle the InvalidPassportUser response when adding buddies and report it to the user. The buddy is also dropped from the userlist to avoid sync errors at next login. Also handle InvalidPassportUser and EmailDomainIsFederated in the "add contact to group" response (in addition to plain "add contact").
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 08 Dec 2008 00:14:46 +0000
parents e63483708bd7
children 77873bca18bb
files libpurple/protocols/msn/contact.c
diffstat 1 files changed, 50 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Sun Dec 07 08:18:15 2008 +0000
+++ b/libpurple/protocols/msn/contact.c	Mon Dec 08 00:14:46 2008 +0000
@@ -948,29 +948,38 @@
 
 	xmlnode *fault;
 
+	g_return_if_fail(session != NULL);
+	userlist = session->userlist;
+
 	fault = xmlnode_get_child(resp->xml, "Body/Fault");
 	if (fault != NULL) {
 		char *errorcode = xmlnode_get_data(xmlnode_get_child(fault, "detail/errorcode"));
-		char *fault_str;
 		if (errorcode && !strcmp(errorcode, "EmailDomainIsFederated")) {
 			/* Do something special! */
 			purple_debug_error("msn", "Contact is from a federated domain, but don't know what to do yet!\n");
-		}
+
+		} else if (errorcode && !strcmp(errorcode, "InvalidPassportUser")) {
+			PurpleBuddy *buddy = purple_find_buddy(session->account, state->who);
+			char *str = g_strdup_printf(_("Unable to add \"%s\"."), state->who);
+			purple_notify_error(state->session, _("Buddy Add error"), str,
+			                    _("The username specified does not exist."));
+			g_free(str);
+			msn_userlist_rem_buddy(userlist, state->who);
+			if (buddy != NULL)
+				purple_blist_remove_buddy(buddy);
 
-		/* We don't know how to respond to this faultcode, so log it */
-		fault_str = xmlnode_to_str(fault, NULL);
-		if (fault_str != NULL) {
-			purple_debug_error("msn", "Operation {%s} Failed, SOAP Fault was: %s\n",
-			                   msn_contact_operation_str(state->action), fault_str);
-			g_free(fault_str);
-			return;
+		} else {
+			/* We don't know how to respond to this faultcode, so log it */
+			char *fault_str = xmlnode_to_str(fault, NULL);
+			if (fault_str != NULL) {
+				purple_debug_error("msn", "Operation {%s} Failed, SOAP Fault was: %s\n",
+				                   msn_contact_operation_str(state->action), fault_str);
+				g_free(fault_str);
+			}
 		}
+		return;
 	}
 
-	g_return_if_fail(session != NULL);
-
-	userlist = session->userlist;
-
 	purple_debug_info("msn", "Contact added successfully\n");
 
 	/* the code this block is replacing didn't send ADL for yahoo contacts,
@@ -1033,21 +1042,42 @@
 	gpointer data)
 {
 	MsnCallbackState *state = data;
+	MsnSession *session = state->session;
 	MsnUserList *userlist;
 	xmlnode *fault;
 
-	/* We don't know how to respond to this faultcode, so log it */
+	g_return_if_fail(session != NULL);
+	userlist = session->userlist;
+
 	fault = xmlnode_get_child(resp->xml, "Body/Fault");
 	if (fault != NULL) {
-		char *fault_str = xmlnode_to_str(fault, NULL);
-		purple_debug_error("msn", "Operation {%s} Failed, SOAP Fault was: %s\n",
-		                   msn_contact_operation_str(state->action), fault_str);
-		g_free(fault_str);
+		char *errorcode = xmlnode_get_data(xmlnode_get_child(fault, "detail/errorcode"));
+		if (errorcode && !strcmp(errorcode, "EmailDomainIsFederated")) {
+			/* Do something special! */
+			purple_debug_error("msn", "Contact is from a federated domain, but don't know what to do yet!\n");
+
+		} else if (errorcode && !strcmp(errorcode, "InvalidPassportUser")) {
+			PurpleBuddy *buddy = purple_find_buddy(session->account, state->who);
+			char *str = g_strdup_printf(_("Unable to add \"%s\"."), state->who);
+			purple_notify_error(session, _("Buddy Add error"), str,
+			                    _("The username specified does not exist."));
+			g_free(str);
+			msn_userlist_rem_buddy(userlist, state->who);
+			if (buddy != NULL)
+				purple_blist_remove_buddy(buddy);
+
+		} else {
+			/* We don't know how to respond to this faultcode, so log it */
+			char *fault_str = xmlnode_to_str(fault, NULL);
+			if (fault_str != NULL) {
+				purple_debug_error("msn", "Operation {%s} Failed, SOAP Fault was: %s\n",
+				                   msn_contact_operation_str(state->action), fault_str);
+				g_free(fault_str);
+			}
+		}
 		return;
 	}
 
-	userlist = state->session->userlist;
-
 	if (msn_userlist_add_buddy_to_group(userlist, state->who,
 			state->new_group_name)) {
 		purple_debug_info("msn", "Contact %s added to group %s successfully!\n", state->who, state->new_group_name);