mirror of
https://github.com/espressif/openthread.git
synced 2026-08-02 00:57:47 +00:00
[coap] simplify Coap::Message implementation (#12313)
This change simplifies the `Coap::Message` implementation and removes the fragile `HelpData` struct which was used to cache header information within reserved portion of message. The `Coap::Msg` class is updated to hold the parsed CoAP header information (type, code, message ID, token). It now inherits from a new `HeaderInfo` class which contains the parsed fields. This change helps to simplify many of the call sites which previously had to parse the header information themselves. The key changes are: - The `HelpData` struct is removed from `Coap::Message`. - `Coap::Msg` is updated to track parsed header info in `HeaderInfo`. - `otCoapMessageInit()` and `otCoapMessageInitResponse()` now return an `otError`. - Methods are renamed to harmonize their names. - A new unit test `test_coap_message.cpp` is added to verify the `Coap::Message` implementation.
This commit is contained in:
@@ -557,7 +557,7 @@ void DuaManager::HandleDuaResponse(Coap::Message *aMessage, Error aResult)
|
||||
VerifyOrExit(aResult == kErrorNone, error = kErrorParse);
|
||||
OT_ASSERT(aMessage != nullptr);
|
||||
|
||||
VerifyOrExit(aMessage->GetCode() == Coap::kCodeChanged || aMessage->GetCode() >= Coap::kCodeBadRequest,
|
||||
VerifyOrExit(aMessage->ReadCode() == Coap::kCodeChanged || aMessage->ReadCode() >= Coap::kCodeBadRequest,
|
||||
error = kErrorParse);
|
||||
|
||||
error = ProcessDuaResponse(*aMessage);
|
||||
@@ -575,9 +575,9 @@ template <> void DuaManager::HandleTmf<kUriDuaRegistrationNotify>(Coap::Msg &aMs
|
||||
{
|
||||
Error error;
|
||||
|
||||
VerifyOrExit(aMsg.mMessage.IsPostRequest(), error = kErrorParse);
|
||||
VerifyOrExit(aMsg.IsPostRequest(), error = kErrorParse);
|
||||
|
||||
if (aMsg.mMessage.IsConfirmable() && Get<Tmf::Agent>().SendEmptyAck(aMsg) == kErrorNone)
|
||||
if (aMsg.IsConfirmable() && Get<Tmf::Agent>().SendEmptyAck(aMsg) == kErrorNone)
|
||||
{
|
||||
LogInfo("Sent %s ack", UriToString<kUriDuaRegistrationNotify>());
|
||||
}
|
||||
@@ -595,7 +595,7 @@ Error DuaManager::ProcessDuaResponse(Coap::Message &aMessage)
|
||||
Ip6::Address target;
|
||||
uint8_t status;
|
||||
|
||||
if (aMessage.GetCode() >= Coap::kCodeBadRequest)
|
||||
if (aMessage.ReadCode() >= Coap::kCodeBadRequest)
|
||||
{
|
||||
status = kDuaGeneralFailure;
|
||||
target = mRegisteringDua;
|
||||
|
||||
Reference in New Issue
Block a user