Commit Graph
13 Commits
Author SHA1 Message Date
Jon Shallow e0a6593728 memory: Add in support for creating coap_binary_t objects
Add in coap_new_binary() and coap_delete_binary() functions which operate
in the same way as coap_new_string() and coap_delete_string() but work on
coap_binary_t objects.

include/coap2/str.h:
src/str.c:

Add in the coap_new_binary(), coap_resize_binary() and coap_delete_binary()
functions.

configure.ac:
man/Makefile.am:
man/coap.txt.in:
man/coap_string.txt.in: (new)

Add in documentation for the coap_string functions.

libcoap-2.map:
libcoap-2.sym:

Update with new functions.

coap_config.h.contiki:
include/coap2/lwippools.h:
include/coap2/mem.h:
src/mem.c:

Add support for fixed memory allocations for Cacke-Key and Cache-Entry
2020-10-14 09:33:37 -04:00
Jon Shallow f1bc324f9b LwIP: Check memory allocation sizes for COAP_OPTLIST and COAP_STRING
These are fixed memory sizes, but applications can ask for a bigger size
which will lead to memory corruption.

src/option.c:
src/str.c:

Check the requesting size to verify that it is within limits.  Contiki
properly checks the sizes.  Return NULL if too large with a logged varning.
2020-06-30 19:51:06 +01:00
Jon Shallow 23b3e6e17e Add in coap_new_client_session_psk2 and coap_context_set_psk2 functions
This fix is in preparation for the full coap_new_client_session_psk2()
and coap_context_set_psk2() functions.  Structures are updated with the
necessary information, as well as provide the high level support.

As new sessions are now created for every genuine incoming session (#333),
coap_context_t will only hold the initial information provided by
coap_context_set_psk2() (server mode), but if there is any updated
(triggered by SNI or Indentity), this will be kept in coap_session_t.

Likewise, the client initial information will be kept in the
coap_session_t, and if modified (triggered by Hint) will be kept separately
in coap_session_t.

This change does not include the support required in the DTLS interface modules
other than changes required to make the code compilable and still run the
existing examples - so it is a standalone change.

Makefile.am:

Make coap_dtls_context_set_cpsk, coap_dtls_context_set_spsk,
coap_session_refresh_psk_key and coap_session_refresh_psk_hint hidden
Remove coap_dtls_context_set_psk

include/coap2/*.h:

Replace call-back with callback for consistency

include/coap2/coap_dtls.h:

Include coap_dtls_cpsk_key_t and coap_dtls_spsk_key_t definitions
Define coap_dtls_spsk_key_t for the new coap_*_psk2 functions.
Include all the new call back function definitions

include/coap2/coap_session.h:

Update coap_session_t with the new PSK information
Define coap_new_client_session_psk2(), coap_session_refresh_psk_key() and
coap_session_refresh_psk_hint() functions

include/coap2/net.h:

Update coap_context_t with the new PSK information
Define the coap_context_set_psk2() function

include/coap2/str.h:

Add in a new struct coap_bin_const_t
Define new functions coap_new_bin_const(), coap_delete_bin_const()
and coap_binary_equal().

libcoap-2.{map|sym}

Expose the new coap_context_set_psk2, coap_new_client_session_psk2,
coap_new_bin_const and coap_delete_bin_const functions

src/coap_gnutls.c:
src/coap_notls.c:
src/coap_tinydtls.c:

Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk()
and coap_dtls_context_set_cpsk()

src/coap_openssl.c:

Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk()
and coap_dtls_context_set_cpsk()
Update the SSL_CTX_use* and SSL_set_* functions with the new variable
locations

src/coap_session.c:

Free off new information on coap_session_t in coap_session_mfree()

Build parameters for coap_new_client_session_psk2() in
coap_new_client_session_psk() and call coap_new_client_session_psk2() instead
of coap_session_create_client().
Create new coap_new_client_session_psk2().
Create new coap_session_refresh_psk_key() (will be used when DTLS interface
code is updated

src/net.c:

Update coap_get_session_client_psk() to use the new PSK locations.
Update coap_get_session_server_psk() to use the new PSK locations.
Update coap_get_session_server_hint() to use the new PSK locations.
Build parameters for coap_context_set_psk2() in
coap_context_set_psk() and call coap_context_set_psk2().
Create new coap_context_set_psk2().
Cleanup usage of old PSK information in coap_free_context()

src/str.c:

Code for coap_new_bin_const() and coap_delete_bin_const() functions
2019-12-03 14:46:26 +00:00
Jon Shallow 8faa8c28ff Add --disable-assert support for the library
Let configure enable (the default) or disable assert() code.

configure.ac:

Add in --enable-assert (the default) / --disable-assert support in libcoap.
Previously this was always enabled unless -DNDEBUG was passed in as a compiler
option.  Now NDEBUG is set or unset as appropriate in coap_config.h
This does not affect how assert()s work within the examples etc., only in the
library.

TODO:

HAVE_ASSERT_H is now cleaned up, so remove entry.

include/coap2/coap_internal.h:

Include assert.h for the library.

include/coap2/coap_io.h:
include/coap2/net.h:
include/coap2/resource.h:
src/address.c:
src/block.c:
src/coap_debug.c:
src/encode.c:
src/mem.c:
src/option.c:
src/pdu.c:
src/subscribe.c:
src/uri.c:

Remove un-needed '#include <assert.h>'
Note: address.h and utlist.h still include assert.h as there are assert()
within the header files.

examples/client.c:
src/coap_io.c:
src/coap_session.c:
src/net.c:
src/pdu.c:
src/resource.c:
src/str.c:

Remove any '#ifndef NDEBUG' wrappers for coap_log() output as they were true
before, but may not be now.
2019-09-20 13:09:56 +01:00
Jon Shallow 2900f72a64 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.
2019-09-03 11:59:07 +01:00
Jon Shallow 5d32ffe920 str.h: Fix coap_make_str_const() for C++
As pointed out in issue #368 [1], C++ officially forbids aggregate
initialization for non-aggegrates. This change therefore introduces
an alternative version (which works for both C and C++) to provide
the required functionality.

str.c:
str.h:

Make coap_make_str_const() a function.

examples/coap-server.c:

Fix parameter type in coap_add_attr() call.

src/resource.c:

Static variables can no longer make use of coap_make_str_const().

libcoap-2.map:
libcoap-2.sym:

Make coap_make_str_const() appication visible.

Fixes #368.

[1] https://github.com/obgm/libcoap/issues/368

Update
2019-08-30 10:29:17 +01:00
Olaf Bergmann 0388bb9e38 Renamed debug.[hc] to coap_debug.[hc]
Prefixing the file name with "coap_" helps avoiding a name clash
when libcoap is included as package in RIOT [1].

[1] https://github.com/RIOT-OS/RIOT
2019-01-07 00:51:10 +01:00
Jon Shallow f5367ef3de Delete trailing spaces from files, replace TAB with 8*SPACE
"git diff -w" shows no differences

TAB left alone in files that are not C based files or documentation
2018-09-28 17:34:07 +01:00
Jon Shallow 06f57978de Replace str with coap_string_t. Make tokens coap_binary_t
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
2018-07-26 15:45:38 +01:00
Jon Shallow 25a8414105 src/*.c: Remove cast-qual compiler warnings
Where appropriate in general

Replace 'unsigned char' with 'const uint8_t'
Replace 'str' with 'coap_str_c_t'
Replace str with coap_string_t
Prefix with 'const' some type casts
Remove unnecessary type casting
Remove unneeded WITH_LWIP wrappers to select coap_malloc_type() or memp_malloc()
as underlying  coap_malloc_type() is correctly selected in include/coap/mem.h

src/block.c:
Replace coap_opt_const_value() with coap_opt_value()

src/coap_io.c:
Due to the definations of struct iovec and struct msghdr, and const parameters
getting passed in, as this is a write of data function, the pointers are
copied into the 2 structures to get around the cast-qual warnings

src/net.c:
Release any sessions (so that they may get freed off) in coap_free_context()

src/option.c:
coap_option_filter_get() had to be downgraded as coap_option_filter_op() is
used by set functions as well.

src/pdu.c:
Remove const out of next_option_safe() parameters

As coap_resource_init() has a const uri_path parameter passed into it, it is not
possible to have these values legally freed off if flags is set to
COAP_RESOURCE_FLAGS_RELEASE_URI.

coap_resource_init_release() has been created to handle this.  However, as it
is likely to be called with a coap_string_t generated from a call to
coap_get_uri_path(), the string must be correctly freed off.  Hence the
use of coap_string_t as a parameter.

coap_add_attr_release() has been added in as well, using coap_string_t* as
parameters, to allow the coap_string_t to be freed off correctly.

Add in coap_log warning if the functions coap_resource_init*() and
coap_add_attr*() are called incorrectly.

Update src
2018-05-25 16:38:07 +01:00
Jon Shallow 9821b4b689 str.c: Replace str with coap_string_t
At some point, str will get replaced in all of the code with coap_string_t.
This is to prevent potential name clashes when compiling application code.

Use coap_malloc_type(COAP_STRING,... instead of coap_malloc(...
2018-04-04 16:19:37 +01:00
jcmichelou 9b647d5d05 Add visual studio 2015 solution and project files for building libcoap on windows.
Merge changes from PR #47 related to windows platform support.
Add full windows platform support including correct error checking and working regression tests and examples.
Remove need to build applications using libcoap with -DWITH_POSIX and to include coap_config.h. This applies to the examples as well.
2017-05-05 20:29:10 +02:00
Carsten Schoenert fc9b47167a moving library related files to new folders
In preparation for changing the make buildsystem to a fully autotools
controlled system moving the core libcoap source files to a better logical
place.

All the library related header files moving to include/coap/ to get
all the public and local header files in a separate place. Also moving
the C source files of the libcoap library to the folder src/.
2015-03-03 19:21:43 +01:00