This then makes sure that all things libcoap are properly initialized
before use, and coders realize they need to do this.
Note: coap_new_context() continues to make sure that coap_startup()
is invoked if not done previously, but this may be too late.
Drop the use of syslog LOG_DEBUG etc. for coap_log() and use the
coap_log_debug() etc. macros which make use of COAP_LOG_DEBUG etc.
Application examples updated, as well as the man page examples.
Move coap_pdu_t to coap_pdu_internal.h.
Move internal PDU based function definitions to coap_pdu_internal.h.
Replace most references to "struct coap_pdu_t" with "coap_pdu_t".
Create new enum coap_pdu_type_t, enum coap_pdu_code_t and coap_option_num_t,
using them where appropriate for clarity of documentation.
Provide new functions to allow applications to access/update parts of
coap_pdu_t as appropriate and document as appropriate.
Update examples to use these new access functions where appropriate.
Create a new include/coap2/coap_resource_internal.h to hold all the information
not available to applications.
Makefile.am:
Include coap_resource_internal.h in EXTRA_DIST.
Remove functions no longer visible from CTAGS_IGNORE.
examples/coap-rd.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
tests/test_wellknown.c
Replace direct access to coap_resource_t variables with functions as
appropriate.
include/coap2/resource.h:
include/coap2/subscribe.h:
include/coap2/coap_resource_internal.h: (New)
include/coap2/coap_subscribe_internal.h:
Move coap_resource_t, coap_addr_t, non API #defines and non API functions from
resource.h into coap_resource_internal.h, coap_subscribe_internal.h and
subscribe.h.
Replace inline functions accessing coap_resource_t with actual function
definitions.
Add new functions coap_resource_release_userdata_handler() and
coap_attr_get_value().
include/coap2/block.h:
Use coap_resource_t typedef.
include/coap2/coap_forward_decls.h:
Include coap_resource_t and coap_addr_t typedefs. Also typedef coap_context_t
to get rid of #include circular requirements.
include/coap2/coap_internal.h:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:
Include coap_resource_internal.h.
include/coap2/net.h:
Remove "typedef struct coap_context_t" and do this in coap_forward_decls.h.
src/resource.c:
Update with the replaced inline functions. Add in the new functions
coap_resource_release_userdata_handler() and coap_attr_get_value().
libcoap-2.map:
libcoap-2.sym:
Update with new function visibility.
man/Makefile.am:
man/coap_attribute.txt.in:
man/coap_observe.txt.in:
man/coap_resource.txt.in:
Update with the new coap_resource_t and coap_attr_t usage.
Replace COAP_RUN_BLOCK with COAP_IO_WAIT and COAP_RUN_NOBLOCK with
COAP_IO_NO_WAIT for naming clarity.
Instead of COAP_IO_NO_WAIT being 1, make it -1 to fix 1ms busy loop.
Handle the case when coap_io_prepare_io returns 0 to prevent indefinite
select() wait.
include/coap2/net.h:
Make the timeout_ms parameter uint32_t in coap_io_process*() functions to
make sure special case of COAP_IO_NO_BLOCK is correctly handled on different
architectures.
Update COAP_IO_NO_BLOCK to -1.
src/coap_io.c:
Fix the 1ms busy loop and potential infinite wait in the non epoll case.
man/coap_io.txt.in:
Update documentation to reflect the changes.
examples/coap-server.c:
examples/contiki/server.c:
Update to use COAP_IO WAIT and COAP_IO_NO_WAIT as appropriate.
coap_read(), coap_write() and coap_run_once() are confusing in their names
and do not really describe what they do.
For example, coap_read() does both reading and writing, coap_write() may
do some writing, but primarily is used to determine what should be monitored
and for how long to wait in the following select() or epoll_wait() calls.
coap_run_once() implies that the code is only to be run once - again confusing.
By renaming coap_read() to coap_io_do_io(), this better describes what this
function does.
By renaming coap_write() to coap_io_prepare_io() this better describes what this
function does.
By renaming coap_run_once() to coap_io_process(), this better describes what
this function does.
By renaming coap_io_do_events() to coap_io_do_epoll(), this better describes what
this function does and is associated with.
A wrapper function coap_io_prepare_epoll() has been created, using
coap_io_prepare_io() with some preset values to simplify function usage.
include/coap2/net.h:
Update with the new function names, and deprecate the old functions. Also
document the fact that coap_io_prepare_io(), coap_io_do_io(),
coap_io_prepare_epoll(), and coap_io_do_epoll() are really internal functions.
Create app_io module for Doxygen.
libcoap-2.map:
libcoap-2.sym:
Expose the new functions to applications.
examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/contiki/coap-observer.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
man/coap_io.txt.in:
man/coap_observe.txt.in:
src/coap_io.c:
src/coap_io_lwip.c:
src/net.c:
src/pdu.c:
Update using the new function names.
Setting the etimer has been moved out of coap_io_process() into
coap_io_do_epoll(), making the logic easier for applications to use
coap_io_do_epoll() should they need to. This also gets rid of a
potential timing window where a pending etimer event gets missed.
coap_io_do_epoll() now calls coap_io_prepare_epoll() if the etimer has
triggered removing the need for applications using coap_io_do_epoll() to
set up their own loops if etimer is triggered.
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.
Update code to use new APIs
[Some code changes modelled on PR #202, some code being moved between files]
Remove #ifdef WITH_LWIP from coap_io.c as file is not used
Add in resource time to lwip
Update for Travis build
Report on Contiki memory allocate failures to ease debugging
Make the different memory type counts configurable by using the -D option
included in a CFLAGS definition to the ./configure command line
.travis.yml
BUILDING
Makefile.libcoap
examples/contiki/Makefile
examples/contiki/README new
examples/contiki/server.c
examples/contiki/.gitignore (new)
examples/lwip/Makefile
examples/lwip/README
examples/lwip/lwipopts.h
examples/lwip/server-coap.c
examples/lwip/server.c
include/coap/address.h
include/coap/coap_io.h
include/coap/lwippools.h
include/coap/pdu.h
scripts/build.sh
src/address.c
src/coap_io.c
src/coap_io_lwip.c
src/coap_session.c
src/mem.c
src/net.c
src/pdu.c
New struct coap_binary_t - same as coap_string_t, used for tokens
Deprecate struct str with the intent of removing it downstream as it
polutes namespace.
Make end of coap_string_t data a NUL.
Updated coap_make_str_const(), removing .length= and .s= to keep upstream
compilers happy.
Update Doxygen for str.h
Files:
examples/client.c
examples/coap-rd.c
examples/coap-server.c
examples/contiki/server.c
examples/etsi_iot_01.c
include/coap/resource.h
include/coap/str.h
include/coap/subscribe.h
man/coap_observe.txt.in
src/net.c
src/resource.c
src/str.c
src/uri.c
tests/test_options.c
Update
Update code / examples / man pages with the updated function.
include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used
include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.
Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability
src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.
examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
The value of the observe option is kept for each resource rather than being global to the context.
The value of the observe option must wrap to be stay below 2^24.
The value of the observe option must be different from the initial value when a notification is sent.
The debug function for printing lladdress have been renamed and moved
to net-debug.h. This change now includes this header and uses the
appropriate macros instead.
uip_ds6_prefix_add is using 6 arguments, better use explicit argument
list than let the compiler decide. Some compiler will complain if some
optionally arguments are missed.
Directory examples/contiki now contains a small example server for
Contiki and a Makefile for platform minimal-net.
Build:
make contiki # clones Contiki
make server # creates the minimal-net coap server
Run:
Unfortunately, you have to run the server with sudo unless you
set CAP_NET_ADMIN for both, the server executable, and ifconfig
(sudo setcap cap_net_admin+pei ...).
sudo ./server
Then, add the server's interface address to the tap0 device and
optionally set a default route:
sudo ip -6 a a aaaa::1000 dev tap0
sudo ip -6 r a aaaa::/64 dev tap0
Although everything should work now, it does not. I had to send
router advertisements on tap0:
sudo radvd -C ./radvd.conf
Note that on Debian (and Ubuntu, and ...), radvd will not start
when IPv6 forwarding is disabled (which is usually the case on
end systems). Trying to enable like this did not work for me:
sudo sysctl -w net.ipv6.conf.tap0.forwarding=1
sudo sysctl -w net.ipv6.conf.tap0.mc_forwarding=1
Workaround (ugly): get the radvd sources, compile them and use that.