Skip to content

Commit

Permalink
nanocoap: change method flag type to uint32_t
Browse files Browse the repository at this point in the history
  • Loading branch information
bergzand committed Sep 9, 2019
1 parent dbd97b7 commit 4d399bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern "C" {

/**
* @name Nanocoap specific CoAP method flags used in coap_handlers array
* @anchor nanocoap_method_flags
* @{
*/
#define COAP_GET (0x1)
Expand Down Expand Up @@ -197,12 +198,19 @@ typedef struct {
*/
typedef ssize_t (*coap_handler_t)(coap_pkt_t *pkt, uint8_t *buf, size_t len, void *context);

/**
* @brief Method flag type
*
* Must be large enough to contain all @ref nanocoap_method_flags "CoAP method flags"
*/
typedef uint16_t coap_method_flags_t;

/**
* @brief Type for CoAP resource entry
*/
typedef struct {
const char *path; /**< URI path of resource */
unsigned methods; /**< OR'ed methods this resource allows */
coap_method_flags_t methods; /**< OR'ed methods this resource allows */
coap_handler_t handler; /**< ptr to resource handler */
void *context; /**< ptr to user defined context data */
} coap_resource_t;
Expand Down Expand Up @@ -1153,7 +1161,7 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
*
* @returns bit field corresponding to the given request method
*/
static inline unsigned coap_method2flag(unsigned code)
static inline coap_method_flags_t coap_method2flag(unsigned code)
{
return (1 << (code - 1));
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
return coap_build_reply(pkt, COAP_CODE_EMPTY, resp_buf, resp_buf_len, 0);
}

unsigned method_flag = coap_method2flag(coap_get_code_detail(pkt));
coap_method_flags_t method_flag = coap_method2flag(coap_get_code_detail(pkt));

uint8_t uri[NANOCOAP_URI_MAX];
if (coap_get_uri_path(pkt, uri) <= 0) {
Expand Down

0 comments on commit 4d399bf

Please sign in to comment.