wait for session iq to return sucessfully before sending other stanzas. fixed #1017

This commit is contained in:
iNPUTmice 2015-03-20 21:48:45 +01:00
parent 5793fb680f
commit da099e5fa4
1 changed files with 42 additions and 26 deletions

View File

@ -687,14 +687,44 @@ public class XmppConnection implements Runnable {
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
// TODO: Handle the case where an external JID is technically invalid? // TODO: Handle the case where an external JID is technically invalid?
} }
if (streamFeatures.hasChild("session")) {
sendStartSession();
} else {
sendPostBindInitialization();
}
} else {
disconnect(true);
}
} else {
disconnect(true);
}
}
});
}
private void sendStartSession() {
final IqPacket startSession = new IqPacket(IqPacket.TYPE.SET);
startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session");
this.sendUnmodifiedIqPacket(startSession, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
sendPostBindInitialization();
} else {
disconnect(true);
}
}
});
}
private void sendPostBindInitialization() {
smVersion = 0;
if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) { if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) {
smVersion = 3; smVersion = 3;
final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable);
stanzasSent = 0;
messageReceipts.clear();
} else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) { } else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) {
smVersion = 2; smVersion = 2;
}
if (smVersion != 0) {
final EnablePacket enable = new EnablePacket(smVersion); final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable); tagWriter.writeStanzaAsync(enable);
stanzasSent = 0; stanzasSent = 0;
@ -709,20 +739,6 @@ public class XmppConnection implements Runnable {
bindListener.onBind(account); bindListener.onBind(account);
} }
sendInitialPing(); sendInitialPing();
} else {
disconnect(true);
}
} else {
disconnect(true);
}
}
});
if (this.streamFeatures.hasChild("session")) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending deprecated session");
final IqPacket startSession = new IqPacket(IqPacket.TYPE.SET);
startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session");
this.sendUnmodifiedIqPacket(startSession, null);
}
} }
private void sendServiceDiscoveryInfo(final Jid server) { private void sendServiceDiscoveryInfo(final Jid server) {