added coap_get_data() to retrieve PDU payload

This commit is contained in:
Olaf Bergmann committed 2010-07-12 23:49:33 +02:00
1 parent 0f2d5b3c34
commit 72500fa297
2 files changed
+25

No files matched your search

+18
View File
@@ -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;
}
+7
View File
@@ -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_ */