mirror of
https://github.com/espressif/openthread.git
synced 2026-08-12 21:57:47 +00:00
[tmf] validate method as POST centrally in resource handlers (#12661)
This commit updates the central CoAP resource handlers in TMF agents (`Agent::HandleResource`, `BackboneTmfAgent::HandleResource`, and `Manager::CoapDtlsSession::HandleResource`) to verify that the incoming request method is a POST request. If the URI is recognized but the method is not POST, a `kCodeMethodNotAllowed` response is now sent. Since all TMF requests are now guaranteed to be POST requests before reaching their specific handlers, the `IsPostRequest()` checks in individual handlers are removed. Additionally, the `IsConfirmablePostRequest()` and `IsNonConfirmablePostRequest()` helper methods in `Coap::Message` are removed and their usages are simplified to `IsConfirmable()` and `IsNonConfirmable()` in the respective handlers.
This commit is contained in:
@@ -72,6 +72,12 @@ bool Agent::HandleResource(const char *aUriPath, Msg &aMsg)
|
||||
bool didHandle = true;
|
||||
Uri uri = UriFromPath(aUriPath);
|
||||
|
||||
if ((uri != kUriUnknown) && !aMsg.IsPostRequest())
|
||||
{
|
||||
IgnoreError(SendAckResponse(aMsg, ot::Coap::kCodeMethodNotAllowed));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
#define Case(kUri, Type) \
|
||||
case kUri: \
|
||||
Get<Type>().HandleTmf<kUri>(aMsg); \
|
||||
@@ -159,6 +165,7 @@ bool Agent::HandleResource(const char *aUriPath, Msg &aMsg)
|
||||
|
||||
#undef Case
|
||||
|
||||
exit:
|
||||
return didHandle;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user