summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/io.pri3
-rw-r--r--src/corelib/io/qtldurl.cpp117
-rw-r--r--src/corelib/io/qtldurl_p.h66
-rw-r--r--src/corelib/io/qurl.cpp19
-rw-r--r--src/corelib/io/qurl.h3
-rw-r--r--src/corelib/io/qurltlds_p.h (renamed from src/network/access/qnetworkcookiejartlds_p.h)10
-rw-r--r--src/corelib/io/qurltlds_p.h.INFO (renamed from src/network/access/qnetworkcookiejartlds_p.h.INFO)8
-rw-r--r--src/network/access/access.pri1
-rw-r--r--src/network/access/qnetworkcookiejar.cpp43
-rw-r--r--src/network/access/qnetworkcookiejar_p.h3
10 files changed, 218 insertions, 55 deletions
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index f67600d750..e411f8f643 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -24,6 +24,8 @@ HEADERS += \
io/qresource_p.h \
io/qresource_iterator_p.h \
io/qurl.h \
+ io/qurltlds_p.h \
+ io/qtldurl_p.h \
io/qsettings.h \
io/qsettings_p.h \
io/qfsfileengine.h \
@@ -41,6 +43,7 @@ SOURCES += \
io/qbuffer.cpp \
io/qdatastream.cpp \
io/qdataurl.cpp \
+ io/qtldurl.cpp \
io/qdebug.cpp \
io/qdir.cpp \
io/qdiriterator.cpp \
diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp
new file mode 100644
index 0000000000..7db4bbddd5
--- /dev/null
+++ b/src/corelib/io/qtldurl.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformdefs.h"
+#include "qurl.h"
+#include "private/qurltlds_p.h"
+#include "private/qtldurl_p.h"
+#include "QtCore/qstringlist.h"
+
+QT_BEGIN_NAMESPACE
+
+static bool containsTLDEntry(const QString &entry)
+{
+ int index = qHash(entry) % tldCount;
+ int currentDomainIndex = tldIndices[index];
+ while (currentDomainIndex < tldIndices[index+1]) {
+ QString currentEntry = QString::fromUtf8(tldData + currentDomainIndex);
+ if (currentEntry == entry)
+ return true;
+ currentDomainIndex += qstrlen(tldData + currentDomainIndex) + 1; // +1 for the ending \0
+ }
+ return false;
+}
+
+/*!
+ \internal
+
+ Return the top-level-domain per Qt's copy of the Mozilla public suffix list of
+ \a domain.
+*/
+
+Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain)
+{
+ QStringList sections = domain.toLower().split(QLatin1Char('.'), QString::SkipEmptyParts);
+ if (sections.isEmpty())
+ return QString();
+
+ QString level, tld;
+ for (int j = sections.count() - 1; j >= 0; --j) {
+ level.prepend(QLatin1Char('.') + sections.at(j));
+ if (qIsEffectiveTLD(level.right(level.size() - 1)))
+ tld = level;
+ }
+ return tld;
+}
+
+/*!
+ \internal
+
+ Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.
+*/
+
+Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain)
+{
+ // for domain 'foo.bar.com':
+ // 1. return if TLD table contains 'foo.bar.com'
+ if (containsTLDEntry(domain))
+ return true;
+
+ if (domain.contains(QLatin1Char('.'))) {
+ int count = domain.size() - domain.indexOf(QLatin1Char('.'));
+ QString wildCardDomain;
+ wildCardDomain.reserve(count + 1);
+ wildCardDomain.append(QLatin1Char('*'));
+ wildCardDomain.append(domain.right(count));
+ // 2. if table contains '*.bar.com',
+ // test if table contains '!foo.bar.com'
+ if (containsTLDEntry(wildCardDomain)) {
+ QString exceptionDomain;
+ exceptionDomain.reserve(domain.size() + 1);
+ exceptionDomain.append(QLatin1Char('!'));
+ exceptionDomain.append(domain);
+ return (! containsTLDEntry(exceptionDomain));
+ }
+ }
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/io/qtldurl_p.h b/src/corelib/io/qtldurl_p.h
new file mode 100644
index 0000000000..152ffa0f63
--- /dev/null
+++ b/src/corelib/io/qtldurl_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTLDURL_P_H
+#define QTLDURL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qDecodeDataUrl. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qurl.h"
+#include "QtCore/qstring.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain);
+Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain);
+
+QT_END_NAMESPACE
+
+#endif // QDATAURL_P_H
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index efd3f45ef0..c433d3519c 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -192,7 +192,9 @@
#if defined QT3_SUPPORT
#include "qfileinfo.h"
#endif
-
+#ifndef QT_BOOTSTRAPPED
+#include "qtldurl_p.h"
+#endif
#if defined(Q_OS_WINCE_WM)
#pragma optimize("g", off)
#endif
@@ -5593,6 +5595,21 @@ bool QUrl::hasFragment() const
}
/*!
+ \since 4.8
+
+ Returns the TLD (Top-Level Domain) of the URL, (e.g. .co.uk, .net).
+ Note that the return value is prefixed with a '.' unless the
+ URL does not contain a valid TLD, in which case the function returns
+ an empty string.
+*/
+#ifndef QT_BOOTSTRAPPED
+QString QUrl::topLevelDomain() const
+{
+ return qTopLevelDomain(host());
+}
+#endif
+
+/*!
Returns the result of the merge of this URL with \a relative. This
URL is used as a base to convert \a relative to an absolute URL.
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index 7534b8d474..07b0b4e68d 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -181,6 +181,9 @@ public:
void setEncodedFragment(const QByteArray &fragment);
QByteArray encodedFragment() const;
bool hasFragment() const;
+#ifndef QT_BOOTSTRAPPED
+ QString topLevelDomain() const;
+#endif
QUrl resolved(const QUrl &relative) const;
diff --git a/src/network/access/qnetworkcookiejartlds_p.h b/src/corelib/io/qurltlds_p.h
index b06d881131..f4f525ced7 100644
--- a/src/network/access/qnetworkcookiejartlds_p.h
+++ b/src/corelib/io/qurltlds_p.h
@@ -38,15 +38,15 @@
// the terms of any one of the MPL, the GPL or the LGPL.
//
-#ifndef QNETWORKCOOKIEJARTLD_P_H
-#define QNETWORKCOOKIEJARTLD_P_H
+#ifndef QURLTLD_P_H
+#define QURLTLD_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of the Network Access framework. This header file may change from
+// of the Network Access and Core framework. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
// note to maintainer:
// this file should be updated before each release ->
// for instructions see the program at
-// util/network/cookiejar-generateTLDs
+// util/corelib/qurl-generateTLDs
static const quint16 tldCount = 3949;
static const quint16 tldIndices[] = {
@@ -6478,4 +6478,4 @@ static const char tldData[] = {
QT_END_NAMESPACE
-#endif // QNETWORKCOOKIEJARTLD_P_H
+#endif // QURLTLD_P_H
diff --git a/src/network/access/qnetworkcookiejartlds_p.h.INFO b/src/corelib/io/qurltlds_p.h.INFO
index 57a8d0e0cc..5781c2c678 100644
--- a/src/network/access/qnetworkcookiejartlds_p.h.INFO
+++ b/src/corelib/io/qurltlds_p.h.INFO
@@ -1,15 +1,15 @@
-The file qnetworkcookiejartlds_p.h is generated from the Public Suffix
+The file qurltlds_p.h is generated from the Public Suffix
List (see [1] and [2]), by the program residing at
-util/network/cookiejar-generateTLDs in the Qt source tree.
+util/corelib/qurl-generateTLDs in the Qt source tree.
That program generates a character array and an index array from the
list to provide fast lookups of elements within C++.
-Those arrays in qnetworkcookiejartlds_p.h are derived from the Public
+Those arrays in qurltlds_p.h are derived from the Public
Suffix List ([2]), which was originally provided by
Jo Hermans <jo.hermans@gmail.com>.
-The file qnetworkcookiejartlds_p.h was last generated Friday,
+The file qurltlds_p.h was last generated Friday,
November 19th 15:24 2010.
----
diff --git a/src/network/access/access.pri b/src/network/access/access.pri
index 0f901b873d..3d5558d334 100644
--- a/src/network/access/access.pri
+++ b/src/network/access/access.pri
@@ -21,7 +21,6 @@ HEADERS += \
access/qnetworkcookie_p.h \
access/qnetworkcookiejar.h \
access/qnetworkcookiejar_p.h \
- access/qnetworkcookiejartlds_p.h \
access/qnetworkrequest.h \
access/qnetworkrequest_p.h \
access/qnetworkreply.h \
diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp
index 53fab9f0c4..f2b1714002 100644
--- a/src/network/access/qnetworkcookiejar.cpp
+++ b/src/network/access/qnetworkcookiejar.cpp
@@ -40,12 +40,12 @@
****************************************************************************/
#include "qnetworkcookiejar.h"
-#include "qnetworkcookiejartlds_p.h"
#include "qnetworkcookiejar_p.h"
#include "QtNetwork/qnetworkcookie.h"
#include "QtCore/qurl.h"
#include "QtCore/qdatetime.h"
+#include "private/qtldurl_p.h"
QT_BEGIN_NAMESPACE
@@ -216,7 +216,7 @@ bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieLis
// the check for effective TLDs makes the "embedded dot" rule from RFC 2109 section 4.3.2
// redundant; the "leading dot" rule has been relaxed anyway, see above
// we remove the leading dot for this check
- if (QNetworkCookieJarPrivate::isEffectiveTLD(domain.remove(0, 1)))
+ if (qIsEffectiveTLD(domain.remove(0, 1)))
continue; // not accepted
}
@@ -304,43 +304,4 @@ QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const
return result;
}
-bool QNetworkCookieJarPrivate::isEffectiveTLD(const QString &domain)
-{
- // for domain 'foo.bar.com':
- // 1. return if TLD table contains 'foo.bar.com'
- if (containsTLDEntry(domain))
- return true;
-
- if (domain.contains(QLatin1Char('.'))) {
- int count = domain.size() - domain.indexOf(QLatin1Char('.'));
- QString wildCardDomain;
- wildCardDomain.reserve(count + 1);
- wildCardDomain.append(QLatin1Char('*'));
- wildCardDomain.append(domain.right(count));
- // 2. if table contains '*.bar.com',
- // test if table contains '!foo.bar.com'
- if (containsTLDEntry(wildCardDomain)) {
- QString exceptionDomain;
- exceptionDomain.reserve(domain.size() + 1);
- exceptionDomain.append(QLatin1Char('!'));
- exceptionDomain.append(domain);
- return (! containsTLDEntry(exceptionDomain));
- }
- }
- return false;
-}
-
-bool QNetworkCookieJarPrivate::containsTLDEntry(const QString &entry)
-{
- int index = qHash(entry) % tldCount;
- int currentDomainIndex = tldIndices[index];
- while (currentDomainIndex < tldIndices[index+1]) {
- QString currentEntry = QString::fromUtf8(tldData + currentDomainIndex);
- if (currentEntry == entry)
- return true;
- currentDomainIndex += qstrlen(tldData + currentDomainIndex) + 1; // +1 for the ending \0
- }
- return false;
-}
-
QT_END_NAMESPACE
diff --git a/src/network/access/qnetworkcookiejar_p.h b/src/network/access/qnetworkcookiejar_p.h
index d6dc45057c..ce5a87a98c 100644
--- a/src/network/access/qnetworkcookiejar_p.h
+++ b/src/network/access/qnetworkcookiejar_p.h
@@ -63,9 +63,6 @@ class QNetworkCookieJarPrivate: public QObjectPrivate
public:
QList<QNetworkCookie> allCookies;
- static bool Q_AUTOTEST_EXPORT isEffectiveTLD(const QString &domain);
- static bool containsTLDEntry(const QString &entry);
-
Q_DECLARE_PUBLIC(QNetworkCookieJar)
};