diff libpurple/protocols/jabber/jabber.c @ 20117:f24a2cacacd1

Use PurpleDisconnectReasons in prpl-jabber.
author Will Thompson <will.thompson@collabora.co.uk>
date Wed, 19 Sep 2007 15:03:59 +0000
parents ca7ab06673dd
children 57e9d1ecefff
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Wed Sep 19 15:01:47 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Wed Sep 19 15:03:59 2007 +0000
@@ -89,7 +89,8 @@
 		if(js->unregistration)
 			jabber_unregister_account_cb(js);
 	} else {
-		purple_connection_error(js->gc, _("Error initializing session"));
+		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
+			("Error initializing session"));
 	}
 }
 
@@ -120,7 +121,8 @@
 			JabberBuddy *my_jb = NULL;
 			jabber_id_free(js->user);
 			if(!(js->user = jabber_id_new(full_jid))) {
-				purple_connection_error(js->gc, _("Invalid response from server."));
+				purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
+					_("Invalid response from server."));
 			}
 			if((my_jb = jabber_buddy_find(js, full_jid, TRUE)))
 				my_jb->subscription |= JABBER_SUB_BOTH;
@@ -128,7 +130,7 @@
 		}
 	} else {
 		char *msg = jabber_parse_error(js, packet);
-		purple_connection_error(js->gc, msg);
+		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR, msg);
 		g_free(msg);
 	}
 
@@ -142,7 +144,8 @@
 			return;
 	} else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) {
 		js->gc->wants_to_die = TRUE;
-		purple_connection_error(js->gc, _("You require encryption, but it is not available on this server."));
+		purple_connection_error_reason (js->gc, PURPLE_REASON_ENCRYPTION_ERROR,
+			_("You require encryption, but it is not available on this server."));
 		return;
 	}
 
@@ -175,7 +178,10 @@
 {
 	char *msg = jabber_parse_error(js, packet);
 
-	purple_connection_error(js->gc, msg);
+	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);
 	g_free(msg);
 }
 
@@ -256,7 +262,8 @@
 	if (ret < 0 && errno == EAGAIN)
 		return;
 	else if (ret <= 0) {
-		purple_connection_error(js->gc, _("Write error"));
+		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
+			_("Write error"));
 		return;
 	}
 
@@ -309,7 +316,9 @@
 			}
 
 			if (ret < 0 && errno != EAGAIN)
-				purple_connection_error(js->gc, _("Write error"));
+				purple_connection_error_reason (js->gc,
+					PURPLE_REASON_NETWORK_ERROR,
+					_("Write error"));
 			else if (ret < olen) {
 				if (ret < 0)
 					ret = 0;
@@ -337,7 +346,9 @@
 	}
 
 	if (ret < 0 && errno != EAGAIN)
-		purple_connection_error(js->gc, _("Write error"));
+		purple_connection_error_reason (js->gc,
+			PURPLE_REASON_NETWORK_ERROR,
+			_("Write error"));
 	else if (ret < len) {
 		if (ret < 0)
 			ret = 0;
@@ -405,7 +416,9 @@
 	if(errno == EAGAIN)
 		return;
 	else
-		purple_connection_error(gc, _("Read Error"));
+		purple_connection_error_reason (js->gc,
+			PURPLE_REASON_NETWORK_ERROR,
+			_("Read Error"));
 }
 
 static void
@@ -442,7 +455,9 @@
 	} else if(errno == EAGAIN) {
 		return;
 	} else {
-		purple_connection_error(gc, _("Read Error"));
+		purple_connection_error_reason (js->gc,
+			PURPLE_REASON_NETWORK_ERROR,
+			_("Read Error"));
 	}
 }
 
@@ -481,7 +496,7 @@
 		gchar *tmp;
 		tmp = g_strdup_printf(_("Could not establish a connection with the server:\n%s"),
 				error);
-		purple_connection_error(gc, tmp);
+		purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR, tmp);
 		g_free(tmp);
 		return;
 	}
@@ -509,7 +524,7 @@
 	js = gc->proto_data;
 	js->gsc = NULL;
 
-	purple_connection_error(gc, purple_ssl_strerror(error));
+	purple_connection_ssl_error (gc, error);
 }
 
 static void tls_init(JabberStream *js)
@@ -526,7 +541,8 @@
 
 	if (purple_proxy_connect(js->gc, js->gc->account, host,
 			port, jabber_login_callback, js->gc) == NULL)
-		purple_connection_error(js->gc, _("Unable to create socket"));
+		purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
+			_("Unable to create socket"));
 }
 
 static void srv_resolved_cb(PurpleSrvResponse *resp, int results, gpointer data)
@@ -572,12 +588,14 @@
 	js->old_length = -1;
 
 	if(!js->user) {
-		purple_connection_error(gc, _("Invalid XMPP ID"));
+		purple_connection_error_reason (gc, PURPLE_REASON_INVALID_USERNAME,
+			_("Invalid XMPP ID"));
 		return;
 	}
 	
 	if (!js->user->domain || *(js->user->domain) == '\0') {
-		purple_connection_error(gc, _("Invalid XMPP ID. Domain must be set."));
+		purple_connection_error_reason (gc, PURPLE_REASON_INVALID_USERNAME,
+			_("Invalid XMPP ID. Domain must be set."));
 		return;
 	}
 	
@@ -607,7 +625,8 @@
 					purple_account_get_int(account, "port", 5223), jabber_login_callback_ssl,
 					jabber_ssl_connect_failure, js->gc);
 		} else {
-			purple_connection_error(js->gc, _("SSL support unavailable"));
+			purple_connection_error_reason (js->gc, PURPLE_REASON_ENCRYPTION_ERROR,
+				_("SSL support unavailable"));
 		}
 	}
 
@@ -1060,7 +1079,8 @@
 	js->old_length = -1;
 
 	if(!js->user) {
-		purple_connection_error(gc, _("Invalid XMPP ID"));
+		purple_connection_error_reason (gc, PURPLE_REASON_INVALID_USERNAME,
+			_("Invalid XMPP ID"));
 		return;
 	}
 
@@ -1092,7 +1112,8 @@
 					purple_account_get_int(account, "port", 5222),
 					jabber_login_callback_ssl, jabber_ssl_connect_failure, gc);
 		} else {
-			purple_connection_error(gc, _("SSL support unavailable"));
+			purple_connection_error_reason (gc, PURPLE_REASON_ENCRYPTION_ERROR,
+				_("SSL support unavailable"));
 		}
 	}