aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2023-01-31 19:55:13 +0100
committerLinus Jahn <lnj@kaidan.im>2023-01-31 19:55:42 +0100
commit1a79303169e245891a911174b6f1fa87fd177597 (patch)
treefe9d1ce5bae58d8a51255370257b3c0c3f699e73
parenta97ae4c0fa96666326c29e7bacad92c8082598ae (diff)
Remove Qt < 5.15 compat code
-rw-r--r--src/base/QXmppBitsOfBinaryContentId.cpp7
-rw-r--r--src/base/QXmppHash.cpp4
-rw-r--r--src/base/QXmppPresence.cpp4
-rw-r--r--src/base/QXmppSasl.cpp22
-rw-r--r--src/base/QXmppStream.cpp15
-rw-r--r--src/base/QXmppUtils.cpp28
-rw-r--r--src/client/QXmppCallStream.cpp10
-rw-r--r--src/client/QXmppHttpFileSharingProvider.cpp9
-rw-r--r--src/client/QXmppHttpUploadManager.cpp4
-rw-r--r--src/client/QXmppOutgoingClient.cpp4
-rw-r--r--src/omemo/QXmppOmemoManager_p.cpp7
-rw-r--r--src/server/QXmppOutgoingServer.cpp4
-rw-r--r--tests/IntegrationTesting.h4
-rw-r--r--tests/qxmppbitsofbinarycontentid/tst_qxmppbitsofbinarycontentid.cpp11
14 files changed, 6 insertions, 127 deletions
diff --git a/src/base/QXmppBitsOfBinaryContentId.cpp b/src/base/QXmppBitsOfBinaryContentId.cpp
index a348b2f8..46e203a8 100644
--- a/src/base/QXmppBitsOfBinaryContentId.cpp
+++ b/src/base/QXmppBitsOfBinaryContentId.cpp
@@ -219,21 +219,16 @@ void QXmppBitsOfBinaryContentId::setAlgorithm(QCryptographicHash::Algorithm algo
///
/// Checks whether the content id is valid and can be serialized into a string.
///
-/// \note Checking the hash length requires QXmpp to be built with Qt 5.12.0 or
-/// later.
+/// Also checks the length of the hash.
///
/// \returns True, if the set hashing algorithm is supported, a hash value is
/// set and its length is correct, false otherwise.
///
bool QXmppBitsOfBinaryContentId::isValid() const
{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
return !d->hash.isEmpty() &&
HASH_ALGORITHMS.contains(d->algorithm) &&
d->hash.length() == QCryptographicHash::hashLength(d->algorithm);
-#else
- return !d->hash.isEmpty() && HASH_ALGORITHMS.contains(d->algorithm);
-#endif
}
///
diff --git a/src/base/QXmppHash.cpp b/src/base/QXmppHash.cpp
index 6d1dcb07..09b0cbc6 100644
--- a/src/base/QXmppHash.cpp
+++ b/src/base/QXmppHash.cpp
@@ -114,15 +114,11 @@ bool QXmppHash::parse(const QDomElement &el)
{
if (el.tagName() == "hash" && el.namespaceURI() == ns_hashes) {
m_algorithm = hashAlgorithmFromString(el.attribute("algo"));
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
if (auto hashResult = QByteArray::fromBase64Encoding(el.text().toUtf8())) {
m_hash = std::move(*hashResult);
} else {
return false;
}
-#else
- m_hash = QByteArray::fromBase64(el.text().toUtf8());
-#endif
return true;
}
return false;
diff --git a/src/base/QXmppPresence.cpp b/src/base/QXmppPresence.cpp
index 059bd642..dd66e30d 100644
--- a/src/base/QXmppPresence.cpp
+++ b/src/base/QXmppPresence.cpp
@@ -482,11 +482,7 @@ void QXmppPresence::parseExtension(const QDomElement &element, QXmppElementList
d->capabilityNode = element.attribute(QStringLiteral("node"));
d->capabilityVer = QByteArray::fromBase64(element.attribute(QStringLiteral("ver")).toLatin1());
d->capabilityHash = element.attribute(QStringLiteral("hash"));
-#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
d->capabilityExt = element.attribute(QStringLiteral("ext")).split(' ', Qt::SkipEmptyParts);
-#else
- d->capabilityExt = element.attribute(QStringLiteral("ext")).split(' ', QString::SkipEmptyParts);
-#endif
// XEP-0153: vCard-Based Avatars
} else if (element.namespaceURI() == ns_vcard_update) {
QDomElement photoElement = element.firstChildElement(QStringLiteral("photo"));
diff --git a/src/base/QXmppSasl.cpp b/src/base/QXmppSasl.cpp
index d8a86bb0..d566dc5c 100644
--- a/src/base/QXmppSasl.cpp
+++ b/src/base/QXmppSasl.cpp
@@ -27,26 +27,6 @@ static const QMap<QString, QCryptographicHash::Algorithm> SCRAM_ALGORITHMS = {
{ QStringLiteral("SCRAM-SHA3-512"), QCryptographicHash::RealSha3_512 },
};
-// Returns the hash length in bytes (QCH::hashLength() only exists since 5.12).
-int hashLength(QCryptographicHash::Algorithm algorithm)
-{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
- return QCryptographicHash::hashLength(algorithm);
-#else
- switch (algorithm) {
- case QCryptographicHash::Sha1:
- return 160 / 8;
- case QCryptographicHash::Sha256:
- return 256 / 8;
- case QCryptographicHash::Sha512:
- case QCryptographicHash::RealSha3_512:
- return 512 / 8;
- default:
- return QCryptographicHash::hash({}, algorithm).size();
- }
-#endif
-}
-
// Calculate digest response for use with XMPP/SASL.
static QByteArray calculateDigest(const QByteArray &method, const QByteArray &digestUri, const QByteArray &secret, const QByteArray &nonce, const QByteArray &cnonce, const QByteArray &nc)
@@ -577,7 +557,7 @@ QXmppSaslClientScram::QXmppSaslClientScram(QCryptographicHash::Algorithm algorit
: QXmppSaslClient(parent),
m_algorithm(algorithm),
m_step(0),
- m_dklen(hashLength(algorithm))
+ m_dklen(QCryptographicHash::hashLength(algorithm))
{
const auto itr = std::find(SCRAM_ALGORITHMS.cbegin(), SCRAM_ALGORITHMS.cend(), algorithm);
Q_ASSERT(itr != SCRAM_ALGORITHMS.cend());
diff --git a/src/base/QXmppStream.cpp b/src/base/QXmppStream.cpp
index 428e8e55..0ea87cbd 100644
--- a/src/base/QXmppStream.cpp
+++ b/src/base/QXmppStream.cpp
@@ -29,10 +29,6 @@
using namespace QXmpp::Private;
-#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
-static bool randomSeeded = false;
-#endif
-
struct IqState
{
QXmppPromise<QXmppStream::IqResult> interface;
@@ -83,13 +79,6 @@ QXmppStream::QXmppStream(QObject *parent)
: QXmppLoggable(parent),
d(new QXmppStreamPrivate(this))
{
-#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
- // Make sure the random number generator is seeded
- if (!randomSeeded) {
- qsrand(QTime(0, 0, 0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this));
- randomSeeded = true;
- }
-#endif
}
///
@@ -331,11 +320,7 @@ void QXmppStream::setSocket(QSslSocket *socket)
// socket events
connect(socket, &QAbstractSocket::connected, this, &QXmppStream::_q_socketConnected);
connect(socket, &QSslSocket::encrypted, this, &QXmppStream::_q_socketEncrypted);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
connect(socket, &QSslSocket::errorOccurred, this, &QXmppStream::_q_socketError);
-#else
- connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QSslSocket::error), this, &QXmppStream::_q_socketError);
-#endif
connect(socket, &QIODevice::readyRead, this, &QXmppStream::_q_socketReadyRead);
}
diff --git a/src/base/QXmppUtils.cpp b/src/base/QXmppUtils.cpp
index e0225d77..3bd57284 100644
--- a/src/base/QXmppUtils.cpp
+++ b/src/base/QXmppUtils.cpp
@@ -14,9 +14,7 @@
#include <QDateTime>
#include <QDebug>
#include <QDomElement>
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QRandomGenerator>
-#endif
#include <QRegularExpression>
#include <QString>
#include <QStringList>
@@ -254,13 +252,8 @@ int QXmppUtils::generateRandomInteger(int N)
{
Q_ASSERT(N > 0 && N <= RAND_MAX);
int val;
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
while (N <= (val = QRandomGenerator::global()->generate() / (RAND_MAX / N))) {
}
-#else
- while (N <= (val = qrand() / (RAND_MAX / N))) {
- }
-#endif
return val;
}
@@ -284,11 +277,7 @@ QByteArray QXmppUtils::generateRandomBytes(int length)
///
QString QXmppUtils::generateStanzaUuid()
{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
return QUuid::createUuid().toString(QUuid::WithoutBraces);
-#else
- return QUuid::createUuid().toString().mid(1, 36);
-#endif
}
///
@@ -351,11 +340,7 @@ void helperToXmlAddTextElement(QXmlStreamWriter *stream, const QString &name,
//
QByteArray QXmpp::Private::generateRandomBytes(uint32_t minimumByteCount, uint32_t maximumByteCount)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
const auto byteCount = QRandomGenerator::system()->bounded(minimumByteCount, maximumByteCount);
-#else
- const auto byteCount = (qrand() % (maximumByteCount - minimumByteCount)) + minimumByteCount;
-#endif
QByteArray bytes;
bytes.resize(byteCount);
generateRandomBytes(reinterpret_cast<uint8_t *>(bytes.data()), byteCount);
@@ -377,7 +362,6 @@ void QXmpp::Private::generateRandomBytes(uint8_t *bytes, uint32_t byteCount)
constexpr uint32_t intSize = sizeof(uint32_t);
auto intCount = byteCount / intSize;
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
auto *randomGenerator = QRandomGenerator::system();
// Fill the space with intCount unsigned integers.
@@ -389,18 +373,6 @@ void QXmpp::Private::generateRandomBytes(uint8_t *bytes, uint32_t byteCount)
for (size_t i = byteCount - byteCount % intSize; i < byteCount; i++) {
bytes[i] = randomGenerator->bounded(std::numeric_limits<uint8_t>::max() + 1);
}
-#else
- // Fill the range with intCount unsigned integers.
- for (size_t i = 0; i < intCount; i++) {
- reinterpret_cast<int *>(bytes)[i] = qrand();
- }
-
- // Fill the remaining space with single bytes.
- for (size_t i = byteCount - byteCount % intSize; i < byteCount; i++) {
- auto rand = qrand();
- bytes[i] = *reinterpret_cast<uint *>(&rand) % (std::numeric_limits<uint8_t>::max() + 1);
- }
-#endif
}
float QXmpp::Private::calculateProgress(qint64 transferred, qint64 total)
diff --git a/src/client/QXmppCallStream.cpp b/src/client/QXmppCallStream.cpp
index 868a1df8..042739ee 100644
--- a/src/client/QXmppCallStream.cpp
+++ b/src/client/QXmppCallStream.cpp
@@ -8,13 +8,11 @@
#include "QXmppCall_p.h"
#include "QXmppStun.h"
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
-#include <QRandomGenerator>
-#endif
-
#include <cstring>
#include <gst/gst.h>
+#include <QRandomGenerator>
+
/// \cond
QXmppCallStreamPrivate::QXmppCallStreamPrivate(QXmppCallStream *parent, GstElement *pipeline_,
GstElement *rtpbin_, QString media_, QString creator_,
@@ -34,11 +32,7 @@ QXmppCallStreamPrivate::QXmppCallStreamPrivate(QXmppCallStream *parent, GstEleme
name(std::move(name_)),
id(id_)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
localSsrc = QRandomGenerator::global()->generate();
-#else
- localSsrc = qrand();
-#endif
iceReceiveBin = gst_bin_new(QStringLiteral("receive_%1").arg(id).toLatin1().data());
iceSendBin = gst_bin_new(QStringLiteral("send_%1").arg(id).toLatin1().data());
diff --git a/src/client/QXmppHttpFileSharingProvider.cpp b/src/client/QXmppHttpFileSharingProvider.cpp
index 5b7304c5..ecd2b4fd 100644
--- a/src/client/QXmppHttpFileSharingProvider.cpp
+++ b/src/client/QXmppHttpFileSharingProvider.cpp
@@ -95,12 +95,7 @@ auto QXmppHttpFileSharingProvider::downloadFile(const std::any &source,
}
});
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QObject::connect(state->reply, &QNetworkReply::readyRead, [state, file = std::move(target)]() {
-#else
- auto file = std::shared_ptr<QIODevice>(std::move(target));
- QObject::connect(state->reply, &QNetworkReply::readyRead, [state, file]() {
-#endif
auto data = state->reply->readAll();
if (file->write(data) != data.size()) {
state->error = QXmppError::fromIoDevice(*file);
@@ -113,11 +108,7 @@ auto QXmppHttpFileSharingProvider::downloadFile(const std::any &source,
}
});
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QObject::connect(state->reply, &QNetworkReply::errorOccurred,
-#else
- QObject::connect(state->reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
-#endif
[state](QNetworkReply::NetworkError) {
// Qt doc: the finished() signal will "probably" follow
// => we can't be sure that finished() is going to be called
diff --git a/src/client/QXmppHttpUploadManager.cpp b/src/client/QXmppHttpUploadManager.cpp
index c5b3fe89..85c1ac90 100644
--- a/src/client/QXmppHttpUploadManager.cpp
+++ b/src/client/QXmppHttpUploadManager.cpp
@@ -339,11 +339,7 @@ std::shared_ptr<QXmppHttpUpload> QXmppHttpUploadManager::uploadFile(std::unique_
reply->deleteLater();
});
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
connect(reply, &QNetworkReply::errorOccurred, this,
-#else
- connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this,
-#endif
[upload, reply](QNetworkReply::NetworkError error) {
upload->d->reportError({ reply->errorString(), error });
upload->d->reportFinished();
diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp
index 20e88b9c..046bdcf2 100644
--- a/src/client/QXmppOutgoingClient.cpp
+++ b/src/client/QXmppOutgoingClient.cpp
@@ -176,11 +176,7 @@ QXmppOutgoingClient::QXmppOutgoingClient(QObject *parent)
connect(socket, &QAbstractSocket::disconnected, this, &QXmppOutgoingClient::_q_socketDisconnected);
connect(socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors), this, &QXmppOutgoingClient::socketSslErrors);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
connect(socket, &QSslSocket::errorOccurred, this, &QXmppOutgoingClient::socketError);
-#else
- connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QSslSocket::error), this, &QXmppOutgoingClient::socketError);
-#endif
// DNS lookups
connect(&d->dns, &QDnsLookup::finished, this, &QXmppOutgoingClient::_q_dnsLookupFinished);
diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp
index 485ef7b4..ca625322 100644
--- a/src/omemo/QXmppOmemoManager_p.cpp
+++ b/src/omemo/QXmppOmemoManager_p.cpp
@@ -22,10 +22,7 @@
#include <protocol.h>
#include "OmemoCryptoProvider.h"
-
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QRandomGenerator>
-#endif
#include <QStringBuilder>
using namespace QXmpp;
@@ -3411,11 +3408,7 @@ bool ManagerPrivate::buildSession(signal_protocol_address address, const QXmppOm
warning("No public pre key could be found in device bundle");
}
const auto publicPreKeyIds = publicPreKeys.keys();
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
const auto publicPreKeyIndex = QRandomGenerator::system()->bounded(publicPreKeyIds.size());
-#else
- const auto publicPreKeyIndex = qrand() % publicPreKeyIds.size();
-#endif
const auto publicPreKeyId = publicPreKeyIds.at(publicPreKeyIndex);
const auto publicPreKey = publicPreKeys.value(publicPreKeyId);
diff --git a/src/server/QXmppOutgoingServer.cpp b/src/server/QXmppOutgoingServer.cpp
index 83075ac7..e7ee9436 100644
--- a/src/server/QXmppOutgoingServer.cpp
+++ b/src/server/QXmppOutgoingServer.cpp
@@ -47,11 +47,7 @@ QXmppOutgoingServer::QXmppOutgoingServer(const QString &domain, QObject *parent)
setSocket(socket);
connect(socket, &QAbstractSocket::disconnected, this, &QXmppOutgoingServer::_q_socketDisconnected);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
connect(socket, &QSslSocket::errorOccurred, this, &QXmppOutgoingServer::socketError);
-#else
- connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QSslSocket::error), this, &QXmppOutgoingServer::socketError);
-#endif
// DNS lookups
connect(&d->dns, &QDnsLookup::finished, this, &QXmppOutgoingServer::_q_dnsLookupFinished);
diff --git a/tests/IntegrationTesting.h b/tests/IntegrationTesting.h
index 9733295e..15d45c62 100644
--- a/tests/IntegrationTesting.h
+++ b/tests/IntegrationTesting.h
@@ -27,11 +27,7 @@ class IntegrationTests
public:
static QString environmentVariable(const char *varName, const QString &defaultValue = {})
{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return qEnvironmentVariable(varName, defaultValue);
-#else
- return qEnvironmentVariableIsSet(varName) ? QString::fromLocal8Bit(qgetenv(varName)) : QString();
-#endif
}
static bool enabled()
diff --git a/tests/qxmppbitsofbinarycontentid/tst_qxmppbitsofbinarycontentid.cpp b/tests/qxmppbitsofbinarycontentid/tst_qxmppbitsofbinarycontentid.cpp
index f5aaa44c..fbe15ebc 100644
--- a/tests/qxmppbitsofbinarycontentid/tst_qxmppbitsofbinarycontentid.cpp
+++ b/tests/qxmppbitsofbinarycontentid/tst_qxmppbitsofbinarycontentid.cpp
@@ -78,10 +78,8 @@ void tst_QXmppBitsOfBinaryContentId::testFromContentId_data()
ROW("url", "cid:sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org", false);
ROW("url-and-wrong-namespace", "cid:sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob_222.xmpp.org", false);
ROW("too-many-pluses", "sha1+sha256+sha3-256+blake2b256+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org", false);
-
-#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
ROW("wrong-hash-length", "cid:sha1+08d579a50083ff9308fb6242@bob.xmpp.org", false);
-#endif
+
#undef ROW
}
@@ -136,17 +134,12 @@ void tst_QXmppBitsOfBinaryContentId::testIsValid_data()
"8f35fef110ffc5df08d579a50083ff9308fb6242",
QCryptographicHash::Sha1,
true);
-
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
ROW("valid-sha256",
"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
QCryptographicHash::Sha256,
true);
-#endif
-
-#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
ROW("wrong-hash-length", "8f35fef110ffc5df08", QCryptographicHash::Sha1, false);
-#endif
+
#undef ROW
}