introduce special iq type for internal timeouts. always use != result to check for error in callbacks

This commit is contained in:
Daniel Gultsch 2015-08-23 17:53:23 +02:00
parent bbfd98b726
commit 0dfb9bd1a0
7 changed files with 18 additions and 20 deletions

View file

@ -236,7 +236,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
@Override @Override
public void onIqPacketReceived(final Account account, final IqPacket packet) { public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() == IqPacket.TYPE.ERROR || packet.getType() == IqPacket.TYPE.TIMEOUT) {
return; return;
} else if (packet.hasChild("query", Xmlns.ROSTER) && packet.fromServer(account)) { } else if (packet.hasChild("query", Xmlns.ROSTER) && packet.fromServer(account)) {
final Element query = packet.findChild("query"); final Element query = packet.findChild("query");

View file

@ -111,7 +111,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() != IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString()); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString());
finalizeQuery(query); finalizeQuery(query);
} }

View file

@ -214,7 +214,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private OnIqPacketReceived mDefaultIqHandler = new OnIqPacketReceived() { private OnIqPacketReceived mDefaultIqHandler = new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() != IqPacket.TYPE.RESULT) {
Element error = packet.findChild("error"); Element error = packet.findChild("error");
String text = error != null ? error.findChildContent("text") : null; String text = error != null ? error.findChildContent("text") : null;
if (text != null) { if (text != null) {
@ -1678,7 +1678,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() { sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.ERROR) { if (packet.getType() == IqPacket.TYPE.RESULT) {
ArrayList<String> features = new ArrayList<>(); ArrayList<String> features = new ArrayList<>();
for (Element child : packet.query().getChildren()) { for (Element child : packet.query().getChildren()) {
if (child != null && child.getName().equals("feature")) { if (child != null && child.getName().equals("feature")) {
@ -1702,7 +1702,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() { sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.ERROR) { if (packet.getType() == IqPacket.TYPE.RESULT) {
Data data = Data.parse(packet.query().findChild("x", "jabber:x:data")); Data data = Data.parse(packet.query().findChild("x", "jabber:x:data"));
for (Field field : data.getFields()) { for (Field field : data.getFields()) {
if (options.containsKey(field.getName())) { if (options.containsKey(field.getName())) {
@ -1716,12 +1716,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendIqPacket(account, set, new OnIqPacketReceived() { sendIqPacket(account, set, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (callback != null) {
if (packet.getType() == IqPacket.TYPE.RESULT) { if (packet.getType() == IqPacket.TYPE.RESULT) {
if (callback != null) {
callback.onPushSucceeded(); callback.onPushSucceeded();
}
} else { } else {
if (callback != null) {
callback.onPushFailed(); callback.onPushFailed();
} }
} }

View file

@ -414,7 +414,7 @@ public class XmppConnection implements Runnable {
this.sendIqPacket(iq, new OnIqPacketReceived() { this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(final Account account, final IqPacket packet) { public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) { if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource()); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource());
changeStatus(Account.State.ONLINE); changeStatus(Account.State.ONLINE);
} else { } else {
@ -739,7 +739,7 @@ public class XmppConnection implements Runnable {
} }
private void clearIqCallbacks() { private void clearIqCallbacks() {
final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.ERROR); final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.TIMEOUT);
final ArrayList<OnIqPacketReceived> callbacks = new ArrayList<>(); final ArrayList<OnIqPacketReceived> callbacks = new ArrayList<>();
synchronized (this.packetCallbacks) { synchronized (this.packetCallbacks) {
if (this.packetCallbacks.size() == 0) { if (this.packetCallbacks.size() == 0) {

View file

@ -85,7 +85,7 @@ public class JingleConnection implements Transferable {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() != IqPacket.TYPE.RESULT) {
fail(); fail();
} }
} }
@ -449,7 +449,7 @@ public class JingleConnection implements Transferable {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.ERROR) { if (packet.getType() == IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer"); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer");
mJingleStatus = JINGLE_STATUS_INITIATED; mJingleStatus = JINGLE_STATUS_INITIATED;
mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
@ -634,12 +634,11 @@ public class JingleConnection implements Transferable {
@Override @Override
public void onIqPacketReceived(Account account, public void onIqPacketReceived(Account account,
IqPacket packet) { IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() != IqPacket.TYPE.RESULT) {
onProxyActivated.failed(); onProxyActivated.failed();
} else { } else {
onProxyActivated.success(); onProxyActivated.success();
sendProxyActivated(connection sendProxyActivated(connection.getCandidate().getCid());
.getCandidate().getCid());
} }
} }
}); });

View file

@ -74,7 +74,7 @@ public class JingleInbandTransport extends JingleTransport {
@Override @Override
public void onIqPacketReceived(Account account, public void onIqPacketReceived(Account account,
IqPacket packet) { IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() != IqPacket.TYPE.RESULT) {
callback.failed(); callback.failed();
} else { } else {
callback.established(); callback.established();

View file

@ -4,12 +4,13 @@ import eu.siacs.conversations.xml.Element;
public class IqPacket extends AbstractStanza { public class IqPacket extends AbstractStanza {
public static enum TYPE { public enum TYPE {
ERROR, ERROR,
SET, SET,
RESULT, RESULT,
GET, GET,
INVALID INVALID,
TIMEOUT
} }
public IqPacket(final TYPE type) { public IqPacket(final TYPE type) {