Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qplatformdefs.h" | - |
43 | #include "qurl.h" | - |
44 | #include "private/qurltlds_p.h" | - |
45 | #include "private/qtldurl_p.h" | - |
46 | #include "QtCore/qstringlist.h" | - |
47 | #include "QtCore/qhash.h" | - |
48 | | - |
49 | QT_BEGIN_NAMESPACE | - |
50 | | - |
51 | static bool containsTLDEntry(const QString &entry) | - |
52 | { | - |
53 | int index = qt_hash(entry) % tldCount; executed (the execution status of this line is deduced): int index = qt_hash(entry) % tldCount; | - |
54 | int currentDomainIndex = tldIndices[index]; executed (the execution status of this line is deduced): int currentDomainIndex = tldIndices[index]; | - |
55 | while (currentDomainIndex < tldIndices[index+1]) { evaluated: currentDomainIndex < tldIndices[index+1] yes Evaluation Count:563 | yes Evaluation Count:510 |
| 510-563 |
56 | QString currentEntry = QString::fromUtf8(tldData + currentDomainIndex); executed (the execution status of this line is deduced): QString currentEntry = QString::fromUtf8(tldData + currentDomainIndex); | - |
57 | if (currentEntry == entry) evaluated: currentEntry == entry yes Evaluation Count:24 | yes Evaluation Count:539 |
| 24-539 |
58 | return true; executed: return true; Execution Count:24 | 24 |
59 | currentDomainIndex += qstrlen(tldData + currentDomainIndex) + 1; // +1 for the ending \0 executed (the execution status of this line is deduced): currentDomainIndex += qstrlen(tldData + currentDomainIndex) + 1; | - |
60 | } executed: } Execution Count:539 | 539 |
61 | return false; executed: return false; Execution Count:510 | 510 |
62 | } | - |
63 | | - |
64 | /*! | - |
65 | \internal | - |
66 | | - |
67 | Return the top-level-domain per Qt's copy of the Mozilla public suffix list of | - |
68 | \a domain. | - |
69 | */ | - |
70 | | - |
71 | Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain) | - |
72 | { | - |
73 | QStringList sections = domain.toLower().split(QLatin1Char('.'), QString::SkipEmptyParts); executed (the execution status of this line is deduced): QStringList sections = domain.toLower().split(QLatin1Char('.'), QString::SkipEmptyParts); | - |
74 | if (sections.isEmpty()) partially evaluated: sections.isEmpty() no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
75 | return QString(); never executed: return QString(); | 0 |
76 | | - |
77 | QString level, tld; executed (the execution status of this line is deduced): QString level, tld; | - |
78 | for (int j = sections.count() - 1; j >= 0; --j) { evaluated: j >= 0 yes Evaluation Count:34 | yes Evaluation Count:9 |
| 9-34 |
79 | level.prepend(QLatin1Char('.') + sections.at(j)); executed (the execution status of this line is deduced): level.prepend(QLatin1Char('.') + sections.at(j)); | - |
80 | if (qIsEffectiveTLD(level.right(level.size() - 1))) evaluated: qIsEffectiveTLD(level.right(level.size() - 1)) yes Evaluation Count:15 | yes Evaluation Count:19 |
| 15-19 |
81 | tld = level; executed: tld = level; Execution Count:15 | 15 |
82 | } executed: } Execution Count:34 | 34 |
83 | return tld; executed: return tld; Execution Count:9 | 9 |
84 | } | - |
85 | | - |
86 | /*! | - |
87 | \internal | - |
88 | | - |
89 | Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list. | - |
90 | */ | - |
91 | | - |
92 | Q_CORE_EXPORT bool qIsEffectiveTLD(const QString &domain) | - |
93 | { | - |
94 | // for domain 'foo.bar.com': | - |
95 | // 1. return if TLD table contains 'foo.bar.com' | - |
96 | if (containsTLDEntry(domain)) evaluated: containsTLDEntry(domain) yes Evaluation Count:16 | yes Evaluation Count:256 |
| 16-256 |
97 | return true; executed: return true; Execution Count:16 | 16 |
98 | | - |
99 | if (domain.contains(QLatin1Char('.'))) { evaluated: domain.contains(QLatin1Char('.')) yes Evaluation Count:255 | yes Evaluation Count:1 |
| 1-255 |
100 | int count = domain.size() - domain.indexOf(QLatin1Char('.')); executed (the execution status of this line is deduced): int count = domain.size() - domain.indexOf(QLatin1Char('.')); | - |
101 | QString wildCardDomain; executed (the execution status of this line is deduced): QString wildCardDomain; | - |
102 | wildCardDomain.reserve(count + 1); executed (the execution status of this line is deduced): wildCardDomain.reserve(count + 1); | - |
103 | wildCardDomain.append(QLatin1Char('*')); executed (the execution status of this line is deduced): wildCardDomain.append(QLatin1Char('*')); | - |
104 | wildCardDomain.append(domain.right(count)); executed (the execution status of this line is deduced): wildCardDomain.append(domain.right(count)); | - |
105 | // 2. if table contains '*.bar.com', | - |
106 | // test if table contains '!foo.bar.com' | - |
107 | if (containsTLDEntry(wildCardDomain)) { evaluated: containsTLDEntry(wildCardDomain) yes Evaluation Count:7 | yes Evaluation Count:248 |
| 7-248 |
108 | QString exceptionDomain; executed (the execution status of this line is deduced): QString exceptionDomain; | - |
109 | exceptionDomain.reserve(domain.size() + 1); executed (the execution status of this line is deduced): exceptionDomain.reserve(domain.size() + 1); | - |
110 | exceptionDomain.append(QLatin1Char('!')); executed (the execution status of this line is deduced): exceptionDomain.append(QLatin1Char('!')); | - |
111 | exceptionDomain.append(domain); executed (the execution status of this line is deduced): exceptionDomain.append(domain); | - |
112 | return (! containsTLDEntry(exceptionDomain)); executed: return (! containsTLDEntry(exceptionDomain)); Execution Count:7 | 7 |
113 | } | - |
114 | } executed: } Execution Count:248 | 248 |
115 | return false; executed: return false; Execution Count:249 | 249 |
116 | } | - |
117 | | - |
118 | QT_END_NAMESPACE | - |
119 | | - |
| | |