2003/12/13 00:44:41
[org.ibex.core.git] / src / org / xwt / HTTP.java
index f3ff183..5f89ce3 100644 (file)
@@ -189,7 +189,7 @@ public class HTTP {
     // Methods to attempt socket creation /////////////////////////////////////////////////////////////////
 
     private Socket getSocket(String host, int port, boolean ssl, boolean negotiate) throws IOException {
-        Socket ret = ssl ? new TinySSL(host, port, negotiate) : new Socket(java.net.InetAddress.getByName(host), port);
+        Socket ret = ssl ? new SSL(host, port, negotiate) : new Socket(java.net.InetAddress.getByName(host), port);
         ret.setTcpNoDelay(true);
         return ret;
     }
@@ -222,7 +222,7 @@ public class HTTP {
                 String s = br.readLine();
                 if (s.charAt(9) != '2') throw new HTTPException("proxy refused CONNECT method: \"" + s + "\"");
                 while (br.readLine().length() > 0) { };
-                ((TinySSL)sock).negotiate();
+                ((SSL)sock).negotiate();
             }
             return sock;
 
@@ -270,7 +270,7 @@ public class HTTP {
             dis.skip(6);                                 // ip/port
             
             if ((int)(success & 0xff) == 90) {
-                if (ssl) ((TinySSL)sock).negotiate();
+                if (ssl) ((SSL)sock).negotiate();
                 return sock;
             }
             if (Log.on) Log.log(this, "SOCKS server denied access, code " + (success & 0xff));
@@ -283,14 +283,12 @@ public class HTTP {
     }
 
     /** executes the PAC script and dispatches a call to one of the other attempt methods based on the result */
-    public Socket attemptPAC(org.xwt.js.JSCallable pacFunc) {
+    public Socket attemptPAC(org.xwt.js.JS pacFunc) {
         if (Log.verbose) Log.log(this, "evaluating PAC script");
         String pac = null;
         try {
             org.xwt.js.JSArray args = new org.xwt.js.JSArray();
-            args.addElement(url.toString());
-            args.addElement(url.getHost());
-            Object obj = pacFunc.call(null, args);
+            Object obj = pacFunc.call(url.toString(), url.getHost(), null, null, 2);
             if (Log.verbose) Log.log(this, "  PAC script returned \"" + obj + "\"");
             pac = obj.toString();
         } catch (Throwable e) {
@@ -706,7 +704,7 @@ public class HTTP {
         public String[] excluded = null;
     
         /** the PAC script */
-        public JSCallable proxyAutoConfigJSFunction = null;
+        public JS proxyAutoConfigJSFunction = null;
     
         public static Proxy detectProxyViaManual() {
             Proxy ret = new Proxy();
@@ -759,7 +757,7 @@ public class HTTP {
         }
     
         public static JSScope proxyAutoConfigRootJSScope = new ProxyAutoConfigRootJSScope();
-        public static JSCallable getProxyAutoConfigJSFunction(String url) {
+        public static JS getProxyAutoConfigJSFunction(String url) {
             try { 
                 BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
                 String s = null;
@@ -785,16 +783,16 @@ public class HTTP {
                     if (Log.on) Log.log(Proxy.class, script);
                 }
 
-                JSFunction scr = JS.parse("PAC script at " + url, 0, new StringReader(script));
-                scr.cloneWithNewParentJSScope(proxyAutoConfigRootJSScope).call(null, new JSArray());
-                return (JSCallable)proxyAutoConfigRootJSScope.get("FindProxyForURL");
+                JSFunction scr = JSFunction.fromReader("PAC script at " + url, 0, new StringReader(script));
+                scr.cloneWithNewParentScope(proxyAutoConfigRootJSScope).call(null, null, null, null, 0);
+                return (JS)proxyAutoConfigRootJSScope.get("FindProxyForURL");
             } catch (Exception e) {
                 if (Log.on) {
                     Log.log(Platform.class, "WPAD detection failed due to:");
-                    if (e instanceof JS.Exn) {
+                    if (e instanceof JSExn) {
                         try {
                             org.xwt.js.JSArray arr = new org.xwt.js.JSArray();
-                            arr.addElement(((JS.Exn)e).getObject());
+                            arr.addElement(((JSExn)e).getObject());
                         } catch (Exception e2) {
                             Log.log(Platform.class, e);
                         }
@@ -844,9 +842,9 @@ public class HTTP {
 
         public static class ProxyAutoConfigRootJSScope extends JSScope.Global {
 
-            public ProxyAutoConfigRootJSScope() { super(null); }
+            public ProxyAutoConfigRootJSScope() { super(); }
         
-            public Object get(Object name) {
+            public Object get(Object name) throws JSExn {
                 if (name.equals("isPlainHostName")) return isPlainHostName;
                 else if (name.equals("dnsDomainIs")) return dnsDomainIs;
                 else if (name.equals("localHostOrDomainIs")) return localHostOrDomainIs;
@@ -863,36 +861,36 @@ public class HTTP {
                 else return super.get(name);
             }
         
-            private static final JSObj proxyConfigBindings = new JSObj();
-            private static final JSObj ProxyConfig = new JSObj() {
+            private static final JS proxyConfigBindings = new JS();
+            private static final JS ProxyConfig = new JS() {
                     public Object get(Object name) {
                         if (name.equals("bindings")) return proxyConfigBindings;
                         return null;
                     }
                 };
         
-            private static final JSCallable isPlainHostName = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS isPlainHostName = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         return (args.elementAt(0).toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE;
                     }
                 };
         
-            private static final JSCallable dnsDomainIs = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS dnsDomainIs = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         return (args.elementAt(0).toString().endsWith(args.elementAt(1).toString())) ? Boolean.TRUE : Boolean.FALSE;
                     }
                 };
         
-            private static final JSCallable localHostOrDomainIs = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS localHostOrDomainIs = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         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 JSCallable isResolvable = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS isResolvable = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         try {
                             return (InetAddress.getByName(args.elementAt(0).toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
                         } catch (UnknownHostException e) {
@@ -901,8 +899,8 @@ public class HTTP {
                     }
                 };
         
-            private static final JSCallable isInNet = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS isInNet = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         if (args.length() != 3) return Boolean.FALSE;
                         try {
                             byte[] host = InetAddress.getByName(args.elementAt(0).toString()).getAddress();
@@ -914,13 +912,13 @@ public class HTTP {
                                     (host[3] & mask[3]) == net[3]) ?
                                 Boolean.TRUE : Boolean.FALSE;
                         } catch (Exception e) {
-                            throw new JS.Exn("exception in isInNet(): " + e);
+                            throw new JSExn("exception in isInNet(): " + e);
                         }
                     }
                 };
         
-            private static final JSCallable dnsResolve = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS dnsResolve = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         try {
                             return InetAddress.getByName(args.elementAt(0).toString()).getHostAddress();
                         } catch (UnknownHostException e) {
@@ -929,8 +927,8 @@ public class HTTP {
                     }
                 };
         
-            private static final JSCallable myIpAddress = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS myIpAddress = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         try {
                             return InetAddress.getLocalHost().getHostAddress();
                         } catch (UnknownHostException e) {
@@ -940,8 +938,8 @@ public class HTTP {
                     }
                 };
         
-            private static final JSCallable dnsDomainLevels = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS dnsDomainLevels = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         String s = args.elementAt(0).toString();
                         int i = 0;
                         while((i = s.indexOf('.', i)) != -1) i++;
@@ -958,8 +956,8 @@ public class HTTP {
                 return false;
             }
         
-            private static final JSCallable shExpMatch = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS shExpMatch = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         StringTokenizer st = new StringTokenizer(args.elementAt(1).toString(), "*", false);
                         String[] arr = new String[st.countTokens()];
                         String s = args.elementAt(0).toString();
@@ -970,8 +968,8 @@ public class HTTP {
         
             public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
         
-            private static final JSCallable weekdayRange = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
+            private static final JS weekdayRange = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
                         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);
@@ -996,15 +994,15 @@ public class HTTP {
                     }
                 };
         
-            private static final JSCallable dateRange = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
-                        throw new JS.Exn("XWT does not support dateRange() in PAC scripts");
+            private static final JS dateRange = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
+                        throw new JSExn("XWT does not support dateRange() in PAC scripts");
                     }
                 };
         
-            private static final JSCallable timeRange = new JSCallable() {
-                    public Object call(org.xwt.js.JSArray args) throws JS.Exn {
-                        throw new JS.Exn("XWT does not support timeRange() in PAC scripts");
+            private static final JS timeRange = new JS() {
+                    public Object call(org.xwt.js.JSArray args) throws JSExn {
+                        throw new JSExn("XWT does not support timeRange() in PAC scripts");
                     }
                 };