From 63fabf78ed082d3c3dde18847f100d960543b219 Mon Sep 17 00:00:00 2001 From: Anno van Vliet Date: Mon, 2 Mar 2015 14:46:42 +0100 Subject: [PATCH] Fixed Data IQ packet receiving Data packets where not received by the InBandByteStream due to a missing IQRequestHandler Conflicts: smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java --- .../smackx/bytestreams/ibb/DataListener.java | 26 ++++++++++++++++++- .../ibb/InBandBytestreamManager.java | 3 ++- .../ibb/InBandBytestreamSession.java | 8 ++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java index 432e02d1e..28fc0c1b2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java @@ -21,8 +21,12 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.filter.StanzaTypeFilter; +import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler; +import org.jivesoftware.smack.iqrequest.IQRequestHandler; +import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; +import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; /** * DataListener handles all In-Band Bytestream IQ stanzas containing a data @@ -38,7 +42,7 @@ import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; * * @author Henning Staib */ -class DataListener implements StanzaListener { +class DataListener extends AbstractIqRequestHandler implements StanzaListener, IQRequestHandler { /* manager containing the listeners and the XMPP connection */ private final InBandBytestreamManager manager; @@ -53,6 +57,7 @@ class DataListener implements StanzaListener { * @param manager the In-Band Bytestream manager */ public DataListener(InBandBytestreamManager manager) { + super(DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE, IQ.Type.set, Mode.async); this.manager = manager; } @@ -74,4 +79,23 @@ class DataListener implements StanzaListener { return this.dataFilter; } + @Override + public IQ handleIQRequest(IQ iqRequest) { + Data data = (Data) iqRequest; + InBandBytestreamSession ibbSession = this.manager.getSessions().get( + data.getDataPacketExtension().getSessionID()); + try { + if (ibbSession == null) { + this.manager.replyItemNotFoundPacket(data); + } + else { + ibbSession.processIQPacket(data); + } + } + catch (NotConnectedException e) { + return null; + } + return null; + } + } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java index 7fa27c46b..f3757ed14 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java @@ -25,11 +25,11 @@ import java.util.Random; import java.util.concurrent.ConcurrentHashMap; import org.jivesoftware.smack.AbstractConnectionClosedListener; +import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; @@ -215,6 +215,7 @@ public class InBandBytestreamManager implements BytestreamManager { // register bytestream data packet listener this.dataListener = new DataListener(this); this.connection.addSyncStanzaListener(this.dataListener, this.dataListener.getFilter()); + connection.registerIQRequestHandler(dataListener); // register bytestream close packet listener this.closeListener = new CloseListener(this); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java index e7a99d934..a82526ebd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java @@ -814,4 +814,12 @@ public class InBandBytestreamSession implements BytestreamSession { } + /** + * @param data + * @throws NotConnectedException + */ + public void processIQPacket(Data data) throws NotConnectedException { + inputStream.dataPacketListener.processPacket(data); + } + }