mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-23 07:35:13 +03:00
options: Update documentation and fix incorrect function usage
Correct documented return values from changes back in 2015 for option filter checking (option numbers could only be 1 byte then). Correct code in coap_option_next() that assumed one of the defunct return values.
This commit is contained in:
1 parent
d8d9101f9c
commit
8a40fcc4aa
3 files changed
+19
-34
No files matched your search
+7
-11
@@ -153,7 +153,6 @@ coap_option_next(coap_opt_iterator_t *oi) {
|
||||
coap_option_t option;
|
||||
coap_opt_t *current_opt = NULL;
|
||||
size_t optsize;
|
||||
int b; /* to store result of coap_option_getb() */
|
||||
|
||||
assert(oi);
|
||||
|
||||
@@ -161,13 +160,15 @@ coap_option_next(coap_opt_iterator_t *oi) {
|
||||
return NULL;
|
||||
|
||||
while (1) {
|
||||
/* oi->option always points to the next option to deliver; as
|
||||
/* oi->next_option always points to the next option to deliver; as
|
||||
* opt_finished() filters out any bad conditions, we can assume that
|
||||
* oi->option is valid. */
|
||||
* oi->next_option is valid. */
|
||||
current_opt = oi->next_option;
|
||||
|
||||
/* Advance internal pointer to next option, skipping any option that
|
||||
* is not included in oi->filter. */
|
||||
/*
|
||||
* Advance internal pointer to next option.
|
||||
* optsize will be 0 when no more options
|
||||
*/
|
||||
optsize = coap_opt_parse(oi->next_option, oi->length, &option);
|
||||
if (optsize) {
|
||||
assert(optsize <= oi->length);
|
||||
@@ -184,15 +185,10 @@ coap_option_next(coap_opt_iterator_t *oi) {
|
||||
/* Exit the while loop when:
|
||||
* - no filtering is done at all
|
||||
* - the filter matches for the current option
|
||||
* - the filter is too small for the current option number
|
||||
*/
|
||||
if (!oi->filtered ||
|
||||
(b = coap_option_filter_get(&oi->filter, oi->number)) > 0)
|
||||
coap_option_filter_get(&oi->filter, oi->number) > 0)
|
||||
break;
|
||||
else if (b < 0) { /* filter too small, cannot proceed */
|
||||
oi->bad = 1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return current_opt;
|
||||
|
||||
@@ -684,13 +684,6 @@ coap_option_check_critical(coap_session_t *session,
|
||||
coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL);
|
||||
|
||||
while (coap_option_next(&opt_iter)) {
|
||||
|
||||
/* The following condition makes use of the fact that
|
||||
* coap_option_getb() returns -1 if type exceeds the bit-vector
|
||||
* filter. As the vector is supposed to be large enough to hold
|
||||
* the largest known option, we know that everything beyond is
|
||||
* bad.
|
||||
*/
|
||||
if (opt_iter.number & 0x01) {
|
||||
/* first check the known built-in critical options */
|
||||
switch (opt_iter.number) {
|
||||
@@ -726,10 +719,10 @@ coap_option_check_critical(coap_session_t *session,
|
||||
coap_log(LOG_DEBUG, "unknown critical option %d\n", opt_iter.number);
|
||||
ok = 0;
|
||||
|
||||
/* When opt_iter.number is beyond our known option range,
|
||||
* coap_option_filter_set() will return -1 and we are safe to leave
|
||||
* this loop. */
|
||||
if (coap_option_filter_set(unknown, opt_iter.number) == -1) {
|
||||
/* When opt_iter.number cannot be set in unknown, all of the appropriate
|
||||
* slots have been used up and no more options can be tracked.
|
||||
* Safe to break out of this loop as ok is already set. */
|
||||
if (coap_option_filter_set(unknown, opt_iter.number) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user