1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #18651 from benpicco/gcoap-footgun

gcoap: accept resources in any order
This commit is contained in:
benpicco 2022-09-28 10:48:51 +02:00 committed by GitHub
commit e9b5bd712c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 17 deletions

View File

@ -750,8 +750,7 @@ typedef struct {
* @brief A modular collection of resources for a server
*/
struct gcoap_listener {
const coap_resource_t *resources; /**< First element in the array of
* resources; must order alphabetically */
const coap_resource_t *resources; /**< First element in the array of resources */
size_t resources_len; /**< Length of array */
/**
* @brief Transport type for the listener

View File

@ -744,13 +744,9 @@ static int _request_matcher_default(gcoap_listener_t *listener,
int res = coap_match_path(*resource, uri);
/* URI mismatch */
if (res > 0) {
if (res != 0) {
continue;
}
/* resources expected in alphabetical order */
else if (res < 0) {
break;
}
/* potential match, check for method */
if (! ((*resource)->methods & method_flag)) {

View File

@ -454,18 +454,14 @@ ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
}
int res = coap_match_path(resource, uri);
if (res > 0) {
if (res != 0) {
continue;
}
else if (res < 0) {
break;
}
else {
coap_request_ctx_t ctx = {
.resource = resource,
};
return resource->handler(pkt, resp_buf, resp_buf_len, &ctx);
}
coap_request_ctx_t ctx = {
.resource = resource,
};
return resource->handler(pkt, resp_buf, resp_buf_len, &ctx);
}
return coap_build_reply(pkt, COAP_CODE_404, resp_buf, resp_buf_len, 0);