nanocoap: added function for finding options#18
nanocoap: added function for finding options#18haukepetersen wants to merge 3 commits intokaspar030:masterfrom
Conversation
|
@kaspar030: ping |
nanocoap/nanocoap.c
Outdated
| return coap_build_reply(pkt, COAP_CODE_205, buf, len, payload_len); | ||
| } | ||
|
|
||
| size_t get_lenval(uint8_t *buf, uint16_t *val) |
There was a problem hiding this comment.
make static, add underscore, maybe rename to "_decode_optlen" to be in line with the other coap decode functions?
There was a problem hiding this comment.
yes, forgot the static. Will do both.
nanocoap/nanocoap.c
Outdated
| return len; | ||
| } | ||
|
|
||
| int parse_opt(uint8_t *optpos, coap_opt_t *opt) |
|
|
||
| uint16_t delta = 0; | ||
|
|
||
| do { |
There was a problem hiding this comment.
Can we add packet length checks here? Seems like a bogus header leads to crashes here.
nanocoap/nanocoap.h
Outdated
| size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type); | ||
| size_t coap_put_option_url(uint8_t *buf, uint16_t lastonum, const char *url); | ||
|
|
||
| uint8_t *coap_find_opt(coap_pkt_t *pkt, uint8_t *bufpos, coap_opt_t *opt, uint16_t optnum); |
There was a problem hiding this comment.
the other public functions carry "option" written out, so maybe rename?
|
I'm trying to use your For the context, I'm implementing block2 support (rfc7959). Before constructing the packet payload I insert a block2 header. This header consists of a block number (known), a size exponent (known) and a "more" bit flag. This more bit flag is set if there are more blocks following the current block. I currently set this flag if the payload of the reply exceeds the current block. This flag thus have to be adjusted after the payload is added and I would like to use the So at that moment a |
0ca72be to
ca04f1e
Compare
|
@kaspar030 fixed your remarks, better now? |
|
@bergzand yes, that makes sense ineed: see last commit |
yes! (I guess we leave the size validity check for later?) |
why? It should be fixed now, is it not? |
|
I thought the check in line 428 is doing that?! |
| len = 1; | ||
| } | ||
| else if (*val == 14) { | ||
| memcpy(val, buf, 2); |
There was a problem hiding this comment.
this might read past packet length
| return -1; | ||
| } | ||
|
|
||
| opt->val += _decode_optlen(opt->val, &opt->delta); |
There was a problem hiding this comment.
through _decode_optlen(), this might read past the packet
|
For |
|
Ah, I see... |
|
@haukepetersen @kaspar030 would love to see this in ;) |
|
closing in favor of #8920 and #8772 |
After receiving a packet, I needed to be able to read out certain options (
COAP_OPT_LOCATION_PATHin my case), and to copy their content into some user defined buffers. This was not able with the current interface, so I added a function that allows for finding certain options.The usage is quite easy (I hope):
With this function one can read ANY option and do with its values whatever they like...