aboutsummaryrefslogtreecommitdiffstats
path: root/src/coap/qcoapprotocol.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Build with QT_NO_CONTEXTLESS_CONNECT (add it to .cmake.conf)Ahmad Samir2023-08-211-2/+2
| | | | | | | | | | | This disables the 3-arg QObject::connect() overload: QObject::connect(sender, signal, functor) For details see: https://lists.qt-project.org/pipermail/development/2023-July/044141.html Change-Id: Ie9fe431feac6db6a8981b65fbc25bc8a1e352457 Reviewed-by: Sona Kurazyan <kurazyan.sona@gmail.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-061-1/+1
| | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace. Task-number: QTBUG-99313 Change-Id: I0483bd72018332f9a1d7c60537228ea6c85f7029 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-061-1/+1
| | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8: auto QtContainerClass = anyOf( expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o), expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)); makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container', with the extended set of container classes recognized. Change-Id: I227e49052f5f1a2a8abfc719112facb5c805d463 Reviewed-by: Sona Kurazyan <kurazyan.sona@gmail.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Use SPDX license identifiersLucie Gérard2022-06-151-29/+3
| | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I2f390c365ce2d50aa79d317eafd63be19e530c1e Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Remove the trailing token from empty acknowledgment packetsSona Kurazyan2021-06-301-3/+3
| | | | | | | | | | | | | | | When sending Acknowledgment packets with code 0.00, the message should be empty (RFC-7252 section 12.1). An empty message should have no token (token length is 0), and no bytes should appear after the message ID (RFC-7252 section 4.1, section 3). Since Reset packets have the same structure (only the packet type differs), unified the packet creation for both cases in one method. Fixes: QTBUG-94763 Pick-to: 6.2 6.1 5.15 Change-Id: If2619ad6f4f5dba500e04ab10dbbbf08e4887aef Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use QList instead of QVector in qtcoapSona Kurazyan2020-06-241-2/+2
| | | | | | | | And fix dependencies. Task-number: QTBUG-84469 Change-Id: Ic68bcf0229b516a04ba3d9e515dfb992e12d1f49 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
* Fix compilationSona Kurazyan2019-10-041-2/+2
| | | | | | | | | | | - Some compilers don't like using QPointer in connect(). Use QPointer::data() instead. This fixes the build for linux SLES 12. - Enable simplecoapclient example only when Qt is compiled with gui. Fixes: QTBUG-78884 Change-Id: I592e52eaea93f8f94a2b1af18ea29e745c44dde9 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix assertion when setting the timeoutSona Kurazyan2019-07-111-3/+10
| | | | | | | | | After 5d7e221bbf9e27e90448243909abc76d81733381 an assertion will be triggered when calling QRandomGenerator::bounded with equal low and high values. Change-Id: Id6d7c0f583285a54303452a6f2538f3ca72adced Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix warningsSona Kurazyan2019-06-141-2/+2
| | | | | | | | | | - qcoapprotocol.cpp:387: implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int') - tst_qcoapclient.cpp:365: implicit conversion loses integer precision: 'int' to 'quint16' (aka 'unsigned short') - tst_qcoapclient.cpp:502: implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int') - tst_qcoapclient.cpp:504: implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int') Change-Id: I5bec42fc69925f04641285c6473d9ddc3ba6ec56 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Fix calculation of MAX_TRANSMIT_SPANSona Kurazyan2019-06-121-1/+3
| | | | | | | Fixed a wrong closing parenthesis location, based on the RFC. Change-Id: I3aa369a66411bbef1ca6f7b8b8c72fad9281c60c Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix a typo: setMinumumTokenSize -> setMinimumTokenSizeSona Kurazyan2019-05-241-1/+1
| | | | | Change-Id: Ifcef69e73ea89f30499063452920dd9abb446f7e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add a method for setting the minimum token sizeSona Kurazyan2019-05-221-3/+21
| | | | | | | | | | For security reasons it is recommended to use tokens with a length of at least 4 bytes. Added a method for setting the minimum token size and changed it to be 4 by default. Change-Id: Ib589b338df8e59ccaf24dceab6691f92d92f861c Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Use maximum/minimum instead of max/minSona Kurazyan2019-05-141-36/+36
| | | | | | | This change is based on the feedback from API review. Change-Id: Ia17d061c60fcf7aa4da38542d96d75ae621f657a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Improve the API of QCoapRequestSona Kurazyan2019-05-141-1/+3
| | | | | | | | | | | | | - Moved internally used methods to the private class. - Replaced the internally used protected constructor with a static method in the private class. - Removed the internally used setMethod(), no need for it anymore. - Removed the isValid() method, no point in keeping it. This change is based on the feedback from API review. Change-Id: I177efdb1d436266549dea3e8d2b01160648fce90 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Improve the API of QCoapMessageSona Kurazyan2019-05-141-4/+4
| | | | | | | | | | | | | - Rename QCoapMessage::MessageType -> QCoapMessage::Type - Rename option() -> optionAt() - Rename removeAllOptions() -> clearOptions() - Hide findOption(). option() is more convenient to use instead. - Add a setOptions() method. This change is based on the feedback from API review. Change-Id: I2093a06ca09eebb95865a82e09d2aa2265379e5d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Hide internally used methods from QtCoap namespaceSona Kurazyan2019-05-141-1/+2
| | | | | | | | | Additionally rename responseCodeError() -> errorForResponseCode(). This change is based on the feedback from API review. Change-Id: Ida63a854f628d3d92a93bd54bd80f2368de48d8d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Hide the API of QCoapProtocolSona Kurazyan2019-05-141-2/+42
| | | | | | | | No need to keep this class public, there is no public API for accessing it anyway. Change-Id: I231a560becb5799667819c30eca6372282adeb41 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Hide the APIs of QCoapConnection and QCoapQUdpConnectionSona Kurazyan2019-05-141-1/+0
| | | | | | | | | | | | At the moment only the QCoapQUdpConnection class implements the QCoapConnection interface. If later we decide to add other implementations, and it turns out that the current API is not good enough, it won't be possible to change it without breaking the source compatibility. Let's make these classes private, we can make them public when there is a need for it. Change-Id: I41336dda0e6eaa762f0eb9c8f4aa98a9c7b62a2c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove the "Error" ending from QtCoap::Error enum value namesv5.13.0-rc3v5.13.0-rc2v5.13.0-rc1v5.13.0-beta4v5.13.05.13.0Sona Kurazyan2019-05-031-8/+8
| | | | | | | | | | | | | QtCoap::Error is a scoped enum class, so its value names will get the "Error::" prefix anyway. No need to have it as a suffix for the value names. For the same reason replaced QtCoap::Error::NoError by QtCoap::Error::Ok. Change-Id: Iaf7b51cdab6ea330e940e5af73ba93a55eb48315 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Use scoped enumsSona Kurazyan2019-05-031-13/+13
| | | | | | | | | | | Execptions are made for QCoapOption::OptionName and QtCoap::Port enums, because the values of these types are not limited only to the values listed in the enums. In case of using custom values, it would be more convenient to use integers directly, instead of using a static_cast each time the user needs a custom value. Change-Id: Ibc63e26c59629702c03528dd7e5e5eedc6bcc90a Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Hide the API for sending byte array requestsSona Kurazyan2019-03-201-1/+3
| | | | | | | | | | | Users should not be able to send "manually" constructed requests with raw byte array data. Only QCoapProtocol knows how to correctly construct/send coap messages and make the proper signal/slot connections. Change-Id: I8fd64638ea7f8e7b20671b80e6db4e1a7758c4fa Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Improve logging of the CoAP moduleSona Kurazyan2019-03-191-12/+16
| | | | | | | | | | | | | - Introduced different log categories and categorized log messages accordingly. - Improved logs from console example by: * Changing debug messages to info or warning, * Removing extra spaces from the log messages. Change-Id: Ia6b2006db5e7cce853e59fb7d0a1c20064444c8e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Add the sender address to responses for a multicast requestSona Kurazyan2019-03-111-3/+5
| | | | | | | | | | | For the responses to multicast requests the address of the sender of the reply does not match with the host address in the request URI. There should be a way to find out who has sent the response. Change-Id: Icbc6c6ae926198870dbc7dbbb92dc319c46d7de7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Move resourcesFromCoreLinkList() where it fits betterSona Kurazyan2019-03-061-43/+0
| | | | | Change-Id: I930f53462598fd7019da2144ddf1bf04dc5930c8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Code cleanup: replace int by uint, where it makes senseSona Kurazyan2019-03-051-25/+15
| | | | | | | | This saves us several checks and "static_cast"s. Change-Id: I81e2253929f1fe0a7a052e8c2988e28229b0c9db Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Improve the documentation and fix warningsSona Kurazyan2019-03-051-2/+37
| | | | | | | Change-Id: I9b26337ba976079608ece4781999ad0ef49a4f19 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Change QtCoap to be a namespace and improve the docsSona Kurazyan2019-03-041-4/+4
| | | | | | | | | | | | | - QtCoap was changed to be a namespace instead of a class. - Moved the static QtCoap::randomGenerator to a method returning a reference to a local static object. - The corresponding documentation and function definitions were moved to its .cpp file. - Added the missing documentation. Change-Id: Ie0c60189b18b8f5e8d9a94f91b6fb7b9259984dd Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Add support for multicast CoAP requestsSona Kurazyan2019-02-211-8/+70
| | | | | | | Change-Id: I9cf6d4f97c863c232b17bc8e560c6b62c3f39624 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Do not override the request token, if it was set beforeSona Kurazyan2019-02-151-1/+2
| | | | | | | | | | | | Currently the request token is generated randomly, and even if the user sets a token to the request, it is being overridden. It makes sense to allow users to provide the desired token. This is also useful for unit tests. Change-Id: Ia45ec70a1eaa125bcd35e00fa2cce753d081ab9d Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Introduce timeouts needed for multicast requestsSona Kurazyan2019-02-141-0/+42
| | | | | Change-Id: I7abb22364531af43e0ab4f10436f0b787cd36291 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Add API for canceling observe for the given URLSona Kurazyan2019-02-051-2/+21
| | | | | Change-Id: Idb84601dd8f1d8c011ecccd95c0e65e77920bd11 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Interface cleanupSona Kurazyan2019-02-051-21/+13
| | | | | | | | | - restrict access to QCoapProtocol::cancelObserve slot - fixed const-correctness of QCoapProtocolPrivate - removed unnecessary QCoapProtocolPrivate::encode method Change-Id: I63948418e21708526c11b9608baba60e0e6d3532 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Use function pointer syntax for connect statementsSona Kurazyan2019-02-051-5/+16
| | | | | Change-Id: I0fe67e7307f67543f0c63a5be46b92f2dd074d45 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Add DTLS support to CoAP implementationv5.13.0-alpha1Sona Kurazyan2019-01-301-15/+18
| | | | | | | | | | | | | | | | | | | | | | | | | Added transport layer security based on QDtls. This implementation supports authentication using pre-shared keys and X.509 certificates. Split the QCoapConnection class into a base class to be shared with other transports and a specialized class that relies on QUdpSocket using QDtls for security. Note, that raw public key mode (which is mandatory to implement according to RFC) is not implemented yet, since the underlying OpenSSL library does not support it yet. However, if we later decide to integrate another DTLS implementation, it can be done with minimal changes, by having the new implementations's connection type inherit the QCoapConnection class, which hides the implementation of the transport layer. Tests and examples will be added in a later commit. Change-Id: I14b34a9fd978e1993e86d47becbeed74397d1d6e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Add the CoAP module, providing a client for QtAdrien Leravat2018-12-141-0/+992
Features: - Send GET/POST/PUT/DELETE requests - Discover resources (single server) - Observe resources and cancel the observation - Blockwise requests and replies - Requests (and replies) can be confirmable or non-confirmable - Some options can be added to the request - Replies can be received in a separate or piggybacked message Change-Id: I31e0e20a4f19bdc6d6489281fde73a4ff848eda4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>