| 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) 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 | - | |||||||||||||
| 41 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | static 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]) {
| 0-899 | ||||||||||||
| 51 | chunkIndex -= tldChunks[chunk]; | - | ||||||||||||
| 52 | offset += tldChunks[chunk]; | - | ||||||||||||
| 53 | chunk++; | - | ||||||||||||
| 54 | } executed 135 times by 3 tests: end of blockExecuted by:
| 135 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | // check all the entries from the given index | - | ||||||||||||
| 57 | while (chunkIndex < tldIndices[index+1] - offset) {
| 640-656 | ||||||||||||
| 58 | QString currentEntry = QString::fromUtf8(tldData[chunk] + chunkIndex); | - | ||||||||||||
| 59 | if (currentEntry == entry)
| 108-532 | ||||||||||||
| 60 | return true; executed 108 times by 2 tests: return true;Executed by:
| 108 | ||||||||||||
| 61 | chunkIndex += qstrlen(tldData[chunk] + chunkIndex) + 1; // +1 for the ending \0 | - | ||||||||||||
| 62 | } executed 532 times by 3 tests: end of blockExecuted by:
| 532 | ||||||||||||
| 63 | return false; executed 656 times by 3 tests: return false;Executed by:
| 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 | - | |||||||||||||
| 73 | Q_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())
| 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) {
| 36-136 | ||||||||||||
| 82 | level.prepend(QLatin1Char('.') + sections.at(j)); | - | ||||||||||||
| 83 | if (qIsEffectiveTLD(level.right(level.size() - 1)))
| 62-74 | ||||||||||||
| 84 | tld = level; executed 74 times by 1 test: tld = level;Executed by:
| 74 | ||||||||||||
| 85 | } executed 136 times by 1 test: end of blockExecuted by:
| 136 | ||||||||||||
| 86 | return tld; executed 36 times by 1 test: return tld;Executed by:
| 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 | - | |||||||||||||
| 95 | Q_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))
| 98-330 | ||||||||||||
| 100 | return true; executed 98 times by 2 tests: return true;Executed by:
| 98 | ||||||||||||
| 101 | - | |||||||||||||
| 102 | const int dot = domain.indexOf(QLatin1Char('.')); | - | ||||||||||||
| 103 | if (dot >= 0) {
| 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)) {
| 9-318 | ||||||||||||
| 109 | QString exceptionDomain = QLatin1Char('!') + domain; | - | ||||||||||||
| 110 | return (! containsTLDEntry(exceptionDomain)); executed 9 times by 1 test: return (! containsTLDEntry(exceptionDomain));Executed by:
| 9 | ||||||||||||
| 111 | } | - | ||||||||||||
| 112 | } executed 318 times by 3 tests: end of blockExecuted by:
| 318 | ||||||||||||
| 113 | return false; executed 321 times by 3 tests: return false;Executed by:
| 321 | ||||||||||||
| 114 | } | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |