From 26cd2446a85fdfb64c77471a46e1c9d0fe00422e Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 10 Aug 2020 15:48:58 +0100 Subject: [PATCH] Deprecated: Replace deprecated functions in library examples/contiki/coap-observer.c: examples/etsi_iot_01.c: include/coap2/coap_prng.h: include/coap2/net.h: src/coap_debug.c: src/coap_openssl.c: src/coap_session.c: src/net.c: src/option.c: tests/test_error_response.c: tests/test_options.c: prng -> coap_prng prng_init -> coap_prng_init coap_option_setb -> coap_option_filter_set coap_option_clrb -> coap_option_filter_unset coap_option_getb -> coap_option_filter_get include/coap2/coap.h.windows: win32/libcoap.vcxproj: win32/libcoap.vcxproj.filters: prng.h -> coap_prng.h include/coap2/option.h: Add in COAP_DEPRECATED in deprecated functions. --- examples/contiki/coap-observer.c | 2 +- examples/etsi_iot_01.c | 4 +-- include/coap2/coap.h.windows | 2 +- include/coap2/coap_prng.h | 59 ++++++++++++-------------------- include/coap2/net.h | 2 +- include/coap2/option.h | 6 ++-- src/coap_debug.c | 2 +- src/coap_openssl.c | 2 +- src/coap_session.c | 4 +-- src/net.c | 10 +++--- src/option.c | 4 +-- tests/test_error_response.c | 14 ++++---- tests/test_options.c | 12 +++---- win32/libcoap.vcxproj | 2 +- win32/libcoap.vcxproj.filters | 6 ++-- 15 files changed, 59 insertions(+), 72 deletions(-) diff --git a/examples/contiki/coap-observer.c b/examples/contiki/coap-observer.c index 8b7810ef..00378bd9 100644 --- a/examples/contiki/coap-observer.c +++ b/examples/contiki/coap-observer.c @@ -166,7 +166,7 @@ PROCESS_THREAD(coap_server_process, ev, data) coap_add_option(request, COAP_OPTION_OBSERVE, 0, NULL); { unsigned char buf[2]; - prng(buf, 2); + coap_prng(buf, 2); coap_add_option(request, COAP_OPTION_TOKEN, 2, buf); } diff --git a/examples/etsi_iot_01.c b/examples/etsi_iot_01.c index 1b95c1a2..8b5302b0 100644 --- a/examples/etsi_iot_01.c +++ b/examples/etsi_iot_01.c @@ -340,7 +340,7 @@ hnd_get_query(coap_context_t *ctx UNUSED_PARAM, buf); coap_option_filter_clear(f); - coap_option_setb(f, COAP_OPTION_URI_QUERY); + coap_option_filter_set(f, COAP_OPTION_URI_QUERY); coap_option_iterator_init(request, &opt_iter, f); @@ -385,7 +385,7 @@ hnd_get_separate(coap_context_t *ctx, /* search for option delay in query list */ coap_option_filter_clear(f); - coap_option_setb(f, COAP_OPTION_URI_QUERY); + coap_option_filter_set(f, COAP_OPTION_URI_QUERY); coap_option_iterator_init(request, &opt_iter, f); diff --git a/include/coap2/coap.h.windows b/include/coap2/coap.h.windows index 1ecd6cf4..bb626f28 100644 --- a/include/coap2/coap.h.windows +++ b/include/coap2/coap.h.windows @@ -41,13 +41,13 @@ extern "C" { #include "coap_dtls.h" #include "coap_event.h" #include "coap_io.h" +#include "coap_prng.h" #include "coap_time.h" #include "encode.h" #include "mem.h" #include "net.h" #include "option.h" #include "pdu.h" -#include "prng.h" #include "resource.h" #include "str.h" #include "subscribe.h" diff --git a/include/coap2/coap_prng.h b/include/coap2/coap_prng.h index fdce7d25..2f50c85b 100644 --- a/include/coap2/coap_prng.h +++ b/include/coap2/coap_prng.h @@ -1,14 +1,14 @@ /* - * prng.h -- Pseudo Random Numbers + * coap_prng.h -- Pseudo Random Numbers * - * Copyright (C) 2010-2011 Olaf Bergmann + * Copyright (C) 2010-2020 Olaf Bergmann * * This file is part of the CoAP library libcoap. Please see README for terms * of use. */ /** - * @file prng.h + * @file coap_prng.h * @brief Pseudo Random Numbers */ @@ -16,7 +16,7 @@ #define COAP_PRNG_H_ /** - * @defgroup prng Pseudo Random Numbers + * @defgroup coap_prng Pseudo Random Numbers * API functions for gerating pseudo random numbers * @{ */ @@ -26,8 +26,8 @@ /** * Fills \p buf with \p len random bytes. This is the default implementation for - * prng(). You might want to change prng() to use a better PRNG on your specific - * platform. + * coap_prng(). You might want to change contiki_prng_impl() to use a better + * PRNG on your specific platform. */ COAP_STATIC_INLINE int contiki_prng_impl(unsigned char *buf, size_t len) { @@ -43,9 +43,11 @@ contiki_prng_impl(unsigned char *buf, size_t len) { return 1; } -#define prng(Buf,Length) contiki_prng_impl((Buf), (Length)) -#define prng_init(Value) random_init((uint16_t)(Value)) +#define coap_prng(Buf,Length) contiki_prng_impl((Buf), (Length)) +#define coap_prng_init(Value) random_init((uint16_t)(Value)) + #elif defined(WITH_LWIP) && defined(LWIP_RAND) + COAP_STATIC_INLINE int lwip_prng_impl(unsigned char *buf, size_t len) { u32_t v = LWIP_RAND(); @@ -60,15 +62,16 @@ lwip_prng_impl(unsigned char *buf, size_t len) { return 1; } -#define prng(Buf,Length) lwip_prng_impl((Buf), (Length)) -#define prng_init(Value) +#define coap_prng(Buf,Length) lwip_prng_impl((Buf), (Length)) +#define coap_prng_init(Value) + #elif defined(_WIN32) -#define prng_init(Value) + errno_t __cdecl rand_s( _Out_ unsigned int* _RandomValue ); - /** +/** * Fills \p buf with \p len random bytes. This is the default implementation for - * prng(). You might want to change prng() to use a better PRNG on your specific - * platform. + * coap_prng(). You might want to change coap_prng_impl() to use a better + * PRNG on your specific platform. */ COAP_STATIC_INLINE int coap_prng_impl( unsigned char *buf, size_t len ) { @@ -86,6 +89,9 @@ coap_prng_impl( unsigned char *buf, size_t len ) { return 1; } +#define coap_prng(Buf,Length) coap_prng_impl((Buf), (Length)) +#define coap_prng_init(Value) + #else /** @@ -116,36 +122,15 @@ void coap_prng_init(unsigned long seed); * Fills @p buf with @p len random bytes using the default pseudo * random number generator. The default PRNG can be changed with * coap_set_prng(). This function returns 1 when @p len random bytes - * have been written to @buf, zero otherwise. + * have been written to @p buf, zero otherwise. * * @param buf The buffer to fill with random bytes. * @param len The number of random bytes to write into @p buf. * - * @param 1 on success, 0 otherwise. + * @return 1 on success, 0 otherwise. */ int coap_prng(void *buf, size_t len); -#ifndef prng -/** - * Fills \p Buf with \p Length bytes of random data. - * - * @deprecated Use coap_prng() instead. - * @hideinitializer - */ -#define prng(Buf,Length) coap_prng((Buf), (Length)) -#endif - -#ifndef prng_init -/** - * Called to set the PRNG seed. You may want to re-define this to allow for a - * better PRNG. - * - * @deprecated Use coap_prng_init() instead. - * @hideinitializer - */ -#define prng_init(Value) coap_prng_init((unsigned long)(Value)) -#endif - #endif /* POSIX */ /** @} */ diff --git a/include/coap2/net.h b/include/coap2/net.h index 0090d096..1287ad5e 100644 --- a/include/coap2/net.h +++ b/include/coap2/net.h @@ -279,7 +279,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_setb(ctx->known_options, type); + coap_option_filter_set(ctx->known_options, type); } /** diff --git a/include/coap2/option.h b/include/coap2/option.h index 3af9e71e..23913afc 100644 --- a/include/coap2/option.h +++ b/include/coap2/option.h @@ -179,7 +179,7 @@ int coap_option_filter_get(coap_opt_filter_t filter, uint16_t type); * * @return @c 1 if bit was set, @c -1 otherwise. */ -COAP_STATIC_INLINE int +COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_setb(coap_opt_filter_t filter, uint16_t type) { return coap_option_filter_set(filter, type) ? 1 : -1; } @@ -196,7 +196,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 int +COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_clrb(coap_opt_filter_t filter, uint16_t type) { return coap_option_filter_unset(filter, type) ? 1 : -1; } @@ -213,7 +213,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 int +COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_getb(coap_opt_filter_t filter, uint16_t type) { return coap_option_filter_get(filter, type); } diff --git a/src/coap_debug.c b/src/coap_debug.c index 95faaeb9..3bd8df44 100644 --- a/src/coap_debug.c +++ b/src/coap_debug.c @@ -885,7 +885,7 @@ int coap_debug_send_packet(void) { } if ( packet_loss_level > 0 ) { uint16_t r = 0; - prng( (uint8_t*)&r, 2 ); + coap_prng( (uint8_t*)&r, 2 ); if ( r < packet_loss_level ) return 0; } diff --git a/src/coap_openssl.c b/src/coap_openssl.c index d24fc2ba..dee80b37 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -704,7 +704,7 @@ void *coap_dtls_new_context(struct coap_context_t *coap_context) { if (dtls_log_level >= LOG_WARNING) coap_log(LOG_WARNING, "Insufficient entropy for random cookie generation"); - prng(cookie_secret, sizeof(cookie_secret)); + coap_prng(cookie_secret, sizeof(cookie_secret)); } context->dtls.cookie_hmac = HMAC_CTX_new(); if (!HMAC_Init_ex(context->dtls.cookie_hmac, cookie_secret, (int)sizeof(cookie_secret), EVP_sha256(), NULL)) diff --git a/src/coap_session.c b/src/coap_session.c index a5bfcf7d..8c405daa 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -148,7 +148,7 @@ coap_make_session(coap_proto_t proto, coap_session_type_t type, session->last_ping_mid = COAP_INVALID_TID; /* initialize message id */ - prng((unsigned char *)&session->tx_mid, sizeof(session->tx_mid)); + coap_prng((unsigned char *)&session->tx_mid, sizeof(session->tx_mid)); return session; } @@ -293,7 +293,7 @@ coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, node->pdu = pdu; if (pdu->type == COAP_MESSAGE_CON && COAP_PROTO_NOT_RELIABLE(session->proto)) { uint8_t r; - prng(&r, sizeof(r)); + coap_prng(&r, sizeof(r)); /* add timeout in range [ACK_TIMEOUT...ACK_TIMEOUT * ACK_RANDOM_FACTOR] */ node->timeout = coap_calc_timeout(session, r); } diff --git a/src/net.c b/src/net.c index 262c7397..f2adf49e 100644 --- a/src/net.c +++ b/src/net.c @@ -1174,7 +1174,7 @@ coap_send(coap_session_t *session, coap_pdu_t *pdu) { node->id = pdu->tid; node->pdu = pdu; - prng(&r, sizeof(r)); + coap_prng(&r, sizeof(r)); /* add timeout in range [ACK_TIMEOUT...ACK_TIMEOUT * ACK_RANDOM_FACTOR] */ node->timeout = coap_calc_timeout(session, r); return coap_wait_ack(session->context, session, node); @@ -1937,8 +1937,10 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code, /* Estimate how much space we need for options to copy from * request. We always need the Token, for 4.02 the unknown critical * options must be included as well. */ - coap_option_clrb(opts, COAP_OPTION_CONTENT_TYPE); /* we do not want this */ - coap_option_clrb(opts, COAP_OPTION_HOP_LIMIT); /* we do not want this */ + + /* we do not want these */ + coap_option_filter_unset(opts, COAP_OPTION_CONTENT_TYPE); + coap_option_filter_unset(opts, COAP_OPTION_HOP_LIMIT); coap_option_iterator_init(request, &opt_iter, opts); @@ -2832,7 +2834,7 @@ void coap_startup(void) { coap_ticks(&now); us = coap_ticks_to_rt_us(now); /* Be accurate to the nearest (approx) us */ - prng_init(us); + coap_prng_init(us); coap_memory_init(); coap_dtls_startup(); } diff --git a/src/option.c b/src/option.c index 38b3ffef..e260d24d 100644 --- a/src/option.c +++ b/src/option.c @@ -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_getb(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; @@ -198,7 +198,7 @@ coap_check_option(coap_pdu_t *pdu, uint16_t type, coap_opt_filter_t f; coap_option_filter_clear(f); - coap_option_setb(f, type); + coap_option_filter_set(f, type); coap_option_iterator_init(pdu, oi, f); diff --git a/tests/test_error_response.c b/tests/test_error_response.c index 2f3bc46c..70401779 100644 --- a/tests/test_error_response.c +++ b/tests/test_error_response.c @@ -101,7 +101,7 @@ t_error_response3(void) { coap_add_option(pdu, 9, 0, NULL); coap_option_filter_clear(opts); - coap_option_setb(opts, 9); + coap_option_filter_set(opts, 9); response = coap_new_error_response(pdu, code, opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -140,7 +140,7 @@ t_error_response4(void) { coap_add_option(pdu, 9, sizeof(optval), optval); coap_option_filter_clear(opts); - coap_option_setb(opts, 9); + coap_option_filter_set(opts, 9); response = coap_new_error_response(pdu, code, opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -181,7 +181,7 @@ t_error_response5(void) { coap_add_option(pdu, 9, sizeof(optval), optval); coap_option_filter_clear(opts); - coap_option_setb(opts, 9); + coap_option_filter_set(opts, 9); response = coap_new_error_response(pdu, code, opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -222,7 +222,7 @@ t_error_response6(void) { coap_add_option(pdu, 23, sizeof(optval), optval); coap_option_filter_clear(opts); - coap_option_setb(opts, 23); + coap_option_filter_set(opts, 23); response = coap_new_error_response(pdu, code, opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -264,7 +264,7 @@ t_error_response7(void) { coap_add_option(pdu, 23, sizeof(optval), optval); coap_option_filter_clear(opts); - coap_option_setb(opts, 23); + coap_option_filter_set(opts, 23); response = coap_new_error_response(pdu, code, opts); CU_ASSERT_PTR_NOT_NULL(response); @@ -304,8 +304,8 @@ t_error_response8(void) { coap_add_option(pdu, 2000, 0, NULL); coap_option_filter_clear(opts); - coap_option_setb(opts, 1001); - coap_option_setb(opts, 1014); + 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 40f544ab..effc1215 100644 --- a/tests/test_options.c +++ b/tests/test_options.c @@ -630,7 +630,7 @@ t_iterate_option6(void) { coap_opt_filter_t filter; coap_option_filter_clear(filter); - coap_option_setb(filter, 10); /* option nr 10 only */ + coap_option_filter_set(filter, 10); /* option nr 10 only */ result = coap_option_iterator_init(&pdu, &oi, filter); CU_ASSERT_PTR_EQUAL(result, &oi); @@ -676,8 +676,8 @@ t_iterate_option7(void) { /* search options nr 8 and 22 */ coap_option_filter_clear(filter); - coap_option_setb(filter, 8); - coap_option_setb(filter, 22); + 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); @@ -723,7 +723,7 @@ t_iterate_option8(void) { /* search option nr 36 */ coap_option_filter_clear(filter); - coap_option_setb(filter, 36); + coap_option_filter_set(filter, 36); result = coap_option_iterator_init(&pdu, &oi, filter); CU_ASSERT_PTR_EQUAL(result, &oi); @@ -754,7 +754,7 @@ t_iterate_option9(void) { /* search option nr 100 */ coap_option_filter_clear(filter); - coap_option_setb(filter, 100); + coap_option_filter_set(filter, 100); result = coap_option_iterator_init(&pdu, &oi, filter); CU_ASSERT_PTR_EQUAL(result, &oi); @@ -785,7 +785,7 @@ t_iterate_option10(void) { /* search option nr 61 */ coap_option_filter_clear(filter); - coap_option_setb(filter, 61); + coap_option_filter_set(filter, 61); result = coap_option_iterator_init(&pdu, &oi, filter); CU_ASSERT_PTR_EQUAL(result, &oi); diff --git a/win32/libcoap.vcxproj b/win32/libcoap.vcxproj index 63c8300c..5b6f37f7 100644 --- a/win32/libcoap.vcxproj +++ b/win32/libcoap.vcxproj @@ -75,6 +75,7 @@ + @@ -86,7 +87,6 @@ - diff --git a/win32/libcoap.vcxproj.filters b/win32/libcoap.vcxproj.filters index 1fdcd196..40ceddd2 100644 --- a/win32/libcoap.vcxproj.filters +++ b/win32/libcoap.vcxproj.filters @@ -131,6 +131,9 @@ Header Files + + Header Files + Header Files @@ -164,9 +167,6 @@ Header Files - - Header Files - Header Files