[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kioslave/http/kcookiejar
From:       Waldo Bastian <bastian () kde ! org>
Date:       2004-11-30 10:26:24
Message-ID: 20041130102624.78E161BA04 () office ! kde ! org
[Download RAW message or body]

CVS commit by waba: 

Implemented cookie limits, disabled for now.
CCBUG: 87227


  M +32 -3     kcookiejar.cpp   1.120


--- kdelibs/kioslave/http/kcookiejar/kcookiejar.cpp  #1.119:1.120
@@ -72,4 +72,14 @@
 #include "kcookiejar.h"
 
+
+// BR87227
+// Waba: Should the number of cookies be limited?
+// I am not convinced of the need of such limit
+// Mozilla seems to limit to 20 cookies / domain
+// but it is unclear which policy it uses to expire
+// cookies when it exceeds that amount
+#undef MAX_COOKIE_LIMIT
+
+#define MAX_COOKIES_PER_HOST 25
 #define READ_BUFFER_SIZE 8192
 
@@ -873,4 +882,20 @@ KHttpCookieList KCookieJar::makeDOMCooki
 }
 
+#ifdef MAX_COOKIE_LIMIT
+static void makeRoom(KHttpCookieList *cookieList, KHttpCookiePtr &cookiePtr)
+{
+     // Too much cookies: throw one away, try to be somewhat clever
+     KHttpCookiePtr lastCookie = 0;
+     for(KHttpCookiePtr cookie = cookieList->first(); cookie; cookie = cookieList->next())
+     {
+         if (cookieList->compareItems(cookie, cookiePtr) < 0)
+            break;
+         lastCookie = cookie;
+     }
+     if (!lastCookie)
+         lastCookie = cookieList->first();
+     cookieList->removeRef(lastCookie);
+}
+#endif
 
 //
@@ -923,4 +948,8 @@ void KCookieJar::addCookie(KHttpCookiePt
     if (!cookiePtr->isExpired(time(0)))
     {
+#ifdef MAX_COOKIE_LIMIT
+        if (cookieList->count() >= MAX_COOKIES_PER_HOST)
+           makeRoom(cookieList, cookiePtr); // Delete a cookie
+#endif           
         cookieList->inSort( cookiePtr );
         m_cookiesChanged = true;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic