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.
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.
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(...
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.
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
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.
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_*()
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().
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
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.
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.
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
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()
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.
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()
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.
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.
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.
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.
coap_session_t uses reference counting hence client sessions must be
released by coap_session_release() instead of directly calling
coap_session_free().
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>