libcoap  4.2.1
String handling support

API functions for handling strings. More...

Data Structures

struct  coap_string_t
 Coap string data definition. More...
 
struct  coap_str_const_t
 Coap string data definition with const data. More...
 
struct  coap_binary_t
 Coap binary data definition. More...
 

Macros

#define COAP_SET_STR(st, l, v)   { (st)->length = (l), (st)->s = (v); }
 
#define COAP_MAX_STR_CONST_FUNC   2
 
#define coap_string_equal(string1, string2)
 Compares the two strings for equality. More...
 

Typedefs

typedef struct coap_string_t coap_string_t
 Coap string data definition. More...
 
typedef struct coap_str_const_t coap_str_const_t
 Coap string data definition with const data. More...
 
typedef struct coap_binary_t coap_binary_t
 Coap binary data definition. More...
 

Functions

coap_string_tcoap_new_string (size_t size)
 Returns a new string object with at least size+1 bytes storage allocated. More...
 
void coap_delete_string (coap_string_t *string)
 Deletes the given string and releases any memory allocated. More...
 
coap_str_const_tcoap_new_str_const (const uint8_t *data, size_t size)
 Returns a new const string object with at least size+1 bytes storage allocated, and the provided data copied into the string object. More...
 
void coap_delete_str_const (coap_str_const_t *string)
 Deletes the given const string and releases any memory allocated. More...
 
coap_str_const_tcoap_make_str_const (const char *string)
 Take the specified string and create a coap_str_const_t *. More...
 

Detailed Description

API functions for handling strings.

Macro Definition Documentation

◆ COAP_MAX_STR_CONST_FUNC

#define COAP_MAX_STR_CONST_FUNC   2

Definition at line 84 of file str.h.

◆ COAP_SET_STR

#define COAP_SET_STR (   st,
  l,
 
)    { (st)->length = (l), (st)->s = (v); }

Definition at line 38 of file str.h.

◆ coap_string_equal

#define coap_string_equal (   string1,
  string2 
)
Value:
((string1)->length == (string2)->length && ((string1)->length == 0 || \
memcmp((string1)->s, (string2)->s, (string1)->length) == 0))

Compares the two strings for equality.

Parameters
string1The first string.
string2The second string.
Returns
1 if the strings are equal 0 otherwise.

Definition at line 109 of file str.h.

Typedef Documentation

◆ coap_binary_t

typedef struct coap_binary_t coap_binary_t

Coap binary data definition.

◆ coap_str_const_t

Coap string data definition with const data.

◆ coap_string_t

typedef struct coap_string_t coap_string_t

Coap string data definition.

Function Documentation

◆ coap_delete_str_const()

void coap_delete_str_const ( coap_str_const_t string)

Deletes the given const string and releases any memory allocated.

Parameters
stringThe string to free off.

Definition at line 40 of file str.c.

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

◆ coap_delete_string()

void coap_delete_string ( coap_string_t string)

Deletes the given string and releases any memory allocated.

Parameters
stringThe string to free off.

Definition at line 27 of file str.c.

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

◆ coap_make_str_const()

coap_str_const_t* coap_make_str_const ( const char *  string)

Take the specified string and create a coap_str_const_t *.

Note: the array is 2 deep as there are up to two callings of coap_make_str_const in a function call. e.g. coap_add_attr(). Caution: If there are local variable assignments, these will cycle around the var[COAP_MAX_STR_CONST_FUNC] set. No current examples do this.

Parameters
stringThe const string to convert to a coap_str_const_t *
Returns
A pointer to one of two static variables containing the coap_str_const_t * result

Definition at line 44 of file str.c.

◆ coap_new_str_const()

coap_str_const_t* coap_new_str_const ( const uint8_t data,
size_t  size 
)

Returns a new const string object with at least size+1 bytes storage allocated, and the provided data copied into the string object.

The string must be released using coap_delete_str_const().

Parameters
dataThe data to put in the new string object.
sizeThe size to allocate for the binary string data.
Returns
A pointer to the new object or NULL on error.

Definition at line 31 of file str.c.

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

◆ coap_new_string()

coap_string_t* coap_new_string ( size_t  size)

Returns a new string object with at least size+1 bytes storage allocated.

The string must be released using coap_delete_string().

Parameters
sizeThe size to allocate for the binary string data.
Returns
A pointer to the new object or NULL on error.

Definition at line 13 of file str.c.

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