/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A simple in-memory java.net.CookieStore implementation
*
* @author Edward Wang
* @since 1.6
*/
// the in-memory representation of cookies
// the cookies are indexed by its domain and associated uri (if present)
// CAUTION: when a cookie removed from main data structure (i.e. cookieJar),
// it won't be cleared in domainIndex & uriIndex. Double-check the
// presence of cookie when retrieve one form index store.
// use ReentrantLock instead of syncronized for scalability
/**
* The default ctor
*/
public InMemoryCookieStore() {
lock = new ReentrantLock(false);
}
/**
* Add one cookie into cookie store.
*/
// pre-condition : argument can't be null
throw new NullPointerException("cookie is null");
}
try {
// remove the ole cookie if there has had one
// add new cookie if it has a non-zero max-age
// and add it to domain index
}
// add it to uri index, too
}
}
} finally {
}
}
/**
* Get all cookies, which:
* 1) given uri domain-matches with, or, associated with
* given uri when added to the cookie store.
* 3) not expired.
* See RFC 2965 sec. 3.3.4 for more detail.
*/
// argument can't be null
throw new NullPointerException("uri is null");
}
try {
// check domainIndex first
// check uriIndex then
} finally {
}
return cookies;
}
/**
* Get all cookies in cookie store, except those have expired
*/
try {
}
}
} finally {
}
return rt;
}
/**
* Get all URIs, which are associated with at least one cookie
* of this cookie store.
*/
try {
// no cookies list or an empty list associated with
// this uri entry, delete it
}
}
} finally {
}
return uris;
}
/**
* Remove a cookie from store
*/
// argument can't be null
throw new NullPointerException("cookie is null");
}
boolean modified = false;
try {
} finally {
}
return modified;
}
/**
* Remove all cookies in this cookie store.
*/
public boolean removeAll() {
try {
domainIndex.clear();
} finally {
}
return true;
}
/* ---------------- Private operations -------------- */
/*
* This is almost the same as HttpCookie.domainMatches except for
* one difference: It won't reject cookies when the 'H' part of the
* domain contains a dot ('.').
* I.E.: RFC 2965 section 3.3.2 says that if host is x.y.domain.com
* and the cookie domain is .domain.com, then it should be rejected.
* However that's not how the real world works. Browsers don't reject and
* some sites, like yahoo.com do actually expect these cookies to be
* passed along.
* And should be used for 'old' style cookies (aka Netscape type of cookies)
*/
{
return false;
}
// if there's no embedded dot in domain and domain is not .local
if (embeddedDotInDomain == 0) {
}
return false;
}
// if the host name contains no dot and the domain name is .local
return true;
}
if (lengthDiff == 0) {
// if the host name and the domain name are just string-compare euqal
} else if (lengthDiff > 0) {
// need to check H & D component
return (D.equalsIgnoreCase(domain));
} else if (lengthDiff == -1) {
// if domain is actually .host
}
return false;
}
// Use a separate list to handle cookies that need to be removed so
// that there is no conflict with iterators.
for (HttpCookie c : lst) {
// the cookie still in main cookie store
if (!c.hasExpired()) {
// don't add twice and make sure it's the proper
// security level
if ((secureLink || !c.getSecure()) &&
}
} else {
}
} else {
// the cookie has beed removed from main store,
// so also remove it from domain indexed store
}
}
}
// Clear up the cookies that need to be removed
for (HttpCookie c : toRemove) {
}
}
}
// @param cookies [OUT] contains the found cookies
// @param cookieIndex the index
// @param comparator the prediction to decide whether or not
// a cookie in index should be returned
{
// check the list of cookies associated with this domain
if (indexedCookies != null) {
// the cookie still in main cookie store
if (!ck.hasExpired()) {
// don't add twice
} else {
}
} else {
// the cookie has beed removed from main store,
// so also remove it from domain indexed store
}
}
} // end of indexedCookies != null
} // end of comparator.compareTo(index) == 0
} // end of cookieIndex iteration
}
// add 'cookie' indexed by 'index' into 'indexStore'
T index,
{
// there may already have the same cookie, so remove it first
} else {
}
}
}
//
// for cookie purpose, the effective uri should only be http://host
// the path will be taken into account when path-match algorithm applied
//
try {
null, // path component
null, // query component
null // fragment component
);
} catch (URISyntaxException ignored) {
effectiveURI = uri;
}
return effectiveURI;
}
}