From c767a06a53230ec3829a6ad76b1201a20fae76fa Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 4 Jan 2013 15:03:19 +0100 Subject: remote overrides port and proto options (Closes issue #128) --- src/de/blinkt/openvpn/ConfigParser.java | 51 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'src/de') diff --git a/src/de/blinkt/openvpn/ConfigParser.java b/src/de/blinkt/openvpn/ConfigParser.java index 37741937..4eeaee86 100644 --- a/src/de/blinkt/openvpn/ConfigParser.java +++ b/src/de/blinkt/openvpn/ConfigParser.java @@ -327,19 +327,23 @@ public class ConfigParser { if(!mode.get(1).equals("p2p")) throw new ConfigParseError("Invalid mode for --mode specified, need p2p"); } + + Vector port = getOption("port", 1,1); + if(port!=null){ + np.mServerPort = port.get(1); + } + + Vector proto = getOption("proto", 1,1); + if(proto!=null){ + np.mUseUdp=isUdpProto(proto.get(1));; + } // Parse remote config Vector remote = getOption("remote",1,3); if(remote != null){ switch (remote.size()) { case 4: - String proto = remote.get(3); - if(proto.equals("udp")) - np.mUseUdp=true; - else if (proto.equals("tcp")) - np.mUseUdp=false; - else - throw new ConfigParseError("remote protocol must be tcp or udp"); + np.mUseUdp=isUdpProto(remote.get(3)); case 3: np.mServerPort = remote.get(2); case 2: @@ -347,25 +351,6 @@ public class ConfigParser { } } - Vector port = getOption("port", 1,1); - if(port!=null){ - np.mServerPort = port.get(1); - } - - Vector proto = getOption("proto", 1,1); - if(proto!=null){ - if(proto.get(1).equals("udp") || proto.get(1).equals("udp6")) - np.mUseUdp=true; - else if (proto.get(1).equals("tcp-client") || - proto.get(1).equals("tcp") || - proto.get(1).equals("tcp6") || - proto.get(1).endsWith("tcp6-client")) - np.mUseUdp=false; - else - throw new ConfigParseError("Unsupported option to --proto " + proto.get(1)); - - } - Vector> dhcpoptions = getAllOption("dhcp-option", 2, 2); if(dhcpoptions!=null) { for(Vector dhcpoption:dhcpoptions) { @@ -483,6 +468,20 @@ public class ConfigParser { return np; } + + private boolean isUdpProto(String proto) throws ConfigParseError { + boolean isudp; + if(proto.equals("udp") || proto.equals("udp6")) + isudp=true; + else if (proto.equals("tcp-client") || + proto.equals("tcp") || + proto.equals("tcp6") || + proto.endsWith("tcp6-client")) + isudp =false; + else + throw new ConfigParseError("Unsupported option to --proto " + proto); + return isudp; + } static public void useEmbbedUserAuth(VpnProfile np,String inlinedata) { -- cgit v1.2.3