- try {
- // continue iff one of the two resolves
- try { InetAddress.getByName("xwt-proxy-httpHost"); }
- catch (UnknownHostException e) { InetAddress.getByName("xwt-proxy-socksHost"); }
-
- if (Log.on) Log.log(Platform.class, "using xwt-proxy-* configuration");
- ProxyInfo ret = new ProxyInfo();
- try {
- ret.httpProxyHost = InetAddress.getByName("xwt-proxy-httpHost").getHostAddress();
- byte[] quadbyte = InetAddress.getByName("xwt-proxy-httpPort").getAddress();
- ret.httpProxyPort = ((quadbyte[1] & 0xff) * 10000) + ((quadbyte[2] & 0xff) * 100) + (quadbyte[3] & 0xff);
- } catch (UnknownHostException e) { }
- try {
- ret.httpsProxyHost = InetAddress.getByName("xwt-proxy-httpsHost").getHostAddress();
- byte[] quadbyte = InetAddress.getByName("xwt-proxy-httpsPort").getAddress();
- ret.httpsProxyPort = ((quadbyte[1] & 0xff) * 10000) + ((quadbyte[2] & 0xff) * 100) + (quadbyte[3] & 0xff);
- } catch (UnknownHostException e) { }
- try {
- ret.socksProxyHost = InetAddress.getByName("xwt-proxy-socksHost").getHostAddress();
- byte[] quadbyte = InetAddress.getByName("xwt-proxy-socksPort").getAddress();
- ret.socksProxyPort = ((quadbyte[1] & 0xff) * 10000) + ((quadbyte[2] & 0xff) * 100) + (quadbyte[3] & 0xff);
- } catch (UnknownHostException e) { }
- return ret;
- } catch (UnknownHostException e) {
- if (Log.on) Log.log(Platform.class, "xwt-proxy-* detection failed due to: " + e);
- return null;
+ ProxyInfo ret = new ProxyInfo();
+
+ ret.httpProxyHost = Platform.getEnv("http_proxy");
+ if (ret.httpProxyHost != null) {
+ if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7);
+ if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1);
+ if (ret.httpProxyHost.indexOf(':') != -1) {
+ ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1));
+ ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':'));
+ } else {
+ ret.httpProxyPort = 80;
+ }
+ }
+
+ ret.httpsProxyHost = Platform.getEnv("https_proxy");
+ if (ret.httpsProxyHost != null) {
+ if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7);
+ if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1);
+ if (ret.httpsProxyHost.indexOf(':') != -1) {
+ ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1));
+ ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':'));
+ } else {
+ ret.httpsProxyPort = 80;
+ }
+ }
+
+ ret.socksProxyHost = Platform.getEnv("socks_proxy");
+ if (ret.socksProxyHost != null) {
+ if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7);
+ if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1);
+ if (ret.socksProxyHost.indexOf(':') != -1) {
+ ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1));
+ ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':'));
+ } else {
+ ret.socksProxyPort = 80;
+ }