don't make subsequent iq request when original stanza returned an error

This commit is contained in:
Daniel Gultsch 2015-08-23 08:27:05 +02:00
parent 496f531e2e
commit 1688b65965
2 changed files with 67 additions and 51 deletions

View file

@ -871,10 +871,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@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) {
final Element query = packet.query(); final Element query = packet.query();
final List<Bookmark> bookmarks = new CopyOnWriteArrayList<>(); final List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
final Element storage = query.findChild("storage", final Element storage = query.findChild("storage", "storage:bookmarks");
"storage:bookmarks");
if (storage != null) { if (storage != null) {
for (final Element item : storage.getChildren()) { for (final Element item : storage.getChildren()) {
if (item.getName().equals("conference")) { if (item.getName().equals("conference")) {
@ -893,6 +893,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
account.setBookmarks(bookmarks); account.setBookmarks(bookmarks);
} else {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not fetch bookmarks");
}
} }
}; };
sendIqPacket(account, iqPacket, callback); sendIqPacket(account, iqPacket, callback);
@ -1955,10 +1958,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final IqPacket packet = XmppConnectionService.this.mIqGenerator final IqPacket packet = XmppConnectionService.this.mIqGenerator
.publishAvatarMetadata(avatar); .publishAvatarMetadata(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() { sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, public void onIqPacketReceived(Account account, IqPacket result) {
IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) { if (result.getType() == IqPacket.TYPE.RESULT) {
if (account.setAvatar(avatar.getFilename())) { if (account.setAvatar(avatar.getFilename())) {
getAvatarService().clear(account); getAvatarService().clear(account);

View file

@ -414,9 +414,12 @@ 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) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() if (packet.getType() == IqPacket.TYPE.RESULT) {
+ ": 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 {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": initial ping failed");
}
} }
}); });
} }
@ -656,8 +659,8 @@ public class XmppConnection implements Runnable {
@Override @Override
public void onIqPacketReceived(final Account account, final IqPacket packet) { public void onIqPacketReceived(final Account account, final IqPacket packet) {
final Element instructions = packet.query().findChild("instructions"); if (packet.getType() == IqPacket.TYPE.RESULT
if (packet.query().hasChild("username") && packet.query().hasChild("username")
&& (packet.query().hasChild("password"))) { && (packet.query().hasChild("password"))) {
final IqPacket register = new IqPacket(IqPacket.TYPE.SET); final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
final Element username = new Element("username").setContent(account.getUsername()); final Element username = new Element("username").setContent(account.getUsername());
@ -684,6 +687,7 @@ public class XmppConnection implements Runnable {
} }
}); });
} else { } else {
final Element instructions = packet.query().findChild("instructions");
changeStatus(Account.State.REGISTRATION_FAILED); changeStatus(Account.State.REGISTRATION_FAILED);
disconnect(true); disconnect(true);
Log.d(Config.LOGTAG, account.getJid().toBareJid() Log.d(Config.LOGTAG, account.getJid().toBareJid()
@ -735,10 +739,13 @@ public class XmppConnection implements Runnable {
} }
private void clearIqCallbacks() { private void clearIqCallbacks() {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": clearing "+this.packetCallbacks.size()+" iq callbacks");
final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.ERROR); final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.ERROR);
final ArrayList<OnIqPacketReceived> callbacks = new ArrayList<>(); final ArrayList<OnIqPacketReceived> callbacks = new ArrayList<>();
synchronized (this.packetCallbacks) { synchronized (this.packetCallbacks) {
if (this.packetCallbacks.size() == 0) {
return;
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": clearing "+this.packetCallbacks.size()+" iq callbacks");
final Iterator<Pair<IqPacket, OnIqPacketReceived>> iterator = this.packetCallbacks.values().iterator(); final Iterator<Pair<IqPacket, OnIqPacketReceived>> iterator = this.packetCallbacks.values().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Pair<IqPacket, OnIqPacketReceived> entry = iterator.next(); Pair<IqPacket, OnIqPacketReceived> entry = iterator.next();
@ -749,6 +756,7 @@ public class XmppConnection implements Runnable {
for(OnIqPacketReceived callback : callbacks) { for(OnIqPacketReceived callback : callbacks) {
callback.onIqPacketReceived(account,failurePacket); callback.onIqPacketReceived(account,failurePacket);
} }
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": done clearing iq callbacks");
} }
private void sendStartSession() { private void sendStartSession() {
@ -805,6 +813,7 @@ public class XmppConnection implements Runnable {
@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) {
final List<Element> elements = packet.query().getChildren(); final List<Element> elements = packet.query().getChildren();
final Info info = new Info(); final Info info = new Info();
for (final Element element : elements) { for (final Element element : elements) {
@ -819,13 +828,15 @@ public class XmppConnection implements Runnable {
} }
} }
disco.put(jid, info); disco.put(jid, info);
if (account.getServer().equals(jid)) { if (account.getServer().equals(jid)) {
enableAdvancedStreamFeatures(); enableAdvancedStreamFeatures();
for (final OnAdvancedStreamFeaturesLoaded listener : advancedStreamFeaturesLoadedListeners) { for (final OnAdvancedStreamFeaturesLoaded listener : advancedStreamFeaturesLoadedListeners) {
listener.onAdvancedStreamFeaturesAvailable(account); listener.onAdvancedStreamFeaturesAvailable(account);
} }
} }
} else {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not query disco info for "+jid.toString());
}
} }
}); });
} }
@ -849,6 +860,7 @@ public class XmppConnection implements Runnable {
@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) {
final List<Element> elements = packet.query().getChildren(); final List<Element> elements = packet.query().getChildren();
for (final Element element : elements) { for (final Element element : elements) {
if (element.getName().equals("item")) { if (element.getName().equals("item")) {
@ -858,6 +870,9 @@ public class XmppConnection implements Runnable {
} }
} }
} }
} else {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not query disco items of "+server);
}
} }
}); });
} }