diff options
Diffstat (limited to 'mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie')
19 files changed, 1434 insertions, 0 deletions
diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/ClientCookie.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/ClientCookie.java new file mode 100644 index 000000000..1909f0999 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/ClientCookie.java @@ -0,0 +1,62 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +/** + * ClientCookie extends the standard {@link Cookie} interface with + * additional client specific functionality such ability to retrieve + * original cookie attributes exactly as they were specified by the + * origin server. This is important for generating the <tt>Cookie</tt> + * header because some cookie specifications require that the + * <tt>Cookie</tt> header should include certain attributes only if + * they were specified in the <tt>Set-Cookie</tt> header. + * + * + * @since 4.0 + */ +public interface ClientCookie extends Cookie { + + // RFC2109 attributes + public static final String VERSION_ATTR = "version"; + public static final String PATH_ATTR = "path"; + public static final String DOMAIN_ATTR = "domain"; + public static final String MAX_AGE_ATTR = "max-age"; + public static final String SECURE_ATTR = "secure"; + public static final String COMMENT_ATTR = "comment"; + public static final String EXPIRES_ATTR = "expires"; + + // RFC2965 attributes + public static final String PORT_ATTR = "port"; + public static final String COMMENTURL_ATTR = "commenturl"; + public static final String DISCARD_ATTR = "discard"; + + String getAttribute(String name); + + boolean containsAttribute(String name); + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/Cookie.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/Cookie.java new file mode 100644 index 000000000..9953ab794 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/Cookie.java @@ -0,0 +1,137 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import java.util.Date; + +/** + * Cookie interface represents a token or short packet of state information + * (also referred to as "magic-cookie") that the HTTP agent and the target + * server can exchange to maintain a session. In its simples form an HTTP + * cookie is merely a name / value pair. + * + * @since 4.0 + */ +public interface Cookie { + + /** + * Returns the name. + * + * @return String name The name + */ + String getName(); + + /** + * Returns the value. + * + * @return String value The current value. + */ + String getValue(); + + /** + * Returns the comment describing the purpose of this cookie, or + * <tt>null</tt> if no such comment has been defined. + * + * @return comment + */ + String getComment(); + + /** + * If a user agent (web browser) presents this cookie to a user, the + * cookie's purpose will be described by the information at this URL. + */ + String getCommentURL(); + + /** + * Returns the expiration {@link Date} of the cookie, or <tt>null</tt> + * if none exists. + * <p><strong>Note:</strong> the object returned by this method is + * considered immutable. Changing it (e.g. using setTime()) could result + * in undefined behaviour. Do so at your peril. </p> + * @return Expiration {@link Date}, or <tt>null</tt>. + */ + Date getExpiryDate(); + + /** + * Returns <tt>false</tt> if the cookie should be discarded at the end + * of the "session"; <tt>true</tt> otherwise. + * + * @return <tt>false</tt> if the cookie should be discarded at the end + * of the "session"; <tt>true</tt> otherwise + */ + boolean isPersistent(); + + /** + * Returns domain attribute of the cookie. The value of the Domain + * attribute specifies the domain for which the cookie is valid. + * + * @return the value of the domain attribute. + */ + String getDomain(); + + /** + * Returns the path attribute of the cookie. The value of the Path + * attribute specifies the subset of URLs on the origin server to which + * this cookie applies. + * + * @return The value of the path attribute. + */ + String getPath(); + + /** + * Get the Port attribute. It restricts the ports to which a cookie + * may be returned in a Cookie request header. + */ + int[] getPorts(); + + /** + * Indicates whether this cookie requires a secure connection. + * + * @return <code>true</code> if this cookie should only be sent + * over secure connections, <code>false</code> otherwise. + */ + boolean isSecure(); + + /** + * Returns the version of the cookie specification to which this + * cookie conforms. + * + * @return the version of the cookie. + */ + int getVersion(); + + /** + * Returns true if this cookie has expired. + * @param date Current time + * + * @return <tt>true</tt> if the cookie has expired. + */ + boolean isExpired(final Date date); + +} + diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieAttributeHandler.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieAttributeHandler.java new file mode 100644 index 000000000..3d94c8a6f --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieAttributeHandler.java @@ -0,0 +1,73 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package ch.boye.httpclientandroidlib.cookie; + +/** + * This interface represents a cookie attribute handler responsible + * for parsing, validating, and matching a specific cookie attribute, + * such as path, domain, port, etc. + * + * Different cookie specifications can provide a specific + * implementation for this class based on their cookie handling + * rules. + * + * + * @since 4.0 + */ +public interface CookieAttributeHandler { + + /** + * Parse the given cookie attribute value and update the corresponding + * {@link ch.boye.httpclientandroidlib.cookie.Cookie} property. + * + * @param cookie {@link ch.boye.httpclientandroidlib.cookie.Cookie} to be updated + * @param value cookie attribute value from the cookie response header + */ + void parse(SetCookie cookie, String value) + throws MalformedCookieException; + + /** + * Peforms cookie validation for the given attribute value. + * + * @param cookie {@link ch.boye.httpclientandroidlib.cookie.Cookie} to validate + * @param origin the cookie source to validate against + * @throws MalformedCookieException if cookie validation fails for this attribute + */ + void validate(Cookie cookie, CookieOrigin origin) + throws MalformedCookieException; + + /** + * Matches the given value (property of the destination host where request is being + * submitted) with the corresponding cookie attribute. + * + * @param cookie {@link ch.boye.httpclientandroidlib.cookie.Cookie} to match + * @param origin the cookie source to match against + * @return <tt>true</tt> if the match is successful; <tt>false</tt> otherwise + */ + boolean match(Cookie cookie, CookieOrigin origin); + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieIdentityComparator.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieIdentityComparator.java new file mode 100644 index 000000000..863640e69 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieIdentityComparator.java @@ -0,0 +1,80 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import java.io.Serializable; +import java.util.Comparator; + +import ch.boye.httpclientandroidlib.annotation.Immutable; + +/** + * This cookie comparator can be used to compare identity of cookies. + * <p> + * Cookies are considered identical if their names are equal and + * their domain attributes match ignoring case. + * + * @since 4.0 + */ +@Immutable +public class CookieIdentityComparator implements Serializable, Comparator<Cookie> { + + private static final long serialVersionUID = 4466565437490631532L; + + public int compare(final Cookie c1, final Cookie c2) { + int res = c1.getName().compareTo(c2.getName()); + if (res == 0) { + // do not differentiate empty and null domains + String d1 = c1.getDomain(); + if (d1 == null) { + d1 = ""; + } else if (d1.indexOf('.') == -1) { + d1 = d1 + ".local"; + } + String d2 = c2.getDomain(); + if (d2 == null) { + d2 = ""; + } else if (d2.indexOf('.') == -1) { + d2 = d2 + ".local"; + } + res = d1.compareToIgnoreCase(d2); + } + if (res == 0) { + String p1 = c1.getPath(); + if (p1 == null) { + p1 = "/"; + } + String p2 = c2.getPath(); + if (p2 == null) { + p2 = "/"; + } + res = p1.compareTo(p2); + } + return res; + } + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieOrigin.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieOrigin.java new file mode 100644 index 000000000..aef29023d --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieOrigin.java @@ -0,0 +1,94 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package ch.boye.httpclientandroidlib.cookie; + +import java.util.Locale; + +import ch.boye.httpclientandroidlib.annotation.Immutable; +import ch.boye.httpclientandroidlib.util.Args; + +/** + * CookieOrigin class encapsulates details of an origin server that + * are relevant when parsing, validating or matching HTTP cookies. + * + * @since 4.0 + */ +@Immutable +public final class CookieOrigin { + + private final String host; + private final int port; + private final String path; + private final boolean secure; + + public CookieOrigin(final String host, final int port, final String path, final boolean secure) { + super(); + Args.notBlank(host, "Host"); + Args.notNegative(port, "Port"); + Args.notNull(path, "Path"); + this.host = host.toLowerCase(Locale.ENGLISH); + this.port = port; + if (path.trim().length() != 0) { + this.path = path; + } else { + this.path = "/"; + } + this.secure = secure; + } + + public String getHost() { + return this.host; + } + + public String getPath() { + return this.path; + } + + public int getPort() { + return this.port; + } + + public boolean isSecure() { + return this.secure; + } + + @Override + public String toString() { + final StringBuilder buffer = new StringBuilder(); + buffer.append('['); + if (this.secure) { + buffer.append("(secure)"); + } + buffer.append(this.host); + buffer.append(':'); + buffer.append(Integer.toString(this.port)); + buffer.append(this.path); + buffer.append(']'); + return buffer.toString(); + } + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookiePathComparator.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookiePathComparator.java new file mode 100644 index 000000000..984bb850f --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookiePathComparator.java @@ -0,0 +1,81 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import java.io.Serializable; +import java.util.Comparator; + +import ch.boye.httpclientandroidlib.annotation.Immutable; + +/** + * This cookie comparator ensures that multiple cookies satisfying + * a common criteria are ordered in the <tt>Cookie</tt> header such + * that those with more specific Path attributes precede those with + * less specific. + * + * <p> + * This comparator assumes that Path attributes of two cookies + * path-match a commmon request-URI. Otherwise, the result of the + * comparison is undefined. + * </p> + * + * + * @since 4.0 + */ +@Immutable +public class CookiePathComparator implements Serializable, Comparator<Cookie> { + + private static final long serialVersionUID = 7523645369616405818L; + + private String normalizePath(final Cookie cookie) { + String path = cookie.getPath(); + if (path == null) { + path = "/"; + } + if (!path.endsWith("/")) { + path = path + '/'; + } + return path; + } + + public int compare(final Cookie c1, final Cookie c2) { + final String path1 = normalizePath(c1); + final String path2 = normalizePath(c2); + if (path1.equals(path2)) { + return 0; + } else if (path1.startsWith(path2)) { + return -1; + } else if (path2.startsWith(path1)) { + return 1; + } else { + // Does not really matter + return 0; + } + } + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieRestrictionViolationException.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieRestrictionViolationException.java new file mode 100644 index 000000000..1e3f2d70c --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieRestrictionViolationException.java @@ -0,0 +1,61 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import ch.boye.httpclientandroidlib.annotation.Immutable; + +/** + * Signals that a cookie violates a restriction imposed by the cookie + * specification. + * + * @since 4.1 + */ +@Immutable +public class CookieRestrictionViolationException extends MalformedCookieException { + + private static final long serialVersionUID = 7371235577078589013L; + + /** + * Creates a new CookeFormatViolationException with a <tt>null</tt> detail + * message. + */ + public CookieRestrictionViolationException() { + super(); + } + + /** + * Creates a new CookeRestrictionViolationException with a specified + * message string. + * + * @param message The exception detail message + */ + public CookieRestrictionViolationException(final String message) { + super(message); + } + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpec.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpec.java new file mode 100644 index 000000000..c222e5e72 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpec.java @@ -0,0 +1,109 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import java.util.List; + +import ch.boye.httpclientandroidlib.Header; + +/** + * Defines the cookie management specification. + * <p>Cookie management specification must define + * <ul> + * <li> rules of parsing "Set-Cookie" header + * <li> rules of validation of parsed cookies + * <li> formatting of "Cookie" header + * </ul> + * for a given host, port and path of origin + * + * + * @since 4.0 + */ +public interface CookieSpec { + + /** + * Returns version of the state management this cookie specification + * conforms to. + * + * @return version of the state management specification + */ + int getVersion(); + + /** + * Parse the <tt>"Set-Cookie"</tt> Header into an array of Cookies. + * + * <p>This method will not perform the validation of the resultant + * {@link Cookie}s</p> + * + * @see #validate + * + * @param header the <tt>Set-Cookie</tt> received from the server + * @param origin details of the cookie origin + * @return an array of <tt>Cookie</tt>s parsed from the header + * @throws MalformedCookieException if an exception occurs during parsing + */ + List<Cookie> parse(Header header, CookieOrigin origin) throws MalformedCookieException; + + /** + * Validate the cookie according to validation rules defined by the + * cookie specification. + * + * @param cookie the Cookie to validate + * @param origin details of the cookie origin + * @throws MalformedCookieException if the cookie is invalid + */ + void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException; + + /** + * Determines if a Cookie matches the target location. + * + * @param cookie the Cookie to be matched + * @param origin the target to test against + * + * @return <tt>true</tt> if the cookie should be submitted with a request + * with given attributes, <tt>false</tt> otherwise. + */ + boolean match(Cookie cookie, CookieOrigin origin); + + /** + * Create <tt>"Cookie"</tt> headers for an array of Cookies. + * + * @param cookies the Cookies format into a Cookie header + * @return a Header for the given Cookies. + * @throws IllegalArgumentException if an input parameter is illegal + */ + List<Header> formatCookies(List<Cookie> cookies); + + /** + * Returns a request header identifying what version of the state management + * specification is understood. May be <code>null</code> if the cookie + * specification does not support <tt>Cookie2</tt> header. + */ + Header getVersionHeader(); + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecFactory.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecFactory.java new file mode 100644 index 000000000..fd7851626 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecFactory.java @@ -0,0 +1,51 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import ch.boye.httpclientandroidlib.params.HttpParams; + +/** + * Factory for {@link CookieSpec} implementations. + * + * @since 4.0 + * + * @deprecated (4.3) use {@link CookieSpecProvider} + */ +@Deprecated +public interface CookieSpecFactory { + + /** + * Creates an instance of {@link CookieSpec} using given HTTP parameters. + * + * @param params HTTP parameters. + * + * @return cookie spec. + */ + CookieSpec newInstance(HttpParams params); + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecProvider.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecProvider.java new file mode 100644 index 000000000..921adfba4 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecProvider.java @@ -0,0 +1,46 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import ch.boye.httpclientandroidlib.protocol.HttpContext; + +/** + * Factory for {@link CookieSpec} implementations. + * + * @since 4.3 + */ +public interface CookieSpecProvider { + + /** + * Creates an instance of {@link CookieSpec}. + * + * @return auth scheme. + */ + CookieSpec create(HttpContext context); + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecRegistry.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecRegistry.java new file mode 100644 index 000000000..adbfe863a --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieSpecRegistry.java @@ -0,0 +1,167 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import ch.boye.httpclientandroidlib.HttpRequest; +import ch.boye.httpclientandroidlib.annotation.ThreadSafe; +import ch.boye.httpclientandroidlib.config.Lookup; +import ch.boye.httpclientandroidlib.params.HttpParams; +import ch.boye.httpclientandroidlib.protocol.ExecutionContext; +import ch.boye.httpclientandroidlib.protocol.HttpContext; +import ch.boye.httpclientandroidlib.util.Args; + +/** + * Cookie specification registry that can be used to obtain the corresponding + * cookie specification implementation for a given type of type or version of + * cookie. + * + * @since 4.0 + * + * @deprecated (4.3) use {@link ch.boye.httpclientandroidlib.config.Registry}. + */ +@ThreadSafe +@Deprecated +public final class CookieSpecRegistry implements Lookup<CookieSpecProvider> { + + private final ConcurrentHashMap<String,CookieSpecFactory> registeredSpecs; + + public CookieSpecRegistry() { + super(); + this.registeredSpecs = new ConcurrentHashMap<String,CookieSpecFactory>(); + } + + /** + * Registers a {@link CookieSpecFactory} with the given identifier. + * If a specification with the given name already exists it will be overridden. + * This nameis the same one used to retrieve the {@link CookieSpecFactory} + * from {@link #getCookieSpec(String)}. + * + * @param name the identifier for this specification + * @param factory the {@link CookieSpecFactory} class to register + * + * @see #getCookieSpec(String) + */ + public void register(final String name, final CookieSpecFactory factory) { + Args.notNull(name, "Name"); + Args.notNull(factory, "Cookie spec factory"); + registeredSpecs.put(name.toLowerCase(Locale.ENGLISH), factory); + } + + /** + * Unregisters the {@link CookieSpecFactory} with the given ID. + * + * @param id the identifier of the {@link CookieSpec cookie specification} to unregister + */ + public void unregister(final String id) { + Args.notNull(id, "Id"); + registeredSpecs.remove(id.toLowerCase(Locale.ENGLISH)); + } + + /** + * Gets the {@link CookieSpec cookie specification} with the given ID. + * + * @param name the {@link CookieSpec cookie specification} identifier + * @param params the {@link HttpParams HTTP parameters} for the cookie + * specification. + * + * @return {@link CookieSpec cookie specification} + * + * @throws IllegalStateException if a policy with the given name cannot be found + */ + public CookieSpec getCookieSpec(final String name, final HttpParams params) + throws IllegalStateException { + + Args.notNull(name, "Name"); + final CookieSpecFactory factory = registeredSpecs.get(name.toLowerCase(Locale.ENGLISH)); + if (factory != null) { + return factory.newInstance(params); + } else { + throw new IllegalStateException("Unsupported cookie spec: " + name); + } + } + + /** + * Gets the {@link CookieSpec cookie specification} with the given name. + * + * @param name the {@link CookieSpec cookie specification} identifier + * + * @return {@link CookieSpec cookie specification} + * + * @throws IllegalStateException if a policy with the given name cannot be found + */ + public CookieSpec getCookieSpec(final String name) + throws IllegalStateException { + return getCookieSpec(name, null); + } + + /** + * Obtains a list containing the names of all registered {@link CookieSpec cookie + * specs}. + * + * Note that the DEFAULT policy (if present) is likely to be the same + * as one of the other policies, but does not have to be. + * + * @return list of registered cookie spec names + */ + public List<String> getSpecNames(){ + return new ArrayList<String>(registeredSpecs.keySet()); + } + + /** + * Populates the internal collection of registered {@link CookieSpec cookie + * specs} with the content of the map passed as a parameter. + * + * @param map cookie specs + */ + public void setItems(final Map<String, CookieSpecFactory> map) { + if (map == null) { + return; + } + registeredSpecs.clear(); + registeredSpecs.putAll(map); + } + + public CookieSpecProvider lookup(final String name) { + return new CookieSpecProvider() { + + public CookieSpec create(final HttpContext context) { + final HttpRequest request = (HttpRequest) context.getAttribute( + ExecutionContext.HTTP_REQUEST); + return getCookieSpec(name, request.getParams()); + } + + }; + } + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/MalformedCookieException.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/MalformedCookieException.java new file mode 100644 index 000000000..dba7b9b25 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/MalformedCookieException.java @@ -0,0 +1,71 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import ch.boye.httpclientandroidlib.ProtocolException; +import ch.boye.httpclientandroidlib.annotation.Immutable; + +/** + * Signals that a cookie is in some way invalid or illegal in a given + * context + * + * + * @since 4.0 + */ +@Immutable +public class MalformedCookieException extends ProtocolException { + + private static final long serialVersionUID = -6695462944287282185L; + + /** + * Creates a new MalformedCookieException with a <tt>null</tt> detail message. + */ + public MalformedCookieException() { + super(); + } + + /** + * Creates a new MalformedCookieException with a specified message string. + * + * @param message The exception detail message + */ + public MalformedCookieException(final String message) { + super(message); + } + + /** + * Creates a new MalformedCookieException with the specified detail message and cause. + * + * @param message the exception detail message + * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt> + * if the cause is unavailable, unknown, or not a <tt>Throwable</tt> + */ + public MalformedCookieException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SM.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SM.java new file mode 100644 index 000000000..463da4d25 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SM.java @@ -0,0 +1,43 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +/** + * Constants and static helpers related to the HTTP state management. + * + * + * @since 4.0 + */ +public interface SM { + + public static final String COOKIE = "Cookie"; + public static final String COOKIE2 = "Cookie2"; + public static final String SET_COOKIE = "Set-Cookie"; + public static final String SET_COOKIE2 = "Set-Cookie2"; + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SetCookie.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SetCookie.java new file mode 100644 index 000000000..5bd5b7121 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SetCookie.java @@ -0,0 +1,109 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +import java.util.Date; + +/** + * This interface represents a <code>Set-Cookie</code> response header sent by the + * origin server to the HTTP agent in order to maintain a conversational state. + * + * @since 4.0 + */ +public interface SetCookie extends Cookie { + + void setValue(String value); + + /** + * If a user agent (web browser) presents this cookie to a user, the + * cookie's purpose will be described using this comment. + * + * @param comment + * + * @see #getComment() + */ + void setComment(String comment); + + /** + * Sets expiration date. + * <p><strong>Note:</strong> the object returned by this method is considered + * immutable. Changing it (e.g. using setTime()) could result in undefined + * behaviour. Do so at your peril.</p> + * + * @param expiryDate the {@link Date} after which this cookie is no longer valid. + * + * @see Cookie#getExpiryDate + * + */ + void setExpiryDate (Date expiryDate); + + /** + * Sets the domain attribute. + * + * @param domain The value of the domain attribute + * + * @see Cookie#getDomain + */ + void setDomain(String domain); + + /** + * Sets the path attribute. + * + * @param path The value of the path attribute + * + * @see Cookie#getPath + * + */ + void setPath(String path); + + /** + * Sets the secure attribute of the cookie. + * <p> + * When <tt>true</tt> the cookie should only be sent + * using a secure protocol (https). This should only be set when + * the cookie's originating server used a secure protocol to set the + * cookie's value. + * + * @param secure The value of the secure attribute + * + * @see #isSecure() + */ + void setSecure (boolean secure); + + /** + * Sets the version of the cookie specification to which this + * cookie conforms. + * + * @param version the version of the cookie. + * + * @see Cookie#getVersion + */ + void setVersion(int version); + +} + diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SetCookie2.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SetCookie2.java new file mode 100644 index 000000000..bc3508059 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/SetCookie2.java @@ -0,0 +1,60 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie; + +/** + * This interface represents a <code>Set-Cookie2</code> response header sent by the + * origin server to the HTTP agent in order to maintain a conversational state. + * + * @since 4.0 + */ +public interface SetCookie2 extends SetCookie { + + /** + * If a user agent (web browser) presents this cookie to a user, the + * cookie's purpose will be described by the information at this URL. + */ + void setCommentURL(String commentURL); + + /** + * Sets the Port attribute. It restricts the ports to which a cookie + * may be returned in a Cookie request header. + */ + void setPorts(int[] ports); + + /** + * Set the Discard attribute. + * + * Note: <tt>Discard</tt> attribute overrides <tt>Max-age</tt>. + * + * @see #isPersistent() + */ + void setDiscard(boolean discard); + +} + diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/package-info.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/package-info.java new file mode 100644 index 000000000..80a831709 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/package-info.java @@ -0,0 +1,31 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +/** + * Client HTTP state management APIs. + */ +package ch.boye.httpclientandroidlib.cookie; diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/CookieSpecPNames.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/CookieSpecPNames.java new file mode 100644 index 000000000..a93a26f16 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/CookieSpecPNames.java @@ -0,0 +1,65 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie.params; + +/** + * Parameter names for HTTP cookie management classes. + * + * @since 4.0 + * + * @deprecated (4.3) use constructor parameters of {@link + * ch.boye.httpclientandroidlib.cookie.CookieSpecProvider}s. + */ +@Deprecated +public interface CookieSpecPNames { + + /** + * Defines valid date patterns to be used for parsing non-standard + * <code>expires</code> attribute. Only required for compatibility + * with non-compliant servers that still use <code>expires</code> + * defined in the Netscape draft instead of the standard + * <code>max-age</code> attribute. + * <p> + * This parameter expects a value of type {@link java.util.Collection}. + * The collection elements must be of type {@link String} compatible + * with the syntax of {@link java.text.SimpleDateFormat}. + * </p> + */ + public static final String DATE_PATTERNS = "http.protocol.cookie-datepatterns"; + + /** + * Defines whether cookies should be forced into a single + * <code>Cookie</code> request header. Otherwise, each cookie is formatted + * as a separate <code>Cookie</code> header. + * <p> + * This parameter expects a value of type {@link Boolean}. + * </p> + */ + public static final String SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header"; + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/CookieSpecParamBean.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/CookieSpecParamBean.java new file mode 100644 index 000000000..0e007a54f --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/CookieSpecParamBean.java @@ -0,0 +1,62 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package ch.boye.httpclientandroidlib.cookie.params; + +import java.util.Collection; + +import ch.boye.httpclientandroidlib.annotation.NotThreadSafe; +import ch.boye.httpclientandroidlib.params.HttpAbstractParamBean; +import ch.boye.httpclientandroidlib.params.HttpParams; + +/** + * This is a Java Bean class that can be used to wrap an instance of + * {@link HttpParams} and manipulate HTTP cookie parameters using Java Beans + * conventions. + * + * @since 4.0 + * + * @deprecated (4.3) use constructor parameters of {@link + * ch.boye.httpclientandroidlib.cookie.CookieSpecProvider}s. + */ +@Deprecated +@NotThreadSafe +public class CookieSpecParamBean extends HttpAbstractParamBean { + + public CookieSpecParamBean (final HttpParams params) { + super(params); + } + + public void setDatePatterns (final Collection <String> patterns) { + params.setParameter(CookieSpecPNames.DATE_PATTERNS, patterns); + } + + public void setSingleHeader (final boolean singleHeader) { + params.setBooleanParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, singleHeader); + } + +} diff --git a/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/package-info.java b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/package-info.java new file mode 100644 index 000000000..9314e1e63 --- /dev/null +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/params/package-info.java @@ -0,0 +1,32 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +/** + * Deprecated. + * @deprecated (4.3). + */ +package ch.boye.httpclientandroidlib.cookie.params; |