diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-02-24 23:55:03 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-08-19 00:30:43 +0200 |
commit | d87fefd1caa8dd8ffc4db607ce846a7bfa3c071e (patch) | |
tree | 2c9002939ef3c29e98c8f8a26b5c20c50ff7a950 /tunnel/src | |
parent | e22cc0235da95caee124a4a9bf5b7ec26b2012e3 (diff) |
tunnel: download pac in java
Diffstat (limited to 'tunnel/src')
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 35 | ||||
-rw-r--r-- | tunnel/src/main/proto/libwg.proto | 5 |
2 files changed, 36 insertions, 4 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java index 596bea7d..6afdfd95 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -59,6 +59,9 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.Inet4Address; import java.net.Inet6Address; @@ -287,12 +290,38 @@ public final class GoBackend implements Backend { return getState(tunnel); } - private int startHttpProxy(Uri pacFileUrl) { + private static String downloadPacFile(Network network, Uri pacFileUrl) { + HttpURLConnection urlConnection = null; + StringBuffer buf = new StringBuffer(); + try { + URL url = new URL(pacFileUrl.toString()); + urlConnection = (HttpURLConnection) network.openConnection(url); + + InputStream in = urlConnection.getInputStream(); + InputStreamReader isw = new InputStreamReader(in); + + int data = isw.read(); + while (data != -1) { + char current = (char) data; + data = isw.read(); + buf.append(current); + } + } catch (Exception e) { + } finally { + if (urlConnection != null) { + urlConnection.disconnect(); + } + } + + return buf.toString(); + } + + private int startHttpProxy(String pacFile) { LibwgGrpc.LibwgStub asyncStub = LibwgGrpc.newStub(channel); LibwgGrpc.LibwgBlockingStub stub = LibwgGrpc.newBlockingStub(channel); StartHttpProxyRequest.Builder reqBuilder = StartHttpProxyRequest.newBuilder(); - if (pacFileUrl != null && pacFileUrl != Uri.EMPTY) { - reqBuilder.setPacFileUrl(pacFileUrl.toString()); + if (pacFile != null && pacFile != "") { + reqBuilder.setPacFileContent(pacFile); } Thread streamer = new Thread(new Runnable() { diff --git a/tunnel/src/main/proto/libwg.proto b/tunnel/src/main/proto/libwg.proto index da6f6da4..c87eb9ef 100644 --- a/tunnel/src/main/proto/libwg.proto +++ b/tunnel/src/main/proto/libwg.proto @@ -50,7 +50,10 @@ message VersionResponse { } message StartHttpProxyRequest { - string pacFileUrl = 1; + oneof pacFile { + string pacFileUrl = 1; + string pacFileContent = 2; + } } message StartHttpProxyResponse { |