aboutsummaryrefslogtreecommitdiff
path: root/src/base
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/base
parentf28225a6b3413b8e8decac40bfd0ee394e6dee01 (diff)
downloadqxmpp-aaa64971fcf3d72d8b66ebf37b8c1005017a5ea4.tar.gz
Port remaining Qt-6-removed APIs
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppSasl.cpp5
-rw-r--r--src/base/QXmppStun.cpp1
-rw-r--r--src/base/QXmppUtils.cpp54
-rw-r--r--src/base/QXmppUtils.h1
4 files changed, 20 insertions, 41 deletions
diff --git a/src/base/QXmppSasl.cpp b/src/base/QXmppSasl.cpp
index b045c864..372f4d28 100644
--- a/src/base/QXmppSasl.cpp
+++ b/src/base/QXmppSasl.cpp
@@ -927,9 +927,10 @@ QByteArray QXmppSaslDigestMd5::serializeMessage(const QMap<QByteArray, QByteArra
if (quote) {
value.replace(QByteArrayLiteral("\\"), QByteArrayLiteral("\\\\"));
value.replace(QByteArrayLiteral("\""), QByteArrayLiteral("\\\""));
- ba.append(QByteArrayLiteral("\"") + value + QByteArrayLiteral("\""));
- } else
+ ba.append('"' + value + '"');
+ } else {
ba.append(value);
+ }
}
return ba;
}
diff --git a/src/base/QXmppStun.cpp b/src/base/QXmppStun.cpp
index f109d5c6..af36a085 100644
--- a/src/base/QXmppStun.cpp
+++ b/src/base/QXmppStun.cpp
@@ -32,6 +32,7 @@
#include <QNetworkInterface>
#include <QTimer>
#include <QUdpSocket>
+#include <QVariant>
#define STUN_ID_SIZE 12
#define STUN_RTO_INTERVAL 500
diff --git a/src/base/QXmppUtils.cpp b/src/base/QXmppUtils.cpp
index 1c0c1906..238aca70 100644
--- a/src/base/QXmppUtils.cpp
+++ b/src/base/QXmppUtils.cpp
@@ -35,7 +35,7 @@
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QRandomGenerator>
#endif
-#include <QRegExp>
+#include <QRegularExpression>
#include <QString>
#include <QStringList>
#include <QUuid>
@@ -116,30 +116,8 @@ static quint32 crctable[256] = {
///
QDateTime QXmppUtils::datetimeFromString(const QString &str)
{
- QRegExp tzRe(QStringLiteral("(Z|([+-])([0-9]{2}):([0-9]{2}))"));
- int tzPos = tzRe.indexIn(str, 19);
- if (str.size() < 20 || tzPos < 0)
- return QDateTime();
-
- // process date and time
- QDateTime dt = QDateTime::fromString(str.left(19), QStringLiteral("yyyy-MM-ddThh:mm:ss"));
- dt.setTimeSpec(Qt::UTC);
-
- // process milliseconds
- if (tzPos > 20 && str.at(19) == '.') {
- QString millis = (str.mid(20, tzPos - 20) + QStringLiteral("000")).left(3);
- dt = dt.addMSecs(millis.toInt());
- }
-
- // process time zone
- if (tzRe.cap(1) != QStringLiteral("Z")) {
- int offset = tzRe.cap(3).toInt() * 3600 + tzRe.cap(4).toInt() * 60;
- if (tzRe.cap(2) == QStringLiteral("+"))
- dt = dt.addSecs(-offset);
- else
- dt = dt.addSecs(offset);
- }
- return dt;
+ // Qt::ISODate parses milliseconds, but doesn't output them
+ return QDateTime::fromString(str, Qt::ISODate).toUTC();
}
///
@@ -148,11 +126,9 @@ QDateTime QXmppUtils::datetimeFromString(const QString &str)
///
QString QXmppUtils::datetimeToString(const QDateTime &dt)
{
- QDateTime utc = dt.toUTC();
- if (utc.time().msec())
- return utc.toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzzZ"));
- else
- return utc.toString(QStringLiteral("yyyy-MM-ddThh:mm:ssZ"));
+ if (dt.time().msec())
+ return dt.toUTC().toString(Qt::ISODateWithMs);
+ return dt.toUTC().toString(Qt::ISODate);
}
///
@@ -161,21 +137,23 @@ QString QXmppUtils::datetimeToString(const QDateTime &dt)
///
int QXmppUtils::timezoneOffsetFromString(const QString &str)
{
- QRegExp tzRe(QStringLiteral("(Z|([+-])([0-9]{2}):([0-9]{2}))"));
- if (!tzRe.exactMatch(str))
+ static const QRegularExpression timezoneRegex(QStringLiteral("(Z|([+-])([0-9]{2}):([0-9]{2}))"));
+
+ const auto match = timezoneRegex.match(str);
+ if (!match.hasMatch())
return 0;
// No offset from UTC
- if (tzRe.cap(1) == QStringLiteral("Z"))
+ if (match.captured(1) == u'Z')
return 0;
// Calculate offset
- const int offset = tzRe.cap(3).toInt() * 3600 +
- tzRe.cap(4).toInt() * 60;
- if (tzRe.cap(2) == QStringLiteral("-"))
+ const int offset = match.captured(3).toInt() * 3600 +
+ match.captured(4).toInt() * 60;
+
+ if (match.captured(2) == u'-')
return -offset;
- else
- return offset;
+ return offset;
}
///
diff --git a/src/base/QXmppUtils.h b/src/base/QXmppUtils.h
index 88d7123b..5a465819 100644
--- a/src/base/QXmppUtils.h
+++ b/src/base/QXmppUtils.h
@@ -37,7 +37,6 @@ class QByteArray;
class QDateTime;
class QDomElement;
class QString;
-class QStringList;
/// \brief The QXmppUtils class contains static utility functions.
///