modified clearIqCallbacks into 2-step process
This commit is contained in:
parent
7c822c9b75
commit
496f531e2e
|
@ -236,7 +236,9 @@ 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.hasChild("query", Xmlns.ROSTER) && packet.fromServer(account)) {
|
if (packet.getType() == IqPacket.TYPE.ERROR) {
|
||||||
|
return;
|
||||||
|
} else if (packet.hasChild("query", Xmlns.ROSTER) && packet.fromServer(account)) {
|
||||||
final Element query = packet.findChild("query");
|
final Element query = packet.findChild("query");
|
||||||
// If this is in response to a query for the whole roster:
|
// If this is in response to a query for the whole roster:
|
||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
|
@ -306,15 +308,13 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
|
||||||
final IqPacket response = packet.generateResponse(IqPacket.TYPE.RESULT);
|
final IqPacket response = packet.generateResponse(IqPacket.TYPE.RESULT);
|
||||||
mXmppConnectionService.sendIqPacket(account, response, null);
|
mXmppConnectionService.sendIqPacket(account, response, null);
|
||||||
} else {
|
} else {
|
||||||
if ((packet.getType() == IqPacket.TYPE.GET)
|
if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) {
|
||||||
|| (packet.getType() == IqPacket.TYPE.SET)) {
|
|
||||||
final IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
|
final IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
|
||||||
final Element error = response.addChild("error");
|
final Element error = response.addChild("error");
|
||||||
error.setAttribute("type", "cancel");
|
error.setAttribute("type", "cancel");
|
||||||
error.addChild("feature-not-implemented",
|
error.addChild("feature-not-implemented","urn:ietf:params:xml:ns:xmpp-stanzas");
|
||||||
"urn:ietf:params:xml:ns:xmpp-stanzas");
|
|
||||||
account.getXmppConnection().sendIqPacket(response, null);
|
account.getXmppConnection().sendIqPacket(response, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,10 +69,9 @@ public class Element {
|
||||||
|
|
||||||
public Element findChild(String name, String xmlns) {
|
public Element findChild(String name, String xmlns) {
|
||||||
for (Element child : this.children) {
|
for (Element child : this.children) {
|
||||||
if (child.getName().equals(name)
|
if (name.equals(child.getName()) && xmlns.equals(child.getAttribute("xmlns"))) {
|
||||||
&& (child.getAttribute("xmlns").equals(xmlns))) {
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package eu.siacs.conversations.xmpp;
|
package eu.siacs.conversations.xmpp;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
@ -37,7 +34,6 @@ import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
@ -103,7 +99,7 @@ public class XmppConnection implements Runnable {
|
||||||
private long lastConnect = 0;
|
private long lastConnect = 0;
|
||||||
private long lastSessionStarted = 0;
|
private long lastSessionStarted = 0;
|
||||||
private int attempt = 0;
|
private int attempt = 0;
|
||||||
private final Map<String, Pair<IqPacket, OnIqPacketReceived>> packetCallbacks = new Hashtable<>();
|
private final Hashtable<String, Pair<IqPacket, OnIqPacketReceived>> packetCallbacks = new Hashtable<>();
|
||||||
private OnPresencePacketReceived presenceListener = null;
|
private OnPresencePacketReceived presenceListener = null;
|
||||||
private OnJinglePacketReceived jingleListener = null;
|
private OnJinglePacketReceived jingleListener = null;
|
||||||
private OnIqPacketReceived unregisteredIqListener = null;
|
private OnIqPacketReceived unregisteredIqListener = null;
|
||||||
|
@ -727,9 +723,11 @@ public class XmppConnection implements Runnable {
|
||||||
sendPostBindInitialization();
|
sendPostBindInitialization();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid()+": disconnecting because of bind failure");
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid()+": disconnecting because of bind failure");
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -737,15 +735,19 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearIqCallbacks() {
|
private void clearIqCallbacks() {
|
||||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": clearing iq iq callbacks");
|
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<>();
|
||||||
synchronized (this.packetCallbacks) {
|
synchronized (this.packetCallbacks) {
|
||||||
Iterator<Entry<String, Pair<IqPacket, OnIqPacketReceived>>> iterator = this.packetCallbacks.entrySet().iterator();
|
final Iterator<Pair<IqPacket, OnIqPacketReceived>> iterator = this.packetCallbacks.values().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Entry<String, Pair<IqPacket, OnIqPacketReceived>> entry = iterator.next();
|
Pair<IqPacket, OnIqPacketReceived> entry = iterator.next();
|
||||||
entry.getValue().second.onIqPacketReceived(account, failurePacket);
|
callbacks.add(entry.second);
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
this.packetCallbacks.clear();
|
||||||
|
}
|
||||||
|
for(OnIqPacketReceived callback : callbacks) {
|
||||||
|
callback.onIqPacketReceived(account,failurePacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,6 +760,7 @@ public class XmppConnection implements Runnable {
|
||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
sendPostBindInitialization();
|
sendPostBindInitialization();
|
||||||
} else {
|
} else {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not init sessions");
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -887,6 +890,8 @@ public class XmppConnection implements Runnable {
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG,
|
||||||
account.getJid().toBareJid() + ": switching resource due to conflict ("
|
account.getJid().toBareJid() + ": switching resource due to conflict ("
|
||||||
+ account.getResource() + ")");
|
+ account.getResource() + ")");
|
||||||
|
} else if (streamError != null) {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": stream error "+streamError.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue