diff --git a/ChangeLog b/ChangeLog index 664b0f77..ef3e2119 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-10 Tatsuhiro Tsujikawa + + Remove expired cookies first when cookies_ is full. + * src/CookieStorage.cc + 2010-10-10 Tatsuhiro Tsujikawa Rewritten util::split() diff --git a/src/CookieStorage.cc b/src/CookieStorage.cc index fd547230..b8b3bdb1 100644 --- a/src/CookieStorage.cc +++ b/src/CookieStorage.cc @@ -70,10 +70,18 @@ bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now) return false; } else { if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) { - // TODO First remove expired cookie - std::deque::iterator m = std::min_element - (cookies_.begin(), cookies_.end(), LeastRecentAccess()); - *m = cookie; + cookies_.erase + (std::remove_if(cookies_.begin(), cookies_.end(), + std::bind2nd + (std::mem_fun_ref(&Cookie::isExpired), now)), + cookies_.end()); + if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) { + std::deque::iterator m = std::min_element + (cookies_.begin(), cookies_.end(), LeastRecentAccess()); + *m = cookie; + } else { + cookies_.push_back(cookie); + } } else { cookies_.push_back(cookie); } @@ -113,8 +121,6 @@ static const double DOMAIN_EVICTION_RATE = 0.1; bool CookieStorage::store(const Cookie& cookie, time_t now) { if(domains_.size() >= DOMAIN_EVICTION_TRIGGER) { - // TODO Do this in a separete Command. - // TODO Erase expired cookie first std::sort(domains_.begin(), domains_.end(), LeastRecentAccess()); size_t delnum = (size_t)(domains_.size()*DOMAIN_EVICTION_RATE);