summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2020-02-27 05:23:39 +0300
committerKonstantin Ritt <ritt.ks@gmail.com>2020-03-31 12:50:48 +0300
commit8b90d4808fad9e2fffda02dd90fa48e86d65e171 (patch)
tree2e8feb8906db3afb9354304d8b9ca3c31bd9f105
parent9750e33b22d76a0fc9e7c4e6925b85b66beb8122 (diff)
Introduce MQTT 5 AUTH specific Reason Codes
and use them in place of magic numbers to improve the code readability Change-Id: Iec458898f9aee79b4e1977cd3bbe8697cb036ce6 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r--src/mqtt/qmqttconnection.cpp13
-rw-r--r--src/mqtt/qmqttglobal.h2
-rw-r--r--src/mqtt/qmqtttype.cpp4
3 files changed, 13 insertions, 6 deletions
diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp
index a236797..be1c4a8 100644
--- a/src/mqtt/qmqttconnection.cpp
+++ b/src/mqtt/qmqttconnection.cpp
@@ -321,11 +321,11 @@ bool QMqttConnection::sendControlAuthenticate(const QMqttAuthenticationPropertie
return false;
case BrokerWaitForConnectAck:
qCDebug(lcMqttConnection) << "AUTH while connecting, set continuation flag.";
- packet.append(char(0x18));
+ packet.append(char(QMqtt::ReasonCode::ContinueAuthentication));
break;
case BrokerConnected:
qCDebug(lcMqttConnection) << "AUTH while connected, initiate re-authentication.";
- packet.append(char(0x19));
+ packet.append(char(QMqtt::ReasonCode::ReAuthenticate));
break;
}
@@ -1401,12 +1401,13 @@ void QMqttConnection::finalize_auth()
} else if (m_missingData > 0)
readAuthProperties(authProperties);
- switch (authReason) {
- case 0x00: // Success
+ // 3.15.2.1
+ switch (QMqtt::ReasonCode(authReason)) {
+ case QMqtt::ReasonCode::Success:
emit m_clientPrivate->m_client->authenticationFinished(authProperties);
break;
- case 0x18: // Continue Authentication
- case 0x19: // Re-authenticate
+ case QMqtt::ReasonCode::ContinueAuthentication:
+ case QMqtt::ReasonCode::ReAuthenticate:
emit m_clientPrivate->m_client->authenticationRequested(authProperties);
break;
default:
diff --git a/src/mqtt/qmqttglobal.h b/src/mqtt/qmqttglobal.h
index 8386a7c..56139b7 100644
--- a/src/mqtt/qmqttglobal.h
+++ b/src/mqtt/qmqttglobal.h
@@ -66,6 +66,8 @@ enum class ReasonCode : quint16 {
SubscriptionQoSLevel1 = 0x01,
SubscriptionQoSLevel2 = 0x02,
NoMatchingSubscriber = 0x10,
+ ContinueAuthentication = 0x18,
+ ReAuthenticate = 0x19,
UnspecifiedError = 0x80,
MalformedPacket = 0x81,
ProtocolError = 0x82,
diff --git a/src/mqtt/qmqtttype.cpp b/src/mqtt/qmqtttype.cpp
index bc7298b..256d009 100644
--- a/src/mqtt/qmqtttype.cpp
+++ b/src/mqtt/qmqtttype.cpp
@@ -136,6 +136,10 @@ QT_BEGIN_NAMESPACE
The message has been accepted by the server, but there are no
subscribers to receive this message. A broker may send this
reason code instead of \l Success.
+ \value ContinueAuthentication
+ Continue the authentication with another step. Since 5.15.
+ \value ReAuthenticate
+ Initiate a re-authentication. Since 5.15.
\value UnspecifiedError
An unspecified error occurred.
\value MalformedPacket