Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
602b620
net/unicoap/rfc7252: add config for RFC 7252 messaging
carl-tud Jul 7, 2025
c078e80
net/unicoap/rfc7252: implement RFC 7252 messaging
carl-tud Jul 7, 2025
92318c0
net/unicoap: add private messaging interface
carl-tud Jul 7, 2025
fde948c
net/unicoap/rfc7252/udp: implement UDP driver
carl-tud Jul 7, 2025
dc75bc8
net/unicoap/rfc7252/dtls: implement DTLS driver
carl-tud Jul 7, 2025
c0216cf
net/unicoap: add transport abstraction
carl-tud Jul 7, 2025
d579ab0
net/unicoap: add sock dependencies
carl-tud Jul 7, 2025
ae32c8f
net/unicoap: implement state handling
carl-tud Jul 7, 2025
ad8ebd6
net/unicoap: implement basic server functionality
carl-tud Jul 7, 2025
755cdd8
net/unicoap: implement initialization
carl-tud Jul 7, 2025
98120ff
auto_init: enable auto-init for unicoap
carl-tud Jul 7, 2025
cc690df
net/unicoap: document server
carl-tud Jul 7, 2025
5503d4f
net/unicoap/rfc7252: add docs for UDP and DTLS drivers
carl-tud Jul 7, 2025
4d00949
examples/unicoap_server: add sample unicoap server application
carl-tud Jul 7, 2025
232a4e3
fixup: examples/unicoap_server: update Makefile.ci
carl-tud Jul 9, 2025
30a7f6e
fixup: net/unicoap: add interface note to server tutorial
carl-tud Jul 9, 2025
8d3db35
fixup: net/unicoap: server tutorial docs: remove trailing whitespace
carl-tud Jul 9, 2025
6e3c37b
fixup: examples/unicoap_server: add README, fix typos
carl-tud Jul 17, 2025
1d7061c
auto_init: fix indent in unicoap prio
carl-tud Jul 17, 2025
fd13630
net/unicoap: init: docs
carl-tud Jul 17, 2025
d623b0a
fixup: net/unicoap/rfc7252/udp (alongside): config.h: typo
carl-tud Jul 17, 2025
f2208cb
fixup: net/unicoap/application.h: docs, typos
carl-tud Jul 17, 2025
e848212
fixup: examples/unicoap_server: Add documentation to server example m…
carl-tud Sep 24, 2025
cad01e2
fixup: examples/unicoap_server: mind very very weird coding convetion
carl-tud Sep 24, 2025
3882e16
fixup: examples/unicoap_server: conditionally compile UDP-specific co…
carl-tud Sep 24, 2025
88e6d45
fixup: examples/unicoap_server: again, mind terrific coding convention
carl-tud Sep 24, 2025
ad68328
fixup: remove listener documentation comment regarding custom matchers
carl-tud Sep 24, 2025
8b9c225
fixup: typo
carl-tud Sep 24, 2025
eff8829
fixup: docs debugging logging deffault
carl-tud Sep 24, 2025
51d3a37
fixup: docs
carl-tud Sep 24, 2025
4345b6c
fixup: docs
carl-tud Sep 24, 2025
93d3379
fixup: docs
carl-tud Sep 24, 2025
6bb868c
fixup: docs
carl-tud Sep 24, 2025
5aafac3
remove feature check from preproc
carl-tud Sep 24, 2025
ca60a48
fixup: docs
carl-tud Sep 24, 2025
fc4ee20
fixup: i love the coding convention
carl-tud Sep 24, 2025
1861b3a
fixup: style and docs
carl-tud Sep 24, 2025
5e9bca9
fixup: remove mention of auto-init config constant
carl-tud Sep 24, 2025
8c69b0b
fixup: typo CONFIG_ in Kconfig
carl-tud Sep 24, 2025
12987d0
fixup: no tabs in makefile
carl-tud Sep 24, 2025
9d2bbdd
fixup: typos
carl-tud Sep 24, 2025
339d9ad
explain black magic
carl-tud Sep 24, 2025
3652c35
fixup: use correct code sample
carl-tud Sep 24, 2025
6a401f6
fixup: typos
carl-tud Sep 24, 2025
f0fe642
fixup: typos
carl-tud Sep 24, 2025
cc85bba
fixup: docs
carl-tud Sep 24, 2025
bff57dd
fixup: docs
carl-tud Sep 24, 2025
d4863b5
fixup: preproc indents
carl-tud Sep 24, 2025
b8dca8f
fixup: fix long lines in DTLS code
carl-tud Sep 24, 2025
1555fba
fixup: preprocessor indent fixes in drivers
carl-tud Sep 24, 2025
35787c4
fixup: docs
carl-tud Sep 24, 2025
5abe9e7
fixup: docs
carl-tud Sep 24, 2025
1c8483a
fixup: typo
carl-tud Sep 24, 2025
7223cd1
fixup: use _transmission_t instead
carl-tud Sep 24, 2025
17a74e2
fixup: do not indent top-level preprocessor directives
carl-tud Sep 24, 2025
4334c7d
fixup: typo
carl-tud Sep 24, 2025
fc5ff18
fixup: typos
carl-tud Sep 24, 2025
44ea8d3
fixup: _packet_get_dtls_session
carl-tud Sep 24, 2025
265f2cb
address messaging.c review comments
carl-tud Sep 24, 2025
be62ad8
naming
carl-tud Sep 24, 2025
ab2a99d
fixup: typo
carl-tud Sep 24, 2025
4aab839
fixup: preprocessor directive indents at top level
carl-tud Sep 24, 2025
0ffd285
fixup: typo
carl-tud Sep 24, 2025
d391e27
fixup: use correct callback type on scheduling fn
carl-tud Sep 24, 2025
9f99d5b
fixup: address review comments in messaging-related parts
carl-tud Sep 24, 2025
4b63e55
fixup: address review comments
carl-tud Sep 25, 2025
20dcf80
fixup: address review comments
carl-tud Sep 25, 2025
35bdd05
fixup: fix path string matching
carl-tud Sep 25, 2025
f1dd384
fixup: compile is_multicast helper when UDP support is missing
carl-tud Sep 26, 2025
57123e1
fixup: typos
carl-tud Oct 4, 2025
438ad7f
fixup: clarify atomic usage
carl-tud Oct 4, 2025
2f0e872
fixup: partially fix running loop on any thread
carl-tud Oct 10, 2025
9370c26
main.c
carl-tud Oct 12, 2025
0c5ed49
fixup: add unicoap_loop_enqueue to example app
carl-tud Oct 12, 2025
6a8f77c
fixup: restore unicoap_server config to defaults
carl-tud Oct 12, 2025
0cb5868
fixup: use unicoap_job_t proxy, typecheck macro expr
carl-tud Oct 12, 2025
35a0100
fixup: remove unused typecheck func from unicoap.h
carl-tud Oct 12, 2025
15f49c4
fixup: typo
carl-tud Oct 12, 2025
78e3da3
fixup: docs
carl-tud Oct 12, 2025
277b634
fixup: only use __has_builtin if available
carl-tud Oct 13, 2025
7cd0ff7
fixup: __typeof__?
carl-tud Oct 15, 2025
c307339
fixup: forgot to check in util_macros.h
carl-tud Oct 15, 2025
eee23ef
fixup: default config for server example
carl-tud Oct 19, 2025
a48ee62
fixup: timeout option in client.py (aiocoap issue)
carl-tud Oct 19, 2025
cf5df59
fixup: dtls debug logging
carl-tud Oct 19, 2025
95c0be4
fixup: proper asyncio timeout in client.py
carl-tud Oct 19, 2025
dc7b68f
docs: remove shell ifconfig hint
carl-tud Oct 19, 2025
20cf4d7
fixup: use event queue's detached init functions
carl-tud Oct 19, 2025
a0eacaa
fixup: docs
carl-tud Oct 19, 2025
4b118b1
fixup: remove job example from unicoap_server app
carl-tud Oct 19, 2025
1b7984d
fixup: assist wording sock support
carl-tud Oct 19, 2025
634a5d5
fixup: document dark compiler magic
carl-tud Oct 19, 2025
300f842
fixup: typo
carl-tud Oct 19, 2025
c7ad597
fixup: client.py now uses -mt and -to
carl-tud Oct 19, 2025
c8f4b65
fixup: use unicoap_message_code_is_* instead of unicoap_message_is_*
carl-tud Oct 19, 2025
0523502
fixup: remove erroneous assert(session) in DTLS transport driver
carl-tud Oct 19, 2025
af34573
fixup: add note on multiple consecutive slashes
carl-tud Oct 19, 2025
28ec273
fixup: fix various path matching issues (write tests!)
carl-tud Oct 19, 2025
eedc942
fixup: unittests: unicoap path matching
carl-tud Oct 19, 2025
cf3818c
fixup: return error when trying to unregister unknown listener
carl-tud Oct 19, 2025
fa1e31d
fixup: use packet->message
carl-tud Oct 19, 2025
ec11bfb
fixup: example: disable debug logging by default to save space
carl-tud Oct 19, 2025
dc097d0
fixup: forgot to check in tests
carl-tud Oct 19, 2025
47b3b00
fixup: typo
carl-tud Oct 19, 2025
e343b86
fixup: fix unresponsive CoAP over DTLS server
carl-tud Oct 22, 2025
a166aa8
fixup: dtls: style
carl-tud Oct 22, 2025
e7b4ef1
fixup: example: docs
carl-tud Oct 22, 2025
53c479e
fixup: client.py tells users that aiocoap DTLS error is expected
carl-tud Oct 22, 2025
a09f34a
fixup: naming
carl-tud Oct 23, 2025
d5578a3
fixup: comments
carl-tud Oct 23, 2025
01fe535
fixup: client.py: context.shutdown()
carl-tud Oct 24, 2025
3f8c798
fixup: use correct timeouts in CoAP over DTLS driver
carl-tud Oct 24, 2025
89580a5
fixup: WIP: sock->buf_ctx dtls (commented out)
carl-tud Oct 24, 2025
7aa791e
fixup: typo
carl-tud Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/networking/coap/unicoap_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To try this example on your host, run:
BOARD=native make flash term
```
This will compile and run the application.
The application will print a link-layer address.
The application will print a network-layer address.

In a second terminal session, you can run

Expand Down
4 changes: 2 additions & 2 deletions examples/networking/coap/unicoap_server/app.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CONFIG_UNICOAP_DEBUG_LOGGING=y
CONFIG_UNICOAP_ASSIST=y
CONFIG_UNICOAP_DEBUG_LOGGING=n
CONFIG_UNICOAP_ASSIST=n
CONFIG_UNICOAP_CREATE_THREAD=y
6 changes: 5 additions & 1 deletion sys/include/net/unicoap/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@
* @brief Resource path
*
* Must be a null-terminated string with slash-separated path components
*
* @warning This path must not have any trailing slash separators, apart from the root path `/`
*/
const char* path;

Expand Down Expand Up @@ -353,7 +355,7 @@
* </sensors/light>;rt="light-lux"
* ```
*
* @see [Constrained RESTful Environments (CoRE) Link Format](https://datatracker.ietf.org/doc/html/rfc6690)

Check warning on line 358 in sys/include/net/unicoap/application.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*
* @param[in,out] buffer The buffer that will contain the built string in CoRE Link Format
* @param capacity The capacity @p buffer in bytes
Expand Down Expand Up @@ -479,7 +481,7 @@
/**
* @brief Allowed protocols for the resources grouped together by this resource
*
* Example: Set to `UNICOAP_PROTOCOL_FLAG(UNICOAP_PROTO_UDP) | UNICOAP_PROTOCOL_FLAG(UNICOAP_PROTO_DTLS)`

Check warning on line 484 in sys/include/net/unicoap/application.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* to allow only CoAP over UDP and DTLS. Alternatively you can use
* `UNICOAP_PROTOCOLS(UNICOAP_PROTO_UDP, UNICOAP_PROTO_DTLS)`.
*
Expand Down Expand Up @@ -516,8 +518,10 @@
* @pre @p listener is a valid pointer to a single listener
*
* @param[in] listener Listener containing the resources.
* @returns Negative integer on error, zero on success.
* @retval `-ENOENT` if the given listener is not registered with `unicoap`.
*/
void unicoap_listener_deregister(unicoap_listener_t* listener);
int unicoap_listener_deregister(unicoap_listener_t* listener);

/**
* @brief Determines whether the complete Uri-Path matches the resources path.
Expand All @@ -533,7 +537,7 @@
*
* @returns A boolean value indicating whether the specified path matches the resource definition.
*/
bool unicoap_resource_match_path_string(const unicoap_resource_t* resource, const char* path, size_t length);

Check warning on line 540 in sys/include/net/unicoap/application.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

/**
* @brief Determines whether the complete Uri-Path matches the resources path.
Expand Down Expand Up @@ -566,7 +570,7 @@
#define UNICOAP_METHOD_FLAG(method) (1 << (method))

/**
* @brief Macro that builds a bit field where the i-th bit indicates the i-th request method (`0.0i`)

Check warning on line 573 in sys/include/net/unicoap/application.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* @see @ref unicoap_resource_t.flags
*
* Use this macro to create a bitfield of allowed methods for a given
Expand Down Expand Up @@ -596,7 +600,7 @@
* @param methods Methods bit field, each set bit's position corresponds to a method allowed
* @param method Method to be checked
*/
static inline bool unicoap_resource_match_method(unicoap_method_set_t methods, unicoap_method_t method)

Check warning on line 603 in sys/include/net/unicoap/application.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
return (methods & UNICOAP_METHOD_FLAG(method)) != 0;
}
Expand Down
10 changes: 5 additions & 5 deletions sys/net/application_layer/unicoap/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,28 +863,28 @@ ssize_t unicoap_options_get_next_query_by_name(unicoap_options_iterator_t* itera
unicoap_option_number_t number, const char* name,
const char** value)
{
char* _name = NULL;
const char* component = NULL;
const uint8_t* _name = NULL;
const uint8_t* component = NULL;
ssize_t res = -1;
while ((res =unicoap_options_get_next_by_number(iterator, number,
(const uint8_t**)&component)) >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(const uint8_t**)&component)) >= 0) {
&component)) >= 0) {

or why would you still need this cast now that component is const uint8_t *?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I remember you saying you a doing this kind of casts in other places across unicoap, have you double-checked and changed?

assert(component);
_name = (char*)component;
_name = component;

while (res > 0 && *component != '=') {
component += 1;
res -= 1;
}

if (strncmp(name, _name, (uintptr_t)component - (uintptr_t)_name) != 0) {
if (strncmp(name, (char*)_name, (uintptr_t)component - (uintptr_t)_name) != 0) {
continue;
}

if (res > 0) {
assert(*component == '=');
component += 1;
res -= 1;
*value = component;
*value = (const char*)component;
}
else {
*value = NULL;
Expand Down
88 changes: 77 additions & 11 deletions sys/net/application_layer/unicoap/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,70 @@
#include "debug.h"
#include "private.h"


/** @brief Returns new length of path excluding trailing slashes */
static inline size_t _trim_trailing_slashes(const char* path, size_t length) {
if (length > 0) {
size_t i = length - 1;
while (i > 0) {
if (path[i] == '/') {
i -= 1;
} else {
break;
}
}
return i + 1;
} else {
return length;
}
Comment on lines +31 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (length > 0) {
size_t i = length - 1;
while (i > 0) {
if (path[i] == '/') {
i -= 1;
} else {
break;
}
}
return i + 1;
} else {
return length;
}
if (length == 0) {
return length;
}
size_t i = length - 1;
while (i > 0) {
if (path[i] == '/') {
i -= 1;
}
else {
break;
}
}
return i + 1;

less indentation

}

bool unicoap_resource_match_path_string(const unicoap_resource_t* resource,
const char* lhs_path, size_t lhs_length)
const char* lhs_path, size_t _lhs_length)
{
assert(resource);
assert(lhs_path);

/* We are comparing the left-hand side (path from request) to the right-hand side (resource). */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is pretty bound to LHS = request path and RHS = resource definition path, why not reflecting that in the variable name instead of LHS and RHS? Would probably ease understanding.


size_t rhs_length = strlen(resource->path);
assert(rhs_length > 0);
size_t lhs_length = _trim_trailing_slashes(lhs_path, _lhs_length);

if (resource->flags & UNICOAP_RESOURCE_FLAG_MATCH_SUBTREE) {
/* The actual path (LHS) length may be longer. If it is shorter, bail out. */
if (lhs_length < rhs_length) {
return false;
}

/* The actual path (LHS) is now either as long or longer. If it is longer, then we
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* The actual path (LHS) is now either as long or longer. If it is longer, then we
/* The actual path (LHS) is now either as long or longer than RHS. If it is longer, then we

* expect a slash to indicate a subtree. Either the RHS path already ends with a slash
* or the LHS has a slash that succeeds the last RHS character.
Comment on lines +65 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get that part. Isn't LHS trimmed to have no slashes at the end?

*
* Examples:
*
* LHS: /a -> RHS ends in slash, every path that is longer than RHS is a subpath
* RHS: /
Comment on lines +70 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* LHS: /a -> RHS ends in slash, every path that is longer than RHS is a subpath
* RHS: /
* RHS: /, LHS: /a -> RHS ends in slash, every path that is longer than RHS is a subpath

similar below

*
* LHS: /a/a -> RHS ends in slash, every path that is longer than RHS is a subpath
* RHS: /a/
Comment on lines +73 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this basically the same case as the one above?

*
* LHS: /a/a -> RHS does not end in slash, so we need to require one to indicate subpath
* RHS: /a
*/
if (lhs_length > rhs_length && !(lhs_path[rhs_length] == '/' || resource->path[rhs_length - 1] == '/')) {
return false;
}

return strncmp(lhs_path, resource->path, rhs_length) == 0; /* RHS is null-terminated */
} else {
/* The actual path (LHS) length must match. If it is unequal, bail out. */
if (lhs_length != rhs_length) {
return false;
}
}

return strncmp(lhs_path, resource->path, lhs_length) == 0; /* rhs is null-terminated */
return strncmp(lhs_path, resource->path, lhs_length) == 0; /* RHS is null-terminated */
}
}

bool unicoap_resource_match_path_options(const unicoap_resource_t* resource,
Expand All @@ -63,38 +104,64 @@ bool unicoap_resource_match_path_options(const unicoap_resource_t* resource,

char* cursor = (char*)resource->path;
const char* end = resource->path + strlen(resource->path);

/* Skip multiple successive slashes.
* https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266
*/
while (*cursor == '/') {
cursor += 1;
}
char* start = cursor;
const char* component = NULL;

/* You might think, why not check cursor < end. To remove the need for end - 1 and bounds
* checks, we use cursor <= end and treat that case as if the NULL-terminator were a slash.
* The slash/NULL-terminator signals to the loop that it is supposed to compare the
* sequence of characters it has read since the last slash to the current Uri-Path option. */
while (cursor <= end) {
/* Found the end of a path component.
* That may either be a slash or the end of the string. */
if ((*cursor == '/') || ((cursor != start) && (cursor == end))) {
const char* component;

int res = -1;
if ((res = unicoap_options_get_next_uri_path_component(&iterator, &component)) < 0) {
break;
}
/* Cursor points to the element with the index one greater than the last character. */
size_t size = (uintptr_t)cursor - (uintptr_t)start;

/* Compare Uri-Path component with string path component. */
if (((size_t)res != size) || (strncmp(start, component, size) != 0)) {
return false;
}

/* Skip multiple successive slashes. */
while (*cursor == '/') {
cursor += 1;
}
start = cursor;
}
else {
/* Skip over path component characters. */
cursor += 1;
}
}

if (cursor != end + 1) {
/* If the resource's path is longer than the actual path, the paths definitely don't match.
* The end + 1 comparison is justified as we treat the NULL-terminator like a trailing
* slash. See above. */
return false;
}

if (resource->flags & UNICOAP_RESOURCE_FLAG_MATCH_SUBTREE) {
/* There may be more Uri-Path options. But this is fine as subpaths are allowed. */
return true;
}
else {
return cursor == (end + 1);
/* Make sure we read all options, i.e., the actual path is not longer than the resource's.
*/
return unicoap_options_get_next_uri_path_component(&iterator, &component) == -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're welcome for the unittest nagging :P

}
}

Expand Down Expand Up @@ -184,7 +251,6 @@ int unicoap_server_process_request(unicoap_packet_t* packet, const unicoap_resou
assert(packet);
assert(packet->remote);
int res = 0;
unicoap_message_t* message = packet->message;

unicoap_request_context_t context = {
.resource = resource, ._packet = packet
Expand All @@ -197,15 +263,15 @@ int unicoap_server_process_request(unicoap_packet_t* packet, const unicoap_resou
};

SERVER_DEBUG("invoking handler\n");
res = resource->handler(message, &aux, &context, resource->handler_arg);
res = resource->handler(packet->message, &aux, &context, resource->handler_arg);

if (res > 0) {
SERVER_DEBUG("sending response " UNICOAP_CODE_CLASS_DETAIL_FORMAT
" from return value\n",
unicoap_code_class((uint8_t)res), unicoap_code_detail((uint8_t)res));

if (IS_ACTIVE(CONFIG_UNICOAP_PREVENT_OPTIONAL_RESPONSES)) {
if (unicoap_response_is_optional(message->options, (unicoap_status_t)res)) {
if (unicoap_response_is_optional(packet->message->options, (unicoap_status_t)res)) {
SERVER_DEBUG("response " UNICOAP_CODE_CLASS_DETAIL_FORMAT
" is optional, not responding\n",
unicoap_code_class((uint8_t)res),
Expand All @@ -214,7 +280,7 @@ int unicoap_server_process_request(unicoap_packet_t* packet, const unicoap_resou
}
}

unicoap_response_init_empty(message, (unicoap_status_t)res);
unicoap_response_init_empty(packet->message, (unicoap_status_t)res);
return unicoap_server_send_response_body(packet, resource);
}
else if (context._packet) {
Expand All @@ -229,8 +295,8 @@ int unicoap_server_process_request(unicoap_packet_t* packet, const unicoap_resou
FIXIT("set USEMODULE += unicoap_deferred_response and"
"call unicoap_defer_response")
FIXIT("ignore request by returning UNICOAP_IGNORING_REQUEST"));
unicoap_response_init_string(message, UNICOAP_STATUS_INTERNAL_SERVER_ERROR,
"application");
unicoap_response_init_string(packet->message,
UNICOAP_STATUS_INTERNAL_SERVER_ERROR, "application");
goto error;
}
}
Expand Down
16 changes: 7 additions & 9 deletions sys/net/application_layer/unicoap/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ int unicoap_deinit(void)
}

_deinit_drivers(&_queue);
/* TODO: Thread: Figure out how to die properly, in an orderly fashion. */
_unicoap_pid = KERNEL_PID_UNDEF;
memset(&_state, 0, sizeof(_state));
memset(&_queue, 0, sizeof(_queue));
Expand Down Expand Up @@ -245,18 +244,19 @@ void unicoap_listener_register(unicoap_listener_t* listener)
}
}

void unicoap_listener_deregister(unicoap_listener_t* listener)
int unicoap_listener_deregister(unicoap_listener_t* listener)
{
assert(listener);

unicoap_listener_t* l = _state.listeners;
while (l) {
if (l->next == listener) {
l->next = listener->next;
break;
return 0;
}
l = l->next;
}
return -ENOENT;
}

/* MARK: - Intersection with messaging */
Expand Down Expand Up @@ -333,23 +333,21 @@ unicoap_preprocessing_result_t unicoap_exchange_preprocess(unicoap_packet_t* pac
unicoap_options_set_size1(&response_options, CONFIG_UNICOAP_BLOCK_SIZE);
unicoap_response_init_with_options(message, UNICOAP_STATUS_REQUEST_ENTITY_TOO_LARGE,
NULL, 0, &response_options);
goto server_prewarming_error;
unicoap_messaging_send(packet, UNICOAP_MESSAGING_FLAGS_DEFAULT);
return UNICOAP_PREPROCESSING_ERROR_REQUEST;
}

const unicoap_resource_t* resource = NULL;
const unicoap_listener_t* listener = NULL;
if ((res = unicoap_resource_find(packet, &resource, &listener)) != 0) {
unicoap_response_init_empty(message, res < 0 ? UNICOAP_STATUS_INTERNAL_SERVER_ERROR :
(unicoap_status_t)res);
goto server_prewarming_error;
unicoap_messaging_send(packet, UNICOAP_MESSAGING_FLAGS_DEFAULT);
return UNICOAP_PREPROCESSING_ERROR_REQUEST;
}
arg->resource = resource;
*flags = _messaging_flags_resource(resource->flags);
return UNICOAP_PREPROCESSING_SUCCESS_REQUEST;

server_prewarming_error:
unicoap_messaging_send(packet, UNICOAP_MESSAGING_FLAGS_DEFAULT);
return UNICOAP_PREPROCESSING_ERROR_REQUEST;
}

case UNICOAP_CODE_CLASS_RESPONSE_SUCCESS:
Expand Down
Loading
Loading