libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
option.h File Reference

helpers for handling options in CoAP PDUs More...

#include "bits.h"
#include "pdu.h"

Go to the source code of this file.

Data Structures

struct  coap_option_t
 Representation of CoAP options. More...
 
struct  coap_opt_iterator_t
 Iterator to run through PDU options. More...
 

Macros

#define PCHAR(p)   ((coap_opt_t *)(p))
 
#define COAP_OPT_SIZE(opt)   coap_opt_size(opt)
 
#define options_next(opt)
 Interprets opt as pointer to a CoAP option and advances to the next byte past this option. More...
 
#define COAP_OPT_ALL   NULL
 Pre-defined filter that includes all options. More...
 
#define COAP_OPT_DELTA(opt)   coap_opt_delta(opt)
 
#define COAP_OPT_SETDELTA(opt, val)   coap_opt_encode((opt), COAP_MAX_PDU_SIZE, (val), NULL, 0)
 
#define COAP_OPT_LENGTH(opt)   coap_opt_length(opt)
 
#define COAP_OPT_VALUE(opt)   coap_opt_value((coap_opt_t *)opt)
 

Typedefs

typedef unsigned char coap_opt_t
 Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffer may cause bus error on certain platforms. More...
 
typedef unsigned char coap_opt_filter_t [(COAP_MAX_OPT >> 3)+1]
 Fixed-size bit-vector we use for option filtering. More...
 

Functions

size_t coap_opt_parse (const coap_opt_t *opt, size_t length, coap_option_t *result)
 Parses the option pointed to by opt into result. More...
 
size_t coap_opt_size (const coap_opt_t *opt)
 Returns the size of the given option, taking into account a possible option jump. More...
 
coap_opt_toptions_start (coap_pdu_t *pdu)
 Calculates the beginning of the PDU's option section. More...
 
static void coap_option_filter_clear (coap_opt_filter_t f)
 Clears filter f. More...
 
static int coap_option_setb (coap_opt_filter_t filter, unsigned short type)
 Sets the corresponding bit for type in filter. More...
 
static int coap_option_clrb (coap_opt_filter_t filter, unsigned short type)
 Clears the corresponding bit for type in filter. More...
 
static int coap_option_getb (const coap_opt_filter_t filter, unsigned short type)
 Gets the corresponding bit for type in filter. More...
 
coap_opt_iterator_tcoap_option_iterator_init (coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t filter)
 Initializes the given option iterator oi to point to the beginning of the pdu's option list. More...
 
coap_opt_tcoap_option_next (coap_opt_iterator_t *oi)
 Updates the iterator oi to point to the next option. More...
 
coap_opt_tcoap_check_option (coap_pdu_t *pdu, unsigned char type, coap_opt_iterator_t *oi)
 Retrieves the first option of type type from pdu. More...
 
size_t coap_opt_setheader (coap_opt_t *opt, size_t maxlen, unsigned short delta, size_t length)
 Encodes the given delta and length values into opt. More...
 
size_t coap_opt_encode (coap_opt_t *opt, size_t n, unsigned short delta, const unsigned char *val, size_t length)
 Encodes option with given delta into opt. More...
 
unsigned short coap_opt_delta (const coap_opt_t *opt)
 Decodes the delta value of the next option. More...
 
unsigned short coap_opt_length (const coap_opt_t *opt)
 Returns the length of the given option. More...
 
unsigned char * coap_opt_value (coap_opt_t *opt)
 Returns a pointer to the value of the given option. More...
 

Detailed Description

helpers for handling options in CoAP PDUs

Definition in file option.h.

Macro Definition Documentation

#define COAP_OPT_SIZE (   opt)    coap_opt_size(opt)
Deprecated:
{ Use coap_opt_size() instead. }

Definition at line 65 of file option.h.

#define options_next (   opt)

Interprets opt as pointer to a CoAP option and advances to the next byte past this option.

Definition at line 80 of file option.h.

#define PCHAR (   p)    ((coap_opt_t *)(p))

Definition at line 27 of file option.h.

Typedef Documentation

typedef unsigned char coap_opt_t

Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffer may cause bus error on certain platforms.

Definition at line 26 of file option.h.

Function Documentation

size_t coap_opt_parse ( const coap_opt_t opt,
size_t  length,
coap_option_t result 
)

Parses the option pointed to by opt into result.

This function returns the number of bytes that have been parsed, or 0 on error. An error is signaled when illegal delta or length values are encountered or when option parsing would result in reading past the option (i.e. beyond opt + length).

Parameters
optThe beginning of the option to parse.
lengthThe maximum length of opt.
resultA pointer to the coap_option_t structure that is filled with actual values iff coap_opt_parse() > 0.
Returns
The number of bytes parsed or 0 on error.

Definition at line 38 of file option.c.

size_t coap_opt_size ( const coap_opt_t opt)

Returns the size of the given option, taking into account a possible option jump.

Parameters
optAn option jump or the beginning of the option.
Returns
The number of bytes between opt and the end of the option starting at opt. In case of an error, this function returns 0 as options need at least one byte storage space.

Definition at line 319 of file option.c.

coap_opt_t* options_start ( coap_pdu_t pdu)

Calculates the beginning of the PDU's option section.

Parameters
pduThe PDU containing the options.
Returns
A pointer to the first option if available, or NULL otherwise.

Definition at line 24 of file option.c.