net/gcoap: expose creation of resource list to API#7408
net/gcoap: expose creation of resource list to API#7408miri64 merged 2 commits intoRIOT-OS:masterfrom
Conversation
a0a00f5 to
fa303d3
Compare
kb2ma
left a comment
There was a problem hiding this comment.
Works for me when buf not null.
| for (unsigned i = 0; i < listener->resources_len; i++) { | ||
| size_t path_len = strlen(resource->path); | ||
| /* only add new resources if there is space in the buffer */ | ||
| if ((pos + path_len + 3) > maxlen) { |
There was a problem hiding this comment.
Function spec says maxlen ignored if buf is NULL.
| } | ||
| else { | ||
| out += (i) ? 3 : 2; | ||
| out += path_len; |
There was a problem hiding this comment.
Maybe we want to increment pos here? ;-)
|
Also, what is the value of returning only the length of the resource list without also providing the content? |
|
It also should be straightforward to write a unit test for this new function since no packet exchange is required. |
The idea was to be able to find out the length of the resulting string so one can allocate/provide a sufficient buffer later (same principle as applied for the
Didn't seem that simple to me, though I have not really looked into it more than 30s... Will look some seconds more and see what I can do :-) |
|
added unittests |
|
Thanks for the unit test and the rationale on returning only the length of the contents. The more I think about this function, it seems valuable to ensure a client can retrieve the entire list. I wonder if it would be more useful to recast it like this: where index is into the list of resources. This way buf doesn't need to be so big, and the client is guaranteed to be able to increment through all of the resources. The function can return some flag value like GCOAP_END_OF_RESOURCES when done. This approach would mesh well with CoAP block support for a /.well-known/core request. |
|
I have been thinking the same, but came to the conclusion that I wanted to keep the function straight forward in the first round and add this 'advanced' buffer handling later. I actually expect this function to change/advance anyway in the near future, as I am looking into ways to specify more context information about the resources (e.g. void gcoap_init_reslist(gcoap_reslist_ctx_t *ctx, size_t blocksize, unsigned block_num, uint8_t cf);
int gcoap_read_reslist(gcoap_reslist_ctx-t *ctx, void *buf);But anyway: I would like to put this on the (ever growing) 'lets-improve-later' list if that is alright with you. |
|
Sounds good. ACK on this PR. |
Creating the resource list is useful outside the /.well-known/core handler, e.g. for the registration to resource directories.
75cf78a to
813c92e
Compare
|
awesome. Fixed typo in doxygen and squashed -> Murdock should be happy now. |
Creating the resource list is useful outside the /.well-known/core
handler, e.g. for the registration to resource directories.