diff --git a/examples/client.c b/examples/client.c index 24a5245b..20b138c0 100644 --- a/examples/client.c +++ b/examples/client.c @@ -17,6 +17,7 @@ #include #ifdef _WIN32 #define strcasecmp _stricmp +#define strncasecmp _strnicmp #include "getopt.c" #if !defined(S_ISDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) diff --git a/examples/coap-server.c b/examples/coap-server.c index b9bcf8d7..57c32a78 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -19,6 +19,7 @@ #include #ifdef _WIN32 #define strcasecmp _stricmp +#define strncasecmp _strnicmp #include "getopt.c" #if !defined(S_ISDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) diff --git a/include/coap2/coap_prng.h b/include/coap2/coap_prng.h index 2f50c85b..b8564031 100644 --- a/include/coap2/coap_prng.h +++ b/include/coap2/coap_prng.h @@ -65,33 +65,6 @@ lwip_prng_impl(unsigned char *buf, size_t len) { #define coap_prng(Buf,Length) lwip_prng_impl((Buf), (Length)) #define coap_prng_init(Value) -#elif defined(_WIN32) - -errno_t __cdecl rand_s( _Out_ unsigned int* _RandomValue ); -/** - * Fills \p buf with \p len random bytes. This is the default implementation for - * 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 ) { - while ( len != 0 ) { - uint32_t r = 0; - size_t i; - if ( rand_s( &r ) != 0 ) - return 0; - for ( i = 0; i < len && i < 4; i++ ) { - *buf++ = (uint8_t)r; - r >>= 8; - } - len -= i; - } - return 1; -} - -#define coap_prng(Buf,Length) coap_prng_impl((Buf), (Length)) -#define coap_prng_init(Value) - #else /** diff --git a/include/coap2/pdu.h b/include/coap2/pdu.h index cbaeaaa3..d83ca74c 100644 --- a/include/coap2/pdu.h +++ b/include/coap2/pdu.h @@ -508,16 +508,6 @@ size_t coap_add_option(coap_pdu_t *pdu, size_t len, const uint8_t *data); -/** - * Adds option of given type to pdu that is passed as first parameter, but does - * not write a value. It works like coap_add_option with respect to calling - * sequence (i.e. after token and before data). This function returns a memory - * address to which the option data has to be written before the PDU can be - * sent, or @c NULL on error. - */ -uint8_t *coap_add_option_later(coap_pdu_t *pdu, - uint16_t type, - size_t len); /** diff --git a/libcoap-2.map b/libcoap-2.map index e0853a14..147ca086 100644 --- a/libcoap-2.map +++ b/libcoap-2.map @@ -7,7 +7,6 @@ global: coap_add_data_blocked_response; coap_add_observer; coap_add_option; - coap_add_option_later; coap_add_optlist_pdu; coap_add_resource; coap_address_equals; diff --git a/libcoap-2.sym b/libcoap-2.sym index 15073ef6..704b5f1c 100644 --- a/libcoap-2.sym +++ b/libcoap-2.sym @@ -5,7 +5,6 @@ coap_add_data_after coap_add_data_blocked_response coap_add_observer coap_add_option -coap_add_option_later coap_add_optlist_pdu coap_add_resource coap_address_equals diff --git a/src/coap_openssl.c b/src/coap_openssl.c index 15f094f2..cfe5bdfc 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -79,6 +79,7 @@ #ifdef _WIN32 #define strcasecmp _stricmp +#define strncasecmp _strnicmp #endif /* RFC6091/RFC7250 */ diff --git a/src/coap_prng.c b/src/coap_prng.c index 92b0d79d..c825dbd6 100644 --- a/src/coap_prng.c +++ b/src/coap_prng.c @@ -15,20 +15,49 @@ #include #endif /* !HAVE_GETRANDOM */ +#if defined(_WIN32) + +errno_t __cdecl rand_s( _Out_ unsigned int* _RandomValue ); +/** + * Fills \p buf with \p len random bytes. This is the default implementation for + * 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 ) { + while ( len != 0 ) { + uint32_t r = 0; + size_t i; + if ( rand_s( &r ) != 0 ) + return 0; + for ( i = 0; i < len && i < 4; i++ ) { + *buf++ = (uint8_t)r; + r >>= 8; + } + len -= i; + } + return 1; +} + +#endif + static int coap_prng_default(void *buf, size_t len) { #ifdef HAVE_GETRANDOM return getrandom(buf, len, 0); #else /* !HAVE_GETRANDOM */ - unsigned char *dst = (unsigned char *)buf; - while (len--) - *dst++ = rand() & 0xFF; - return 1; + return coap_prng_impl(buf,len); #endif /* !HAVE_GETRANDOM */ } static coap_rand_func_t rand_func = coap_prng_default; +#if defined(WITH_CONTIKI) + +#elif defined(WITH_LWIP) && defined(LWIP_RAND) + +#else + void coap_set_prng(coap_rand_func_t rng) { rand_func = rng; @@ -54,3 +83,5 @@ coap_prng(void *buf, size_t len) { rand_func(buf, len); return 1; } + +#endif diff --git a/win32/libcoap.vcxproj b/win32/libcoap.vcxproj index 7a3c65ce..6cf60eac 100644 --- a/win32/libcoap.vcxproj +++ b/win32/libcoap.vcxproj @@ -47,6 +47,7 @@ +