Merge pull request #13688 from bergzand/pr/suit/cleanup_subtree

suit/transport/coap: Make use of exposed tree handler function
This commit is contained in:
Francisco 2020-03-24 11:44:52 +01:00 committed by GitHub
commit 3a4048d05e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 31 deletions

View File

@ -79,8 +79,8 @@ void suit_coap_run(void);
* *
* @returns ssize_t Size of the reply * @returns ssize_t Size of the reply
*/ */
ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf,
void *context); size_t len, void *context);
/** /**
* @brief Type for CoAP resource subtrees * @brief Type for CoAP resource subtrees

View File

@ -101,35 +101,9 @@ static kernel_pid_t _suit_coap_pid;
ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
void *context) void *context)
{ {
uint8_t uri[NANOCOAP_URI_MAX]; coap_resource_subtree_t *subtree = context;
return coap_tree_handler(pkt, buf, len, subtree->resources,
unsigned method_flag = coap_method2flag(coap_get_code_detail(pkt)); subtree->resources_numof);
if (coap_get_uri_path(pkt, uri) > 0) {
coap_resource_subtree_t *subtree = context;
for (unsigned i = 0; i < subtree->resources_numof; i++) {
const coap_resource_t *resource = &subtree->resources[i];
if (!(resource->methods & method_flag)) {
continue;
}
int res = coap_match_path(resource, uri);
if (res > 0) {
continue;
}
else if (res < 0) {
break;
}
else {
return resource->handler(pkt, buf, len, resource->context);
}
}
}
return coap_reply_simple(pkt, COAP_CODE_INTERNAL_SERVER_ERROR, buf,
len, COAP_FORMAT_TEXT, NULL, 0);
} }
static inline uint32_t _now(void) static inline uint32_t _now(void)