X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FProxy.java;h=876d35c14e50c7082f176922176016041793dbaf;hb=fa9b47fdfcfd055b2027f5aa49bfb68209a00e1b;hp=81318a09b598e1161bc9141d763c86f8caa5deaf;hpb=e58686eae8a823ed64ed0ec92c2274c41d90ec93;p=org.ibex.core.git diff --git a/src/org/xwt/Proxy.java b/src/org/xwt/Proxy.java index 81318a0..876d35c 100644 --- a/src/org/xwt/Proxy.java +++ b/src/org/xwt/Proxy.java @@ -35,7 +35,7 @@ public class Proxy { public String[] excluded = null; /** the PAC script */ - public JS.Function proxyAutoConfigFunction = null; + public JS.Callable proxyAutoConfigFunction = null; public static Proxy detectProxyViaManual() { Proxy ret = new Proxy(); @@ -87,14 +87,9 @@ public class Proxy { return ret; } - //public static JS proxyAutoConfigRootScope = new ProxyAutoConfigRootScope(); - public static JS.Function getProxyAutoConfigFunction(String url) { - throw new Error("not implemented"); - // FIXME - /* + public static JS.Scope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope(); + public static JS.Callable getProxyAutoConfigFunction(String url) { try { - Context cx = Context.enter(); - cx.setOptimizationLevel(-1); BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET())); String s = null; String script = ""; @@ -118,28 +113,27 @@ public class Proxy { if (Log.on) Log.log(Proxy.class, "DeCARPed PAC script:"); if (Log.on) Log.log(Proxy.class, script); } - - Script scr = cx.compileReader(proxyAutoConfigRootScope, new StringReader(script), "PAC script at " + url, 0, null); - scr.exec(cx, proxyAutoConfigRootScope); - return (JS.Function)proxyAutoConfigRootScope.get("FindProxyForURL", null); + + JS.CompiledFunction scr = JS.parse("PAC script at " + url, 0, new StringReader(script)); + scr.call(new JS.Array(), proxyAutoConfigRootScope); + return (JS.Callable)proxyAutoConfigRootScope.get("FindProxyForURL"); } catch (Exception e) { if (Log.on) { Log.log(Platform.class, "WPAD detection failed due to:"); - if (e instanceof EcmaError) Log.log(HTTP.class, ((EcmaError)e).getMessage() + " at " + - ((EcmaError)e).getSourceName() + ":" + ((EcmaError)e).getLineNumber()); - else if (e instanceof JS.Exn) { - try { - XWT.recursivePrintObject.call(Context.enter(), null, null, new Object[] { - ((JS.Exn)e).getValue() }); - } catch (Exception e2) { - Log.log(Platform.class, e); - } - } + if (e instanceof JS.Exn) { + try { + org.xwt.js.JS.Array arr = new org.xwt.js.JS.Array(); + arr.addElement(((JS.Exn)e).getObject()); + // FIXME + //XWT.recursivePrintObject.call(); + } catch (Exception e2) { + Log.log(Platform.class, e); + } + } else Log.log(Platform.class, e); } return null; } - */ } @@ -175,13 +169,14 @@ public class Proxy { // ProxyAutoConfigRootScope //////////////////////////////////////////////////////////////////// - /* - public static class ProxyAutoConfigRootScope extends JSObject { - - public String getClassName() { return "ProxyAutoConfigRootScope"; } - ProxyAutoConfigRootScope() { Context.enter().initStandardObjects(this); } + + public static class ProxyAutoConfigRootScope extends JS.Scope { + + public ProxyAutoConfigRootScope() { super(null); } - public Object get(String name, JS start) { + // FIXME: needs "standard objects" + + public Object get(Object name) { if (name.equals("isPlainHostName")) return isPlainHostName; else if (name.equals("dnsDomainIs")) return dnsDomainIs; else if (name.equals("localHostOrDomainIs")) return localHostOrDomainIs; @@ -195,54 +190,54 @@ public class Proxy { else if (name.equals("dateRange")) return dateRange; else if (name.equals("timeRange")) return timeRange; else if (name.equals("ProxyConfig")) return ProxyConfig; - else return super.get(name, start); + else return super.get(name); } - private static final JS.Object proxyConfigBindings = new JS.Object(); - private static final JS.Object ProxyConfig = new JS.Object() { - public Object get(String name, JS start) { + private static final JS.Obj proxyConfigBindings = new JS.Obj(); + private static final JS.Obj ProxyConfig = new JS.Obj() { + public Object get(Object name) { if (name.equals("bindings")) return proxyConfigBindings; return null; } }; - private static final JS.Function isPlainHostName = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - return (args[0].toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE; + private static final JS.Callable isPlainHostName = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + return (args.elementAt(0).toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE; } }; - private static final JS.Function dnsDomainIs = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - return (args[0].toString().endsWith(args[1].toString())) ? Boolean.TRUE : Boolean.FALSE; + private static final JS.Callable dnsDomainIs = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + return (args.elementAt(0).toString().endsWith(args.elementAt(1).toString())) ? Boolean.TRUE : Boolean.FALSE; } }; - private static final JS.Function localHostOrDomainIs = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - return (args[0].toString().equals(args[1].toString()) || - (args[0].toString().indexOf('.') == -1 && args[1].toString().startsWith(args[0].toString()))) ? + private static final JS.Callable localHostOrDomainIs = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + return (args.elementAt(0).toString().equals(args.elementAt(1).toString()) || + (args.elementAt(0).toString().indexOf('.') == -1 && args.elementAt(1).toString().startsWith(args.elementAt(0).toString()))) ? Boolean.TRUE : Boolean.FALSE; } }; - private static final JS.Function isResolvable = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { + private static final JS.Callable isResolvable = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { try { - return (InetAddress.getByName(args[0].toString()) != null) ? Boolean.TRUE : Boolean.FALSE; + return (InetAddress.getByName(args.elementAt(0).toString()) != null) ? Boolean.TRUE : Boolean.FALSE; } catch (UnknownHostException e) { return Boolean.FALSE; } } }; - private static final JS.Function isInNet = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - if (args.length != 3) return Boolean.FALSE; + private static final JS.Callable isInNet = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + if (args.length() != 3) return Boolean.FALSE; try { - byte[] host = InetAddress.getByName(args[0].toString()).getAddress(); - byte[] net = InetAddress.getByName(args[1].toString()).getAddress(); - byte[] mask = InetAddress.getByName(args[2].toString()).getAddress(); + byte[] host = InetAddress.getByName(args.elementAt(0).toString()).getAddress(); + byte[] net = InetAddress.getByName(args.elementAt(1).toString()).getAddress(); + byte[] mask = InetAddress.getByName(args.elementAt(2).toString()).getAddress(); return ((host[0] & mask[0]) == net[0] && (host[1] & mask[1]) == net[1] && (host[2] & mask[2]) == net[2] && @@ -254,18 +249,18 @@ public class Proxy { } }; - private static final JS.Function dnsResolve = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { + private static final JS.Callable dnsResolve = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { try { - return InetAddress.getByName(args[0].toString()).getHostAddress(); + return InetAddress.getByName(args.elementAt(0).toString()).getHostAddress(); } catch (UnknownHostException e) { return null; } } }; - private static final JS.Function myIpAddress = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { + private static final JS.Callable myIpAddress = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { @@ -275,9 +270,9 @@ public class Proxy { } }; - private static final JS.Function dnsDomainLevels = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - String s = args[0].toString(); + private static final JS.Callable dnsDomainLevels = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + String s = args.elementAt(0).toString(); int i = 0; while((i = s.indexOf('.', i)) != -1) i++; return new Integer(i); @@ -293,11 +288,11 @@ public class Proxy { return false; } - private static final JS.Function shExpMatch = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - StringTokenizer st = new StringTokenizer(args[1].toString(), "*", false); + private static final JS.Callable shExpMatch = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + StringTokenizer st = new StringTokenizer(args.elementAt(1).toString(), "*", false); String[] arr = new String[st.countTokens()]; - String s = args[0].toString(); + String s = args.elementAt(0).toString(); for (int i=0; st.hasMoreTokens(); i++) arr[i] = st.nextToken(); return match(arr, s, 0) ? Boolean.TRUE : Boolean.FALSE; } @@ -305,23 +300,23 @@ public class Proxy { public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; - private static final JS.Function weekdayRange = new JS.Function() { - public Object call(Context cx, JS thisObj, JS ctorObj, Object[] args) throws JS.Exn { - TimeZone tz = (args.length < 3 || args[2] == null || !args[2].equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault(); + private static final JS.Callable weekdayRange = new JS.Callable() { + public Object call(org.xwt.js.JS.Array args) throws JS.Exn { + TimeZone tz = (args.length() < 3 || args.elementAt(2) == null || !args.elementAt(2).equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault(); Calendar c = new GregorianCalendar(); c.setTimeZone(tz); - c.setTime(new Date()); - Date d = c.getTime(); + c.setTime(new java.util.Date()); + java.util.Date d = c.getTime(); int day = d.getDay(); - String d1s = args[0].toString().toUpperCase(); + String d1s = args.elementAt(0).toString().toUpperCase(); int d1 = 0, d2 = 0; for(int i=0; i