aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/coap/coap.pro12
-rw-r--r--src/coap/doc/src/qtcoap-overview.qdoc8
-rw-r--r--src/coap/qcoapclient.cpp104
-rw-r--r--src/coap/qcoapclient.h23
-rw-r--r--src/coap/qcoapclient_p.h4
-rw-r--r--src/coap/qcoapconnection.cpp34
-rw-r--r--src/coap/qcoapconnection.h87
-rw-r--r--src/coap/qcoapconnection_p.h51
-rw-r--r--src/coap/qcoapinternalmessage.cpp5
-rw-r--r--src/coap/qcoapinternalreply.cpp4
-rw-r--r--src/coap/qcoapinternalrequest.cpp10
-rw-r--r--src/coap/qcoapinternalrequest_p.h2
-rw-r--r--src/coap/qcoapmessage.cpp39
-rw-r--r--src/coap/qcoapmessage.h18
-rw-r--r--src/coap/qcoapmessage_p.h6
-rw-r--r--src/coap/qcoapnamespace.cpp12
-rw-r--r--src/coap/qcoapnamespace.h6
-rw-r--r--src/coap/qcoapnamespace_p.h57
-rw-r--r--src/coap/qcoapoption.cpp126
-rw-r--r--src/coap/qcoapoption.h22
-rw-r--r--src/coap/qcoapoption_p.h4
-rw-r--r--src/coap/qcoapprotocol.cpp132
-rw-r--r--src/coap/qcoapprotocol.h96
-rw-r--r--src/coap/qcoapprotocol_p.h60
-rw-r--r--src/coap/qcoapqudpconnection.cpp20
-rw-r--r--src/coap/qcoapqudpconnection.h81
-rw-r--r--src/coap/qcoapqudpconnection_p.h37
-rw-r--r--src/coap/qcoapreply.cpp25
-rw-r--r--src/coap/qcoapreply.h11
-rw-r--r--src/coap/qcoapreply_p.h2
-rw-r--r--src/coap/qcoaprequest.cpp70
-rw-r--r--src/coap/qcoaprequest.h19
-rw-r--r--src/coap/qcoaprequest_p.h10
-rw-r--r--src/coap/qcoapresource.cpp4
-rw-r--r--src/coap/qcoapresource.h2
-rw-r--r--src/coap/qcoapresourcediscoveryreply.cpp (renamed from src/coap/qcoapdiscoveryreply.cpp)40
-rw-r--r--src/coap/qcoapresourcediscoveryreply.h (renamed from src/coap/qcoapdiscoveryreply.h)23
-rw-r--r--src/coap/qcoapresourcediscoveryreply_p.h (renamed from src/coap/qcoapdiscoveryreply_p.h)17
-rw-r--r--src/coap/qcoapsecurityconfiguration.cpp16
-rw-r--r--src/coap/qcoapsecurityconfiguration.h18
40 files changed, 646 insertions, 671 deletions
diff --git a/src/coap/coap.pro b/src/coap/coap.pro
index 024de15..dbd9e6c 100644
--- a/src/coap/coap.pro
+++ b/src/coap/coap.pro
@@ -7,38 +7,35 @@ QMAKE_DOCS = $$PWD/doc/qtcoap.qdocconf
PUBLIC_HEADERS += \
qcoapclient.h \
- qcoapconnection.h \
- qcoapdiscoveryreply.h \
qcoapglobal.h \
qcoapmessage.h \
qcoapnamespace.h \
qcoapoption.h \
- qcoapprotocol.h \
- qcoapqudpconnection.h \
qcoapreply.h \
qcoaprequest.h \
qcoapresource.h \
+ qcoapresourcediscoveryreply.h \
qcoapsecurityconfiguration.h
PRIVATE_HEADERS += \
qcoapclient_p.h \
qcoapconnection_p.h \
- qcoapdiscoveryreply_p.h \
qcoapinternalmessage_p.h \
qcoapinternalreply_p.h \
qcoapinternalrequest_p.h \
qcoapmessage_p.h \
+ qcoapnamespace_p.h \
qcoapoption_p.h \
qcoapprotocol_p.h \
qcoapqudpconnection_p.h \
qcoapreply_p.h \
qcoaprequest_p.h \
- qcoapresource_p.h
+ qcoapresource_p.h \
+ qcoapresourcediscoveryreply_p.h
SOURCES += \
qcoapclient.cpp \
qcoapconnection.cpp \
- qcoapdiscoveryreply.cpp \
qcoapinternalmessage.cpp \
qcoapinternalreply.cpp \
qcoapinternalrequest.cpp \
@@ -50,6 +47,7 @@ SOURCES += \
qcoapreply.cpp \
qcoaprequest.cpp \
qcoapresource.cpp \
+ qcoapresourcediscoveryreply.cpp \
qcoapsecurityconfiguration.cpp
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
diff --git a/src/coap/doc/src/qtcoap-overview.qdoc b/src/coap/doc/src/qtcoap-overview.qdoc
index 5400362..c686974 100644
--- a/src/coap/doc/src/qtcoap-overview.qdoc
+++ b/src/coap/doc/src/qtcoap-overview.qdoc
@@ -106,15 +106,15 @@
firmware resource available in the network. The reply is represented in
\l {https://tools.ietf.org/html/rfc6690}{CoRE Link Format}.
- The specialized QCoapDiscoveryReply class is used to get the discovery replies:
+ The specialized QCoapResourceDiscoveryReply class is used to get the discovery replies:
\code
// This will make a multicast discovery request to the CoAP IPv4 multicast group.
- QCoapDiscoveryReply *discoverReply = client->discover();
- connect(discoverReply, &QCoapDiscoveryReply::discovered, this, &MyClass::onDiscovered);
+ QCoapResourceDiscoveryReply *discoverReply = client->discover();
+ connect(discoverReply, &QCoapResourceDiscoveryReply::discovered, this, &MyClass::onDiscovered);
\endcode
- The QCoapDiscoveryReply::discovered will return the list of CoAP resources found in the
+ The QCoapResourceDiscoveryReply::discovered will return the list of CoAP resources found in the
network.
\section2 Resource Observation
diff --git a/src/coap/qcoapclient.cpp b/src/coap/qcoapclient.cpp
index 767f7f0..5469ef2 100644
--- a/src/coap/qcoapclient.cpp
+++ b/src/coap/qcoapclient.cpp
@@ -31,10 +31,12 @@
#include "qcoapclient_p.h"
#include "qcoapprotocol_p.h"
#include "qcoapreply.h"
-#include "qcoapdiscoveryreply.h"
+#include "qcoapresourcediscoveryreply.h"
#include "qcoapnamespace.h"
#include "qcoapsecurityconfiguration.h"
-#include "qcoapqudpconnection.h"
+#include "qcoapqudpconnection_p.h"
+#include "qcoaprequest_p.h"
+#include "qcoapreply_p.h"
#include <QtCore/qiodevice.h>
#include <QtCore/qurl.h>
#include <QtCore/qloggingcategory.h>
@@ -107,11 +109,11 @@ QCoapClientPrivate::~QCoapClientPrivate()
When a reply arrives, the QCoapClient emits a finished() signal.
- \note For a discovery request, the returned object is a QCoapDiscoveryReply.
+ \note For a discovery request, the returned object is a QCoapResourceDiscoveryReply.
It can be used the same way as a QCoapReply but contains also a list of
resources.
- \sa QCoapRequest, QCoapReply, QCoapDiscoveryReply
+ \sa QCoapRequest, QCoapReply, QCoapResourceDiscoveryReply
*/
/*!
@@ -152,7 +154,7 @@ QCoapClientPrivate::~QCoapClientPrivate()
Constructs a QCoapClient object for the given \a securityMode and
sets \a parent as the parent object.
- The default for \a securityMode is SecurityMode::NoSec, which
+ The default for \a securityMode is QtCoap::NoSecurity, which
disables security.
This connects using a QCoapQUdpConnection; to use a custom transport,
@@ -160,7 +162,7 @@ QCoapClientPrivate::~QCoapClientPrivate()
constructors.
*/
QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode, QObject *parent) :
- QCoapClient(new QCoapProtocol, new QCoapQUdpConnection(securityMode), parent)
+ QCoapClient(new QCoapQUdpConnection(securityMode), parent)
{
}
@@ -169,23 +171,14 @@ QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode, QObject *parent) :
sets \a parent as the parent object.
*/
QCoapClient::QCoapClient(QCoapConnection *connection, QObject *parent) :
- QCoapClient(new QCoapProtocol, connection, parent)
-{
-}
-
-/*!
- Base constructor, taking the \a protocol, \a connection, and \a parent
- as arguments.
-*/
-QCoapClient::QCoapClient(QCoapProtocol *protocol, QCoapConnection *connection, QObject *parent) :
- QObject(*new QCoapClientPrivate(protocol, connection), parent)
+ QObject(*new QCoapClientPrivate(new QCoapProtocol, connection), parent)
{
Q_D(QCoapClient);
qRegisterMetaType<QCoapReply *>();
qRegisterMetaType<QCoapMessage>();
qRegisterMetaType<QPointer<QCoapReply>>();
- qRegisterMetaType<QPointer<QCoapDiscoveryReply>>();
+ qRegisterMetaType<QPointer<QCoapResourceDiscoveryReply>>();
qRegisterMetaType<QCoapConnection *>();
qRegisterMetaType<QtCoap::Error>();
qRegisterMetaType<QtCoap::ResponseCode>();
@@ -236,9 +229,8 @@ QCoapReply *QCoapClient::get(const QCoapRequest &request)
{
Q_D(QCoapClient);
- QCoapRequest copyRequest(request, QtCoap::Method::Get);
- copyRequest.adjustUrl(d->connection->isSecure());
-
+ QCoapRequest copyRequest = QCoapRequestPrivate::createRequest(request, QtCoap::Method::Get,
+ d->connection->isSecure());
return d->sendRequest(copyRequest);
}
@@ -265,10 +257,9 @@ QCoapReply *QCoapClient::put(const QCoapRequest &request, const QByteArray &data
{
Q_D(QCoapClient);
- QCoapRequest copyRequest(request, QtCoap::Method::Put);
+ QCoapRequest copyRequest = QCoapRequestPrivate::createRequest(request, QtCoap::Method::Put,
+ d->connection->isSecure());
copyRequest.setPayload(data);
- copyRequest.adjustUrl(d->connection->isSecure());
-
return d->sendRequest(copyRequest);
}
@@ -311,10 +302,9 @@ QCoapReply *QCoapClient::post(const QCoapRequest &request, const QByteArray &dat
{
Q_D(QCoapClient);
- QCoapRequest copyRequest(request, QtCoap::Method::Post);
+ QCoapRequest copyRequest = QCoapRequestPrivate::createRequest(request, QtCoap::Method::Post,
+ d->connection->isSecure());
copyRequest.setPayload(data);
- copyRequest.adjustUrl(d->connection->isSecure());
-
return d->sendRequest(copyRequest);
}
@@ -360,9 +350,8 @@ QCoapReply *QCoapClient::deleteResource(const QCoapRequest &request)
{
Q_D(QCoapClient);
- QCoapRequest copyRequest(request, QtCoap::Method::Delete);
- copyRequest.adjustUrl(d->connection->isSecure());
-
+ QCoapRequest copyRequest = QCoapRequestPrivate::createRequest(request, QtCoap::Method::Delete,
+ d->connection->isSecure());
return d->sendRequest(copyRequest);
}
@@ -382,8 +371,8 @@ QCoapReply *QCoapClient::deleteResource(const QUrl &url)
\overload
Discovers the resources available at the endpoints which have joined
- the \a group at the given \a port. Returns a new QCoapDiscoveryReply
- object which emits the \l QCoapDiscoveryReply::discovered() signal whenever
+ the \a group at the given \a port. Returns a new QCoapResourceDiscoveryReply
+ object which emits the \l QCoapResourceDiscoveryReply::discovered() signal whenever
a response arrives. The \a group is one of the CoAP multicast group addresses
and defaults to QtCoap::AllCoapNodesIPv4.
@@ -393,7 +382,7 @@ QCoapReply *QCoapClient::deleteResource(const QUrl &url)
\sa get(), post(), put(), deleteResource(), observe()
*/
-QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int port,
+QCoapResourceDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int port,
const QString &discoveryPath)
{
Q_D(QCoapClient);
@@ -416,17 +405,17 @@ QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int por
discoveryUrl.setPath(discoveryPath);
discoveryUrl.setPort(port);
- QCoapRequest request(discoveryUrl);
- request.setMethod(QtCoap::Method::Get);
- request.adjustUrl(d->connection->isSecure());
+ QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest(discoveryUrl),
+ QtCoap::Method::Get,
+ d->connection->isSecure());
return d->sendDiscovery(request);
}
/*!
Discovers the resources available at the given \a url and returns
- a new QCoapDiscoveryReply object which emits the
- \l QCoapDiscoveryReply::discovered() signal whenever the response
+ a new QCoapResourceDiscoveryReply object which emits the
+ \l QCoapResourceDiscoveryReply::discovered() signal whenever the response
arrives.
Discovery path defaults to "/.well-known/core", but can be changed
@@ -435,17 +424,16 @@ QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int por
\sa get(), post(), put(), deleteResource(), observe()
*/
-QCoapDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &discoveryPath)
+QCoapResourceDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &discoveryPath)
{
Q_D(QCoapClient);
QUrl discoveryUrl(url);
discoveryUrl.setPath(url.path() + discoveryPath);
- QCoapRequest request(discoveryUrl);
- request.setMethod(QtCoap::Method::Get);
- request.adjustUrl(d->connection->isSecure());
-
+ QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest(discoveryUrl),
+ QtCoap::Method::Get,
+ d->connection->isSecure());
return d->sendDiscovery(request);
}
@@ -458,7 +446,7 @@ QCoapDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &disco
*/
QCoapReply *QCoapClient::observe(const QCoapRequest &request)
{
- QCoapRequest copyRequest(request, QtCoap::Method::Get);
+ QCoapRequest copyRequest = QCoapRequestPrivate::createRequest(request, QtCoap::Method::Get);
copyRequest.enableObserve();
return get(copyRequest);
@@ -503,7 +491,7 @@ void QCoapClient::cancelObserve(QCoapReply *notifiedReply)
void QCoapClient::cancelObserve(const QUrl &url)
{
Q_D(QCoapClient);
- const auto adjustedUrl = QCoapRequest::adjustedUrl(url, d->connection->isSecure());
+ const auto adjustedUrl = QCoapRequestPrivate::adjustedUrl(url, d->connection->isSecure());
QMetaObject::invokeMethod(d->protocol, "cancelObserve", Q_ARG(QUrl, adjustedUrl));
}
@@ -527,7 +515,7 @@ QCoapReply *QCoapClientPrivate::sendRequest(const QCoapRequest &request)
Q_Q(QCoapClient);
// Prepare the reply
- QCoapReply *reply = new QCoapReply(request, q);
+ QCoapReply *reply = QCoapReplyPrivate::createCoapReply(request, q);
if (!send(reply)) {
delete reply;
@@ -541,14 +529,14 @@ QCoapReply *QCoapClientPrivate::sendRequest(const QCoapRequest &request)
\internal
Sends the CoAP \a request to its own URL and returns a
- new QCoapDiscoveryReply object.
+ new QCoapResourceDiscoveryReply object.
*/
-QCoapDiscoveryReply *QCoapClientPrivate::sendDiscovery(const QCoapRequest &request)
+QCoapResourceDiscoveryReply *QCoapClientPrivate::sendDiscovery(const QCoapRequest &request)
{
Q_Q(QCoapClient);
// Prepare the reply
- QCoapDiscoveryReply *reply = new QCoapDiscoveryReply(request, q);
+ QCoapResourceDiscoveryReply *reply = new QCoapResourceDiscoveryReply(request, q);
if (!send(reply)) {
delete reply;
@@ -571,7 +559,7 @@ bool QCoapClientPrivate::send(QCoapReply *reply)
return false;
}
- if (!QCoapRequest::isUrlValid(reply->request().url())) {
+ if (!QCoapRequestPrivate::isUrlValid(reply->request().url())) {
qCWarning(lcCoapClient, "Failed to send request for an invalid URL.");
return false;
}
@@ -579,7 +567,7 @@ bool QCoapClientPrivate::send(QCoapReply *reply)
// According to https://tools.ietf.org/html/rfc7252#section-8.1,
// multicast requests MUST be Non-confirmable.
if (QHostAddress(reply->url().host()).isMulticast()
- && reply->request().type() == QCoapMessage::MessageType::Confirmable) {
+ && reply->request().type() == QCoapMessage::Type::Confirmable) {
qCWarning(lcCoapClient, "Failed to send request, "
"multicast requests must be non-confirmable.");
return false;
@@ -594,7 +582,7 @@ bool QCoapClientPrivate::send(QCoapReply *reply)
/*!
Sets the security configuration parameters from \a configuration.
- Configuration will be ignored if the QtCoap::NoSec mode is used.
+ Configuration will be ignored if the QtCoap::NoSecurity mode is used.
\note This method must be called before the handshake starts.
*/
@@ -610,8 +598,6 @@ void QCoapClient::setSecurityConfiguration(const QCoapSecurityConfiguration &con
Sets the maximum block size used by the protocol to \a blockSize
when sending requests and receiving replies. The block size must be
a power of two.
-
- \sa QCoapProtocol::setBlockSize()
*/
void QCoapClient::setBlockSize(quint16 blockSize)
{
@@ -640,10 +626,10 @@ void QCoapClient::setSocketOption(QAbstractSocket::SocketOption option, const QV
As defined in \l {RFC 7390 - Section 2.5}, \c MAX_SERVER_RESPONSE_DELAY is the expected
maximum response delay over all servers that the client can send a multicast request to.
*/
-void QCoapClient::setMaxServerResponseDelay(uint responseDelay)
+void QCoapClient::setMaximumServerResponseDelay(uint responseDelay)
{
Q_D(QCoapClient);
- QMetaObject::invokeMethod(d->protocol, "setMaxServerResponseDelay", Qt::QueuedConnection,
+ QMetaObject::invokeMethod(d->protocol, "setMaximumServerResponseDelay", Qt::QueuedConnection,
Q_ARG(uint, responseDelay));
}
@@ -680,14 +666,14 @@ void QCoapClient::setAckRandomFactor(double ackRandomFactor)
/*!
Sets the \c MAX_RETRANSMIT value defined in \l {RFC 7252 - Section 4.2}
- to \a maxRetransmit. This value should be less than or equal to 25.
+ to \a maximumRetransmitCount. This value should be less than or equal to 25.
The default is 4.
*/
-void QCoapClient::setMaxRetransmit(uint maxRetransmit)
+void QCoapClient::setMaximumRetransmitCount(uint maximumRetransmitCount)
{
Q_D(QCoapClient);
- QMetaObject::invokeMethod(d->protocol, "setMaxRetransmit", Qt::QueuedConnection,
- Q_ARG(uint, maxRetransmit));
+ QMetaObject::invokeMethod(d->protocol, "setMaximumRetransmitCount", Qt::QueuedConnection,
+ Q_ARG(uint, maximumRetransmitCount));
}
QT_END_NAMESPACE
diff --git a/src/coap/qcoapclient.h b/src/coap/qcoapclient.h
index fb06903..7171b59 100644
--- a/src/coap/qcoapclient.h
+++ b/src/coap/qcoapclient.h
@@ -40,7 +40,7 @@
QT_BEGIN_NAMESPACE
class QCoapReply;
-class QCoapDiscoveryReply;
+class QCoapResourceDiscoveryReply;
class QCoapRequest;
class QCoapProtocol;
class QCoapConnection;
@@ -53,7 +53,7 @@ class Q_COAP_EXPORT QCoapClient : public QObject
{
Q_OBJECT
public:
- explicit QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSec,
+ explicit QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSecurity,
QObject *parent = nullptr);
explicit QCoapClient(QCoapConnection *connection, QObject *parent = nullptr);
~QCoapClient();
@@ -74,19 +74,21 @@ public:
void cancelObserve(const QUrl &url);
void disconnect();
- QCoapDiscoveryReply *discover(QtCoap::MulticastGroup group = QtCoap::MulticastGroup::AllCoapNodesIPv4,
- int port = QtCoap::DefaultPort,
- const QString &discoveryPath = QLatin1String("/.well-known/core"));
- QCoapDiscoveryReply *discover(const QUrl &baseUrl,
- const QString &discoveryPath = QLatin1String("/.well-known/core"));
+ QCoapResourceDiscoveryReply *discover(
+ QtCoap::MulticastGroup group = QtCoap::MulticastGroup::AllCoapNodesIPv4,
+ int port = QtCoap::DefaultPort,
+ const QString &discoveryPath = QLatin1String("/.well-known/core"));
+ QCoapResourceDiscoveryReply *discover(
+ const QUrl &baseUrl,
+ const QString &discoveryPath = QLatin1String("/.well-known/core"));
void setSecurityConfiguration(const QCoapSecurityConfiguration &configuration);
void setBlockSize(quint16 blockSize);
void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
- void setMaxServerResponseDelay(uint responseDelay);
+ void setMaximumServerResponseDelay(uint responseDelay);
void setAckTimeout(uint ackTimeout);
void setAckRandomFactor(double ackRandomFactor);
- void setMaxRetransmit(uint maxRetransmit);
+ void setMaximumRetransmitCount(uint maximumRetransmitCount);
Q_SIGNALS:
void finished(QCoapReply *reply);
@@ -95,9 +97,6 @@ Q_SIGNALS:
void error(QCoapReply *reply, QtCoap::Error error);
protected:
- explicit QCoapClient(QCoapProtocol *protocol, QCoapConnection *connection,
- QObject *parent = nullptr);
-
Q_DECLARE_PRIVATE(QCoapClient)
};
diff --git a/src/coap/qcoapclient_p.h b/src/coap/qcoapclient_p.h
index 40db811..84d3a83 100644
--- a/src/coap/qcoapclient_p.h
+++ b/src/coap/qcoapclient_p.h
@@ -31,9 +31,7 @@
#ifndef QCOAPCLIENT_P_H
#define QCOAPCLIENT_P_H
-#include <QtCoap/qcoapconnection.h>
#include <QtCoap/qcoapclient.h>
-#include <QtCoap/qcoapprotocol.h>
#include <QtCore/qthread.h>
#include <QtCore/qpointer.h>
#include <private/qobject_p.h>
@@ -62,7 +60,7 @@ public:
QThread *workerThread = nullptr;
QCoapReply *sendRequest(const QCoapRequest &request);
- QCoapDiscoveryReply *sendDiscovery(const QCoapRequest &request);
+ QCoapResourceDiscoveryReply *sendDiscovery(const QCoapRequest &request);
bool send(QCoapReply *reply);
Q_DECLARE_PUBLIC(QCoapClient)
diff --git a/src/coap/qcoapconnection.cpp b/src/coap/qcoapconnection.cpp
index 96e98fa..23cb0d9 100644
--- a/src/coap/qcoapconnection.cpp
+++ b/src/coap/qcoapconnection.cpp
@@ -36,6 +36,8 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
/*!
+ \internal
+
\class QCoapConnection
\inmodule QtCoap
@@ -47,6 +49,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\enum QCoapConnection::ConnectionState
This enum specifies the state of the underlying transport.
@@ -60,6 +64,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\fn void QCoapConnection::error(QAbstractSocket::SocketError error)
This signal is emitted when a connection error occurs. The \a error
@@ -67,6 +73,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\fn void QCoapConnection::readyRead(const QByteArray &data, const QHostAddress &sender)
This signal is emitted when a network reply is available. The \a data
@@ -75,6 +83,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\fn void QCoapConnection::bound()
This signal is emitted when the underlying transport is ready for data transmission.
@@ -91,6 +101,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\fn void QCoapConnection::bind(const QString &host, quint16 port)
Prepares the underlying transport for data transmission to to the given \a host
@@ -102,6 +114,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\fn void QCoapConnection::close()
Closes the open sockets and connections to free the underlying transport.
@@ -111,6 +125,8 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection")
*/
/*!
+ \internal
+
\fn void QCoapConnection::writeData(const QByteArray &data, const QString &host, quint16 port)
Sends the given \a data frame to the host address \a host at port \a port.
@@ -151,6 +167,8 @@ QCoapConnection::QCoapConnection(QObjectPrivate &dd, QObject *parent)
}
/*!
+ \internal
+
Releases any resources held by QCoapConnection.
*/
QCoapConnection::~QCoapConnection()
@@ -182,15 +200,19 @@ QCoapConnectionPrivate::sendRequest(const QByteArray &request, const QString &ho
}
/*!
+ \internal
+
Returns \c true if security is used, returns \c false otherwise.
*/
bool QCoapConnection::isSecure() const
{
Q_D(const QCoapConnection);
- return d->securityMode != QtCoap::SecurityMode::NoSec;
+ return d->securityMode != QtCoap::SecurityMode::NoSecurity;
}
/*!
+ \internal
+
Returns the security mode.
*/
QtCoap::SecurityMode QCoapConnection::securityMode() const
@@ -200,6 +222,8 @@ QtCoap::SecurityMode QCoapConnection::securityMode() const
}
/*!
+ \internal
+
Returns the connection state.
*/
QCoapConnection::ConnectionState QCoapConnection::state() const
@@ -225,8 +249,8 @@ void QCoapConnection::startToSendRequest()
/*!
Sets the security configuration parameters from the \a configuration.
- The security configuration will be ignored if the QtCoap::NoSec mode is used
- for connection.
+ The security configuration will be ignored if the QtCoap::NoSecurity mode is
+ used for connection.
\note This method must be called before the handshake starts.
*/
@@ -243,6 +267,8 @@ void QCoapConnection::setSecurityConfiguration(const QCoapSecurityConfiguration
}
/*!
+ \internal
+
Returns the security configuration.
*/
QCoapSecurityConfiguration QCoapConnection::securityConfiguration() const
@@ -252,6 +278,8 @@ QCoapSecurityConfiguration QCoapConnection::securityConfiguration() const
}
/*!
+ \internal
+
Closes the open sockets and connections to free the transport and clears
the connection state.
*/
diff --git a/src/coap/qcoapconnection.h b/src/coap/qcoapconnection.h
deleted file mode 100644
index 6f2931f..0000000
--- a/src/coap/qcoapconnection.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCoap module.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) any later version
-** approved by the KDE Free Qt Foundation. The licenses are as published by
-** the Free Software Foundation and appearing in the file LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCOAPCONNECTION_H
-#define QCOAPCONNECTION_H
-
-#include <QtCoap/qcoapglobal.h>
-#include <QtCoap/qcoapnamespace.h>
-#include <QtCoap/qcoapsecurityconfiguration.h>
-
-#include <QtNetwork/QAbstractSocket>
-
-QT_BEGIN_NAMESPACE
-
-class QCoapConnectionPrivate;
-class Q_COAP_EXPORT QCoapConnection : public QObject
-{
- Q_OBJECT
-public:
- enum class ConnectionState : quint8 {
- Unconnected,
- Bound
- };
-
- explicit QCoapConnection(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSec,
- QObject *parent = nullptr);
- virtual ~QCoapConnection();
-
- bool isSecure() const;
- QtCoap::SecurityMode securityMode() const;
- ConnectionState state() const;
- QCoapSecurityConfiguration securityConfiguration() const;
-
- Q_INVOKABLE void setSecurityConfiguration(const QCoapSecurityConfiguration &configuration);
- Q_INVOKABLE void disconnect();
-
-Q_SIGNALS:
- void error(QAbstractSocket::SocketError error);
- void readyRead(const QByteArray &data, const QHostAddress &sender);
- void bound();
- void securityConfigurationChanged();
-
-private:
- void startToSendRequest();
-
-protected:
- QCoapConnection(QObjectPrivate &dd, QObject *parent = nullptr);
-
- virtual void bind(const QString &host, quint16 port) = 0;
- virtual void writeData(const QByteArray &data, const QString &host, quint16 port) = 0;
- virtual void close() = 0;
-
-private:
- friend class QCoapProtocolPrivate;
-
- Q_DECLARE_PRIVATE(QCoapConnection)
-};
-
-QT_END_NAMESPACE
-
-#endif // QCOAPCONNECTION_H
diff --git a/src/coap/qcoapconnection_p.h b/src/coap/qcoapconnection_p.h
index d75c794..200744d 100644
--- a/src/coap/qcoapconnection_p.h
+++ b/src/coap/qcoapconnection_p.h
@@ -30,9 +30,12 @@
#ifndef QCOAPCONNECTION_P_H
#define QCOAPCONNECTION_P_H
-#include <QtCoap/qcoapconnection.h>
+#include <QtCoap/qcoapnamespace.h>
+#include <QtCoap/qcoapsecurityconfiguration.h>
#include <QtCore/qqueue.h>
+#include <QtCore/qobject.h>
+#include <QtNetwork/qabstractsocket.h>
#include <private/qobject_p.h>
//
@@ -48,6 +51,50 @@
QT_BEGIN_NAMESPACE
+class QCoapConnectionPrivate;
+class Q_AUTOTEST_EXPORT QCoapConnection : public QObject
+{
+ Q_OBJECT
+public:
+ enum class ConnectionState : quint8 {
+ Unconnected,
+ Bound
+ };
+
+ explicit QCoapConnection(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSecurity,
+ QObject *parent = nullptr);
+ virtual ~QCoapConnection();
+
+ bool isSecure() const;
+ QtCoap::SecurityMode securityMode() const;
+ ConnectionState state() const;
+ QCoapSecurityConfiguration securityConfiguration() const;
+
+ Q_INVOKABLE void setSecurityConfiguration(const QCoapSecurityConfiguration &configuration);
+ Q_INVOKABLE void disconnect();
+
+Q_SIGNALS:
+ void error(QAbstractSocket::SocketError error);
+ void readyRead(const QByteArray &data, const QHostAddress &sender);
+ void bound();
+ void securityConfigurationChanged();
+
+private:
+ void startToSendRequest();
+
+protected:
+ QCoapConnection(QObjectPrivate &dd, QObject *parent = nullptr);
+
+ virtual void bind(const QString &host, quint16 port) = 0;
+ virtual void writeData(const QByteArray &data, const QString &host, quint16 port) = 0;
+ virtual void close() = 0;
+
+private:
+ friend class QCoapProtocolPrivate;
+
+ Q_DECLARE_PRIVATE(QCoapConnection)
+};
+
struct CoapFrame {
QByteArray currentPdu;
QString host;
@@ -60,7 +107,7 @@ struct CoapFrame {
class Q_AUTOTEST_EXPORT QCoapConnectionPrivate : public QObjectPrivate
{
public:
- QCoapConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSec);
+ QCoapConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSecurity);
~QCoapConnectionPrivate() override = default;
diff --git a/src/coap/qcoapinternalmessage.cpp b/src/coap/qcoapinternalmessage.cpp
index 85c2263..121ee74 100644
--- a/src/coap/qcoapinternalmessage.cpp
+++ b/src/coap/qcoapinternalmessage.cpp
@@ -29,6 +29,7 @@
****************************************************************************/
#include "qcoapinternalmessage_p.h"
+#include "qcoaprequest_p.h"
#include <QtCoap/qcoaprequest.h>
#include <QtCore/qloggingcategory.h>
@@ -123,7 +124,7 @@ void QCoapInternalMessage::setFromDescriptiveBlockOption(const QCoapOption &opti
Q_D(QCoapInternalMessage);
//! TODO Cover with tests
- const quint8 *optionData = reinterpret_cast<const quint8 *>(option.value().data());
+ const quint8 *optionData = reinterpret_cast<const quint8 *>(option.opaqueValue().data());
const quint8 lastByte = optionData[option.length() - 1];
quint32 blockNumber = 0;
@@ -261,7 +262,7 @@ bool QCoapInternalMessage::isValid() const
*/
bool QCoapInternalMessage::isUrlValid(const QUrl &url)
{
- return QCoapRequest::isUrlValid(url);
+ return QCoapRequestPrivate::isUrlValid(url);
}
QT_END_NAMESPACE
diff --git a/src/coap/qcoapinternalreply.cpp b/src/coap/qcoapinternalreply.cpp
index 191e8ba..2480a05 100644
--- a/src/coap/qcoapinternalreply.cpp
+++ b/src/coap/qcoapinternalreply.cpp
@@ -92,7 +92,7 @@ QCoapInternalReply *QCoapInternalReply::createFromFrame(const QByteArray &reply,
// Parse Header and Token
d->message.setVersion((pduData[0] >> 6) & 0x03);
- d->message.setType(QCoapMessage::MessageType((pduData[0] >> 4) & 0x03));
+ d->message.setType(QCoapMessage::Type((pduData[0] >> 4) & 0x03));
quint8 tokenLength = (pduData[0]) & 0x0F;
d->responseCode = static_cast<QtCoap::ResponseCode>(pduData[1]);
d->message.setMessageId(static_cast<quint16>((static_cast<quint16>(pduData[2]) << 8)
@@ -188,7 +188,7 @@ int QCoapInternalReply::nextBlockToSend() const
if (!option.isValid())
return -1;
- const quint8 *optionData = reinterpret_cast<const quint8 *>(option.value().data());
+ const quint8 *optionData = reinterpret_cast<const quint8 *>(option.opaqueValue().data());
const quint8 lastByte = optionData[option.length() - 1];
// M field
diff --git a/src/coap/qcoapinternalrequest.cpp b/src/coap/qcoapinternalrequest.cpp
index 2e10432..ff6354c 100644
--- a/src/coap/qcoapinternalrequest.cpp
+++ b/src/coap/qcoapinternalrequest.cpp
@@ -111,11 +111,11 @@ void QCoapInternalRequest::initForAcknowledgment(quint16 messageId, const QByteA
Q_D(QCoapInternalRequest);
setMethod(QtCoap::Method::Invalid);
- d->message.setType(QCoapMessage::MessageType::Acknowledgment);
+ d->message.setType(QCoapMessage::Type::Acknowledgment);
d->message.setMessageId(messageId);
d->message.setToken(token);
d->message.setPayload(QByteArray());
- d->message.removeAllOptions();
+ d->message.clearOptions();
}
/*!
@@ -130,11 +130,11 @@ void QCoapInternalRequest::initForReset(quint16 messageId)
Q_D(QCoapInternalRequest);
setMethod(QtCoap::Method::Invalid);
- d->message.setType(QCoapMessage::MessageType::Reset);
+ d->message.setType(QCoapMessage::Type::Reset);
d->message.setMessageId(messageId);
d->message.setToken(QByteArray());
d->message.setPayload(QByteArray());
- d->message.removeAllOptions();
+ d->message.clearOptions();
}
/*!
@@ -231,7 +231,7 @@ QByteArray QCoapInternalRequest::toQByteArray() const
if (isOptionLengthExtended)
appendByte(&pdu, optionLengthExtended);
- pdu.append(option.value());
+ pdu.append(option.opaqueValue());
lastOptionNumber = option.name();
}
diff --git a/src/coap/qcoapinternalrequest_p.h b/src/coap/qcoapinternalrequest_p.h
index 549f5f0..f6875b3 100644
--- a/src/coap/qcoapinternalrequest_p.h
+++ b/src/coap/qcoapinternalrequest_p.h
@@ -35,7 +35,7 @@
#include <QtCoap/qcoapglobal.h>
#include <QtCoap/qcoapnamespace.h>
-#include <QtCoap/qcoapconnection.h>
+#include <private/qcoapconnection_p.h>
#include <QtCore/qglobal.h>
#include <QtCore/qtimer.h>
diff --git a/src/coap/qcoapmessage.cpp b/src/coap/qcoapmessage.cpp
index d07611c..d1ad665 100644
--- a/src/coap/qcoapmessage.cpp
+++ b/src/coap/qcoapmessage.cpp
@@ -32,7 +32,7 @@
QT_BEGIN_NAMESPACE
-QCoapMessagePrivate::QCoapMessagePrivate(QCoapMessage::MessageType _type) :
+QCoapMessagePrivate::QCoapMessagePrivate(QCoapMessage::Type _type) :
type(_type)
{
}
@@ -64,7 +64,7 @@ QCoapMessagePrivate::~QCoapMessagePrivate()
*/
/*!
- \enum QCoapMessage::MessageType
+ \enum QCoapMessage::Type
Indicates the type of the message.
@@ -179,7 +179,7 @@ void QCoapMessage::removeOption(QCoapOption::OptionName name)
/*!
Removes all options.
*/
-void QCoapMessage::removeAllOptions()
+void QCoapMessage::clearOptions()
{
Q_D(QCoapMessage);
d->options.clear();
@@ -201,7 +201,7 @@ quint8 QCoapMessage::version() const
\sa setType()
*/
-QCoapMessage::MessageType QCoapMessage::type() const
+QCoapMessage::Type QCoapMessage::type() const
{
Q_D(const QCoapMessage);
return d->type;
@@ -252,7 +252,7 @@ QByteArray QCoapMessage::payload() const
/*!
Returns the option at \a index position.
*/
-QCoapOption QCoapMessage::option(int index) const
+QCoapOption QCoapMessage::optionAt(int index) const
{
Q_D(const QCoapMessage);
return d->options.at(index);
@@ -260,25 +260,27 @@ QCoapOption QCoapMessage::option(int index) const
/*!
Finds and returns the first option with the given \a name.
- If there is no such option, returns an Invalid CoapOption with an empty value.
+ If there is no such option, returns an invalid QCoapOption with an empty value.
*/
QCoapOption QCoapMessage::option(QCoapOption::OptionName name) const
{
Q_D(const QCoapMessage);
- auto it = findOption(name);
+ auto it = d->findOption(name);
return it != d->options.end() ? *it : QCoapOption();
}
/*!
+ \internal
+
Finds and returns a constant iterator to the first option
with the given \a name.
If there is no such option, returns \c d->options.end().
*/
-QVector<QCoapOption>::const_iterator QCoapMessage::findOption(QCoapOption::OptionName name) const
+QVector<QCoapOption>::const_iterator
+QCoapMessagePrivate::findOption(QCoapOption::OptionName name) const
{
- Q_D(const QCoapMessage);
- return std::find_if(d->options.begin(), d->options.end(), [name](const QCoapOption &option) {
+ return std::find_if(options.begin(), options.end(), [name](const QCoapOption &option) {
return option.name() == name;
});
}
@@ -290,7 +292,7 @@ QVector<QCoapOption>::const_iterator QCoapMessage::findOption(QCoapOption::Optio
bool QCoapMessage::hasOption(QCoapOption::OptionName name) const
{
Q_D(const QCoapMessage);
- return findOption(name) != d->options.end();
+ return d->findOption(name) != d->options.end();
}
/*!
@@ -342,7 +344,7 @@ void QCoapMessage::setVersion(quint8 version)
\sa type()
*/
-void QCoapMessage::setType(const MessageType &type)
+void QCoapMessage::setType(const Type &type)
{
Q_D(QCoapMessage);
d->type = type;
@@ -387,7 +389,16 @@ void QCoapMessage::setPayload(const QByteArray &payload)
d->payload = payload;
}
-void QCoapMessage::swap(QCoapMessage &other) Q_DECL_NOTHROW
+/*!
+ Sets the message options to \a options.
+*/
+void QCoapMessage::setOptions(const QVector<QCoapOption> &options)
+{
+ Q_D(QCoapMessage);
+ d->options = options;
+}
+
+void QCoapMessage::swap(QCoapMessage &other) noexcept
{
qSwap(d_ptr, other.d_ptr);
}
@@ -395,7 +406,7 @@ void QCoapMessage::swap(QCoapMessage &other) Q_DECL_NOTHROW
/*!
Move-assignment operator.
*/
-QCoapMessage &QCoapMessage::operator=(QCoapMessage &&other) Q_DECL_NOTHROW
+QCoapMessage &QCoapMessage::operator=(QCoapMessage &&other) noexcept
{
swap(other);
return *this;
diff --git a/src/coap/qcoapmessage.h b/src/coap/qcoapmessage.h
index 36288a7..200a44b 100644
--- a/src/coap/qcoapmessage.h
+++ b/src/coap/qcoapmessage.h
@@ -44,7 +44,7 @@ class QCoapMessagePrivate;
class Q_COAP_EXPORT QCoapMessage
{
public:
- enum class MessageType : quint8 {
+ enum class Type : quint8 {
Confirmable,
NonConfirmable,
Acknowledgment,
@@ -55,25 +55,25 @@ public:
QCoapMessage(const QCoapMessage &other);
~QCoapMessage();
- void swap(QCoapMessage &other) Q_DECL_NOTHROW;
+ void swap(QCoapMessage &other) noexcept;
QCoapMessage &operator=(const QCoapMessage &other);
- QCoapMessage &operator=(QCoapMessage &&other) Q_DECL_NOTHROW;
+ QCoapMessage &operator=(QCoapMessage &&other) noexcept;
quint8 version() const;
- MessageType type() const;
+ Type type() const;
QByteArray token() const;
quint8 tokenLength() const;
quint16 messageId() const;
QByteArray payload() const;
void setVersion(quint8 version);
- void setType(const MessageType &type);
+ void setType(const Type &type);
void setToken(const QByteArray &token);
void setMessageId(quint16);
void setPayload(const QByteArray &payload);
+ void setOptions(const QVector<QCoapOption> &options);
- QCoapOption option(int index) const;
+ QCoapOption optionAt(int index) const;
QCoapOption option(QCoapOption::OptionName name) const;
- QVector<QCoapOption>::const_iterator findOption(QCoapOption::OptionName name) const;
bool hasOption(QCoapOption::OptionName name) const;
const QVector<QCoapOption> &options() const;
QVector<QCoapOption> options(QCoapOption::OptionName name) const;
@@ -82,7 +82,7 @@ public:
void addOption(const QCoapOption &option);
void removeOption(const QCoapOption &option);
void removeOption(QCoapOption::OptionName name);
- void removeAllOptions();
+ void clearOptions();
protected:
explicit QCoapMessage(QCoapMessagePrivate &dd);
@@ -99,6 +99,6 @@ Q_DECLARE_SHARED(QCoapMessage)
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QCoapMessage)
-Q_DECLARE_METATYPE(QCoapMessage::MessageType)
+Q_DECLARE_METATYPE(QCoapMessage::Type)
#endif // QCOAPMESSAGE_H
diff --git a/src/coap/qcoapmessage_p.h b/src/coap/qcoapmessage_p.h
index b16ba2b..fbff1b8 100644
--- a/src/coap/qcoapmessage_p.h
+++ b/src/coap/qcoapmessage_p.h
@@ -51,12 +51,14 @@ QT_BEGIN_NAMESPACE
class Q_AUTOTEST_EXPORT QCoapMessagePrivate : public QSharedData
{
public:
- QCoapMessagePrivate(QCoapMessage::MessageType type = QCoapMessage::MessageType::NonConfirmable);
+ QCoapMessagePrivate(QCoapMessage::Type type = QCoapMessage::Type::NonConfirmable);
QCoapMessagePrivate(const QCoapMessagePrivate &other);
~QCoapMessagePrivate();
+ QVector<QCoapOption>::const_iterator findOption(QCoapOption::OptionName name) const;
+
quint8 version = 1;
- QCoapMessage::MessageType type = QCoapMessage::MessageType::NonConfirmable;
+ QCoapMessage::Type type = QCoapMessage::Type::NonConfirmable;
quint16 messageId = 0;
QByteArray token;
QVector<QCoapOption> options;
diff --git a/src/coap/qcoapnamespace.cpp b/src/coap/qcoapnamespace.cpp
index b1e5fc4..dbf0f52 100644
--- a/src/coap/qcoapnamespace.cpp
+++ b/src/coap/qcoapnamespace.cpp
@@ -27,7 +27,7 @@
**
****************************************************************************/
-#include "qcoapnamespace.h"
+#include "qcoapnamespace_p.h"
QT_BEGIN_NAMESPACE
@@ -238,7 +238,7 @@ QT_BEGIN_NAMESPACE
Specifies the security mode used for securing a CoAP connection, as defined in
\l{https://tools.ietf.org/html/rfc7252#section-9}{RFC 7252}.
- \value NoSec There is no protocol-level security (DTLS is disabled).
+ \value NoSecurity There is no protocol-level security (DTLS is disabled).
\value PreSharedKey DTLS is enabled. PSK authentication will be used for security.
@@ -269,6 +269,8 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \internal
+
Returns \c true if \a code corresponds to an error, returns \c false otherwise.
*/
bool QtCoap::isError(QtCoap::ResponseCode code)
@@ -277,10 +279,12 @@ bool QtCoap::isError(QtCoap::ResponseCode code)
}
/*!
+ \internal
+
Returns the QtCoap::Error corresponding to the \a code passed to this
method.
*/
-QtCoap::Error QtCoap::responseCodeError(QtCoap::ResponseCode code)
+QtCoap::Error QtCoap::errorForResponseCode(QtCoap::ResponseCode code)
{
if (!isError(code))
return QtCoap::Error::Ok;
@@ -295,6 +299,8 @@ QtCoap::Error QtCoap::responseCodeError(QtCoap::ResponseCode code)
}
/*!
+ \internal
+
Returns the internal random generator used for generating token values and
message IDs.
*/
diff --git a/src/coap/qcoapnamespace.h b/src/coap/qcoapnamespace.h
index 353a046..f81c92b 100644
--- a/src/coap/qcoapnamespace.h
+++ b/src/coap/qcoapnamespace.h
@@ -104,7 +104,7 @@ namespace QtCoap
Q_ENUM_NS(Port)
enum class SecurityMode : quint8 {
- NoSec = 0,
+ NoSecurity = 0,
PreSharedKey,
RawPublicKey,
Certificate
@@ -118,10 +118,6 @@ namespace QtCoap
};
Q_ENUM_NS(MulticastGroup)
- Q_COAP_EXPORT bool isError(ResponseCode code);
- Q_COAP_EXPORT Error responseCodeError(ResponseCode code);
- Q_COAP_EXPORT QRandomGenerator &randomGenerator();
-
Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
}
diff --git a/src/coap/qcoapnamespace_p.h b/src/coap/qcoapnamespace_p.h
new file mode 100644
index 0000000..0417a04
--- /dev/null
+++ b/src/coap/qcoapnamespace_p.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtCoap module.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOAPNAMESPACE_P_H
+#define QCOAPNAMESPACE_P_H
+
+#include "qcoapnamespace.h"
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+namespace QtCoap
+{
+ bool Q_AUTOTEST_EXPORT isError(QtCoap::ResponseCode code);
+ Error Q_AUTOTEST_EXPORT errorForResponseCode(QtCoap::ResponseCode code);
+ QRandomGenerator Q_AUTOTEST_EXPORT &randomGenerator();
+}
+
+QT_END_NAMESPACE
+
+#endif // QCOAPNAMESPACE_P_H
diff --git a/src/coap/qcoapoption.cpp b/src/coap/qcoapoption.cpp
index ddb42fd..ac5e809 100644
--- a/src/coap/qcoapoption.cpp
+++ b/src/coap/qcoapoption.cpp
@@ -88,59 +88,45 @@ Q_LOGGING_CATEGORY(lcCoapOption, "qt.coap.option")
/*!
Constructs a new CoAP option with the given \a name
- and QByteArray \a value.
+ and QByteArray \a opaqueValue.
If no parameters are passed, constructs an Invalid object.
\sa isValid()
*/
-QCoapOption::QCoapOption(OptionName name, const QByteArray &value) :
+QCoapOption::QCoapOption(OptionName name, const QByteArray &opaqueValue) :
d_ptr(new QCoapOptionPrivate)
{
Q_D(QCoapOption);
d->name = name;
- setValue(value);
+ d->setValue(opaqueValue);
}
/*!
Constructs a new CoAP option with the given \a name
- and the QStringView \a value.
+ and the QString \a stringValue.
\sa isValid()
*/
-QCoapOption::QCoapOption(OptionName name, QStringView value) :
+QCoapOption::QCoapOption(OptionName name, const QString &stringValue) :
d_ptr(new QCoapOptionPrivate)
{
Q_D(QCoapOption);
d->name = name;
- setValue(value);
+ d->setValue(stringValue);
}
/*!
Constructs a new CoAP option with the given \a name
- and the string \a value.
+ and the unsigned integer \a intValue.
\sa isValid()
*/
-QCoapOption::QCoapOption(OptionName name, const char *value) :
+QCoapOption::QCoapOption(OptionName name, quint32 intValue) :
d_ptr(new QCoapOptionPrivate)
{
Q_D(QCoapOption);
d->name = name;
- setValue(value);
-}
-
-/*!
- Constructs a new CoAP option with the given \a name
- and the unsigned integer \a value.
-
- \sa isValid()
- */
-QCoapOption::QCoapOption(OptionName name, quint32 value) :
- d_ptr(new QCoapOptionPrivate)
-{
- Q_D(QCoapOption);
- d->name = name;
- setValue(value);
+ d->setValue(intValue);
}
/*!
@@ -186,7 +172,7 @@ QCoapOption &QCoapOption::operator=(const QCoapOption &other)
/*!
Move-assignment operator.
*/
-QCoapOption &QCoapOption::operator=(QCoapOption &&other) Q_DECL_NOTHROW
+QCoapOption &QCoapOption::operator=(QCoapOption &&other) noexcept
{
swap(other);
return *this;
@@ -195,7 +181,7 @@ QCoapOption &QCoapOption::operator=(QCoapOption &&other) Q_DECL_NOTHROW
/*!
Swaps this option with \a other. This operation is very fast and never fails.
*/
-void QCoapOption::swap(QCoapOption &other) Q_DECL_NOTHROW
+void QCoapOption::swap(QCoapOption &other) noexcept
{
qSwap(d_ptr, other.d_ptr);
}
@@ -203,7 +189,7 @@ void QCoapOption::swap(QCoapOption &other) Q_DECL_NOTHROW
/*!
Returns the value of the option.
*/
-QByteArray QCoapOption::value() const
+QByteArray QCoapOption::opaqueValue() const
{
Q_D(const QCoapOption);
return d->value;
@@ -212,7 +198,7 @@ QByteArray QCoapOption::value() const
/*!
Returns the integer value of the option.
*/
-quint32 QCoapOption::valueToInt() const
+quint32 QCoapOption::uintValue() const
{
Q_D(const QCoapOption);
@@ -224,6 +210,15 @@ quint32 QCoapOption::valueToInt() const
}
/*!
+ Returns the QString value of the option.
+*/
+QString QCoapOption::stringValue() const
+{
+ Q_D(const QCoapOption);
+ return QString::fromUtf8(d->value);
+}
+
+/*!
Returns the length of the value of the option.
*/
int QCoapOption::length() const
@@ -269,95 +264,88 @@ bool QCoapOption::operator!=(const QCoapOption &other) const
}
/*!
+ \internal
+
Sets the \a value for the option.
*/
-void QCoapOption::setValue(const QByteArray &value)
+void QCoapOptionPrivate::setValue(const QByteArray &opaqueValue)
{
- Q_D(QCoapOption);
bool oversized = false;
// Check for value maximum size, according to section 5.10 of RFC 7252
// https://tools.ietf.org/html/rfc7252#section-5.10
- switch (d_ptr->name) {
- case IfNoneMatch:
- if (value.size() > 0)
+ switch (name) {
+ case QCoapOption::IfNoneMatch:
+ if (opaqueValue.size() > 0)
oversized = true;
break;
- case UriPort:
- case ContentFormat:
- case Accept:
- if (value.size() > 2)
+ case QCoapOption::UriPort:
+ case QCoapOption::ContentFormat:
+ case QCoapOption::Accept:
+ if (opaqueValue.size() > 2)
oversized = true;
break;
- case MaxAge:
- case Size1:
- if (value.size() > 4)
+ case QCoapOption::MaxAge:
+ case QCoapOption::Size1:
+ if (opaqueValue.size() > 4)
oversized = true;
break;
- case IfMatch:
- case Etag:
- if (value.size() > 8)
+ case QCoapOption::IfMatch:
+ case QCoapOption::Etag:
+ if (opaqueValue.size() > 8)
oversized = true;
break;
- case UriHost:
- case LocationPath:
- case UriPath:
- case UriQuery:
- case LocationQuery:
- case ProxyScheme:
- if (value.size() > 255)
+ case QCoapOption::UriHost:
+ case QCoapOption::LocationPath:
+ case QCoapOption::UriPath:
+ case QCoapOption::UriQuery:
+ case QCoapOption::LocationQuery:
+ case QCoapOption::ProxyScheme:
+ if (opaqueValue.size() > 255)
oversized = true;
break;
- case ProxyUri:
- if (value.size() > 1034)
+ case QCoapOption::ProxyUri:
+ if (opaqueValue.size() > 1034)
oversized = true;
break;
- case Observe:
- case Block2:
- case Block1:
- case Size2:
+ case QCoapOption::Observe:
+ case QCoapOption::Block2:
+ case QCoapOption::Block1:
+ case QCoapOption::Size2:
default:
break;
}
if (oversized)
- qCWarning(lcCoapOption) << "Value" << value << "is probably too big for option" << d->name;
+ qCWarning(lcCoapOption) << "Value" << opaqueValue << "is probably too big for option" << name;
- d->value = value;
+ value = opaqueValue;
}
/*!
+ \internal
\overload
Sets the \a value for the option.
*/
-void QCoapOption::setValue(QStringView value)
+void QCoapOptionPrivate::setValue(const QString &value)
{
setValue(value.toUtf8());
}
/*!
+ \internal
\overload
Sets the \a value for the option.
*/
-void QCoapOption::setValue(const char *value)
-{
- setValue(QByteArray(value, static_cast<int>(strlen(value))));
-}
-
-/*!
- \overload
-
- Sets the \a value for the option.
- */
-void QCoapOption::setValue(quint32 value)
+void QCoapOptionPrivate::setValue(quint32 value)
{
QByteArray data;
for (; value; value >>= 8)
diff --git a/src/coap/qcoapoption.h b/src/coap/qcoapoption.h
index ea9dc3c..3b44450 100644
--- a/src/coap/qcoapoption.h
+++ b/src/coap/qcoapoption.h
@@ -64,20 +64,20 @@ public:
Size1 = 60
};
- QCoapOption(OptionName name = Invalid, const QByteArray &value = QByteArray());
- QCoapOption(OptionName name, QStringView value);
- QCoapOption(OptionName name, const char *value);
- QCoapOption(OptionName name, quint32 value);
+ QCoapOption(OptionName name = Invalid, const QByteArray &opaqueValue = QByteArray());
+ QCoapOption(OptionName name, const QString &stringValue);
+ QCoapOption(OptionName name, quint32 intValue);
QCoapOption(const QCoapOption &other);
QCoapOption(QCoapOption &&other);
~QCoapOption();
QCoapOption &operator=(const QCoapOption &other);
- QCoapOption &operator=(QCoapOption &&other) Q_DECL_NOTHROW;
- void swap(QCoapOption &other) Q_DECL_NOTHROW;
+ QCoapOption &operator=(QCoapOption &&other) noexcept;
+ void swap(QCoapOption &other) noexcept;
- QByteArray value() const;
- quint32 valueToInt() const;
+ QByteArray opaqueValue() const;
+ quint32 uintValue() const;
+ QString stringValue() const;
int length() const;
OptionName name() const;
bool isValid() const;
@@ -85,12 +85,6 @@ public:
bool operator==(const QCoapOption &other) const;
bool operator!=(const QCoapOption &other) const;
-protected:
- void setValue(const QByteArray &value);
- void setValue(QStringView value);
- void setValue(const char *value);
- void setValue(quint32 value);
-
private:
QCoapOptionPrivate *d_ptr;
diff --git a/src/coap/qcoapoption_p.h b/src/coap/qcoapoption_p.h
index 9cc1bac..ff60acd 100644
--- a/src/coap/qcoapoption_p.h
+++ b/src/coap/qcoapoption_p.h
@@ -52,6 +52,10 @@ class Q_AUTOTEST_EXPORT QCoapOptionPrivate
public:
QCoapOptionPrivate() = default;
+ void setValue(const QByteArray &opaqueValue);
+ void setValue(const QString &value);
+ void setValue(quint32 value);
+
QCoapOption::OptionName name = QCoapOption::Invalid;
QByteArray value;
};
diff --git a/src/coap/qcoapprotocol.cpp b/src/coap/qcoapprotocol.cpp
index dd5f25d..46f420c 100644
--- a/src/coap/qcoapprotocol.cpp
+++ b/src/coap/qcoapprotocol.cpp
@@ -31,8 +31,9 @@
#include "qcoapprotocol_p.h"
#include "qcoapinternalrequest_p.h"
#include "qcoapinternalreply_p.h"
-#include "qcoapconnection.h"
+#include "qcoaprequest_p.h"
#include "qcoapconnection_p.h"
+#include "qcoapnamespace_p.h"
#include <QtCore/qrandom.h>
#include <QtCore/qthread.h>
@@ -44,6 +45,8 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcCoapProtocol, "qt.coap.protocol")
/*!
+ \internal
+
\class QCoapProtocol
\inmodule QtCoap
@@ -61,6 +64,8 @@ Q_LOGGING_CATEGORY(lcCoapProtocol, "qt.coap.protocol")
*/
/*!
+ \internal
+
\fn void QCoapProtocol::finished(QCoapReply *reply)
This signal is emitted along with the \l QCoapReply::finished() signal
@@ -72,6 +77,8 @@ Q_LOGGING_CATEGORY(lcCoapProtocol, "qt.coap.protocol")
*/
/*!
+ \internal
+
\fn void QCoapProtocol::responseToMulticastReceived(QCoapReply *reply,
const QCoapMessage& message,
const QHostAddress &sender)
@@ -85,6 +92,8 @@ Q_LOGGING_CATEGORY(lcCoapProtocol, "qt.coap.protocol")
*/
/*!
+ \internal
+
\fn void QCoapProtocol::error(QCoapReply *reply, QtCoap::Error error)
This signal is emitted whenever an error occurs. The \a reply parameter
@@ -95,6 +104,8 @@ Q_LOGGING_CATEGORY(lcCoapProtocol, "qt.coap.protocol")
*/
/*!
+ \internal
+
Constructs a new QCoapProtocol and sets \a parent as the parent object.
*/
QCoapProtocol::QCoapProtocol(QObject *parent) :
@@ -124,7 +135,8 @@ void QCoapProtocol::sendRequest(QPointer<QCoapReply> reply, QCoapConnection *con
Q_D(QCoapProtocol);
Q_ASSERT(QThread::currentThread() == thread());
- if (reply.isNull() || !reply->request().isValid())
+ if (reply.isNull() || reply->request().method() == QtCoap::Method::Invalid
+ || !QCoapRequestPrivate::isUrlValid(reply->request().url()))
return;
connect(reply, &QCoapReply::aborted, this, [this](const QCoapToken &token) {
@@ -133,7 +145,7 @@ void QCoapProtocol::sendRequest(QPointer<QCoapReply> reply, QCoapConnection *con
});
auto internalRequest = QSharedPointer<QCoapInternalRequest>::create(reply->request(), this);
- internalRequest->setMaxTransmissionWait(maxTransmitWait());
+ internalRequest->setMaxTransmissionWait(maximumTransmitWait());
connect(reply, &QCoapReply::finished, this, &QCoapProtocol::finished);
if (internalRequest->isMulticast()) {
@@ -145,8 +157,8 @@ void QCoapProtocol::sendRequest(QPointer<QCoapReply> reply, QCoapConnection *con
// The timeout interval is chosen based on
// https://tools.ietf.org/html/rfc7390#section-2.5
internalRequest->setMulticastTimeout(nonConfirmLifetime()
- + maxLatency()
- + maxServerResponseDelay());
+ + maximumLatency()
+ + maximumServerResponseDelay());
}
// Set a unique Message Id and Token
@@ -168,10 +180,10 @@ void QCoapProtocol::sendRequest(QPointer<QCoapReply> reply, QCoapConnection *con
internalRequest->setToSendBlock(0, d->blockSize);
}
- if (requestMessage->type() == QCoapMessage::MessageType::Confirmable)
- internalRequest->setTimeout(QtCoap::randomGenerator().bounded(minTimeout(), maxTimeout()));
+ if (requestMessage->type() == QCoapMessage::Type::Confirmable)
+ internalRequest->setTimeout(QtCoap::randomGenerator().bounded(minimumTimeout(), maximumTimeout()));
else
- internalRequest->setTimeout(maxTimeout());
+ internalRequest->setTimeout(maximumTimeout());
connect(internalRequest.data(), &QCoapInternalRequest::timeout,
[this](QCoapInternalRequest *request) {
@@ -229,8 +241,8 @@ void QCoapProtocolPrivate::onRequestTimeout(QCoapInternalRequest *request)
if (!isRequestRegistered(request))
return;
- if (request->message()->type() == QCoapMessage::MessageType::Confirmable
- && request->retransmissionCounter() < maxRetransmit) {
+ if (request->message()->type() == QCoapMessage::Type::Confirmable
+ && request->retransmissionCounter() < maximumRetransmitCount) {
sendRequest(request);
} else {
onRequestError(request, QtCoap::Error::TimeOut);
@@ -282,7 +294,7 @@ void QCoapProtocolPrivate::onMulticastRequestExpired(QCoapInternalRequest *reque
*/
void QCoapProtocolPrivate::onRequestError(QCoapInternalRequest *request, QCoapInternalReply *reply)
{
- QtCoap::Error error = QtCoap::responseCodeError(reply->responseCode());
+ QtCoap::Error error = QtCoap::errorForResponseCode(reply->responseCode());
onRequestError(request, error, reply);
}
@@ -366,7 +378,7 @@ void QCoapProtocolPrivate::onFrameReceived(const QByteArray &data, const QHostAd
// Remove option to ensure that it will stop
request->removeOption(QCoapOption::Observe);
sendReset(request);
- } else if (messageReceived->type() == QCoapMessage::MessageType::Confirmable) {
+ } else if (messageReceived->type() == QCoapMessage::Type::Confirmable) {
sendAcknowledgment(request);
}
@@ -505,7 +517,7 @@ void QCoapProtocolPrivate::onLastMessageReceived(QCoapInternalRequest *request,
auto lastReply = replies.last();
// Ignore empty ACK messages
- if (lastReply->message()->type() == QCoapMessage::MessageType::Acknowledgment
+ if (lastReply->message()->type() == QCoapMessage::Type::Acknowledgment
&& lastReply->responseCode() == QtCoap::ResponseCode::EmptyMessage) {
exchangeMap[request->token()].replies.takeLast();
return;
@@ -877,10 +889,12 @@ bool QCoapProtocolPrivate::isMessageIdRegistered(quint16 id) const
}
/*!
+ \internal
+
Returns the ACK_TIMEOUT value in milliseconds.
The default is 2000.
- \sa minTimeout(), setAckTimeout()
+ \sa minimumTimeout(), setAckTimeout()
*/
uint QCoapProtocol::ackTimeout() const
{
@@ -889,6 +903,8 @@ uint QCoapProtocol::ackTimeout() const
}
/*!
+ \internal
+
Returns the ACK_RANDOM_FACTOR value.
The default is 1.5.
@@ -901,20 +917,24 @@ double QCoapProtocol::ackRandomFactor() const
}
/*!
+ \internal
+
Returns the MAX_RETRANSMIT value. This is the maximum number of
retransmissions of a message, before notifying a timeout error.
The default is 4.
- \sa setMaxRetransmit()
+ \sa setMaximumRetransmitCount()
*/
-uint QCoapProtocol::maxRetransmit() const
+uint QCoapProtocol::maximumRetransmitCount() const
{
Q_D(const QCoapProtocol);
- return d->maxRetransmit;
+ return d->maximumRetransmitCount;
}
/*!
- Returns the max block size wanted.
+ \internal
+
+ Returns the maximum block size wanted.
The default is 0, which invites the server to choose the block size.
\sa setBlockSize()
@@ -926,18 +946,22 @@ quint16 QCoapProtocol::blockSize() const
}
/*!
+ \internal
+
Returns the MAX_TRANSMIT_SPAN in milliseconds, as defined in
\l{https://tools.ietf.org/search/rfc7252#section-4.8.2}{RFC 7252}.
It is the maximum time from the first transmission of a Confirmable
message to its last retransmission.
*/
-uint QCoapProtocol::maxTransmitSpan() const
+uint QCoapProtocol::maximumTransmitSpan() const
{
- return static_cast<uint>(ackTimeout() * (1u << (maxRetransmit() - 1)) * ackRandomFactor());
+ return static_cast<uint>(ackTimeout() * (1u << (maximumRetransmitCount() - 1)) * ackRandomFactor());
}
/*!
+ \internal
+
Returns the MAX_TRANSMIT_WAIT in milliseconds, as defined in
\l{https://tools.ietf.org/search/rfc7252#section-4.8.2}{RFC 7252}.
@@ -945,13 +969,15 @@ uint QCoapProtocol::maxTransmitSpan() const
message to the time when the sender gives up on receiving an
acknowledgment or reset.
*/
-uint QCoapProtocol::maxTransmitWait() const
+uint QCoapProtocol::maximumTransmitWait() const
{
- return static_cast<uint>(ackTimeout() * ((1u << (maxRetransmit() + 1)) - 1)
+ return static_cast<uint>(ackTimeout() * ((1u << (maximumRetransmitCount() + 1)) - 1)
* ackRandomFactor());
}
/*!
+ \internal
+
Returns the MAX_LATENCY in milliseconds, as defined in
\l{https://tools.ietf.org/search/rfc7252#section-4.8.2}{RFC 7252}. This
value is arbitrarily set to 100 seconds by the standard.
@@ -959,36 +985,42 @@ uint QCoapProtocol::maxTransmitWait() const
It is the maximum time a datagram is expected to take from the start of
its transmission to the completion of its reception.
*/
-constexpr uint QCoapProtocol::maxLatency()
+uint QCoapProtocol::maximumLatency() const
{
return 100 * 1000;
}
/*!
+ \internal
+
Returns the minimum duration for messages timeout. The timeout is defined
- as a random value between minTimeout() and maxTimeout(). This is a
+ as a random value between minimumTimeout() and maximumTimeout(). This is a
convenience method identical to ackTimeout().
\sa ackTimeout(), setAckTimeout()
*/
-uint QCoapProtocol::minTimeout() const
+uint QCoapProtocol::minimumTimeout() const
{
Q_D(const QCoapProtocol);
return d->ackTimeout;
}
/*!
+ \internal
+
Returns the maximum duration for messages timeout in milliseconds.
- \sa maxTimeout(), setAckTimeout(), setAckRandomFactor()
+ \sa maximumTimeout(), setAckTimeout(), setAckRandomFactor()
*/
-uint QCoapProtocol::maxTimeout() const
+uint QCoapProtocol::maximumTimeout() const
{
Q_D(const QCoapProtocol);
return static_cast<uint>(d->ackTimeout * d->ackRandomFactor);
}
/*!
+ \internal
+
Returns the \c NON_LIFETIME in milliseconds, as defined in
\l{https://tools.ietf.org/search/rfc7252#section-4.8.2}{RFC 7252}.
@@ -997,25 +1029,29 @@ uint QCoapProtocol::maxTimeout() const
*/
uint QCoapProtocol::nonConfirmLifetime() const
{
- return maxTransmitSpan() + maxLatency();
+ return maximumTransmitSpan() + maximumLatency();
}
/*!
+ \internal
+
Returns the \c MAX_SERVER_RESPONSE_DELAY in milliseconds, as defined in
\l {RFC 7390 - Section 2.5}.
It is the expected maximum response delay over all servers that the client
can send a multicast request to.
- \sa setMaxServerResponseDelay()
+ \sa setMaximumServerResponseDelay()
*/
-uint QCoapProtocol::maxServerResponseDelay() const
+uint QCoapProtocol::maximumServerResponseDelay() const
{
Q_D(const QCoapProtocol);
- return d->maxServerResponseDelay;
+ return d->maximumServerResponseDelay;
}
/*!
+ \internal
+
Sets the ACK_TIMEOUT value to \a ackTimeout in milliseconds.
The default is 2000 ms.
@@ -1023,7 +1059,7 @@ uint QCoapProtocol::maxServerResponseDelay() const
reliable transmissions is a random value between ackTimeout() and
ackTimeout() * ackRandomFactor().
- \sa ackTimeout(), setAckRandomFactor(), minTimeout(), maxTimeout()
+ \sa ackTimeout(), setAckRandomFactor(), minimumTimeout(), maximumTimeout()
*/
void QCoapProtocol::setAckTimeout(uint ackTimeout)
{
@@ -1032,6 +1068,8 @@ void QCoapProtocol::setAckTimeout(uint ackTimeout)
}
/*!
+ \internal
+
Sets the ACK_RANDOM_FACTOR value to \a ackRandomFactor. This value
should be greater than or equal to 1.
The default is 1.5.
@@ -1048,26 +1086,30 @@ void QCoapProtocol::setAckRandomFactor(double ackRandomFactor)
}
/*!
- Sets the MAX_RETRANSMIT value to \a maxRetransmit, but never
+ \internal
+
+ Sets the MAX_RETRANSMIT value to \a maximumRetransmitCount, but never
to more than 25.
The default is 4.
- \sa maxRetransmit()
+ \sa maximumRetransmitCount()
*/
-void QCoapProtocol::setMaxRetransmit(uint maxRetransmit)
+void QCoapProtocol::setMaximumRetransmitCount(uint maximumRetransmitCount)
{
Q_D(QCoapProtocol);
- if (maxRetransmit > 25) {
- qCWarning(lcCoapProtocol, "Max retransmit count is capped at 25.");
- maxRetransmit = 25;
+ if (maximumRetransmitCount > 25) {
+ qCWarning(lcCoapProtocol, "Maximum retransmit count is capped at 25.");
+ maximumRetransmitCount = 25;
}
- d->maxRetransmit = maxRetransmit;
+ d->maximumRetransmitCount = maximumRetransmitCount;
}
/*!
- Sets the max block size wanted to \a blockSize.
+ \internal
+
+ Sets the maximum block size wanted to \a blockSize.
The \a blockSize should be zero, or range from 16 to 1024 and be a
power of 2. A size of 0 invites the server to choose the block size.
@@ -1093,20 +1135,20 @@ void QCoapProtocol::setBlockSize(quint16 blockSize)
}
/*!
+ \internal
+
Sets the \c MAX_SERVER_RESPONSE_DELAY value to \a responseDelay in milliseconds.
The default is 250 seconds.
As defined in \l {RFC 7390 - Section 2.5}, \c MAX_SERVER_RESPONSE_DELAY is the expected
maximum response delay over all servers that the client can send a multicast request to.
- \sa maxServerResponseDelay()
+ \sa maximumServerResponseDelay()
*/
-void QCoapProtocol::setMaxServerResponseDelay(uint responseDelay)
+void QCoapProtocol::setMaximumServerResponseDelay(uint responseDelay)
{
Q_D(QCoapProtocol);
- d->maxServerResponseDelay = responseDelay;
+ d->maximumServerResponseDelay = responseDelay;
}
QT_END_NAMESPACE
-
-#include "moc_qcoapprotocol.cpp"
diff --git a/src/coap/qcoapprotocol.h b/src/coap/qcoapprotocol.h
deleted file mode 100644
index 0c91443..0000000
--- a/src/coap/qcoapprotocol.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Witekio.
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCoap module.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) any later version
-** approved by the KDE Free Qt Foundation. The licenses are as published by
-** the Free Software Foundation and appearing in the file LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCOAPPROTOCOL_H
-#define QCOAPPROTOCOL_H
-
-#include <QtCoap/qcoapglobal.h>
-#include <QtCoap/qcoapreply.h>
-#include <QtCoap/qcoapresource.h>
-#include <QtCore/qobject.h>
-#include <QtNetwork/qudpsocket.h>
-#include <QtNetwork/qhostaddress.h>
-
-QT_BEGIN_NAMESPACE
-
-class QCoapInternalRequest;
-class QCoapInternalReply;
-class QCoapProtocolPrivate;
-class QCoapConnection;
-class Q_COAP_EXPORT QCoapProtocol : public QObject
-{
- Q_OBJECT
-public:
- explicit QCoapProtocol(QObject *parent = nullptr);
- ~QCoapProtocol();
-
- uint ackTimeout() const;
- double ackRandomFactor() const;
- uint maxRetransmit() const;
- quint16 blockSize() const;
- uint maxTransmitSpan() const;
- uint maxTransmitWait() const;
- static constexpr uint maxLatency();
-
- uint minTimeout() const;
- uint maxTimeout() const;
-
- uint nonConfirmLifetime() const;
- uint maxServerResponseDelay() const;
-
-Q_SIGNALS:
- void finished(QCoapReply *reply);
- void responseToMulticastReceived(QCoapReply *reply, const QCoapMessage &message,
- const QHostAddress &sender);
- void error(QCoapReply *reply, QtCoap::Error error);
-
-public:
- Q_INVOKABLE void setAckTimeout(uint ackTimeout);
- Q_INVOKABLE void setAckRandomFactor(double ackRandomFactor);
- Q_INVOKABLE void setMaxRetransmit(uint maxRetransmit);
- Q_INVOKABLE void setBlockSize(quint16 blockSize);
- Q_INVOKABLE void setMaxServerResponseDelay(uint responseDelay);
-
-private:
- Q_INVOKABLE void sendRequest(QPointer<QCoapReply> reply, QCoapConnection *connection);
- Q_INVOKABLE void cancelObserve(QPointer<QCoapReply> reply) const;
- Q_INVOKABLE void cancelObserve(const QUrl &url) const;
-
-private:
- Q_DECLARE_PRIVATE(QCoapProtocol)
-
- friend class QCoapClient;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QHostAddress)
-
-#endif // QCOAPPROTOCOL_H
diff --git a/src/coap/qcoapprotocol_p.h b/src/coap/qcoapprotocol_p.h
index 602ef73..4bd61c8 100644
--- a/src/coap/qcoapprotocol_p.h
+++ b/src/coap/qcoapprotocol_p.h
@@ -31,10 +31,13 @@
#ifndef QCOAPPROTOCOL_P_H
#define QCOAPPROTOCOL_P_H
-#include <QtCoap/qcoapprotocol.h>
+#include <QtCoap/qcoapglobal.h>
+#include <QtCoap/qcoapreply.h>
+#include <QtCoap/qcoapresource.h>
#include <QtCore/qvector.h>
#include <QtCore/qqueue.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qobject.h>
#include <private/qobject_p.h>
//
@@ -50,6 +53,55 @@
QT_BEGIN_NAMESPACE
+class QCoapInternalRequest;
+class QCoapInternalReply;
+class QCoapProtocolPrivate;
+class QCoapConnection;
+class Q_AUTOTEST_EXPORT QCoapProtocol : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QCoapProtocol(QObject *parent = nullptr);
+ ~QCoapProtocol();
+
+ uint ackTimeout() const;
+ double ackRandomFactor() const;
+ uint maximumRetransmitCount() const;
+ quint16 blockSize() const;
+ uint maximumTransmitSpan() const;
+ uint maximumTransmitWait() const;
+ uint maximumLatency() const;
+
+ uint minimumTimeout() const;
+ uint maximumTimeout() const;
+
+ uint nonConfirmLifetime() const;
+ uint maximumServerResponseDelay() const;
+
+Q_SIGNALS:
+ void finished(QCoapReply *reply);
+ void responseToMulticastReceived(QCoapReply *reply, const QCoapMessage &message,
+ const QHostAddress &sender);
+ void error(QCoapReply *reply, QtCoap::Error error);
+
+public:
+ Q_INVOKABLE void setAckTimeout(uint ackTimeout);
+ Q_INVOKABLE void setAckRandomFactor(double ackRandomFactor);
+ Q_INVOKABLE void setMaximumRetransmitCount(uint maximumRetransmitCount);
+ Q_INVOKABLE void setBlockSize(quint16 blockSize);
+ Q_INVOKABLE void setMaximumServerResponseDelay(uint responseDelay);
+
+private:
+ Q_INVOKABLE void sendRequest(QPointer<QCoapReply> reply, QCoapConnection *connection);
+ Q_INVOKABLE void cancelObserve(QPointer<QCoapReply> reply) const;
+ Q_INVOKABLE void cancelObserve(const QUrl &url) const;
+
+private:
+ Q_DECLARE_PRIVATE(QCoapProtocol)
+
+ friend class QCoapClient;
+};
+
struct CoapExchangeData {
QPointer<QCoapReply> userReply;
QSharedPointer<QCoapInternalRequest> request;
@@ -105,9 +157,9 @@ public:
CoapExchangeMap exchangeMap;
quint16 blockSize = 0;
- uint maxRetransmit = 4;
+ uint maximumRetransmitCount = 4;
uint ackTimeout = 2000;
- uint maxServerResponseDelay = 250 * 1000;
+ uint maximumServerResponseDelay = 250 * 1000;
double ackRandomFactor = 1.5;
Q_DECLARE_PUBLIC(QCoapProtocol)
@@ -115,4 +167,6 @@ public:
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QHostAddress)
+
#endif // QCOAPPROTOCOL_P_H
diff --git a/src/coap/qcoapqudpconnection.cpp b/src/coap/qcoapqudpconnection.cpp
index e38fe5b..ebb3fa9 100644
--- a/src/coap/qcoapqudpconnection.cpp
+++ b/src/coap/qcoapqudpconnection.cpp
@@ -45,6 +45,8 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(lcCoapConnection)
/*!
+ \internal
+
\class QCoapQUdpConnection
\inmodule QtCoap
@@ -68,7 +70,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcCoapConnection)
sets \a parent as the parent object.
\note Since QtCoap::RawPublicKey is not supported yet, the connection
- will fall back to the QtCoap::NoSec in the QtCoap::RawPublicKey mode.
+ will fall back to the QtCoap::NoSecurity in the QtCoap::RawPublicKey mode.
That is, the connection won't be secure in this mode.
*/
QCoapQUdpConnection::QCoapQUdpConnection(QtCoap::SecurityMode securityMode, QObject *parent) :
@@ -104,7 +106,7 @@ QCoapQUdpConnection::QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject
case QtCoap::SecurityMode::RawPublicKey:
qCWarning(lcCoapConnection, "RawPublicKey security is not supported yet,"
"disabling security");
- d->securityMode = QtCoap::SecurityMode::NoSec;
+ d->securityMode = QtCoap::SecurityMode::NoSecurity;
break;
case QtCoap::SecurityMode::PreSharedKey:
d->dtls = new QDtls(QSslSocket::SslClientMode, this);
@@ -125,8 +127,8 @@ QCoapQUdpConnection::QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject
break;
}
#else
- qCWarning(lcCoapConnection, "DTLS is disabled, falling back to QtCoap::NoSec mode.");
- d->securityMode = QtCoap::SecurityMode::NoSec;
+ qCWarning(lcCoapConnection, "DTLS is disabled, falling back to QtCoap::NoSecurity mode.");
+ d->securityMode = QtCoap::SecurityMode::NoSecurity;
#endif
}
}
@@ -266,6 +268,8 @@ void QCoapQUdpConnection::close()
}
/*!
+ \internal
+
Sets the QUdpSocket socket \a option to \a value.
*/
void QCoapQUdpConnection::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)
@@ -339,6 +343,8 @@ void QCoapQUdpConnectionPrivate::socketReadyRead()
}
/*!
+ \internal
+
Returns the socket.
*/
QUdpSocket *QCoapQUdpConnection::socket() const
@@ -370,7 +376,7 @@ void QCoapQUdpConnectionPrivate::setSecurityConfiguration(
if (!configuration.localCertificateChain().isEmpty())
dtlsConfig.setLocalCertificateChain(configuration.localCertificateChain().toList());
- if (!configuration.privateKey().isEmpty()) {
+ if (!configuration.privateKey().isNull()) {
if (configuration.privateKey().algorithm() != QSsl::Opaque) {
QSslKey privateKey(configuration.privateKey().key(),
configuration.privateKey().algorithm(),
@@ -403,7 +409,7 @@ void QCoapQUdpConnectionPrivate::setSecurityConfiguration(
void QCoapQUdpConnection::pskRequired(QSslPreSharedKeyAuthenticator *authenticator)
{
Q_ASSERT(authenticator);
- authenticator->setIdentity(securityConfiguration().identity());
+ authenticator->setIdentity(securityConfiguration().preSharedKeyIdentity());
authenticator->setPreSharedKey(securityConfiguration().preSharedKey());
}
@@ -468,5 +474,3 @@ void QCoapQUdpConnectionPrivate::handleEncryptedDatagram()
#endif // dtls
QT_END_NAMESPACE
-
-#include "moc_qcoapqudpconnection.cpp"
diff --git a/src/coap/qcoapqudpconnection.h b/src/coap/qcoapqudpconnection.h
deleted file mode 100644
index f9ca356..0000000
--- a/src/coap/qcoapqudpconnection.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Witekio.
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCoap module.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) any later version
-** approved by the KDE Free Qt Foundation. The licenses are as published by
-** the Free Software Foundation and appearing in the file LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCOAPQUDPCONNECTION_H
-#define QCOAPQUDPCONNECTION_H
-
-#include <QtCoap/qcoapconnection.h>
-#include <QtCoap/qcoapnamespace.h>
-#include <QtCoap/qcoapglobal.h>
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qstring.h>
-#include <QtNetwork/qudpsocket.h>
-
-QT_BEGIN_NAMESPACE
-
-class QCoapQUdpConnectionPrivate;
-class QSslPreSharedKeyAuthenticator;
-class Q_COAP_EXPORT QCoapQUdpConnection : public QCoapConnection
-{
- Q_OBJECT
-
-public:
- explicit QCoapQUdpConnection(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSec,
- QObject *parent = nullptr);
-
- ~QCoapQUdpConnection() override = default;
-
- QUdpSocket *socket() const;
-
-public Q_SLOTS:
- void setSocketOption(QAbstractSocket::SocketOption, const QVariant &value);
-
-#if QT_CONFIG(dtls)
-private Q_SLOTS:
- void pskRequired(QSslPreSharedKeyAuthenticator *authenticator);
- void handshakeTimeout();
-#endif
-
-protected:
- explicit QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject *parent = nullptr);
-
- void bind(const QString &host, quint16 port) override;
- void writeData(const QByteArray &data, const QString &host, quint16 port) override;
- void close() override;
-
- void createSocket();
-
- Q_DECLARE_PRIVATE(QCoapQUdpConnection)
-};
-
-QT_END_NAMESPACE
-
-#endif // QCOAPQUDPCONNECTION_H
diff --git a/src/coap/qcoapqudpconnection_p.h b/src/coap/qcoapqudpconnection_p.h
index 3901af8..ba953e4 100644
--- a/src/coap/qcoapqudpconnection_p.h
+++ b/src/coap/qcoapqudpconnection_p.h
@@ -31,7 +31,6 @@
#ifndef QCOAPQUDPCONNECTION_P_H
#define QCOAPQUDPCONNECTION_P_H
-#include <QtCoap/qcoapqudpconnection.h>
#include <QtCoap/qcoapsecurityconfiguration.h>
#include <private/qcoapconnection_p.h>
@@ -53,10 +52,44 @@ QT_BEGIN_NAMESPACE
class QDtls;
class QSslPreSharedKeyAuthenticator;
+class QCoapQUdpConnectionPrivate;
+class Q_AUTOTEST_EXPORT QCoapQUdpConnection : public QCoapConnection
+{
+ Q_OBJECT
+
+public:
+ explicit QCoapQUdpConnection(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSecurity,
+ QObject *parent = nullptr);
+
+ ~QCoapQUdpConnection() override = default;
+
+ QUdpSocket *socket() const;
+
+public Q_SLOTS:
+ void setSocketOption(QAbstractSocket::SocketOption, const QVariant &value);
+
+#if QT_CONFIG(dtls)
+private Q_SLOTS:
+ void pskRequired(QSslPreSharedKeyAuthenticator *authenticator);
+ void handshakeTimeout();
+#endif
+
+protected:
+ explicit QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject *parent = nullptr);
+
+ void bind(const QString &host, quint16 port) override;
+ void writeData(const QByteArray &data, const QString &host, quint16 port) override;
+ void close() override;
+
+ void createSocket();
+
+ Q_DECLARE_PRIVATE(QCoapQUdpConnection)
+};
+
class Q_AUTOTEST_EXPORT QCoapQUdpConnectionPrivate : public QCoapConnectionPrivate
{
public:
- QCoapQUdpConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSec);
+ QCoapQUdpConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSecurity);
~QCoapQUdpConnectionPrivate() override;
virtual bool bind();
diff --git a/src/coap/qcoapreply.cpp b/src/coap/qcoapreply.cpp
index 9122551..2880fd6 100644
--- a/src/coap/qcoapreply.cpp
+++ b/src/coap/qcoapreply.cpp
@@ -30,6 +30,8 @@
#include "qcoapreply_p.h"
#include "qcoapinternalreply_p.h"
+#include "qcoapnamespace_p.h"
+
#include <QtCore/qmath.h>
#include <QtCore/qloggingcategory.h>
@@ -161,7 +163,7 @@ void QCoapReplyPrivate::_q_setError(QtCoap::Error newError)
*/
void QCoapReplyPrivate::_q_setError(QtCoap::ResponseCode code)
{
- _q_setError(QtCoap::responseCodeError(code));
+ _q_setError(QtCoap::errorForResponseCode(code));
}
/*!
@@ -181,7 +183,7 @@ void QCoapReplyPrivate::_q_setError(QtCoap::ResponseCode code)
For \e Observe requests specifically, the notified() signal is emitted
whenever a notification is received.
- \sa QCoapClient, QCoapRequest, QCoapDiscoveryReply
+ \sa QCoapClient, QCoapRequest, QCoapResourceDiscoveryReply
*/
/*!
@@ -241,15 +243,6 @@ void QCoapReplyPrivate::_q_setError(QtCoap::ResponseCode code)
*/
/*!
- Constructs a new CoAP reply for the \a request and sets \a parent as
- its parent.
-*/
-QCoapReply::QCoapReply(const QCoapRequest &request, QObject *parent) :
- QCoapReply(*new QCoapReplyPrivate(request), parent)
-{
-}
-
-/*!
\internal
Constructs a new CoAP reply with \a dd as the d_ptr.
This constructor must be used when subclassing internally
@@ -425,6 +418,16 @@ void QCoapReply::abortRequest()
emit finished(this);
}
+/*!
+ \internal
+
+ Creates a new instance of QCoapReply and returns a pointer to it.
+*/
+QCoapReply *QCoapReplyPrivate::createCoapReply(const QCoapRequest &request, QObject *parent)
+{
+ return new QCoapReply(*new QCoapReplyPrivate(request), parent);
+}
+
QT_END_NAMESPACE
#include "moc_qcoapreply.cpp"
diff --git a/src/coap/qcoapreply.h b/src/coap/qcoapreply.h
index afdd5ea..019fba5 100644
--- a/src/coap/qcoapreply.h
+++ b/src/coap/qcoapreply.h
@@ -45,8 +45,6 @@ class Q_COAP_EXPORT QCoapReply : public QIODevice
{
Q_OBJECT
public:
-
- explicit QCoapReply(const QCoapRequest &request, QObject *parent = nullptr);
~QCoapReply() override;
QtCoap::ResponseCode responseCode() const;
@@ -68,11 +66,6 @@ Q_SIGNALS:
void aborted(const QCoapToken &token);
protected:
- friend class QCoapProtocol;
- friend class QCoapProtocolPrivate;
-
- explicit QCoapReply(QCoapReplyPrivate &dd, QObject *parent = nullptr);
-
qint64 readData(char *data, qint64 maxSize) override;
qint64 writeData(const char *data, qint64 maxSize) override;
@@ -85,6 +78,10 @@ protected:
Q_PRIVATE_SLOT(d_func(), void _q_setFinished(QtCoap::Error))
Q_PRIVATE_SLOT(d_func(), void _q_setError(QtCoap::ResponseCode))
Q_PRIVATE_SLOT(d_func(), void _q_setError(QtCoap::Error))
+
+private:
+ explicit QCoapReply(QCoapReplyPrivate &dd, QObject *parent = nullptr);
+ friend class QCoapResourceDiscoveryReply;
};
QT_END_NAMESPACE
diff --git a/src/coap/qcoapreply_p.h b/src/coap/qcoapreply_p.h
index 68e9062..500c1dd 100644
--- a/src/coap/qcoapreply_p.h
+++ b/src/coap/qcoapreply_p.h
@@ -62,6 +62,8 @@ public:
void _q_setError(QtCoap::ResponseCode code);
void _q_setError(QtCoap::Error);
+ static QCoapReply *createCoapReply(const QCoapRequest &request, QObject *parent = nullptr);
+
QCoapRequest request;
QCoapMessage message;
QtCoap::ResponseCode responseCode = QtCoap::ResponseCode::InvalidCode;
diff --git a/src/coap/qcoaprequest.cpp b/src/coap/qcoaprequest.cpp
index 1d9a441..4a61643 100644
--- a/src/coap/qcoaprequest.cpp
+++ b/src/coap/qcoaprequest.cpp
@@ -44,7 +44,7 @@ const auto CoapScheme = QLatin1String("coap");
const auto CoapSecureScheme = QLatin1String("coaps");
}
-QCoapRequestPrivate::QCoapRequestPrivate(const QUrl &url, QCoapMessage::MessageType type,
+QCoapRequestPrivate::QCoapRequestPrivate(const QUrl &url, QCoapMessage::Type type,
const QUrl &proxyUrl) :
QCoapMessagePrivate(type),
proxyUri(proxyUrl)
@@ -107,14 +107,14 @@ void QCoapRequestPrivate::setUrl(const QUrl &url)
The QCoapRequest contains data needed to make CoAP frames that can be
sent to the URL it holds.
- \sa QCoapClient, QCoapReply, QCoapDiscoveryReply
+ \sa QCoapClient, QCoapReply, QCoapResourceDiscoveryReply
*/
/*!
Constructs a QCoapRequest object with the target \a url,
the proxy URL \a proxyUrl and the \a type of the message.
*/
-QCoapRequest::QCoapRequest(const QUrl &url, MessageType type, const QUrl &proxyUrl) :
+QCoapRequest::QCoapRequest(const QUrl &url, Type type, const QUrl &proxyUrl) :
QCoapMessage(*new QCoapRequestPrivate(url, type, proxyUrl))
{
}
@@ -122,7 +122,7 @@ QCoapRequest::QCoapRequest(const QUrl &url, MessageType type, const QUrl &proxyU
/*!
Constructs a QCoapRequest from a string literal
*/
-QCoapRequest::QCoapRequest(const char *url, MessageType type) :
+QCoapRequest::QCoapRequest(const char *url, Type type) :
QCoapMessage(*new QCoapRequestPrivate(QUrl(QString::fromUtf8(url)), type))
{
}
@@ -138,19 +138,6 @@ QCoapRequest::QCoapRequest(const QCoapRequest &other) :
}
/*!
- \internal
-
- Constructs a copy of the \a other QCoapRequest and sets the request
- method to \a method.
-*/
-QCoapRequest::QCoapRequest(const QCoapRequest &other, QtCoap::Method method) :
- QCoapRequest(other)
-{
- if (method != QtCoap::Method::Invalid)
- setMethod(method);
-}
-
-/*!
Destroys the QCoapRequest.
*/
QCoapRequest::~QCoapRequest()
@@ -225,19 +212,6 @@ void QCoapRequest::setProxyUrl(const QUrl &proxyUrl)
}
/*!
- \internal
-
- Sets the method of the request to the given \a method.
-
- \sa method()
-*/
-void QCoapRequest::setMethod(QtCoap::Method method)
-{
- Q_D(QCoapRequest);
- d->method = method;
-}
-
-/*!
Sets the observe to \c true to make an observe request.
\sa isObserve()
@@ -251,6 +225,8 @@ void QCoapRequest::enableObserve()
}
/*!
+ \internal
+
Adjusts the request URL by setting the correct default scheme and port
(if not indicated) based on the \a secure parameter.
@@ -258,10 +234,9 @@ void QCoapRequest::enableObserve()
its port will default to \e 5683. In secure mode the scheme will default to
\c coaps, and the port will default to \e 5684.
*/
-void QCoapRequest::adjustUrl(bool secure)
+void QCoapRequestPrivate::adjustUrl(bool secure)
{
- Q_D(QCoapRequest);
- d->uri = adjustedUrl(d->uri, secure);
+ uri = adjustedUrl(uri, secure);
}
/*!
@@ -274,17 +249,11 @@ QCoapRequest &QCoapRequest::operator=(const QCoapRequest &other)
}
/*!
- Returns \c true if the request is valid, \c false otherwise.
-*/
-bool QCoapRequest::isValid() const
-{
- return isUrlValid(url()) && method() != QtCoap::Method::Invalid;
-}
+ \internal
-/*!
Returns \c true if the \a url is a valid CoAP URL.
*/
-bool QCoapRequest::isUrlValid(const QUrl &url)
+bool QCoapRequestPrivate::isUrlValid(const QUrl &url)
{
return (url.isValid() && !url.isLocalFile() && !url.isRelative()
&& (url.scheme() == CoapScheme || url.scheme() == CoapSecureScheme)
@@ -292,6 +261,8 @@ bool QCoapRequest::isUrlValid(const QUrl &url)
}
/*!
+ \internal
+
Adjusts the \a url by setting the correct default scheme and port
(if not indicated) based on the \a secure parameter. Returns the
adjusted URL.
@@ -300,7 +271,7 @@ bool QCoapRequest::isUrlValid(const QUrl &url)
its port will default to \e 5683. In secure mode the scheme will default to
\c coaps, and the port will default to \e 5684.
*/
-QUrl QCoapRequest::adjustedUrl(const QUrl &url, bool secure)
+QUrl QCoapRequestPrivate::adjustedUrl(const QUrl &url, bool secure)
{
if (url.isEmpty() || !url.isValid())
return QUrl();
@@ -338,4 +309,19 @@ QCoapRequestPrivate* QCoapRequest::d_func()
return static_cast<QCoapRequestPrivate*>(d_ptr.data());
}
+/*!
+ \internal
+
+ Creates a copy of \a other request and sets \a method as its request method.
+ Adjusts the request URL based on \a isSecure parameter.
+*/
+QCoapRequest
+QCoapRequestPrivate::createRequest(const QCoapRequest &other, QtCoap::Method method, bool isSecure)
+{
+ QCoapRequest request(other);
+ request.d_func()->method = method;
+ request.d_func()->adjustUrl(isSecure);
+ return request;
+}
+
QT_END_NAMESPACE
diff --git a/src/coap/qcoaprequest.h b/src/coap/qcoaprequest.h
index c833334..848d357 100644
--- a/src/coap/qcoaprequest.h
+++ b/src/coap/qcoaprequest.h
@@ -46,10 +46,9 @@ class Q_COAP_EXPORT QCoapRequest : public QCoapMessage
{
public:
explicit QCoapRequest(const QUrl &url = QUrl(),
- MessageType type = MessageType::NonConfirmable,
- const QUrl &proxyUrl = QUrl());
- explicit QCoapRequest(const char* url,
- MessageType type = MessageType::NonConfirmable);
+ Type type = Type::NonConfirmable,
+ const QUrl &proxyUrl = QUrl());
+ explicit QCoapRequest(const char* url, Type type = Type::NonConfirmable);
QCoapRequest(const QCoapRequest &other);
~QCoapRequest();
@@ -62,16 +61,6 @@ public:
void setUrl(const QUrl &url);
void setProxyUrl(const QUrl &proxyUrl);
void enableObserve();
- void adjustUrl(bool secure);
-
- bool isValid() const;
- static bool isUrlValid(const QUrl &url);
- static QUrl adjustedUrl(const QUrl &url, bool secure);
-
-protected:
- QCoapRequest(const QCoapRequest &other, QtCoap::Method method);
-
- void setMethod(QtCoap::Method method);
private:
// Q_DECLARE_PRIVATE equivalent for shared data pointers
@@ -79,7 +68,7 @@ private:
const QCoapRequestPrivate* d_func() const
{ return reinterpret_cast<const QCoapRequestPrivate*>(d_ptr.constData()); }
- friend class QCoapClient;
+ friend class QCoapRequestPrivate;
};
QT_END_NAMESPACE
diff --git a/src/coap/qcoaprequest_p.h b/src/coap/qcoaprequest_p.h
index 67c26c6..20af324 100644
--- a/src/coap/qcoaprequest_p.h
+++ b/src/coap/qcoaprequest_p.h
@@ -52,12 +52,18 @@ class Q_AUTOTEST_EXPORT QCoapRequestPrivate : public QCoapMessagePrivate
{
public:
QCoapRequestPrivate(const QUrl &url = QUrl(),
- QCoapMessage::MessageType type = QCoapMessage::MessageType::NonConfirmable,
- const QUrl &proxyUrl = QUrl());
+ QCoapMessage::Type type = QCoapMessage::Type::NonConfirmable,
+ const QUrl &proxyUrl = QUrl());
QCoapRequestPrivate(const QCoapRequestPrivate &other) = default;
~QCoapRequestPrivate();
void setUrl(const QUrl &url);
+ void adjustUrl(bool secure);
+
+ static QCoapRequest createRequest(const QCoapRequest &other, QtCoap::Method method,
+ bool isSecure = false);
+ static QUrl adjustedUrl(const QUrl &url, bool secure);
+ static bool isUrlValid(const QUrl &url);
QUrl uri;
QUrl proxyUri;
diff --git a/src/coap/qcoapresource.cpp b/src/coap/qcoapresource.cpp
index 7e20209..3e0dc15 100644
--- a/src/coap/qcoapresource.cpp
+++ b/src/coap/qcoapresource.cpp
@@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE
The QCoapRequest contains data as the path and title of the resource
and other ancillary information.
- \sa QCoapDiscoveryReply
+ \sa QCoapResourceDiscoveryReply
*/
/*!
@@ -84,7 +84,7 @@ QCoapResource &QCoapResource::operator=(const QCoapResource &other)
/*!
Swaps this resource with \a other. This operation is very fast and never fails.
*/
-void QCoapResource::swap(QCoapResource &other) Q_DECL_NOTHROW
+void QCoapResource::swap(QCoapResource &other) noexcept
{
d.swap(other.d);
}
diff --git a/src/coap/qcoapresource.h b/src/coap/qcoapresource.h
index 5a97e12..9b1e421 100644
--- a/src/coap/qcoapresource.h
+++ b/src/coap/qcoapresource.h
@@ -47,7 +47,7 @@ public:
~QCoapResource();
QCoapResource &operator =(const QCoapResource &other);
- void swap(QCoapResource &other) Q_DECL_NOTHROW;
+ void swap(QCoapResource &other) noexcept;
QHostAddress host() const;
QString path() const;
diff --git a/src/coap/qcoapdiscoveryreply.cpp b/src/coap/qcoapresourcediscoveryreply.cpp
index def9d19..c709331 100644
--- a/src/coap/qcoapdiscoveryreply.cpp
+++ b/src/coap/qcoapresourcediscoveryreply.cpp
@@ -28,12 +28,13 @@
**
****************************************************************************/
-#include "qcoapdiscoveryreply_p.h"
+#include "qcoapresourcediscoveryreply_p.h"
#include "qcoapinternalreply_p.h"
+#include "qcoapnamespace_p.h"
QT_BEGIN_NAMESPACE
-QCoapDiscoveryReplyPrivate::QCoapDiscoveryReplyPrivate(const QCoapRequest &request) :
+QCoapResourceDiscoveryReplyPrivate::QCoapResourceDiscoveryReplyPrivate(const QCoapRequest &request) :
QCoapReplyPrivate(request)
{
}
@@ -41,13 +42,14 @@ QCoapDiscoveryReplyPrivate::QCoapDiscoveryReplyPrivate(const QCoapRequest &reque
/*!
\internal
- Updates the QCoapDiscoveryReply object, its message and list of resources
+ Updates the QCoapResourceDiscoveryReply object, its message and list of resources
with data of the internal reply \a internalReply.
*/
-void QCoapDiscoveryReplyPrivate::_q_setContent(const QHostAddress &sender, const QCoapMessage &msg,
- QtCoap::ResponseCode code)
+void QCoapResourceDiscoveryReplyPrivate::_q_setContent(const QHostAddress &sender,
+ const QCoapMessage &msg,
+ QtCoap::ResponseCode code)
{
- Q_Q(QCoapDiscoveryReply);
+ Q_Q(QCoapResourceDiscoveryReply);
if (q->isFinished())
return;
@@ -58,17 +60,18 @@ void QCoapDiscoveryReplyPrivate::_q_setContent(const QHostAddress &sender, const
if (QtCoap::isError(responseCode)) {
_q_setError(responseCode);
} else {
- auto res = QCoapDiscoveryReply::resourcesFromCoreLinkList(sender, message.payload());
+ auto res = QCoapResourceDiscoveryReplyPrivate::resourcesFromCoreLinkList(sender,
+ message.payload());
resources.append(res);
emit q->discovered(q, res);
}
}
/*!
- \class QCoapDiscoveryReply
+ \class QCoapResourceDiscoveryReply
\inmodule QtCoap
- \brief The QCoapDiscoveryReply class holds the data of a CoAP reply
+ \brief The QCoapResourceDiscoveryReply class holds the data of a CoAP reply
for a resource discovery request.
\reentrant
@@ -78,14 +81,14 @@ void QCoapDiscoveryReplyPrivate::_q_setContent(const QHostAddress &sender, const
address for discovery, the discovered() signal will be emitted once
for each response received.
- \note A QCoapDiscoveryReply is a QCoapReply that stores also a list
+ \note A QCoapResourceDiscoveryReply is a QCoapReply that stores also a list
of QCoapResources.
\sa QCoapClient, QCoapRequest, QCoapReply, QCoapResource
*/
/*!
- \fn void QCoapDiscoveryReply::discovered(QCoapDiscoveryReply *reply,
+ \fn void QCoapResourceDiscoveryReply::discovered(QCoapResourceDiscoveryReply *reply,
QVector<QCoapResource> resources);
This signal is emitted whenever a CoAP resource is discovered.
@@ -97,30 +100,35 @@ void QCoapDiscoveryReplyPrivate::_q_setContent(const QHostAddress &sender, const
*/
/*!
+ \internal
+
Constructs a new CoAP discovery reply from the \a request and sets \a parent
as its parent.
*/
-QCoapDiscoveryReply::QCoapDiscoveryReply(const QCoapRequest &request, QObject *parent) :
- QCoapReply(*new QCoapDiscoveryReplyPrivate(request), parent)
+QCoapResourceDiscoveryReply::QCoapResourceDiscoveryReply(const QCoapRequest &request, QObject *parent) :
+ QCoapReply(*new QCoapResourceDiscoveryReplyPrivate(request), parent)
{
}
/*!
Returns the list of resources.
*/
-QVector<QCoapResource> QCoapDiscoveryReply::resources() const
+QVector<QCoapResource> QCoapResourceDiscoveryReply::resources() const
{
- Q_D(const QCoapDiscoveryReply);
+ Q_D(const QCoapResourceDiscoveryReply);
return d->resources;
}
/*!
+ \internal
+
Decodes the \a data received from the \a sender to a list of QCoapResource
objects. The \a data byte array contains the frame returned by the
discovery request.
*/
QVector<QCoapResource>
-QCoapDiscoveryReply::resourcesFromCoreLinkList(const QHostAddress &sender, const QByteArray &data)
+QCoapResourceDiscoveryReplyPrivate::resourcesFromCoreLinkList(const QHostAddress &sender,
+ const QByteArray &data)
{
QVector<QCoapResource> resourceList;
diff --git a/src/coap/qcoapdiscoveryreply.h b/src/coap/qcoapresourcediscoveryreply.h
index 0a09ccf..bd575e0 100644
--- a/src/coap/qcoapdiscoveryreply.h
+++ b/src/coap/qcoapresourcediscoveryreply.h
@@ -28,36 +28,33 @@
**
****************************************************************************/
-#ifndef QCOAPDISCOVERYREPLY_H
-#define QCOAPDISCOVERYREPLY_H
+#ifndef QCOAPRESOURCEDISCOVERYREPLY_H
+#define QCOAPRESOURCEDISCOVERYREPLY_H
#include <QtCoap/qcoapreply.h>
#include <QtCoap/qcoapresource.h>
-#include <QtCoap/qcoapprotocol.h>
#include <QtCore/qlist.h>
QT_BEGIN_NAMESPACE
-class QCoapDiscoveryReplyPrivate;
-class Q_COAP_EXPORT QCoapDiscoveryReply : public QCoapReply
+class QCoapResourceDiscoveryReplyPrivate;
+class Q_COAP_EXPORT QCoapResourceDiscoveryReply : public QCoapReply
{
Q_OBJECT
public:
- explicit QCoapDiscoveryReply(const QCoapRequest &request, QObject *parent = nullptr);
-
QVector<QCoapResource> resources() const;
- static QVector<QCoapResource> resourcesFromCoreLinkList(
- const QHostAddress &sender, const QByteArray &data);
-
Q_SIGNALS:
- void discovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> resources);
+ void discovered(QCoapResourceDiscoveryReply *reply, QVector<QCoapResource> resources);
private:
- Q_DECLARE_PRIVATE(QCoapDiscoveryReply)
+ explicit QCoapResourceDiscoveryReply(const QCoapRequest &request, QObject *parent = nullptr);
+ friend class QCoapClientPrivate;
+
+ Q_DECLARE_PRIVATE(QCoapResourceDiscoveryReply)
};
QT_END_NAMESPACE
-#endif // QCOAPDISCOVERYREPLY_H
+#endif // QCOAPRESOURCEDISCOVERYREPLY_H
diff --git a/src/coap/qcoapdiscoveryreply_p.h b/src/coap/qcoapresourcediscoveryreply_p.h
index 5f4856e..d074dbf 100644
--- a/src/coap/qcoapdiscoveryreply_p.h
+++ b/src/coap/qcoapresourcediscoveryreply_p.h
@@ -28,11 +28,11 @@
**
****************************************************************************/
-#ifndef QCOAPDISCOVERYREPLY_P_H
-#define QCOAPDISCOVERYREPLY_P_H
+#ifndef QCOAPRESOURCEDISCOVERYREPLY_P_H
+#define QCOAPRESOURCEDISCOVERYREPLY_P_H
#include <QtCore/qlist.h>
-#include <QtCoap/qcoapdiscoveryreply.h>
+#include <QtCoap/qcoapresourcediscoveryreply.h>
#include <QtCoap/qcoapresource.h>
#include <private/qcoapreply_p.h>
@@ -49,18 +49,21 @@
QT_BEGIN_NAMESPACE
-class Q_AUTOTEST_EXPORT QCoapDiscoveryReplyPrivate : public QCoapReplyPrivate
+class Q_AUTOTEST_EXPORT QCoapResourceDiscoveryReplyPrivate : public QCoapReplyPrivate
{
public:
- QCoapDiscoveryReplyPrivate(const QCoapRequest &request);
+ QCoapResourceDiscoveryReplyPrivate(const QCoapRequest &request);
void _q_setContent(const QHostAddress &sender, const QCoapMessage &, QtCoap::ResponseCode) override;
+ static QVector<QCoapResource> resourcesFromCoreLinkList(
+ const QHostAddress &sender, const QByteArray &data);
+
QVector<QCoapResource> resources;
- Q_DECLARE_PUBLIC(QCoapDiscoveryReply)
+ Q_DECLARE_PUBLIC(QCoapResourceDiscoveryReply)
};
QT_END_NAMESPACE
-#endif // QCOAPDISCOVERYREPLY_P_H
+#endif // QCOAPRESOURCEDISCOVERYREPLY_P_H
diff --git a/src/coap/qcoapsecurityconfiguration.cpp b/src/coap/qcoapsecurityconfiguration.cpp
index 02b4022..c9dba57 100644
--- a/src/coap/qcoapsecurityconfiguration.cpp
+++ b/src/coap/qcoapsecurityconfiguration.cpp
@@ -123,7 +123,7 @@ QCoapPrivateKey::QCoapPrivateKey(const QCoapPrivateKey &other)
Move-constructs a QCoapPrivateKey, making it point to the same
object as \a other was pointing to.
*/
-QCoapPrivateKey::QCoapPrivateKey(QCoapPrivateKey &&other) Q_DECL_NOTHROW
+QCoapPrivateKey::QCoapPrivateKey(QCoapPrivateKey &&other) noexcept
: d(other.d)
{
other.d = nullptr;
@@ -149,9 +149,9 @@ QCoapPrivateKey &QCoapPrivateKey::operator=(const QCoapPrivateKey &other)
}
/*!
- Returns \c true if the private key is empty, returns \c false otherwise.
+ Returns \c true if the private key is null, returns \c false otherwise.
*/
-bool QCoapPrivateKey::isEmpty() const
+bool QCoapPrivateKey::isNull() const
{
return d->algorithm == QSsl::Opaque ? !d->opaqueKey : d->key.isEmpty();
}
@@ -236,7 +236,7 @@ QCoapSecurityConfiguration::QCoapSecurityConfiguration(const QCoapSecurityConfig
object as \a other was pointing to.
*/
QCoapSecurityConfiguration::QCoapSecurityConfiguration(
- QCoapSecurityConfiguration &&other) Q_DECL_NOTHROW
+ QCoapSecurityConfiguration &&other) noexcept
: d(other.d)
{
other.d = nullptr;
@@ -262,9 +262,9 @@ QCoapSecurityConfiguration::~QCoapSecurityConfiguration()
/*!
Sets the PSK client identity (to be advised to the server) to \a identity.
- \sa identity()
+ \sa preSharedKeyIdentity()
*/
-void QCoapSecurityConfiguration::setIdentity(const QByteArray &identity)
+void QCoapSecurityConfiguration::setPreSharedKeyIdentity(const QByteArray &identity)
{
d->identity = identity;
}
@@ -272,9 +272,9 @@ void QCoapSecurityConfiguration::setIdentity(const QByteArray &identity)
/*!
Returns the PSK client identity.
- \sa setIdentity()
+ \sa setPreSharedKeyIdentity()
*/
-QByteArray QCoapSecurityConfiguration::identity() const
+QByteArray QCoapSecurityConfiguration::preSharedKeyIdentity() const
{
return d->identity;
}
diff --git a/src/coap/qcoapsecurityconfiguration.h b/src/coap/qcoapsecurityconfiguration.h
index 7dc00bf..f935b5e 100644
--- a/src/coap/qcoapsecurityconfiguration.h
+++ b/src/coap/qcoapsecurityconfiguration.h
@@ -49,17 +49,17 @@ public:
QCoapPrivateKey(const Qt::HANDLE &handle);
QCoapPrivateKey(const QCoapPrivateKey& other);
- QCoapPrivateKey(QCoapPrivateKey&& other) Q_DECL_NOTHROW;
+ QCoapPrivateKey(QCoapPrivateKey&& other) noexcept;
~QCoapPrivateKey();
- QCoapPrivateKey &operator=(QCoapPrivateKey &&other) Q_DECL_NOTHROW
+ QCoapPrivateKey &operator=(QCoapPrivateKey &&other) noexcept
{ swap(other); return *this; }
QCoapPrivateKey &operator=(const QCoapPrivateKey &other);
- void swap(QCoapPrivateKey &other) Q_DECL_NOTHROW
+ void swap(QCoapPrivateKey &other) noexcept
{ qSwap(d, other.d); }
- bool isEmpty() const;
+ bool isNull() const;
QByteArray key() const;
Qt::HANDLE handle() const;
@@ -78,16 +78,16 @@ public:
QCoapSecurityConfiguration(const QCoapSecurityConfiguration &other);
~QCoapSecurityConfiguration();
- QCoapSecurityConfiguration(QCoapSecurityConfiguration &&other) Q_DECL_NOTHROW;
- QCoapSecurityConfiguration &operator=(QCoapSecurityConfiguration &&other) Q_DECL_NOTHROW
+ QCoapSecurityConfiguration(QCoapSecurityConfiguration &&other) noexcept;
+ QCoapSecurityConfiguration &operator=(QCoapSecurityConfiguration &&other) noexcept
{ swap(other); return *this; }
QCoapSecurityConfiguration &operator=(const QCoapSecurityConfiguration &other);
- void swap(QCoapSecurityConfiguration &other) Q_DECL_NOTHROW
+ void swap(QCoapSecurityConfiguration &other) noexcept
{ qSwap(d, other.d); }
- void setIdentity(const QByteArray &identity);
- QByteArray identity() const;
+ void setPreSharedKeyIdentity(const QByteArray &preSharedKeyIdentity);
+ QByteArray preSharedKeyIdentity() const;
void setPreSharedKey(const QByteArray &preSharedKey);
QByteArray preSharedKey() const;