summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/config
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/config')
-rw-r--r--app/src/main/java/com/wireguard/config/Attribute.java5
-rw-r--r--app/src/main/java/com/wireguard/config/Interface.java44
2 files changed, 47 insertions, 2 deletions
diff --git a/app/src/main/java/com/wireguard/config/Attribute.java b/app/src/main/java/com/wireguard/config/Attribute.java
index 7fbffa7f..5ce6431d 100644
--- a/app/src/main/java/com/wireguard/config/Attribute.java
+++ b/app/src/main/java/com/wireguard/config/Attribute.java
@@ -18,10 +18,11 @@ import java.util.regex.Pattern;
* The set of valid attributes for an interface or peer in a WireGuard configuration file.
*/
-enum Attribute {
+public enum Attribute {
ADDRESS("Address"),
ALLOWED_IPS("AllowedIPs"),
DNS("DNS"),
+ EXCLUDED_APPLICATIONS("ExcludedApplications"),
ENDPOINT("Endpoint"),
LISTEN_PORT("ListenPort"),
MTU("MTU"),
@@ -59,7 +60,7 @@ enum Attribute {
}
public static String[] stringToList(final String string) {
- if (string == null)
+ if (TextUtils.isEmpty(string))
return EMPTY_LIST;
return LIST_SEPARATOR_PATTERN.split(string.trim());
}
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java
index 824bb122..c3068dbb 100644
--- a/app/src/main/java/com/wireguard/config/Interface.java
+++ b/app/src/main/java/com/wireguard/config/Interface.java
@@ -16,6 +16,7 @@ import com.wireguard.crypto.Keypair;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -25,6 +26,7 @@ import java.util.List;
public class Interface {
private final List<InetNetwork> addressList;
private final List<InetAddress> dnsList;
+ private final List<String> excludedApplications;
private Keypair keypair;
private int listenPort;
private int mtu;
@@ -32,6 +34,7 @@ public class Interface {
public Interface() {
addressList = new ArrayList<>();
dnsList = new ArrayList<>();
+ excludedApplications = new ArrayList<>();
}
private void addAddresses(final String[] addresses) {
@@ -52,6 +55,12 @@ public class Interface {
}
}
+ private void addExcludedApplications(final String[] applications) {
+ if (applications != null && applications.length > 0) {
+ excludedApplications.addAll(Arrays.asList(applications));
+ }
+ }
+
private String getAddressString() {
if (addressList.isEmpty())
return null;
@@ -79,6 +88,16 @@ public class Interface {
return dnsList.toArray(new InetAddress[dnsList.size()]);
}
+ private String getExcludedApplicationsString() {
+ if (excludedApplications.isEmpty())
+ return null;
+ return Attribute.iterableToString(excludedApplications);
+ }
+
+ public String[] getExcludedApplications() {
+ return excludedApplications.toArray(new String[excludedApplications.size()]);
+ }
+
public int getListenPort() {
return listenPort;
}
@@ -120,6 +139,9 @@ public class Interface {
case DNS:
addDnses(key.parseList(line));
break;
+ case EXCLUDED_APPLICATIONS:
+ addExcludedApplications(key.parseList(line));
+ break;
case LISTEN_PORT:
setListenPortString(key.parse(line));
break;
@@ -144,6 +166,11 @@ public class Interface {
addDnses(Attribute.stringToList(dnsString));
}
+ private void setExcludedApplicationsString(final String applicationsString) {
+ excludedApplications.clear();
+ addExcludedApplications(Attribute.stringToList(applicationsString));
+ }
+
private void setListenPort(final int listenPort) {
this.listenPort = listenPort;
}
@@ -179,6 +206,8 @@ public class Interface {
sb.append(Attribute.ADDRESS.composeWith(addressList));
if (!dnsList.isEmpty())
sb.append(Attribute.DNS.composeWith(getDnsStrings()));
+ if (!excludedApplications.isEmpty())
+ sb.append(Attribute.EXCLUDED_APPLICATIONS.composeWith(excludedApplications));
if (listenPort != 0)
sb.append(Attribute.LISTEN_PORT.composeWith(listenPort));
if (mtu != 0)
@@ -202,6 +231,7 @@ public class Interface {
};
private String addresses;
private String dnses;
+ private String excludedApplications;
private String listenPort;
private String mtu;
private String privateKey;
@@ -219,11 +249,13 @@ public class Interface {
privateKey = in.readString();
listenPort = in.readString();
mtu = in.readString();
+ excludedApplications = in.readString();
}
public void commitData(final Interface parent) {
parent.setAddressString(addresses);
parent.setDnsString(dnses);
+ parent.setExcludedApplicationsString(excludedApplications);
parent.setPrivateKey(privateKey);
parent.setListenPortString(listenPort);
parent.setMtuString(mtu);
@@ -255,6 +287,11 @@ public class Interface {
}
@Bindable
+ public String getExcludedApplications() {
+ return excludedApplications;
+ }
+
+ @Bindable
public String getListenPort() {
return listenPort;
}
@@ -277,6 +314,7 @@ public class Interface {
protected void loadData(final Interface parent) {
addresses = parent.getAddressString();
dnses = parent.getDnsString();
+ excludedApplications = parent.getExcludedApplicationsString();
publicKey = parent.getPublicKey();
privateKey = parent.getPrivateKey();
listenPort = parent.getListenPortString();
@@ -293,6 +331,11 @@ public class Interface {
notifyPropertyChanged(BR.dnses);
}
+ public void setExcludedApplications(final String excludedApplications) {
+ this.excludedApplications = excludedApplications;
+ notifyPropertyChanged(BR.excludedApplications);
+ }
+
public void setListenPort(final String listenPort) {
this.listenPort = listenPort;
notifyPropertyChanged(BR.listenPort);
@@ -324,6 +367,7 @@ public class Interface {
dest.writeString(privateKey);
dest.writeString(listenPort);
dest.writeString(mtu);
+ dest.writeString(excludedApplications);
}
}
}