libcoap  4.3.0rc3
URI Parsing Functions

CoAP PDUs contain normalized URIs with their path and query split into multiple segments. More...

Functions

int coap_split_uri (const uint8_t *str_var, size_t len, coap_uri_t *uri)
 Parses a given string into URI components. More...
 
int coap_split_proxy_uri (const uint8_t *str_var, size_t len, coap_uri_t *uri)
 Parses a given string into URI components. More...
 
int coap_split_path (const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
 Splits the given URI path into segments. More...
 
int coap_split_query (const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
 Splits the given URI query into segments. More...
 
coap_string_tcoap_get_query (const coap_pdu_t *request)
 Extract query string from request PDU according to escape rules in 6.5.8. More...
 
coap_string_tcoap_get_uri_path (const coap_pdu_t *request)
 Extract uri_path string from request PDU. More...
 

Detailed Description

CoAP PDUs contain normalized URIs with their path and query split into multiple segments.

The functions in this module help splitting strings.

Function Documentation

◆ coap_get_query()

coap_string_t* coap_get_query ( const coap_pdu_t request)

Extract query string from request PDU according to escape rules in 6.5.8.

Parameters
requestRequest PDU.
Returns
Reconstructed and escaped query string part or NULL if no query was contained in request. The coap_string_t object returned by this function must be released with coap_delete_string.

Definition at line 554 of file uri.c.

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

◆ coap_get_uri_path()

coap_string_t* coap_get_uri_path ( const coap_pdu_t request)

Extract uri_path string from request PDU.

Parameters
requestRequest PDU.
Returns
Reconstructed and escaped uri path string part or NULL if no URI-Path was contained in request. The coap_string_t object returned by this function must be released with coap_delete_string.

Definition at line 604 of file uri.c.

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

◆ coap_split_path()

int coap_split_path ( const uint8_t *  s,
size_t  length,
unsigned char *  buf,
size_t *  buflen 
)

Splits the given URI path into segments.

Each segment is preceded by an option pseudo-header with delta-value 0 and the actual length of the respective segment after percent-decoding.

Parameters
sThe path string to split.
lengthThe actual length of s.
bufResult buffer for parsed segments.
buflenMaximum length of buf. Will be set to the actual number of bytes written into buf on success.
Returns
The number of segments created or -1 on error.

Definition at line 442 of file uri.c.

+ Here is the call graph for this function:

◆ coap_split_proxy_uri()

int coap_split_proxy_uri ( const uint8_t *  str_var,
size_t  len,
coap_uri_t uri 
)

Parses a given string into URI components.

The identified syntactic components are stored in the result parameter uri. Optional URI components that are not specified will be set to { 0, 0 }, except for the port which is set to default port for the protocol. This function returns 0 if parsing succeeded, a value less than zero otherwise. Note: This function enforces that the given string is in Proxy-Uri format as well as supports different schema such as http.

Parameters
str_varThe string to split up.
lenThe actual length of str_var
uriThe coap_uri_t object to store the result.
Returns
0 on success, or < 0 on error.

Definition at line 239 of file uri.c.

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

◆ coap_split_query()

int coap_split_query ( const uint8_t *  s,
size_t  length,
unsigned char *  buf,
size_t *  buflen 
)

Splits the given URI query into segments.

Each segment is preceded by an option pseudo-header with delta-value 0 and the actual length of the respective query term.

Parameters
sThe query string to split.
lengthThe actual length of s.
bufResult buffer for parsed segments.
buflenMaximum length of buf. Will be set to the actual number of bytes written into buf on success.
Returns
The number of segments created or -1 on error.

Definition at line 454 of file uri.c.

+ Here is the call graph for this function:

◆ coap_split_uri()

int coap_split_uri ( const uint8_t *  str_var,
size_t  len,
coap_uri_t uri 
)

Parses a given string into URI components.

The identified syntactic components are stored in the result parameter uri. Optional URI components that are not specified will be set to { 0, 0 }, except for the port which is set to the default port for the protocol. This function returns 0 if parsing succeeded, a value less than zero otherwise.

Parameters
str_varThe string to split up.
lenThe actual length of str_var
uriThe coap_uri_t object to store the result.
Returns
0 on success, or < 0 on error.

Definition at line 234 of file uri.c.

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