aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-06-25 16:41:12 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2021-06-30 16:55:22 +0200
commite40563354fdbda99783a53c34defedc93550a066 (patch)
treef07f4fbe8b24bd5149a40c626e96d98db173923b /src
parent0d856879e87ea9ec390f76aa840cfcc3da016329 (diff)
Remove the trailing token from empty acknowledgment packets
When sending Acknowledgment packets with code 0.00, the message should be empty (RFC-7252 section 12.1). An empty message should have no token (token length is 0), and no bytes should appear after the message ID (RFC-7252 section 4.1, section 3). Since Reset packets have the same structure (only the packet type differs), unified the packet creation for both cases in one method. Fixes: QTBUG-94763 Pick-to: 6.2 6.1 5.15 Change-Id: If2619ad6f4f5dba500e04ab10dbbbf08e4887aef Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/coap/qcoapinternalrequest.cpp28
-rw-r--r--src/coap/qcoapinternalrequest_p.h3
-rw-r--r--src/coap/qcoapprotocol.cpp6
3 files changed, 10 insertions, 27 deletions
diff --git a/src/coap/qcoapinternalrequest.cpp b/src/coap/qcoapinternalrequest.cpp
index 48a2b9f..a6b8c04 100644
--- a/src/coap/qcoapinternalrequest.cpp
+++ b/src/coap/qcoapinternalrequest.cpp
@@ -103,34 +103,18 @@ bool QCoapInternalRequest::isValid() const
/*!
\internal
Initialize parameters to transform the QCoapInternalRequest into an
- acknowledgment message with the message id \a messageId and the given
- \a token.
-*/
-void QCoapInternalRequest::initForAcknowledgment(quint16 messageId, const QByteArray &token)
-{
- Q_D(QCoapInternalRequest);
-
- setMethod(QtCoap::Method::Invalid);
- d->message.setType(QCoapMessage::Type::Acknowledgment);
- d->message.setMessageId(messageId);
- d->message.setToken(token);
- d->message.setPayload(QByteArray());
- d->message.clearOptions();
-}
+ empty message (RST or ACK) with the message id \a messageId.
-/*!
- \internal
- Initialize parameters to transform the QCoapInternalRequest into a
- Reset message (RST) with the message id \a messageId.
-
- A Reset message should contain only the \a messageId.
+ An empty message should contain only the \a messageId.
*/
-void QCoapInternalRequest::initForReset(quint16 messageId)
+void QCoapInternalRequest::initEmptyMessage(quint16 messageId, QCoapMessage::Type type)
{
Q_D(QCoapInternalRequest);
+ Q_ASSERT(type == QCoapMessage::Type::Acknowledgment || type == QCoapMessage::Type::Reset);
+
setMethod(QtCoap::Method::Invalid);
- d->message.setType(QCoapMessage::Type::Reset);
+ d->message.setType(type);
d->message.setMessageId(messageId);
d->message.setToken(QByteArray());
d->message.setPayload(QByteArray());
diff --git a/src/coap/qcoapinternalrequest_p.h b/src/coap/qcoapinternalrequest_p.h
index f6875b3..6073df4 100644
--- a/src/coap/qcoapinternalrequest_p.h
+++ b/src/coap/qcoapinternalrequest_p.h
@@ -65,8 +65,7 @@ public:
bool isValid() const override;
- void initForAcknowledgment(quint16 messageId, const QByteArray &token);
- void initForReset(quint16 messageId);
+ void initEmptyMessage(quint16 messageId, QCoapMessage::Type type);
QByteArray toQByteArray() const;
void setMessageId(quint16);
diff --git a/src/coap/qcoapprotocol.cpp b/src/coap/qcoapprotocol.cpp
index c9e720d..3121ea4 100644
--- a/src/coap/qcoapprotocol.cpp
+++ b/src/coap/qcoapprotocol.cpp
@@ -596,8 +596,8 @@ void QCoapProtocolPrivate::sendAcknowledgment(QCoapInternalRequest *request) con
ackRequest.setTargetUri(request->targetUri());
auto internalReply = lastReplyForToken(request->token());
- ackRequest.initForAcknowledgment(internalReply->message()->messageId(),
- internalReply->message()->token());
+ ackRequest.initEmptyMessage(internalReply->message()->messageId(),
+ QCoapMessage::Type::Acknowledgment);
ackRequest.setConnection(request->connection());
sendRequest(&ackRequest);
}
@@ -618,7 +618,7 @@ void QCoapProtocolPrivate::sendReset(QCoapInternalRequest *request) const
resetRequest.setTargetUri(request->targetUri());
auto lastReply = lastReplyForToken(request->token());
- resetRequest.initForReset(lastReply->message()->messageId());
+ resetRequest.initEmptyMessage(lastReply->message()->messageId(), QCoapMessage::Type::Reset);
resetRequest.setConnection(request->connection());
sendRequest(&resetRequest);
}