summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/base/ByteArray.java10
-rw-r--r--src/com/isode/stroke/base/SafeByteArray.java10
-rw-r--r--src/com/isode/stroke/filetransfer/ByteArrayReadBytestream.java10
-rw-r--r--src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java3
-rw-r--r--src/com/isode/stroke/filetransfer/SOCKS5BytestreamClientSession.java15
-rw-r--r--src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerSession.java17
-rw-r--r--src/com/isode/stroke/network/DummyNetworkEnvironment.java32
7 files changed, 76 insertions, 21 deletions
diff --git a/src/com/isode/stroke/base/ByteArray.java b/src/com/isode/stroke/base/ByteArray.java
index 997cc6e..f1181f5 100644
--- a/src/com/isode/stroke/base/ByteArray.java
+++ b/src/com/isode/stroke/base/ByteArray.java
@@ -3,7 +3,7 @@
* All rights reserved.
*/
/*
- * Copyright (c) 2010-2015, Isode Limited, London, England.
+ * Copyright (c) 2010-2016, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.base;
@@ -61,6 +61,14 @@ public class ByteArray {
public ByteArray(ByteArray b) {
append(b);
}
+
+ /**
+ * Constructs a new {@link ByteArray} containing the user supplied byte.
+ * @param b a byte.
+ */
+ public ByteArray(byte b) {
+ append(b);
+ }
/*public ByteArray(char[] c, int n) {
for (int i = 0; i < n; i++) {
diff --git a/src/com/isode/stroke/base/SafeByteArray.java b/src/com/isode/stroke/base/SafeByteArray.java
index 437346f..f07cbe1 100644
--- a/src/com/isode/stroke/base/SafeByteArray.java
+++ b/src/com/isode/stroke/base/SafeByteArray.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2015, Isode Limited, London, England.
+ * Copyright (c) 2011-2016, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.base;
@@ -34,6 +34,14 @@ public class SafeByteArray extends ByteArray {
public SafeByteArray(byte[] c) {
super(c);
}
+
+ /**
+ * Constructs a new {@link SafeByteArray} containing the user supplied byte.
+ * @param b a byte.
+ */
+ public SafeByteArray(byte b) {
+ super(b);
+ }
/**
* Creates a new SafeByteArray object containing all
diff --git a/src/com/isode/stroke/filetransfer/ByteArrayReadBytestream.java b/src/com/isode/stroke/filetransfer/ByteArrayReadBytestream.java
index 41528fa..5b3542f 100644
--- a/src/com/isode/stroke/filetransfer/ByteArrayReadBytestream.java
+++ b/src/com/isode/stroke/filetransfer/ByteArrayReadBytestream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -11,6 +11,8 @@
package com.isode.stroke.filetransfer;
+import java.util.Arrays;
+
import com.isode.stroke.base.ByteArray;
public class ByteArrayReadBytestream extends ReadBytestream {
@@ -30,9 +32,9 @@ public class ByteArrayReadBytestream extends ReadBytestream {
if (position + readSize > data.getSize()) {
readSize = data.getSize() - position;
}
- String s = data.toString();
- s = s.substring(position, position+readSize);
- ByteArray result = new ByteArray(s);
+ byte[] rawBytes = data.getData();
+ byte[] resultRawBytes = Arrays.copyOfRange(rawBytes, position, position+readSize);
+ ByteArray result = new ByteArray(resultRawBytes);
onRead.emit(result);
position += readSize;
diff --git a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java
index 10760a1..c5a1f11 100644
--- a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java
+++ b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java
@@ -4,7 +4,7 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
- * Copyright (c) 2013-2015 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -100,6 +100,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
this.idGenerator = idGenerator;
this.stream = stream;
this.fileInfo = fileInfo;
+ this.options = options;
this.session = session;
this.contentID = new JingleContentID(idGenerator.generateID(), JingleContentPayload.Creator.InitiatorCreator);
this.state = State.Initial;
diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamClientSession.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamClientSession.java
index 3e51b5f..18e4484 100644
--- a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamClientSession.java
+++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamClientSession.java
@@ -55,7 +55,7 @@ public class SOCKS5BytestreamClientSession extends SOCKS5AbstractBytestreamSessi
private State state;
- private ByteArray unprocessedData;
+ private final ByteArray unprocessedData = new ByteArray();
private ByteArray authenticateAddress;
private int chunkSize;
@@ -227,12 +227,9 @@ public class SOCKS5BytestreamClientSession extends SOCKS5AbstractBytestreamSessi
private void authenticate() {
logger_.fine("\n");
- SafeByteArray header = new SafeByteArray(new byte[]{0x05, 0x01, 0x00, 0x03});
- SafeByteArray message = header;
- String destinationlength = Integer.toString(destination.length());
- message.append(new SafeByteArray(destinationlength));
- authenticateAddress = new ByteArray(destination);
- message.append(authenticateAddress);
+ SafeByteArray message = new SafeByteArray(new byte[]{0x05, 0x01, 0x00, 0x03});
+ message.append((byte)destination.length());
+ message.append(destination);
message.append(new SafeByteArray(new byte[]{0x00, 0x00})); // 2 byte for port
connection.write(message);
state = State.Authenticating;
@@ -324,7 +321,9 @@ public class SOCKS5BytestreamClientSession extends SOCKS5AbstractBytestreamSessi
private void closeConnection() {
connectFinishedConnection.disconnect();
- dataWrittenConnection.disconnect();
+ if (dataWrittenConnection != null) {
+ dataWrittenConnection.disconnect();
+ }
dataReadConnection.disconnect();
disconnectedConnection.disconnect();
connection.disconnect();
diff --git a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerSession.java b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerSession.java
index 8452e36..8facca0 100644
--- a/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerSession.java
+++ b/src/com/isode/stroke/filetransfer/SOCKS5BytestreamServerSession.java
@@ -15,6 +15,7 @@ import com.isode.stroke.network.Connection;
import com.isode.stroke.network.HostAddressPort;
import com.isode.stroke.base.ByteArray;
import com.isode.stroke.base.SafeByteArray;
+import com.isode.stroke.base.StartStoppable;
import com.isode.stroke.signals.SignalConnection;
import com.isode.stroke.signals.Signal1;
import com.isode.stroke.signals.Signal;
@@ -23,11 +24,11 @@ import com.isode.stroke.signals.Slot1;
import java.util.logging.Logger;
-public class SOCKS5BytestreamServerSession extends SOCKS5AbstractBytestreamSession {
+public class SOCKS5BytestreamServerSession extends SOCKS5AbstractBytestreamSession implements StartStoppable {
private Connection connection;
private SOCKS5BytestreamRegistry bytestreams;
- private ByteArray unprocessedData;
+ private ByteArray unprocessedData = new ByteArray();
private State state;
private int chunkSize;
private String streamID = "";
@@ -131,8 +132,12 @@ public class SOCKS5BytestreamServerSession extends SOCKS5AbstractBytestreamSess
disconnectedConnection.disconnect();
dataReadConnection.disconnect();
- dataWrittenConnection.disconnect();
- dataAvailableConnection.disconnect();
+ if (dataWrittenConnection != null) {
+ dataWrittenConnection.disconnect();
+ }
+ if (dataAvailableConnection != null) {
+ dataAvailableConnection.disconnect();
+ }
readBytestream = null;
state = State.Finished;
if (error) {
@@ -180,10 +185,10 @@ public class SOCKS5BytestreamServerSession extends SOCKS5AbstractBytestreamSess
unprocessedData.clear();
streamID = requestID.toString();
boolean hasBytestream = bytestreams.hasBytestream(streamID);
- SafeByteArray result = new SafeByteArray("0x05");
+ SafeByteArray result = new SafeByteArray((byte)0x05);
result.append(hasBytestream ? (byte)0x0 : (byte)0x4);
result.append(new ByteArray(new byte[]{0x00, 0x03}));
- result.append(Integer.toString(requestID.getSize()));
+ result.append((byte)requestID.getSize());
result.append(requestID.append(new ByteArray(new byte[]{0x00, 0x00})));
if (!hasBytestream) {
logger_.fine("Readstream or Wrtiestream with ID " + streamID + " not found!\n");
diff --git a/src/com/isode/stroke/network/DummyNetworkEnvironment.java b/src/com/isode/stroke/network/DummyNetworkEnvironment.java
new file mode 100644
index 0000000..32524d9
--- /dev/null
+++ b/src/com/isode/stroke/network/DummyNetworkEnvironment.java
@@ -0,0 +1,32 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.network;
+
+import java.util.Vector;
+
+/**
+ * Dummy {@link NetworkEnvironment} for testing, returns an empty vector
+ * of {@link NetworkInterface}
+ */
+public class DummyNetworkEnvironment extends NetworkEnvironment {
+
+ /**
+ * Constructor
+ */
+ public DummyNetworkEnvironment() {
+ // Empty Constructor
+ }
+
+ @Override
+ public Vector<NetworkInterface> getNetworkInterfaces() {
+ return new Vector<NetworkInterface>();
+ }
+
+}