-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt;
import java.net.*;
else doWebAuth(h, content == null ? "GET" : "POST");
if (h.get("HTTP").equals("1.0") && h.get("content-length") == null) {
- if (Log.on) Log.log(this, "proxy returned an HTTP/1.0 reply with no content-length...");
+ if (Log.on) Log.info(this, "proxy returned an HTTP/1.0 reply with no content-length...");
reset();
} else {
int cl = h.get("content-length") == null ? -1 : Integer.parseInt(h.get("content-length").toString());
/** Attempts a direct connection */
private Socket attemptDirect() {
try {
- if (Log.verbose) Log.log(this, "attempting to create unproxied socket to " +
+ if (Log.verbose) Log.info(this, "attempting to create unproxied socket to " +
host + ":" + port + (ssl ? " [ssl]" : ""));
return getSocket(host, port, ssl, true);
} catch (IOException e) {
- if (Log.on) Log.log(this, "exception in attemptDirect(): " + e);
+ if (Log.on) Log.info(this, "exception in attemptDirect(): " + e);
return null;
}
}
/** Attempts to use an HTTP proxy, employing the CONNECT method if HTTPS is requested */
private Socket attemptHttpProxy(String proxyHost, int proxyPort) {
try {
- if (Log.verbose) Log.log(this, "attempting to create HTTP proxied socket using proxy " + proxyHost + ":" + proxyPort);
+ if (Log.verbose) Log.info(this, "attempting to create HTTP proxied socket using proxy " + proxyHost + ":" + proxyPort);
Socket sock = getSocket(proxyHost, proxyPort, ssl, false);
if (!ssl) {
return sock;
} catch (IOException e) {
- if (Log.on) Log.log(this, "exception in attemptHttpProxy(): " + e);
+ if (Log.on) Log.info(this, "exception in attemptHttpProxy(): " + e);
return null;
}
}
InetAddress addr = null;
try { addr = InetAddress.getByName(host); } catch (Exception e) { }
- if (Log.verbose) Log.log(this, "attempting to create SOCKSv4" + (addr == null ? "" : "a") +
+ if (Log.verbose) Log.info(this, "attempting to create SOCKSv4" + (addr == null ? "" : "a") +
" proxied socket using proxy " + proxyHost + ":" + proxyPort);
try {
if (ssl) ((SSL)sock).negotiate();
return sock;
}
- if (Log.on) Log.log(this, "SOCKS server denied access, code " + (success & 0xff));
+ if (Log.on) Log.info(this, "SOCKS server denied access, code " + (success & 0xff));
return null;
} catch (IOException e) {
- if (Log.on) Log.log(this, "exception in attemptSocksProxy(): " + e);
+ if (Log.on) Log.info(this, "exception in attemptSocksProxy(): " + e);
return null;
}
}
/** executes the PAC script and dispatches a call to one of the other attempt methods based on the result */
private Socket attemptPAC(org.xwt.js.JS pacFunc) {
- if (Log.verbose) Log.log(this, "evaluating PAC script");
+ if (Log.verbose) Log.info(this, "evaluating PAC script");
String pac = null;
try {
org.xwt.js.JSArray args = new org.xwt.js.JSArray();
Object obj = pacFunc.call(url.toString(), url.getHost(), null, null, 2);
- if (Log.verbose) Log.log(this, " PAC script returned \"" + obj + "\"");
+ if (Log.verbose) Log.info(this, " PAC script returned \"" + obj + "\"");
pac = obj.toString();
} catch (Throwable e) {
- if (Log.on) Log.log(this, "PAC script threw exception " + e);
+ if (Log.on) Log.info(this, "PAC script threw exception " + e);
return null;
}
StringTokenizer st = new StringTokenizer(pac, ";", false);
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
- if (Log.verbose) Log.log(this, " trying \"" + token + "\"...");
+ if (Log.verbose) Log.info(this, " trying \"" + token + "\"...");
try {
Socket ret = null;
if (token.startsWith("DIRECT"))
Integer.parseInt(token.substring(token.indexOf(':') + 1)));
if (ret != null) return ret;
} catch (Throwable e) {
- if (Log.on) Log.log(this, "attempt at \"" + token + "\" failed due to " + e + "; trying next token");
+ if (Log.on) Log.info(this, "attempt at \"" + token + "\" failed due to " + e + "; trying next token");
}
}
- if (Log.on) Log.log(this, "all PAC results exhausted");
+ if (Log.on) Log.info(this, "all PAC results exhausted");
return null;
}
path = this.url.getFile();
if (port == -1) port = ssl ? 443 : 80;
host = this.url.getHost();
- if (Log.verbose) Log.log(this, "creating HTTP object for connection to " + host + ":" + port);
+ if (Log.verbose) Log.info(this, "creating HTTP object for connection to " + host + ":" + port);
Proxy pi = Platform.detectProxy();
OUTER: do {
if (pi != null) {
for(int i=0; i<pi.excluded.length; i++) if (host.equals(pi.excluded[i])) break OUTER;
- if (sock == null && pi.proxyAutoConfigJSFunction != null) sock = attemptPAC(pi.proxyAutoConfigJSFunction);
+ if (sock == null && pi.proxyAutoConfigFunction != null) sock = attemptPAC(pi.proxyAutoConfigFunction);
if (sock == null && ssl && pi.httpsProxyHost != null) sock = attemptHttpProxy(pi.httpsProxyHost,pi.httpsProxyPort);
if (sock == null && pi.httpProxyHost != null) sock = attemptHttpProxy(pi.httpProxyHost, pi.httpProxyPort);
if (sock == null && pi.socksProxyHost != null) sock = attemptSocksProxy(pi.socksProxyHost, pi.socksProxyPort);
}
private void doProxyAuth(Hashtable h0, String method) throws IOException {
- if (Log.on) Log.log(this, "Proxy AuthChallenge: " + h0.get("proxy-authenticate"));
+ if (Log.on) Log.info(this, "Proxy AuthChallenge: " + h0.get("proxy-authenticate"));
Hashtable h = parseAuthenticationChallenge(h0.get("proxy-authenticate").toString());
String style = h.get("AUTHTYPE").toString();
String realm = (String)h.get("realm");
if (style.equals("NTLM") && Proxy.Authorization.authorization2 == null) {
- Log.log(this, "Proxy identified itself as NTLM, sending Type 1 packet");
+ Log.info(this, "Proxy identified itself as NTLM, sending Type 1 packet");
Proxy.Authorization.authorization2 = "NTLM " + Base64.encode(Proxy.NTLM.type1);
return;
}
"algorithm=MD5";
} else if (style.equals("NTLM")) {
- Log.log(this, "Proxy identified itself as NTLM, got Type 2 packet");
+ Log.info(this, "Proxy identified itself as NTLM, got Type 2 packet");
byte[] type2 = Base64.decode(((String)h0.get("proxy-authenticate")).substring(5).trim());
for(int i=0; i<type2.length; i += 4) {
String log = "";
if (i+1<type2.length) log += Integer.toString(type2[i+1] & 0xff, 16) + " ";
if (i+2<type2.length) log += Integer.toString(type2[i+2] & 0xff, 16) + " ";
if (i+3<type2.length) log += Integer.toString(type2[i+3] & 0xff, 16) + " ";
- Log.log(this, log);
+ Log.info(this, log);
}
// FEATURE: need to keep the connection open between type1 and type3
// FEATURE: finish this
public String socksProxyHost = null; ///< the SOCKS Proxy Host to use
public int socksProxyPort = -1; ///< the SOCKS Proxy Port to use
public String[] excluded = null; ///< hosts to be excluded from proxy use; wildcards permitted
- public JSFunction proxyAutoConfigJSFunction = null; ///< the PAC script
+ public JS proxyAutoConfigFunction = null; ///< the PAC script
public static Proxy detectProxyViaManual() {
Proxy ret = new Proxy();
return ret;
}
- public static JSScope proxyAutoConfigRootJSScope = new ProxyAutoConfigRootJSScope();
- public static JSFunction getProxyAutoConfigJSFunction(String url) {
+ public static JSScope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
+ public static JS getProxyAutoConfigFunction(String url) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
String s = null;
String script = "";
while((s = br.readLine()) != null) script += s + "\n";
- if (Log.on) Log.log(Proxy.class, "successfully retrieved WPAD PAC:");
- if (Log.on) Log.log(Proxy.class, script);
+ if (Log.on) Log.info(Proxy.class, "successfully retrieved WPAD PAC:");
+ if (Log.on) Log.info(Proxy.class, script);
// MS CARP hack
Vector carpHosts = new Vector();
for(int i=0; i<script.length(); i++)
if (script.regionMatches(i, "new Node(", 0, 9)) {
String host = script.substring(i + 10, script.indexOf('\"', i + 11));
- if (Log.on) Log.log(Proxy.class, "Detected MS Proxy Server CARP Script, Host=" + host);
+ if (Log.on) Log.info(Proxy.class, "Detected MS Proxy Server CARP Script, Host=" + host);
carpHosts.addElement(host);
}
if (carpHosts.size() > 0) {
for(int i=0; i<carpHosts.size(); i++)
script += "PROXY " + carpHosts.elementAt(i) + "; ";
script += "\";\n}";
- if (Log.on) Log.log(Proxy.class, "DeCARPed PAC script:");
- if (Log.on) Log.log(Proxy.class, script);
+ if (Log.on) Log.info(Proxy.class, "DeCARPed PAC script:");
+ if (Log.on) Log.info(Proxy.class, script);
}
- JSFunction scr = JSFunction.fromReader("PAC script at " + url, 0, new StringReader(script));
- scr.cloneWithNewParentScope(proxyAutoConfigRootJSScope).call(null, null, null, null, 0);
- return (JSFunction)proxyAutoConfigRootJSScope.get("FindProxyForURL");
+ JS scr = JS.fromReader("PAC script at " + url, 0, new StringReader(script));
+ JS.cloneWithNewParentScope(scr, proxyAutoConfigRootScope).call(null, null, null, null, 0);
+ return (JS)proxyAutoConfigRootScope.get("FindProxyForURL");
} catch (Exception e) {
if (Log.on) {
- Log.log(Platform.class, "WPAD detection failed due to:");
+ Log.info(Platform.class, "WPAD detection failed due to:");
if (e instanceof JSExn) {
try {
org.xwt.js.JSArray arr = new org.xwt.js.JSArray();
arr.addElement(((JSExn)e).getObject());
} catch (Exception e2) {
- Log.log(Platform.class, e);
+ Log.info(Platform.class, e);
}
}
- else Log.log(Platform.class, e);
+ else Log.info(Platform.class, e);
}
return null;
}
// a password, so we should reattempt authorization.
if (authorization != oldAuth) return;
- if (Log.on) Log.log(Authorization.class, "displaying proxy authorization dialog");
+ if (Log.on) Log.info(Authorization.class, "displaying proxy authorization dialog");
Scheduler.add(new Scheduler.Task() {
public void perform() throws Exception {
Box b = new Box();
- Template t = Template.getTemplate((Res)Main.builtin.get("org/xwt/builtin/proxy_authorization.xwt"));
- t.apply(b, null);
+ Template t = new Template(Stream.getInputStream((JS)Main.builtin.get("org/xwt/builtin/proxy_authorization.xwt")), new XWT(null));
+ t.apply(b);
b.put("realm", realm);
b.put("proxyIP", proxyIP);
}
});
waitingForUser.block();
- if (Log.on) Log.log(Authorization.class, "got proxy authorization info; re-attempting connection");
+ if (Log.on) Log.info(Authorization.class, "got proxy authorization info; re-attempting connection");
}
}
// ProxyAutoConfigRootJSScope ////////////////////////////////////////////////////////////////////
- public static class ProxyAutoConfigRootJSScope extends JSScope.Global {
+ public static class ProxyAutoConfigRootScope extends JSScope.Global {
- public ProxyAutoConfigRootJSScope() { super(); }
+ public ProxyAutoConfigRootScope() { super(); }
public Object get(Object name) throws JSExn {
//#switch(name)
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
- if (Log.on) Log.log(this, "strange... host does not know its own address");
+ if (Log.on) Log.info(this, "strange... host does not know its own address");
return null;
}
case "dnsDomainLevels":