include/coap/option.h: Add in optlist structures / functions

Add in new coap_optlist_t structure
Add in the new functions
 coap_new_optlist()
 coap_add_optlist_pdu()
 coap_insert_optlist()
 coap_delete_optlist()
This commit is contained in:
Jon Shallow committed 2018-05-17 18:45:26 +01:00
1 parent ece443f107
commit 3122428445
1 file changed
+72 -1
+72 -1
View File
@@ -25,7 +25,9 @@
typedef uint8_t coap_opt_t;
#define PCHAR(p) ((coap_opt_t *)(p))
/** Representation of CoAP options. */
/**
* Representation of CoAP options.
*/
typedef struct {
uint16_t delta;
size_t length;
@@ -407,4 +409,73 @@ coap_opt_const_value( const coap_opt_t *opt ) {
/** @} */
/**
* Representation of chained list of CoAP options to install.
*
* @code
* coap_optlist_t *optlist_chain = NULL;
* coap_pdu_t *pdu = coap_new_pdu(session);
*
* ... other set up code ...
* coap_insert_optlist(&optlist_chain, coap_new_optlist(COAP_OPTION_OBSERVE,
* COAP_OBSERVE_ESTABLISH, NULL));
*
* coap_add_optlist_pdu(pdu, *optlist_chain);
* ... other code ...
* coap_delete_optlist(optlist_chain);
* @endcode
*/
typedef struct coap_optlist_t {
struct coap_optlist_t *next; /**< next entry in the optlist chain */
uint16_t number; /**< the option number (no delta coding) */
size_t length; /**< the option value length */
uint8_t data[]; /**< the option data */
} coap_optlist_t;
/**
* Create a new optlist entry.
*
* @param number The option number (COAP_OPTION_*)
* @param length The option length
* @param data The option value data
*
* @return A pointer to the new optlist entry, or @c NULL if error
*/
coap_optlist_t *coap_new_optlist(uint16_t number,
size_t length,
const uint8_t *data);
/**
* The current optlist of @p optlist_chain is first sorted (as per RFC7272
* ordering requirements) and then added to the @pdu.
*
* @param pdu The pdu to add the options to from the chain list
* @param optlist_chain The chained list of optlist to add to the pdu
*
* @return @c 1 if succesful or @c 0 if failure;
*/
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain);
/**
* Adds @p optlist to the given @p optlist_chain. The optlist_chain variable
* be set to NULL before the initial call to coap_insert_optlist().
* The optlist_chain will need to be deleted using coap_delete_optlist()
* when no longer required.
*
* @param optlist_chain The chain to add optlist to
* @param optlist The optlist to add to the queue
*
* @return @c 1 if successful, @c 0 otherwise.
*/
int coap_insert_optlist(coap_optlist_t **optlist_chain,
coap_optlist_t *optlist);
/**
* Removes all entries from the @p optlist_chain, freeing off their
* memory usage.
*
* @param optlist_chain The optlist chain to remove all the entries from
*/
void coap_delete_optlist(coap_optlist_t *optlist_chain);
#endif /* _OPTION_H_ */