Commit Graph
1211 Commits
Author SHA1 Message Date
Olaf Bergmann db48a839b6 test_uri.c: additional unit tests for URI creation
Added several unit tests for coap_get_uri_path():

* Check corner cases such as one or more zero-length Uri-Paths.
* Check percent-encoding of reserved characters.
* Check non-reserved characters that should not be percent-encoded.

This change also removes a couple of trailing LWS by accident.
2018-04-04 17:40:03 +02:00
obgm d28a8b5402 Merge pull request #133 from mrdeep1/issue-125
Issue 125 Fix - Support for unknown resource Uri when doing PUT/DELETE
2018-04-04 17:38:23 +02:00
Jon Shallow 373c132c27 resource.c: Add in support for unknown URI handler and update hashing
Include coap_resource_unknown_init() function for defining the unknown
resource.

Update hashing to use the resource's uri_path instead of key where appropriate
to avoid clashes when using the old hashed key.

coap_add_resource() now deletes previous resource with matching uri_path to
prevent duplication.

Remove now obsolete functions
coap_hash_request_uri()
coap_get_resource_from_key()

New function
coap_get_resource_from_uri_path()

*API Update coap_delete_resource() now deletes by resource, not by key.
2018-04-04 16:19:37 +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
Jon Shallow 1c2d9416fe str.h: Add coap_string_equal() and create coap_string_t as replacement for str
Rename struct str as struct coap_string_t and 'typedef coap_string_t str' for
backwards compatabilty with the intent of removing str at some point to
prevent potential name clashes when compiling application code.

Add in new coap_string_equal() function for consistent comparing of strings.
2018-04-04 16:19:37 +01:00
Jon Shallow b7e1040fac hashkey.[ch]: Files removed as no longer used 2018-04-04 16:19:37 +01:00
Jon Shallow fbe1b8283d coap_config.h.lwip: Remove COAP_RESOURCES_NOHASH as no longer supported 2018-04-04 16:19:37 +01:00
Jon Shallow 8b5b9e083e coap_config.h.contiki: Remove COAP_RESOURCES_NOHASH as no longer supported 2018-04-04 16:19:37 +01:00
Jon Shallow 60e07c4eed Makefile.libcoap: Remove -DCOAP_RESOURCES_NOHASH as no longer supported 2018-04-04 16:19:37 +01:00
Jon Shallow 59d0d36b1d libcoap.vcxproj libcoap.vcxproj.filters: Stop building obsoleted hash libraries 2018-04-04 16:19:37 +01:00
Jon Shallow 1d61c32fee tests/test_uri.c: Update to use uri_path instead of key for resource hash. 2018-04-04 16:19:36 +01:00
Jon Shallow 14a2dc5b0b uri.c: Remove obsoleted functions, add in coap_get_uri_path()
With resource's hashed key being replaced by uri_path, old hash functions have
been removed and a new fuction coap_get_uri_path() added to abstract the
uri_path from the pdu.

Tidy up usage of is_unescaped_in_query() and slit it partially out to support
is_unescaped_in_path.

Update unsigned to uint16_t in appropriate places
2018-04-04 16:19:26 +01:00
obgm 0e672d048a Merge pull request #157 from mrdeep1/observers-memleak
resource.c: Fix memory leaks when deleting observers
2018-04-04 17:06:20 +02:00
Jon Shallow 11224dde47 resource.c: Fix memory leaks when deleting observers
When freeing off a subscriber entry, free off the saved query at
the same time.  Already done once, needs to be done in the three
other instances.
2018-03-15 20:33:25 +00:00
Jon Shallow 235a11ebe8 uri.h: remove coap_hash_path() and add coap_get_uri_path()
The old hashed key is no longer used, so coap_hash_path() is obsolete.

coap_get_uri_path() added to build the resource Uri Path from the pdu.
2018-03-14 09:32:58 +00:00
Jon Shallow ff6f8e041c pdu.h: remove COAP_DEFAULT_WKC_HASHKEY as no longer needed 2018-03-14 09:32:58 +00: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 d88b0bb7fe Makefile.am: Drop building coap hash functions
As "coap_key_t key" is no longer used as the key for hashing resources onto
the hashlist which gave the potential for coap hashes clashing for the
resource Uri, "str uri" being used instead, so disable the building of the
coap_hash functions.

In addition, the .sym and .map file information now has duplicate
entries removed.
2018-03-14 09:32:58 +00:00
Jon Shallow be0c6616c6 libcoap-1.map & libcoap-1.sym: Add in coap_resource_unknown_init
Expose the new functions
coap_resource_unknown_init()
coap_get_uri_path()
coap_get_resource_from_uri_path()

Drop the functions as old hashed key is no longer supported
coap_get_resource_from_key()
coap_hash_*()
2018-03-14 09:32:58 +00:00
Jon Shallow e907596473 net.c: Update handle_request() to support unknown resource handler
Update handle_request() to call context->unknown_resource handler (if defined)
to support "RFC7252: 5.8.3.  PUT" requirements.

Allow only handlers defined for unknown_resource

Update handle_request() to return 2.02 for an unknown resource (and
context->unknown_resource is not defined) for a DELETE request
"RFC7252: 5.8.4.  DELETE"

Update code to use resource's uri_path not key as the item to hash for lookups

Make use of the new function coap_string_equal() when checking for
COAP_DEFAULT_URI_WELLKNOWN resource request.

Remove now obsolete hashed key code for is_wkc().
2018-03-14 09:32:45 +00:00
Jon Shallow 5aa31d010c resource.h: Add coap_add_resource_unknown() and hash resource on uri_path
Need to support
"RFC7252: 5.8.3.  PUT
 If no resource exists, then the server MAY create a new resource with that
 URI, resulting in a 2.01 (Created) Response Code."

Add in the function definition for the coap_add_resource_unknown().
Add in 'is_unknown' flag into coap_resource_t.

Make the resource uri_path be the hash lookup key, not the old hashed key, to
stop hash lookup clashes.

*API Change* Update coap_delete_resource() to not use the old hashed key.
Remove coap_get_resource_from_key() function and replace it with
coap_get_resource_from_uri_path().

Make the coap_resource_set_mode() more robust against bad parameters.

Remove #ifdef COAP_RESOURCES_NOHASH logic as no longer required
2018-03-13 14:49:22 +00:00
Olaf Bergmann f3c1542900 coap_session.c: reference new session objects before release
In case of failure, coap_session_accept() and coap_session_connect()
need to release the session object that has been passed as parameter.
Usually, session->ref would be 0 at the time these functions are
called, causing coap_session_release() to abort in debug mode.
To ensure that the object is referenced at least once,
coap_session_reference() is therefore called before
coap_session_release(). This fixes an error introduced in ommit 46c908a.

This change closes issue #155.
2018-03-12 16:00:16 +01:00
Jon Shallow cfe82719d3 net.h: Add in unknown_resource to coap_context_t
Needed to handle
"RFC7252: 5.8.3.  PUT
 If no resource exists, then the server MAY create a new resource with that
 URI, resulting in a 2.01 (Created) Response Code."

Needed for support of PUT requests to an unknown resource.

Remove structure coap_mid_cache_t as it is not used and refers to the now
obsolete coap_key_t.
2018-03-10 16:02:56 +00:00
obgm a674334afc Merge pull request #146 from mrdeep1/COAP_SOCKET_CONNECTED_issue
coap_io.c: Set COAP_SOCKET_CONNECTED before connect() for TCP
2018-03-09 17:44:57 +01:00
Jon Shallow f453902425 src/net.c: Support RFC8323 for empty messages and rate limit RSTs
Do not send back a RST is there is receipt of an empty message and using
TCP.

Otherwise, rate limit RST packets to 4 a second when receiving empty
messages
2018-03-09 15:08:14 +00:00
Jon Shallow c4bd74040c coap_session.h: Add in last_tx_rst to coap_session_t for RST ratelimiting 2018-03-09 14:53:32 +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
Olaf Bergmann d02ab4d0ab libcoap-1.{sym,map}: updated map files
The function coap_calc_timeout() was missing from the symbol mappings.
2018-03-06 16:56:51 +01:00
Olaf Bergmann 8f9ca22e05 tests: add unit tests for session handling
This change adds an initial set of unit tests for sessions:

* reference counting and release
* timeout calculation
2018-03-06 16:45:28 +01:00
obgm bf43c3af6c Merge pull request #137 from mrdeep1/session-retries
Require support for configuring session recovery parameters
2018-03-06 16:43:51 +01:00
Jon Shallow 7b2a7bca36 libcoap-1.map & libcoap-1.sym: Expose the new functions
Add in the new functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()
2018-03-05 16:12:25 +00:00
Jon Shallow 9c6c72565e net.c: Remove 'cc Rate Control', update code to use session recovery parameters
Remove 'cc Rate Control' which is now in coap_session.h.

Update Q, ACK_TIMEOUT and ACK_RANDOM_FACTOR #defines to include session's
recovery parameters, now in coap_fixed_point_t.

Update calc_timeout() to include session (now called coap_calc_timeout()).

Update coap_retransmit() to use session's max_retransmit.
2018-03-05 16:12:18 +00:00
Jon Shallow fb626df651 coap_session.c: Add in new functions, set the defaults and update calc_timeout
Add in the new functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()

Add in the default values in coap_make_session()

Update coap_calc_timeout() in coap_session_delay_pdu()
2018-03-05 16:12:18 +00:00
Jon Shallow ecf3321c67 net.h: Update and document coap_calc_timeout() function
Include session as one of the parameters to coap_calc_timeout() as it is now
per session, which is renamed from calc_timeout() as it is now a public
function.
2018-03-05 16:12:07 +00:00
Jon Shallow b105a7dea2 coap_session.h: Add definitions/functions to configure session retransmissions
Support is required (RFC7252: 4.8.1.  Changing the Parameters) to support
changing max_retransmit, ack_timeout and ack_random_factor values per
session instead of just using the default values.

Define struct coap_fixed_point_t to handle fixed point parameters

Added functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()

'cc Rate Control' moved from net.c into coap_session.h and updated to use
coap_fixed_point_t values where appropriate.
2018-03-05 12:09:45 +00:00
Jon Shallow 5969ae7633 coap_io.c: Set COAP_SOCKET_CONNECTED if connect does not complete for TCP
If the non-blocking connect() does not immediately complete, when the main i/o
processing loop runs and coap_read is called, coap_read_session() will assert if
COAP_SOCKET_CONNECTED is not set as there will be some TLS level packets to
process.

If WSAEWOULDBLOCK/EINPROGRESS is returned from the connect() set
COAP_SOCKET_CONNECTED in the socket flags.
2018-03-02 10:47:44 +00:00
obgm 3870bfc809 Merge pull request #142 from mrdeep1/coap-write-missing-tls
coap_write can assert if s->tls is not set when determining next to resend packet
2018-03-01 13:13:19 +01:00
Olaf Bergmann 7872a80fb4 network I/O: fixed socket creation for multicast communication
This bugfix allows clients to send datagrams to IP multicast groups.
After introducing the concept of client sessions, datagram sockets
have been connected to their remote peer in coap_socket_connect_udp().
As this operation fails for multicast addresses, sending to multicast
groups was not possible anymore.

coap_socket_connect_udp() now checks whether the given server address
is a multicast address. If this is the case, connect() is not called
and the flag COAP_SOCKET_MULTICAST is set in the coap_socket_t
structure while COAP_SOCKET_CONNECTED is cleared.

The flag COAP_SOCKET_CONNECTED is now set by coap_socket_connect_udp()
and coap_socket_connect_tcp1().

coap_read_session() now allows reading from sockets that have either
the flag COAP_SOCKET_CONNECTED or COAP_SOCKET_MULTICAST set.
2018-02-28 15:44:32 +01:00
obgm b6f6cb274c Merge pull request #141 from mrdeep1/coap-log-syntax
Add in GNU compiler checking of parameter syntax for coap_log() functions
2018-02-26 17:35:10 +01:00
obgm 4885d87f6d Merge pull request #140 from mrdeep1/coap-server-pki-fix
coap-server: Re-order code (move fill_keystore) to support PKI
2018-02-26 17:25:44 +01:00
Olaf Bergmann 9b9b39a3cd Merge branch 'develop' of github.com:obgm/libcoap into develop 2018-02-26 17:18:43 +01:00
obgm fafd4745b7 Merge pull request #136 from mrdeep1/ping-pong-handlers
Ping Pong handlers: Need for applications to see ping requests / pong responses
2018-02-26 17:17:54 +01:00
Olaf Bergmann 46c908af8f coap_session.c: fix session release
coap_session_t uses reference counting hence client sessions must be
released by coap_session_release() instead of directly calling
coap_session_free().
2018-02-20 13:55:25 +01:00
obgm 08f7f5c2ce Merge pull request #131 from mrdeep1/fd-close-leak
coap_io.c: Fix file descriptor leaks when "connections" fail
2018-02-20 13:53:11 +01:00
obgm 63cac59c62 Merge pull request #132 from mrdeep1/coap_session_send-assert
coap_openssl.c: client assert error if DTLS error closed socket
2018-02-20 13:52:56 +01:00
Olaf Bergmann 90d90232c4 .travis.yml: minimize build matrix 2018-02-16 10:43:28 +01:00
Olaf Bergmann 67291e397b tests: revert commit a3da53d to re-enable IPv6 in unit tests 2018-02-15 20:05:01 +01:00
Olaf Bergmann e40c6ea799 .travis.yml: enable IPv6 on travis docker
This workaround has been suggested [1] to fix the recent IPv6 issue
in travis docker containers.

[1] https://github.com/travis-ci/travis-ci/issues/8711
2018-02-15 20:03:40 +01:00
John Carter c7936acf71 coap_io.c: fix apparently uninitialized buffer in syscall param
Valgrind reports Syscall param  sendmsg(msg.msg_control) points to
uninitialised byte(s) due alignment padding in the CMSG macros
leaving uninitialized gaps in struct sent to the sendmsg system call.

This issue was reported including this patch on the libcoap-developers
mailing list [1].

[1] https://sourceforge.net/p/libcoap/mailman/message/36141279/

Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2018-02-15 19:38:42 +01:00
Olaf Bergmann c46de196e5 .travis.yml: added tinydtls build to POSIX test matrix 2018-02-15 12:14:16 +01:00