From 74eae55c878e031fa25971378abf0cadee7bbaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Chabot?= Date: Mon, 5 Mar 2018 23:47:07 +1100 Subject: [PATCH] Config: Handle multiple address or dns in config file Signed-off-by: Jason A. Donenfeld --- .../java/com/wireguard/config/Interface.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index 431f0e31..b13f78a0 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -90,9 +90,9 @@ public class Interface extends BaseObservable implements Parcelable { public void parse(final String line) { final Attribute key = Attribute.match(line); if (key == Attribute.ADDRESS) - setAddress(key.parse(line)); + addAddress(key.parse(line)); else if (key == Attribute.DNS) - setDns(key.parse(line)); + addDns(key.parse(line)); else if (key == Attribute.LISTEN_PORT) setListenPort(key.parse(line)); else if (key == Attribute.MTU) @@ -103,6 +103,13 @@ public class Interface extends BaseObservable implements Parcelable { throw new IllegalArgumentException(line); } + public void addAddress(String address) { + if (address != null && address.isEmpty()) + address = null; + setAddress((this.address == null) ? address + : this.address + ", " + address); + } + public void setAddress(String address) { if (address != null && address.isEmpty()) address = null; @@ -110,6 +117,13 @@ public class Interface extends BaseObservable implements Parcelable { notifyPropertyChanged(BR.address); } + public void addDns(String dns) { + if (dns != null && dns.isEmpty()) + dns = null; + setDns((this.dns == null) ? dns + : this.dns + ", " + dns); + } + public void setDns(String dns) { if (dns != null && dns.isEmpty()) dns = null;