qtldurl.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qtldurl.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qplatformdefs.h"-
41#include "qurl.h"-
42#include "private/qurltlds_p.h"-
43#include "private/qtldurl_p.h"-
44#include "QtCore/qstring.h"-
45#include "QtCore/qvector.h"-
46-
47QT_BEGIN_NAMESPACE-
48-
49static bool containsTLDEntry(const QStringRef &entry)-
50{-
51 int index = qt_hash(entry) % tldCount;-
52-
53 // select the right chunk from the big table-
54 short chunk = 0;-
55 uint chunkIndex = tldIndices[index], offset = 0;-
56 while (chunk < tldChunkCount && tldIndices[index] >= tldChunks[chunk]) {
chunk < tldChunkCountDescription
TRUEevaluated 899 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
FALSEnever evaluated
tldIndices[ind...dChunks[chunk]Description
TRUEevaluated 135 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
FALSEevaluated 764 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
0-899
57 chunkIndex -= tldChunks[chunk];-
58 offset += tldChunks[chunk];-
59 chunk++;-
60 }
executed 135 times by 3 tests: end of block
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
135
61-
62 // check all the entries from the given index-
63 while (chunkIndex < tldIndices[index+1] - offset) {
chunkIndex < t...ex+1] - offsetDescription
TRUEevaluated 640 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
FALSEevaluated 656 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
640-656
64 QString currentEntry = QString::fromUtf8(tldData[chunk] + chunkIndex);-
65 if (currentEntry == entry)
currentEntry == entryDescription
TRUEevaluated 108 times by 2 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QUrl
FALSEevaluated 532 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
108-532
66 return true;
executed 108 times by 2 tests: return true;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QUrl
108
67 chunkIndex += qstrlen(tldData[chunk] + chunkIndex) + 1; // +1 for the ending \0-
68 }
executed 532 times by 3 tests: end of block
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
532
69 return false;
executed 656 times by 3 tests: return false;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
656
70}-
71-
72static inline bool containsTLDEntry(const QString &entry)-
73{-
74 return containsTLDEntry(QStringRef(&entry));
executed 336 times by 3 tests: return containsTLDEntry(QStringRef(&entry));
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
336
75}-
76-
77/*!-
78 \internal-
79-
80 Return the top-level-domain per Qt's copy of the Mozilla public suffix list of-
81 \a domain.-
82*/-
83-
84Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain)-
85{-
86 const QString domainLower = domain.toLower();-
87 QVector<QStringRef> sections = domainLower.splitRef(QLatin1Char('.'), QString::SkipEmptyParts);-
88 if (sections.isEmpty())
sections.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 36 times by 1 test
Evaluated by:
  • tst_QUrl
0-36
89 return QString();
never executed: return QString();
0
90-
91 QString level, tld;-
92 for (int j = sections.count() - 1; j >= 0; --j) {
j >= 0Description
TRUEevaluated 136 times by 1 test
Evaluated by:
  • tst_QUrl
FALSEevaluated 36 times by 1 test
Evaluated by:
  • tst_QUrl
36-136
93 level.prepend(QLatin1Char('.') + sections.at(j));-
94 if (qIsEffectiveTLD(level.rightRef(level.size() - 1)))
qIsEffectiveTL...l.size() - 1))Description
TRUEevaluated 74 times by 1 test
Evaluated by:
  • tst_QUrl
FALSEevaluated 62 times by 1 test
Evaluated by:
  • tst_QUrl
62-74
95 tld = level;
executed 74 times by 1 test: tld = level;
Executed by:
  • tst_QUrl
74
96 }
executed 136 times by 1 test: end of block
Executed by:
  • tst_QUrl
136
97 return tld;
executed 36 times by 1 test: return tld;
Executed by:
  • tst_QUrl
36
98}-
99-
100/*!-
101 \internal-
102-
103 Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.-
104*/-
105-
106Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain)-
107{-
108 // for domain 'foo.bar.com':-
109 // 1. return if TLD table contains 'foo.bar.com'-
110 if (containsTLDEntry(domain))
containsTLDEntry(domain)Description
TRUEevaluated 98 times by 2 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QUrl
FALSEevaluated 330 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
98-330
111 return true;
executed 98 times by 2 tests: return true;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QUrl
98
112-
113 const int dot = domain.indexOf(QLatin1Char('.'));-
114 if (dot >= 0) {
dot >= 0Description
TRUEevaluated 327 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkCookieJar
3-327
115 int count = domain.size() - dot;-
116 QString wildCardDomain = QLatin1Char('*') + domain.right(count);-
117 // 2. if table contains '*.bar.com',-
118 // test if table contains '!foo.bar.com'-
119 if (containsTLDEntry(wildCardDomain)) {
containsTLDEnt...ildCardDomain)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QNetworkCookieJar
FALSEevaluated 318 times by 3 tests
Evaluated by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
9-318
120 QString exceptionDomain = QLatin1Char('!') + domain;-
121 return (! containsTLDEntry(exceptionDomain));
executed 9 times by 1 test: return (! containsTLDEntry(exceptionDomain));
Executed by:
  • tst_QNetworkCookieJar
9
122 }-
123 }
executed 318 times by 3 tests: end of block
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
318
124 return false;
executed 321 times by 3 tests: return false;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
321
125}-
126-
127QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9