kioslave: convert TLDs to static immutable lists

too much I/O and parsing for two sets converted from lists, it is absurd

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-05-28 03:06:21 +03:00
parent 5d024e5a0e
commit 7160a409e5
4 changed files with 60 additions and 20 deletions

View file

@ -47,10 +47,6 @@ install(TARGETS kded_kcookiejar DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
########### install files ###############
install(
FILES domain_info
DESTINATION ${KDE4_DATA_INSTALL_DIR}/kwebkitpart
)
install(
FILES
kcookiejar.desktop

View file

@ -1,2 +0,0 @@
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
gTLDs=com,edu,gov,int,mil,net,org,biz,info,name,pro,aero,coop,museum,asia,cat,jobs,mobi,tel,travel

View file

@ -293,11 +293,6 @@ KCookieJar::KCookieJar()
m_globalAdvice = KCookieDunno;
m_configChanged = false;
m_cookiesChanged = false;
KConfig cfg( "khtml/domain_info", KConfig::NoGlobals, "data" );
KConfigGroup group( &cfg, QString() );
m_gTLDs = QSet<QString>::fromList(group.readEntry("gTLDs", QStringList()));
m_twoLevelTLD = QSet<QString>::fromList(group.readEntry("twoLevelTLD", QStringList()));
}
//
@ -588,10 +583,64 @@ bool KCookieJar::parseUrl(const QString &_url, QString &_fqdn, QString &_path, i
return true;
}
// not static because it uses m_twoLevelTLD
void KCookieJar::extractDomains(const QString &_fqdn,
QStringList &_domains) const
void KCookieJar::extractDomains(const QString &_fqdn, QStringList &_domains)
{
static const QStringList s_twoLevelTLD = QStringList()
<< "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";
static const QStringList s_gTLDs = QStringList()
<< "com"
<< "edu"
<< "gov"
<< "int"
<< "mil"
<< "net"
<< "org"
<< "biz"
<< "info"
<< "name"
<< "pro"
<< "aero"
<< "coop"
<< "museum"
<< "asia"
<< "cat"
<< "jobs"
<< "mobi"
<< "tel"
<< "travel";
if (_fqdn.isEmpty()) {
_domains.append( QL1S("localhost") );
return;
@ -626,7 +675,7 @@ void KCookieJar::extractDomains(const QString &_fqdn,
if (partList.count() == 1)
break; // We only have a TLD left.
if ((partList.count() == 2) && m_twoLevelTLD.contains(partList[1].toLower()))
if ((partList.count() == 2) && s_twoLevelTLD.contains(partList[1].toLower()))
{
// This domain uses two-level TLDs in the form xxxx.yy
break;
@ -641,7 +690,7 @@ void KCookieJar::extractDomains(const QString &_fqdn,
// Catch some TLDs that we miss with the previous check
// e.g. com.au, org.uk, mil.co
if (m_gTLDs.contains(partList[0].toLower()))
if (s_gTLDs.contains(partList[0].toLower()))
break;
}

View file

@ -347,8 +347,7 @@ public:
* The list is sorted with the FQDN listed first and the top-most
* domain listed last
*/
void extractDomains(const QString &_fqdn,
QStringList &_domainList) const;
static void extractDomains(const QString &_fqdn, QStringList &_domainList);
static QString adviceToStr(KCookieAdvice _advice);
static KCookieAdvice strToAdvice(const QString &_str);
@ -383,8 +382,6 @@ protected:
QStringList m_domainList;
KCookieAdvice m_globalAdvice;
QHash<QString, KHttpCookieList*> m_cookieDomains;
QSet<QString> m_twoLevelTLD;
QSet<QString> m_gTLDs;
bool m_configChanged;
bool m_cookiesChanged;