more details connection error messages

This commit is contained in:
Daniel Gultsch 2014-03-06 15:11:56 +01:00
parent a73cc24c3f
commit 4edd623a1e
4 changed files with 42 additions and 28 deletions

View file

@ -13,8 +13,6 @@ import eu.siacs.conversations.xmpp.XmppConnection;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.JsonReader;
import android.util.Log;
public class Account extends AbstractEntity{
@ -41,6 +39,8 @@ public class Account extends AbstractEntity{
public static final int STATUS_TLS_ERROR = 4;
public static final int STATUS_SERVER_NOT_FOUND = 5;
public static final int STATUS_SERVER_REQUIRES_TLS = 6;
protected String username;
protected String server;
protected String password;

View file

@ -819,8 +819,12 @@ public class XmppConnectionService extends Service {
disconnect(account);
}
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
if (account.getXmppConnection()==null) {
account.setXmppConnection(this.createConnection(account));
}
Thread thread = new Thread(account.getXmppConnection());
thread.start();
}
if (accountChangedListener != null)
accountChangedListener.onAccountListChangedListener();
}

View file

@ -110,6 +110,10 @@ public class ManageAccountActivity extends XmppActivity {
statusView.setText("no internet");
statusView.setTextColor(0xFFe92727);
break;
case Account.STATUS_SERVER_REQUIRES_TLS:
statusView.setText("server requires TLS");
statusView.setTextColor(0xFFe92727);
break;
default:
break;
}

View file

@ -7,6 +7,7 @@ import java.math.BigInteger;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.security.cert.CertPathValidatorException;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
@ -75,6 +76,7 @@ public class XmppConnection implements Runnable {
}
protected void connect() {
Log.d(LOGTAG, "connecting");
try {
this.changeStatus(Account.STATUS_CONNECTING);
Bundle namePort = DNSHelper.getSRVRecord(account.getServer());
@ -143,6 +145,11 @@ public class XmppConnection implements Runnable {
processStreamError(nextTag);
} else if (nextTag.isStart("features")) {
processStreamFeatures(nextTag);
if ((streamFeatures.getChildren().size() == 1)
&& (streamFeatures.hasChild("starttls"))
&& (!account.isOptionSet(Account.OPTION_USETLS))) {
changeStatus(Account.STATUS_SERVER_REQUIRES_TLS);
}
} else if (nextTag.isStart("proceed")) {
switchOverToTls(nextTag);
} else if (nextTag.isStart("success")) {
@ -156,12 +163,7 @@ public class XmppConnection implements Runnable {
break;
} else if (nextTag.isStart("failure")) {
Element failure = tagReader.readElement(nextTag);
Log.d(LOGTAG, "read failure element" + failure.toString());
account.setStatus(Account.STATUS_UNAUTHORIZED);
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
tagWriter.writeTag(Tag.end("stream"));
changeStatus(Account.STATUS_UNAUTHORIZED);
} else if (nextTag.isStart("iq")) {
processIq(nextTag);
} else if (nextTag.isStart("message")) {
@ -215,8 +217,8 @@ public class XmppConnection implements Runnable {
IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
if (packetCallbacks.containsKey(packet.getId())) {
if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
((OnIqPacketReceived) packetCallbacks.get(packet.getId())).onIqPacketReceived(account,
packet);
((OnIqPacketReceived) packetCallbacks.get(packet.getId()))
.onIqPacketReceived(account, packet);
}
packetCallbacks.remove(packet.getId());
@ -230,10 +232,10 @@ public class XmppConnection implements Runnable {
MessagePacket packet = (MessagePacket) processPacket(currentTag,
PACKET_MESSAGE);
String id = packet.getAttribute("id");
if ((id!=null)&&(packetCallbacks.containsKey(id))) {
if ((id != null) && (packetCallbacks.containsKey(id))) {
if (packetCallbacks.get(id) instanceof OnMessagePacketReceived) {
((OnMessagePacketReceived) packetCallbacks.get(id)).onMessagePacketReceived(account,
packet);
((OnMessagePacketReceived) packetCallbacks.get(id))
.onMessagePacketReceived(account, packet);
}
packetCallbacks.remove(id);
} else if (this.messageListener != null) {
@ -246,10 +248,10 @@ public class XmppConnection implements Runnable {
PresencePacket packet = (PresencePacket) processPacket(currentTag,
PACKET_PRESENCE);
String id = packet.getAttribute("id");
if ((id!=null)&&(packetCallbacks.containsKey(id))) {
if ((id != null) && (packetCallbacks.containsKey(id))) {
if (packetCallbacks.get(id) instanceof OnPresencePacketReceived) {
((OnPresencePacketReceived) packetCallbacks.get(id)).onPresencePacketReceived(account,
packet);
((OnPresencePacketReceived) packetCallbacks.get(id))
.onPresencePacketReceived(account, packet);
}
packetCallbacks.remove(id);
} else if (this.presenceListener != null) {
@ -377,7 +379,7 @@ public class XmppConnection implements Runnable {
}
private void sendEnableCarbons() {
Log.d(LOGTAG,account.getJid()+": enable carbons");
Log.d(LOGTAG, account.getJid() + ": enable carbons");
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element enable = new Element("enable");
enable.setAttribute("xmlns", "urn:xmpp:carbons:2");
@ -387,9 +389,11 @@ public class XmppConnection implements Runnable {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (!packet.hasChild("error")) {
Log.d(LOGTAG,account.getJid()+": successfully enabled carbons");
Log.d(LOGTAG, account.getJid()
+ ": successfully enabled carbons");
} else {
Log.d(LOGTAG,account.getJid()+": error enableing carbons "+packet.toString());
Log.d(LOGTAG, account.getJid()
+ ": error enableing carbons " + packet.toString());
}
}
});
@ -427,7 +431,8 @@ public class XmppConnection implements Runnable {
this.sendMessagePacket(packet, null);
}
public void sendMessagePacket(MessagePacket packet, OnMessagePacketReceived callback) {
public void sendMessagePacket(MessagePacket packet,
OnMessagePacketReceived callback) {
String id = nextRandomId();
packet.setAttribute("id", id);
tagWriter.writeElement(packet);
@ -440,7 +445,8 @@ public class XmppConnection implements Runnable {
this.sendPresencePacket(packet, null);
}
public PresencePacket sendPresencePacket(PresencePacket packet, OnPresencePacketReceived callback) {
public PresencePacket sendPresencePacket(PresencePacket packet,
OnPresencePacketReceived callback) {
String id = nextRandomId();
packet.setAttribute("id", id);
tagWriter.writeElement(packet);