mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-08 18:32:53 +03:00
added coap_get_data() to retrieve PDU payload
This commit is contained in:
1 parent
0f2d5b3c34
commit
72500fa297
2 files changed
+25
No files matched your search
@@ -120,3 +120,21 @@ coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data) {
|
||||
pdu->length += len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
coap_get_data(coap_pdu_t *pdu, unsigned int *len, unsigned char **data) {
|
||||
if ( !pdu )
|
||||
return 0;
|
||||
|
||||
if ( pdu->data < (unsigned char *)pdu->hdr + pdu->length ) {
|
||||
/* pdu contains data */
|
||||
|
||||
*len = (unsigned char *)pdu->hdr + pdu->length - pdu->data;
|
||||
*data = pdu->data;
|
||||
} else { /* no data, clear everything */
|
||||
*len = 0;
|
||||
*data = NULL;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -228,4 +228,11 @@ coap_opt_t *coap_check_option(coap_pdu_t *pdu, unsigned char type);
|
||||
|
||||
int coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data);
|
||||
|
||||
/**
|
||||
* Retrieves the length and data pointer of specified PDU. Returns 0 on error
|
||||
* or 1 if *len and *data have correct values. Note that these values are
|
||||
* destroyed with the pdu.
|
||||
*/
|
||||
int coap_get_data(coap_pdu_t *pdu, unsigned int *len, unsigned char **data);
|
||||
|
||||
#endif /* _PDU_H_ */
|
||||
Reference in new issue
Block a user