[riot-notifications] [RIOT-OS/RIOT] nanocoap: Support adding opaque (blob / buffer) data (#11386)

chrysn notifications at github.com
Fri Apr 12 11:40:02 CEST 2019


### Contribution description

This adds a `coap_opt_add_opaque(...)` function that adds binary data from a buffer as an option. The name stems from the RFC7252 name for such options.

The ETag options (ETag, If-Match) are options of that form, and having a generic way of adding options also helps porting more high-level CoAP libraries to nanocoap / Gcoap. (My current use case involves using Rust CoAP abstractions on a gcoap handled server).

A follow-up commit adds const qualifiers to input data of the function itself, its internal helper (which does not modify the data in its original location) and the public `coap_put_option` low-level function used by it (which does neither). The behavior of the functions, both in implementation and semantically, is already const, the declarations were just missing; adding them makes using it easier with const-heavy code.

### Testing procedure

None of the examples use the method, but the gcoap example can easily be made to, by adding in _riot_board_handler before (!) coap_opt_add_format:

```patch
     gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT);
+    coap_opt_add_opaque(pdu, 4, (uint8_t*)"etag", 4);
     coap_opt_add_format(pdu, COAP_FORMAT_TEXT);
```

Then, a query to the riot/board resource can be verified using Wireshark to contain a 4-byte ETag option. (Tested using the native board).

### Issues/PRs references

This was not reported as a dedicated issue as it's probably small enough to handle in a PR right away.
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/11386

-- Commit Summary --

  * nanocoap: Add coap_opt_add_opaque
  * nanocoap: add some const qualifiers

-- File Changes --

    M sys/include/net/nanocoap.h (19)
    M sys/net/application_layer/nanocoap/nanocoap.c (9)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/11386.patch
https://github.com/RIOT-OS/RIOT/pull/11386.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11386
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190412/0a152f65/attachment-0001.html>


More information about the notifications mailing list