httpclient-4.3.5

16:36:36.722 INFO  jd.cli.Main - Decompiling httpclient-4.3.5.jar
package org.apache.http.impl.cookie;

import java.util.List;
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.message.ParserCursor;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class BestMatchSpec
  implements CookieSpec
{
  private final String[] datepatterns;
  private final boolean oneHeader;
  private RFC2965Spec strict;
  private RFC2109Spec obsoleteStrict;
  private BrowserCompatSpec compat;
  
  public BestMatchSpec(String[] datepatterns, boolean oneHeader)
  {
    this.datepatterns = (datepatterns == null ? null : (String[])datepatterns.clone());
    this.oneHeader = oneHeader;
  }
  
  public BestMatchSpec()
  {
    this(null, false);
  }
  
  private RFC2965Spec getStrict()
  {
    if (strict == null) {
      strict = new RFC2965Spec(datepatterns, oneHeader);
    }
    return strict;
  }
  
  private RFC2109Spec getObsoleteStrict()
  {
    if (obsoleteStrict == null) {
      obsoleteStrict = new RFC2109Spec(datepatterns, oneHeader);
    }
    return obsoleteStrict;
  }
  
  private BrowserCompatSpec getCompat()
  {
    if (compat == null) {
      compat = new BrowserCompatSpec(datepatterns);
    }
    return compat;
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(header, "Header");
    Args.notNull(origin, "Cookie origin");
    HeaderElement[] helems = header.getElements();
    boolean versioned = false;
    boolean netscape = false;
    for (HeaderElement helem : helems)
    {
      if (helem.getParameterByName("version") != null) {
        versioned = true;
      }
      if (helem.getParameterByName("expires") != null) {
        netscape = true;
      }
    }
    if ((netscape) || (!versioned))
    {
      NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
      ParserCursor cursor;
      CharArrayBuffer buffer;
      ParserCursor cursor;
      if ((header instanceof FormattedHeader))
      {
        CharArrayBuffer buffer = ((FormattedHeader)header).getBuffer();
        cursor = new ParserCursor(((FormattedHeader)header).getValuePos(), buffer.length());
      }
      else
      {
        String s = header.getValue();
        if (s == null) {
          throw new MalformedCookieException("Header value is null");
        }
        buffer = new CharArrayBuffer(s.length());
        buffer.append(s);
        cursor = new ParserCursor(0, buffer.length());
      }
      helems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
      return getCompat().parse(helems, origin);
    }
    if ("Set-Cookie2".equals(header.getName())) {
      return getStrict().parse(helems, origin);
    }
    return getObsoleteStrict().parse(helems, origin);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    if (cookie.getVersion() > 0)
    {
      if ((cookie instanceof SetCookie2)) {
        getStrict().validate(cookie, origin);
      } else {
        getObsoleteStrict().validate(cookie, origin);
      }
    }
    else {
      getCompat().validate(cookie, origin);
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    if (cookie.getVersion() > 0)
    {
      if ((cookie instanceof SetCookie2)) {
        return getStrict().match(cookie, origin);
      }
      return getObsoleteStrict().match(cookie, origin);
    }
    return getCompat().match(cookie, origin);
  }
  
  public List<Header> formatCookies(List<Cookie> cookies)
  {
    Args.notNull(cookies, "List of cookies");
    int version = Integer.MAX_VALUE;
    boolean isSetCookie2 = true;
    for (Cookie cookie : cookies)
    {
      if (!(cookie instanceof SetCookie2)) {
        isSetCookie2 = false;
      }
      if (cookie.getVersion() < version) {
        version = cookie.getVersion();
      }
    }
    if (version > 0)
    {
      if (isSetCookie2) {
        return getStrict().formatCookies(cookies);
      }
      return getObsoleteStrict().formatCookies(cookies);
    }
    return getCompat().formatCookies(cookies);
  }
  
  public int getVersion()
  {
    return getStrict().getVersion();
  }
  
  public Header getVersionHeader()
  {
    return getStrict().getVersionHeader();
  }
  
  public String toString()
  {
    return "best-match";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BestMatchSpec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.StringTokenizer;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.util.Args;

@Immutable
public class RFC2965PortAttributeHandler
  implements CookieAttributeHandler
{
  private static int[] parsePortAttribute(String portValue)
    throws MalformedCookieException
  {
    StringTokenizer st = new StringTokenizer(portValue, ",");
    int[] ports = new int[st.countTokens()];
    try
    {
      int i = 0;
      while (st.hasMoreTokens())
      {
        ports[i] = Integer.parseInt(st.nextToken().trim());
        if (ports[i] < 0) {
          throw new MalformedCookieException("Invalid Port attribute.");
        }
        i++;
      }
    }
    catch (NumberFormatException e)
    {
      throw new MalformedCookieException("Invalid Port attribute: " + e.getMessage());
    }
    return ports;
  }
  
  private static boolean portMatch(int port, int[] ports)
  {
    boolean portInList = false;
    for (int port2 : ports) {
      if (port == port2)
      {
        portInList = true;
        break;
      }
    }
    return portInList;
  }
  
  public void parse(SetCookie cookie, String portValue)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if ((cookie instanceof SetCookie2))
    {
      SetCookie2 cookie2 = (SetCookie2)cookie;
      if ((portValue != null) && (portValue.trim().length() > 0))
      {
        int[] ports = parsePortAttribute(portValue);
        cookie2.setPorts(ports);
      }
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    int port = origin.getPort();
    if (((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("port"))) {
      if (!portMatch(port, cookie.getPorts())) {
        throw new CookieRestrictionViolationException("Port attribute violates RFC 2965: Request port not found in cookie's port list.");
      }
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    int port = origin.getPort();
    if (((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("port")))
    {
      if (cookie.getPorts() == null) {
        return false;
      }
      if (!portMatch(port, cookie.getPorts())) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965PortAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.Args;

@Immutable
public class BasicSecureHandler
  extends AbstractCookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    cookie.setSecure(true);
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    return (!cookie.isSecure()) || (origin.isSecure());
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BasicSecureHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.http.annotation.Immutable;

@Immutable
public class PublicSuffixListParser
{
  private static final int MAX_LINE_LEN = 256;
  private final PublicSuffixFilter filter;
  
  PublicSuffixListParser(PublicSuffixFilter filter)
  {
    this.filter = filter;
  }
  
  public void parse(Reader list)
    throws IOException
  {
    Collection<String> rules = new ArrayList();
    Collection<String> exceptions = new ArrayList();
    BufferedReader r = new BufferedReader(list);
    StringBuilder sb = new StringBuilder(256);
    boolean more = true;
    while (more)
    {
      more = readLine(r, sb);
      String line = sb.toString();
      if ((line.length() != 0) && 
      
        (!line.startsWith("//")))
      {
        if (line.startsWith(".")) {
          line = line.substring(1);
        }
        boolean isException = line.startsWith("!");
        if (isException) {
          line = line.substring(1);
        }
        if (isException) {
          exceptions.add(line);
        } else {
          rules.add(line);
        }
      }
    }
    filter.setPublicSuffixes(rules);
    filter.setExceptions(exceptions);
  }
  
  private boolean readLine(Reader r, StringBuilder sb)
    throws IOException
  {
    sb.setLength(0);
    
    boolean hitWhitespace = false;
    int b;
    while ((b = r.read()) != -1)
    {
      char c = (char)b;
      if (c == '\n') {
        break;
      }
      if (Character.isWhitespace(c)) {
        hitWhitespace = true;
      }
      if (!hitWhitespace) {
        sb.append(c);
      }
      if (sb.length() > 256) {
        throw new IOException("Line too long");
      }
    }
    return b != -1;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.PublicSuffixListParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.message.BasicHeaderElement;
import org.apache.http.message.BasicHeaderValueFormatter;
import org.apache.http.message.BufferedHeader;
import org.apache.http.message.ParserCursor;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class BrowserCompatSpec
  extends CookieSpecBase
{
  private static final String[] DEFAULT_DATE_PATTERNS = { "EEE, dd MMM yyyy HH:mm:ss zzz", "EEE, dd-MMM-yy HH:mm:ss zzz", "EEE MMM d HH:mm:ss yyyy", "EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd-MMM-yyyy HH-mm-ss z", "EEE, dd MMM yy HH:mm:ss z", "EEE dd-MMM-yyyy HH:mm:ss z", "EEE dd MMM yyyy HH:mm:ss z", "EEE dd-MMM-yyyy HH-mm-ss z", "EEE dd-MMM-yy HH:mm:ss z", "EEE dd MMM yy HH:mm:ss z", "EEE,dd-MMM-yy HH:mm:ss z", "EEE,dd-MMM-yyyy HH:mm:ss z", "EEE, dd-MM-yyyy HH:mm:ss z" };
  private final String[] datepatterns;
  
  public BrowserCompatSpec(String[] datepatterns, BrowserCompatSpecFactory.SecurityLevel securityLevel)
  {
    if (datepatterns != null) {
      this.datepatterns = ((String[])datepatterns.clone());
    } else {
      this.datepatterns = DEFAULT_DATE_PATTERNS;
    }
    switch (securityLevel)
    {
    case SECURITYLEVEL_DEFAULT: 
      registerAttribHandler("path", new BasicPathHandler());
      break;
    case SECURITYLEVEL_IE_MEDIUM: 
      registerAttribHandler("path", new BasicPathHandler()
      {
        public void validate(Cookie cookie, CookieOrigin origin)
          throws MalformedCookieException
        {}
      });
      break;
    default: 
      throw new RuntimeException("Unknown security level");
    }
    registerAttribHandler("domain", new BasicDomainHandler());
    registerAttribHandler("max-age", new BasicMaxAgeHandler());
    registerAttribHandler("secure", new BasicSecureHandler());
    registerAttribHandler("comment", new BasicCommentHandler());
    registerAttribHandler("expires", new BasicExpiresHandler(this.datepatterns));
    
    registerAttribHandler("version", new BrowserCompatVersionAttributeHandler());
  }
  
  public BrowserCompatSpec(String[] datepatterns)
  {
    this(datepatterns, BrowserCompatSpecFactory.SecurityLevel.SECURITYLEVEL_DEFAULT);
  }
  
  public BrowserCompatSpec()
  {
    this(null, BrowserCompatSpecFactory.SecurityLevel.SECURITYLEVEL_DEFAULT);
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(header, "Header");
    Args.notNull(origin, "Cookie origin");
    String headername = header.getName();
    if (!headername.equalsIgnoreCase("Set-Cookie")) {
      throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
    }
    HeaderElement[] helems = header.getElements();
    boolean versioned = false;
    boolean netscape = false;
    for (HeaderElement helem : helems)
    {
      if (helem.getParameterByName("version") != null) {
        versioned = true;
      }
      if (helem.getParameterByName("expires") != null) {
        netscape = true;
      }
    }
    if ((netscape) || (!versioned))
    {
      NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
      ParserCursor cursor;
      CharArrayBuffer buffer;
      ParserCursor cursor;
      if ((header instanceof FormattedHeader))
      {
        CharArrayBuffer buffer = ((FormattedHeader)header).getBuffer();
        cursor = new ParserCursor(((FormattedHeader)header).getValuePos(), buffer.length());
      }
      else
      {
        String s = header.getValue();
        if (s == null) {
          throw new MalformedCookieException("Header value is null");
        }
        buffer = new CharArrayBuffer(s.length());
        buffer.append(s);
        cursor = new ParserCursor(0, buffer.length());
      }
      helems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
    }
    return parse(helems, origin);
  }
  
  private static boolean isQuoteEnclosed(String s)
  {
    return (s != null) && (s.startsWith("\"")) && (s.endsWith("\""));
  }
  
  public List<Header> formatCookies(List<Cookie> cookies)
  {
    Args.notEmpty(cookies, "List of cookies");
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append("Cookie");
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++)
    {
      Cookie cookie = (Cookie)cookies.get(i);
      if (i > 0) {
        buffer.append("; ");
      }
      String cookieName = cookie.getName();
      String cookieValue = cookie.getValue();
      if ((cookie.getVersion() > 0) && (!isQuoteEnclosed(cookieValue)))
      {
        BasicHeaderValueFormatter.INSTANCE.formatHeaderElement(buffer, new BasicHeaderElement(cookieName, cookieValue), false);
      }
      else
      {
        buffer.append(cookieName);
        buffer.append("=");
        if (cookieValue != null) {
          buffer.append(cookieValue);
        }
      }
    }
    List<Header> headers = new ArrayList(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
  }
  
  public int getVersion()
  {
    return 0;
  }
  
  public Header getVersionHeader()
  {
    return null;
  }
  
  public String toString()
  {
    return "compatibility";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BrowserCompatSpec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class NetscapeDraftSpecFactory
  implements CookieSpecFactory, CookieSpecProvider
{
  private final String[] datepatterns;
  
  public NetscapeDraftSpecFactory(String[] datepatterns)
  {
    this.datepatterns = datepatterns;
  }
  
  public NetscapeDraftSpecFactory()
  {
    this(null);
  }
  
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      return new NetscapeDraftSpec(patterns);
    }
    return new NetscapeDraftSpec();
  }
  
  public CookieSpec create(HttpContext context)
  {
    return new NetscapeDraftSpec(datepatterns);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.NetscapeDraftSpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Locale;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.Args;

@Immutable
public class RFC2109DomainHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (value == null) {
      throw new MalformedCookieException("Missing value for domain attribute");
    }
    if (value.trim().length() == 0) {
      throw new MalformedCookieException("Blank value for domain attribute");
    }
    cookie.setDomain(value);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    String host = origin.getHost();
    String domain = cookie.getDomain();
    if (domain == null) {
      throw new CookieRestrictionViolationException("Cookie domain may not be null");
    }
    if (!domain.equals(host))
    {
      int dotIndex = domain.indexOf('.');
      if (dotIndex == -1) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + domain + "\" does not match the host \"" + host + "\"");
      }
      if (!domain.startsWith(".")) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + domain + "\" violates RFC 2109: domain must start with a dot");
      }
      dotIndex = domain.indexOf('.', 1);
      if ((dotIndex < 0) || (dotIndex == domain.length() - 1)) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + domain + "\" violates RFC 2109: domain must contain an embedded dot");
      }
      host = host.toLowerCase(Locale.ENGLISH);
      if (!host.endsWith(domain)) {
        throw new CookieRestrictionViolationException("Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\"");
      }
      String hostWithoutDomain = host.substring(0, host.length() - domain.length());
      if (hostWithoutDomain.indexOf('.') != -1) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + domain + "\" violates RFC 2109: host minus domain may not contain any dots");
      }
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    String host = origin.getHost();
    String domain = cookie.getDomain();
    if (domain == null) {
      return false;
    }
    return (host.equals(domain)) || ((domain.startsWith(".")) && (host.endsWith(domain)));
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109DomainHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class BestMatchSpecFactory
  implements CookieSpecFactory, CookieSpecProvider
{
  private final String[] datepatterns;
  private final boolean oneHeader;
  
  public BestMatchSpecFactory(String[] datepatterns, boolean oneHeader)
  {
    this.datepatterns = datepatterns;
    this.oneHeader = oneHeader;
  }
  
  public BestMatchSpecFactory()
  {
    this(null, false);
  }
  
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      boolean singleHeader = params.getBooleanParameter("http.protocol.single-cookie-header", false);
      
      return new BestMatchSpec(patterns, singleHeader);
    }
    return new BestMatchSpec();
  }
  
  public CookieSpec create(HttpContext context)
  {
    return new BestMatchSpec(datepatterns, oneHeader);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BestMatchSpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class IgnoreSpecFactory
  implements CookieSpecFactory, CookieSpecProvider
{
  public CookieSpec newInstance(HttpParams params)
  {
    return new IgnoreSpec();
  }
  
  public CookieSpec create(HttpContext context)
  {
    return new IgnoreSpec();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.IgnoreSpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.Args;

@Immutable
public class RFC2109VersionHandler
  extends AbstractCookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (value == null) {
      throw new MalformedCookieException("Missing value for version attribute");
    }
    if (value.trim().length() == 0) {
      throw new MalformedCookieException("Blank value for version attribute");
    }
    try
    {
      cookie.setVersion(Integer.parseInt(value));
    }
    catch (NumberFormatException e)
    {
      throw new MalformedCookieException("Invalid version: " + e.getMessage());
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (cookie.getVersion() < 0) {
      throw new CookieRestrictionViolationException("Cookie version may not be negative");
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109VersionHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

public enum BrowserCompatSpecFactory$SecurityLevel
{
  SECURITYLEVEL_DEFAULT,  SECURITYLEVEL_IE_MEDIUM;
  
  private BrowserCompatSpecFactory$SecurityLevel() {}
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BrowserCompatSpecFactory.SecurityLevel
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.annotation.Immutable;
import org.apache.http.message.BasicHeaderElement;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.ParserCursor;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;

@Immutable
public class NetscapeDraftHeaderParser
{
  public static final NetscapeDraftHeaderParser DEFAULT = new NetscapeDraftHeaderParser();
  
  public HeaderElement parseHeader(CharArrayBuffer buffer, ParserCursor cursor)
    throws ParseException
  {
    Args.notNull(buffer, "Char array buffer");
    Args.notNull(cursor, "Parser cursor");
    NameValuePair nvp = parseNameValuePair(buffer, cursor);
    List<NameValuePair> params = new ArrayList();
    while (!cursor.atEnd())
    {
      NameValuePair param = parseNameValuePair(buffer, cursor);
      params.add(param);
    }
    return new BasicHeaderElement(nvp.getName(), nvp.getValue(), (NameValuePair[])params.toArray(new NameValuePair[params.size()]));
  }
  
  private NameValuePair parseNameValuePair(CharArrayBuffer buffer, ParserCursor cursor)
  {
    boolean terminated = false;
    
    int pos = cursor.getPos();
    int indexFrom = cursor.getPos();
    int indexTo = cursor.getUpperBound();
    
    String name = null;
    while (pos < indexTo)
    {
      char ch = buffer.charAt(pos);
      if (ch == '=') {
        break;
      }
      if (ch == ';')
      {
        terminated = true;
        break;
      }
      pos++;
    }
    if (pos == indexTo)
    {
      terminated = true;
      name = buffer.substringTrimmed(indexFrom, indexTo);
    }
    else
    {
      name = buffer.substringTrimmed(indexFrom, pos);
      pos++;
    }
    if (terminated)
    {
      cursor.updatePos(pos);
      return new BasicNameValuePair(name, null);
    }
    String value = null;
    int i1 = pos;
    while (pos < indexTo)
    {
      char ch = buffer.charAt(pos);
      if (ch == ';')
      {
        terminated = true;
        break;
      }
      pos++;
    }
    int i2 = pos;
    while ((i1 < i2) && (HTTP.isWhitespace(buffer.charAt(i1)))) {
      i1++;
    }
    while ((i2 > i1) && (HTTP.isWhitespace(buffer.charAt(i2 - 1)))) {
      i2--;
    }
    value = buffer.substring(i1, i2);
    if (terminated) {
      pos++;
    }
    cursor.updatePos(pos);
    return new BasicNameValuePair(name, value);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.NetscapeDraftHeaderParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.Args;

@Immutable
public class BasicCommentHandler
  extends AbstractCookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    cookie.setComment(value);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.BasicCommentHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.message.BufferedHeader;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class RFC2965Spec
  extends RFC2109Spec
{
  public RFC2965Spec()
  {
    this(null, false);
  }
  
  public RFC2965Spec(String[] datepatterns, boolean oneHeader)
  {
    super(datepatterns, oneHeader);
    registerAttribHandler("domain", new RFC2965DomainAttributeHandler());
    registerAttribHandler("port", new RFC2965PortAttributeHandler());
    registerAttribHandler("commenturl", new RFC2965CommentUrlAttributeHandler());
    registerAttribHandler("discard", new RFC2965DiscardAttributeHandler());
    registerAttribHandler("version", new RFC2965VersionAttributeHandler());
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(header, "Header");
    Args.notNull(origin, "Cookie origin");
    if (!header.getName().equalsIgnoreCase("Set-Cookie2")) {
      throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
    }
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, adjustEffectiveHost(origin));
  }
  
  protected List<Cookie> parse(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    return createCookies(elems, adjustEffectiveHost(origin));
  }
  
  private List<Cookie> createCookies(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    List<Cookie> cookies = new ArrayList(elems.length);
    for (HeaderElement headerelement : elems)
    {
      String name = headerelement.getName();
      String value = headerelement.getValue();
      if ((name == null) || (name.length() == 0)) {
        throw new MalformedCookieException("Cookie name may not be empty");
      }
      BasicClientCookie2 cookie = new BasicClientCookie2(name, value);
      cookie.setPath(getDefaultPath(origin));
      cookie.setDomain(getDefaultDomain(origin));
      cookie.setPorts(new int[] { origin.getPort() });
      
      NameValuePair[] attribs = headerelement.getParameters();
      
      Map<String, NameValuePair> attribmap = new HashMap(attribs.length);
      for (int j = attribs.length - 1; j >= 0; j--)
      {
        NameValuePair param = attribs[j];
        attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
      }
      for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet())
      {
        NameValuePair attrib = (NameValuePair)entry.getValue();
        String s = attrib.getName().toLowerCase(Locale.ENGLISH);
        
        cookie.setAttribute(s, attrib.getValue());
        
        CookieAttributeHandler handler = findAttribHandler(s);
        if (handler != null) {
          handler.parse(cookie, attrib.getValue());
        }
      }
      cookies.add(cookie);
    }
    return cookies;
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    super.validate(cookie, adjustEffectiveHost(origin));
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    return super.match(cookie, adjustEffectiveHost(origin));
  }
  
  protected void formatCookieAsVer(CharArrayBuffer buffer, Cookie cookie, int version)
  {
    super.formatCookieAsVer(buffer, cookie, version);
    if ((cookie instanceof ClientCookie))
    {
      String s = ((ClientCookie)cookie).getAttribute("port");
      if (s != null)
      {
        buffer.append("; $Port");
        buffer.append("=\"");
        if (s.trim().length() > 0)
        {
          int[] ports = cookie.getPorts();
          if (ports != null)
          {
            int len = ports.length;
            for (int i = 0; i < len; i++)
            {
              if (i > 0) {
                buffer.append(",");
              }
              buffer.append(Integer.toString(ports[i]));
            }
          }
        }
        buffer.append("\"");
      }
    }
  }
  
  private static CookieOrigin adjustEffectiveHost(CookieOrigin origin)
  {
    String host = origin.getHost();
    
    boolean isLocalHost = true;
    for (int i = 0; i < host.length(); i++)
    {
      char ch = host.charAt(i);
      if ((ch == '.') || (ch == ':'))
      {
        isLocalHost = false;
        break;
      }
    }
    if (isLocalHost)
    {
      host = host + ".local";
      return new CookieOrigin(host, origin.getPort(), origin.getPath(), origin.isSecure());
    }
    return origin;
  }
  
  public int getVersion()
  {
    return 1;
  }
  
  public Header getVersionHeader()
  {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append("Cookie2");
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
  }
  
  public String toString()
  {
    return "rfc2965";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965Spec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.util.Args;

@Immutable
public class RFC2965VersionAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (value == null) {
      throw new MalformedCookieException("Missing value for version attribute");
    }
    int version = -1;
    try
    {
      version = Integer.parseInt(value);
    }
    catch (NumberFormatException e)
    {
      version = -1;
    }
    if (version < 0) {
      throw new MalformedCookieException("Invalid cookie version.");
    }
    cookie.setVersion(version);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (((cookie instanceof SetCookie2)) && 
      ((cookie instanceof ClientCookie)) && (!((ClientCookie)cookie).containsAttribute("version"))) {
      throw new CookieRestrictionViolationException("Violates RFC 2965. Version attribute is required.");
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965VersionAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;

@Immutable
public abstract class AbstractCookieAttributeHandler
  implements CookieAttributeHandler
{
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {}
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.AbstractCookieAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.util.Args;

@NotThreadSafe
public abstract class CookieSpecBase
  extends AbstractCookieSpec
{
  protected static String getDefaultPath(CookieOrigin origin)
  {
    String defaultPath = origin.getPath();
    int lastSlashIndex = defaultPath.lastIndexOf('/');
    if (lastSlashIndex >= 0)
    {
      if (lastSlashIndex == 0) {
        lastSlashIndex = 1;
      }
      defaultPath = defaultPath.substring(0, lastSlashIndex);
    }
    return defaultPath;
  }
  
  protected static String getDefaultDomain(CookieOrigin origin)
  {
    return origin.getHost();
  }
  
  protected List<Cookie> parse(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    List<Cookie> cookies = new ArrayList(elems.length);
    for (HeaderElement headerelement : elems)
    {
      String name = headerelement.getName();
      String value = headerelement.getValue();
      if ((name == null) || (name.length() == 0)) {
        throw new MalformedCookieException("Cookie name may not be empty");
      }
      BasicClientCookie cookie = new BasicClientCookie(name, value);
      cookie.setPath(getDefaultPath(origin));
      cookie.setDomain(getDefaultDomain(origin));
      
      NameValuePair[] attribs = headerelement.getParameters();
      for (int j = attribs.length - 1; j >= 0; j--)
      {
        NameValuePair attrib = attribs[j];
        String s = attrib.getName().toLowerCase(Locale.ENGLISH);
        
        cookie.setAttribute(s, attrib.getValue());
        
        CookieAttributeHandler handler = findAttribHandler(s);
        if (handler != null) {
          handler.parse(cookie, attrib.getValue());
        }
      }
      cookies.add(cookie);
    }
    return cookies;
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    for (CookieAttributeHandler handler : getAttribHandlers()) {
      handler.validate(cookie, origin);
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    for (CookieAttributeHandler handler : getAttribHandlers()) {
      if (!handler.match(cookie, origin)) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.CookieSpecBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Date;
import java.util.TimeZone;
import org.apache.http.annotation.Immutable;

@Deprecated
@Immutable
public final class DateUtils
{
  public static
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd