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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qplatformdefs.h"-
35#include "qurl.h"-
36#include "private/qurltlds_p.h"-
37#include "private/qtldurl_p.h"-
38#include "QtCore/qstring.h"-
39#include "QtCore/qvector.h"-
40-
41QT_BEGIN_NAMESPACE-
42-
43static bool containsTLDEntry(const QString &entry)-
44{-
45 int index = qt_hash(entry) % tldCount;-
46-
47 // select the right chunk from the big table-
48 short chunk = 0;-
49 uint chunkIndex = tldIndices[index], offset = 0;-
50 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
51 chunkIndex -= tldChunks[chunk];-
52 offset += tldChunks[chunk];-
53 chunk++;-
54 }
executed 135 times by 3 tests: end of block
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
135
55-
56 // check all the entries from the given index-
57 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
58 QString currentEntry = QString::fromUtf8(tldData[chunk] + chunkIndex);-
59 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
60 return true;
executed 108 times by 2 tests: return true;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QUrl
108
61 chunkIndex += qstrlen(tldData[chunk] + chunkIndex) + 1; // +1 for the ending \0-
62 }
executed 532 times by 3 tests: end of block
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
532
63 return false;
executed 656 times by 3 tests: return false;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
656
64}-
65-
66/*!-
67 \internal-
68-
69 Return the top-level-domain per Qt's copy of the Mozilla public suffix list of-
70 \a domain.-
71*/-
72-
73Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain)-
74{-
75 const QString domainLower = domain.toLower();-
76 QVector<QStringRef> sections = domainLower.splitRef(QLatin1Char('.'), QString::SkipEmptyParts);-
77 if (sections.isEmpty())
sections.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 36 times by 1 test
Evaluated by:
  • tst_QUrl
0-36
78 return QString();
never executed: return QString();
0
79-
80 QString level, tld;-
81 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
82 level.prepend(QLatin1Char('.') + sections.at(j));-
83 if (qIsEffectiveTLD(level.right(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
84 tld = level;
executed 74 times by 1 test: tld = level;
Executed by:
  • tst_QUrl
74
85 }
executed 136 times by 1 test: end of block
Executed by:
  • tst_QUrl
136
86 return tld;
executed 36 times by 1 test: return tld;
Executed by:
  • tst_QUrl
36
87}-
88-
89/*!-
90 \internal-
91-
92 Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list.-
93*/-
94-
95Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain)-
96{-
97 // for domain 'foo.bar.com':-
98 // 1. return if TLD table contains 'foo.bar.com'-
99 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
100 return true;
executed 98 times by 2 tests: return true;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QUrl
98
101-
102 const int dot = domain.indexOf(QLatin1Char('.'));-
103 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
104 int count = domain.size() - dot;-
105 QString wildCardDomain = QLatin1Char('*') + domain.rightRef(count);-
106 // 2. if table contains '*.bar.com',-
107 // test if table contains '!foo.bar.com'-
108 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
109 QString exceptionDomain = QLatin1Char('!') + domain;-
110 return (! containsTLDEntry(exceptionDomain));
executed 9 times by 1 test: return (! containsTLDEntry(exceptionDomain));
Executed by:
  • tst_QNetworkCookieJar
9
111 }-
112 }
executed 318 times by 3 tests: end of block
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
318
113 return false;
executed 321 times by 3 tests: return false;
Executed by:
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QUrl
321
114}-
115-
116QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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