diff --git a/build/build.xml b/build/build.xml index 1fdcea1fd..8679d29a3 100644 --- a/build/build.xml +++ b/build/build.xml @@ -164,21 +164,32 @@ - + includes="org/jivesoftware/smack/**/*.class, **/smack-config.xml"> + + + + + + + + + excludes="org/jivesoftware/smackx/debugger/*.class"> + + + + + + @@ -186,21 +197,31 @@ + includes="org/jivesoftware/smackx/debugger/*.class, **/*.png"> + + + + + + + includes="org/jivesoftware/smackx/**/*.class"> + + + + + + diff --git a/build/build/biz.aQute.bnd.jar b/build/build/biz.aQute.bnd.jar new file mode 100644 index 000000000..1ff8d4ff5 Binary files /dev/null and b/build/build/biz.aQute.bnd.jar differ diff --git a/build/release.xml b/build/release.xml index 6aa4873a9..b4a0eef4b 100644 --- a/build/release.xml +++ b/build/release.xml @@ -69,6 +69,7 @@ + diff --git a/build/resources/releasedocs/changelog.html b/build/resources/releasedocs/changelog.html index 8e7c67621..9d75fd6a1 100644 --- a/build/resources/releasedocs/changelog.html +++ b/build/resources/releasedocs/changelog.html @@ -141,6 +141,29 @@ hr {
+

3.2.2 -- Dec. 23, 2011

+ +

Bug

+
    +
  • [SMACK-263] - Set file info in all send* methods
  • +
  • [SMACK-322] - NPE in XMPPConnection
  • +
  • [SMACK-324] - Investigate SASL issue with jabberd2 servers
  • +
  • [SMACK-338] - IBB filetransfer doesn't work as expected
  • +
  • [SMACK-346] - Bug in return code for rejection handling in FileTransferManager
  • +
  • [SMACK-348] - Documentation error - broken link
  • +
  • [SMACK-349] - Smack's IBB sends too much data in a packet
  • +
  • [SMACK-350] - Bytestream is not working in Spark 2.6.3 from XP to W7
  • +
  • [SMACK-353] - Thread leak in the FaultTolerantNegotiator
  • +
  • [SMACK-362] - smack throw NoSuchElementException if the muc#roominfo_subject has no values
  • +
+ +

Improvement

+
    +
  • [SMACK-343] - Make Smack jar an OSGi bundle.
  • +
  • [SMACK-354] - Provide milliseconds in timestamp colum debugwindow
  • +
+ +

3.2.1 -- July 4, 2011

Bug

    diff --git a/source/org/jivesoftware/smack/SmackConfiguration.java b/source/org/jivesoftware/smack/SmackConfiguration.java index 5c4c931a3..0cb23abe4 100644 --- a/source/org/jivesoftware/smack/SmackConfiguration.java +++ b/source/org/jivesoftware/smack/SmackConfiguration.java @@ -44,14 +44,14 @@ import java.util.*; */ public final class SmackConfiguration { - private static final String SMACK_VERSION = "3.2.1"; + private static final String SMACK_VERSION = "3.2.2"; private static int packetReplyTimeout = 5000; private static int keepAliveInterval = 30000; private static Vector defaultMechs = new Vector(); private static boolean localSocks5ProxyEnabled = true; - private static int localSocks5ProxyPort = 7778; + private static int localSocks5ProxyPort = 7777; private static int packetCollectorSize = 5000; private SmackConfiguration() { diff --git a/source/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java b/source/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java new file mode 100644 index 000000000..e7b4b9317 --- /dev/null +++ b/source/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java @@ -0,0 +1,109 @@ +/** + * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jivesoftware.smack.provider; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.pubsub.provider.ItemProvider; +import org.jivesoftware.smackx.pubsub.provider.ItemsProvider; +import org.xmlpull.v1.XmlPullParser; + +/** + * + * This class simplifies parsing of embedded elements by using the + * Template Method Pattern. + * After extracting the current element attributes and content of any child elements, the template method + * ({@link #createReturnExtension(String, String, Map, List)} is called. Subclasses + * then override this method to create the specific return type. + * + *

    To use this class, you simply register your subclasses as extension providers in the + * smack.properties file. Then they will be automatically picked up and used to parse + * any child elements. + * + *

    + * For example, given the following message
    + * 
    + * <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo>
    + *    <event xmlns='http://jabber.org/protocol/pubsub#event>
    + *       <items node='princely_musings'>
    + *          <item id='asdjkwei3i34234n356'>
    + *             <entry xmlns='http://www.w3.org/2005/Atom'>
    + *                <title>Soliloquy</title>
    + *                <link rel='alternative' type='text/html'/>
    + *                <id>tag:denmark.lit,2003:entry-32397</id>
    + *             </entry>
    + *          </item>
    + *       </items>
    + *    </event>
    + * </message>
    + * 
    + * I would have a classes
    + * {@link ItemsProvider} extends {@link EmbeddedExtensionProvider}
    + * {@link ItemProvider} extends {@link EmbeddedExtensionProvider}
    + * and
    + * AtomProvider extends {@link PacketExtensionProvider}
    + * 
    + * These classes are then registered in the meta-inf/smack.providers file
    + * as follows.
    + * 
    + *   <extensionProvider>
    + *      <elementName>items</elementName>
    + *      <namespace>http://jabber.org/protocol/pubsub#event</namespace>
    + *      <className>org.jivesoftware.smackx.provider.ItemsEventProvider</className>
    + *   </extensionProvider>
    + *   <extensionProvider>
    + *       <elementName>item</elementName>
    + *       <namespace>http://jabber.org/protocol/pubsub#event</namespace>
    + *       <className>org.jivesoftware.smackx.provider.ItemProvider</className>
    + *   </extensionProvider>
    + * 
    + * 
    + * + * @author Robin Collier + */ +abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider +{ + + final public PacketExtension parseExtension(XmlPullParser parser) throws Exception + { + String namespace = parser.getNamespace(); + String name = parser.getName(); + Map attMap = new HashMap(); + + for(int i=0; i extensions = new ArrayList(); + + do + { + int tag = parser.next(); + + if (tag == XmlPullParser.START_TAG) + extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser)); + } while (!name.equals(parser.getName())); + + return createReturnExtension(name, namespace, attMap, extensions); + } + + abstract protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content); +} diff --git a/source/org/jivesoftware/smackx/packet/SyncPacketSend.java b/source/org/jivesoftware/smack/util/SyncPacketSend.java similarity index 95% rename from source/org/jivesoftware/smackx/packet/SyncPacketSend.java rename to source/org/jivesoftware/smack/util/SyncPacketSend.java index 8ce87f92b..a1c238aeb 100644 --- a/source/org/jivesoftware/smackx/packet/SyncPacketSend.java +++ b/source/org/jivesoftware/smack/util/SyncPacketSend.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx.packet; +package org.jivesoftware.smack.util; import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.SmackConfiguration; diff --git a/source/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java b/source/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java index 6c4e1b57a..ef5253154 100644 --- a/source/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java +++ b/source/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java @@ -27,11 +27,11 @@ import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; +import org.jivesoftware.smack.util.SyncPacketSend; import org.jivesoftware.smackx.bytestreams.BytestreamListener; import org.jivesoftware.smackx.bytestreams.BytestreamManager; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; import org.jivesoftware.smackx.filetransfer.FileTransferManager; -import org.jivesoftware.smackx.packet.SyncPacketSend; /** * The InBandBytestreamManager class handles establishing In-Band Bytestreams as specified in the service - = new ExecutorCompletionService(Executors.newFixedThreadPool(2)); + = new ExecutorCompletionService(threadPoolExecutor); List> futures = new ArrayList>(); InputStream stream = null; XMPPException exception = null; @@ -119,6 +120,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator { future.cancel(true); } collector.cancel(); + threadPoolExecutor.shutdownNow(); } if (stream == null) { if (exception != null) { diff --git a/source/org/jivesoftware/smackx/filetransfer/FileTransfer.java b/source/org/jivesoftware/smackx/filetransfer/FileTransfer.java index f7c2ad934..46c77b53a 100644 --- a/source/org/jivesoftware/smackx/filetransfer/FileTransfer.java +++ b/source/org/jivesoftware/smackx/filetransfer/FileTransfer.java @@ -130,10 +130,10 @@ public abstract class FileTransfer { /** * Returns true if the transfer has been cancelled, if it has stopped because - * of a an error, or the transfer completed succesfully. + * of a an error, or the transfer completed successfully. * * @return Returns true if the transfer has been cancelled, if it has stopped - * because of a an error, or the transfer completed succesfully. + * because of a an error, or the transfer completed successfully. */ public boolean isDone() { return status == Status.cancelled || status == Status.error @@ -141,9 +141,9 @@ public abstract class FileTransfer { } /** - * Retuns the current status of the file transfer. + * Returns the current status of the file transfer. * - * @return Retuns the current status of the file transfer. + * @return Returns the current status of the file transfer. */ public Status getStatus() { return status; @@ -158,7 +158,7 @@ public abstract class FileTransfer { * during the transfer, the type of error can be retrieved through this * method. * - * @return Returns the type of error that occured if one has occured. + * @return Returns the type of error that occurred if one has occurred. */ public Error getError() { return error; @@ -166,9 +166,9 @@ public abstract class FileTransfer { /** * If an exception occurs asynchronously it will be stored for later - * retrival. If there is an error there maybe an exception set. + * retrieval. If there is an error there maybe an exception set. * - * @return The exception that occured or null if there was no exception. + * @return The exception that occurred or null if there was no exception. * @see #getError() */ public Exception getException() { @@ -246,7 +246,7 @@ public abstract class FileTransfer { public enum Status { /** - * An error occured during the transfer. + * An error occurred during the transfer. * * @see FileTransfer#getError() */ @@ -259,7 +259,7 @@ public abstract class FileTransfer { /** * The file transfer is being negotiated with the peer. The party - * recieving the file has the option to accept or refuse a file transfer + * Receiving the file has the option to accept or refuse a file transfer * request. If they accept, then the process of stream negotiation will * begin. If they refuse the file will not be transfered. * @@ -283,7 +283,7 @@ public abstract class FileTransfer { negotiating_stream("Negotiating Stream"), /** - * After the stream negotitation has completed the intermediate state + * After the stream negotiation has completed the intermediate state * between the time when the negotiation is finished and the actual * transfer begins. */ @@ -302,7 +302,7 @@ public abstract class FileTransfer { complete("Complete"), /** - * The file transfer was canceled + * The file transfer was cancelled */ cancelled("Cancelled"); @@ -348,12 +348,12 @@ public abstract class FileTransfer { no_response("The remote user did not respond or the connection timed out."), /** - * An error occured over the socket connected to send the file. + * An error occurred over the socket connected to send the file. */ connection("An error occured over the socket connected to send the file."), /** - * An error occured while sending or recieving the file + * An error occurred while sending or receiving the file */ stream("An error occured while sending or recieving the file."); diff --git a/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java b/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java index 2682c391e..25498a6fc 100644 --- a/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java +++ b/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java @@ -172,7 +172,7 @@ public class FileTransferManager { IQ rejection = FileTransferNegotiator.createIQ( initiation.getPacketID(), initiation.getFrom(), initiation .getTo(), IQ.Type.ERROR); - rejection.setError(new XMPPError(XMPPError.Condition.forbidden)); + rejection.setError(new XMPPError(XMPPError.Condition.no_acceptable)); connection.sendPacket(rejection); } } diff --git a/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java index 2d65cc7e4..290d69cfe 100644 --- a/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java +++ b/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java @@ -52,7 +52,7 @@ import org.jivesoftware.smackx.packet.StreamInitiation; * will be sent. * * @author Alexander Wenckus - * @see JEP-0096: File Transfer + * @see XEP-0096: SI File Transfer */ public class FileTransferNegotiator { @@ -76,7 +76,7 @@ public class FileTransferNegotiator { * set this variable to true for testing purposes as IBB is the backup file transfer method * and shouldn't be used as the only transfer method in production systems. */ - public static boolean IBB_ONLY = false; + public static boolean IBB_ONLY = (System.getProperty("ibb") != null);//true; /** * Returns the file transfer negotiator related to a particular connection. diff --git a/source/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java b/source/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java index 88822fd86..8068b7ef4 100644 --- a/source/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java +++ b/source/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java @@ -80,7 +80,7 @@ public class OutgoingFileTransfer extends FileTransfer { /** * Returns the output stream connected to the peer to transfer the file. It - * is only available after it has been succesfully negotiated by the + * is only available after it has been successfully negotiated by the * {@link StreamNegotiator}. * * @return Returns the output stream connected to the peer to transfer the @@ -120,6 +120,7 @@ public class OutgoingFileTransfer extends FileTransfer { + " been attempted on this file transfer"); } try { + setFileInfo(fileName, fileSize); this.outputStream = negotiateStream(fileName, fileSize, description); } catch (XMPPException e) { handleXMPPException(e); @@ -159,6 +160,7 @@ public class OutgoingFileTransfer extends FileTransfer { "The negotation process has already" + " been attempted for this file transfer"); } + setFileInfo(fileName, fileSize); this.callback = progress; transferThread = new Thread(new Runnable() { public void run() { @@ -184,7 +186,7 @@ public class OutgoingFileTransfer extends FileTransfer { /** * This method handles the stream negotiation process and transmits the file - * to the remote user. It returns immediatly and the progress of the file + * to the remote user. It returns immediately and the progress of the file * transfer can be monitored through several methods: * *
      @@ -257,7 +259,7 @@ public class OutgoingFileTransfer extends FileTransfer { /** * This method handles the stream negotiation process and transmits the file - * to the remote user. It returns immediatly and the progress of the file + * to the remote user. It returns immediately and the progress of the file * transfer can be monitored through several methods: * *
        @@ -274,6 +276,7 @@ public class OutgoingFileTransfer extends FileTransfer { public synchronized void sendStream(final InputStream in, final String fileName, final long fileSize, final String description){ checkTransferThread(); + setFileInfo(fileName, fileSize); transferThread = new Thread(new Runnable() { public void run() { //Create packet filter @@ -339,7 +342,7 @@ public class OutgoingFileTransfer extends FileTransfer { * -1 if the file transfer has not started. *

        * Note: This method is only useful when the {@link #sendFile(File, String)} - * method is called, as it is the only method that actualy transmits the + * method is called, as it is the only method that actually transmits the * file. * * @return Returns the amount of bytes that have been sent for the file @@ -410,7 +413,7 @@ public class OutgoingFileTransfer extends FileTransfer { } /** - * A callback class to retrive the status of an outgoing transfer + * A callback class to retrieve the status of an outgoing transfer * negotiation process. * * @author Alexander Wenckus @@ -438,7 +441,7 @@ public class OutgoingFileTransfer extends FileTransfer { /** * Called when an exception occurs during the negotiation progress. * - * @param e the exception that occured. + * @param e the exception that occurred. */ void errorEstablishingStream(Exception e); } diff --git a/source/org/jivesoftware/smackx/muc/RoomInfo.java b/source/org/jivesoftware/smackx/muc/RoomInfo.java index 7a632cfa0..f97f5443e 100644 --- a/source/org/jivesoftware/smackx/muc/RoomInfo.java +++ b/source/org/jivesoftware/smackx/muc/RoomInfo.java @@ -90,10 +90,10 @@ public class RoomInfo { Form form = Form.getFormFrom(info); if (form != null) { FormField descField = form.getField("muc#roominfo_description"); - this.description = descField == null ? "" : descField.getValues().next(); + this.description = ( descField == null || !(descField.getValues().hasNext()) )? "" : descField.getValues().next(); FormField subjField = form.getField("muc#roominfo_subject"); - this.subject = subjField == null ? "" : subjField.getValues().next(); + this.subject = ( subjField == null || !(subjField.getValues().hasNext()) ) ? "" : subjField.getValues().next(); FormField occCountField = form.getField("muc#roominfo_occupants"); this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues() diff --git a/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java b/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java index 87354c963..3d5ceb458 100644 --- a/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java +++ b/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java @@ -78,6 +78,8 @@ import org.xmlpull.v1.XmlPullParser; * * * @author Robin Collier + * + * @deprecated This has been moved to {@link org.jivesoftware.smack.provider.EmbeddedExtensionProvider} */ abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider { diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java index a420fdff4..632d4410a 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java @@ -40,6 +40,7 @@ public class InBandBytestreamSessionMessageTest { String sessionID = "session_id"; int blockSize = 10; + int dataSize = blockSize/4 * 3; // protocol verifier Protocol protocol; @@ -102,7 +103,7 @@ public class InBandBytestreamSessionMessageTest { protocol.addResponse(null, incrementingSequence); protocol.addResponse(null, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); outputStream.write(controlData); @@ -127,7 +128,7 @@ public class InBandBytestreamSessionMessageTest { protocol.addResponse(null, incrementingSequence); protocol.addResponse(null, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); for (byte b : controlData) { @@ -154,11 +155,11 @@ public class InBandBytestreamSessionMessageTest { protocol.addResponse(null, incrementingSequence); protocol.addResponse(null, incrementingSequence); - byte[] controlData = new byte[(blockSize * 3) - 2]; + byte[] controlData = new byte[(dataSize * 3) - 2]; OutputStream outputStream = session.getOutputStream(); int off = 0; - for (int i = 1; i <= 7; i++) { + for (int i = 1; off+i <= controlData.length; i++) { outputStream.write(controlData, off, i); off += i; } @@ -175,7 +176,7 @@ public class InBandBytestreamSessionMessageTest { */ @Test public void shouldSendThirtyDataPackets() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -202,7 +203,7 @@ public class InBandBytestreamSessionMessageTest { */ @Test public void shouldSendNothingOnSuccessiveCallsToFlush() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -273,7 +274,7 @@ public class InBandBytestreamSessionMessageTest { public void shouldReadAllReceivedData1() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); // get IBB sessions data packet listener @@ -283,8 +284,8 @@ public class InBandBytestreamSessionMessageTest { PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); // verify data packet and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + for (int i = 0; i < controlData.length / dataSize; i++) { + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Message dataMessage = new Message(); @@ -292,14 +293,14 @@ public class InBandBytestreamSessionMessageTest { listener.processPacket(dataMessage); } - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; int read = 0; - read = inputStream.read(bytes, 0, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 10, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 20, blockSize); - assertEquals(blockSize, read); + read = inputStream.read(bytes, 0, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize*2, dataSize); + assertEquals(dataSize, read); // verify data for (int i = 0; i < bytes.length; i++) { @@ -319,7 +320,7 @@ public class InBandBytestreamSessionMessageTest { public void shouldReadAllReceivedData2() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); // get IBB sessions data packet listener @@ -329,8 +330,8 @@ public class InBandBytestreamSessionMessageTest { PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); // verify data packet and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + for (int i = 0; i < controlData.length / dataSize; i++) { + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Message dataMessage = new Message(); @@ -339,7 +340,7 @@ public class InBandBytestreamSessionMessageTest { } // read data - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) inputStream.read(); } diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java index d2f20e5e9..723572747 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java @@ -40,7 +40,8 @@ public class InBandBytestreamSessionTest { String xmppServer = "xmpp-server"; String sessionID = "session_id"; - int blockSize = 10; + int blockSize = 20; + int dataSize = blockSize/4 * 3; // protocol verifier Protocol protocol; @@ -102,7 +103,7 @@ public class InBandBytestreamSessionTest { protocol.addResponse(resultIQ, incrementingSequence); protocol.addResponse(resultIQ, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); outputStream.write(controlData); @@ -128,7 +129,7 @@ public class InBandBytestreamSessionTest { protocol.addResponse(resultIQ, incrementingSequence); protocol.addResponse(resultIQ, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); for (byte b : controlData) { @@ -156,11 +157,11 @@ public class InBandBytestreamSessionTest { protocol.addResponse(resultIQ, incrementingSequence); protocol.addResponse(resultIQ, incrementingSequence); - byte[] controlData = new byte[(blockSize * 3) - 2]; + byte[] controlData = new byte[(dataSize * 3) - 2]; OutputStream outputStream = session.getOutputStream(); int off = 0; - for (int i = 1; i <= 7; i++) { + for (int i = 1; i+off <= controlData.length; i++) { outputStream.write(controlData, off, i); off += i; } @@ -177,7 +178,7 @@ public class InBandBytestreamSessionTest { */ @Test public void shouldSendThirtyDataPackets() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -205,7 +206,7 @@ public class InBandBytestreamSessionTest { */ @Test public void shouldSendNothingOnSuccessiveCallsToFlush() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -236,7 +237,7 @@ public class InBandBytestreamSessionTest { public void shouldSendDataCorrectly() throws Exception { // create random data Random rand = new Random(); - final byte[] controlData = new byte[256 * blockSize]; + final byte[] controlData = new byte[256 * dataSize]; rand.nextBytes(controlData); // compares the data of each packet with the control data @@ -246,7 +247,7 @@ public class InBandBytestreamSessionTest { byte[] decodedData = request.getDataPacketExtension().getDecodedData(); int seq = (int) request.getDataPacketExtension().getSeq(); for (int i = 0; i < decodedData.length; i++) { - assertEquals(controlData[(seq * blockSize) + i], decodedData[i]); + assertEquals(controlData[(seq * dataSize) + i], decodedData[i]); } } @@ -254,7 +255,7 @@ public class InBandBytestreamSessionTest { // set acknowledgments for the data packets IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); - for (int i = 0; i < controlData.length / blockSize; i++) { + for (int i = 0; i < controlData.length / dataSize; i++) { protocol.addResponse(resultIQ, incrementingSequence, dataVerification); } @@ -462,7 +463,7 @@ public class InBandBytestreamSessionTest { public void shouldReadAllReceivedData1() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); @@ -473,24 +474,24 @@ public class InBandBytestreamSessionTest { InputStream inputStream = session.getInputStream(); PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); - // set data packet acknowledgment and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { + // set data packet acknowledgement and notify listener + for (int i = 0; i < controlData.length / dataSize; i++) { protocol.addResponse(resultIQ); - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Data data = new Data(dpe); listener.processPacket(data); } - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; int read = 0; - read = inputStream.read(bytes, 0, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 10, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 20, blockSize); - assertEquals(blockSize, read); + read = inputStream.read(bytes, 0, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize*2, dataSize); + assertEquals(dataSize, read); // verify data for (int i = 0; i < bytes.length; i++) { @@ -510,7 +511,7 @@ public class InBandBytestreamSessionTest { public void shouldReadAllReceivedData2() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); @@ -522,9 +523,9 @@ public class InBandBytestreamSessionTest { PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); // set data packet acknowledgment and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { + for (int i = 0; i < controlData.length / dataSize; i++) { protocol.addResponse(resultIQ); - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Data data = new Data(dpe); @@ -532,7 +533,7 @@ public class InBandBytestreamSessionTest { } // read data - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) inputStream.read(); }