From 3e9846e7f4172926b1de2e16c20d8956f4f5cf98 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sat, 23 Feb 2013 12:23:36 +0100 Subject: Allow more remotes for special internal API use cases. --HG-- extra : rebase_source : dbe2f5929d246ece4f7de71022e96c2455aff3c3 --- src/de/blinkt/openvpn/ConfigParser.java | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/de/blinkt/openvpn/ConfigParser.java b/src/de/blinkt/openvpn/ConfigParser.java index 99e7ec93..e5713c3f 100644 --- a/src/de/blinkt/openvpn/ConfigParser.java +++ b/src/de/blinkt/openvpn/ConfigParser.java @@ -7,6 +7,8 @@ import java.util.HashMap; import java.util.Locale; import java.util.Vector; +import android.text.TextUtils; + //! Openvpn Config FIle Parser, probably not 100% accurate but close enough // And rember, this is valid :) @@ -17,8 +19,11 @@ public class ConfigParser { private HashMap>> options = new HashMap>>(); + + private boolean extraRemotesAsCustom=false; + public void parseConfig(Reader reader) throws IOException, ConfigParseError { - + BufferedReader br =new BufferedReader(reader); @@ -340,8 +345,10 @@ public class ConfigParser { } // Parse remote config - Vector remote = getOption("remote",1,3); - if(remote != null){ + Vector> remotes = getAllOption("remote",1,3); + + if(remotes!=null && remotes.size()>1 && extraRemotesAsCustom) { + Vector remote = remotes.get(0); switch (remote.size()) { case 4: np.mUseUdp=isUdpProto(remote.get(3)); @@ -351,6 +358,8 @@ public class ConfigParser { np.mServerName = remote.get(1); } } + + Vector> dhcpoptions = getAllOption("dhcp-option", 2, 2); if(dhcpoptions!=null) { @@ -468,12 +477,22 @@ public class ConfigParser { // Check the other options + if(remotes !=null && remotes.size()>1 && extraRemotesAsCustom) { + // first is already added + remotes.remove(0); + np.mCustomConfigOptions += getOptionStrings(remotes); + np.mUseCustomConfig=true; + } checkIgnoreAndInvalidOptions(np); fixup(np); return np; } + + public void useExtraRemotesAsCustom(boolean b) { + this.extraRemotesAsCustom = b; + } private boolean isUdpProto(String proto) throws ConfigParseError { boolean isudp; @@ -509,22 +528,27 @@ public class ConfigParser { options.remove(option); if(options.size()> 0) { - String custom = "# These Options were found in the config file do not map to config settings:\n"; + np.mCustomConfigOptions += "# These Options were found in the config file do not map to config settings:\n"; for(Vector> option:options.values()) { - for(Vector optionsline: option) { - for (String arg : optionsline) - custom+= VpnProfile.openVpnEscape(arg) + " "; - } - custom+="\n"; + np.mCustomConfigOptions += getOptionStrings(option); } - np.mCustomConfigOptions = custom; np.mUseCustomConfig=true; } } + private String getOptionStrings( Vector> option) { + String custom=""; + for(Vector optionsline: option) { + for (String arg : optionsline) + custom+= VpnProfile.openVpnEscape(arg) + " "; + custom+="\n"; + } + return custom; + } + private void fixup(VpnProfile np) { if(np.mRemoteCN.equals(np.mServerName)) { -- cgit v1.2.3