aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-08-16 12:12:22 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-08-16 12:12:22 +0200
commit51a2645349e43c5e780b352f7e76fc5aeae1cfde (patch)
treeea8dbdf78e01997c8381857ac28768ac7c09890d /src/main/java/eu/siacs
parentc082066118431a380dc62892c4363f73591b6666 (diff)
synchronize packetCallbacks
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index 5ac08976..44e14614 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -152,7 +152,6 @@ public class XmppConnection implements Runnable {
shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER);
tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter();
- packetCallbacks.clear();
this.changeStatus(Account.State.CONNECTING);
if (DNSHelper.isIp(account.getServer().toString())) {
socket = new Socket();
@@ -489,26 +488,28 @@ public class XmppConnection implements Runnable {
this.jingleListener.onJinglePacketReceived(account,(JinglePacket) packet);
}
} else {
- if (packetCallbacks.containsKey(packet.getId())) {
- final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
- // Packets to the server should have responses from the server
- if (packetCallbackDuple.first.toServer(account)) {
- if (packet.fromServer(account)) {
- packetCallbackDuple.second.onIqPacketReceived(account, packet);
- packetCallbacks.remove(packet.getId());
- } else {
- Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
- }
- } else {
- if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) {
- packetCallbackDuple.second.onIqPacketReceived(account, packet);
- packetCallbacks.remove(packet.getId());
+ synchronized (this.packetCallbacks) {
+ if (packetCallbacks.containsKey(packet.getId())) {
+ final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
+ // Packets to the server should have responses from the server
+ if (packetCallbackDuple.first.toServer(account)) {
+ if (packet.fromServer(account)) {
+ packetCallbackDuple.second.onIqPacketReceived(account, packet);
+ packetCallbacks.remove(packet.getId());
+ } else {
+ Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet");
+ }
} else {
- Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
+ if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) {
+ packetCallbackDuple.second.onIqPacketReceived(account, packet);
+ packetCallbacks.remove(packet.getId());
+ } else {
+ Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet");
+ }
}
+ } else if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) {
+ this.unregisteredIqListener.onIqPacketReceived(account, packet);
}
- } else if (packet.getType() == IqPacket.TYPE.GET|| packet.getType() == IqPacket.TYPE.SET) {
- this.unregisteredIqListener.onIqPacketReceived(account, packet);
}
}
}
@@ -739,13 +740,15 @@ public class XmppConnection implements Runnable {
}
private void clearIqCallbacks() {
- Log.d(Config.LOGTAG,account.getJid().toBareJid()+": clearing iq iq callbacks");
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": clearing iq iq callbacks");
final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.ERROR);
- Iterator<Entry<String, Pair<IqPacket, OnIqPacketReceived>>> iterator = this.packetCallbacks.entrySet().iterator();
- while(iterator.hasNext()) {
- Entry<String, Pair<IqPacket, OnIqPacketReceived>> entry = iterator.next();
- entry.getValue().second.onIqPacketReceived(account,failurePacket);
- iterator.remove();
+ synchronized (this.packetCallbacks) {
+ Iterator<Entry<String, Pair<IqPacket, OnIqPacketReceived>>> iterator = this.packetCallbacks.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Entry<String, Pair<IqPacket, OnIqPacketReceived>> entry = iterator.next();
+ entry.getValue().second.onIqPacketReceived(account, failurePacket);
+ iterator.remove();
+ }
}
}
@@ -917,7 +920,9 @@ public class XmppConnection implements Runnable {
packet.setAttribute("id", id);
}
if (callback != null) {
- packetCallbacks.put(packet.getId(), new Pair<>(packet, callback));
+ synchronized (this.packetCallbacks) {
+ packetCallbacks.put(packet.getId(), new Pair<>(packet, callback));
+ }
}
this.sendPacket(packet);
}