mirror of
https://github.com/qt/qtmqtt.git
synced 2026-10-25 16:16:26 +00:00
Add reason code support for subscriptions
Change-Id: I13064ac4bbd3a42d70485b5055825a824472f9af Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
parent
c4edb58edc
commit
a216985e6a
@ -1441,6 +1441,7 @@ void QMqttConnection::finalize_suback()
|
||||
while (m_missingData > 0) {
|
||||
quint8 reason = readBufferTyped<quint8>(&m_missingData);
|
||||
|
||||
sub->d_func()->m_reasonCode = QMqtt::ReasonCode(reason);
|
||||
qCDebug(lcMqttConnectionVerbose) << "Finalize SUBACK: id:" << id << "qos:" << reason;
|
||||
if (reason <= 2) {
|
||||
// The broker might have a different support level for QoS than what
|
||||
@ -1450,56 +1451,9 @@ void QMqttConnection::finalize_suback()
|
||||
emit sub->qosChanged(reason);
|
||||
}
|
||||
sub->setState(QMqttSubscription::Subscribed);
|
||||
} else if (reason == 0x80) {
|
||||
qCDebug(lcMqttConnection) << "Subscription for id " << id << " failed.";
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
} else {
|
||||
bool mqtt5reason = false;
|
||||
if (m_clientPrivate->m_protocolVersion == QMqttClient::MQTT_5_0) {
|
||||
mqtt5reason = true;
|
||||
switch (reason) {
|
||||
case 0x83:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Implementation specific error for id:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0x87:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Not authorized for id:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0x8F:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Topic filter invalid:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0x91:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Packet identifier in use:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0x97:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Quota exceeded:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0x9E:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Shared subscriptions not supported:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0xA1:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Subscription Identifiers not supported:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
case 0xA2:
|
||||
qCDebug(lcMqttConnection) << "SUBACK Reason code: Wildcard subscriptions not supported:" << id;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
break;
|
||||
default:
|
||||
mqtt5reason = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mqtt5reason) {
|
||||
qCDebug(lcMqttConnection) << "Received invalid SUBACK result value:" << reason;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
}
|
||||
qCDebug(lcMqttConnection) << "Subscription for id " << id << " failed. Reason Code:" << reason;
|
||||
sub->setState(QMqttSubscription::Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +62,9 @@ enum class MessageStatus : quint8 {
|
||||
|
||||
enum class ReasonCode : quint16 {
|
||||
Success = 0,
|
||||
SubscriptionQoSLevel0 = 0,
|
||||
SubscriptionQoSLevel1 = 0x01,
|
||||
SubscriptionQoSLevel2 = 0x02,
|
||||
NoMatchingSubscriber = 0x10,
|
||||
UnspecifiedError = 0x80,
|
||||
MalformedPacket = 0x81,
|
||||
@ -75,6 +78,7 @@ enum class ReasonCode : quint16 {
|
||||
ServerBusy = 0x89,
|
||||
ClientBanned = 0x8A,
|
||||
InvalidAuthenticationMethod = 0x8C,
|
||||
InvalidTopicFilter = 0x8F,
|
||||
InvalidTopicName = 0x90,
|
||||
MessageIdInUse = 0x91,
|
||||
MessageIdNotFound = 0x92,
|
||||
@ -85,7 +89,10 @@ enum class ReasonCode : quint16 {
|
||||
QoSNotSupported = 0x9B,
|
||||
UseAnotherServer = 0x9C,
|
||||
ServerMoved = 0x9D,
|
||||
ExceededConnectionRate = 0x9F
|
||||
SharedSubscriptionsNotSupported = 0x9E,
|
||||
ExceededConnectionRate = 0x9F,
|
||||
SubscriptionIdsNotSupported = 0xA1,
|
||||
WildCardSubscriptionsNotSupported = 0xA2
|
||||
};
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@ -89,13 +89,21 @@ QT_BEGIN_NAMESPACE
|
||||
/*!
|
||||
\property QMqttSubscription::reason
|
||||
\since 5.12
|
||||
\brief This property holds the reason string after subscription has
|
||||
been established.
|
||||
\brief This property holds the reason string for the subscription.
|
||||
|
||||
A reason string is used by the server to provide additional information
|
||||
about the subscription. It is optional for the server to send it.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\property QMqttSubscription::reasonCode
|
||||
\since 5.12
|
||||
\brief This property holds the reason code for the subscription.
|
||||
|
||||
The reason code specifies the error type if a subscription has failed,
|
||||
or the level of QoS for success.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\property QMqttSubscription::shared
|
||||
\since 5.12
|
||||
@ -148,6 +156,12 @@ QString QMqttSubscription::reason() const
|
||||
return d->m_reasonString;
|
||||
}
|
||||
|
||||
QMqtt::ReasonCode QMqttSubscription::reasonCode() const
|
||||
{
|
||||
Q_D(const QMqttSubscription);
|
||||
return d->m_reasonCode;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.12
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ class Q_MQTT_EXPORT QMqttSubscription : public QObject
|
||||
Q_PROPERTY(quint8 qos READ qos NOTIFY qosChanged)
|
||||
Q_PROPERTY(QMqttTopicFilter topic READ topic)
|
||||
Q_PROPERTY(QString reason READ reason)
|
||||
Q_PROPERTY(QMqtt::ReasonCode reasonCode READ reasonCode)
|
||||
Q_PROPERTY(bool shared READ isShared)
|
||||
Q_PROPERTY(QString shareName READ shareName)
|
||||
public:
|
||||
@ -65,6 +66,7 @@ public:
|
||||
QMqttTopicFilter topic() const;
|
||||
quint8 qos() const;
|
||||
QString reason() const;
|
||||
QMqtt::ReasonCode reasonCode() const;
|
||||
QMqttUserProperties userProperties() const;
|
||||
|
||||
bool isShared() const;
|
||||
|
||||
@ -58,6 +58,7 @@ public:
|
||||
QMqttUserProperties m_userProperties;
|
||||
QString m_shareName;
|
||||
QMqttSubscription::SubscriptionState m_state{QMqttSubscription::Unsubscribed};
|
||||
QMqtt::ReasonCode m_reasonCode{QMqtt::ReasonCode::Success};
|
||||
quint8 m_qos{0};
|
||||
bool m_shared{false};
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user