X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2FHTTP.java;h=7f6f248b29b0974390f56ea6475c9b100bee13d2;hb=a726bd527e6364dd00477e17e9c688d32509c62c;hp=5cf4e3aec16b7ee859046e7e603b47009c015fa5;hpb=c04af3bec88e6cbaf461700900d00d1e4d096d26;p=org.ibex.core.git diff --git a/src/org/ibex/HTTP.java b/src/org/ibex/HTTP.java index 5cf4e3a..7f6f248 100644 --- a/src/org/ibex/HTTP.java +++ b/src/org/ibex/HTTP.java @@ -29,6 +29,8 @@ public class HTTP { public static class HTTPException extends IOException { public HTTPException(String s) { super(s); } } + public static HTTP stdio = new HTTP("stdio:"); + // Statics /////////////////////////////////////////////////////////////////////////////////////////////// @@ -86,7 +88,7 @@ public class HTTP { // previous call wrecked the socket connection, but we already sent our request, so we can't just retry -- // this could cause the server to receive the request twice, which could be bad (think of the case where the // server call causes Amazon.com to ship you an item with one-click purchasing). - if (sock == null) + if (in == null) throw new HTTPException("a previous pipelined call messed up the socket"); Hashtable h = in == null ? null : parseHeaders(in); @@ -354,7 +356,7 @@ public class HTTP { PrintWriter pw = new PrintWriter(new OutputStreamWriter(originalUrl.equals("stdio:") ? System.out : sock.getOutputStream())); if (content != null) { - pw.print("POST " + path + " HTTP/1.1\r\n"); + pw.print("POST " + path + " HTTP/1.0\r\n"); // FIXME chunked encoding int contentLength = content.substring(0, 2).equals("\r\n") ? content.length() - 2 : (content.length() - content.indexOf("\r\n\r\n") - 4); @@ -383,7 +385,7 @@ public class HTTP { if (h.get("AUTHTYPE").equals("Basic")) { if (authCache.get(originalUrl) != null) throw new HTTPException("username/password rejected"); - authCache.put(originalUrl, "Basic " + new String(Base64.encode(userInfo.getBytes("US-ASCII")))); + authCache.put(originalUrl, "Basic " + new String(Base64.encode(userInfo.getBytes("UTF8")))); } else if (h.get("AUTHTYPE").equals("Digest")) { if (authCache.get(originalUrl) != null && !"true".equals(h.get("stale"))) @@ -430,7 +432,7 @@ public class HTTP { if (style.equals("Basic")) { Proxy.Authorization.authorization2 = - "Basic " + new String(Base64.encode(Proxy.Authorization.authorization.getBytes("US-ASCII"))); + "Basic " + new String(Base64.encode(Proxy.Authorization.authorization.getBytes("UTF8"))); } else if (style.equals("Digest")) { String A1 = Proxy.Authorization.authorization.substring(0, userInfo.indexOf(':')) + ":" + h.get("realm") + ":" + @@ -579,6 +581,8 @@ public class HTTP { if (buflen >= 4 && buf[buflen - 4] == '\r' && buf[buflen - 3] == '\n' && buf[buflen - 2] == '\r' && buf[buflen - 1] == '\n') break; + if (buflen >=2 && buf[buflen - 1] == '\n' && buf[buflen - 2] == '\n') + break; // nice for people using stdio if (buflen == buf.length) { byte[] newbuf = new byte[buf.length * 2]; System.arraycopy(buf, 0, newbuf, 0, buflen); @@ -629,7 +633,7 @@ public class HTTP { } private String H(String s) throws IOException { - byte[] b = s.getBytes("US-ASCII"); + byte[] b = s.getBytes("UTF8"); MD5Digest md5 = new MD5Digest(); md5.update(b, 0, b.length); byte[] out = new byte[md5.getDigestSize()]; @@ -648,8 +652,6 @@ public class HTTP { /** encapsulates most of the proxy logic; some is shared in HTTP.java */ public static class Proxy { - public Proxy() { } - public String httpProxyHost = null; ///< the HTTP Proxy host to use public int httpProxyPort = -1; ///< the HTTP Proxy port to use public String httpsProxyHost = null; ///< seperate proxy for HTTPS @@ -780,7 +782,9 @@ public class HTTP { Scheduler.add(new Scheduler.Task() { public void perform() throws IOException, JSExn { Box b = new Box(); - Template t = Template.buildTemplate(Stream.getInputStream((JS)Main.builtin.get("org/ibex/builtin/proxy_authorization.ibex")), new Ibex(null)); + Template t = null; + // FIXME + //Template.buildTemplate("org/ibex/builtin/proxy_authorization.ibex", Stream.getInputStream((JS)Main.builtin.get("org/ibex/builtin/proxy_authorization.ibex")), new Ibex(null)); t.apply(b); b.put("realm", realm); b.put("proxyIP", proxyIP); @@ -1033,13 +1037,13 @@ public class HTTP { */ private static byte[] lmHash(String password) { /* - byte[] oemPassword = password.toUpperCase().getBytes("US-ASCII"); + byte[] oemPassword = password.toUpperCase().getBytes("UTF8"); int length = java.lang.Math.min(oemPassword.length, 14); byte[] keyBytes = new byte[14]; System.arraycopy(oemPassword, 0, keyBytes, 0, length); Key lowKey = createDESKey(keyBytes, 0); Key highKey = createDESKey(keyBytes, 7); - byte[] magicConstant = "KGS!@#$%".getBytes("US-ASCII"); + byte[] magicConstant = "KGS!@#$%".getBytes("UTF8"); Cipher des = Cipher.getInstance("DES/ECB/NoPadding"); des.init(Cipher.ENCRYPT_MODE, lowKey); byte[] lowHash = des.doFinal(magicConstant);