mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
nanocoap_sock: implement nanocoap_sock_delete()
This commit is contained in:
parent
b539d7ad6d
commit
c656df9c3a
@ -289,6 +289,27 @@ ssize_t nanocoap_sock_post_url(const char *url,
|
||||
const void *request, size_t len,
|
||||
void *response, size_t len_max);
|
||||
|
||||
/**
|
||||
* @brief Simple synchronous CoAP (confirmable) DELETE
|
||||
*
|
||||
* @param[in] sock socket to use for the request
|
||||
* @param[in] path remote path to delete
|
||||
*
|
||||
* @returns 0 on success
|
||||
* @returns <0 on error
|
||||
*/
|
||||
ssize_t nanocoap_sock_delete(nanocoap_sock_t *sock, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Simple synchronous CoAP (confirmable) DELETE for URL
|
||||
*
|
||||
* @param[in] url URL of the resource that should be deleted
|
||||
*
|
||||
* @returns 0 on success
|
||||
* @returns <0 on error
|
||||
*/
|
||||
ssize_t nanocoap_sock_delete_url(const char *url);
|
||||
|
||||
/**
|
||||
* @brief Performs a blockwise coap get request on a socket.
|
||||
*
|
||||
|
@ -391,6 +391,38 @@ ssize_t nanocoap_sock_post_url(const char *url,
|
||||
return _sock_put_post_url(url, COAP_METHOD_POST, request, len, response, len_max);
|
||||
}
|
||||
|
||||
ssize_t nanocoap_sock_delete(nanocoap_sock_t *sock, const char *path)
|
||||
{
|
||||
/* buffer for CoAP header */
|
||||
uint8_t buffer[CONFIG_NANOCOAP_BLOCK_HEADER_MAX];
|
||||
uint8_t *pktpos = buffer;
|
||||
|
||||
coap_pkt_t pkt = {
|
||||
.hdr = (void *)pktpos,
|
||||
};
|
||||
|
||||
pktpos += coap_build_hdr(pkt.hdr, COAP_TYPE_CON, NULL, 0, COAP_METHOD_DELETE, _get_id());
|
||||
pktpos += coap_opt_put_uri_path(pktpos, 0, path);
|
||||
|
||||
pkt.payload = pktpos;
|
||||
|
||||
return nanocoap_sock_request_cb(sock, &pkt, NULL, NULL);
|
||||
}
|
||||
|
||||
ssize_t nanocoap_sock_delete_url(const char *url)
|
||||
{
|
||||
nanocoap_sock_t sock;
|
||||
int res = nanocoap_sock_url_connect(url, &sock);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = nanocoap_sock_delete(&sock, sock_urlpath(url));
|
||||
nanocoap_sock_close(&sock);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ssize_t nanocoap_request(coap_pkt_t *pkt, const sock_udp_ep_t *local,
|
||||
const sock_udp_ep_t *remote, size_t len)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user