summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-07-17 02:22:32 (GMT)
committerNick Hudson <nick.hudson@isode.com>2015-07-28 13:14:20 (GMT)
commit673655830b0325d964e67fa835ea83f485e9beeb (patch)
tree27e4f8bd20dd9011207641a83212ced393fbada2 /src
parent6f84f6a65b8b80e2f599dff76da0cd13fbead611 (diff)
downloadstroke-673655830b0325d964e67fa835ea83f485e9beeb.zip
stroke-673655830b0325d964e67fa835ea83f485e9beeb.tar.bz2
Complete StreamStack and add tests.
TLSLayer could not be updated because it requires TLS to be ported first. Updates other classes, only for having compatibility with SafeByteArray because of updates in Stream Stack. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for StreamStack and XMPPLayer, which passes. Change-Id: I8707fc1f16d622d2a90f6f39f671b7e7c46aa170
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/base/SafeByteArray.java158
-rw-r--r--src/com/isode/stroke/compress/ZLibCodecompressor.java6
-rw-r--r--src/com/isode/stroke/network/Connection.java6
-rw-r--r--src/com/isode/stroke/network/JavaConnection.java13
-rw-r--r--src/com/isode/stroke/session/BasicSessionStream.java9
-rw-r--r--src/com/isode/stroke/session/Session.java5
-rw-r--r--src/com/isode/stroke/session/SessionTracer.java12
-rw-r--r--src/com/isode/stroke/streamstack/CompressionLayer.java6
-rw-r--r--src/com/isode/stroke/streamstack/ConnectionLayer.java14
-rw-r--r--src/com/isode/stroke/streamstack/HighLayer.java6
-rw-r--r--src/com/isode/stroke/streamstack/LowLayer.java6
-rw-r--r--src/com/isode/stroke/streamstack/StreamLayer.java6
-rw-r--r--src/com/isode/stroke/streamstack/StreamStack.java2
-rw-r--r--src/com/isode/stroke/streamstack/TLSLayer.java16
-rw-r--r--src/com/isode/stroke/streamstack/WhitespacePingLayer.java8
-rw-r--r--src/com/isode/stroke/streamstack/XMPPLayer.java26
-rw-r--r--src/com/isode/stroke/tls/TLSContext.java9
-rw-r--r--src/com/isode/stroke/tls/java/JSSEContext.java15
18 files changed, 169 insertions, 154 deletions
diff --git a/src/com/isode/stroke/base/SafeByteArray.java b/src/com/isode/stroke/base/SafeByteArray.java
index 74c1848..ac8960f 100644
--- a/src/com/isode/stroke/base/SafeByteArray.java
+++ b/src/com/isode/stroke/base/SafeByteArray.java
@@ -22,83 +22,93 @@ public class SafeByteArray extends ByteArray {
super(s);
}
- public SafeByteArray(ByteArray b) {
- this.append(b.getData());
- }
+ public SafeByteArray(ByteArray b) {
+ this.append(b.getData());
+ }
- /**
- * Creates a new SafeByteArray object containing all
- * the elements from two existing ByteArrays (immutable add).
- *
- * @param a an existing SafeByteArray. Must not be null, but may be empty.
- * @param b an existing SafeByteArray. Must not be null, but may be empty.
- * @return a new SafeByteArray containing all the elements of <em>a</em>
- * followed by all the elements of <em>b</em>.
- */
- public static SafeByteArray plus(SafeByteArray a, SafeByteArray b) {
- SafeByteArray x = new SafeByteArray().append(a.getData());
- x.append(b);
- return x;
- }
-
- /**
- * Updates the SafeByteArray by adding all the elements
- * of another SafeByteArray to the end of the array (mutable add).
- * @param b an existing SafeByteArray. Must not be null, but may be empty
- * @return a reference to the updated object
- */
- public SafeByteArray append(ByteArray b) {
- append(b.getData());
- return this;
- }
+ /**
+ * Constructs a new ByteArray containing the bytes in a user-supplied
+ * byte[]
+ * @param c an array of bytes, which must not be null, but may contain
+ * zero elements.
+ */
+ public SafeByteArray(byte[] c) {
+ super(c);
+ }
- /**
- * Updates the SafeByteArray by adding all the bytes
- * in a byte[] to the end of the array (mutable add).
- *
- * @param b an array of bytes. Must not be null, but may contain zero
- * elements.
- *
- * @return a reference to the updated object
- */
- public SafeByteArray append(byte[] b) {
- return append(b, b.length);
- }
+ /**
+ * Creates a new SafeByteArray object containing all
+ * the elements from two existing ByteArrays (immutable add).
+ *
+ * @param a an existing SafeByteArray. Must not be null, but may be empty.
+ * @param b an existing SafeByteArray. Must not be null, but may be empty.
+ * @return a new SafeByteArray containing all the elements of <em>a</em>
+ * followed by all the elements of <em>b</em>.
+ */
+ public static SafeByteArray plus(SafeByteArray a, SafeByteArray b) {
+ SafeByteArray x = new SafeByteArray().append(a.getData());
+ x.append(b);
+ return x;
+ }
+
+ /**
+ * Updates the SafeByteArray by adding all the elements
+ * of another SafeByteArray to the end of the array (mutable add).
+ * @param b an existing SafeByteArray. Must not be null, but may be empty
+ * @return a reference to the updated object
+ */
+ public SafeByteArray append(ByteArray b) {
+ append(b.getData());
+ return this;
+ }
- /** Mutable add */
- public SafeByteArray append(byte[] b, int len) {
- for (int i = 0; i < len; i++) {
- append(b[i]);
- }
- return this;
- }
+ /**
+ * Updates the SafeByteArray by adding all the bytes
+ * in a byte[] to the end of the array (mutable add).
+ *
+ * @param b an array of bytes. Must not be null, but may contain zero
+ * elements.
+ *
+ * @return a reference to the updated object
+ */
+ public SafeByteArray append(byte[] b) {
+ return append(b, b.length);
+ }
- /**
- * Updates the SafeByteArray by adding a single byte
- * value to the end of the array (mutable add).
- * @param b a single byte
- * @return a reference to the updated object
- */
- public SafeByteArray append(byte b) {
- dataCopy_ = null; /* Invalidate cache */
- data_.add(Byte.valueOf(b));
- return this;
- }
+ /** Mutable add */
+ public SafeByteArray append(byte[] b, int len) {
+ for (int i = 0; i < len; i++) {
+ append(b[i]);
+ }
+ return this;
+ }
+
+ /**
+ * Updates the SafeByteArray by adding a single byte
+ * value to the end of the array (mutable add).
+ * @param b a single byte
+ * @return a reference to the updated object
+ */
+ public SafeByteArray append(byte b) {
+ dataCopy_ = null; /* Invalidate cache */
+ data_.add(Byte.valueOf(b));
+ return this;
+ }
- /**
- * Updates the SafeByteArray by adding all the bytes
- * obtained by UTF-8 encoding the provided String to the end of the array (mutable add).
- * @param s a String that must not be null.
- * @return a reference to the updated object.
- */
- public SafeByteArray append(String s) {
- byte[] bytes;
- try {
- bytes = s.getBytes("UTF-8");
- } catch (UnsupportedEncodingException ex) {
- throw new IllegalStateException("JVM has no 'UTF-8' encoding");
- }
- append(bytes);
- return this;
- }
+ /**
+ * Updates the SafeByteArray by adding all the bytes
+ * obtained by UTF-8 encoding the provided String to the end of the array (mutable add).
+ * @param s a String that must not be null.
+ * @return a reference to the updated object.
+ */
+ public SafeByteArray append(String s) {
+ byte[] bytes;
+ try {
+ bytes = s.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException ex) {
+ throw new IllegalStateException("JVM has no 'UTF-8' encoding");
+ }
+ append(bytes);
+ return this;
+ }
} \ No newline at end of file
diff --git a/src/com/isode/stroke/compress/ZLibCodecompressor.java b/src/com/isode/stroke/compress/ZLibCodecompressor.java
index 3925949..fed1f33 100644
--- a/src/com/isode/stroke/compress/ZLibCodecompressor.java
+++ b/src/com/isode/stroke/compress/ZLibCodecompressor.java
@@ -9,7 +9,7 @@
*/
package com.isode.stroke.compress;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.jcraft.jzlib.JZlib;
import com.jcraft.jzlib.ZStream;
@@ -17,8 +17,8 @@ public abstract class ZLibCodecompressor {
protected static final int CHUNK_SIZE = 1024;
protected final ZStream stream_ = new ZStream();
- public ByteArray process(ByteArray input) throws ZLibException {
- ByteArray output = new ByteArray();
+ public SafeByteArray process(SafeByteArray input) throws ZLibException {
+ SafeByteArray output = new SafeByteArray();
stream_.avail_in = input.getSize();
stream_.next_in = input.getData();
stream_.next_in_index = 0;
diff --git a/src/com/isode/stroke/network/Connection.java b/src/com/isode/stroke/network/Connection.java
index dbda1b7..b0e4799 100644
--- a/src/com/isode/stroke/network/Connection.java
+++ b/src/com/isode/stroke/network/Connection.java
@@ -9,7 +9,7 @@
*/
package com.isode.stroke.network;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.signals.Signal;
import com.isode.stroke.signals.Signal1;
@@ -30,11 +30,11 @@ public abstract class Connection {
public abstract void disconnect();
- public abstract void write(ByteArray data);
+ public abstract void write(SafeByteArray data);
public abstract HostAddressPort getLocalAddress();
public final Signal1<Boolean /*error*/> onConnectFinished = new Signal1<Boolean>();
public final Signal1<Error> onDisconnected = new Signal1<Error>();
- public final Signal1<ByteArray> onDataRead = new Signal1<ByteArray>();
+ public final Signal1<SafeByteArray> onDataRead = new Signal1<SafeByteArray>();
public final Signal onDataWritten = new Signal();
}
diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java
index 4e7503b..66f068f 100644
--- a/src/com/isode/stroke/network/JavaConnection.java
+++ b/src/com/isode/stroke/network/JavaConnection.java
@@ -18,6 +18,7 @@ import java.util.Collections;
import java.util.List;
import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.eventloop.Event.Callback;
import com.isode.stroke.eventloop.EventLoop;
import com.isode.stroke.eventloop.EventOwner;
@@ -30,16 +31,16 @@ public class JavaConnection extends Connection implements EventOwner {
* got closed.
*/
private static class ReadResult {
- public ByteArray dataRead_;
+ public SafeByteArray dataRead_;
public boolean socketClosed_;
ReadResult(boolean socketClosed) {
- dataRead_ = new ByteArray();
+ dataRead_ = new SafeByteArray();
socketClosed_ = socketClosed;
}
ReadResult(ByteArrayOutputStream byteArrayOutputStream, boolean socketClosed) {
- dataRead_ = new ByteArray(byteArrayOutputStream.toByteArray());
+ dataRead_ = new SafeByteArray(byteArrayOutputStream.toByteArray());
socketClosed_ = socketClosed;
}
}
@@ -95,7 +96,7 @@ public class JavaConnection extends Connection implements EventOwner {
}
{ /* Handle any reading */
- ByteArray dataRead;
+ SafeByteArray dataRead;
if (readNeeded) {
ReadResult rr = doRead();
@@ -299,7 +300,7 @@ public class JavaConnection extends Connection implements EventOwner {
}
}
- private void handleDataRead(final ByteArray data) {
+ private void handleDataRead(final SafeByteArray data) {
if (synchroniseReads_) {
selectionKey_.interestOps(0);
}
@@ -372,7 +373,7 @@ public class JavaConnection extends Connection implements EventOwner {
}
@Override
- public void write(ByteArray data) {
+ public void write(SafeByteArray data) {
worker_.writeBuffer_.add(data.getData());
// Check "isOpen" to Avoid Android crash see
// https://code.google.com/p/android/issues/detail?id=80785
diff --git a/src/com/isode/stroke/session/BasicSessionStream.java b/src/com/isode/stroke/session/BasicSessionStream.java
index f1e7bf1..4f0e75b 100644
--- a/src/com/isode/stroke/session/BasicSessionStream.java
+++ b/src/com/isode/stroke/session/BasicSessionStream.java
@@ -10,6 +10,7 @@ package com.isode.stroke.session;
import java.util.List;
import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.elements.Element;
import com.isode.stroke.elements.ProtocolHeader;
import com.isode.stroke.elements.StreamType;
@@ -71,15 +72,15 @@ public class BasicSessionStream extends SessionStream {
handleXMPPError();
}
});
- xmppLayer.onDataRead.connect(new Slot1<ByteArray>() {
+ xmppLayer.onDataRead.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
handleDataRead(p1);
}
});
- xmppLayer.onWriteData.connect(new Slot1<ByteArray>() {
+ xmppLayer.onWriteData.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
handleDataWritten(p1);
}
});
diff --git a/src/com/isode/stroke/session/Session.java b/src/com/isode/stroke/session/Session.java
index eb64051..815be02 100644
--- a/src/com/isode/stroke/session/Session.java
+++ b/src/com/isode/stroke/session/Session.java
@@ -10,6 +10,7 @@
package com.isode.stroke.session;
import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.elements.Element;
import com.isode.stroke.elements.ProtocolHeader;
import com.isode.stroke.elements.StreamType;
@@ -81,8 +82,8 @@ public abstract class Session {
}
public final Signal1<Element> onElementReceived = new Signal1<Element>();
public final Signal1<SessionError> onSessionFinished = new Signal1<SessionError>();
- public final Signal1<ByteArray> onDataWritten = new Signal1<ByteArray>();
- public final Signal1<ByteArray> onDataRead = new Signal1<ByteArray>();
+ public final Signal1<SafeByteArray> onDataWritten = new Signal1<SafeByteArray>();
+ public final Signal1<SafeByteArray> onDataRead = new Signal1<SafeByteArray>();
protected void setRemoteJID(JID j) {
remoteJID = j;
diff --git a/src/com/isode/stroke/session/SessionTracer.java b/src/com/isode/stroke/session/SessionTracer.java
index 7db165d..8b878a8 100644
--- a/src/com/isode/stroke/session/SessionTracer.java
+++ b/src/com/isode/stroke/session/SessionTracer.java
@@ -9,29 +9,29 @@
*/
package com.isode.stroke.session;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.signals.Slot1;
public class SessionTracer {
public SessionTracer(Session session) {
this.session = session;
- session.onDataRead.connect(new Slot1<ByteArray>() {
+ session.onDataRead.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
printData('<', p1);
}
});
- session.onDataWritten.connect(new Slot1<ByteArray>() {
+ session.onDataWritten.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
printData('>', p1);
}
});
}
- private void printData(char direction, ByteArray data) {
+ private void printData(char direction, SafeByteArray data) {
System.err.print("" + direction + direction + " " + session.getLocalJID().toString() + " ");
for (int i = 0; i < 72 - session.getLocalJID().toString().length() - session.getRemoteJID().toString().length(); ++i) {
System.err.print(direction);
diff --git a/src/com/isode/stroke/streamstack/CompressionLayer.java b/src/com/isode/stroke/streamstack/CompressionLayer.java
index d08f105..b89b3d2 100644
--- a/src/com/isode/stroke/streamstack/CompressionLayer.java
+++ b/src/com/isode/stroke/streamstack/CompressionLayer.java
@@ -9,7 +9,7 @@
*/
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.compress.ZLibCompressor;
import com.isode.stroke.compress.ZLibDecompressor;
import com.isode.stroke.compress.ZLibException;
@@ -17,7 +17,7 @@ import com.isode.stroke.signals.Signal;
public class CompressionLayer extends StreamLayer {
- public void writeData(ByteArray data) {
+ public void writeData(SafeByteArray data) {
try {
writeDataToChildLayer(compressor_.process(data));
}
@@ -26,7 +26,7 @@ public class CompressionLayer extends StreamLayer {
}
}
- public void handleDataRead(ByteArray data) {
+ public void handleDataRead(SafeByteArray data) {
try {
writeDataToParentLayer(decompressor_.process(data));
}
diff --git a/src/com/isode/stroke/streamstack/ConnectionLayer.java b/src/com/isode/stroke/streamstack/ConnectionLayer.java
index 0927a32..d003b52 100644
--- a/src/com/isode/stroke/streamstack/ConnectionLayer.java
+++ b/src/com/isode/stroke/streamstack/ConnectionLayer.java
@@ -4,7 +4,7 @@
*/
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.network.Connection;
import com.isode.stroke.signals.Slot1;
@@ -12,15 +12,15 @@ public class ConnectionLayer implements LowLayer {
public ConnectionLayer(Connection connection) {
this.connection = connection;
- connection.onDataRead.connect(new Slot1<ByteArray>() {
+ connection.onDataRead.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
writeDataToParentLayer(p1);
}
});
}
- public void writeData(ByteArray data) {
+ public void writeData(SafeByteArray data) {
connection.write(data);
}
@@ -29,11 +29,11 @@ public class ConnectionLayer implements LowLayer {
/* Work around multiple inheritance workaround again */
StreamLayer fakeStreamLayer_ = new StreamLayer() {
- public void writeData(ByteArray data) {
+ public void writeData(SafeByteArray data) {
connection.write(data);
}
- public void handleDataRead(ByteArray data) {
+ public void handleDataRead(SafeByteArray data) {
throw new UnsupportedOperationException("Not supported yet.");
}
};
@@ -46,7 +46,7 @@ public class ConnectionLayer implements LowLayer {
fakeStreamLayer_.setParentLayer(parentLayer);
}
- public void writeDataToParentLayer(ByteArray data) {
+ public void writeDataToParentLayer(SafeByteArray data) {
fakeStreamLayer_.writeDataToParentLayer(data);
}
}
diff --git a/src/com/isode/stroke/streamstack/HighLayer.java b/src/com/isode/stroke/streamstack/HighLayer.java
index 1ff36e1..c95e21f 100644
--- a/src/com/isode/stroke/streamstack/HighLayer.java
+++ b/src/com/isode/stroke/streamstack/HighLayer.java
@@ -9,7 +9,7 @@
*/
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
/**
* Because of the lack of multiple inheritance in Java, this has to be done
@@ -18,7 +18,7 @@ import com.isode.stroke.base.ByteArray;
*/
public interface HighLayer {
- void handleDataRead(ByteArray data);
+ void handleDataRead(SafeByteArray data);
/* Should be protected */
@@ -26,6 +26,6 @@ public interface HighLayer {
void setChildLayer(LowLayer childLayer);
- void writeDataToChildLayer(ByteArray data);
+ void writeDataToChildLayer(SafeByteArray data);
}
diff --git a/src/com/isode/stroke/streamstack/LowLayer.java b/src/com/isode/stroke/streamstack/LowLayer.java
index dcead38..37b04d4 100644
--- a/src/com/isode/stroke/streamstack/LowLayer.java
+++ b/src/com/isode/stroke/streamstack/LowLayer.java
@@ -9,7 +9,7 @@
*/
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
/**
* Because of the lack of multiple inheritance in Java, this has to be done
@@ -18,7 +18,7 @@ import com.isode.stroke.base.ByteArray;
*/
public interface LowLayer {
- void writeData(ByteArray data);
+ void writeData(SafeByteArray data);
/* Should be protected */
@@ -26,5 +26,5 @@ public interface LowLayer {
void setParentLayer(HighLayer parentLayer);
- void writeDataToParentLayer(ByteArray data);
+ void writeDataToParentLayer(SafeByteArray data);
}
diff --git a/src/com/isode/stroke/streamstack/StreamLayer.java b/src/com/isode/stroke/streamstack/StreamLayer.java
index ac9538b..a947400 100644
--- a/src/com/isode/stroke/streamstack/StreamLayer.java
+++ b/src/com/isode/stroke/streamstack/StreamLayer.java
@@ -9,7 +9,7 @@
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
/**
* Because of the lack of multiple inheritance in Java, this implements
@@ -26,7 +26,7 @@ public abstract class StreamLayer implements LowLayer, HighLayer {
this.parentLayer = parentLayer;
}
- public void writeDataToParentLayer(final ByteArray data) {
+ public void writeDataToParentLayer(final SafeByteArray data) {
assert parentLayer != null;
parentLayer.handleDataRead(data);
}
@@ -39,7 +39,7 @@ public abstract class StreamLayer implements LowLayer, HighLayer {
this.childLayer = childLayer;
}
- public void writeDataToChildLayer(final ByteArray data) {
+ public void writeDataToChildLayer(final SafeByteArray data) {
assert childLayer != null;
childLayer.writeData(data);
}
diff --git a/src/com/isode/stroke/streamstack/StreamStack.java b/src/com/isode/stroke/streamstack/StreamStack.java
index 08f986c..96fe2fd 100644
--- a/src/com/isode/stroke/streamstack/StreamStack.java
+++ b/src/com/isode/stroke/streamstack/StreamStack.java
@@ -49,4 +49,4 @@ public class StreamStack {
private XMPPLayer xmppLayer_;
private LowLayer physicalLayer_;
private List<StreamLayer> layers_ = new ArrayList<StreamLayer>();
-}
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/streamstack/TLSLayer.java b/src/com/isode/stroke/streamstack/TLSLayer.java
index 70bcd1a..8244766 100644
--- a/src/com/isode/stroke/streamstack/TLSLayer.java
+++ b/src/com/isode/stroke/streamstack/TLSLayer.java
@@ -11,7 +11,7 @@ package com.isode.stroke.streamstack;
import java.util.List;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.signals.Signal;
import com.isode.stroke.signals.Slot1;
import com.isode.stroke.tls.Certificate;
@@ -24,15 +24,15 @@ public class TLSLayer extends StreamLayer {
public TLSLayer(TLSContextFactory factory) {
context = factory.createTLSContext();
- context.onDataForNetwork.connect(new Slot1<ByteArray>() {
+ context.onDataForNetwork.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
writeDataToChildLayer(p1);
}
});
- context.onDataForApplication.connect(new Slot1<ByteArray>() {
+ context.onDataForApplication.connect(new Slot1<SafeByteArray>() {
- public void call(ByteArray p1) {
+ public void call(SafeByteArray p1) {
writeDataToParentLayer(p1);
}
});
@@ -44,11 +44,11 @@ public class TLSLayer extends StreamLayer {
context.connect();
}
- public void writeData(ByteArray data) {
+ public void writeData(SafeByteArray data) {
context.handleDataFromApplication(data);
}
- public void handleDataRead(ByteArray data) {
+ public void handleDataRead(SafeByteArray data) {
context.handleDataFromNetwork(data);
}
@@ -72,7 +72,7 @@ public class TLSLayer extends StreamLayer {
return context;
}
- public final Signal onError = new Signal();
+ public final Signal onError = new Signal();//needs port
public final Signal onConnected = new Signal();
private final TLSContext context;
diff --git a/src/com/isode/stroke/streamstack/WhitespacePingLayer.java b/src/com/isode/stroke/streamstack/WhitespacePingLayer.java
index 53c360a..3a1805c 100644
--- a/src/com/isode/stroke/streamstack/WhitespacePingLayer.java
+++ b/src/com/isode/stroke/streamstack/WhitespacePingLayer.java
@@ -9,7 +9,7 @@
*/
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.network.Timer;
import com.isode.stroke.network.TimerFactory;
import com.isode.stroke.signals.Slot;
@@ -28,17 +28,17 @@ public class WhitespacePingLayer extends StreamLayer {
});
}
- public void writeData(ByteArray data) {
+ public void writeData(SafeByteArray data) {
writeDataToChildLayer(data);
}
- public void handleDataRead(ByteArray data) {
+ public void handleDataRead(SafeByteArray data) {
writeDataToParentLayer(data);
}
private void handleTimerTick() {
timer.stop();
- writeDataToChildLayer(new ByteArray(" "));
+ writeDataToChildLayer(new SafeByteArray(" "));
timer.start();
}
diff --git a/src/com/isode/stroke/streamstack/XMPPLayer.java b/src/com/isode/stroke/streamstack/XMPPLayer.java
index 4e7a265..6d14b9b 100644
--- a/src/com/isode/stroke/streamstack/XMPPLayer.java
+++ b/src/com/isode/stroke/streamstack/XMPPLayer.java
@@ -4,7 +4,7 @@
*/
package com.isode.stroke.streamstack;
-import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.elements.Element;
import com.isode.stroke.elements.ProtocolHeader;
import com.isode.stroke.elements.StreamType;
@@ -25,8 +25,8 @@ import com.isode.stroke.signals.Signal1;
public class XMPPLayer implements HighLayer, XMPPParserClient {
public final Signal1<ProtocolHeader> onStreamStart = new Signal1<ProtocolHeader>();
public final Signal1<Element> onElement = new Signal1<Element>();
- public final Signal1<ByteArray> onWriteData = new Signal1<ByteArray>();
- public final Signal1<ByteArray> onDataRead = new Signal1<ByteArray>();
+ public final Signal1<SafeByteArray> onWriteData = new Signal1<SafeByteArray>();
+ public final Signal1<SafeByteArray> onDataRead = new Signal1<SafeByteArray>();
public final Signal onError = new Signal();
private PayloadParserFactoryCollection payloadParserFactories_;
@@ -59,19 +59,19 @@ public class XMPPLayer implements HighLayer, XMPPParserClient {
}
public void writeHeader(ProtocolHeader header) {
- writeDataInternal(new ByteArray(xmppSerializer_.serializeHeader(header)));
+ writeDataInternal(new SafeByteArray(xmppSerializer_.serializeHeader(header)));
}
public void writeFooter() {
- writeDataInternal(new ByteArray(xmppSerializer_.serializeFooter()));
+ writeDataInternal(new SafeByteArray(xmppSerializer_.serializeFooter()));
}
public void writeElement(Element element) {
- writeDataInternal(new ByteArray(xmppSerializer_.serializeElement(element)));
+ writeDataInternal(new SafeByteArray(xmppSerializer_.serializeElement(element)));
}
public void writeData(String data) {
- writeDataInternal(new ByteArray(data));
+ writeDataInternal(new SafeByteArray(data));
}
public void resetParser() {
@@ -87,11 +87,11 @@ public class XMPPLayer implements HighLayer, XMPPParserClient {
* Should be protected, but can't because of interface implementation.
* @param data
*/
- public void handleDataRead(ByteArray data) {
+ public void handleDataRead(SafeByteArray data) {
handleDataReadInternal(data);
}
- protected void writeDataInternal(ByteArray data) {
+ protected void writeDataInternal(SafeByteArray data) {
onWriteData.emit(data);
writeDataToChildLayer(data);
}
@@ -115,16 +115,16 @@ public class XMPPLayer implements HighLayer, XMPPParserClient {
/* Multiple-inheritance workarounds */
private StreamLayer fakeStreamLayer_ = new StreamLayer() {
- public void writeData(ByteArray data) {
+ public void writeData(SafeByteArray data) {
throw new UnsupportedOperationException("Not supported yet.");
}
- public void handleDataRead(ByteArray data) {
+ public void handleDataRead(SafeByteArray data) {
handleDataReadInternal(data);
}
};
- private void handleDataReadInternal(ByteArray data) {
+ private void handleDataReadInternal(SafeByteArray data) {
onDataRead.emit(data);
inParser_ = true;
if(!xmppParser_.parse(data.toString())) {
@@ -146,7 +146,7 @@ public class XMPPLayer implements HighLayer, XMPPParserClient {
fakeStreamLayer_.setChildLayer(childLayer);
}
- public void writeDataToChildLayer(ByteArray data) {
+ public void writeDataToChildLayer(SafeByteArray data) {
fakeStreamLayer_.writeDataToChildLayer(data);
}
}
diff --git a/src/com/isode/stroke/tls/TLSContext.java b/src/com/isode/stroke/tls/TLSContext.java
index 738c8b6..3f5e8d7 100644
--- a/src/com/isode/stroke/tls/TLSContext.java
+++ b/src/com/isode/stroke/tls/TLSContext.java
@@ -12,6 +12,7 @@ package com.isode.stroke.tls;
import java.util.List;
import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.signals.Signal;
import com.isode.stroke.signals.Signal1;
@@ -21,8 +22,8 @@ public abstract class TLSContext {
public abstract boolean setClientCertificate(CertificateWithKey cert);
- public abstract void handleDataFromNetwork(ByteArray data);
- public abstract void handleDataFromApplication(ByteArray data);
+ public abstract void handleDataFromNetwork(SafeByteArray data);
+ public abstract void handleDataFromApplication(SafeByteArray data);
/**
* The peer certificate, as presented by the remote entity
@@ -38,8 +39,8 @@ public abstract class TLSContext {
public abstract ByteArray getFinishMessage();
- public Signal1<ByteArray> onDataForNetwork = new Signal1<ByteArray>();
- public Signal1<ByteArray> onDataForApplication = new Signal1<ByteArray>();
+ public Signal1<SafeByteArray> onDataForNetwork = new Signal1<SafeByteArray>();
+ public Signal1<SafeByteArray> onDataForApplication = new Signal1<SafeByteArray>();
public Signal onError = new Signal();
public Signal onConnected = new Signal();
}
diff --git a/src/com/isode/stroke/tls/java/JSSEContext.java b/src/com/isode/stroke/tls/java/JSSEContext.java
index da8316a..17b7d4d 100644
--- a/src/com/isode/stroke/tls/java/JSSEContext.java
+++ b/src/com/isode/stroke/tls/java/JSSEContext.java
@@ -45,6 +45,7 @@ import javax.net.ssl.SSLException;
import javax.net.ssl.X509ExtendedKeyManager;
import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.tls.CAPICertificate;
import com.isode.stroke.tls.Certificate;
import com.isode.stroke.tls.CertificateVerificationError;
@@ -238,7 +239,7 @@ public class JSSEContext extends TLSContext {
int bytesToUnwrap = 0;
int lastConsumed = 0;
HandshakeStatus handshakeStatus = null;
- ByteArray byteArray = null;
+ SafeByteArray byteArray = null;
synchronized(recvMutex) {
try {
@@ -353,7 +354,7 @@ public class JSSEContext extends TLSContext {
byte[] result = new byte[unwrappedReceived.remaining()];
unwrappedReceived.get(result);
unwrappedReceived.compact();
- byteArray = new ByteArray(result);
+ byteArray = new SafeByteArray(result);
}
}
@@ -377,7 +378,7 @@ public class JSSEContext extends TLSContext {
private int wrapAndSendData() {
int bytesSentToSocket = 0;
- ByteArray byteArray = null;
+ SafeByteArray byteArray = null;
SSLEngineResult sslEngineResult = null;
Status status = null;
HandshakeStatus handshakeStatus = null;
@@ -394,7 +395,7 @@ public class JSSEContext extends TLSContext {
if (wrappedToSend.hasRemaining()) {
byte[] b = new byte[(wrappedToSend.remaining())];
wrappedToSend.get(b);
- byteArray = new ByteArray(b);
+ byteArray = new SafeByteArray(b);
}
wrappedToSend.compact();
} /* end synchronized */
@@ -480,7 +481,7 @@ public class JSSEContext extends TLSContext {
if (wrappedToSend.hasRemaining()) {
byte[] b = new byte[(wrappedToSend.remaining())];
wrappedToSend.get(b);
- byteArray = new ByteArray(b);
+ byteArray = new SafeByteArray(b);
}
wrappedToSend.compact();
break;
@@ -917,7 +918,7 @@ public class JSSEContext extends TLSContext {
}
@Override
- public void handleDataFromNetwork(ByteArray data) {
+ public void handleDataFromNetwork(SafeByteArray data) {
if (hasError()) {
/* We have previously seen, and reported, an error. Emit again */
onError.emit();
@@ -995,7 +996,7 @@ public class JSSEContext extends TLSContext {
}
@Override
- public void handleDataFromApplication(ByteArray data) {
+ public void handleDataFromApplication(SafeByteArray data) {
if (hasError()) {
/* We have previously seen, and reported, an error. Emit again */
onError.emit();