Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qtldurl.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | - | |||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
48 | - | |||||||||||||
49 | static 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]) {
| 0-899 | ||||||||||||
57 | chunkIndex -= tldChunks[chunk]; | - | ||||||||||||
58 | offset += tldChunks[chunk]; | - | ||||||||||||
59 | chunk++; | - | ||||||||||||
60 | } executed 135 times by 3 tests: end of block Executed by:
| 135 | ||||||||||||
61 | - | |||||||||||||
62 | // check all the entries from the given index | - | ||||||||||||
63 | while (chunkIndex < tldIndices[index+1] - offset) {
| 640-656 | ||||||||||||
64 | QString currentEntry = QString::fromUtf8(tldData[chunk] + chunkIndex); | - | ||||||||||||
65 | if (currentEntry == entry)
| 108-532 | ||||||||||||
66 | return true; executed 108 times by 2 tests: return true; Executed by:
| 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:
| 532 | ||||||||||||
69 | return false; executed 656 times by 3 tests: return false; Executed by:
| 656 | ||||||||||||
70 | } | - | ||||||||||||
71 | - | |||||||||||||
72 | static inline bool containsTLDEntry(const QString &entry) | - | ||||||||||||
73 | { | - | ||||||||||||
74 | return containsTLDEntry(QStringRef(&entry)); executed 336 times by 3 tests: return containsTLDEntry(QStringRef(&entry)); Executed by:
| 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 | - | |||||||||||||
84 | Q_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())
| 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) {
| 36-136 | ||||||||||||
93 | level.prepend(QLatin1Char('.') + sections.at(j)); | - | ||||||||||||
94 | if (qIsEffectiveTLD(level.rightRef(level.size() - 1)))
| 62-74 | ||||||||||||
95 | tld = level; executed 74 times by 1 test: tld = level; Executed by:
| 74 | ||||||||||||
96 | } executed 136 times by 1 test: end of block Executed by:
| 136 | ||||||||||||
97 | return tld; executed 36 times by 1 test: return tld; Executed by:
| 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 | - | |||||||||||||
106 | Q_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))
| 98-330 | ||||||||||||
111 | return true; executed 98 times by 2 tests: return true; Executed by:
| 98 | ||||||||||||
112 | - | |||||||||||||
113 | const int dot = domain.indexOf(QLatin1Char('.')); | - | ||||||||||||
114 | if (dot >= 0) {
| 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)) {
| 9-318 | ||||||||||||
120 | QString exceptionDomain = QLatin1Char('!') + domain; | - | ||||||||||||
121 | return (! containsTLDEntry(exceptionDomain)); executed 9 times by 1 test: return (! containsTLDEntry(exceptionDomain)); Executed by:
| 9 | ||||||||||||
122 | } | - | ||||||||||||
123 | } executed 318 times by 3 tests: end of block Executed by:
| 318 | ||||||||||||
124 | return false; executed 321 times by 3 tests: return false; Executed by:
| 321 | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |