From ef4438a0ede0394736f8abdbcf4fa24b712ec7eb Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Tue, 12 Mar 2013 14:18:53 +0100 Subject: Break the classes into core classes that deal with handling the backend logic, the fragment and rest. LaunchVPN, MainActivity, ConfigConvert are public API that is recorded in shortcuts, launchers etc. Moving them would break public API. Also VPNProfile belongs into core but since the reading VPN Profiles depends on the class name keep it in the main package. --HG-- rename : src/de/blinkt/openvpn/CIDRIP.java => src/de/blinkt/openvpn/core/CIDRIP.java rename : src/de/blinkt/openvpn/ConfigParser.java => src/de/blinkt/openvpn/core/ConfigParser.java rename : src/de/blinkt/openvpn/NetworkSateReceiver.java => src/de/blinkt/openvpn/core/NetworkSateReceiver.java rename : src/de/blinkt/openvpn/OpenVPN.java => src/de/blinkt/openvpn/core/OpenVPN.java rename : src/de/blinkt/openvpn/OpenVPNMangement.java => src/de/blinkt/openvpn/core/OpenVPNMangement.java rename : src/de/blinkt/openvpn/OpenVPNThread.java => src/de/blinkt/openvpn/core/OpenVPNThread.java rename : src/de/blinkt/openvpn/OpenVpnManagementThread.java => src/de/blinkt/openvpn/core/OpenVpnManagementThread.java rename : src/de/blinkt/openvpn/OpenVpnService.java => src/de/blinkt/openvpn/core/OpenVpnService.java rename : src/de/blinkt/openvpn/ProfileManager.java => src/de/blinkt/openvpn/core/ProfileManager.java rename : src/de/blinkt/openvpn/ProxyDetection.java => src/de/blinkt/openvpn/core/ProxyDetection.java rename : src/de/blinkt/openvpn/VPNLaunchHelper.java => src/de/blinkt/openvpn/core/VPNLaunchHelper.java rename : src/de/blinkt/openvpn/AboutFragment.java => src/de/blinkt/openvpn/fragments/AboutFragment.java rename : src/de/blinkt/openvpn/FaqFragment.java => src/de/blinkt/openvpn/fragments/FaqFragment.java rename : src/de/blinkt/openvpn/FileSelectionFragment.java => src/de/blinkt/openvpn/fragments/FileSelectionFragment.java rename : src/de/blinkt/openvpn/GeneralSettings.java => src/de/blinkt/openvpn/fragments/GeneralSettings.java rename : src/de/blinkt/openvpn/InlineFileTab.java => src/de/blinkt/openvpn/fragments/InlineFileTab.java rename : src/de/blinkt/openvpn/OpenVpnPreferencesFragment.java => src/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java rename : src/de/blinkt/openvpn/SendDumpFragment.java => src/de/blinkt/openvpn/fragments/SendDumpFragment.java rename : src/de/blinkt/openvpn/Settings_Authentication.java => src/de/blinkt/openvpn/fragments/Settings_Authentication.java rename : src/de/blinkt/openvpn/Settings_Basic.java => src/de/blinkt/openvpn/fragments/Settings_Basic.java rename : src/de/blinkt/openvpn/Settings_IP.java => src/de/blinkt/openvpn/fragments/Settings_IP.java rename : src/de/blinkt/openvpn/Settings_Obscure.java => src/de/blinkt/openvpn/fragments/Settings_Obscure.java rename : src/de/blinkt/openvpn/Settings_Routing.java => src/de/blinkt/openvpn/fragments/Settings_Routing.java rename : src/de/blinkt/openvpn/ShowConfigFragment.java => src/de/blinkt/openvpn/fragments/ShowConfigFragment.java rename : src/de/blinkt/openvpn/VPNProfileList.java => src/de/blinkt/openvpn/fragments/VPNProfileList.java --- src/de/blinkt/openvpn/core/CIDRIP.java | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/de/blinkt/openvpn/core/CIDRIP.java (limited to 'src/de/blinkt/openvpn/core/CIDRIP.java') diff --git a/src/de/blinkt/openvpn/core/CIDRIP.java b/src/de/blinkt/openvpn/core/CIDRIP.java new file mode 100644 index 00000000..27ce414c --- /dev/null +++ b/src/de/blinkt/openvpn/core/CIDRIP.java @@ -0,0 +1,66 @@ +package de.blinkt.openvpn.core; + +import java.util.Locale; + +class CIDRIP{ + String mIp; + int len; + + + public CIDRIP(String ip, String mask){ + mIp=ip; + long netmask=getInt(mask); + + // Add 33. bit to ensure the loop terminates + netmask += 1l << 32; + + int lenZeros = 0; + while((netmask & 0x1) == 0) { + lenZeros++; + netmask = netmask >> 1; + } + // Check if rest of netmask is only 1s + if(netmask != (0x1ffffffffl >> lenZeros)) { + // Asume no CIDR, set /32 + len=32; + } else { + len =32 -lenZeros; + } + + } + public CIDRIP(String address, int prefix_length) { + len = prefix_length; + mIp = address; + } + @Override + public String toString() { + return String.format(Locale.ENGLISH,"%s/%d",mIp,len); + } + + public boolean normalise(){ + long ip=getInt(mIp); + + long newip = ip & (0xffffffffl << (32 -len)); + if (newip != ip){ + mIp = String.format("%d.%d.%d.%d", (newip & 0xff000000) >> 24,(newip & 0xff0000) >> 16, (newip & 0xff00) >> 8 ,newip & 0xff); + return true; + } else { + return false; + } + } + static long getInt(String ipaddr) { + String[] ipt = ipaddr.split("\\."); + long ip=0; + + ip += Long.parseLong(ipt[0])<< 24; + ip += Integer.parseInt(ipt[1])<< 16; + ip += Integer.parseInt(ipt[2])<< 8; + ip += Integer.parseInt(ipt[3]); + + return ip; + } + public long getInt() { + return getInt(mIp); + } + +} \ No newline at end of file -- cgit v1.2.3