-
Notifications
You must be signed in to change notification settings - Fork 5
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
nanocoap: added function for finding options #18
nanocoap: added function for finding options #18
Conversation
@kaspar030: ping |
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.
minor comments...
nanocoap/nanocoap.c
Outdated
@@ -369,3 +377,65 @@ ssize_t coap_well_known_core_default_handler(coap_pkt_t* pkt, uint8_t *buf, \ | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, forgot the static. Will do both.
nanocoap/nanocoap.c
Outdated
return len; | ||
} | ||
|
||
int parse_opt(uint8_t *optpos, coap_opt_t *opt) |
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.
static, too?
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.
yes.
|
||
uint16_t delta = 0; | ||
|
||
do { |
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.
Can we add packet length checks here? Seems like a bogus header leads to crashes here.
nanocoap/nanocoap.h
Outdated
@@ -172,6 +180,8 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t * | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other public functions carry "option" written out, so maybe rename?
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.
will do.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might read past packet length
return -1; | ||
} | ||
|
||
opt->val += _decode_optlen(opt->val, &opt->delta); |
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.
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_PATH
in 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...