+ public static InetAddress originAddr = null;
+ public static String originHost = null;
+
+ // FIXME: HACK
+ public static String userAgent = "Ibex";
+
+ // Cookies //////////////////////////////////////////////////////////////////////////////
+
+ public static class Cookie {
+ public final String name;
+ public final String value;
+ public final String domain;
+ public final String path;
+ public final Date expires;
+ public final boolean secure;
+ public Cookie(String name, String value, String domain, String path, Date expires, boolean secure) {
+ this.name = name;
+ this.value = value;
+ this.domain = domain;
+ this.path = path;
+ this.expires = expires;
+ this.secure = secure;
+ }
+
+ // FIXME: this could be much more efficient
+ // FIXME currently only implements http://wp.netscape.com/newsref/std/cookie_spec.html
+ public static class Jar {
+ private Hash h = new Hash();
+ public String getCookieHeader(String domain, String path, boolean secure) {
+ StringBuffer ret = new StringBuffer("Cookie: ");
+ Enumeration e = h.keys();
+ while (e.hasMoreElements()) {
+ Vec v = (Vec)h.get(e.nextElement());
+ Cookie cookie = null;
+ for(int i=0; i<v.size(); i++) {
+ Cookie c = (Cookie)v.elementAt(i);
+ if (domain.endsWith(c.domain) &&
+ (c.path == null || path.startsWith(c.path)) &&
+ (cookie == null || c.domain.length() > cookie.domain.length()))
+ cookie = c;
+ }
+ if (cookie != null) {
+ ret.append(cookie.name);
+ ret.append("=");
+ ret.append(cookie.value);
+ ret.append("; ");
+ }
+ }
+ //ret.setLength(ret.length() - 2);
+ return ret.toString();
+ }
+ public void setCookie(String header, String defaultDomain) {
+ String name = null;
+ String value = null;
+ String domain = defaultDomain;
+ String path = "/";
+ Date expires = null;
+ boolean secure = false;
+ StringTokenizer st = new StringTokenizer(header, ";");
+ while(st.hasMoreTokens()) {
+ String s = st.nextToken();
+ if (s.indexOf('=') == -1) {
+ if (s.equals("secure")) secure = true;
+ continue;
+ }
+ String start = s.substring(0, s.indexOf('='));
+ String end = s.substring(s.indexOf('=')+1);
+ if (name == null) {
+ name = start;
+ value = end;
+ continue;
+ }
+ //#switch(start.toLowerCase())
+ case "domain": domain = end;
+ case "path": path = end;
+ case "expires": expires = new Date(end);
+ //#end
+ }
+ if (h.get(name) == null) h.put(name, new Vec());
+ ((Vec)h.get(name)).addElement(new Cookie(name, value, domain, path, expires, secure));
+ }
+ }
+ }