im.pidgin.cpw.resiak.disconnectreason: 267c137f0b2ae0c530298f1b8b4c42467776db8b

resiak at soc.pidgin.im resiak at soc.pidgin.im
Tue Oct 9 09:45:41 EDT 2007


-----------------------------------------------------------------
Revision: 267c137f0b2ae0c530298f1b8b4c42467776db8b
Ancestor: d6c432d04466e50bb075c5c814cf85150f31a1fb
Author: resiak at soc.pidgin.im
Date: 2007-10-09T13:32:58
Branch: im.pidgin.cpw.resiak.disconnectreason

Modified files:
        libpurple/protocols/jabber/adhoccommands.c
        libpurple/protocols/jabber/auth.c
        libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/chat.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h
        libpurple/protocols/jabber/presence.c

ChangeLog: 

Stop jabber setting wants_to_die itself.  This involved plumbing disconnection
reasons into jabber_parse_error in a slightly dubious fashion.  I'd appreciate
someone sanity-checking this rev.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/adhoccommands.c	1f8c9a282612f146d5e43e994629da3817e88f48
+++ libpurple/protocols/jabber/adhoccommands.c	128cf2932cf155961f2cc1991f999dc1cb97206c
@@ -132,7 +132,7 @@ static void jabber_adhoc_parse(JabberStr
 	const char *type = xmlnode_get_attrib(packet,"type");
 	
 	if(type && !strcmp(type,"error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 		if(!msg)
 			msg = g_strdup(_("Unknown Error"));
 		
============================================================
--- libpurple/protocols/jabber/auth.c	d9edb0dcf9ad22d11ff96a2e5eb46c79bf891589
+++ libpurple/protocols/jabber/auth.c	538bd21583d778e0f680b1389d61c838df366c2e
@@ -541,15 +541,15 @@ static void auth_old_result_cb(JabberStr
 	if(type && !strcmp(type, "result")) {
 		jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
 	} else {
-		char *msg = jabber_parse_error(js, packet);
+		PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
+		char *msg = jabber_parse_error(js, packet, &reason);
 		xmlnode *error;
 		const char *err_code;
-		PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
 
+		/* FIXME: Why is this not in jabber_parse_error? */
 		if((error = xmlnode_get_child(packet, "error")) &&
 					(err_code = xmlnode_get_attrib(error, "code")) &&
 					!strcmp(err_code, "401")) {
-			js->gc->wants_to_die = TRUE;
 			reason = PURPLE_REASON_AUTHENTICATION_FAILED;
 			/* Clear the pasword if it isn't being saved */
 			if (!purple_account_get_remember_password(js->gc->account))
@@ -573,9 +573,9 @@ static void auth_old_cb(JabberStream *js
 			_("Invalid response from server."));
 		return;
 	} else if(!strcmp(type, "error")) {
-		char *msg = jabber_parse_error(js, packet);
-		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
-			msg);
+		PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
+		char *msg = jabber_parse_error(js, packet, &reason);
+		purple_connection_error_reason (js->gc, reason, msg);
 		g_free(msg);
 	} else if(!strcmp(type, "result")) {
 		query = xmlnode_get_child(packet, "query");
@@ -975,14 +975,14 @@ void jabber_auth_handle_failure(JabberSt
 
 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet)
 {
-	char *msg = jabber_parse_error(js, packet);
+	PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
+	char *msg = jabber_parse_error(js, packet, &reason);
 
 	if(!msg) {
 		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
 			_("Invalid response from server."));
 	} else {
-		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
-			msg);
+		purple_connection_error_reason (js->gc, reason, msg);
 		g_free(msg);
 	}
 }
============================================================
--- libpurple/protocols/jabber/buddy.c	2fc3477286700662cf6dc00ccab7d4381e59ca9c
+++ libpurple/protocols/jabber/buddy.c	9b7eb35f320e16cb09e6cd5287df691f8162a3bf
@@ -2334,7 +2334,7 @@ static void user_search_fields_result_cb
 		return;
 
 	if(!(type = xmlnode_get_attrib(packet, "type")) || !strcmp(type, "error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		if(!msg)
 			msg = g_strdup(_("Unknown error"));
============================================================
--- libpurple/protocols/jabber/chat.c	3ea3b18d924a1ede80610670e47ba7ee92d53bce
+++ libpurple/protocols/jabber/chat.c	504bad9aa5c62055a83357246c1cd872cbe7ca1b
@@ -391,7 +391,7 @@ static void jabber_chat_room_configure_c
 			}
 		}
 	} else if(!strcmp(type, "error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		purple_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg);
 
@@ -465,7 +465,7 @@ static void jabber_chat_register_x_data_
 	const char *type = xmlnode_get_attrib(packet, "type");
 
 	if(type && !strcmp(type, "error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
 
@@ -534,7 +534,7 @@ static void jabber_chat_register_cb(Jabb
 			}
 		}
 	} else if(!strcmp(type, "error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
 
@@ -673,7 +673,7 @@ static void roomlist_disco_result_cb(Jab
 		return;
 
 	if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) {
-		char *err = jabber_parse_error(js,packet);
+		char *err = jabber_parse_error(js, packet, NULL);
 		purple_notify_error(js->gc, _("Error"),
 				_("Error retrieving room list"), err);
 		purple_roomlist_set_in_progress(js->roomlist, FALSE);
@@ -684,7 +684,7 @@ static void roomlist_disco_result_cb(Jab
 	}
 
 	if(!(query = xmlnode_get_child(packet, "query"))) {
-		char *err = jabber_parse_error(js, packet);
+		char *err = jabber_parse_error(js, packet, NULL);
 		purple_notify_error(js->gc, _("Error"),
 				_("Error retrieving room list"), err);
 		purple_roomlist_set_in_progress(js->roomlist, FALSE);
============================================================
--- libpurple/protocols/jabber/jabber.c	90f5e32e69693709fabba9f3aaf905e5c20456d3
+++ libpurple/protocols/jabber/jabber.c	6daeab406824ec662e7ab48ee80e61eb37e163ed
@@ -129,8 +129,9 @@ static void jabber_bind_result_cb(Jabber
 			g_free(full_jid);
 		}
 	} else {
-		char *msg = jabber_parse_error(js, packet);
-		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR, msg);
+		PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
+		char *msg = jabber_parse_error(js, packet, &reason);
+		purple_connection_error_reason (js->gc, reason, msg);
 		g_free(msg);
 	}
 
@@ -176,12 +177,11 @@ static void jabber_stream_handle_error(J
 
 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet)
 {
-	char *msg = jabber_parse_error(js, packet);
+	PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
+	char *msg = jabber_parse_error(js, packet, &reason);
 
-	if (js->gc->wants_to_die)
-		purple_connection_error_reason (js->gc, PURPLE_REASON_OTHER_ERROR, msg);
-	else
-		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR, msg);
+	purple_connection_error_reason (js->gc, reason, msg);
+
 	g_free(msg);
 }
 
@@ -687,7 +687,7 @@ jabber_registration_result_cb(JabberStre
 				_("Registration Successful"), buf);
 		g_free(buf);
 	} else {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		if(!msg)
 			msg = g_strdup(_("Unknown Error"));
@@ -717,7 +717,7 @@ jabber_unregistration_result_cb(JabberSt
 						   _("Unregistration Successful"), buf);
 		g_free(buf);
 	} else {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 		
 		if(!msg)
 			msg = g_strdup(_("Unknown Error"));
@@ -1141,7 +1141,7 @@ static void jabber_unregister_account_iq
 	PurpleAccount *account = purple_connection_get_account(js->gc);
 	const char *type = xmlnode_get_attrib(packet,"type");
 	if(!strcmp(type,"error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 		
 		purple_notify_error(js->gc, _("Error unregistering account"),
 							_("Error unregistering account"), msg);
@@ -1691,7 +1691,7 @@ jabber_password_change_result_cb(JabberS
 		purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
 				_("Your password has been changed."));
 	} else {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		purple_notify_error(js->gc, _("Error changing password"),
 				_("Error changing password"), msg);
@@ -1855,13 +1855,18 @@ void jabber_convo_closed(PurpleConnectio
 }
 
 
-char *jabber_parse_error(JabberStream *js, xmlnode *packet)
+char *jabber_parse_error(JabberStream *js,
+                         xmlnode *packet,
+                         PurpleDisconnectReason *reason)
 {
 	xmlnode *error;
 	const char *code = NULL, *text = NULL;
 	const char *xmlns = xmlnode_get_namespace(packet);
 	char *cdata = NULL;
 
+#define SET_REASON(x) \
+	if(reason != NULL) { *reason = x; }
+
 	if((error = xmlnode_get_child(packet, "error"))) {
 		cdata = xmlnode_get_data(error);
 		code = xmlnode_get_attrib(error, "code");
@@ -1913,41 +1918,41 @@ char *jabber_parse_error(JabberStream *j
 			text = _("Unknown Error");
 		}
 	} else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
+		/* Most common reason can be the default */
+		SET_REASON(PURPLE_REASON_AUTHENTICATION_FAILED);
 		if(xmlnode_get_child(packet, "aborted")) {
-			js->gc->wants_to_die = TRUE;
 			text = _("Authorization Aborted");
 		} else if(xmlnode_get_child(packet, "incorrect-encoding")) {
+			SET_REASON(PURPLE_REASON_NETWORK_ERROR);
 			text = _("Incorrect encoding in authorization");
 		} else if(xmlnode_get_child(packet, "invalid-authzid")) {
-			js->gc->wants_to_die = TRUE;
 			text = _("Invalid authzid");
 		} else if(xmlnode_get_child(packet, "invalid-mechanism")) {
-			js->gc->wants_to_die = TRUE;
 			text = _("Invalid Authorization Mechanism");
 		} else if(xmlnode_get_child(packet, "mechanism-too-weak")) {
-			js->gc->wants_to_die = TRUE;
 			text = _("Authorization mechanism too weak");
 		} else if(xmlnode_get_child(packet, "not-authorized")) {
-			js->gc->wants_to_die = TRUE;
 			/* Clear the pasword if it isn't being saved */
 			if (!purple_account_get_remember_password(js->gc->account))
 				purple_account_set_password(js->gc->account, NULL);
 			text = _("Not Authorized");
 		} else if(xmlnode_get_child(packet, "temporary-auth-failure")) {
+			SET_REASON(PURPLE_REASON_NETWORK_ERROR);
 			text = _("Temporary Authentication Failure");
 		} else {
-			js->gc->wants_to_die = TRUE;
 			text = _("Authentication Failure");
 		}
 	} else if(!strcmp(packet->name, "stream:error") ||
 			 (!strcmp(packet->name, "error") &&
 				!strcmp(xmlns, "http://etherx.jabber.org/streams"))) {
+		/* Most common reason as default: */
+		SET_REASON(PURPLE_REASON_NETWORK_ERROR);
 		if(xmlnode_get_child(packet, "bad-format")) {
 			text = _("Bad Format");
 		} else if(xmlnode_get_child(packet, "bad-namespace-prefix")) {
 			text = _("Bad Namespace Prefix");
 		} else if(xmlnode_get_child(packet, "conflict")) {
-			js->gc->wants_to_die = TRUE;
+			SET_REASON(PURPLE_REASON_NAME_IN_USE);
 			text = _("Resource Conflict");
 		} else if(xmlnode_get_child(packet, "connection-timeout")) {
 			text = _("Connection Timeout");
@@ -1996,6 +2001,8 @@ char *jabber_parse_error(JabberStream *j
 		}
 	}
 
+#undef SET_REASON
+
 	if(text || cdata) {
 		char *ret = g_strdup_printf("%s%s%s", code ? code : "",
 				code ? ": " : "", text ? text : cdata);
============================================================
--- libpurple/protocols/jabber/jabber.h	09f1d54e927d0c2d48c4d16c5500db62db4747ea
+++ libpurple/protocols/jabber/jabber.h	0c11fce95d3d2b99cffbed75beed40caf746f3a8
@@ -216,7 +216,14 @@ char *jabber_get_next_id(JabberStream *j
 
 char *jabber_get_next_id(JabberStream *js);
 
-char *jabber_parse_error(JabberStream *js, xmlnode *packet);
+/** Parse an error into a human-readable string and optionally a disconnect
+ *  reason.
+ *  @param js     the stream on which the error occurred.
+ *  @param packet the error packet
+ *  @param reason where to store the disconnection reason, or @c NULL if you
+ *                don't care or you don't intend to close the connection.
+ */
+char *jabber_parse_error(JabberStream *js, xmlnode *packet, PurpleDisconnectReason *reason);
 
 void jabber_add_feature(const gchar *shortname, const gchar *namespace, JabberFeatureEnabled cb); /* cb may be NULL */
 void jabber_remove_feature(const gchar *shortname);
============================================================
--- libpurple/protocols/jabber/presence.c	0ef2f63adee86173f85649a3f9fb573cdec663e6
+++ libpurple/protocols/jabber/presence.c	69b43551b3f0616f11e3cd5a26538648f0d0b9da
@@ -417,7 +417,7 @@ void jabber_presence_parse(JabberStream 
 	}
 
 	if(type && !strcmp(type, "error")) {
-		char *msg = jabber_parse_error(js, packet);
+		char *msg = jabber_parse_error(js, packet, NULL);
 
 		state = JABBER_BUDDY_STATE_ERROR;
 		jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence"));
@@ -549,7 +549,7 @@ void jabber_presence_parse(JabberStream 
 		char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
 
 		if(state == JABBER_BUDDY_STATE_ERROR) {
-			char *title, *msg = jabber_parse_error(js, packet);
+			char *title, *msg = jabber_parse_error(js, packet, NULL);
 
 			if(chat->conv) {
 				title = g_strdup_printf(_("Error in chat %s"), from);


More information about the Commits mailing list