diff options
Diffstat (limited to 'src')
5 files changed, 42 insertions, 19 deletions
diff --git a/src/com/isode/stroke/network/DummyTimerFactory.java b/src/com/isode/stroke/network/DummyTimerFactory.java index f3d083f..b4695f0 100644 --- a/src/com/isode/stroke/network/DummyTimerFactory.java +++ b/src/com/isode/stroke/network/DummyTimerFactory.java @@ -19,7 +19,7 @@ public class DummyTimerFactory implements TimerFactory { private int currentTime; private List<DummyTimer> timers = new ArrayList<DummyTimer>(); - public class DummyTimer extends Timer { + public static class DummyTimer extends Timer { public DummyTimer(long timeout, DummyTimerFactory factory) { this.timeout = timeout; diff --git a/src/com/isode/stroke/network/EnvironmentProxyProvider.java b/src/com/isode/stroke/network/EnvironmentProxyProvider.java index b12fe98..b36d567 100644 --- a/src/com/isode/stroke/network/EnvironmentProxyProvider.java +++ b/src/com/isode/stroke/network/EnvironmentProxyProvider.java @@ -43,9 +43,13 @@ public class EnvironmentProxyProvider implements ProxyProvider { proxyProtocol += "://"; address = envVar != null ? envVar : "0.0.0.0"; - if(envVar != null && address.substring(0, proxyProtocol.length()).equals(proxyProtocol)) { + if(envVar != null && address.startsWith(proxyProtocol)) { address = address.substring(proxyProtocol.length(), address.length()); - port = Integer.parseInt(address.substring(address.indexOf(':') + 1, address.length())); + try { + port = Integer.parseInt(address.substring(address.indexOf(':') + 1, address.length())); + } catch (NumberFormatException e) { + port = 0; + } address = address.substring(0, address.indexOf(':')); } diff --git a/src/com/isode/stroke/network/HTTPConnectProxiedConnection.java b/src/com/isode/stroke/network/HTTPConnectProxiedConnection.java index d9a6cee..a85758c 100644 --- a/src/com/isode/stroke/network/HTTPConnectProxiedConnection.java +++ b/src/com/isode/stroke/network/HTTPConnectProxiedConnection.java @@ -18,6 +18,8 @@ package com.isode.stroke.network; import com.isode.stroke.base.SafeByteArray; import com.isode.stroke.stringcodecs.Base64; + +import java.util.Scanner; import java.util.Vector; public class HTTPConnectProxiedConnection extends ProxiedConnection { @@ -69,8 +71,7 @@ public class HTTPConnectProxiedConnection extends ProxiedConnection { String dataString = data.toString(); //SWIFT_LOG(debug) << data << std::endl; httpResponseBuffer_.append(dataString); - - String statusLine = ""; + Vector<Pair> headerFields = new Vector<Pair>(); int headerEnd = httpResponseBuffer_.indexOf("\r\n\r\n", 0); @@ -81,7 +82,7 @@ public class HTTPConnectProxiedConnection extends ProxiedConnection { return; } - parseHTTPHeader(httpResponseBuffer_.substring(0, headerEnd), statusLine, headerFields); + String statusLine = parseHTTPHeader(httpResponseBuffer_.substring(0, headerEnd), headerFields); if (trafficFilter_ != null) { Vector<Pair> newHeaderFields = trafficFilter_.filterHTTPResponseHeader(headerFields); @@ -128,21 +129,29 @@ public class HTTPConnectProxiedConnection extends ProxiedConnection { write(new SafeByteArray(request.toString())); } - private void parseHTTPHeader(final String data, String statusLine, Vector<Pair> headerFields) { - StringBuffer dataStream = new StringBuffer(data); + private String parseHTTPHeader(final String data, Vector<Pair> headerFields) { + Scanner dataScanner = new Scanner(data); + String statusLine = ""; // parse status line - statusLine = dataStream.toString(); + if (dataScanner.hasNext()) { + statusLine = dataScanner.nextLine(); + } + // parse fields - String headerLine = dataStream.toString(); - int splitIndex; - while (headerLine != null && !headerLine.equals("\r")) { - splitIndex = headerLine.indexOf(':', 0); + while (dataScanner.hasNext()) { + String headerLine = dataScanner.nextLine(); + if (headerLine.equals("\r")) { + break; + } + int splitIndex = headerLine.indexOf(':', 0); if (splitIndex != -1) { headerFields.add(new Pair(headerLine.substring(0, splitIndex), headerLine.substring(splitIndex + 1))); } } + + return statusLine; } }
\ No newline at end of file diff --git a/src/com/isode/stroke/network/JavaProxyProvider.java b/src/com/isode/stroke/network/JavaProxyProvider.java index e2804a3..024efa7 100644 --- a/src/com/isode/stroke/network/JavaProxyProvider.java +++ b/src/com/isode/stroke/network/JavaProxyProvider.java @@ -13,7 +13,7 @@ package com.isode.stroke.network; public class JavaProxyProvider implements ProxyProvider { - private EnvironmentProxyProvider environmentProxyProvider; + private EnvironmentProxyProvider environmentProxyProvider = new EnvironmentProxyProvider(); public JavaProxyProvider() { diff --git a/src/com/isode/stroke/network/TLSConnection.java b/src/com/isode/stroke/network/TLSConnection.java index 16c6617..a67f20d 100644 --- a/src/com/isode/stroke/network/TLSConnection.java +++ b/src/com/isode/stroke/network/TLSConnection.java @@ -86,10 +86,18 @@ public class TLSConnection extends Connection { protected void finalize() throws Throwable { try { - onConnectFinishedConnection.disconnect(); - onDataReadConnection.disconnect(); - onDataWrittenConnection.disconnect(); - onDisconnectedConnection.disconnect(); + if (onConnectFinished != null) { + onConnectFinishedConnection.disconnect(); + } + if (onDataReadConnection != null) { + onDataReadConnection.disconnect(); + } + if (onDataWrittenConnection != null) { + onDataWrittenConnection.disconnect(); + } + if (onDisconnectedConnection != null) { + onDisconnectedConnection.disconnect(); + } } finally { super.finalize(); @@ -117,7 +125,9 @@ public class TLSConnection extends Connection { } private void handleRawConnectFinished(boolean error) { - onConnectFinishedConnection.disconnect(); + if (onConnectFinished != null) { + onConnectFinishedConnection.disconnect(); + } if (error) { onConnectFinished.emit(true); } |