From 2900f72a6426f26281890a678c14cb6594d1322b Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 27 Apr 2019 16:30:05 +0100 Subject: [PATCH] Make coap_subscription_t and coap_endpoint_t opaque to applications include/coap2/coap_subscribe_internal.h and include/coap2/coap_session_internal.h contain the information not exposed to applications. This internal information was moved out of the respective include/coap2/subscribe.h and include/coap2/coap_session.h files comprising of the coap_subscription_t and coap_endpoint_t definitions. To ease inter .h file dependencies, a new file include/coap2/coap_forward_decls.h is added to include forward declarations for both libcoap and applications. Makefile.am: Include include/coap2/coap_*internal.h as files for distribution, but not installed for applications to use. Include include/coap2/coap_forward_decls.h, so it is installed for applications. include/coap2/coap.h.in: Include "coap_forward_decls.h" include/coap2/coap_forward_decls.h: (New) Forward declare structures and typedef the structures defined in coap_internal.h. include/coap2/coap_internal.h: (New) Includes all the required #include files that libcoap internally needs. include/coap2/coap_session_internal.h: (New) Include the coap_endpoint_t information taken from include/coap2/coap_session.h. include/coap2/coap_session.h: Remove coap_endpoint_t definition. include/coap2/lwippools.h: Add in coap_forward_decls.h and coap_internal.h to handle the LwIP memory allocations. include/coap2/resource.h: Add in "block.h" to allow things to build. include/coap2/coap_subscribe_internal.h: (New) Include the coap_subscription_t information taken from include/coap2/subscribe.h. include/coap2/subscribe.h: Remove coap_subscription_t definition. libcoap-2.map: libcoap-2.sym: Updated, removing coap_subscription_init(). src/address.c: src/asyn.c: src/block.c: src/coap_debug.c: src/coap_event.c: src/coap_gnutls.c: src/coap_hashkey.c: src/coap_io.c: src/coap_io_lwip.c: src/coap_notls.c: src/coap_openssl.c: src/coap_session.c: src/coap_time.c: src/coap_tinydtls.c: src/encode.c: src/mem.c: src/net.c: src/option.c: src/pdu.c: src/resource.c: src/str.c: src/subscribe.c: src/uri.c: Add in '#include "coap_internal.h"' to the source files. Remove other libcoap #include files. win32/libcoap.vcxproj: win32/libcoap.vcxproj.filters: Update for Windows build (not tested). examples/contiki/server.c: src/coap_io.c: Remove knowledge of endpoint from the server and update Contiki's version of coap_run_once() to do the work instead. ==== Other structures (plus some internal required #defines) will follow as separate PRs. --- Makefile.am | 6 ++- examples/contiki/server.c | 7 +-- include/coap2/coap.h.in | 1 + include/coap2/coap_forward_decls.h | 48 ++++++++++++++++++ include/coap2/coap_internal.h | 44 +++++++++++++++++ include/coap2/coap_session.h | 24 ++------- include/coap2/coap_session_internal.h | 41 ++++++++++++++++ include/coap2/coap_subscribe_internal.h | 65 +++++++++++++++++++++++++ include/coap2/lwippools.h | 2 +- include/coap2/resource.h | 1 + include/coap2/subscribe.h | 46 ++--------------- libcoap-2.map | 1 - libcoap-2.sym | 1 - src/address.c | 4 +- src/async.c | 9 +--- src/block.c | 8 +-- src/coap_debug.c | 9 +--- src/coap_event.c | 3 +- src/coap_gnutls.c | 6 +-- src/coap_hashkey.c | 2 +- src/coap_io.c | 23 ++++----- src/coap_io_lwip.c | 4 +- src/coap_notls.c | 4 +- src/coap_openssl.c | 6 +-- src/coap_session.c | 12 +---- src/coap_time.c | 5 +- src/coap_tinydtls.c | 7 +-- src/encode.c | 7 +-- src/mem.c | 11 +---- src/net.c | 17 +------ src/option.c | 9 +--- src/pdu.c | 10 +--- src/resource.c | 10 +--- src/str.c | 7 +-- src/subscribe.c | 7 +-- src/uri.c | 9 +--- win32/libcoap.vcxproj | 10 +++- win32/libcoap.vcxproj.filters | 54 ++++++++++++-------- 38 files changed, 294 insertions(+), 246 deletions(-) create mode 100644 include/coap2/coap_forward_decls.h create mode 100644 include/coap2/coap_internal.h create mode 100644 include/coap2/coap_session_internal.h create mode 100644 include/coap2/coap_subscribe_internal.h diff --git a/Makefile.am b/Makefile.am index df21b53a..03c05046 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,9 @@ EXTRA_DIST = \ libcoap-$(LIBCOAP_API_VERSION).sym \ examples/coap_list.h \ examples/getopt.c \ + include/coap$(LIBCOAP_API_VERSION)/coap_internal.h \ + include/coap$(LIBCOAP_API_VERSION)/coap_session_internal.h \ + include/coap$(LIBCOAP_API_VERSION)/coap_subscribe_internal.h \ include/coap$(LIBCOAP_API_VERSION)/utlist.h \ tests/test_error_response.h \ tests/test_options.h \ @@ -68,6 +71,7 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \ src/address.c \ src/async.c \ src/block.c \ + src/coap_debug.c \ src/coap_event.c \ src/coap_hashkey.c \ src/coap_gnutls.c \ @@ -77,7 +81,6 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \ src/coap_session.c \ src/coap_time.c \ src/coap_tinydtls.c \ - src/coap_debug.c \ src/encode.c \ src/mem.c \ src/net.c \ @@ -108,6 +111,7 @@ libcoap_include_HEADERS = \ $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_debug.h \ $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_dtls.h \ $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_event.h \ + $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_forward_decls.h \ $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_hashkey.h \ $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_io.h \ $(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_mutex.h \ diff --git a/examples/contiki/server.c b/examples/contiki/server.c index e51b09c7..ae8f3450 100644 --- a/examples/contiki/server.c +++ b/examples/contiki/server.c @@ -215,13 +215,8 @@ PROCESS_THREAD(coap_server_process, ev, data) while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { - coap_tick_t now; - - coap_ticks(&now); /* There is something to read on the endpoint */ - coap_context->endpoint->sock.flags |= COAP_SOCKET_CAN_READ; - /* read in, and send off any responses */ - coap_read(coap_context, now); /* read received data */ + coap_run_once(coap_context, COAP_RUN_BLOCK); } else if (ev == PROCESS_EVENT_TIMER && etimer_expired(&dirty_timer)) { coap_resource_notify_observers(time_resource, NULL); etimer_reset(&dirty_timer); diff --git a/include/coap2/coap.h.in b/include/coap2/coap.h.in index 17232702..37c249f4 100644 --- a/include/coap2/coap.h.in +++ b/include/coap2/coap.h.in @@ -32,6 +32,7 @@ extern "C" { #include "libcoap.h" +#include "coap_forward_decls.h" #include "address.h" #include "async.h" #include "bits.h" diff --git a/include/coap2/coap_forward_decls.h b/include/coap2/coap_forward_decls.h new file mode 100644 index 00000000..2325f08e --- /dev/null +++ b/include/coap2/coap_forward_decls.h @@ -0,0 +1,48 @@ +/* + * coap_forward_decls.h -- Forward declarations of structures that are + * opaque to application programming that use libcoap. + * + * Copyright (C) 2019 Jon Shallow + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +/** + * @file coap_forward_decls.h + * @brief COAP forward definitions + */ + +#ifndef COAP_FORWARD_DECLS_H_ +#define COAP_FORWARD_DECLS_H_ + +/* + * Define the forward declations for the structures (even non-opaque) + * so that applications (using coap.h) as well as libcoap builds + * can reference them (and makes .h file dependencies a lot simpler). + */ +struct coap_context_t; +struct coap_dtls_pki_t; +struct coap_endpoint_t; +struct coap_queue_t; +struct coap_session_t; +struct coap_string_t; +struct coap_subscription_t; + +/* + * typedef all the structures that are defined in coap_*_internal.h + */ + +/* ************* coap_session_internal.h ***************** */ + +/** +* Abstraction of virtual endpoint that can be attached to coap_context_t. +*/ +typedef struct coap_endpoint_t coap_endpoint_t; + +/* ************* coap_subscribe_internal.h ***************** */ + +/** Subscriber information */ +typedef struct coap_subscription_t coap_subscription_t; + +#endif /* COAP_FORWARD_DECLS_H_ */ diff --git a/include/coap2/coap_internal.h b/include/coap2/coap_internal.h new file mode 100644 index 00000000..08ac4db3 --- /dev/null +++ b/include/coap2/coap_internal.h @@ -0,0 +1,44 @@ +/* + * coap_internal.h -- Structures, Enums & Functions that are not exposed to + * application programming + * + * Copyright (C) 2019 Jon Shallow + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +/* + * All libcoap library files should include this file which then pulls in all + * of the other appropriate header files. + * + * Note: This file should never be included in application code (with the + * possible exception of internal test suites). + */ + +/** + * @file coap_internal.h + * @brief Pulls together all the internal only header files + */ + +#ifndef COAP_INTERNAL_H_ +#define COAP_INTERNAL_H_ + +#include "coap_config.h" +#include "coap.h" + +/* + * Include all the header files that are for internal use only. + */ + +/* Not defined in coap.h - internal usage .h files */ +#include "utlist.h" +#include "uthash.h" +#include "coap_hashkey.h" +#include "coap_mutex.h" + +/* Specifically defined internal .h files */ +#include "coap_session_internal.h" +#include "coap_subscribe_internal.h" + +#endif /* COAP_INTERNAL_H_ */ diff --git a/include/coap2/coap_session.h b/include/coap2/coap_session.h index aa596be3..d8e041de 100644 --- a/include/coap2/coap_session.h +++ b/include/coap2/coap_session.h @@ -6,6 +6,11 @@ * README for terms of use. */ +/** + * @file coap_session.h + * @brief Defines the application visible session information + */ + #ifndef COAP_SESSION_H_ #define COAP_SESSION_H_ @@ -15,10 +20,6 @@ #include "pdu.h" #include "uthash.h" -struct coap_endpoint_t; -struct coap_context_t; -struct coap_queue_t; - /** * Abstraction of a fixed point number that can be used where necessary instead * of a float. 1,000 fractional bits equals one integer @@ -211,8 +212,6 @@ coap_session_t *coap_new_client_session_psk( unsigned key_len ); -struct coap_dtls_pki_t; - /** * Creates a new client session to the designated server with PKI credentials * @param ctx The CoAP context. @@ -305,19 +304,6 @@ const char *coap_session_str(const coap_session_t *session); ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, struct coap_queue_t *node); -/** -* Abstraction of virtual endpoint that can be attached to coap_context_t. The -* tuple (handle, addr) must uniquely identify this endpoint. -*/ -typedef struct coap_endpoint_t { - struct coap_endpoint_t *next; - struct coap_context_t *context; /**< endpoint's context */ - coap_proto_t proto; /**< protocol used on this interface */ - uint16_t default_mtu; /**< default mtu for this interface */ - coap_socket_t sock; /**< socket object for the interface, if any */ - coap_address_t bind_addr; /**< local interface address */ - coap_session_t *sessions; /**< hash table or list of active sessions */ -} coap_endpoint_t; /** * Create a new endpoint for communicating with peers. diff --git a/include/coap2/coap_session_internal.h b/include/coap2/coap_session_internal.h new file mode 100644 index 00000000..966957b2 --- /dev/null +++ b/include/coap2/coap_session_internal.h @@ -0,0 +1,41 @@ +/* + * coap_session_internal.h -- Structures, Enums & Functions that are not + * exposed to application programming + * + * Copyright (C) 2010-2019 Olaf Bergmann + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +/** + * @file coap_session_internal.h + * @brief COAP session internal information + */ + +#ifndef COAP_SESSION_INTERNAL_H_ +#define COAP_SESSION_INTERNAL_H_ + +/** + * @defgroup session_internal Sessions (Internal) + * Structures, Enums and Functions that are not exposed to applications + * @{ + */ + +/** +* Abstraction of virtual endpoint that can be attached to coap_context_t. The +* tuple (handle, addr) must uniquely identify this endpoint. +*/ +struct coap_endpoint_t { + struct coap_endpoint_t *next; + struct coap_context_t *context; /**< endpoint's context */ + coap_proto_t proto; /**< protocol used on this interface */ + uint16_t default_mtu; /**< default mtu for this interface */ + coap_socket_t sock; /**< socket object for the interface, if any */ + coap_address_t bind_addr; /**< local interface address */ + struct coap_session_t *sessions; /**< hash table or list of active sessions */ +}; + +/** @} */ + +#endif /* COAP_SESSION_INTERNAL_H_ */ diff --git a/include/coap2/coap_subscribe_internal.h b/include/coap2/coap_subscribe_internal.h new file mode 100644 index 00000000..3c1ae656 --- /dev/null +++ b/include/coap2/coap_subscribe_internal.h @@ -0,0 +1,65 @@ +/* + * coap_subscribe_internal.h -- Structures, Enums & Functions that are not + * exposed to application programming + * + * Copyright (C) 2010-2019 Olaf Bergmann + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +/** + * @file coap_subscribe_internal.h + * @brief COAP subscribe internal information + */ + +#ifndef COAP_SUBSCRIBE_INTERNAL_H_ +#define COAP_SUBSCRIBE_INTERNAL_H_ + +/** + * @defgroup subscribe_internal Subscribe (Internal) + * Structures, Enums and Functions that are not exposed to applications + * @{ + */ + +#ifndef COAP_OBS_MAX_NON +/** + * Number of notifications that may be sent non-confirmable before a confirmable + * message is sent to detect if observers are alive. The maximum allowed value + * here is @c 15. + */ +#define COAP_OBS_MAX_NON 5 +#endif /* COAP_OBS_MAX_NON */ + +#ifndef COAP_OBS_MAX_FAIL +/** + * Number of confirmable notifications that may fail (i.e. time out without + * being ACKed) before an observer is removed. The maximum value for + * COAP_OBS_MAX_FAIL is @c 3. + */ +#define COAP_OBS_MAX_FAIL 3 +#endif /* COAP_OBS_MAX_FAIL */ + +/** Subscriber information */ +struct coap_subscription_t { + struct coap_subscription_t *next; /**< next element in linked list */ + struct coap_session_t *session; /**< subscriber session */ + + unsigned int non_cnt:4; /**< up to 15 non-confirmable notifies allowed */ + unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */ + unsigned int dirty:1; /**< set if the notification temporarily could not be + * sent (in that case, the resource's partially + * dirty flag is set too) */ + unsigned int has_block2:1; /**< GET request had Block2 definition */ + uint16_t tid; /**< transaction id, if any, in regular host byte order */ + coap_block_t block2; /**< GET request Block2 definition */ + size_t token_length; /**< actual length of token */ + unsigned char token[8]; /**< token used for subscription */ + struct coap_string_t *query; /**< query string used for subscription, if any */ +}; + +void coap_subscription_init(coap_subscription_t *); + +/** @} */ + +#endif /* COAP_SUBSCRIBE_INTERNAL_H_ */ diff --git a/include/coap2/lwippools.h b/include/coap2/lwippools.h index cb90d809..da5eea9a 100644 --- a/include/coap2/lwippools.h +++ b/include/coap2/lwippools.h @@ -9,7 +9,7 @@ * include this or include something more generic which includes this), and * MEMP_USE_CUSTOM_POOLS has to be set in lwipopts.h. */ -#include "coap_config.h" +#include "coap_internal.h" #include #include #include diff --git a/include/coap2/resource.h b/include/coap2/resource.h index 58018720..07effe0d 100644 --- a/include/coap2/resource.h +++ b/include/coap2/resource.h @@ -24,6 +24,7 @@ #include "uthash.h" #include "async.h" +#include "block.h" #include "str.h" #include "pdu.h" #include "net.h" diff --git a/include/coap2/subscribe.h b/include/coap2/subscribe.h index ed635a61..11a769d8 100644 --- a/include/coap2/subscribe.h +++ b/include/coap2/subscribe.h @@ -8,14 +8,14 @@ * of use. */ +/** + * @file subscribe.h + * @brief Defines the application visible subscribe information + */ #ifndef COAP_SUBSCRIBE_H_ #define COAP_SUBSCRIBE_H_ -#include "address.h" -#include "coap_io.h" -#include "block.h" - /** * @defgroup observe Resource observation * API functions for interfacing with the observe handling (RFC7641) @@ -34,44 +34,6 @@ */ #define COAP_OBSERVE_CANCEL 1 -#ifndef COAP_OBS_MAX_NON -/** - * Number of notifications that may be sent non-confirmable before a confirmable - * message is sent to detect if observers are alive. The maximum allowed value - * here is @c 15. - */ -#define COAP_OBS_MAX_NON 5 -#endif /* COAP_OBS_MAX_NON */ - -#ifndef COAP_OBS_MAX_FAIL -/** - * Number of confirmable notifications that may fail (i.e. time out without - * being ACKed) before an observer is removed. The maximum value for - * COAP_OBS_MAX_FAIL is @c 3. - */ -#define COAP_OBS_MAX_FAIL 3 -#endif /* COAP_OBS_MAX_FAIL */ - -/** Subscriber information */ -typedef struct coap_subscription_t { - struct coap_subscription_t *next; /**< next element in linked list */ - coap_session_t *session; /**< subscriber session */ - - unsigned int non_cnt:4; /**< up to 15 non-confirmable notifies allowed */ - unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */ - unsigned int dirty:1; /**< set if the notification temporarily could not be - * sent (in that case, the resource's partially - * dirty flag is set too) */ - unsigned int has_block2:1; /**< GET request had Block2 definition */ - uint16_t tid; /**< transaction id, if any, in regular host byte order */ - coap_block_t block2; /**< GET request Block2 definition */ - size_t token_length; /**< actual length of token */ - unsigned char token[8]; /**< token used for subscription */ - coap_string_t *query; /**< query string used for subscription, if any */ -} coap_subscription_t; - -void coap_subscription_init(coap_subscription_t *); - /** @} */ #endif /* COAP_SUBSCRIBE_H_ */ diff --git a/libcoap-2.map b/libcoap-2.map index 862b2187..3a4f82d1 100644 --- a/libcoap-2.map +++ b/libcoap-2.map @@ -181,7 +181,6 @@ global: coap_split_uri; coap_startup; coap_string_tls_version; - coap_subscription_init; coap_ticks; coap_ticks_from_rt_us; coap_ticks_to_rt; diff --git a/libcoap-2.sym b/libcoap-2.sym index fe2c32e6..3e733379 100644 --- a/libcoap-2.sym +++ b/libcoap-2.sym @@ -179,7 +179,6 @@ coap_split_query coap_split_uri coap_startup coap_string_tls_version -coap_subscription_init coap_ticks coap_ticks_from_rt_us coap_ticks_to_rt diff --git a/src/address.c b/src/address.c index 6762627e..6a49f1fd 100644 --- a/src/address.c +++ b/src/address.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) #ifdef HAVE_ASSERT_H @@ -25,8 +25,6 @@ #include #endif -#include "address.h" - #ifdef RIOT_VERSION /* FIXME */ #define IN_MULTICAST(Address) (0) diff --git a/src/async.c b/src/async.c index d787990a..310cb308 100644 --- a/src/async.c +++ b/src/async.c @@ -11,14 +11,9 @@ * @brief state management for asynchronous messages */ -#ifndef WITHOUT_ASYNC +#include "coap_internal.h" -#include "coap_config.h" -#include "coap.h" -#include "async.h" -#include "coap_debug.h" -#include "mem.h" -#include "utlist.h" +#ifndef WITHOUT_ASYNC /* utlist-style macros for searching pairs in linked lists */ #define SEARCH_PAIR(head,out,field1,val1,field2,val2) \ diff --git a/src/block.c b/src/block.c index 9dbf9d6b..2774acda 100644 --- a/src/block.c +++ b/src/block.c @@ -6,18 +6,12 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #if defined(HAVE_ASSERT_H) && !defined(assert) # include #endif -#include "libcoap.h" -#include "coap_debug.h" -#include "block.h" -#include "resource.h" -#include "coap_hashkey.h" - #ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) #endif diff --git a/src/coap_debug.c b/src/coap_debug.c index 2e01a7e6..ad7fae25 100644 --- a/src/coap_debug.c +++ b/src/coap_debug.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #if defined(HAVE_STRNLEN) && defined(__GNUC__) && !defined(_GNU_SOURCE) #define _GNU_SOURCE 1 @@ -32,13 +32,6 @@ #include #endif -#include "libcoap.h" -#include "block.h" -#include "coap_debug.h" -#include "encode.h" -#include "net.h" -#include "coap_mutex.h" - #ifdef WITH_LWIP # define fprintf(fd, ...) LWIP_PLATFORM_DIAG((__VA_ARGS__)) # define fflush(...) diff --git a/src/coap_event.c b/src/coap_event.c index 91c9ba9a..86f5c9b0 100644 --- a/src/coap_event.c +++ b/src/coap_event.c @@ -7,8 +7,7 @@ * of use. */ -#include "coap_event.h" -#include "net.h" +#include "coap_internal.h" /* * This replaces coap_set_event_handler() so that handler registration is diff --git a/src/coap_gnutls.c b/src/coap_gnutls.c index c1367d34..408e5040 100644 --- a/src/coap_gnutls.c +++ b/src/coap_gnutls.c @@ -19,16 +19,12 @@ * g_env A coap_gnutls_env_t * (held in c_session->tls) */ -#include "coap_config.h" +#include "coap_internal.h" #ifdef HAVE_LIBGNUTLS #define MIN_GNUTLS_VERSION "3.3.0" -#include "net.h" -#include "mem.h" -#include "coap_debug.h" -#include "prng.h" #include #include #include diff --git a/src/coap_hashkey.c b/src/coap_hashkey.c index 7171b48e..f4782d01 100644 --- a/src/coap_hashkey.c +++ b/src/coap_hashkey.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_hashkey.h" +#include "coap_internal.h" void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h) { diff --git a/src/coap_io.c b/src/coap_io.c index d8e0e788..b6964611 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #ifdef HAVE_STDIO_H # include @@ -49,16 +49,6 @@ # include "uip.h" #endif -#include "libcoap.h" -#include "coap_debug.h" -#include "mem.h" -#include "net.h" -#include "coap_io.h" -#include "pdu.h" -#include "utlist.h" -#include "resource.h" -#include "coap_mutex.h" - #if !defined(WITH_CONTIKI) /* define generic PKTINFO for IPv4 */ #if defined(IP_PKTINFO) @@ -1587,8 +1577,15 @@ coap_run_once(coap_context_t *ctx, unsigned timeout_ms) { return (int)(((now - before) * 1000) / COAP_TICKS_PER_SECOND); } -#else +#else /* WITH_CONTIKI */ int coap_run_once(coap_context_t *ctx, unsigned int timeout_ms) { + coap_tick_t now; + + coap_ticks(&now); + /* There is something to read on the endpoint */ + ctx->endpoint->sock.flags |= COAP_SOCKET_CAN_READ; + /* read in, and send off any responses */ + coap_read(ctx, now); /* read received data */ return -1; } @@ -1602,7 +1599,7 @@ coap_write(coap_context_t *ctx, *num_sockets = 0; return 0; } -#endif +#endif /* WITH_CONTIKI */ #ifdef _WIN32 static const char *coap_socket_format_errno(int error) { diff --git a/src/coap_io_lwip.c b/src/coap_io_lwip.c index ac16f099..501c405d 100644 --- a/src/coap_io_lwip.c +++ b/src/coap_io_lwip.c @@ -7,9 +7,7 @@ * README for terms of use. */ -#include "coap_config.h" -#include "mem.h" -#include "coap_io.h" +#include "coap_internal.h" #include #if NO_SYS diff --git a/src/coap_notls.c b/src/coap_notls.c index 4a8344d1..e85bd19e 100644 --- a/src/coap_notls.c +++ b/src/coap_notls.c @@ -7,12 +7,10 @@ * of use. */ -#include "coap_config.h" +#include "coap_internal.h" #if !defined(HAVE_LIBTINYDTLS) && !defined(HAVE_OPENSSL) && !defined(HAVE_LIBGNUTLS) -#include "net.h" - #ifdef __GNUC__ #define UNUSED __attribute__((unused)) #else /* __GNUC__ */ diff --git a/src/coap_openssl.c b/src/coap_openssl.c index 9b0dd66f..70b826d0 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -8,7 +8,7 @@ * of use. */ -#include "coap_config.h" +#include "coap_internal.h" #ifdef HAVE_OPENSSL @@ -40,10 +40,6 @@ * have additional run time checks. * */ -#include "net.h" -#include "mem.h" -#include "coap_debug.h" -#include "prng.h" #include #include #include diff --git a/src/coap_session.c b/src/coap_session.c index 47815883..f2725a92 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -6,19 +6,11 @@ * README for terms of use. */ +#include "coap_internal.h" + #ifndef COAP_SESSION_C_ #define COAP_SESSION_C_ - -#include "coap_config.h" -#include "coap_io.h" -#include "coap_session.h" -#include "net.h" -#include "coap_debug.h" -#include "mem.h" -#include "resource.h" -#include "utlist.h" -#include "encode.h" #include #ifdef COAP_EPOLL_SUPPORT diff --git a/src/coap_time.c b/src/coap_time.c index 0193319a..1af76e06 100644 --- a/src/coap_time.c +++ b/src/coap_time.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #ifdef HAVE_TIME_H #include @@ -21,9 +21,6 @@ #include #endif -#include "libcoap.h" -#include "coap_time.h" - static coap_tick_t coap_clock_offset = 0; #if _POSIX_TIMERS && !defined(__APPLE__) diff --git a/src/coap_tinydtls.c b/src/coap_tinydtls.c index 4de3a5fe..ca2f0f02 100644 --- a/src/coap_tinydtls.c +++ b/src/coap_tinydtls.c @@ -7,15 +7,10 @@ * of use. */ -#include "coap_config.h" +#include "coap_internal.h" #ifdef HAVE_LIBTINYDTLS -#include "net.h" -#include "address.h" -#include "coap_debug.h" -#include "mem.h" - /* We want TinyDTLS versions of these, not libcoap versions */ #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME diff --git a/src/encode.c b/src/encode.c index 28e2bf78..c1474e83 100644 --- a/src/encode.c +++ b/src/encode.c @@ -6,15 +6,12 @@ * README for terms of use. */ +#include "coap_internal.h" + #ifndef NDEBUG # include #endif -#include "coap_config.h" -#include "coap.h" -#include "mem.h" -#include "encode.h" - /* Carsten suggested this when fls() is not available: */ #ifndef HAVE_FLS int coap_fls(unsigned int i) { diff --git a/src/mem.c b/src/mem.c index a181cba4..75b8d98c 100644 --- a/src/mem.c +++ b/src/mem.c @@ -7,10 +7,7 @@ */ -#include "coap_config.h" -#include "libcoap.h" -#include "mem.h" -#include "coap_debug.h" +#include "coap_internal.h" #ifdef HAVE_ASSERT_H #include @@ -67,12 +64,6 @@ struct coap_stringbuf_t { char data[COAP_MAX_STRING_SIZE]; }; -#include "coap_config.h" -#include "net.h" -#include "pdu.h" -#include "coap_io.h" -#include "resource.h" -#include "coap_session.h" #define COAP_MAX_PACKET_SIZE (sizeof(coap_packet_t) + COAP_RXBUFFER_SIZE) #ifndef COAP_MAX_PACKETS diff --git a/src/net.c b/src/net.c index f46b6549..81d97ee7 100644 --- a/src/net.c +++ b/src/net.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #include #include @@ -49,20 +49,6 @@ #include #endif -#include "libcoap.h" -#include "utlist.h" -#include "coap_debug.h" -#include "mem.h" -#include "str.h" -#include "async.h" -#include "resource.h" -#include "option.h" -#include "encode.h" -#include "block.h" -#include "net.h" -#include "utlist.h" -#include "coap_mutex.h" - #ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) #endif @@ -132,7 +118,6 @@ coap_free_node(coap_queue_t *node) { # define DEBUG DEBUG_PRINT # endif /* DEBUG */ -#include "mem.h" #include "net/ip/uip-debug.h" #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) diff --git a/src/option.c b/src/option.c index 84a3127b..b162f5f4 100644 --- a/src/option.c +++ b/src/option.c @@ -8,7 +8,7 @@ */ -#include "coap_config.h" +#include "coap_internal.h" #if defined(HAVE_ASSERT_H) && !defined(assert) # include @@ -17,13 +17,6 @@ #include #include -#include "libcoap.h" -#include "option.h" -#include "encode.h" /* for coap_fls() */ -#include "coap_debug.h" -#include "mem.h" -#include "utlist.h" - #define ADVANCE_OPT(o,e,step) if ((e) < step) { \ coap_log(LOG_DEBUG, "cannot advance opt past end\n"); \ return 0; \ diff --git a/src/pdu.c b/src/pdu.c index fa8d47e3..364b368f 100644 --- a/src/pdu.c +++ b/src/pdu.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #if defined(HAVE_ASSERT_H) && !defined(assert) # include @@ -26,14 +26,6 @@ #include #endif -#include "libcoap.h" -#include "coap_debug.h" -#include "pdu.h" -#include "option.h" -#include "encode.h" -#include "mem.h" -#include "coap_session.h" - #ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) #endif diff --git a/src/resource.c b/src/resource.c index 84fa783c..7c17f360 100644 --- a/src/resource.c +++ b/src/resource.c @@ -6,15 +6,9 @@ * README for terms of use. */ +#include "coap_internal.h" + #include -#include "coap_config.h" -#include "coap.h" -#include "coap_debug.h" -#include "mem.h" -#include "net.h" -#include "resource.h" -#include "subscribe.h" -#include "utlist.h" #if defined(WITH_LWIP) /* mem.h is only needed for the string free calls for diff --git a/src/str.c b/src/str.c index 67fdb10f..16b138bb 100644 --- a/src/str.c +++ b/src/str.c @@ -6,15 +6,10 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #include -#include "libcoap.h" -#include "coap_debug.h" -#include "mem.h" -#include "str.h" - coap_string_t *coap_new_string(size_t size) { coap_string_t *s = (coap_string_t *)coap_malloc_type(COAP_STRING, sizeof(coap_string_t) + size + 1); diff --git a/src/subscribe.c b/src/subscribe.c index 14bad6fa..0a1552d5 100644 --- a/src/subscribe.c +++ b/src/subscribe.c @@ -1,21 +1,18 @@ /* subscribe.c -- subscription handling for CoAP * see draft-ietf-coap-observe-16 * - * Copyright (C) 2010--2013,2015 Olaf Bergmann + * Copyright (C) 2010--2019 Olaf Bergmann * * This file is part of the CoAP library libcoap. Please see * README for terms of use. */ -#include "coap_config.h" -#include "coap.h" +#include "coap_internal.h" #if defined(HAVE_ASSERT_H) && !defined(assert) # include #endif -#include "subscribe.h" - void coap_subscription_init(coap_subscription_t *s) { assert(s); diff --git a/src/uri.c b/src/uri.c index 78dcf716..596e5d16 100644 --- a/src/uri.c +++ b/src/uri.c @@ -6,7 +6,7 @@ * README for terms of use. */ -#include "coap_config.h" +#include "coap_internal.h" #if defined(HAVE_ASSERT_H) && !defined(assert) # include @@ -21,13 +21,6 @@ #include #include -#include "libcoap.h" -#include "mem.h" -#include "coap_debug.h" -#include "pdu.h" -#include "option.h" -#include "uri.h" - /** * A length-safe version of strchr(). This function returns a pointer * to the first occurrence of @p c in @p s, or @c NULL if not found. diff --git a/win32/libcoap.vcxproj b/win32/libcoap.vcxproj index d1bd6d45..2a90ee3d 100644 --- a/win32/libcoap.vcxproj +++ b/win32/libcoap.vcxproj @@ -38,15 +38,16 @@ + + - @@ -64,12 +65,17 @@ + + + + + + - diff --git a/win32/libcoap.vcxproj.filters b/win32/libcoap.vcxproj.filters index a76bf054..3838d1f3 100644 --- a/win32/libcoap.vcxproj.filters +++ b/win32/libcoap.vcxproj.filters @@ -24,13 +24,34 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + Source Files + + Source Files + + + Source Files + + + Source Files + Source Files - + Source Files @@ -60,24 +81,6 @@ Source Files - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - @@ -98,6 +101,9 @@ Header Files + + Header Files + Header Files @@ -107,13 +113,19 @@ Header Files + + Header Files + Header Files - + Header Files - + + Header Files + + Header Files