From 7538e387ec138cb60c2a9cab83cb992cc56c64b2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 1 Apr 2020 15:17:38 +0200 Subject: [PATCH] fixed bug in ibb delivery introduced in earlier refactoring --- .../xmpp/jingle/JingleConnectionManager.java | 12 +++++++++--- .../xmpp/jingle/JingleInBandTransport.java | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 8ba989270..38c98082d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -122,8 +122,8 @@ public class JingleConnectionManager extends AbstractConnectionManager { } public void deliverIbbPacket(Account account, IqPacket packet) { - String sid = null; - Element payload = null; + final String sid; + final Element payload; if (packet.hasChild("open", Namespace.IBB)) { payload = packet.findChild("open", Namespace.IBB); sid = payload.getAttribute("sid"); @@ -133,6 +133,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { } else if (packet.hasChild("close", Namespace.IBB)) { payload = packet.findChild("close", Namespace.IBB); sid = payload.getAttribute("sid"); + } else { + payload = null; + sid = null; } if (sid != null) { for (final AbstractJingleConnection connection : this.connections.values()) { @@ -140,7 +143,10 @@ public class JingleConnectionManager extends AbstractConnectionManager { final JingleFileTransferConnection fileTransfer = (JingleFileTransferConnection) connection; final JingleTransport transport = fileTransfer.getTransport(); if (transport instanceof JingleInBandTransport) { - ((JingleInBandTransport) transport).deliverPayload(packet, payload); + final JingleInBandTransport inBandTransport = (JingleInBandTransport) transport; + if (inBandTransport.matches(account, sid)) { + inBandTransport.deliverPayload(packet, payload); + } return; } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInBandTransport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInBandTransport.java index c5eaca072..fbc1ad95f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInBandTransport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInBandTransport.java @@ -3,6 +3,8 @@ package eu.siacs.conversations.xmpp.jingle; import android.util.Base64; import android.util.Log; +import com.google.common.base.Preconditions; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -77,6 +79,10 @@ public class JingleInBandTransport extends JingleTransport { this.account.getXmppConnection().sendIqPacket(iq, null); } + public boolean matches(final Account account, final String sessionId) { + return this.account == account && this.sessionId.equals(sessionId); + } + public void connect(final OnTransportConnected callback) { IqPacket iq = new IqPacket(IqPacket.TYPE.SET); iq.setTo(this.counterpart); @@ -96,7 +102,7 @@ public class JingleInBandTransport extends JingleTransport { @Override public void receive(DownloadableFile file, OnFileTransmissionStatusChanged callback) { - this.onFileTransmissionStatusChanged = callback; + this.onFileTransmissionStatusChanged = Preconditions.checkNotNull(callback); this.file = file; try { this.digest = MessageDigest.getInstance("SHA-1"); @@ -116,7 +122,7 @@ public class JingleInBandTransport extends JingleTransport { @Override public void send(DownloadableFile file, OnFileTransmissionStatusChanged callback) { - this.onFileTransmissionStatusChanged = callback; + this.onFileTransmissionStatusChanged = Preconditions.checkNotNull(callback); this.file = file; try { this.remainingSize = this.file.getExpectedSize(); @@ -205,7 +211,7 @@ public class JingleInBandTransport extends JingleTransport { connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100)); } } catch (Exception e) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + e.getMessage(), e); FileBackend.close(fileOutputStream); this.onFileTransmissionStatusChanged.onFileTransferAborted(); }