aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-05-18 03:05:08 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-05-18 03:05:08 +0200
commit02d7238391ae0addc6517759b10d01948b108cb3 (patch)
treeb0c4d0497d73e1edde92c3eb4f1a72b726c39396
parentbad7ee3d4f329ad258b4ceacdb3818084208cf5f (diff)
parentfd94d8e5673a5d5228aa2d38b605fde7a881332b (diff)
Merge remote-tracking branch 'origin/5.13' into dev
-rw-r--r--README.md4
-rw-r--r--examples/coap/consolecoapclient/coaphandler.cpp8
-rw-r--r--examples/coap/consolecoapclient/coaphandler.h4
-rw-r--r--examples/coap/doc/simplecoapclient.qdoc4
-rw-r--r--examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp14
-rw-r--r--examples/coap/quickmulticastclient/qmlcoapmulticastclient.h2
-rw-r--r--examples/coap/quicksecureclient/qmlcoapsecureclient.cpp4
-rw-r--r--examples/coap/simplecoapclient/mainwindow.cpp14
-rw-r--r--examples/coap/simplecoapclient/mainwindow.h2
-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
-rw-r--r--tests/auto/auto.pro13
-rw-r--r--tests/auto/qcoapclient/tst_qcoapclient.cpp109
-rw-r--r--tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp91
-rw-r--r--tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp80
-rw-r--r--tests/auto/qcoapmessage/tst_qcoapmessage.cpp48
-rw-r--r--tests/auto/qcoapoption/tst_qcoapoption.cpp21
-rw-r--r--tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp26
-rw-r--r--tests/auto/qcoapreply/tst_qcoapreply.cpp74
-rw-r--r--tests/auto/qcoaprequest/tst_qcoaprequest.cpp26
-rw-r--r--tests/auto/qcoapresource/qcoapresource.pro2
-rw-r--r--tests/auto/qcoapresource/tst_qcoapresource.cpp10
60 files changed, 881 insertions, 992 deletions
diff --git a/README.md b/README.md
index 3d98801..c14ee3e 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,7 @@ The notified signal will provide the `QCoapReply` and most recent message.
For machine to machine communication, CoAP Discovery requests is used to query the resources
available to an endpoint, or to the complete network.
```c++
-QCoapDiscoveryReply* reply = client->discover("coap://coap.me/");
+QCoapResourceDiscoveryReply *reply = client->discover("coap://coap.me/");
connect(reply, &QCoapReply::discovered, this, &MyClass::onDiscovered);
```
@@ -63,7 +63,7 @@ For multicast discovery use one of the groups from the `QtCoap::MulticastGroup`
specifying the discovery path:
```c++
-QCoapDiscoveryReply* reply = client->discover(QtCoap::AllCoapNodesIPv6LinkLocal);
+QCoapResourceDiscoveryReply *reply = client->discover(QtCoap::AllCoapNodesIPv6LinkLocal);
```
If no group is specified, `QtCoap::AllCoapNodesIPv4` will be used by default.
diff --git a/examples/coap/consolecoapclient/coaphandler.cpp b/examples/coap/consolecoapclient/coaphandler.cpp
index 650cf5c..fa9fc34 100644
--- a/examples/coap/consolecoapclient/coaphandler.cpp
+++ b/examples/coap/consolecoapclient/coaphandler.cpp
@@ -34,7 +34,7 @@
#include <QLoggingCategory>
#include <QCoapClient>
#include <QCoapReply>
-#include <QCoapDiscoveryReply>
+#include <QCoapResourceDiscoveryReply>
Q_LOGGING_CATEGORY(lcCoapClient, "qt.coap.client")
@@ -78,11 +78,11 @@ bool CoapHandler::runObserve(const QUrl &url)
bool CoapHandler::runDiscover(const QUrl &url)
{
- QCoapDiscoveryReply *discoverReply = m_coapClient.discover(url);
+ QCoapResourceDiscoveryReply *discoverReply = m_coapClient.discover(url);
if (!discoverReply)
return false;
- connect(discoverReply, &QCoapDiscoveryReply::discovered, this, &CoapHandler::onDiscovered);
+ connect(discoverReply, &QCoapResourceDiscoveryReply::discovered, this, &CoapHandler::onDiscovered);
return true;
}
@@ -105,7 +105,7 @@ void CoapHandler::onNotified(QCoapReply *reply, QCoapMessage message)
qCInfo(lcCoapClient) << "Received Observe notification with payload:" << reply->readAll();
}
-void CoapHandler::onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> resources)
+void CoapHandler::onDiscovered(QCoapResourceDiscoveryReply *reply, QVector<QCoapResource> resources)
{
Q_UNUSED(reply)
diff --git a/examples/coap/consolecoapclient/coaphandler.h b/examples/coap/consolecoapclient/coaphandler.h
index 1034ad1..a109a4c 100644
--- a/examples/coap/consolecoapclient/coaphandler.h
+++ b/examples/coap/consolecoapclient/coaphandler.h
@@ -40,7 +40,7 @@
QT_BEGIN_NAMESPACE
class QCoapReply;
-class QCoapDiscoveryReply;
+class QCoapResourceDiscoveryReply;
class QCoapResource;
QT_END_NAMESPACE
@@ -61,7 +61,7 @@ public:
public Q_SLOTS:
void onFinished(QCoapReply *reply);
void onNotified(QCoapReply *reply, QCoapMessage message);
- void onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> resources);
+ void onDiscovered(QCoapResourceDiscoveryReply *reply, QVector<QCoapResource> resources);
void onResponseToMulticast(QCoapReply *reply, const QCoapMessage& message,
const QHostAddress &sender);
void onError(QCoapReply *reply, QtCoap::Error error);
diff --git a/examples/coap/doc/simplecoapclient.qdoc b/examples/coap/doc/simplecoapclient.qdoc
index 961d473..438442d 100644
--- a/examples/coap/doc/simplecoapclient.qdoc
+++ b/examples/coap/doc/simplecoapclient.qdoc
@@ -134,8 +134,8 @@
\printuntil onDiscovered
\dots
- \note Instead of QCoapReply class, we use the QCoapDiscoveryReply to keep
- the reply for a discovery request. It has the QCoapDiscoveryReply::discovered
+ \note Instead of QCoapReply class, we use the QCoapResourceDiscoveryReply to keep
+ the reply for a discovery request. It has the QCoapResourceDiscoveryReply::discovered
signal, which returns the list of QCoapResources that has been discovered.
If there are \e observable resources on the server (meaning that they have the
diff --git a/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp b/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp
index 4c3592b..7c868eb 100644
--- a/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp
+++ b/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp
@@ -50,13 +50,13 @@
#include "qmlcoapmulticastclient.h"
-#include <QCoapDiscoveryReply>
+#include <QCoapResourceDiscoveryReply>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(lcCoapClient, "qt.coap.client")
QmlCoapMulticastClient::QmlCoapMulticastClient(QObject *parent)
- : QCoapClient(QtCoap::SecurityMode::NoSec, parent)
+ : QCoapClient(QtCoap::SecurityMode::NoSecurity, parent)
{
connect(this, &QCoapClient::finished, this,
[this](QCoapReply *reply) {
@@ -73,9 +73,9 @@ void QmlCoapMulticastClient::discover(const QString &host, int port, const QStri
url.setHost(host);
url.setPort(port);
- QCoapDiscoveryReply *discoverReply = QCoapClient::discover(url, discoveryPath);
+ QCoapResourceDiscoveryReply *discoverReply = QCoapClient::discover(url, discoveryPath);
if (discoverReply) {
- connect(discoverReply, &QCoapDiscoveryReply::discovered,
+ connect(discoverReply, &QCoapResourceDiscoveryReply::discovered,
this, &QmlCoapMulticastClient::onDiscovered);
} else {
qCWarning(lcCoapClient, "Discovery request failed.");
@@ -85,16 +85,16 @@ void QmlCoapMulticastClient::discover(const QString &host, int port, const QStri
void QmlCoapMulticastClient::discover(QtCoap::MulticastGroup group, int port,
const QString &discoveryPath)
{
- QCoapDiscoveryReply *discoverReply = QCoapClient::discover(group, port, discoveryPath);
+ QCoapResourceDiscoveryReply *discoverReply = QCoapClient::discover(group, port, discoveryPath);
if (discoverReply) {
- connect(discoverReply, &QCoapDiscoveryReply::discovered,
+ connect(discoverReply, &QCoapResourceDiscoveryReply::discovered,
this, &QmlCoapMulticastClient::onDiscovered);
} else {
qCWarning(lcCoapClient, "Discovery request failed.");
}
}
-void QmlCoapMulticastClient::onDiscovered(QCoapDiscoveryReply *reply,
+void QmlCoapMulticastClient::onDiscovered(QCoapResourceDiscoveryReply *reply,
const QVector<QCoapResource> &resources)
{
Q_UNUSED(reply)
diff --git a/examples/coap/quickmulticastclient/qmlcoapmulticastclient.h b/examples/coap/quickmulticastclient/qmlcoapmulticastclient.h
index 3dd91fc..7770ade 100644
--- a/examples/coap/quickmulticastclient/qmlcoapmulticastclient.h
+++ b/examples/coap/quickmulticastclient/qmlcoapmulticastclient.h
@@ -85,7 +85,7 @@ Q_SIGNALS:
void finished(QtCoap::Error error);
public slots:
- void onDiscovered(QCoapDiscoveryReply *reply, const QVector<QCoapResource> &resources);
+ void onDiscovered(QCoapResourceDiscoveryReply *reply, const QVector<QCoapResource> &resources);
};
#endif // QMLCOAPMULTICASTCLIENT_H
diff --git a/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp b/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp
index 608ed0c..dd40f4e 100644
--- a/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp
+++ b/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp
@@ -61,7 +61,7 @@ Q_LOGGING_CATEGORY(lcCoapClient, "qt.coap.client")
QmlCoapSecureClient::QmlCoapSecureClient(QObject *parent)
: QObject(parent)
, m_coapClient(nullptr)
- , m_securityMode(QtCoap::SecurityMode::NoSec)
+ , m_securityMode(QtCoap::SecurityMode::NoSecurity)
{
}
@@ -127,7 +127,7 @@ QmlCoapSecureClient::setSecurityConfiguration(const QString &preSharedKey, const
{
QCoapSecurityConfiguration configuration;
configuration.setPreSharedKey(preSharedKey.toUtf8());
- configuration.setIdentity(identity.toUtf8());
+ configuration.setPreSharedKeyIdentity(identity.toUtf8());
m_configuration = configuration;
}
diff --git a/examples/coap/simplecoapclient/mainwindow.cpp b/examples/coap/simplecoapclient/mainwindow.cpp
index e5cda55..19f907a 100644
--- a/examples/coap/simplecoapclient/mainwindow.cpp
+++ b/examples/coap/simplecoapclient/mainwindow.cpp
@@ -52,7 +52,7 @@
#include "optiondialog.h"
#include "ui_mainwindow.h"
-#include <QCoapDiscoveryReply>
+#include <QCoapResourceDiscoveryReply>
#include <QCoapReply>
#include <QDateTime>
#include <QFileDialog>
@@ -65,7 +65,7 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
- m_client = new QCoapClient(QtCoap::SecurityMode::NoSec, this);
+ m_client = new QCoapClient(QtCoap::SecurityMode::NoSecurity, this);
connect(m_client, &QCoapClient::finished, this, &MainWindow::onFinished);
connect(m_client, &QCoapClient::error, this, &MainWindow::onError);
@@ -122,7 +122,7 @@ void MainWindow::onError(QCoapReply *reply, QtCoap::Error error)
addMessage(errorMessage(errorCode), true);
}
-void MainWindow::onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> resources)
+void MainWindow::onDiscovered(QCoapResourceDiscoveryReply *reply, QVector<QCoapResource> resources)
{
if (reply->errorReceived() != QtCoap::Error::Ok)
return;
@@ -154,8 +154,8 @@ static QString tryToResolveHostName(const QString hostName)
void MainWindow::on_runButton_clicked()
{
- const auto msgType = ui->msgTypeCheckBox->isChecked() ? QCoapMessage::MessageType::Confirmable
- : QCoapMessage::MessageType::NonConfirmable;
+ const auto msgType = ui->msgTypeCheckBox->isChecked() ? QCoapMessage::Type::Confirmable
+ : QCoapMessage::Type::NonConfirmable;
QUrl url;
url.setHost(tryToResolveHostName(ui->hostComboBox->currentText()));
url.setPort(ui->portSpinBox->value());
@@ -192,9 +192,9 @@ void MainWindow::on_discoverButton_clicked()
url.setHost(tryToResolveHostName(ui->hostComboBox->currentText()));
url.setPort(ui->portSpinBox->value());
- QCoapDiscoveryReply *discoverReply = m_client->discover(url, ui->discoveryPathEdit->text());
+ QCoapResourceDiscoveryReply *discoverReply = m_client->discover(url, ui->discoveryPathEdit->text());
if (discoverReply)
- connect(discoverReply, &QCoapDiscoveryReply::discovered, this, &MainWindow::onDiscovered);
+ connect(discoverReply, &QCoapResourceDiscoveryReply::discovered, this, &MainWindow::onDiscovered);
else
QMessageBox::critical(this, "Error", "Something went wrong, discovery request failed.");
}
diff --git a/examples/coap/simplecoapclient/mainwindow.h b/examples/coap/simplecoapclient/mainwindow.h
index a561c0e..2cb9f98 100644
--- a/examples/coap/simplecoapclient/mainwindow.h
+++ b/examples/coap/simplecoapclient/mainwindow.h
@@ -78,7 +78,7 @@ private:
private slots:
void onFinished(QCoapReply *reply);
void onError(QCoapReply *reply, QtCoap::Error error);
- void onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> resources);
+ void onDiscovered(QCoapResourceDiscoveryReply *reply, QVector<QCoapResource> resources);
void onNotified(QCoapReply *reply, const QCoapMessage &message);
void on_runButton_clicked();
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;
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 82c8af8..5bfc66e 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,14 +1,17 @@
TEMPLATE = subdirs
+# TODO: enable disabled tests, when CI is configured properly
+
SUBDIRS += \
cmake \
-# TODO: enable the tests below, when CI is configured properly
# qcoapclient \
-# qcoapqudpconnection \
- qcoapinternalreply \
- qcoapinternalrequest \
qcoapmessage \
qcoapoption \
- qcoapreply \
qcoaprequest \
qcoapresource
+
+qtConfig(private_tests): SUBDIRS += \
+# qcoapqudpconnection \
+ qcoapinternalrequest \
+ qcoapinternalreply \
+ qcoapreply
diff --git a/tests/auto/qcoapclient/tst_qcoapclient.cpp b/tests/auto/qcoapclient/tst_qcoapclient.cpp
index 3e5eac0..6f66346 100644
--- a/tests/auto/qcoapclient/tst_qcoapclient.cpp
+++ b/tests/auto/qcoapclient/tst_qcoapclient.cpp
@@ -34,11 +34,13 @@
#include <QtCoap/qcoapclient.h>
#include <QtCoap/qcoaprequest.h>
#include <QtCoap/qcoapreply.h>
-#include <QtCoap/qcoapdiscoveryreply.h>
+#include <QtCoap/qcoapresourcediscoveryreply.h>
#include <QtCore/qbuffer.h>
#include <QtNetwork/qnetworkdatagram.h>
#include <private/qcoapclient_p.h>
#include <private/qcoapqudpconnection_p.h>
+#include <private/qcoapprotocol_p.h>
+#include <private/qcoaprequest_p.h>
#include "../coapnetworksettings.h"
@@ -77,6 +79,8 @@ private Q_SLOTS:
void multicast_blockwise();
};
+#ifdef QT_BUILD_INTERNAL
+
class QCoapQUdpConnectionSocketTestsPrivate : public QCoapQUdpConnectionPrivate
{
bool bind() override
@@ -105,7 +109,7 @@ class QCoapClientForSocketErrorTests : public QCoapClient
{
public:
QCoapClientForSocketErrorTests() :
- QCoapClient(new QCoapProtocol, new QCoapQUdpConnectionSocketTests)
+ QCoapClient(new QCoapQUdpConnectionSocketTests)
{}
QCoapQUdpConnection *connection()
@@ -119,9 +123,6 @@ class QCoapClientForTests : public QCoapClient
{
public:
QCoapClientForTests() {}
- QCoapClientForTests(QCoapProtocol *protocol, QCoapQUdpConnection *connection) :
- QCoapClient(protocol, connection)
- {}
QCoapProtocol *protocol()
{
@@ -162,7 +163,7 @@ class QCoapClientForMulticastTests : public QCoapClient
{
public:
QCoapClientForMulticastTests() :
- QCoapClient(new QCoapProtocol, new QCoapConnectionMulticastTests)
+ QCoapClient(new QCoapConnectionMulticastTests)
{}
QCoapConnection *connection()
@@ -172,6 +173,7 @@ public:
}
};
+#endif
class Helper : public QObject
{
@@ -272,7 +274,9 @@ void tst_QCoapClient::methods()
}
QVERIFY2(!reply.isNull(), "Request failed unexpectedly");
- QCOMPARE(reply->url(), QCoapRequest::adjustedUrl(url, false));
+#ifdef QT_BUILD_INTERNAL
+ QCOMPARE(reply->url(), QCoapRequestPrivate::adjustedUrl(url, false));
+#endif
QSignalSpy spyReplyFinished(reply.data(), SIGNAL(finished(QCoapReply *)));
QTRY_COMPARE(spyReplyFinished.count(), 1);
QTRY_COMPARE(spyClientFinished.count(), 1);
@@ -347,6 +351,7 @@ void tst_QCoapClient::setBlockSize_data()
void tst_QCoapClient::setBlockSize()
{
+#ifdef QT_BUILD_INTERNAL
QFETCH(int, blockSizeSet);
QFETCH(int, blockSizeExpected);
@@ -358,6 +363,9 @@ void tst_QCoapClient::setBlockSize()
eventLoop.exec();
QCOMPARE(client.protocol()->blockSize(), blockSizeExpected);
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
void tst_QCoapClient::requestWithQIODevice_data()
@@ -470,7 +478,7 @@ void tst_QCoapClient::socketError()
void tst_QCoapClient::timeout_data()
{
QTest::addColumn<int>("timeout");
- QTest::addColumn<int>("maxRetransmit");
+ QTest::addColumn<int>("maximumRetransmitCount");
QTest::newRow("2000/0") << 2000 << 0;
QTest::newRow("2000/2") << 2000 << 2;
@@ -479,40 +487,41 @@ void tst_QCoapClient::timeout_data()
void tst_QCoapClient::timeout()
{
+#ifdef QT_BUILD_INTERNAL
QFETCH(int, timeout);
- QFETCH(int, maxRetransmit);
+ QFETCH(int, maximumRetransmitCount);
QCoapClientForTests client;
// Trigger a network timeout
client.protocol()->setAckTimeout(timeout);
client.protocol()->setAckRandomFactor(1);
- client.protocol()->setMaxRetransmit(maxRetransmit);
+ client.protocol()->setMaximumRetransmitCount(maximumRetransmitCount);
QUrl url = QUrl("coap://192.0.2.0:5683/"); // Need an url that returns nothing
QElapsedTimer timeoutTimer;
timeoutTimer.start();
QScopedPointer<QCoapReply> reply(
- client.get(QCoapRequest(url, QCoapMessage::MessageType::Confirmable)));
+ client.get(QCoapRequest(url, QCoapMessage::Type::Confirmable)));
QSignalSpy spyClientError(&client, &QCoapClient::error);
QSignalSpy spyReplyError(reply.data(), &QCoapReply::error);
QSignalSpy spyReplyAborted(reply.data(), &QCoapReply::aborted);
QSignalSpy spyReplyFinished(reply.data(), &QCoapReply::finished);
// Check timeout upper limit
- int transmissions = maxRetransmit + 1;
+ int transmissions = maximumRetransmitCount + 1;
// 10% Precision expected at least, plus timer precision
QTRY_COMPARE_WITH_TIMEOUT(spyReplyError.count(), 1, static_cast<int>(
- 1.1 * client.protocol()->maxTransmitWait() + 20 * transmissions));
+ 1.1 * client.protocol()->maximumTransmitWait() + 20 * transmissions));
// Check timeout lower limit
qint64 elapsedTime = timeoutTimer.elapsed();
QString errorMessage = QString("Timeout was triggered after %1ms, while expecting about %2ms")
.arg(QString::number(elapsedTime),
- QString::number(client.protocol()->maxTransmitWait()));
+ QString::number(client.protocol()->maximumTransmitWait()));
// 10% Precision expected at least, minus timer precision
- QVERIFY2(elapsedTime > 0.9 * client.protocol()->maxTransmitWait() - 20 * transmissions,
+ QVERIFY2(elapsedTime > 0.9 * client.protocol()->maximumTransmitWait() - 20 * transmissions,
qPrintable(errorMessage));
QCOMPARE(qvariant_cast<QtCoap::Error>(spyReplyError.first().at(1)),
@@ -520,6 +529,9 @@ void tst_QCoapClient::timeout()
QCOMPARE(spyReplyFinished.count(), 1);
QCOMPARE(spyReplyAborted.count(), 0);
QCOMPARE(spyClientError.count(), 1);
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
void tst_QCoapClient::abort()
@@ -546,7 +558,7 @@ void tst_QCoapClient::abort()
void tst_QCoapClient::blockwiseReply_data()
{
QTest::addColumn<QUrl>("url");
- QTest::addColumn<QCoapMessage::MessageType>("type");
+ QTest::addColumn<QCoapMessage::Type>("type");
QTest::addColumn<QByteArray>("replyData");
QByteArray data;
@@ -573,34 +585,34 @@ void tst_QCoapClient::blockwiseReply_data()
QTest::newRow("get_large")
<< QUrl(testServerUrl() + "/large")
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< data;
QTest::newRow("get_large_separate")
<< QUrl(testServerUrl() + "/large-separate")
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< data;
QTest::newRow("get_large_confirmable")
<< QUrl(testServerUrl() + "/large")
- << QCoapMessage::MessageType::Confirmable
+ << QCoapMessage::Type::Confirmable
<< data;
QTest::newRow("get_large_separate_confirmable")
<< QUrl(testServerUrl() + "/large-separate")
- << QCoapMessage::MessageType::Confirmable
+ << QCoapMessage::Type::Confirmable
<< data;
QTest::newRow("get_large_16bits")
<< QUrl(testServerUrl() + "/large")
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< data;
QTest::newRow("get_large_16bits_confirmable")
<< QUrl(testServerUrl() + "/large")
- << QCoapMessage::MessageType::Confirmable
+ << QCoapMessage::Type::Confirmable
<< data;
}
void tst_QCoapClient::blockwiseReply()
{
QFETCH(QUrl, url);
- QFETCH(QCoapMessage::MessageType, type);
+ QFETCH(QCoapMessage::Type, type);
QFETCH(QByteArray, replyData);
QCoapClient client;
@@ -624,7 +636,7 @@ void tst_QCoapClient::blockwiseReply()
void tst_QCoapClient::blockwiseRequest_data()
{
QTest::addColumn<QUrl>("url");
- QTest::addColumn<QCoapMessage::MessageType>("type");
+ QTest::addColumn<QCoapMessage::Type>("type");
QTest::addColumn<QByteArray>("requestData");
QTest::addColumn<QtCoap::ResponseCode>("responseCode");
QTest::addColumn<QByteArray>("replyData");
@@ -635,12 +647,12 @@ void tst_QCoapClient::blockwiseRequest_data()
data.append(alphabet);
QTest::newRow("large_post_empty_reply") << QUrl(testServerUrl() + "/query")
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< data
<< QtCoap::ResponseCode::MethodNotAllowed
<< QByteArray();
QTest::newRow("large_post_large_reply") << QUrl(testServerUrl() + "/large-post")
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< data
<< QtCoap::ResponseCode::Changed
<< data.toUpper();
@@ -649,7 +661,7 @@ void tst_QCoapClient::blockwiseRequest_data()
void tst_QCoapClient::blockwiseRequest()
{
QFETCH(QUrl, url);
- QFETCH(QCoapMessage::MessageType, type);
+ QFETCH(QCoapMessage::Type, type);
QFETCH(QByteArray, requestData);
QFETCH(QtCoap::ResponseCode, responseCode);
QFETCH(QByteArray, replyData);
@@ -690,13 +702,15 @@ void tst_QCoapClient::discover()
QCoapClient client;
- QScopedPointer<QCoapDiscoveryReply> resourcesReply(client.discover(url)); // /.well-known/core
+ QScopedPointer<QCoapResourceDiscoveryReply> resourcesReply(client.discover(url)); // /.well-known/core
QSignalSpy spyReplyFinished(resourcesReply.data(), SIGNAL(finished(QCoapReply *)));
QTRY_COMPARE_WITH_TIMEOUT(spyReplyFinished.count(), 1, 30000);
const auto discoverUrl = QUrl(url.toString() + "/.well-known/core");
- QCOMPARE(resourcesReply->url(), QCoapRequest::adjustedUrl(discoverUrl, false));
+#ifdef QT_BUILD_INTERNAL
+ QCOMPARE(resourcesReply->url(), QCoapRequestPrivate::adjustedUrl(discoverUrl, false));
+#endif
QCOMPARE(resourcesReply->resources().length(), resourceNumber);
QCOMPARE(resourcesReply->request().method(), QtCoap::Method::Get);
@@ -707,49 +721,49 @@ void tst_QCoapClient::observe_data()
{
QWARN("Observe tests may take some time, don't forget to raise Tests timeout in settings.");
QTest::addColumn<QUrl>("url");
- QTest::addColumn<QCoapMessage::MessageType>("type");
+ QTest::addColumn<QCoapMessage::Type>("type");
QTest::newRow("observe")
<< QUrl(testServerUrl() + "/obs")
- << QCoapMessage::MessageType::NonConfirmable;
+ << QCoapMessage::Type::NonConfirmable;
QTest::newRow("observe_no_scheme_no_port")
<< QUrl(testServerHost() + "/obs")
- << QCoapMessage::MessageType::NonConfirmable;
+ << QCoapMessage::Type::NonConfirmable;
QTest::newRow("observe_confirmable")
<< QUrl(testServerUrl() + "/obs")
- << QCoapMessage::MessageType::Confirmable;
+ << QCoapMessage::Type::Confirmable;
QTest::newRow("observe_receive")
<< QUrl(testServerUrl() + "/obs-non")
- << QCoapMessage::MessageType::NonConfirmable;
+ << QCoapMessage::Type::NonConfirmable;
QTest::newRow("observe_receive_confirmable")
<< QUrl(testServerUrl() + "/obs-non")
- << QCoapMessage::MessageType::Confirmable;
+ << QCoapMessage::Type::Confirmable;
QTest::newRow("observe_large")
<< QUrl(testServerUrl() + "/obs-large")
- << QCoapMessage::MessageType::NonConfirmable;
+ << QCoapMessage::Type::NonConfirmable;
QTest::newRow("observe_large_confirmable")
<< QUrl(testServerUrl() + "/obs-large")
- << QCoapMessage::MessageType::Confirmable;
+ << QCoapMessage::Type::Confirmable;
QTest::newRow("observe_pumping")
<< QUrl(testServerUrl() + "/obs-pumping")
- << QCoapMessage::MessageType::NonConfirmable;
+ << QCoapMessage::Type::NonConfirmable;
QTest::newRow("observe_pumping_confirmable")
<< QUrl(testServerUrl() + "/obs-pumping")
- << QCoapMessage::MessageType::Confirmable;
+ << QCoapMessage::Type::Confirmable;
}
void tst_QCoapClient::observe()
{
QFETCH(QUrl, url);
- QFETCH(QCoapMessage::MessageType, type);
+ QFETCH(QCoapMessage::Type, type);
QCoapClient client;
QCoapRequest request(url);
@@ -762,7 +776,9 @@ void tst_QCoapClient::observe()
QTRY_COMPARE_WITH_TIMEOUT(spyReplyNotified.count(), 3, 30000);
client.cancelObserve(reply.data());
- QCOMPARE(reply->url(), QCoapRequest::adjustedUrl(url, false));
+#ifdef QT_BUILD_INTERNAL
+ QCOMPARE(reply->url(), QCoapRequestPrivate::adjustedUrl(url, false));
+#endif
QCOMPARE(reply->request().method(), QtCoap::Method::Get);
QVERIFY2(!spyReplyNotified.wait(7000), "'Notify' signal received after cancelling observe");
@@ -779,13 +795,13 @@ void tst_QCoapClient::observe()
void tst_QCoapClient::confirmableMulticast()
{
QCoapClient client;
- const auto reply = client.get(QCoapRequest("224.0.1.187",
- QCoapMessage::MessageType::Confirmable));
+ const auto reply = client.get(QCoapRequest("224.0.1.187", QCoapMessage::Type::Confirmable));
QVERIFY2(!reply, "Confirmable multicast request didn't fail as expected.");
}
void tst_QCoapClient::multicast()
{
+#ifdef QT_BUILD_INTERNAL
QCoapClientForMulticastTests client;
QCoapRequest request = QCoapRequest(QUrl("224.0.1.187"));
request.setToken("abc");
@@ -811,10 +827,14 @@ void tst_QCoapClient::multicast()
QCOMPARE(message1.payload(), "Reply1");
QHostAddress sender1 = qvariant_cast<QHostAddress>(spyMulticastResponse.at(1).at(2));
QCOMPARE(sender1, host1);
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
void tst_QCoapClient::multicast_blockwise()
{
+#ifdef QT_BUILD_INTERNAL
QCoapClientForMulticastTests client;
QCoapRequest request = QCoapRequest(QUrl("224.0.1.187"));
request.setToken("abc");
@@ -842,6 +862,9 @@ void tst_QCoapClient::multicast_blockwise()
QCOMPARE(message1.payload(), "Reply3Reply4");
QHostAddress sender1 = qvariant_cast<QHostAddress>(spyMulticastResponse.at(1).at(2));
QCOMPARE(sender1, host1);
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
QTEST_MAIN(tst_QCoapClient)
diff --git a/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp b/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp
index da2531b..c12592a 100644
--- a/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp
+++ b/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp
@@ -34,8 +34,6 @@
#include <private/qcoapinternalreply_p.h>
#include <private/qcoapreply_p.h>
-#ifdef QT_BUILD_INTERNAL
-
class tst_QCoapInternalReply : public QObject
{
Q_OBJECT
@@ -45,14 +43,12 @@ private Q_SLOTS:
void parseReplyPdu();
void updateReply_data();
void updateReply();
- void requestData();
- void abortRequest();
};
void tst_QCoapInternalReply::parseReplyPdu_data()
{
QTest::addColumn<QtCoap::ResponseCode>("responseCode");
- QTest::addColumn<QCoapMessage::MessageType>("type");
+ QTest::addColumn<QCoapMessage::Type>("type");
QTest::addColumn<quint16>("messageId");
QTest::addColumn<QByteArray>("token");
QTest::addColumn<quint8>("tokenLength");
@@ -73,7 +69,7 @@ void tst_QCoapInternalReply::parseReplyPdu_data()
QTest::newRow("reply_with_options_and_payload")
<< QtCoap::ResponseCode::Content
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< quint16(64463)
<< QByteArray("4647f09b")
<< quint8(4)
@@ -87,7 +83,7 @@ void tst_QCoapInternalReply::parseReplyPdu_data()
QTest::newRow("reply_with_payload")
<< QtCoap::ResponseCode::Content
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< quint16(64463)
<< QByteArray("4647f09b")
<< quint8(4)
@@ -100,7 +96,7 @@ void tst_QCoapInternalReply::parseReplyPdu_data()
QTest::newRow("reply_with_options")
<< QtCoap::ResponseCode::Content
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< quint16(64463)
<< QByteArray("4647f09b")
<< quint8(4)
@@ -112,7 +108,7 @@ void tst_QCoapInternalReply::parseReplyPdu_data()
QTest::newRow("reply_only")
<< QtCoap::ResponseCode::Content
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< quint16(64463)
<< QByteArray("4647f09b")
<< quint8(4)
@@ -124,7 +120,7 @@ void tst_QCoapInternalReply::parseReplyPdu_data()
QTest::newRow("reply_with_big_option")
<< QtCoap::ResponseCode::Content
- << QCoapMessage::MessageType::NonConfirmable
+ << QCoapMessage::Type::NonConfirmable
<< quint16(64463)
<< QByteArray("4647f09b")
<< quint8(4)
@@ -139,7 +135,7 @@ void tst_QCoapInternalReply::parseReplyPdu_data()
void tst_QCoapInternalReply::parseReplyPdu()
{
QFETCH(QtCoap::ResponseCode, responseCode);
- QFETCH(QCoapMessage::MessageType, type);
+ QFETCH(QCoapMessage::Type, type);
QFETCH(quint16, messageId);
QFETCH(QByteArray, token);
QFETCH(quint8, tokenLength);
@@ -159,32 +155,14 @@ void tst_QCoapInternalReply::parseReplyPdu()
QCOMPARE(reply->message()->token().toHex(), token);
QCOMPARE(reply->message()->optionCount(), optionsNames.count());
for (int i = 0; i < reply->message()->optionCount(); ++i) {
- QCoapOption option = reply->message()->option(i);
+ QCoapOption option = reply->message()->optionAt(i);
QCOMPARE(option.name(), optionsNames.at(i));
QCOMPARE(option.length(), optionsLengths.at(i));
- QCOMPARE(option.value(), optionsValues.at(i));
+ QCOMPARE(option.opaqueValue(), optionsValues.at(i));
}
QCOMPARE(reply->message()->payload(), payload);
}
-class QCoapReplyForTests : public QCoapReply
-{
-public:
- QCoapReplyForTests(const QCoapRequest &req) : QCoapReply (req) {}
-
- void setRunning(const QCoapToken &token, QCoapMessageId messageId)
- {
- Q_D(QCoapReply);
- d->_q_setRunning(token, messageId);
- }
- void setContentAndFinished(const QCoapInternalReply *internal)
- {
- Q_D(QCoapReply);
- d->_q_setContent(internal->senderAddress(), *internal->message(), internal->responseCode());
- d->_q_setFinished();
- }
-};
-
void tst_QCoapInternalReply::updateReply_data()
{
QTest::addColumn<QByteArray>("data");
@@ -196,56 +174,21 @@ void tst_QCoapInternalReply::updateReply()
{
QFETCH(QByteArray, data);
- QCoapReplyForTests reply((QCoapRequest()));
+ QScopedPointer<QCoapReply> reply(QCoapReplyPrivate::createCoapReply(QCoapRequest()));
QCoapInternalReply internalReply;
internalReply.message()->setPayload(data);
- QSignalSpy spyReplyFinished(&reply, &QCoapReply::finished);
+ QSignalSpy spyReplyFinished(reply.data(), &QCoapReply::finished);
- reply.setContentAndFinished(&internalReply);
+ QMetaObject::invokeMethod(reply.data(), "_q_setContent",
+ Q_ARG(QHostAddress, internalReply.senderAddress()),
+ Q_ARG(QCoapMessage, *internalReply.message()),
+ Q_ARG(QtCoap::ResponseCode, internalReply.responseCode()));
+ QMetaObject::invokeMethod(reply.data(), "_q_setFinished", Q_ARG(QtCoap::Error, QtCoap::Error::Ok));
QTRY_COMPARE_WITH_TIMEOUT(spyReplyFinished.count(), 1, 1000);
- QCOMPARE(reply.readAll(), data);
+ QCOMPARE(reply->readAll(), data);
}
-void tst_QCoapInternalReply::requestData()
-{
- QCoapReplyForTests reply((QCoapRequest()));
- reply.setRunning("token", 543);
-
- QCOMPARE(reply.request().token(), QByteArray("token"));
- QCOMPARE(reply.request().messageId(), 543);
-}
-
-void tst_QCoapInternalReply::abortRequest()
-{
- QCoapReplyForTests reply((QCoapRequest()));
- reply.setRunning("token", 543);
-
- QSignalSpy spyAborted(&reply, &QCoapReply::aborted);
- QSignalSpy spyFinished(&reply, &QCoapReply::finished);
- reply.abortRequest();
-
- QTRY_COMPARE_WITH_TIMEOUT(spyAborted.count(), 1, 1000);
- QList<QVariant> arguments = spyAborted.takeFirst();
- QTRY_COMPARE_WITH_TIMEOUT(spyFinished.count(), 1, 1000);
- QVERIFY(arguments.at(0).toByteArray() == "token");
-}
-
-#else
-
-class tst_QCoapInternalReply : public QObject
-{
- Q_OBJECT
-
-private slots:
- void initTestCase()
- {
- QSKIP("Not an internal build, nothing to test");
- }
-};
-
-#endif
-
QTEST_MAIN(tst_QCoapInternalReply)
#include "tst_qcoapinternalreply.moc"
diff --git a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp
index 6a61eb1..d14edc1 100644
--- a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp
+++ b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp
@@ -33,8 +33,7 @@
#include <QtCoap/qcoaprequest.h>
#include <private/qcoapinternalrequest_p.h>
-
-#ifdef QT_BUILD_INTERNAL
+#include <private/qcoaprequest_p.h>
class tst_QCoapInternalRequest : public QObject
{
@@ -53,17 +52,11 @@ private Q_SLOTS:
void isMulticast();
};
-struct QCoapRequestForTest : public QCoapRequest
-{
- QCoapRequestForTest(const QUrl& url) : QCoapRequest(url) {}
- using QCoapRequest::setMethod;
-};
-
void tst_QCoapInternalRequest::requestToFrame_data()
{
QTest::addColumn<QUrl>("url");
QTest::addColumn<QtCoap::Method>("method");
- QTest::addColumn<QCoapMessage::MessageType>("type");
+ QTest::addColumn<QCoapMessage::Type>("type");
QTest::addColumn<quint16>("messageId");
QTest::addColumn<QByteArray>("token");
QTest::addColumn<QString>("pduHeader");
@@ -72,7 +65,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_with_option_and_payload")
<< QUrl("coap://10.20.30.40:5683/test")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09bb474657374ff"
@@ -81,7 +74,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_domain")
<< QUrl("coap://domain.com:5683/test")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09b3a646f6d61696e2e636f6d8474657374ff"
@@ -90,7 +83,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_ipv6")
<< QUrl("coap://[::ffff:ac11:3]:5683/test")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09bb474657374ff"
@@ -99,7 +92,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_without_payload")
<< QUrl("coap://10.20.30.40:5683/test")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09bb474657374"
@@ -108,7 +101,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_without_option")
<< QUrl("coap://10.20.30.40:5683/")
<< QtCoap::Method::Put
- << QCoapRequest::MessageType::Confirmable
+ << QCoapRequest::Type::Confirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "4403dc504647f09bff"
@@ -117,7 +110,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_only")
<< QUrl("coap://10.20.30.40:5683/")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09b"
@@ -126,7 +119,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_with_multiple_options")
<< QUrl("coap://10.20.30.40:5683/test/oui")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09bb474657374036f7569"
@@ -135,7 +128,7 @@ void tst_QCoapInternalRequest::requestToFrame_data()
QTest::newRow("request_with_big_option_number")
<< QUrl("coap://10.20.30.40:5683/test")
<< QtCoap::Method::Get
- << QCoapRequest::MessageType::NonConfirmable
+ << QCoapRequest::Type::NonConfirmable
<< quint16(56400)
<< QByteArray::fromHex("4647f09b")
<< "5401dc504647f09bb474657374dd240d6162636465666768696a6b6c6d6e6f70"
@@ -147,15 +140,14 @@ void tst_QCoapInternalRequest::requestToFrame()
{
QFETCH(QUrl, url);
QFETCH(QtCoap::Method, method);
- QFETCH(QCoapMessage::MessageType, type);
+ QFETCH(QCoapMessage::Type, type);
QFETCH(quint16, messageId);
QFETCH(QByteArray, token);
QFETCH(QString, pduHeader);
QFETCH(QString, pduPayload);
- QCoapRequestForTest request(url);
+ QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest(url), method);
request.setType(type);
- request.setMethod(method);
request.setPayload(pduPayload.toUtf8());
request.setMessageId(messageId);
request.setToken(token);
@@ -183,33 +175,34 @@ void tst_QCoapInternalRequest::parseUri_data()
<< QUrl()
<< QVector<QCoapOption>({
QCoapOption(QCoapOption::UriPort, 1234),
- QCoapOption(QCoapOption::UriPath, "test"),
- QCoapOption(QCoapOption::UriPath, "path1") });
+ QCoapOption(QCoapOption::UriPath, QByteArray("test")),
+ QCoapOption(QCoapOption::UriPath, QByteArray("path1")) });
QTest::newRow("path_query")
<< QUrl("coap://10.20.30.40/test/path1/?rd=25&nd=4")
<< QUrl()
<< QVector<QCoapOption>({
- QCoapOption(QCoapOption::UriPath, "test"),
- QCoapOption(QCoapOption::UriPath, "path1"),
- QCoapOption(QCoapOption::UriQuery, "rd=25"),
- QCoapOption(QCoapOption::UriQuery, "nd=4") });
+ QCoapOption(QCoapOption::UriPath, QByteArray("test")),
+ QCoapOption(QCoapOption::UriPath, QByteArray("path1")),
+ QCoapOption(QCoapOption::UriQuery, QByteArray("rd=25")),
+ QCoapOption(QCoapOption::UriQuery, QByteArray("nd=4")) });
QTest::newRow("host_path_query")
<< QUrl("coap://aa.bb.cc.com:5683/test/path1/?rd=25&nd=4")
<< QUrl()
<< QVector<QCoapOption>({
- QCoapOption(QCoapOption::UriHost, "aa.bb.cc.com"),
- QCoapOption(QCoapOption::UriPath, "test"),
- QCoapOption(QCoapOption::UriPath, "path1"),
- QCoapOption(QCoapOption::UriQuery, "rd=25"),
- QCoapOption(QCoapOption::UriQuery, "nd=4") });
+ QCoapOption(QCoapOption::UriHost, QByteArray("aa.bb.cc.com")),
+ QCoapOption(QCoapOption::UriPath, QByteArray("test")),
+ QCoapOption(QCoapOption::UriPath, QByteArray("path1")),
+ QCoapOption(QCoapOption::UriQuery, QByteArray("rd=25")),
+ QCoapOption(QCoapOption::UriQuery, QByteArray("nd=4")) });
QTest::newRow("proxy_url")
<< QUrl("coap://aa.bb.cc.com:5683/test/path1/?rd=25&nd=4")
<< QUrl("coap://10.20.30.40/test:5684/othertest/path")
<< QVector<QCoapOption>({
- QCoapOption(QCoapOption::ProxyUri, "coap://10.20.30.40/test:5684/othertest/path") });
+ QCoapOption(QCoapOption::ProxyUri,
+ QByteArray("coap://10.20.30.40/test:5684/othertest/path")) });
}
void tst_QCoapInternalRequest::parseUri()
@@ -218,7 +211,7 @@ void tst_QCoapInternalRequest::parseUri()
QFETCH(QUrl, proxyUri);
QFETCH(QVector<QCoapOption>, options);
- QCoapRequest request(uri, QCoapMessage::MessageType::NonConfirmable, proxyUri);
+ QCoapRequest request(uri, QCoapMessage::Type::NonConfirmable, proxyUri);
QCoapInternalRequest internalRequest(request);
for (QCoapOption opt : options)
@@ -233,9 +226,9 @@ void tst_QCoapInternalRequest::urlOptions_data()
QTest::addColumn<QVector<QCoapOption>>("options");
QVector<QCoapOption> options = {
- { QCoapOption::UriHost, "example.com" },
- { QCoapOption::UriPath, "~sensors" },
- { QCoapOption::UriPath, "temp.xml" }
+ { QCoapOption::UriHost, QByteArray("example.com") },
+ { QCoapOption::UriPath, QByteArray("~sensors") },
+ { QCoapOption::UriPath, QByteArray("temp.xml") }
};
QTest::newRow("url_with_default_port")
@@ -320,21 +313,6 @@ void tst_QCoapInternalRequest::isMulticast()
QCOMPARE(internalRequest.isMulticast(), result);
}
-#else
-
-class tst_QCoapInternalRequest : public QObject
-{
- Q_OBJECT
-
-private slots:
- void initTestCase()
- {
- QSKIP("Not an internal build, nothing to test");
- }
-};
-
-#endif
-
QTEST_APPLESS_MAIN(tst_QCoapInternalRequest)
#include "tst_qcoapinternalrequest.moc"
diff --git a/tests/auto/qcoapmessage/tst_qcoapmessage.cpp b/tests/auto/qcoapmessage/tst_qcoapmessage.cpp
index 8801ed0..56579e5 100644
--- a/tests/auto/qcoapmessage/tst_qcoapmessage.cpp
+++ b/tests/auto/qcoapmessage/tst_qcoapmessage.cpp
@@ -39,8 +39,8 @@ class tst_QCoapMessage : public QObject
private Q_SLOTS:
void copyAndDetach();
- void setMessageType_data();
- void setMessageType();
+ void setType_data();
+ void setType();
void addOption();
void addOption_string_data();
void addOption_string();
@@ -59,7 +59,7 @@ void tst_QCoapMessage::copyAndDetach()
a.setMessageId(3);
a.setPayload("payload");
a.setToken("token");
- a.setType(QCoapMessage::MessageType::Acknowledgment);
+ a.setType(QCoapMessage::Type::Acknowledgment);
a.setVersion(5);
// Test the copy
@@ -67,7 +67,7 @@ void tst_QCoapMessage::copyAndDetach()
QVERIFY2(b.messageId() == 3, "Message not copied correctly");
QVERIFY2(b.payload() == "payload", "Message not copied correctly");
QVERIFY2(b.token() == "token", "Message not copied correctly");
- QVERIFY2(b.type() == QCoapMessage::MessageType::Acknowledgment, "Message not copied correctly");
+ QVERIFY2(b.type() == QCoapMessage::Type::Acknowledgment, "Message not copied correctly");
QVERIFY2(b.version() == 5, "Message not copied correctly");
// Detach
@@ -76,19 +76,19 @@ void tst_QCoapMessage::copyAndDetach()
QCOMPARE(a.messageId(), 3);
}
-void tst_QCoapMessage::setMessageType_data()
+void tst_QCoapMessage::setType_data()
{
- QTest::addColumn<QCoapMessage::MessageType>("type");
+ QTest::addColumn<QCoapMessage::Type>("type");
- QTest::newRow("acknowledgment") << QCoapMessage::MessageType::Acknowledgment;
- QTest::newRow("confirmable") << QCoapMessage::MessageType::Confirmable;
- QTest::newRow("non-confirmable") << QCoapMessage::MessageType::NonConfirmable;
- QTest::newRow("reset") << QCoapMessage::MessageType::Reset;
+ QTest::newRow("acknowledgment") << QCoapMessage::Type::Acknowledgment;
+ QTest::newRow("confirmable") << QCoapMessage::Type::Confirmable;
+ QTest::newRow("non-confirmable") << QCoapMessage::Type::NonConfirmable;
+ QTest::newRow("reset") << QCoapMessage::Type::Reset;
}
-void tst_QCoapMessage::setMessageType()
+void tst_QCoapMessage::setType()
{
- QFETCH(QCoapMessage::MessageType, type);
+ QFETCH(QCoapMessage::Type, type);
QCoapMessage message;
message.setType(type);
QCOMPARE(message.type(), type);
@@ -123,7 +123,7 @@ void tst_QCoapMessage::addOption()
QVERIFY(std::all_of(message.options().cbegin(), message.options().cend(),
[value](const QCoapOption opt) -> bool {
- return opt.value() == value;
+ return opt.opaqueValue() == value;
}));
}
@@ -131,7 +131,7 @@ void tst_QCoapMessage::addOption_string_data()
{
QTest::addColumn<QVector<QCoapOption>>("options");
- QVector<QCoapOption> single_char_option = { { QCoapOption::LocationPath, "path1" } };
+ QVector<QCoapOption> single_string_option = { { QCoapOption::LocationPath, QString("path1") } };
QVector<QCoapOption> single_ba_option = {
{ QCoapOption::LocationPath, QByteArray("\xAF\x01\xC2") }
};
@@ -140,7 +140,7 @@ void tst_QCoapMessage::addOption_string_data()
{ QCoapOption::LocationPath, QString("str_path3") }
};
- QTest::newRow("single_char_option") << single_char_option;
+ QTest::newRow("single_char_option") << single_string_option;
QTest::newRow("single_ba_option") << single_ba_option;
QTest::newRow("multiple_string_options") << multiple_string_options;
}
@@ -184,18 +184,18 @@ void tst_QCoapMessage::addOption_uint()
message.addOption(option);
QCOMPARE(message.options(name).size(), 1);
- QCOMPARE(message.option(name).valueToInt(), value);
- QCOMPARE(option.value().size(), size);
+ QCOMPARE(message.option(name).uintValue(), value);
+ QCOMPARE(option.opaqueValue().size(), size);
}
void tst_QCoapMessage::removeOption_data()
{
QTest::addColumn<QVector<QCoapOption>>("options");
- QVector<QCoapOption> single_option = { { QCoapOption::LocationPath, "path1" } };
+ QVector<QCoapOption> single_option = { { QCoapOption::LocationPath, QByteArray("path1") } };
QVector<QCoapOption> multiple_options = {
- { QCoapOption::LocationPath, "path2" },
- { QCoapOption::LocationPath, "path3" }
+ { QCoapOption::LocationPath, QByteArray("path2") },
+ { QCoapOption::LocationPath, QByteArray("path3") }
};
QTest::newRow("single_option") << single_option;
@@ -227,10 +227,10 @@ void tst_QCoapMessage::removeOptionByName_data()
QTest::addColumn<QVector<QCoapOption>>("options");
QTest::addColumn<QCoapOption::OptionName>("name");
- QVector<QCoapOption> single_option = { { QCoapOption::LocationPath, "path1" } };
+ QVector<QCoapOption> single_option = { { QCoapOption::LocationPath, QByteArray("path1") } };
QVector<QCoapOption> multiple_options = {
- { QCoapOption::LocationPath, "path2" },
- { QCoapOption::LocationPath, "path3" }
+ { QCoapOption::LocationPath, QByteArray("path2") },
+ { QCoapOption::LocationPath, QByteArray("path3") }
};
QTest::newRow("remove_single_option") << single_option << single_option.back().name();
@@ -256,7 +256,7 @@ void tst_QCoapMessage::removeAll()
message.addOption(QCoapOption::LocationPath, "path");
message.addOption(QCoapOption::ProxyUri, "proxy1");
message.addOption(QCoapOption::ProxyUri, "proxy2");
- message.removeAllOptions();
+ message.clearOptions();
QVERIFY(message.options().isEmpty());
}
diff --git a/tests/auto/qcoapoption/tst_qcoapoption.cpp b/tests/auto/qcoapoption/tst_qcoapoption.cpp
index 2541fad..fec22b1 100644
--- a/tests/auto/qcoapoption/tst_qcoapoption.cpp
+++ b/tests/auto/qcoapoption/tst_qcoapoption.cpp
@@ -38,8 +38,7 @@ class tst_QCoapOption : public QObject
private Q_SLOTS:
void constructWithQByteArray();
- void constructWithQStringView();
- void constructWithCString();
+ void constructWithQString();
void constructWithInteger();
void constructWithUtf8Characters();
};
@@ -49,23 +48,15 @@ void tst_QCoapOption::constructWithQByteArray()
QByteArray ba = "some data";
QCoapOption option(QCoapOption::LocationPath, ba);
- QCOMPARE(option.value(), ba);
+ QCOMPARE(option.opaqueValue(), ba);
}
-void tst_QCoapOption::constructWithQStringView()
+void tst_QCoapOption::constructWithQString()
{
QString str = "some data";
QCoapOption option(QCoapOption::LocationPath, str);
- QCOMPARE(option.value(), str.toUtf8());
-}
-
-void tst_QCoapOption::constructWithCString()
-{
- const char *str = "some data";
- QCoapOption option(QCoapOption::LocationPath, str);
-
- QCOMPARE(option.value(), QByteArray(str));
+ QCOMPARE(option.opaqueValue(), str.toUtf8());
}
void tst_QCoapOption::constructWithInteger()
@@ -73,7 +64,7 @@ void tst_QCoapOption::constructWithInteger()
quint32 value = 64000;
QCoapOption option(QCoapOption::Size1, value);
- QCOMPARE(option.valueToInt(), value);
+ QCOMPARE(option.uintValue(), value);
}
void tst_QCoapOption::constructWithUtf8Characters()
@@ -81,7 +72,7 @@ void tst_QCoapOption::constructWithUtf8Characters()
QByteArray ba = "\xc3\xa9~\xce\xbb\xe2\x82\xb2";
QCoapOption option(QCoapOption::LocationPath, ba);
- QCOMPARE(option.value(), ba);
+ QCOMPARE(option.opaqueValue(), ba);
}
QTEST_APPLESS_MAIN(tst_QCoapOption)
diff --git a/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp b/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp
index 6ce5a87..8876214 100644
--- a/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp
+++ b/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp
@@ -37,20 +37,14 @@
#include <QtNetwork/qudpsocket.h>
#include <QtNetwork/qnetworkdatagram.h>
#include <QtCoap/qcoapglobal.h>
-#include <QtCoap/qcoapqudpconnection.h>
#include <QtCoap/qcoaprequest.h>
#include <private/qcoapqudpconnection_p.h>
#include <private/qcoapinternalrequest_p.h>
+#include <private/qcoaprequest_p.h>
#include "../coapnetworksettings.h"
using namespace QtCoapNetworkSettings;
-struct QCoapRequestForTest : public QCoapRequest
-{
- QCoapRequestForTest(const QUrl &url) : QCoapRequest(url) {}
- using QCoapRequest::setMethod;
-};
-
class tst_QCoapQUdpConnection : public QObject
{
Q_OBJECT
@@ -68,7 +62,7 @@ class QCoapQUdpConnectionForTest : public QCoapQUdpConnection
Q_OBJECT
public:
QCoapQUdpConnectionForTest(QObject *parent = nullptr) :
- QCoapQUdpConnection(QtCoap::SecurityMode::NoSec, parent)
+ QCoapQUdpConnection(QtCoap::SecurityMode::NoSecurity, parent)
{}
void bindSocketForTest() { d_func()->bindSocket(); }
@@ -86,7 +80,6 @@ void tst_QCoapQUdpConnection::ctor()
void tst_QCoapQUdpConnection::connectToHost()
{
-#ifdef QT_BUILD_INTERNAL
QCoapQUdpConnectionForTest connection;
QUdpSocket *socket = qobject_cast<QUdpSocket*>(connection.socket());
@@ -101,14 +94,10 @@ void tst_QCoapQUdpConnection::connectToHost()
QTRY_COMPARE(spySocketStateChanged.count(), 1);
QTRY_COMPARE(spyConnectionBound.count(), 1);
QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Bound);
-#else
- QSKIP("Not an internal build, skipping this test");
-#endif
}
void tst_QCoapQUdpConnection::reconnect()
{
-#ifdef QT_BUILD_INTERNAL
QCoapQUdpConnectionForTest connection;
// This will trigger connection.bind()
@@ -124,9 +113,6 @@ void tst_QCoapQUdpConnection::reconnect()
connection.sendRequest(QByteArray(), QString(), 0);
QTRY_COMPARE(connectionBoundSpy.count(), 2);
QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Bound);
-#else
- QSKIP("Not an internal build, skipping this test");
-#endif
}
void tst_QCoapQUdpConnection::sendRequest_data()
@@ -180,7 +166,6 @@ void tst_QCoapQUdpConnection::sendRequest_data()
void tst_QCoapQUdpConnection::sendRequest()
{
-#ifdef QT_BUILD_INTERNAL
QFETCH(QString, protocol);
QFETCH(QString, host);
QFETCH(QString, path);
@@ -194,10 +179,10 @@ void tst_QCoapQUdpConnection::sendRequest()
QSignalSpy spySocketReadyRead(connection.socket(), &QUdpSocket::readyRead);
QSignalSpy spyConnectionReadyRead(&connection, &QCoapQUdpConnection::readyRead);
- QCoapRequestForTest request(protocol + host + path);
+ QCoapRequest request =
+ QCoapRequestPrivate::createRequest(QCoapRequest(protocol + host + path), method);
request.setMessageId(24806);
request.setToken(QByteArray("abcd"));
- request.setMethod(method);
QVERIFY(connection.socket() != nullptr);
QCoapInternalRequest internalRequest(request);
connection.sendRequest(internalRequest.toQByteArray(), host, port);
@@ -208,9 +193,6 @@ void tst_QCoapQUdpConnection::sendRequest()
QByteArray data = spyConnectionReadyRead.first().first().value<QByteArray>();
QVERIFY(QString(data.toHex()).startsWith(dataHexaHeader));
QVERIFY(QString(data.toHex()).endsWith(dataHexaPayload));
-#else
- QSKIP("Not an internal build, skipping this test");
-#endif
}
QTEST_MAIN(tst_QCoapQUdpConnection)
diff --git a/tests/auto/qcoapreply/tst_qcoapreply.cpp b/tests/auto/qcoapreply/tst_qcoapreply.cpp
index d9a7562..c02c3ae 100644
--- a/tests/auto/qcoapreply/tst_qcoapreply.cpp
+++ b/tests/auto/qcoapreply/tst_qcoapreply.cpp
@@ -33,6 +33,7 @@
#include <QtCoap/qcoapreply.h>
#include <private/qcoapreply_p.h>
+#include <private/qcoapnamespace_p.h>
class tst_QCoapReply : public QObject
{
@@ -45,18 +46,6 @@ private Q_SLOTS:
void abortRequest();
};
-class QCoapReplyForTests : public QCoapReply
-{
-public:
- QCoapReplyForTests(const QCoapRequest &req) : QCoapReply (req) {}
-
- void setRunning(const QCoapToken &token, QCoapMessageId messageId)
- {
- Q_D(QCoapReply);
- d->_q_setRunning(token, messageId);
- }
-};
-
void tst_QCoapReply::updateReply_data()
{
QTest::addColumn<QByteArray>("payload");
@@ -90,22 +79,22 @@ void tst_QCoapReply::updateReply()
const QByteArray token = "\xAF\x01\xC2";
const quint16 id = 645;
- QCoapReply reply(QCoapRequest{});
+ QScopedPointer<QCoapReply> reply(QCoapReplyPrivate::createCoapReply(QCoapRequest()));
QCoapMessage message;
message.setToken(token);
message.setMessageId(id);
message.setPayload(payload);
- QSignalSpy spyReplyFinished(&reply, &QCoapReply::finished);
- QSignalSpy spyReplyNotified(&reply, &QCoapReply::notified);
- QSignalSpy spyReplyError(&reply, &QCoapReply::error);
- QSignalSpy spyReplyAborted(&reply, &QCoapReply::aborted);
+ QSignalSpy spyReplyFinished(reply.data(), &QCoapReply::finished);
+ QSignalSpy spyReplyNotified(reply.data(), &QCoapReply::notified);
+ QSignalSpy spyReplyError(reply.data(), &QCoapReply::error);
+ QSignalSpy spyReplyAborted(reply.data(), &QCoapReply::aborted);
- QMetaObject::invokeMethod(&reply, "_q_setContent",
+ QMetaObject::invokeMethod(reply.data(), "_q_setContent",
Q_ARG(QHostAddress, QHostAddress()),
Q_ARG(QCoapMessage, message),
Q_ARG(QtCoap::ResponseCode, responseCode));
- QMetaObject::invokeMethod(&reply, "_q_setFinished",
+ QMetaObject::invokeMethod(reply.data(), "_q_setFinished",
Q_ARG(QtCoap::Error, error));
QCOMPARE(spyReplyFinished.count(), 1);
@@ -113,50 +102,45 @@ void tst_QCoapReply::updateReply()
QCOMPARE(spyReplyAborted.count(), 0);
if (error != QtCoap::Error::Ok || QtCoap::isError(responseCode)) {
QVERIFY(spyReplyError.count() > 0);
- QCOMPARE(reply.isSuccessful(), false);
+ QCOMPARE(reply->isSuccessful(), false);
} else {
QCOMPARE(spyReplyError.count(), 0);
- QCOMPARE(reply.isSuccessful(), true);
+ QCOMPARE(reply->isSuccessful(), true);
}
- QCOMPARE(reply.readAll(), payload);
- QCOMPARE(reply.readAll(), QByteArray());
- QCOMPARE(reply.responseCode(), responseCode);
- QCOMPARE(reply.message().token(), token);
- QCOMPARE(reply.message().messageId(), id);
+ QCOMPARE(reply->readAll(), payload);
+ QCOMPARE(reply->readAll(), QByteArray());
+ QCOMPARE(reply->responseCode(), responseCode);
+ QCOMPARE(reply->message().token(), token);
+ QCOMPARE(reply->message().messageId(), id);
}
void tst_QCoapReply::requestData()
{
-#ifdef QT_BUILD_INTERNAL
- QCoapReplyForTests reply((QCoapRequest()));
- reply.setRunning("token", 543);
-
- QCOMPARE(reply.request().token(), QByteArray("token"));
- QCOMPARE(reply.request().messageId(), 543);
-#else
- QSKIP("Not an internal build, skipping this test");
-#endif
+ QScopedPointer<QCoapReply> reply(QCoapReplyPrivate::createCoapReply(QCoapRequest()));
+ QMetaObject::invokeMethod(reply.data(), "_q_setRunning",
+ Q_ARG(QCoapToken, "token"),
+ Q_ARG(QCoapMessageId, 543));
+
+ QCOMPARE(reply->request().token(), QByteArray("token"));
+ QCOMPARE(reply->request().messageId(), 543);
}
void tst_QCoapReply::abortRequest()
{
-#ifdef QT_BUILD_INTERNAL
- QCoapReplyForTests reply((QCoapRequest()));
- reply.setRunning("token", 543);
+ QScopedPointer<QCoapReply> reply(QCoapReplyPrivate::createCoapReply(QCoapRequest()));
+ QMetaObject::invokeMethod(reply.data(), "_q_setRunning",
+ Q_ARG(QCoapToken, "token"),
+ Q_ARG(QCoapMessageId, 543));
- QSignalSpy spyAborted(&reply, &QCoapReply::aborted);
- QSignalSpy spyFinished(&reply, &QCoapReply::finished);
- reply.abortRequest();
+ QSignalSpy spyAborted(reply.data(), &QCoapReply::aborted);
+ QSignalSpy spyFinished(reply.data(), &QCoapReply::finished);
+ reply->abortRequest();
QTRY_COMPARE_WITH_TIMEOUT(spyAborted.count(), 1, 1000);
QList<QVariant> arguments = spyAborted.takeFirst();
QTRY_COMPARE_WITH_TIMEOUT(spyFinished.count(), 1, 1000);
QVERIFY(arguments.at(0).toByteArray() == "token");
- QCOMPARE(reply.isSuccessful(), false);
-#else
- QSKIP("Not an internal build, skipping this test");
-#endif
}
QTEST_MAIN(tst_QCoapReply)
diff --git a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp
index 9f66b98..2b042b5 100644
--- a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp
+++ b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp
@@ -34,6 +34,7 @@
#include <QtCoap/qcoapglobal.h>
#include <QtCoap/qcoapnamespace.h>
#include <QtCoap/qcoaprequest.h>
+#include <private/qcoaprequest_p.h>
class tst_QCoapRequest : public QObject
{
@@ -50,11 +51,6 @@ private Q_SLOTS:
void copyAndDetach();
};
-struct QCoapRequestForTest : public QCoapRequest
-{
- using QCoapRequest::setMethod;
-};
-
void tst_QCoapRequest::ctor_data()
{
QTest::addColumn<QUrl>("url");
@@ -103,13 +99,18 @@ void tst_QCoapRequest::adjustUrl_data()
void tst_QCoapRequest::adjustUrl()
{
+#ifdef QT_BUILD_INTERNAL
QFETCH(QUrl, inputUrl);
QFETCH(QUrl, expectedUrl);
QFETCH(bool, secure);
- QCoapRequest request(inputUrl);
- request.adjustUrl(secure);
+ // createRequest() will adjust the url
+ QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest(inputUrl),
+ QtCoap::Method::Get, secure);
QCOMPARE(request.url(), expectedUrl);
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
void tst_QCoapRequest::setUrl_data()
@@ -156,13 +157,13 @@ void tst_QCoapRequest::enableObserve()
void tst_QCoapRequest::copyAndDetach()
{
- QCoapRequestForTest a;
+#ifdef QT_BUILD_INTERNAL
+ QCoapRequest a = QCoapRequestPrivate::createRequest(QCoapRequest(), QtCoap::Method::Delete);
a.setMessageId(3);
a.setPayload("payload");
a.setToken("token");
- a.setType(QCoapMessage::MessageType::Acknowledgment);
+ a.setType(QCoapMessage::Type::Acknowledgment);
a.setVersion(5);
- a.setMethod(QtCoap::Method::Delete);
QUrl testUrl("coap://url:500/resource");
a.setUrl(testUrl);
QUrl testProxyUrl("test://proxyurl");
@@ -173,7 +174,7 @@ void tst_QCoapRequest::copyAndDetach()
QVERIFY2(b.messageId() == 3, "Message not copied correctly");
QVERIFY2(b.payload() == "payload", "Message not copied correctly");
QVERIFY2(b.token() == "token", "Message not copied correctly");
- QVERIFY2(b.type() == QCoapMessage::MessageType::Acknowledgment, "Message not copied correctly");
+ QVERIFY2(b.type() == QCoapMessage::Type::Acknowledgment, "Message not copied correctly");
QVERIFY2(b.version() == 5, "Message not copied correctly");
// Test the QCoapRequest copy
@@ -186,6 +187,9 @@ void tst_QCoapRequest::copyAndDetach()
c.setMessageId(9);
QCOMPARE(c.messageId(), 9);
QCOMPARE(a.messageId(), 3);
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
QTEST_APPLESS_MAIN(tst_QCoapRequest)
diff --git a/tests/auto/qcoapresource/qcoapresource.pro b/tests/auto/qcoapresource/qcoapresource.pro
index 6687ad2..8acf36b 100644
--- a/tests/auto/qcoapresource/qcoapresource.pro
+++ b/tests/auto/qcoapresource/qcoapresource.pro
@@ -1,4 +1,4 @@
-QT = testlib network core-private core coap
+QT = testlib network core-private core coap coap-private
CONFIG += testcase
SOURCES += tst_qcoapresource.cpp
diff --git a/tests/auto/qcoapresource/tst_qcoapresource.cpp b/tests/auto/qcoapresource/tst_qcoapresource.cpp
index 0d54029..52743ee 100644
--- a/tests/auto/qcoapresource/tst_qcoapresource.cpp
+++ b/tests/auto/qcoapresource/tst_qcoapresource.cpp
@@ -32,7 +32,8 @@
#include <QCoreApplication>
#include <QtCoap/qcoapresource.h>
-#include <QtCoap/qcoapdiscoveryreply.h>
+#include <QtCoap/qcoapresourcediscoveryreply.h>
+#include <private/qcoapresourcediscoveryreply_p.h>
class tst_QCoapResource : public QObject
{
@@ -133,6 +134,7 @@ void tst_QCoapResource::parseCoreLink_data()
void tst_QCoapResource::parseCoreLink()
{
+#ifdef QT_BUILD_INTERNAL
QFETCH(int, resourceNumber);
QFETCH(QString, senderAddress);
QFETCH(QList<QString>, pathList);
@@ -145,7 +147,8 @@ void tst_QCoapResource::parseCoreLink()
QFETCH(QByteArray, coreLinkList);
const QVector<QCoapResource> resourceList =
- QCoapDiscoveryReply::resourcesFromCoreLinkList(QHostAddress(senderAddress), coreLinkList);
+ QCoapResourceDiscoveryReplyPrivate::resourcesFromCoreLinkList(
+ QHostAddress(senderAddress), coreLinkList);
QCOMPARE(resourceList.size(), resourceNumber);
@@ -161,6 +164,9 @@ void tst_QCoapResource::parseCoreLink()
QCOMPARE(resource.observable(), observableList[resourceIndex]);
++resourceIndex;
}
+#else
+ QSKIP("Not an internal build, skipping this test");
+#endif
}
QTEST_APPLESS_MAIN(tst_QCoapResource)