From aaa64971fcf3d72d8b66ebf37b8c1005017a5ea4 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 2 Oct 2020 22:56:58 +0200 Subject: Port remaining Qt-6-removed APIs --- src/client/QXmppClientExtension.h | 1 - src/client/QXmppInvokable.cpp | 4 +++ src/client/QXmppOutgoingClient.cpp | 62 +++++++++++++++++++++++--------------- src/client/QXmppOutgoingClient.h | 3 ++ 4 files changed, 45 insertions(+), 25 deletions(-) (limited to 'src/client') diff --git a/src/client/QXmppClientExtension.h b/src/client/QXmppClientExtension.h index 8c115319..5f5c56e5 100644 --- a/src/client/QXmppClientExtension.h +++ b/src/client/QXmppClientExtension.h @@ -28,7 +28,6 @@ #include "QXmppLogger.h" class QDomElement; -class QStringList; class QXmppClient; class QXmppClientExtensionPrivate; diff --git a/src/client/QXmppInvokable.cpp b/src/client/QXmppInvokable.cpp index c3aaa4b9..ccbfb470 100644 --- a/src/client/QXmppInvokable.cpp +++ b/src/client/QXmppInvokable.cpp @@ -80,7 +80,11 @@ QVariant QXmppInvokable::dispatch(const QByteArray &method, const QList= QT_VERSION_CHECK(6, 0, 0) + QVariant returnValue(QMetaType(resultType), result); +#else QVariant returnValue(resultType, result); +#endif QMetaType::destroy(resultType, result); return returnValue; } else { diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index ed3cafb8..9f3e5e58 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include #include @@ -492,13 +492,8 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) emit connected(); } else if (ns == ns_stream && nodeRecv.tagName() == "error") { // handle redirects - QRegExp redirectRegex("([^:]+)(:[0-9]+)?"); - if (redirectRegex.exactMatch(nodeRecv.firstChildElement("see-other-host").text())) { - d->redirectHost = redirectRegex.cap(0); - if (!redirectRegex.cap(2).isEmpty()) - d->redirectPort = redirectRegex.cap(2).mid(1).toUShort(); - else - d->redirectPort = 5222; + const auto otherHost = nodeRecv.firstChildElement("see-other-host"); + if (!otherHost.isNull() && setResumeAddress(otherHost.text())) { QXmppStream::disconnectFromHost(); return; } @@ -573,11 +568,12 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) // bind result if (bind.type() == QXmppIq::Result) { if (!bind.jid().isEmpty()) { - QRegExp jidRegex("^([^@/]+)@([^@/]+)/(.+)$"); - if (jidRegex.exactMatch(bind.jid())) { - configuration().setUser(jidRegex.cap(1)); - configuration().setDomain(jidRegex.cap(2)); - configuration().setResource(jidRegex.cap(3)); + static const QRegularExpression jidRegex("^([^@/]+)@([^@/]+)/(.+)$"); + + if (const auto match = jidRegex.match(bind.jid()); match.hasMatch()) { + configuration().setUser(match.captured(1)); + configuration().setDomain(match.captured(2)); + configuration().setResource(match.captured(3)); } else { warning("Bind IQ received with invalid JID: " + bind.jid()); } @@ -683,17 +679,7 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) d->smId = streamManagementEnabled.id(); d->canResume = streamManagementEnabled.resume(); if (streamManagementEnabled.resume() && !streamManagementEnabled.location().isEmpty()) { - QRegExp locationRegex("([^:]+)(:[0-9]+)?"); - if (locationRegex.exactMatch(streamManagementEnabled.location())) { - d->resumeHost = locationRegex.cap(0); - if (!locationRegex.cap(2).isEmpty()) - d->resumePort = locationRegex.cap(2).mid(1).toUShort(); - else - d->resumePort = 5222; - } else { - d->resumeHost = QString(); - d->resumePort = 0; - } + setResumeAddress(streamManagementEnabled.location()); } enableStreamManagement(true); @@ -776,6 +762,34 @@ void QXmppOutgoingClient::pingTimeout() emit error(QXmppClient::KeepAliveError); } +bool QXmppOutgoingClient::setResumeAddress(const QString &address) +{ + if (const auto location = parseHostAddress(address); + !location.first.isEmpty()) { + d->resumeHost = location.first; + + if (location.second > 0) { + d->resumePort = location.second; + } else { + d->resumePort = 5222; + } + return true; + } + + d->resumeHost.clear(); + d->resumePort = 0; + return false; +} + +std::pair QXmppOutgoingClient::parseHostAddress(const QString &address) +{ + QUrl url("//" + address); + if (url.isValid() && !url.host().isEmpty()) { + return { url.host(), url.port() }; + } + return { {}, -1 }; +} + void QXmppOutgoingClientPrivate::sendNonSASLAuth(bool plainText) { QXmppNonSASLAuthIq authQuery; diff --git a/src/client/QXmppOutgoingClient.h b/src/client/QXmppOutgoingClient.h index abb044f3..8693c877 100644 --- a/src/client/QXmppOutgoingClient.h +++ b/src/client/QXmppOutgoingClient.h @@ -104,6 +104,9 @@ private Q_SLOTS: void pingTimeout(); private: + bool setResumeAddress(const QString &address); + static std::pair parseHostAddress(const QString &address); + friend class QXmppOutgoingClientPrivate; QXmppOutgoingClientPrivate *const d; }; -- cgit v1.2.3