Skip to content

Commit

Permalink
Merge pull request #20191 from benpicco/coap_get_method
Browse files Browse the repository at this point in the history
nanocoap: introduce coap_get_method()
  • Loading branch information
benpicco authored Mar 19, 2024
2 parents 3ebccd7 + 446509c commit e3ce765
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ static inline unsigned coap_get_code_raw(const coap_pkt_t *pkt)
return (unsigned)pkt->hdr->code;
}

/**
* @brief Get a request's method type
*
* @param[in] pkt CoAP request packet
*
* @returns request method type
*/
static inline coap_method_t coap_get_method(const coap_pkt_t *pkt)
{
return pkt->hdr->code;
}

/**
* @brief Get the message ID of the given CoAP packet
*
Expand Down
4 changes: 2 additions & 2 deletions sys/net/application_layer/nanocoap/fileserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static ssize_t _delete_file(coap_pkt_t *pdu, uint8_t *buf, size_t len,
static ssize_t nanocoap_fileserver_file_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len,
struct requestdata *request)
{
switch (coap_get_code_raw(pdu)) {
switch (coap_get_method(pdu)) {
case COAP_METHOD_GET:
return _get_file(pdu, buf, len, request);
#if IS_USED(MODULE_NANOCOAP_FILESERVER_PUT)
Expand Down Expand Up @@ -568,7 +568,7 @@ static ssize_t nanocoap_fileserver_directory_handler(coap_pkt_t *pdu, uint8_t *b
struct requestdata *request,
const char *root, const char* resource_dir)
{
switch (coap_get_code_raw(pdu)) {
switch (coap_get_method(pdu)) {
case COAP_METHOD_GET:
return _get_directory(pdu, buf, len, request, root, resource_dir);
#if IS_USED(MODULE_NANOCOAP_FILESERVER_PUT)
Expand Down

0 comments on commit e3ce765

Please sign in to comment.