nanocoap: allow coap_opt_add_string() for non-zero-terminated strings#13818
nanocoap: allow coap_opt_add_string() for non-zero-terminated strings#13818kb2ma merged 2 commits intoRIOT-OS:masterfrom
Conversation
benpicco
left a comment
There was a problem hiding this comment.
Looks pretty straightforward - would make sense to also add coap_opt_add_uri_path_chars() so applications can make use of this too.
kb2ma
left a comment
There was a problem hiding this comment.
Straightforward addition. Good idea to add a unit test.
kb2ma
left a comment
There was a problem hiding this comment.
Meant to mark as requesting changes.
|
At least in my mind, the intention is to add option(s) with a string
data type, not opaque.
Well, if it's not null-terminated, it's not a string at the API level.
|
|
Does CoAP require it to be an (ASCII) string or could we also add binary data here? |
|
The function works for every option, and some options take binary data (typically used with In the concrete place where it's being introduced for (path components and query parameters of a CoAP URI), it's arbitrary UTF-8 that may contain any code points. (Using a function like coap_opt_add_chars rules out one of them unless the delimiter is 0xff or some other byte invalid in UTF-8). |
|
Let me summarize the conversation to this point. To be clear, when I mention a String option or Opaque option, I mean them as described in sec. 3.2 of 7252 on option value formats. Originally, this PR intended to extend So, the question then is do we want to extend/publish this function to allow writing multiple Opaque options as well as multiple String options? Or perhaps it would be more useful to create a separate function to add multiple Opaque options more tailored to that use case. For example, it might be better to use a size_t array to identify the starting offset for each embedded Opaque value within the buffer so we don't eliminate use of a particular character. At the same time, someone could still use |
|
@kb2ma thanks for the feedback! I added two new fixup commits to address your comments. @benpicco I think we should keep this PR small and clean. We could add
Hm, I am a little bit indifferent about the naming here. I do not see a use case for a generic function that adds opaque values and at the same time includes the feature to split the buffer at a specific character (e.g., '/'). I had a quick look at the available CoAP options and I could not find a scenario, where such a function would be beneficial (although, this doesn't mean that such an option wouldn't be defined in future specs). |
|
Fixups look good. I think this PR is ready to merge, but I'll wait a couple of days for any other feedback before approving. If someone wants to use |
|
@cgundogan, I just noticed Travis found an unused variable. |
66f24ea to
4533c1b
Compare
4533c1b to
ecc4932
Compare
|
@kb2ma I fixed the unused variable warning, squashed all commits and triggered murdock. Let's wait for the outcome. |
|
Murdock and Travis agree (: |
|
Excellent, I'll take one more look to be sure we're good. |
|
thanks for the review @kb2ma ! (: |
Contribution description
The current nanocoap API allows to add a path using the convenient
coap_opt_add_string()function. The path is then split into multiple CoAP options. However, this function requires the path to be zero-terminated, which is quite inconvenient when dealing with buffers.This PR adds
coap_opt_add_chars(), which takes a character array and the length of the desired string as input.coap_opt_add_string()is modified to callcoap_opt_add_chars()withstrlen()as input.Testing procedure
The unittests should run for the existing
coap_opt_add_string()test cases, and for the newly introducedcoap_opt_add_chars()test case (at the very end of the unittest file).Issues/PRs references
This is a cutout of #13790