From e2e783033ca41a29eb506ab9d9e7aacc4e720d50 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Wed, 16 Dec 2020 12:29:11 +0000 Subject: [PATCH] coap_opt_filter_t: Make it a proper structure Update coap_opt_filter_t to be a structure rather than a 16bit array that is aliased with the real structure format. Update code to use pointers where appropriate. --- examples/coap-server.c | 2 +- examples/etsi_iot_01.c | 14 ++--- include/coap2/net.h | 6 +- include/coap2/option.h | 50 ++++++---------- include/coap2/pdu.h | 2 +- src/block.c | 6 +- src/net.c | 24 ++++---- src/option.c | 32 +++++------ src/pdu.c | 2 +- src/uri.c | 16 +++--- tests/test_error_response.c | 46 +++++++-------- tests/test_options.c | 112 ++++++++++++++++++------------------ 12 files changed, 145 insertions(+), 167 deletions(-) diff --git a/examples/coap-server.c b/examples/coap-server.c index cea65967..0234746f 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -319,7 +319,7 @@ hnd_get_async(coap_context_t *ctx, if (async) { if (async->id != request->tid) { coap_opt_filter_t f; - coap_option_filter_clear(f); + coap_option_filter_clear(&f); response->code = COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE; } return; diff --git a/examples/etsi_iot_01.c b/examples/etsi_iot_01.c index c87b5523..fc5a6cb4 100644 --- a/examples/etsi_iot_01.c +++ b/examples/etsi_iot_01.c @@ -341,10 +341,10 @@ hnd_get_query(coap_context_t *ctx UNUSED_PARAM, COAP_MEDIATYPE_TEXT_PLAIN), buf); - coap_option_filter_clear(f); - coap_option_filter_set(f, COAP_OPTION_URI_QUERY); + coap_option_filter_clear(&f); + coap_option_filter_set(&f, COAP_OPTION_URI_QUERY); - coap_option_iterator_init(request, &opt_iter, f); + coap_option_iterator_init(request, &opt_iter, &f); len = 0; while ((len < sizeof(buf)) && (q = coap_option_next(&opt_iter))) { @@ -379,17 +379,17 @@ hnd_get_separate(coap_context_t *ctx, if (async) { if (async->id != request->tid) { - coap_option_filter_clear(f); + coap_option_filter_clear(&f); response->code = COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE; } return; } /* search for option delay in query list */ - coap_option_filter_clear(f); - coap_option_filter_set(f, COAP_OPTION_URI_QUERY); + coap_option_filter_clear(&f); + coap_option_filter_set(&f, COAP_OPTION_URI_QUERY); - coap_option_iterator_init(request, &opt_iter, f); + coap_option_iterator_init(request, &opt_iter, &f); while ((option = coap_option_next(&opt_iter))) { if (strncmp("delay=", (const char *)coap_opt_value(option), 6) == 0) { diff --git a/include/coap2/net.h b/include/coap2/net.h index 6d8cdd73..c1df5d92 100644 --- a/include/coap2/net.h +++ b/include/coap2/net.h @@ -282,7 +282,7 @@ coap_register_pong_handler(coap_context_t *context, */ COAP_STATIC_INLINE void coap_register_option(coap_context_t *ctx, uint16_t type) { - coap_option_filter_set(ctx->known_options, type); + coap_option_filter_set(&ctx->known_options, type); } /** @@ -456,7 +456,7 @@ void *coap_get_app_data(const coap_context_t *context); */ coap_pdu_t *coap_new_error_response(coap_pdu_t *request, unsigned char code, - coap_opt_filter_t opts); + coap_opt_filter_t *opts); /** * Sends an error response with code @p code for request @p request to @p dst. @@ -476,7 +476,7 @@ coap_pdu_t *coap_new_error_response(coap_pdu_t *request, coap_tid_t coap_send_error(coap_session_t *session, coap_pdu_t *request, unsigned char code, - coap_opt_filter_t opts); + coap_opt_filter_t *opts); /** * Helper function to create and send a message with @p type (usually ACK or diff --git a/include/coap2/option.h b/include/coap2/option.h index 6c95ac45..d835b961 100644 --- a/include/coap2/option.h +++ b/include/coap2/option.h @@ -88,34 +88,18 @@ size_t coap_opt_size(const coap_opt_t *opt); #error COAP_OPT_FILTER_SHORT + COAP_OPT_FILTER_LONG must be less or equal 16 #endif /* (COAP_OPT_FILTER_SHORT + COAP_OPT_FILTER_LONG > 16) */ -/** The number of elements in coap_opt_filter_t. */ -#define COAP_OPT_FILTER_SIZE \ - (((COAP_OPT_FILTER_SHORT + 1) >> 1) + COAP_OPT_FILTER_LONG) +1 - -/** - * Fixed-size vector we use for option filtering. It is large enough - * to hold COAP_OPT_FILTER_SHORT entries with an option number between - * 0 and 255, and COAP_OPT_FILTER_LONG entries with an option number - * between 256 and 65535. Its internal structure is - * - * @code -struct { +/* + * mask contains a bit vector that indicates which fields in the long_opts[] + * and subsequent short_opts[] are used. The first COAP_OPT_FILTER_LONG bits + * correspond to the long option types that are stored in long_opts[] + * elements. The next COAP_OPT_FILTER_SHORT bits correspond to the short + * option types that are stored in short_opts[]. + */ +typedef struct coap_opt_filter_t { uint16_t mask; uint16_t long_opts[COAP_OPT_FILTER_LONG]; uint8_t short_opts[COAP_OPT_FILTER_SHORT]; -} - * @endcode - * - * The first element contains a bit vector that indicates which fields - * in the remaining array are used. The first COAP_OPT_FILTER_LONG - * bits correspond to the long option types that are stored in the - * elements from index 1 to COAP_OPT_FILTER_LONG. The next - * COAP_OPT_FILTER_SHORT bits correspond to the short option types - * that are stored in the elements from index COAP_OPT_FILTER_LONG + 1 - * to COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT. The latter - * elements are treated as bytes. - */ -typedef uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]; +} coap_opt_filter_t; /** Pre-defined filter that includes all options. */ #define COAP_OPT_ALL NULL @@ -126,7 +110,7 @@ typedef uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]; * @param f The filter to clear. */ COAP_STATIC_INLINE void -coap_option_filter_clear(coap_opt_filter_t f) { +coap_option_filter_clear(coap_opt_filter_t *f) { memset(f, 0, sizeof(coap_opt_filter_t)); } @@ -140,7 +124,7 @@ coap_option_filter_clear(coap_opt_filter_t f) { * * @return @c 1 if bit was set, @c 0 otherwise. */ -int coap_option_filter_set(coap_opt_filter_t filter, uint16_t type); +int coap_option_filter_set(coap_opt_filter_t *filter, uint16_t type); /** * Clears the corresponding entry for @p type in @p filter. This @@ -152,7 +136,7 @@ int coap_option_filter_set(coap_opt_filter_t filter, uint16_t type); * * @return @c 1 if bit was set, @c 0 otherwise. */ -int coap_option_filter_unset(coap_opt_filter_t filter, uint16_t type); +int coap_option_filter_unset(coap_opt_filter_t *filter, uint16_t type); /** * Checks if @p type is contained in @p filter. This function returns @@ -164,7 +148,7 @@ int coap_option_filter_unset(coap_opt_filter_t filter, uint16_t type); * * @return @c 1 if @p type was found, @c 0 otherwise, or @c -1 on error. */ -int coap_option_filter_get(coap_opt_filter_t filter, uint16_t type); +int coap_option_filter_get(coap_opt_filter_t *filter, uint16_t type); /** * Iterator to run through PDU options. This object must be @@ -209,7 +193,7 @@ typedef struct { */ coap_opt_iterator_t *coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, - const coap_opt_filter_t filter); + const coap_opt_filter_t *filter); /** * Updates the iterator @p oi to point to the next option. This function returns @@ -407,7 +391,7 @@ void coap_delete_optlist(coap_optlist_t *optlist_chain); * @return @c 1 if bit was set, @c -1 otherwise. */ COAP_STATIC_INLINE COAP_DEPRECATED int -coap_option_setb(coap_opt_filter_t filter, uint16_t type) { +coap_option_setb(coap_opt_filter_t *filter, uint16_t type) { return coap_option_filter_set(filter, type) ? 1 : -1; } @@ -424,7 +408,7 @@ coap_option_setb(coap_opt_filter_t filter, uint16_t type) { * @return @c 1 if bit was set, @c -1 otherwise. */ COAP_STATIC_INLINE COAP_DEPRECATED int -coap_option_clrb(coap_opt_filter_t filter, uint16_t type) { +coap_option_clrb(coap_opt_filter_t *filter, uint16_t type) { return coap_option_filter_unset(filter, type) ? 1 : -1; } @@ -441,7 +425,7 @@ coap_option_clrb(coap_opt_filter_t filter, uint16_t type) { * @return @c 1 if bit was set, @c 0 if not, @c -1 on error. */ COAP_STATIC_INLINE COAP_DEPRECATED int -coap_option_getb(coap_opt_filter_t filter, uint16_t type) { +coap_option_getb(coap_opt_filter_t *filter, uint16_t type) { return coap_option_filter_get(filter, type); } diff --git a/include/coap2/pdu.h b/include/coap2/pdu.h index 14f46818..498c178b 100644 --- a/include/coap2/pdu.h +++ b/include/coap2/pdu.h @@ -477,7 +477,7 @@ coap_pdu_duplicate(const coap_pdu_t *old_pdu, struct coap_session_t *session, size_t token_length, uint8_t *token, - coap_opt_filter_t drop_options); + coap_opt_filter_t *drop_options); /** * Interprets @p data to determine the number of bytes in the header. diff --git a/src/block.c b/src/block.c index 4e61d7f7..1d922280 100644 --- a/src/block.c +++ b/src/block.c @@ -1071,11 +1071,11 @@ coap_handle_request_send_block(coap_session_t *session, /* Need to set up a copy of the pdu to send */ coap_opt_filter_t drop_options; - memset(drop_options, 0, sizeof(coap_opt_filter_t)); + memset(&drop_options, 0, sizeof(coap_opt_filter_t)); if (block.num != 0) - coap_option_filter_set(drop_options, COAP_OPTION_OBSERVE); + coap_option_filter_set(&drop_options, COAP_OPTION_OBSERVE); out_pdu = coap_pdu_duplicate(&p->pdu, session, pdu->token_length, - pdu->token, drop_options); + pdu->token, &drop_options); if (!out_pdu) { response->code = COAP_RESPONSE_CODE(500); goto fail; diff --git a/src/net.c b/src/net.c index d799d9ba..cbbdf275 100644 --- a/src/net.c +++ b/src/net.c @@ -678,14 +678,14 @@ coap_option_check_critical(coap_context_t *ctx, case COAP_OPTION_BLOCK1: break; default: - if (coap_option_filter_get(ctx->known_options, opt_iter.type) <= 0) { + if (coap_option_filter_get(&ctx->known_options, opt_iter.type) <= 0) { coap_log(LOG_DEBUG, "unknown critical option %d\n", opt_iter.type); ok = 0; /* When opt_iter.type 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.type) == -1) { + if (coap_option_filter_set(&unknown, opt_iter.type) == -1) { break; } } @@ -857,7 +857,7 @@ coap_tid_t coap_send_error(coap_session_t *session, coap_pdu_t *request, unsigned char code, - coap_opt_filter_t opts) { + coap_opt_filter_t *opts) { coap_pdu_t *response; coap_tid_t result = COAP_INVALID_TID; @@ -1995,7 +1995,7 @@ coap_find_transaction(coap_queue_t *queue, coap_session_t *session, coap_tid_t i coap_pdu_t * coap_new_error_response(coap_pdu_t *request, unsigned char code, - coap_opt_filter_t opts) { + coap_opt_filter_t *opts) { coap_opt_iterator_t opt_iter; coap_pdu_t *response; size_t size = request->token_length; @@ -2387,7 +2387,7 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu int skip_hop_limit_check = 0; int resp; - coap_option_filter_clear(opt_filter); + coap_option_filter_clear(&opt_filter); opt = coap_check_option(pdu, COAP_OPTION_PROXY_SCHEME, &opt_iter); if (opt) is_proxy_scheme = 1; @@ -2519,7 +2519,7 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu } else { coap_log(LOG_DEBUG, "method not allowed for .well-known/core\n"); response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(405), - opt_filter); + &opt_filter); } } else if (is_proxy_uri || is_proxy_scheme) { resource = context->proxy_uri_resource; @@ -2554,14 +2554,14 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu uri_path->s); response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(202), - opt_filter); + &opt_filter); } else { /* request for any another resource, return 4.04 */ coap_log(LOG_DEBUG, "request for unknown resource '%*.*s', return 4.04\n", (int)uri_path->length, (int)uri_path->length, uri_path->s); response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(404), - opt_filter); + &opt_filter); } if (!resource) { @@ -2716,7 +2716,7 @@ skip_handler: coap_log(LOG_DEBUG, "have wellknown response %p\n", (void *)response); } else response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(405), - opt_filter); + &opt_filter); if (response && (no_response(pdu, response) != RESPONSE_DROP)) { coap_tid_t mid = pdu->tid; @@ -2735,7 +2735,7 @@ skip_handler: fail_response: response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(resp), - opt_filter); + &opt_filter); if (response) { coap_tid_t mid = pdu->tid; if (coap_send(session, response) == COAP_INVALID_TID) @@ -2838,7 +2838,7 @@ coap_dispatch(coap_context_t *context, coap_session_t *session, coap_show_pdu(LOG_DEBUG, pdu); } - memset(opt_filter, 0, sizeof(coap_opt_filter_t)); + memset(&opt_filter, 0, sizeof(coap_opt_filter_t)); switch (pdu->type) { case COAP_MESSAGE_ACK: @@ -2940,7 +2940,7 @@ coap_dispatch(coap_context_t *context, coap_session_t *session, if (COAP_PDU_IS_REQUEST(pdu)) { response = - coap_new_error_response(pdu, COAP_RESPONSE_CODE(402), opt_filter); + coap_new_error_response(pdu, COAP_RESPONSE_CODE(402), &opt_filter); if (!response) { coap_log(LOG_WARNING, diff --git a/src/option.c b/src/option.c index b6c09ae5..2f1d3bca 100644 --- a/src/option.c +++ b/src/option.c @@ -108,7 +108,7 @@ coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) { coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, - const coap_opt_filter_t filter) { + const coap_opt_filter_t *filter) { assert(pdu); assert(pdu->token); assert(oi); @@ -124,7 +124,7 @@ coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, oi->length = pdu->used_size - pdu->token_length; if (filter) { - memcpy(oi->filter, filter, sizeof(coap_opt_filter_t)); + memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t)); oi->filtered = 1; } return oi; @@ -181,7 +181,7 @@ coap_option_next(coap_opt_iterator_t *oi) { * - the filter is too small for the current option number */ if (!oi->filtered || - (b = coap_option_filter_get(oi->filter, oi->type)) > 0) + (b = coap_option_filter_get(&oi->filter, oi->type)) > 0) break; else if (b < 0) { /* filter too small, cannot proceed */ oi->bad = 1; @@ -197,10 +197,10 @@ coap_check_option(coap_pdu_t *pdu, uint16_t type, coap_opt_iterator_t *oi) { coap_opt_filter_t f; - coap_option_filter_clear(f); - coap_option_filter_set(f, type); + coap_option_filter_clear(&f); + coap_option_filter_set(&f, type); - coap_option_iterator_init(pdu, oi, f); + coap_option_iterator_init(pdu, oi, &f); return coap_option_next(oi); } @@ -392,18 +392,10 @@ coap_opt_encode(coap_opt_t *opt, size_t maxlen, uint16_t delta, return l + length; } -/* coap_opt_filter_t has the following internal structure: */ -typedef struct { - uint16_t mask; - #define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1) #define SHORT_MASK \ (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1)) - uint16_t long_opts[COAP_OPT_FILTER_LONG]; - uint8_t short_opts[COAP_OPT_FILTER_SHORT]; -} opt_filter; - /** Returns true iff @p type denotes an option type larger than 255. */ COAP_STATIC_INLINE int is_long_option(uint16_t type) { return type > 255; } @@ -431,11 +423,11 @@ enum filter_op_t { FILTER_SET, FILTER_CLEAR, FILTER_GET }; * hit or no free slot is available to store @p type with FILTER_SET. */ static int -coap_option_filter_op(coap_opt_filter_t filter, +coap_option_filter_op(coap_opt_filter_t *filter, uint16_t type, enum filter_op_t op) { size_t lindex = 0; - opt_filter *of = (opt_filter *)filter; + coap_opt_filter_t *of = filter; uint16_t nr, mask = 0; if (is_long_option(type)) { @@ -491,17 +483,19 @@ coap_option_filter_op(coap_opt_filter_t filter, } int -coap_option_filter_set(coap_opt_filter_t filter, uint16_t type) { +coap_option_filter_set(coap_opt_filter_t *filter, uint16_t type) { return coap_option_filter_op(filter, type, FILTER_SET); } int -coap_option_filter_unset(coap_opt_filter_t filter, uint16_t type) { +coap_option_filter_unset(coap_opt_filter_t *filter, uint16_t type) { return coap_option_filter_op(filter, type, FILTER_CLEAR); } int -coap_option_filter_get(coap_opt_filter_t filter, uint16_t type) { +coap_option_filter_get(coap_opt_filter_t *filter, uint16_t type) { + /* Ugly cast to make the const go away (FILTER_GET wont change filter + * but as _set and _unset do, the function does not take a const). */ return coap_option_filter_op(filter, type, FILTER_GET); } diff --git a/src/pdu.c b/src/pdu.c index ccd84948..7e5099a1 100644 --- a/src/pdu.c +++ b/src/pdu.c @@ -147,7 +147,7 @@ coap_pdu_duplicate(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, uint8_t *token, - coap_opt_filter_t drop_options) { + coap_opt_filter_t *drop_options) { coap_pdu_t *pdu = coap_pdu_init(old_pdu->type, old_pdu->code, coap_new_message_id(session), diff --git a/src/uri.c b/src/uri.c index 454b8b17..60c01d51 100644 --- a/src/uri.c +++ b/src/uri.c @@ -559,9 +559,9 @@ coap_string_t *coap_get_query(const coap_pdu_t *request) { size_t length = 0; static const uint8_t hex[] = "0123456789ABCDEF"; - coap_option_filter_clear(f); - coap_option_filter_set(f, COAP_OPTION_URI_QUERY); - coap_option_iterator_init(request, &opt_iter, f); + coap_option_filter_clear(&f); + coap_option_filter_set(&f, COAP_OPTION_URI_QUERY); + coap_option_iterator_init(request, &opt_iter, &f); while ((q = coap_option_next(&opt_iter))) { uint16_t seg_len = coap_opt_length(q), i; const uint8_t *seg= coap_opt_value(q); @@ -580,7 +580,7 @@ coap_string_t *coap_get_query(const coap_pdu_t *request) { if (query) { query->length = length; unsigned char *s = query->s; - coap_option_iterator_init(request, &opt_iter, f); + coap_option_iterator_init(request, &opt_iter, &f); while ((q = coap_option_next(&opt_iter))) { if (s != query->s) *s++ = '&'; @@ -609,9 +609,9 @@ coap_string_t *coap_get_uri_path(const coap_pdu_t *request) { size_t length = 0; static const uint8_t hex[] = "0123456789ABCDEF"; - coap_option_filter_clear(f); - coap_option_filter_set(f, COAP_OPTION_URI_PATH); - coap_option_iterator_init(request, &opt_iter, f); + coap_option_filter_clear(&f); + coap_option_filter_set(&f, COAP_OPTION_URI_PATH); + coap_option_iterator_init(request, &opt_iter, &f); while ((q = coap_option_next(&opt_iter))) { uint16_t seg_len = coap_opt_length(q), i; const uint8_t *seg= coap_opt_value(q); @@ -634,7 +634,7 @@ coap_string_t *coap_get_uri_path(const coap_pdu_t *request) { uri_path->length = length; unsigned char *s = uri_path->s; int n = 0; - coap_option_iterator_init(request, &opt_iter, f); + coap_option_iterator_init(request, &opt_iter, &f); while ((q = coap_option_next(&opt_iter))) { if (n++) { *s++ = '/'; diff --git a/tests/test_error_response.c b/tests/test_error_response.c index 70401779..8901c4ac 100644 --- a/tests/test_error_response.c +++ b/tests/test_error_response.c @@ -38,8 +38,8 @@ t_error_response1(void) { pdu->tid = 0x1234; /* result = coap_add_token(pdu, 5, (unsigned char *)"token"); */ - coap_option_filter_clear(opts); - response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(400), opts); + coap_option_filter_clear(&opts); + response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(400), &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -68,8 +68,8 @@ t_error_response2(void) { coap_add_token(pdu, 5, (const uint8_t *)"token"); coap_add_option(pdu, COAP_OPTION_URI_HOST, 4, (const uint8_t *)"time"); - coap_option_filter_clear(opts); - response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(404), opts); + coap_option_filter_clear(&opts); + response = coap_new_error_response(pdu, COAP_RESPONSE_CODE(404), &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -100,9 +100,9 @@ t_error_response3(void) { /* unknown critical option 9 */ coap_add_option(pdu, 9, 0, NULL); - coap_option_filter_clear(opts); - coap_option_filter_set(opts, 9); - response = coap_new_error_response(pdu, code, opts); + coap_option_filter_clear(&opts); + coap_option_filter_set(&opts, 9); + response = coap_new_error_response(pdu, code, &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -139,9 +139,9 @@ t_error_response4(void) { /* unknown critical option 9 */ coap_add_option(pdu, 9, sizeof(optval), optval); - coap_option_filter_clear(opts); - coap_option_filter_set(opts, 9); - response = coap_new_error_response(pdu, code, opts); + coap_option_filter_clear(&opts); + coap_option_filter_set(&opts, 9); + response = coap_new_error_response(pdu, code, &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -180,9 +180,9 @@ t_error_response5(void) { /* unknown critical option 9 */ coap_add_option(pdu, 9, sizeof(optval), optval); - coap_option_filter_clear(opts); - coap_option_filter_set(opts, 9); - response = coap_new_error_response(pdu, code, opts); + coap_option_filter_clear(&opts); + coap_option_filter_set(&opts, 9); + response = coap_new_error_response(pdu, code, &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -221,9 +221,9 @@ t_error_response6(void) { /* unknown critical option 23 */ coap_add_option(pdu, 23, sizeof(optval), optval); - coap_option_filter_clear(opts); - coap_option_filter_set(opts, 23); - response = coap_new_error_response(pdu, code, opts); + coap_option_filter_clear(&opts); + coap_option_filter_set(&opts, 23); + response = coap_new_error_response(pdu, code, &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -263,9 +263,9 @@ t_error_response7(void) { /* unknown critical option 23 */ coap_add_option(pdu, 23, sizeof(optval), optval); - coap_option_filter_clear(opts); - coap_option_filter_set(opts, 23); - response = coap_new_error_response(pdu, code, opts); + coap_option_filter_clear(&opts); + coap_option_filter_set(&opts, 23); + response = coap_new_error_response(pdu, code, &opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -303,10 +303,10 @@ t_error_response8(void) { /* known option 2000 */ coap_add_option(pdu, 2000, 0, NULL); - coap_option_filter_clear(opts); - coap_option_filter_set(opts, 1001); - coap_option_filter_set(opts, 1014); - response = coap_new_error_response(pdu, code, opts); + coap_option_filter_clear(&opts); + coap_option_filter_set(&opts, 1001); + coap_option_filter_set(&opts, 1014); + response = coap_new_error_response(pdu, code, &opts); CU_ASSERT_PTR_NOT_NULL(response); diff --git a/tests/test_options.c b/tests/test_options.c index 982ede64..3d086b3f 100644 --- a/tests/test_options.c +++ b/tests/test_options.c @@ -650,9 +650,9 @@ t_iterate_option6(void) { coap_opt_t *option; coap_opt_filter_t filter; - coap_option_filter_clear(filter); - coap_option_filter_set(filter, 10); /* option nr 10 only */ - result = coap_option_iterator_init(&pdu, &oi, filter); + coap_option_filter_clear(&filter); + coap_option_filter_set(&filter, 10); /* option nr 10 only */ + result = coap_option_iterator_init(&pdu, &oi, &filter); CU_ASSERT_PTR_EQUAL(result, &oi); CU_ASSERT(oi.bad == 0); @@ -696,10 +696,10 @@ t_iterate_option7(void) { coap_opt_filter_t filter; /* search options nr 8 and 22 */ - coap_option_filter_clear(filter); - coap_option_filter_set(filter, 8); - coap_option_filter_set(filter, 22); - result = coap_option_iterator_init(&pdu, &oi, filter); + coap_option_filter_clear(&filter); + coap_option_filter_set(&filter, 8); + coap_option_filter_set(&filter, 22); + result = coap_option_iterator_init(&pdu, &oi, &filter); CU_ASSERT_PTR_EQUAL(result, &oi); CU_ASSERT(oi.bad == 0); @@ -743,9 +743,9 @@ t_iterate_option8(void) { coap_opt_filter_t filter; /* search option nr 36 */ - coap_option_filter_clear(filter); - coap_option_filter_set(filter, 36); - result = coap_option_iterator_init(&pdu, &oi, filter); + coap_option_filter_clear(&filter); + coap_option_filter_set(&filter, 36); + result = coap_option_iterator_init(&pdu, &oi, &filter); CU_ASSERT_PTR_EQUAL(result, &oi); CU_ASSERT(oi.bad == 0); @@ -774,9 +774,9 @@ t_iterate_option9(void) { coap_opt_filter_t filter; /* search option nr 100 */ - coap_option_filter_clear(filter); - coap_option_filter_set(filter, 100); - result = coap_option_iterator_init(&pdu, &oi, filter); + coap_option_filter_clear(&filter); + coap_option_filter_set(&filter, 100); + result = coap_option_iterator_init(&pdu, &oi, &filter); CU_ASSERT_PTR_EQUAL(result, &oi); CU_ASSERT(oi.bad == 0); @@ -805,9 +805,9 @@ t_iterate_option10(void) { coap_opt_filter_t filter; /* search option nr 61 */ - coap_option_filter_clear(filter); - coap_option_filter_set(filter, 61); - result = coap_option_iterator_init(&pdu, &oi, filter); + coap_option_filter_clear(&filter); + coap_option_filter_set(&filter, 61); + result = coap_option_iterator_init(&pdu, &oi, &filter); CU_ASSERT_PTR_EQUAL(result, &oi); CU_ASSERT(oi.bad == 0); @@ -829,30 +829,30 @@ static void t_filter_option1(void) { coap_opt_filter_t filter; - coap_option_filter_clear(filter); + coap_option_filter_clear(&filter); - CU_ASSERT(coap_option_filter_set(filter, 0) == 1); - CU_ASSERT(coap_option_filter_set(filter, 37) == 1); - CU_ASSERT(coap_option_filter_set(filter, 37) == 1); - CU_ASSERT(coap_option_filter_set(filter, 43) == 1); - CU_ASSERT(coap_option_filter_set(filter, 290) == 1); - CU_ASSERT(coap_option_filter_set(filter, 65535) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 0) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 37) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 37) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 43) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 290) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 65535) == 1); - CU_ASSERT(coap_option_filter_get(filter, 0) == 1); - CU_ASSERT(coap_option_filter_get(filter, 37) == 1); - CU_ASSERT(coap_option_filter_get(filter, 43) == 1); - CU_ASSERT(coap_option_filter_get(filter, 290) == 1); - CU_ASSERT(coap_option_filter_get(filter, 65535) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 0) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 37) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 43) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 290) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 65535) == 1); - CU_ASSERT(coap_option_filter_unset(filter, 37) == 1); + CU_ASSERT(coap_option_filter_unset(&filter, 37) == 1); - CU_ASSERT(coap_option_filter_get(filter, 0) == 1); - CU_ASSERT(coap_option_filter_get(filter, 43) == 1); - CU_ASSERT(coap_option_filter_get(filter, 290) == 1); - CU_ASSERT(coap_option_filter_get(filter, 65535) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 0) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 43) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 290) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 65535) == 1); - CU_ASSERT(coap_option_filter_get(filter, 37) == 0); - CU_ASSERT(coap_option_filter_get(filter, 89) == 0); + CU_ASSERT(coap_option_filter_get(&filter, 37) == 0); + CU_ASSERT(coap_option_filter_get(&filter, 89) == 0); } static void @@ -860,18 +860,18 @@ t_filter_option2(void) { coap_opt_filter_t filter; int s; - coap_option_filter_clear(filter); + coap_option_filter_clear(&filter); /* fill all COAP_OPT_FILTER_SHORT slots */ for (s = 0; s < COAP_OPT_FILTER_SHORT; s++) { - CU_ASSERT(coap_option_filter_set(filter, s)); + CU_ASSERT(coap_option_filter_set(&filter, s)); } /* adding a short option type must fail */ - CU_ASSERT(coap_option_filter_set(filter, COAP_OPT_FILTER_SHORT) == 0); + CU_ASSERT(coap_option_filter_set(&filter, COAP_OPT_FILTER_SHORT) == 0); /* adding a long option type must succeed */ - CU_ASSERT(coap_option_filter_set(filter, 256) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 256) == 1); } static void @@ -879,50 +879,50 @@ t_filter_option3(void) { coap_opt_filter_t filter; int l; - coap_option_filter_clear(filter); + coap_option_filter_clear(&filter); /* set COAP_OPT_FILTER_LONG long filters */ for (l = 0; l < COAP_OPT_FILTER_LONG; l++) { - CU_ASSERT(coap_option_filter_set(filter, 256 + l) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 256 + l) == 1); } /* the next must fail and must not be found */ - CU_ASSERT(coap_option_filter_set(filter, 256 + COAP_OPT_FILTER_LONG) == 0); - CU_ASSERT(coap_option_filter_get(filter, 256 + COAP_OPT_FILTER_LONG) == 0); + CU_ASSERT(coap_option_filter_set(&filter, 256 + COAP_OPT_FILTER_LONG) == 0); + CU_ASSERT(coap_option_filter_get(&filter, 256 + COAP_OPT_FILTER_LONG) == 0); /* remove one item */ - CU_ASSERT(coap_option_filter_unset(filter, 256) == 1); - CU_ASSERT(coap_option_filter_get(filter, 256) == 0); + CU_ASSERT(coap_option_filter_unset(&filter, 256) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 256) == 0); /* now, storing a new filter must succeed */ - CU_ASSERT(coap_option_filter_set(filter, 256 + COAP_OPT_FILTER_LONG) == 1); - CU_ASSERT(coap_option_filter_get(filter, 256 + COAP_OPT_FILTER_LONG) == 1); + CU_ASSERT(coap_option_filter_set(&filter, 256 + COAP_OPT_FILTER_LONG) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 256 + COAP_OPT_FILTER_LONG) == 1); /* and all other items must be available as well */ for (l = 0; l < COAP_OPT_FILTER_LONG; l++) { - CU_ASSERT(coap_option_filter_get(filter, 256 + l + 1) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 256 + l + 1) == 1); } /* set COAP_OPT_FILTER_SHORT short filters */ for (l = 0; l < COAP_OPT_FILTER_SHORT; l++) { - CU_ASSERT(coap_option_filter_set(filter, l) == 1); + CU_ASSERT(coap_option_filter_set(&filter, l) == 1); } /* the next must fail and must not be found */ - CU_ASSERT(coap_option_filter_set(filter, COAP_OPT_FILTER_SHORT) == 0); - CU_ASSERT(coap_option_filter_get(filter, COAP_OPT_FILTER_SHORT) == 0); + CU_ASSERT(coap_option_filter_set(&filter, COAP_OPT_FILTER_SHORT) == 0); + CU_ASSERT(coap_option_filter_get(&filter, COAP_OPT_FILTER_SHORT) == 0); /* remove one item */ - CU_ASSERT(coap_option_filter_unset(filter, 0) == 1); - CU_ASSERT(coap_option_filter_get(filter, 0) == 0); + CU_ASSERT(coap_option_filter_unset(&filter, 0) == 1); + CU_ASSERT(coap_option_filter_get(&filter, 0) == 0); /* now, storing a new filter must succeed */ - CU_ASSERT(coap_option_filter_set(filter, COAP_OPT_FILTER_SHORT) == 1); - CU_ASSERT(coap_option_filter_get(filter, COAP_OPT_FILTER_SHORT) == 1); + CU_ASSERT(coap_option_filter_set(&filter, COAP_OPT_FILTER_SHORT) == 1); + CU_ASSERT(coap_option_filter_get(&filter, COAP_OPT_FILTER_SHORT) == 1); /* and all other items must be available as well */ for (l = 0; l < COAP_OPT_FILTER_SHORT; l++) { - CU_ASSERT(coap_option_filter_get(filter, l + 1) == 1); + CU_ASSERT(coap_option_filter_get(&filter, l + 1) == 1); } }