| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimemagicrule.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 | - | |||||||||||||
| 41 | #define QT_NO_CAST_FROM_ASCII | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | #include "qmimemagicrule_p.h" | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | #ifndef QT_NO_MIMETYPE | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | #include "qmimetypeparser_p.h" | - | ||||||||||||
| 48 | #include <QtCore/QList> | - | ||||||||||||
| 49 | #include <QtCore/QDebug> | - | ||||||||||||
| 50 | #include <qendian.h> | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | // in the same order as Type! | - | ||||||||||||
| 55 | static const char magicRuleTypes_string[] = | - | ||||||||||||
| 56 | "invalid\0" | - | ||||||||||||
| 57 | "string\0" | - | ||||||||||||
| 58 | "host16\0" | - | ||||||||||||
| 59 | "host32\0" | - | ||||||||||||
| 60 | "big16\0" | - | ||||||||||||
| 61 | "big32\0" | - | ||||||||||||
| 62 | "little16\0" | - | ||||||||||||
| 63 | "little32\0" | - | ||||||||||||
| 64 | "byte\0" | - | ||||||||||||
| 65 | "\0"; | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | static const int magicRuleTypes_indices[] = { | - | ||||||||||||
| 68 | 0, 8, 15, 22, 29, 35, 41, 50, 59, 65, 0 | - | ||||||||||||
| 69 | }; | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName) | - | ||||||||||||
| 72 | { | - | ||||||||||||
| 73 | for (int i = String; i <= Byte; ++i) { | - | ||||||||||||
| 74 | if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i]) | - | ||||||||||||
| 75 | return Type(i); | - | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | return Invalid; | - | ||||||||||||
| 78 | } | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType) | - | ||||||||||||
| 81 | { | - | ||||||||||||
| 82 | return magicRuleTypes_string + magicRuleTypes_indices[theType]; | - | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | - | |||||||||||||
| class QMimeMagicRulePrivate | ||||||||||||||
| { | ||||||||||||||
| public:bool operator==(const QMimeMagicRulePrivate &other) const;QMimeMagicRule::Type type; | ||||||||||||||
| QByteArray value; | ||||||||||||||
| int startPos; | ||||||||||||||
| int endPos; | ||||||||||||||
| QByteArray mask; | ||||||||||||||
| QByteArray pattern; | ||||||||||||||
| quint32 number; | ||||||||||||||
| quint32 numberMask; | ||||||||||||||
| typedef bool (*MatchFunction)(const QMimeMagicRulePrivate *d, const QByteArray &data); | ||||||||||||||
| MatchFunction matchFunction; | ||||||||||||||
| }; | ||||||||||||||
| bool QMimeMagicRulePrivate::operator==(const QMimeMagicRulePrivateQMimeMagicRule &other) const | ||||||||||||||
| 86 | { | - | ||||||||||||
| 87 | return typem_type == other.typem_type && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 88 | valuem_value == other.valuem_value && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 89 | startPosm_startPos == other.startPosm_startPos && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 90 | endPosm_endPos == other.endPosm_endPos && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 91 | maskm_mask == other.maskm_mask && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 92 | patternm_pattern == other.patternm_pattern && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 93 | numberm_number == other.numberm_number && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 94 | numberMaskm_numberMask == other.numberMaskm_numberMask && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 95 | matchFunctionm_matchFunction == other.matchFunctionm_matchFunction; never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||
| 96 | } | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | // Used by both providers | - | ||||||||||||
| 99 | bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, | - | ||||||||||||
| 100 | int valueLength, const char *valueData, const char *mask) | - | ||||||||||||
| 101 | { | - | ||||||||||||
| 102 | // Size of searched data. | - | ||||||||||||
| 103 | // Example: value="ABC", rangeLength=3 -> we need 3+3-1=5 bytes (ABCxx,xABCx,xxABC would match) | - | ||||||||||||
| 104 | const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart); | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | if (!mask) { | - | ||||||||||||
| 107 | // callgrind says QByteArray::indexOf is much slower, since our strings are typically too | - | ||||||||||||
| 108 | // short for be worth Boyer-Moore matching (1 to 71 bytes, 11 bytes on average). | - | ||||||||||||
| 109 | bool found = false; | - | ||||||||||||
| 110 | for (int i = rangeStart; i < rangeStart + rangeLength; ++i) { | - | ||||||||||||
| 111 | if (i + valueLength > dataSize) | - | ||||||||||||
| 112 | break; | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | if (memcmp(valueData, dataPtr + i, valueLength) == 0) { | - | ||||||||||||
| 115 | found = true; | - | ||||||||||||
| 116 | break; | - | ||||||||||||
| 117 | } | - | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | if (!found) | - | ||||||||||||
| 120 | return false; | - | ||||||||||||
| 121 | } else { | - | ||||||||||||
| 122 | bool found = false; | - | ||||||||||||
| 123 | const char *readDataBase = dataPtr + rangeStart; | - | ||||||||||||
| 124 | // Example (continued from above): | - | ||||||||||||
| 125 | // deviceSize is 4, so dataNeeded was max'ed to 4. | - | ||||||||||||
| 126 | // maxStartPos = 4 - 3 + 1 = 2, and indeed | - | ||||||||||||
| 127 | // we need to check for a match a positions 0 and 1 (ABCx and xABC). | - | ||||||||||||
| 128 | const int maxStartPos = dataNeeded - valueLength + 1; | - | ||||||||||||
| 129 | for (int i = 0; i < maxStartPos; ++i) { | - | ||||||||||||
| 130 | const char *d = readDataBase + i; | - | ||||||||||||
| 131 | bool valid = true; | - | ||||||||||||
| 132 | for (int idx = 0; idx < valueLength; ++idx) { | - | ||||||||||||
| 133 | if (((*d++) & mask[idx]) != (valueData[idx] & mask[idx])) { | - | ||||||||||||
| 134 | valid = false; | - | ||||||||||||
| 135 | break; | - | ||||||||||||
| 136 | } | - | ||||||||||||
| 137 | } | - | ||||||||||||
| 138 | if (valid) | - | ||||||||||||
| 139 | found = true; | - | ||||||||||||
| 140 | } | - | ||||||||||||
| 141 | if (!found) | - | ||||||||||||
| 142 | return false; | - | ||||||||||||
| 143 | } | - | ||||||||||||
| 144 | //qDebug() << "Found" << value << "in" << searchedData; | - | ||||||||||||
| 145 | return true; | - | ||||||||||||
| 146 | } | - | ||||||||||||
| 147 | - | |||||||||||||
| staticbool QMimeMagicRule::matchString(const QMimeMagicRulePrivate *d,const QByteArray &data) const | ||||||||||||||
| 149 | { | - | ||||||||||||
| 150 | const int rangeLength = d->endPosm_endPos - d->startPosm_startPos + 1; | - | ||||||||||||
| 151 | return QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPosm_startPos, rangeLength, d->patternm_pattern.size(), d->patternm_pattern.constData(), d->maskm_mask.constData()); executed 17377 times by 1 test: return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());Executed by:
| 17377 | ||||||||||||
| 152 | } | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | template <typename T> | - | ||||||||||||
| staticbool QMimeMagicRule::matchNumber(const QMimeMagicRulePrivate *d,const QByteArray &data) const | ||||||||||||||
| 156 | { | - | ||||||||||||
| 157 | const T value(d->numberm_number); | - | ||||||||||||
| 158 | const T mask(d->numberMaskm_numberMask); | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | //qDebug() << "matchNumber" << "0x" << QString::number(m_number, 16) << "size" << sizeof(T); | - | ||||||||||||
| 161 | //qDebug() << "mask" << QString::number(m_numberMask, 16); | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | const char *p = data.constData() + d->startPosm_startPos; | - | ||||||||||||
| 164 | const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), d->endPosm_endPos + 1); | - | ||||||||||||
| 165 | for ( ; p <= e; ++p) {
| 1854-3457 | ||||||||||||
| 166 | if ((qFromUnaligned<T>(reinterpret_cast<const uchar *>(p))) & mask) == (value & mask))
| 13-3444 | ||||||||||||
| 167 | return true; executed 13 times by 1 test: return true;Executed by:
| 13 | ||||||||||||
| 168 | } executed 3444 times by 1 test: end of blockExecuted by:
| 3444 | ||||||||||||
| 169 | - | |||||||||||||
| 170 | return false; executed 1854 times by 1 test: return false;Executed by:
| 1854 | ||||||||||||
| 171 | } | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | static inline QByteArray makePattern(const QByteArray &value) | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | QByteArray pattern(value.size(), Qt::Uninitialized); | - | ||||||||||||
| 176 | char *data = pattern.data(); | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | const char *p = value.constData(); | - | ||||||||||||
| 179 | const char *e = p + value.size(); | - | ||||||||||||
| 180 | for ( ; p < e; ++p) { | - | ||||||||||||
| 181 | if (*p == '\\' && ++p < e) { | - | ||||||||||||
| 182 | if (*p == 'x') { // hex (\\xff) | - | ||||||||||||
| 183 | char c = 0; | - | ||||||||||||
| 184 | for (int i = 0; i < 2 && p + 1 < e; ++i) { | - | ||||||||||||
| 185 | ++p; | - | ||||||||||||
| 186 | if (*p >= '0' && *p <= '9') | - | ||||||||||||
| 187 | c = (c << 4) + *p - '0'; | - | ||||||||||||
| 188 | else if (*p >= 'a' && *p <= 'f') | - | ||||||||||||
| 189 | c = (c << 4) + *p - 'a' + 10; | - | ||||||||||||
| 190 | else if (*p >= 'A' && *p <= 'F') | - | ||||||||||||
| 191 | c = (c << 4) + *p - 'A' + 10; | - | ||||||||||||
| 192 | else | - | ||||||||||||
| 193 | continue; | - | ||||||||||||
| 194 | } | - | ||||||||||||
| 195 | *data++ = c; | - | ||||||||||||
| 196 | } else if (*p >= '0' && *p <= '7') { // oct (\\7, or \\77, or \\377) | - | ||||||||||||
| 197 | char c = *p - '0'; | - | ||||||||||||
| 198 | if (p + 1 < e && p[1] >= '0' && p[1] <= '7') { | - | ||||||||||||
| 199 | c = (c << 3) + *(++p) - '0'; | - | ||||||||||||
| 200 | if (p + 1 < e && p[1] >= '0' && p[1] <= '7' && p[-1] <= '3') | - | ||||||||||||
| 201 | c = (c << 3) + *(++p) - '0'; | - | ||||||||||||
| 202 | } | - | ||||||||||||
| 203 | *data++ = c; | - | ||||||||||||
| 204 | } else if (*p == 'n') { | - | ||||||||||||
| 205 | *data++ = '\n'; | - | ||||||||||||
| 206 | } else if (*p == 'r') { | - | ||||||||||||
| 207 | *data++ = '\r'; | - | ||||||||||||
| 208 | } else if (*p == 't') { | - | ||||||||||||
| 209 | *data++ = '\t'; | - | ||||||||||||
| 210 | } else { // escaped | - | ||||||||||||
| 211 | *data++ = *p; | - | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | } else { | - | ||||||||||||
| 214 | *data++ = *p; | - | ||||||||||||
| 215 | } | - | ||||||||||||
| 216 | } | - | ||||||||||||
| 217 | pattern.truncate(data - pattern.data()); | - | ||||||||||||
| 218 | - | |||||||||||||
| 219 | return pattern; | - | ||||||||||||
| 220 | } | - | ||||||||||||
| 221 | - | |||||||||||||
| 222 | // Evaluate a magic match rule like | - | ||||||||||||
| 223 | // <match value="must be converted with BinHex" type="string" offset="11"/> | - | ||||||||||||
| 224 | // <match value="0x9501" type="big16" offset="0:64"/> | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | QMimeMagicRule::QMimeMagicRule(const QString &typeStr&type, | - | ||||||||||||
| 227 | const QByteArray &theValue&value, | - | ||||||||||||
| 228 | const QString &offsets, | - | ||||||||||||
| 229 | const QByteArray &theMask&mask, | - | ||||||||||||
| 230 | QString *errorString) | - | ||||||||||||
| 231 | : dm_type(new QMimeMagicRulePrivate) | - | ||||||||||||
| { | ||||||||||||||
| d->value = theValue; | ||||||||||||||
| d->mask = theMask; | ||||||||||||||
| d->matchFunction = 0; | ||||||||||||||
| d->type =QMimeMagicRule::type(typeStrtype.toLatin1());())), | ||||||||||||||
| 232 | m_value(value), | - | ||||||||||||
| 233 | m_mask(mask), | - | ||||||||||||
| 234 | m_matchFunction(nullptr) | - | ||||||||||||
| 235 | { | - | ||||||||||||
| 236 | if (d->typeQ_UNLIKELY(m_type == Invalid) {))
| 0-4058 | ||||||||||||
| 237 | *errorString = QStringLiteralQLatin1String("Type %s") + type + QLatin1String(" is not supported").arg(typeStr); never executed: *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported"); | 0 | ||||||||||||
| 238 | - | |||||||||||||
| 239 | }// Parse for offset as "1" or "1:10" | - | ||||||||||||
| 240 | const int colonIndex = offsets.indexOf(QLatin1Char(':')); | - | ||||||||||||
| 241 | const QStringQStringRef startPosStr = colonIndex == -1 ? offsets :offsets.midmidRef(0, colonIndex); // \ These decay to returning 'offsets' | - | ||||||||||||
| 242 | const QStringQStringRef endPosStr = colonIndex == -1 ? offsets :offsets.midmidRef(colonIndex + 1);// / unchanged when colonIndex == -1 | - | ||||||||||||
| 243 | if (Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(startPosStr, &d->startPos&m_startPos, errorString))) ||
| 0-4058 | ||||||||||||
| 244 | !Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(endPosStr, &d->endPos&m_endPos, errorString))))) {
| 0-4058 | ||||||||||||
| 245 | d->typem_type = Invalid; | - | ||||||||||||
| 246 | return; never executed: return; | 0 | ||||||||||||
| 247 | } | - | ||||||||||||
| 248 | - | |||||||||||||
| 249 | if (d->valueQ_UNLIKELY(m_value.isEmpty())())) {
| 0-4058 | ||||||||||||
| 250 | d->typem_type = Invalid; | - | ||||||||||||
| 251 | if (errorString)
| 0 | ||||||||||||
| 252 | *errorString = QLatin1StringQStringLiteral("Invalid empty magic rule value"); never executed: *errorString = ([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||
| 253 | return; never executed: return; | 0 | ||||||||||||
| 254 | } | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | if (d->typem_type >= Host16 && d->typem_type <= Byte) {
| 0-3431 | ||||||||||||
| 257 | bool ok; | - | ||||||||||||
| 258 | d->numberm_number = d->valuem_value.toUInt(&ok, 0); // autodetect base | - | ||||||||||||
| 259 | if (Q_UNLIKELY(!ok))) {
| 2-625 | ||||||||||||
| 260 | d->typem_type = Invalid; | - | ||||||||||||
| 261 | if (errorString)
| 0-2 | ||||||||||||
| 262 | *errorString = QString::fromLatin1QLatin1String("Invalid magic rule value \"%1\"").arg\"") + QLatin1String(QString::fromLatin1m_value) + QLatin1Char(d->value));'"'); executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');Executed by:
| 2 | ||||||||||||
| 263 | executed 2 times by 1 test: return;return;Executed by:
executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||
| 264 | }d->numberMask | - | ||||||||||||
| 265 | m_numberMask
| 50-575 | ||||||||||||
| 266 | executed 625 times by 1 test: }end of blockExecuted by:
executed 625 times by 1 test: end of blockExecuted by:
| 625 | ||||||||||||
| 267 | - | |||||||||||||
| 268 | switch (d->typem_type) { | - | ||||||||||||
| 269 | executed 3431 times by 1 test: case String:d->patterncase String:Executed by:
executed 3431 times by 1 test: case String:Executed by:
| 3431 | ||||||||||||
| 270 | m_pattern = makePattern(d->valuem_value);d->pattern | - | ||||||||||||
| 271 | m_pattern.squeeze(); | - | ||||||||||||
| 272 |
| 29-3402 | ||||||||||||
| 273 |
| 2-27 | ||||||||||||
| 274 | m_type = Invalid; | - | ||||||||||||
| 275 |
| 0-2 | ||||||||||||
| 276 | executed 2 times by 1 test: *errorString =QString::fromLatin1 QLatin1String("Invalid magic rule mask \"") \"%1\"").arg+ QLatin1String(QString::fromLatin1m_mask) + QLatin1Char(d->mask));'"');*errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
| 2 | ||||||||||||
| 277 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||
| 278 | } | - | ||||||||||||
| 279 | const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( | - | ||||||||||||
| 280 | d->maskm_mask.constData() + 2, d->maskm_mask.size() - 2)); | - | ||||||||||||
| 281 | if (Q_UNLIKELY(tempMask.size() != d->patternm_pattern.size())())) {
| 2-25 | ||||||||||||
| 282 | d->typem_type = Invalid; | - | ||||||||||||
| 283 | if (errorString)
| 0-2 | ||||||||||||
| 284 | *errorString = QString::fromLatin1QLatin1String("Invalid magic rule mask size \"%1\"").arg\"") + QLatin1String(QString::fromLatin1m_mask) + QLatin1Char(d->mask));'"'); executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
| 2 | ||||||||||||
| 285 | executed 2 times by 1 test: return;return;Executed by:
executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||
| 286 | }d->mask | - | ||||||||||||
| 287 | m_mask = tempMask; | - | ||||||||||||
| 288 | executed 25 times by 1 test: } else {d->maskend of blockExecuted by:
executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||
| 289 | m_mask.fill(char(-1),d->pattern m_pattern.size()); | - | ||||||||||||
| 290 | executed 3402 times by 1 test: }d->maskend of blockExecuted by:
executed 3402 times by 1 test: end of blockExecuted by:
| 3402 | ||||||||||||
| 291 | m_mask.squeeze();d->matchFunction | - | ||||||||||||
| 292 | m_matchFunction = &QMimeMagicRule::matchString; | - | ||||||||||||
| 293 | executed 3427 times by 1 test: break;break;Executed by:
executed 3427 times by 1 test: break;Executed by:
| 3427 | ||||||||||||
| 294 | executed 205 times by 1 test: case Byte:case Byte:Executed by:
executed 205 times by 1 test: case Byte:Executed by:
| 205 | ||||||||||||
| 295 |
| 0-205 | ||||||||||||
| 296 |
| 0-205 | ||||||||||||
| 297 | m_numberMask executed 205 times by 1 test: = quint8(-1);d->matchFunctionm_numberMask = quint8(-1);Executed by:
executed 205 times by 1 test: m_numberMask = quint8(-1);Executed by:
| 205 | ||||||||||||
| 298 | m_matchFunction = &QMimeMagicRule::matchNumber<quint8>; | - | ||||||||||||
| 299 | executed 205 times by 1 test: }end of blockExecuted by:
executed 205 times by 1 test: end of blockExecuted by:
| 205 | ||||||||||||
| 300 | executed 205 times by 1 test: break;break;Executed by:
executed 205 times by 1 test: break;Executed by:
| 205 | ||||||||||||
| 301 | executed 65 times by 1 test: case Big16:case Big16:Executed by:
executed 65 times by 1 test: case Big16:Executed by:
| 65 | ||||||||||||
| 302 | executed 20 times by 1 test: case Host16:case Host16:Executed by:
executed 20 times by 1 test: case Host16:Executed by:
| 20 | ||||||||||||
| 303 | executed 85 times by 1 test: case Little16:case Little16:Executed by:
executed 85 times by 1 test: case Little16:Executed by:
| 85 | ||||||||||||
| 304 |
| 0-170 | ||||||||||||
| 305 | m_number
| 85 | ||||||||||||
| 306 |
| 5-165 | ||||||||||||
| 307 | m_numberMask executed 165 times by 1 test: = quint16(-1);d->matchFunctionm_numberMask = quint16(-1);Executed by:
executed 165 times by 1 test: m_numberMask = quint16(-1);Executed by:
| 165 | ||||||||||||
| 308 | m_matchFunction = &QMimeMagicRule::matchNumber<quint16>; | - | ||||||||||||
| 309 | executed 170 times by 1 test: }end of blockExecuted by:
executed 170 times by 1 test: end of blockExecuted by:
| 170 | ||||||||||||
| 310 | executed 170 times by 1 test: break;break;Executed by:
executed 170 times by 1 test: break;Executed by:
| 170 | ||||||||||||
| 311 | executed 95 times by 1 test: case Big32:case Big32:Executed by:
executed 95 times by 1 test: case Big32:Executed by:
| 95 | ||||||||||||
| 312 | executed 20 times by 1 test: case Host32:case Host32:Executed by:
executed 20 times by 1 test: case Host32:Executed by:
| 20 | ||||||||||||
| 313 | executed 135 times by 1 test: case Little32:case Little32:Executed by:
executed 135 times by 1 test: case Little32:Executed by:
| 135 | ||||||||||||
| 314 |
| 0-250 | ||||||||||||
| 315 | m_number
| 115-135 | ||||||||||||
| 316 |
| 45-205 | ||||||||||||
| 317 | m_numberMask executed 205 times by 1 test: = quint32(-1);d->matchFunctionm_numberMask = quint32(-1);Executed by:
executed 205 times by 1 test: m_numberMask = quint32(-1);Executed by:
| 205 | ||||||||||||
| 318 | m_matchFunction = &QMimeMagicRule::matchNumber<quint32>; | - | ||||||||||||
| 319 | executed 250 times by 1 test: }end of blockExecuted by:
executed 250 times by 1 test: end of blockExecuted by:
| 250 | ||||||||||||
| 320 | executed 250 times by 1 test: break;break;Executed by:
executed 250 times by 1 test: break;Executed by:
| 250 | ||||||||||||
| 321 | never executed: default:default:never executed: default: | 0 | ||||||||||||
| 322 | never executed: break;break;never executed: break; | 0 | ||||||||||||
| } never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| QMimeMagicRule::QMimeMagicRule(const QMimeMagicRule &other) : never executed: break; | ||||||||||||||
| d(new QMimeMagicRulePrivate(*other.d)) never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| QMimeMagicRule::~QMimeMagicRule() never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| QMimeMagicRule &QMimeMagicRule::operator=(const QMimeMagicRule &other) never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| *d = *other.d; never executed: break; | ||||||||||||||
| return *this; never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| return d == other.d || never executed: break; | ||||||||||||||
| *d == *other.d; never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| QMimeMagicRule::Type QMimeMagicRule::type() const never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| return d->type; never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| QByteArray QMimeMagicRule::value() const never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| return d->value; never executed: break; | ||||||||||||||
| } never executed: break; | ||||||||||||||
| int QMimeMagicRule::startPos() const never executed: break; | ||||||||||||||
| { never executed: break; | ||||||||||||||
| return d->startPos never executed: ;break;never executed: break; | ||||||||||||||
| 323 | }int QMimeMagicRule::endPos() const | - | ||||||||||||
| { | ||||||||||||||
| return d->endPos; | ||||||||||||||
| 324 | } | - | ||||||||||||
| 325 | - | |||||||||||||
| 326 | QByteArray QMimeMagicRule::mask() const | - | ||||||||||||
| 327 | { | - | ||||||||||||
| 328 | QByteArray result =d->mask m_mask; | - | ||||||||||||
| 329 |
| 0 | ||||||||||||
| 330 | // restore '0x' | - | ||||||||||||
| 331 | result= = "0x" + result.toHex(); | - | ||||||||||||
| 332 | never executed: }end of blocknever executed: end of block | 0 | ||||||||||||
| 333 | never executed: return result;return result;never executed: return result; | 0 | ||||||||||||
| } never executed: return result; | ||||||||||||||
| bool QMimeMagicRule::isValid() const never executed: return result; | ||||||||||||||
| { never executed: return result; | ||||||||||||||
| return d->matchFunction never executed: ;return result;never executed: return result; | ||||||||||||||
| 334 | } | - | ||||||||||||
| 335 | - | |||||||||||||
| 336 | bool QMimeMagicRule::matches(const QByteArray &data) const | - | ||||||||||||
| 337 | { | - | ||||||||||||
| 338 |
| 59-19185 | ||||||||||||
| 339 |
| 59-19185 | ||||||||||||
| 340 | executed 19185 times by 1 test: return false;return false;Executed by:
executed 19185 times by 1 test: return false;Executed by:
| 19185 | ||||||||||||
| 341 | - | |||||||||||||
| 342 | // No submatch? Then we are done. | - | ||||||||||||
| 343 |
| 22-37 | ||||||||||||
| 344 | executed 37 times by 1 test: return true;return true;Executed by:
executed 37 times by 1 test: return true;Executed by:
| 37 | ||||||||||||
| 345 | - | |||||||||||||
| 346 | //qDebug() << "Checking" << m_subMatches.count() << "sub-rules"; | - | ||||||||||||
| 347 | // Check that one of the submatches matches too | - | ||||||||||||
| 348 | for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ; | - | ||||||||||||
| 349 |
| 18-22 | ||||||||||||
| 350 |
| 4-18 | ||||||||||||
| 351 | // One of the hierarchies matched -> mimetype recognized. | - | ||||||||||||
| 352 | executed 4 times by 1 test: return true;return true;Executed by:
executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||
| 353 | } | - | ||||||||||||
| 354 | executed 18 times by 1 test: }end of blockExecuted by:
executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 355 | executed 18 times by 1 test: return false;return false;Executed by:
executed 18 times by 1 test: return false;Executed by:
| 18 | ||||||||||||
| 356 | - | |||||||||||||
| 357 | - | |||||||||||||
| 358 | } | - | ||||||||||||
| 359 | - | |||||||||||||
| 360 | QT_END_NAMESPACE | - | ||||||||||||
| 361 | - | |||||||||||||
| 362 | #endif // QT_NO_MIMETYPE | - | ||||||||||||
| Source code | Switch to Preprocessed file |