summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes/qmimemagicrule.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QMime: remove unused qmap.h includesMarc Mutz2024-02-211-1/+0
| | | | | | | | | | | These TUs never seem to never have used QMap, QMultiMap or QVariantMap, so remove the superfluous includes. Amends ffa5820fa3bf8b28675129919d748373d6c77827. Pick-to: 6.7 6.6 6.5 Change-Id: I3381fced294d7b99d3553d0efde38f20f01e4e97 Reviewed-by: David Faure <david.faure@kdab.com>
* mimetypes/: port to qsizetypeAhmad Samir2023-04-151-5/+5
| | | | | | | | | | | | | | | Fixes compiler warnings about narrowing conversions. Found by compiling with clang and -Wshorten-64-to-32. Drive-by changes: - use range-for instead of an iterator based loop - use strlen("*.") instead of magic number 2 Pick-to: 6.5 Task-number: QTBUG-102461 Change-Id: I0bf2299049c0411ed496468238ca30b69946ffc2 Reviewed-by: David Faure <david.faure@kdab.com>
* Use QtMiscUtils hex/oct-related helpersAhmad Samir2023-02-071-6/+2
| | | | | | | Thanks to Thiago for pointing them out in review. Change-Id: I14d588a8bd5ba29d43a5daeacfd55d974eb65557 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtMiscUtils: add some more character helpersAhmad Samir2023-02-071-3/+5
| | | | | | | | | | | | | isHexDigit, isOctalDigit, isAsciiDigit, isAsciiLower, isAsciiUpper, isAsciiLetterOrNumber. This de-duplicates some code through out. Rename two local lambdas that were called "isAsciiLetterOrNumber" to not conflict with the method in QtMiscUtils. Change-Id: I5b631f95b9f109136d19515f7e20b8e2fbca3d43 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeMagicRule: use qOffsetStringArray for storing typesSona Kurazyan2022-09-061-17/+15
| | | | | | | | Each element of the array corresponds to an item in QMimeMagicRule::Type enum, so dropped the last empty string of the array which is not used. Change-Id: I4786afaa58287c26d4525180fe6fa6891ddcde26 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-3/+3
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicableSona Kurazyan2022-03-251-5/+7
| | | | | | | | | | | As a drive-by, did also minor refactorings/improvements. Task-number: QTBUG-98434 Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* Core: Do not depend on transitive includesFabian Kosmale2022-03-171-0/+1
| | | | | Change-Id: I2c71188a4d27692a2d6ef1aa447b329627214b17 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QMimeMagicRule: Fix missing check and return for "Invalid" typeEike Ziller2022-03-021-2/+5
| | | | | | | In the QMimeMagicRule constructor. Change-Id: Icdd1c4bc0e8d7cc39c8f63b416deec84b2607c96 Reviewed-by: David Faure <david.faure@kdab.com>
* Port mimetypes away from QStringRefLars Knoll2020-06-111-2/+2
| | | | | | Task-number: QTBUG-84319 Change-Id: I2bed1149df7f11495fd9dc3577828c0790b17dab Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Modernize the "mimetype" featureLiang Qi2018-10-121-4/+0
| | | | | | Change-Id: I9b67c2cbc0891a38ece18d521c86fbc7344dce7a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* Fix build for Android with android-clang in r17Liang Qi2018-06-061-10/+6
| | | | | | Task-number: QTBUG-67464 Change-Id: Ib971a5da82b31bce9ac1c9ac623ad7d5302cfaec Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* QMimeMagicRule: fix inconsequential out-of-bounds accessMarc Mutz2017-11-301-1/+1
| | | | | | | | | | The penultimate entry in mimeRuleTypes_strings is "byte", which, incl. the terminating NUL character, has length five. But 65-59 == 6, so the last index in magicRuleType_indices was off by one. No harm done, since there's one more NUL (three in total...), but fix for the next reader of the code. Change-Id: Ibdf855014a313a0486d013c9d06d55cea96435fd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeMagicRule: endianness fixesDavid Faure2016-12-271-2/+12
| | | | | | | | | | | | | | | | | * apply endianness to the mask as well * do not apply endianness to "host" entries, they were wrongly behaving exactly like "big endian" entries. The issue with the mask was detected by the audio/aac magic <match type="big16" value="0xFFF0" mask="0xFFF6" offset="0"/> which failed to identify the test file ct_faac-adts.aac since it was applying the mask 0xFFF6 instead of 0xF6FF (on a little-endian machine). Not yet detected by tst_qmimedatabase which is based on shared-mime-info 1.0, will be covered by the upgrade to 1.8 in dev. Change-Id: I4fb7af2d367099817e712b14f2a031066d0ac432 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeMagicRule: fix off by one in the number of bytes checkedDavid Faure2016-12-271-1/+1
| | | | | | | | | | | | | | | | | | | | | Since the loop says p <= e, no +1 should be added to e. Testcase: The magic for application/x-gameboy-rom says <match type="byte" value="0x0" mask="0x80" offset="323"/> and this code was checking both byte 323 and byte 324, finding a match at pos 324, returning application/x-gameboy-rom erroneously. Given the magic for application/x-gameboy-color-rom: <match type="byte" value="0x80" mask="0x80" offset="323"/> the expected result for game-boy-color-test.gbc is application/x-gameboy-color-rom Not yet detected by tst_qmimedatabase which is based on shared-mime-info 1.0, will be covered by the upgrade to 1.8. Change-Id: I2396cb1ccfb26db5a24d5551fef493cc0b98a247 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use void instead of uchar in the endian-swapping function parametersv5.7.0-rc1Thiago Macieira2016-05-261-1/+1
| | | | | | | | | This allows us to pass pointers to storage that is not an array of uchar, which it hardly ever is. Change-Id: Ifea6e497f11a461db432ffff14490d2c2df21906 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Merge remote-tracking branch 'origin/5.6.1' into 5.7.0Liang Qi2016-05-261-2/+1
|\ | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qsimd_p.h src/network/socket/qnativesocketengine_winrt.cpp Change-Id: I2765b671664c2a84839b2f88ba724fdf0c1fa7c6
| * Replace qUnaligned{Load,Store} with the existing q{To,From}Unalignedv5.6.1-1v5.6.1Thiago Macieira2016-05-251-2/+1
| | | | | | | | | | | | | | | | Move the Q_ALWAYS_INLINE and forcing of __builtin_memcpy to the existing functions. Change-Id: Icaa7fb2a490246bda156ffff143c137e520eea79 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | Merge "Merge remote-tracking branch 'origin/5.6' into 5.7" into refs/staging/5.7Liang Qi2016-03-131-1/+2
|\ \
| * | Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-03-111-1/+2
| |\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change partially reverts 1bfc7f68 about QT_HAS_BUILTIN define and undef in src/corelib/tools/qsimd_p.h. This change is also squashed with "Fall back to c++11 standard compiler flag for host builds" which is done by Peter Seiderer. Conflicts: mkspecs/features/default_post.prf src/3rdparty/sqlite/0001-Fixing-the-SQLite3-build-for-WEC2013-again.patch src/3rdparty/sqlite/sqlite3.c src/corelib/tools/qsimd_p.h src/gui/kernel/qevent.cpp src/gui/kernel/qwindowsysteminterface.cpp src/gui/kernel/qwindowsysteminterface_p.h src/plugins/bearer/blackberry/blackberry.pro src/plugins/platforms/cocoa/qcocoasystemsettings.mm src/plugins/platformthemes/gtk2/gtk2.pro src/plugins/styles/bb10style/bb10style.pro src/sql/drivers/sqlite2/qsql_sqlite2.cpp tools/configure/configureapp.cpp Task-number: QTBUG-51644 Done-with: Peter Seiderer <ps.report@gmx.net> Change-Id: I6100d6ace31b2e8d41a95f0b5d5ebf8f1fd88b44
| | * QMimeMagicRule: fix UB (misaligned load) in matchNumber<T>()Marc Mutz2016-03-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found by UBSan: qmimemagicrule.cpp:166:53: runtime error: load of misaligned address 0x00000124bcb9 for type 'const short unsigned int', which requires 2 byte alignment qmimemagicrule.cpp:166:53: runtime error: load of misaligned address 0x00000124bcb9 for type 'const unsigned int', which requires 4 byte alignment Fix by using new qUnalignedLoad<T>() instead of a load through a type-punned pointer and misaligned pointer. Change-Id: I6b876f1ce7e01369fbb25a51263d1ad04be07d52 Reviewed-by: David Faure <david.faure@kdab.com>
* | | QMimeTypeParser: plaster error paths with Q_UNLIKELYMarc Mutz2016-03-131-5/+5
|/ / | | | | | | | | | | | | | | | | | | | | | | ... when more than a return would be executed, to prompt the compiler to move it out of the way of the normal execution path. Unexpectedly costs ~200b in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: I0ebfb56af7c2262f64271a1b0ec46533e6000bc9 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
* | QMimeTypeParser: use QStringBuilder moreMarc Mutz2016-02-241-8/+5
| | | | | | | | | | | | | | | | | | | | | | Replace QString::arg() with QStringBuilder, use QStringLiteral where appropriate, and remove it where it isn't (e.g. in QStringBuilder expressions). Saves ~750b in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: I2471c849db79f477677213f9a155053248800590 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | QMimeTypeParser: use QStringRef moreMarc Mutz2016-02-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Keep the return values of QXmlStream*::value() around as QStringRefs for as long as possible. Avoids conversions to QString, among other things, for: - comparison to another string - conversion to int - conversion to UTF-8 or Latin-1 byte arrays Add a pair of Q_UNLIKELY as a drive-by. Saves ~900b in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: I17d440a11aeb8675979483f89e66d0a088ccc605 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Remove QMimeMagicRule's pimplMarc Mutz2016-02-171-140/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It didn't make the class implicitly shared, but required an additional heap allocation on construction and copy, as it used 'only' QScopedPointer. As it's private API the pimpl is also not needed for BC reasons. So inline the data members, and some trivial accessors. As a by-product of removing the copy special member functions, we gain nothrow move special member functions. Interestingly, the memory layout of a QList<QMimeMagicRule> (replacing which is the topic of a future patch) doesn't change due to this change, because the type that formerly fit QList very well now is too large. But copying the type outside QList now no longer allocates memory. Saves more than 2.5KiB in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: Ie3588cb5693227da6f1bfa196db924e075a750b3 Reviewed-by: David Faure <david.faure@kdab.com>
* | Updated license headersJani Heikkinen2016-01-151-14/+20
|/ | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* QMimeDatabase: warn instead of asserting on bad magic.David Faure2015-09-041-13/+55
| | | | | | | | | | | | | | | An invalid mime magic definition could lead to an assert. Replaced with a qWarning. Move all checking to the QMimeMagicRule constructor, and do keep invalid rules since they are need to parse child rules. Unit test added, with QTest::ignoreMessage when using the XML backend (there's no warning from update-mime-database when using the cache). Also make it easier to add more shared mime info files for tests. Task-number: QTBUG-44319 Done-with: Eike Ziller <eike.ziller@theqtcompany.com> Change-Id: Ie39a160a106b650cdcee88778fa7eff9e932a988 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.4' into 5.5Liang Qi2015-03-311-0/+2
|\ | | | | | | | | | | | | | | | | Conflicts: mkspecs/android-g++/qmake.conf qmake/generators/unix/unixmake2.cpp src/gui/image/qimage_conversions.cpp Change-Id: Ib76264b8c2d29a0228438ec02bd97d4b97545be0
| * QMimeDatabase: Fix magic rules with \tEike Ziller2015-03-101-0/+2
| | | | | | | | | | | | | | | | | | \t was not interpreted as a tab character. Task-number: QTBUG-44884 Change-Id: I3c733e227fba7e5fd5153df0ae4d0431903bb104 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com> Reviewed-by: David Faure <david.faure@kdab.com>
* | Introduce QT_NO_MIMETYPESérgio Martins2015-02-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | The mime type stuff generates one of the biggest translation units in QtCore due to the compressed 1.7MB freedesktop.org.xml resource. With QT_NO_MIMETYPE, libQt5Core.so is almost 400Kb smaller (4.8MB->4.4MB gcc 4.9 stripped release build) Change-Id: I5339090994034355724ff4deddb64720e81baeaf Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Update copyright headersJani Heikkinen2015-02-111-7/+7
|/ | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Fix warnings about truncations in constants.Friedemann Kleint2012-04-031-1/+1
| | | | | Change-Id: I46872c5b2866454112092c1ec5efbfe15db5af33 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Import QMimeType / QMimeDatabase into QtCore.David Faure2012-02-181-0/+387
History of the development before the import: ssh://codereview.qt-project.org/playground/mimetypes.git Mimetype definitions come from shared-mime-info where available (UNIX systems), loaded using a mmap'ed binary cache generated by update-mime-database. As a fallback if no cache is found, we parse the raw XML files otherwise. This makes the MIME type support fast and with very low memory usage on UNIX, and it makes it easy to use on Windows (no dependency on shared-mime-info, Qt even includes a freedesktop.xml file to use if none are found on the system). Change-Id: I27b05008216ff936dc463bd80d3893422bfb940e Reviewed-by: Richard J. Moore <rich@kde.org>