Commit Graph
273 Commits
Author SHA1 Message Date
Jean-Claude Michelou 01b2ec78fd examples: Add missing stat macro for win32. 2018-09-24 15:54:11 +02:00
jcmichelou 4e73052872 session: Improve event reporting, add auto-ping and csm timeout.
Add new event types to report the TCP connection status and CSM exchange
status to the application. Add optional auto send of ping messages for
reliable client sessions. Add default timeout of 30s for receiving a CSM
message from the remote host after connect.
2018-09-24 15:42:40 +02:00
Olaf Bergmann 1cef78ebda coap-server.c: check if data is present in PUT request
This change change fixes coverity CID 1472105.
2018-07-31 11:26:33 +02:00
Olaf Bergmann 57ee5eb55c coap-server.c: fix NULL-pointer dereference in example server
When realloc() returns NULL, hnd_put() must be left immediately
after setting the response code.

This change fixes coverity CID 1472106.
2018-07-31 11:23:04 +02: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 224153c206 coap-server: Support for being able to create dynamic resources on the fly
Add in -d max option, which then causes coap_resource_unknown_init() to get
called.

Number of dynamic resoures is limited by 'max'.  The current set of resources
can be determined by using .well-known/core

If max is reached, 4.06 is returned.

Fixed typo in man coap_resource(3) in example for unknown resources
2018-07-25 10:12:14 +01:00
Jon Shallow bb0b19546f examples/coap-server.c, examples/client.c Support new coap_dtls_pki_t
Updated to support the new coap_dtls_pki_t.

Add in new -C and -R options to support / test PKI mutual authentication

Make sure time resource is triggered no more frequently than once a sec.
2018-07-25 09:16:00 +01:00
Jon Shallow fd421dd119 debug.c: Make coap_show_pdu() use coap_log() or fprintf()
coap_show_pdu()'s API is now coap_show_pdu(coap_log_t, coap_pdu_t*)
New function void coap_set_show_pdu_output(int use_fprintf)
Default is use fprintf() instead of coap_log()

The output buffer size can be configuring -DCOAP_DEBUG_BUF_SIZE

Output COAP_OPTION_SIZE2 option as well

For binary data, output ascii readable equivalent immediately under the
hex output for ease of debugging.

include/coap/debug.h
src/debug.c

Update coap_show_pdu() API
New function coap_set_show_pdu_output()
Update coap_show_pdu() code

include/coap/pdu.h

Define the coap debug output debug buffer size
COAP_DEBUG_BUF_SIZE

examples/client.c
examples/contiki/coap-observer.c
src/net.c
tests/test_wellknown.c
tests/test_pdu.c

Update coap_show_pdu() calls

libcoap-2.map
libcoap-2.sym

New function coap_set_show_pdu_output()
2018-07-20 18:58:55 +01:00
Jon Shallow bf5dd5a82f coap-{client|server}: Add in PKI Support. Tidy up Usage output
examples/client.c

Add in support for using PKI certificates

examples/coap-server.c

Add in support for using PKI certificates
remove default PSK key
Add in '-h hint' option

Make Usage reflect actual options available to use

man/coap-client.txt.in

Include the missing options
Update -A option to be a single entity
Sort the options into ascending order as reported by Usage

man/coap-server.txt.in

Include the missing options
Add in '-h hint' option
2018-07-03 15:06:17 +01:00
Olaf Bergmann 0f8a3b334f coap-rd.c: remove type cast from RD_ROOT_STR
To ensure correct use of RD_ROOT_STR in coap_make_str_const() the
type cast to const uint8_t * has been removed.
This change addresses CID 1469634.
2018-06-06 16:49:12 +02:00
Olaf Bergmann df7b36edd5 client.c: explicitly restrict URI port number to 16 bits
To document that uri.port input to coap_encode_var_safe() never
has more than 16 bits, an explicit bit mask has been added. This
change is supposed to avoid the false positive CID 1469635.
2018-06-06 16:42:47 +02:00
Olaf Bergmann ec9bf6eb4a client.c: fix bug in Accept option parser
cmdline_content_type() treated option numbers as 8-bit integers and
therefore could not parse values >255. Now, option numbers are
represented as uint16_t to allow for numbers between 0 and 65535.

Moreover, as RFC 7252 has made the Accept option non-repeatable,
cmdline_content_type() now will only add a single Accept option.
2018-06-06 16:30:40 +02:00
Olaf Bergmann 171f25e123 client.c: fix -Wstringop-overflow warning in cmdline_token()
Calling strncpy() on the variable (and erroneous) calculated token
length in cmdline_token() has caused stringop-overflow warning by
GCC 8. This change fixes the error and replaces strncpy() by
memcpy() to quieten the compiler.
2018-06-05 12:28:40 +02:00
Jon Shallow c7e9359f02 Make coap_encode_var_bytes() by replacing with coap_encode_var_safe()
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
2018-06-05 09:41:58 +01:00
obgm 60f699d535 Merge pull request #189 from mrdeep1/optlist-mem-leak
options: Fix subtle memory leak in coap_add_optlist_pdu()
2018-06-04 14:05:01 +02:00
Olaf Bergmann 8e446e732a client.c: Remove unused function set_timeout()
The function is not used because most of the timer handling has
been moved to coap_run_once().

This change avoids clang to emit a warning due to -Wunused-function.
2018-05-31 11:12:01 +02:00
obgm 4cfc722bf1 Merge pull request #181 from mrdeep1/coap-server-crash
coap-server: Sanity check of input to hnd_put_time() to prevent crashes
2018-05-31 10:24:32 +02:00
Jon Shallow 9fa448e439 options: Fix subtle memory leak in coap_add_optlist_pdu()
coap_add_optlist_pdu() sorted the options for insertion, but did not update
the coap_optlist_t head (whch may then no longer point to the first entry in the
sorted chain) and so when coap_delete_optlist() was called, the first few
entries of the sorted chain may not get deleted.
Fixed by making it
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t** optlist_chain)
instead of
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain)

Additionally deleted options_start() and options_next() as they are not
required - Issue #184.

examples/client.c:
Fix coap_add_optlist_pdu() call

include/coap/options.h:
Fix coap_add_optlist_pdu() call

libcoap-2.{map|sym}:
Delete options_start()

man/coap_observe.txt.in:
man/coap_pdu_setup.txt.in:

Update docmentation

src/option.c:
Update coap_add_optlist_pdu()

tests/test_pdu.c:
New tests for checkout out coap_insert_optlist() and coap_add_optlist_pdu()
functions
2018-05-30 11:38:50 +01:00
Jon Shallow 7dc16ed184 tests/*.c, examples/*.c: Remove cast-qual compiler warnings
Created new 'CU_ASSERT_PTR_EQUAL_C(actual, expected)' to handle const variable matching

Where appropriate

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
Update coap_add_attr() calls inline with updated API
Update coap_resource_init() calls inline with updated API
Make use of coap_make_str_const() for defining parameters

tests*/.c
Update code to stop memory leaks (as found by valgrind)

examples/coap-rd.c
Track the fact that uri_path in coap_resource_t is now a pointer
2018-05-25 14:11:04 +01:00
Olaf Bergmann a2d263356e configure.ac: enable -Wwrite-strings
As discussed in bug #185 [1], const strings should be protected
from being overwritten. This change adds -Wwrite-strings to the
compiler warning flags and fixes resulting warnings by making
static strings const.

[1] https://github.com/obgm/libcoap/issues/185
2018-05-19 09:27:50 +02:00
Jon Shallow 828967bb43 examples/coap-server.c: Sanity check of input to hnd_put_time to prevent core
The input value for time in hnd_put_time() is not sanity checked for the
upper limit.  If too large, gmtime() etc. functions will return a failure
(errno is EOVERFLOW).

Validate the input value to hnd_put_time().  Return 4.00 if failure

Verify return from gmtime() in hnd_get_time() before trying to convert to
ascii readable string. Return 4.04 if failure.
[Time may just be valid when updated in hnd_put_time(), but then
increments to be too large - hence check also in hnd_get_time()]
2018-05-18 15:10:09 +01:00
Jon Shallow 02195e13a6 examples/coap_list.[ch]: Document that these files are DEPRECATED
/*
 * examples/coap_list.[ch] are DEPRECATED.  You should be using
 * struct coap_optlist_t instead with the following functions which are a part
 * of libcoap.
 *
 * coap_new_optlist()
 * coap_insert_optlist()
 * coap_delete_optlist()
 * coap_add_optlist_pdu()
 *
 * See 'man coap_pdu_setup' for further information.
 *
 * examples/coap_list.[ch] files will be removed in a future release
 * They are left here to support building backward compatability of old versions
 * of coap-client
 */
2018-05-17 19:02:21 +01:00
Jon Shallow 89f2f68ddf examples/coap-server.c: Replace debug() with coap_log(LOG_DEBUG, )
Replace debug() with coap_log(LOG_DEBUG, )
Remove unneeded include files
Remove compiler optimizer warnings for ntohs(htons())
Fix compiler warning about unused options
2018-05-17 18:45:07 +01:00
Jon Shallow 032a46fcb3 examples/coap-rd.c: Replace debug() with coap_log(LOG_DEBUG, ) 2018-05-17 18:45:07 +01:00
Jon Shallow 843f036b16 examples/Makefile.am: Remove coap_list.c from files needed for coap-client 2018-05-17 18:45:07 +01:00
Jon Shallow c129a0abe8 examples/client.c: Make use of new optlist functions
Remove coap_list_t structure and replace with coap_optlist_t to maintain
backward code compatability.
Make use of the new coap_optlist_* functions
Use the new coap_optlist_t structure
Remove unneeded header includes
warn() -> coap_log(LOG_WARNING, )
debug() -> coap_log(LOG_DEBUG, )
2018-05-17 18:41:46 +01:00
obgm 132a830b59 Merge pull request #165 from mrdeep1/DTLS-Connection
DTLS session setup retries to establish DTLS many times before failure
2018-04-13 17:53:20 +02:00
Jon Shallow 2582d085f8 examples/client.c: Run at least once per sec to aid debugging 2018-04-13 14:08:08 +01:00
Jon Shallow ef6c72bf44 examples/Makefile.am: Update for new libcoap library naming 2018-04-13 08:43:37 +01:00
Jon Shallow d015c50091 coap-{client|rd|server}.txt.in: Move from examples to man directory 2018-04-07 11:34:44 +01:00
Jon Shallow 20cd610c03 examples/Makefile.am: Remove building man pages
Delete building man pages as they are now a part of the man directory
2018-04-07 11:34:44 +01:00
Jon Shallow 849deb2610 examples/contiki/coap-observer.c: Use COAP_OPTION_OBSERVE
As it is Observe that we are talking about here.
2018-04-04 16:46:04 +01:00
Jon Shallow 80cae52441 examples/coap-server.c: Update inline with new Observe functions
As we are talking about Observe here
2018-04-04 16:46:04 +01:00
Jon Shallow 97486e7112 examples/client.c: Change COAP_OPTION_SUBSCRIPTION to COAP_OPTION_OBSERVE
As we are talking about Observe here
2018-04-04 16:46:04 +01:00
Jon Shallow 6bbf993dbe examples/coap-rd.c: Update resource hashing from key to uri_path
Resources are now hashed by uri_path, not key.
2018-03-14 09:32:58 +00:00
Jon Shallow 45a95c776d examples/coap-client.txt.in: Add in coap+tcp to the documentation 2018-03-09 14:52:14 +00:00
Jon Shallow b2205d2e40 examples/coap-server.c: Re-order code (move fill_keystore) to support PKI
fill_keystore() now needs to be before coap_new_endpoint() is called.
2018-02-12 11:58:59 +00:00
Olaf Bergmann e5064a47e7 client.c: removed dead code in message_handler()
Coverity scan has detected dead code that has been removed in this
change. (CID 1382575)
2017-11-03 15:15:06 +01:00
Olaf Bergmann edca08249b coap-server.c: fixed memory leak in get_context()
When getaddrinfo() failed, the context object was not released before
returning NULL. Coverity scan has detected this with CID 1458398.
2017-11-03 14:18:19 +01:00
Olaf Bergmann 29692faa86 coap-server.c: fix use after free in check_async()
As coap_send() automatically releases the specified pdu, it must
not be accessed after coap_send() has returned.

This change fixes CID 1458399 reported by Coverity scan.
2017-11-03 14:12:22 +01:00
jcmichelou 3f77c117ea resource: Fix issues #90, #91 and #92
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.
2017-10-25 20:22:01 +02:00
jcmichelou d89c99f5f8 uri: Add coap+tcp:// and coaps+tcp:// schemes. 2017-10-21 16:52:02 +02:00
jcmichelou cd804ba3bf client.c: Make observation timeout work with TCP. 2017-10-21 16:11:15 +02:00
jcmichelou f81cb43fd3 session, pdu: Enforce maximum message size. 2017-10-21 16:11:12 +02:00
jcmichelou dfff930805 io, net: Add TCP accept/connect/read/write 2017-10-21 16:11:12 +02:00
jcmichelou bcfd7a0753 pdu: add support for TCP-style headers
Make coap_pdu-t independent of the header style.
Use C99 sized types when applicable.
Use transaction ids in host byte order in the library.
Make coap_pdu_t payload storage grow on demand.
Add parsing and encoding of PDUs with UDP or TCP style headers.
Adapt examples and unit tests to the new PDU format.
2017-10-21 16:11:11 +02:00
obgm c1254c1be8 Merge pull request #111 from spinetix/build-fixes
Assorted build fixes
2017-09-21 12:48:10 +02:00
Diego Santa Cruz 9b12571804 Makefile.am: fix building outside of source tree
When building outside the source tree compilation fails on
examples, because the libcoap headers expect to be all in the
same directory but coap.h is generated under the build
directory, so it is necessary to add an extra include path
for it.

Also, build directories should always appear before source
directories in the include path, so that any leftover
generated files in the source tree are ignored.
2017-09-20 10:48:54 +02:00
cladmi 57a3b59060 coap-server: fix unused 'request' parameter 2017-09-12 15:48:58 +02:00
jcmichelou 30619691e2 resource.[ch], uri.c[ch]: Query string dependent observe.
Remember the query string used during the observe request and pass it to the resource handler.
Support partial notification of observers based on the query string.
2017-09-08 19:50:34 +02:00