libcoap  4.2.1
option.c File Reference
#include "coap_internal.h"
#include <stdio.h>
#include <string.h>
+ Include dependency graph for option.c:

Go to the source code of this file.

Data Structures

struct  opt_filter
 

Macros

#define ADVANCE_OPT(o, e, step)
 
#define ADVANCE_OPT_CHECK(o, e, step)
 
#define LONG_MASK   ((1 << COAP_OPT_FILTER_LONG) - 1)
 
#define SHORT_MASK   (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
 

Enumerations

enum  filter_op_t { FILTER_SET, FILTER_CLEAR, FILTER_GET }
 Operation specifiers for coap_filter_op(). 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...
 
coap_opt_iterator_tcoap_option_iterator_init (const 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_STATIC_INLINE int opt_finished (coap_opt_iterator_t *oi)
 
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, uint16_t type, coap_opt_iterator_t *oi)
 Retrieves the first option of type type from pdu. More...
 
uint16_t coap_opt_delta (const coap_opt_t *opt)
 Decodes the delta value of the next option. More...
 
uint16_t coap_opt_length (const coap_opt_t *opt)
 Returns the length of the given option. More...
 
const uint8_tcoap_opt_value (const coap_opt_t *opt)
 Returns a pointer to the value of the given option. 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...
 
size_t coap_opt_setheader (coap_opt_t *opt, size_t maxlen, uint16_t delta, size_t length)
 Encodes the given delta and length values into opt. More...
 
size_t coap_opt_encode_size (uint16_t delta, size_t length)
 Compute storage bytes needed for an option with given delta and length. More...
 
size_t coap_opt_encode (coap_opt_t *opt, size_t maxlen, uint16_t delta, const uint8_t *val, size_t length)
 Encodes option with given delta into opt. More...
 
COAP_STATIC_INLINE int is_long_option (uint16_t type)
 Returns true iff type denotes an option type larger than 255. More...
 
static int coap_option_filter_op (coap_opt_filter_t filter, uint16_t type, enum filter_op_t op)
 Applies op on filter with respect to type. More...
 
int coap_option_filter_set (coap_opt_filter_t filter, uint16_t type)
 Sets the corresponding entry for type in filter. More...
 
int coap_option_filter_unset (coap_opt_filter_t filter, uint16_t type)
 Clears the corresponding entry for type in filter. More...
 
int coap_option_filter_get (coap_opt_filter_t filter, uint16_t type)
 Checks if type is contained in filter. More...
 
coap_optlist_tcoap_new_optlist (uint16_t number, size_t length, const uint8_t *data)
 Create a new optlist entry. More...
 
static int order_opts (void *a, void *b)
 
int coap_add_optlist_pdu (coap_pdu_t *pdu, coap_optlist_t **options)
 The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then added to the pdu. More...
 
int coap_insert_optlist (coap_optlist_t **head, coap_optlist_t *node)
 Adds optlist to the given optlist_chain. More...
 
static int coap_internal_delete (coap_optlist_t *node)
 
void coap_delete_optlist (coap_optlist_t *queue)
 Removes all entries from the optlist_chain, freeing off their memory usage. More...
 

Macro Definition Documentation

◆ ADVANCE_OPT

#define ADVANCE_OPT (   o,
  e,
  step 
)
Value:
if ((e) < step) { \
coap_log(LOG_DEBUG, "cannot advance opt past end\n"); \
return 0; \
} else { \
(e) -= step; \
(o) = ((o)) + step; \
}
Debug.
Definition: coap_debug.h:55

Definition at line 16 of file option.c.

◆ ADVANCE_OPT_CHECK

#define ADVANCE_OPT_CHECK (   o,
  e,
  step 
)
Value:
do { \
ADVANCE_OPT(o,e,step); \
if ((e) < 1) \
return 0; \
} while (0)

Definition at line 28 of file option.c.

◆ LONG_MASK

#define LONG_MASK   ((1 << COAP_OPT_FILTER_LONG) - 1)

Definition at line 428 of file option.c.

◆ SHORT_MASK

#define SHORT_MASK   (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))

Definition at line 429 of file option.c.

Enumeration Type Documentation

◆ filter_op_t

Operation specifiers for coap_filter_op().

Enumerator
FILTER_SET 
FILTER_CLEAR 
FILTER_GET 

Definition at line 441 of file option.c.

Function Documentation

◆ coap_add_optlist_pdu()

int coap_add_optlist_pdu ( coap_pdu_t pdu,
coap_optlist_t **  optlist_chain 
)

The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then added to the pdu.

Parameters
pduThe pdu to add the options to from the chain list
optlist_chainThe chained list of optlist to add to the pdu
Returns
1 if succesful or 0 if failure;

Definition at line 573 of file option.c.

+ Here is the call graph for this function:

◆ coap_delete_optlist()

void coap_delete_optlist ( coap_optlist_t optlist_chain)

Removes all entries from the optlist_chain, freeing off their memory usage.

Parameters
optlist_chainThe optlist chain to remove all the entries from

Definition at line 610 of file option.c.

+ Here is the call graph for this function:

◆ coap_insert_optlist()

int coap_insert_optlist ( coap_optlist_t **  optlist_chain,
coap_optlist_t optlist 
)

Adds optlist to the given 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.

Parameters
optlist_chainThe chain to add optlist to
optlistThe optlist to add to the queue
Returns
1 if successful, 0 otherwise.

Definition at line 589 of file option.c.

◆ coap_internal_delete()

static int coap_internal_delete ( coap_optlist_t node)
static

Definition at line 602 of file option.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_new_optlist()

coap_optlist_t* coap_new_optlist ( uint16_t  number,
size_t  length,
const uint8_t data 
)

Create a new optlist entry.

Parameters
numberThe option number (COAP_OPTION_*)
lengthThe option length
dataThe option value data
Returns
A pointer to the new optlist entry, or NULL if error

Definition at line 540 of file option.c.

+ Here is the call graph for this function:

◆ coap_opt_parse()

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 35 of file option.c.

+ Here is the caller graph for this function:

◆ coap_opt_size()

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 310 of file option.c.

+ Here is the call graph for this function:

◆ coap_option_filter_op()

static int coap_option_filter_op ( coap_opt_filter_t  filter,
uint16_t  type,
enum filter_op_t  op 
)
static

Applies op on filter with respect to type.

The following operations are defined:

FILTER_SET: Store type into an empty slot in filter. Returns 1 on success, or 0 if no spare slot was available.

FILTER_CLEAR: Remove type from filter if it exists.

FILTER_GET: Search for type in filter. Returns 1 if found, or 0 if not found.

Parameters
filterThe filter object.
typeThe option type to set, get or clear in filter.
opThe operation to apply to filter and type.
Returns
1 on success, and 0 when FILTER_GET yields no hit or no free slot is available to store type with FILTER_SET.

Definition at line 463 of file option.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_long_option()

COAP_STATIC_INLINE int is_long_option ( uint16_t  type)

Returns true iff type denotes an option type larger than 255.

Definition at line 438 of file option.c.

+ Here is the caller graph for this function:

◆ opt_finished()

COAP_STATIC_INLINE int opt_finished ( coap_opt_iterator_t oi)

Definition at line 134 of file option.c.

+ Here is the caller graph for this function:

◆ order_opts()

static int order_opts ( void *  a,
void *  b 
)
static

Definition at line 562 of file option.c.

+ Here is the caller graph for this function: