aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-10-02 22:56:58 +0200
committerLNJ <lnj@kaidan.im>2020-10-10 22:33:41 +0200
commitaaa64971fcf3d72d8b66ebf37b8c1005017a5ea4 (patch)
treeb2c8f44029b8d1eee0f1382569ca7655d156d3f3 /src/client
parentf28225a6b3413b8e8decac40bfd0ee394e6dee01 (diff)
downloadqxmpp-aaa64971fcf3d72d8b66ebf37b8c1005017a5ea4.tar.gz
Port remaining Qt-6-removed APIs
Diffstat (limited to 'src/client')
-rw-r--r--src/client/QXmppClientExtension.h1
-rw-r--r--src/client/QXmppInvokable.cpp4
-rw-r--r--src/client/QXmppOutgoingClient.cpp62
-rw-r--r--src/client/QXmppOutgoingClient.h3
4 files changed, 45 insertions, 25 deletions
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<QVariant
genericArgs.value(7, QGenericArgument()),
genericArgs.value(8, QGenericArgument()),
genericArgs.value(9, QGenericArgument()))) {
+#if QT_VERSION >= 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 <QCoreApplication>
#include <QDomDocument>
#include <QHostAddress>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QStringList>
#include <QTimer>
#include <QXmlStreamWriter>
@@ -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<QString, int> 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<QString, int> parseHostAddress(const QString &address);
+
friend class QXmppOutgoingClientPrivate;
QXmppOutgoingClientPrivate *const d;
};