-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/gcoap: add Uri-Query strings for requests #7402
net/gcoap: add Uri-Query strings for requests #7402
Conversation
added missing qs buffer initialization |
b4390d7
to
5e58982
Compare
Here is an idea for a somewhat lower level approach to this implementation. We assume there is no intrinsic value to gcoap in storage of the URL-encoded query string in With this approach, gcoap_add_qstring() uses coap_put_option() to append each encoded option to Then in _write_options(), one more adaptation required -- fixing the option number delta for the first option in
So, in _write_options() first call coap_get_opt_hdr() on qs to get the length of the first option. Then call coap_put_opt_hdr() on the PDU buf, using this length. Finally memcpy On the receiving side, use the new coap_find_opt() in nanocoap #18 to read out the query values directly from the packet buf. So then, with this approach the rework to coap_put_option_url() in nanocoap #16 becomes unnecessary. We could even take this implementation another step and eliminate With this extension we can eliminate nanocoap #16 altogether. The real beauty here is that the use of the url buffer for its original purpose it not affected because the url and the Uri-Query options are separated by \0 bytes. We just need to be sure they don't overlap. |
I agree that we can quite significantly optimize this PR (and some other parts with it). I would actually go so far as to remove the 'special' handling of the Uri-Query and the Uri-Path option all together and unify everything down to one set of generic option handling functions (probably as port of nanocaop), and maybe only extend this with some optional, user friendly access function(s) in My problem is only, that this type of refactoring will take a (little) while, stalling the merger of all the RD related code. So I would like to request if we could merge my current proposal like this (with all its drawbacks), and optimize the whole option handling as the next step. |
I look forward to the proposal for generic improvements to option handling. At the same time, I am disappointed to see the addition of a 64-byte array to coap_pkt_t, and hope its life is short. I will review this PR ASAP from that perspective. |
I suggest limiting GCOAP_REQ_OPTIONS_BUF to 40 bytes. My concern is with a PUT or a POST over 802.15.4. gcoap_req_init() allows a payload length reduced by the size of the header, the path, and this options buf value. Let's assume 128 - 6 (header+token) - 10 (path option) = 112. Then 112 - 48 (options) = 64 bytes for the payload. For the payload, I think 64 bytes is the minimum acceptable, to support a power-of-2 block transfer. Ideally I would want to support 80 bytes for the payload without a block option, assuming we have header compression. So, I think 48 bytes is too generous on the options side, and would cut that back a bit. The other option is to extend GCOAP_PDU_BUF_SIZE larger than 128. I don't feel really strongly about this change though -- just putting it out there for feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on native. Code is clear, and nice comment for the function. Also, consider referencing the new function in the 'Creating a request' section of the module documentation.
sys/include/net/gcoap.h
Outdated
@@ -633,6 +633,20 @@ size_t gcoap_obs_send(const uint8_t *buf, size_t len, | |||
*/ | |||
uint8_t gcoap_op_state(void); | |||
|
|||
/** | |||
* @brief Add Uri-Query options to a CoAP request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest "Adds a Uri-Query option..." I have used the 3rd person verb rather than the 2nd person imperative form for other gcoap commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, fixed.
sys/include/net/gcoap.h
Outdated
/** | ||
* @brief Add Uri-Query options to a CoAP request | ||
* | ||
* @param[out] pkt The package that is being build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest naming the variable 'pdu', to be consistent with other gcoap functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@@ -473,7 +474,14 @@ static ssize_t _write_options(coap_pkt_t *pdu, uint8_t *buf, size_t len) | |||
if (pdu->content_type != COAP_FORMAT_NONE) { | |||
bufpos += coap_put_option_ct(bufpos, last_optnum, pdu->content_type); | |||
/* uncomment when add an option after Content-Format */ | |||
/* last_optnum = COAP_OPT_CONTENT_FORMAT; */ | |||
last_optnum = COAP_OPT_CONTENT_FORMAT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
87ceb49
to
f24f4b5
Compare
rebased, fixed comments, and switched nanocoap pkg to newest commit. |
Thanks for those updates. The only open question for me then is your reaction to my comment above on the size of GCOAP_REQ_OPTIONS_BUF relative to the remaining payload size. |
08a6d24
to
9f13395
Compare
Oh sorry, slipped through yesterday. Changed |
I'll ACK to that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proxy-ACK, but please rebase.
9f13395
to
0c659c6
Compare
done |
0c659c6
to
8f577ec
Compare
all green -> go |
Needs kaspar030/sock#16 merged to work...This PR adds means to
gcoap
for adding query strings (Uri-Query options) to any given CoAP request. The functionality is split and partly placed innanocoap
.The usage is very simple, e.g.:
will result in: