Index: kioslave/http/kcookiejar/kcookiejar.cpp =================================================================== RCS file: /home/kde/kdelibs/kioslave/http/kcookiejar/kcookiejar.cpp,v retrieving revision 1.76.2.1 diff -u -p -r1.76.2.1 kcookiejar.cpp --- kioslave/http/kcookiejar/kcookiejar.cpp 2 Aug 2002 19:01:34 -0000 1.76.2.1 +++ kioslave/http/kcookiejar/kcookiejar.cpp 28 Jul 2004 06:51:40 -0000 @@ -240,6 +240,14 @@ KCookieJar::KCookieJar() globalAdvice = KCookieDunno; configChanged = false; cookiesChanged = false; + + QString twoLevelTLD="name,ai,au,bd,bh,ck,eg,et,fk,il,in,kh,kr,mk,mt,na,np,nz,pg,pk,qa,sa,sb,sg,sv,ua,ug,uk,uy,vn,za,zw"; + QStringList countries = QStringList::split(',', twoLevelTLD); + for(QStringList::ConstIterator it = countries.begin(); + it != countries.end(); ++it) + { + m_twoLevelTLD.replace(*it, (int *) 1); + } } // @@ -444,14 +452,14 @@ static const char * parseNameValue(const } -static void stripDomain(const QString &_fqdn, QString &_domain) +void KCookieJar::stripDomain(const QString &_fqdn, QString &_domain) { QStringList domains; - KCookieJar::extractDomains(_fqdn, domains); + extractDomains(_fqdn, domains); _domain = domains[0]; } -static QString stripDomain( KHttpCookiePtr cookiePtr) +QString KCookieJar::stripDomain( KHttpCookiePtr cookiePtr) { QString domain; // We file the cookie under this domain. if (cookiePtr->domain().isEmpty()) @@ -504,13 +512,30 @@ void KCookieJar::extractDomains(const QS { if (partList.count() == 1) break; // We only have a TLD left. + if (partList.count() == 2) { // If this is a TLD, we should stop. (e.g. co.uk) + if (m_twoLevelTLD[partList[1].lower()]) + { + // This domain uses two-level TLDs in the form xxxx.yy + break; + } + // We assume this is a TLD if it ends with .xx.yy or .x.yy - if ((partList[0].length() <= 2) && - (partList[1].length() == 2)) - break; // This is a TLD. + if (partList[1].length() == 2) + { + // If this is a TLD, we should stop. (e.g. co.uk) + // We assume this is a TLD if it ends with .xx.yy or .x.yy + if (partList[0].length() <= 2) + break; // This is a TLD. + + // Catch some TLDs that we miss with the previous check + // e.g. com.au, org.uk, mil.co + QCString t = partList[0].lower().utf8(); + if ((t == "com") || (t == "net") || (t == "org") || (t == "gov") || (t == "edu") || (t == "mil") || (t == "int")) + break; + } } QString domain = partList.join("."); _domains.append("." + domain); Index: kioslave/http/kcookiejar/kcookiejar.h =================================================================== RCS file: /home/kde/kdelibs/kioslave/http/kcookiejar/kcookiejar.h,v retrieving revision 1.24 diff -u -p -r1.24 kcookiejar.h --- kioslave/http/kcookiejar/kcookiejar.h 22 Sep 2001 22:56:14 -0000 1.24 +++ kioslave/http/kcookiejar/kcookiejar.h 28 Jul 2004 06:51:41 -0000 @@ -297,8 +297,8 @@ public: /** * Returns a list of domains (_domainList) relevant for this host. */ - static void extractDomains(const QString &_fqdn, - QStringList &_domainList); + void extractDomains(const QString &_fqdn, + QStringList &_domainList); static QString adviceToStr(KCookieAdvice _advice); static KCookieAdvice strToAdvice(const QString &_str); @@ -308,9 +308,15 @@ public: bool showCookieDetails; // true, false protected: + void stripDomain(const QString &_fqdn, QString &_domain); + QString stripDomain( KHttpCookiePtr cookiePtr); + +protected: QDict cookieDomains; QStringList domainList; KCookieAdvice globalAdvice; + QDict m_twoLevelTLD; + bool configChanged; bool cookiesChanged; }; Index: kioslave/http/kcookiejar/kcookieserver.cpp =================================================================== RCS file: /home/kde/kdelibs/kioslave/http/kcookiejar/kcookieserver.cpp,v retrieving revision 1.38 diff -u -p -r1.38 kcookieserver.cpp --- kioslave/http/kcookiejar/kcookieserver.cpp 10 Oct 2001 17:40:40 -0000 1.38 +++ kioslave/http/kcookiejar/kcookieserver.cpp 28 Jul 2004 06:51:41 -0000 @@ -136,7 +136,7 @@ bool KCookieServer::cookiesPending( cons if (!KCookieJar::parseURL(url, fqdn, path)) return false; - KCookieJar::extractDomains( fqdn, domains ); + mCookieJar->extractDomains( fqdn, domains ); for( KHttpCookie *cookie = mPendingCookies->first(); cookie != 0L; cookie = mPendingCookies->next()) @@ -500,7 +500,7 @@ KCookieServer::setDomainAdvice(QString u if (KCookieJar::parseURL(url, fqdn, dummy)) { QStringList domains; - KCookieJar::extractDomains(fqdn, domains); + mCookieJar->extractDomains(fqdn, domains); mCookieJar->setDomainAdvice(domains[0], KCookieJar::strToAdvice(advice)); } @@ -516,7 +516,7 @@ KCookieServer::getDomainAdvice(QString u if (KCookieJar::parseURL(url, fqdn, dummy)) { QStringList domains; - KCookieJar::extractDomains(fqdn, domains); + mCookieJar->extractDomains(fqdn, domains); advice = mCookieJar->getDomainAdvice(domains[0]); } return KCookieJar::adviceToStr(advice);