libcoap 4.3.5-develop-72190a8
Loading...
Searching...
No Matches
URI Parsing Functions

API for parsing URIs. More...

+ Collaboration diagram for URI Parsing Functions:

Functions

int coap_split_uri (const uint8_t *str_var, size_t len, coap_uri_t *uri)
 Parses a given string into URI components.
 
int coap_split_proxy_uri (const uint8_t *str_var, size_t len, coap_uri_t *uri)
 Parses a given string into URI components.
 
int coap_uri_into_options (const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt, uint8_t *buf, size_t buflen)
 Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
 
int coap_uri_into_optlist (const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt)
 Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
 
int coap_split_path (const uint8_t *path, size_t length, unsigned char *buf, size_t *buflen)
 Splits the given URI path into segments.
 
int coap_path_into_optlist (const uint8_t *path, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
 Splits the given URI path into '/' separate segments, and then adds the Uri-Path / Location-Path option for each segment to the optlist_chain.
 
int coap_split_query (const uint8_t *query, size_t length, unsigned char *buf, size_t *buflen)
 Splits the given URI query into segments.
 
int coap_query_into_optlist (const uint8_t *query, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
 Splits the given URI query into '&' separate segments, and then adds the Uri-Query / Location-Query option for each segment to the optlist_chain.
 
coap_string_tcoap_get_query (const coap_pdu_t *request)
 Extract query string from request PDU according to escape rules in 6.5.8.
 
coap_string_tcoap_get_uri_path (const coap_pdu_t *request)
 Extract uri_path string from request PDU.
 

Detailed Description

API for parsing URIs.

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 939 of file coap_uri.c.

+ Here is the call 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 990 of file coap_uri.c.

+ Here is the call graph for this function:

◆ coap_path_into_optlist()

int coap_path_into_optlist ( const uint8_t *  path,
size_t  length,
coap_option_num_t  optnum,
coap_optlist_t **  optlist_chain 
)

Splits the given URI path into '/' separate segments, and then adds the Uri-Path / Location-Path option for each segment to the optlist_chain.

Note: any segments that are just '.' or '..' are stripped out.

Parameters
pathThe path string to split.
lengthThe actual length of path.
optnumThe CoAP option (COAP_OPTION_URI_PATH or COAP_OPTION_LOCATION_PATH)
optlist_chainThe chain of optlists to add to. optlist_chain parent is to be NULL or a previous set of optlists.
Returns
1 on success else 0 if error.

Definition at line 737 of file coap_uri.c.

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

◆ coap_query_into_optlist()

int coap_query_into_optlist ( const uint8_t *  query,
size_t  length,
coap_option_num_t  optnum,
coap_optlist_t **  optlist_chain 
)

Splits the given URI query into '&' separate segments, and then adds the Uri-Query / Location-Query option for each segment to the optlist_chain.

Parameters
queryThe query string to split.
lengthThe actual length of query.
optnumThe CoAP option (COAP_OPTION_URI_QUERY or COAP_OPTION_LOCATION_QUERY)
optlist_chainThe chain of optlists to add to. optlist_chain parent is to be NULL or a previous set of optlists.
Returns
1 on success else 0 if error.

Definition at line 827 of file coap_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 *  path,
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
pathThe path string to split.
lengthThe actual length of path.
bufResult buffer for parsed segments.
buflenMaximum length of buf. Will be set to the actual number of bytes written into buf on success. This needs to be at least length, but 2 bytes should be added for each segment to handle large segments.
Returns
The number of segments created or -1 on error.

Definition at line 685 of file coap_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 and https.

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 281 of file coap_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 *  query,
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 segment.

Parameters
queryThe query string to split.
lengthThe actual length of query
bufResult buffer for parsed segments.
buflenMaximum length of buf. Will be set to the actual number of bytes written into buf on success. This needs to be at least length, but 2 bytes should be added for each segment to handle large segments.
Returns
The number of segments created or -1 on error.

Definition at line 803 of file coap_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 276 of file coap_uri.c.

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

◆ coap_uri_into_options()

int coap_uri_into_options ( const coap_uri_t uri,
const coap_address_t dst,
coap_optlist_t **  optlist_chain,
int  create_port_host_opt,
uint8_t *  buf,
size_t  buflen 
)

Takes a coap_uri_t and then adds CoAP options into the optlist_chain.

If the port is not the default port and create_port_host_opt is not 0, then the Uri-Port option is added to the optlist_chain. If the dst defines an address that does not match the host in uri->host and is not 0, then the Uri-Host option is added to the optlist_chain. Any path or query are broken down into the individual segment Uri-Path or Uri-Query options and added to the optlist_chain.

Note: coap_uri_into_optlist(3) is an alternative function (but has a different return value).

Parameters
uriThe coap_uri_t object.
dstThe destination, or NULL if URI_HOST not to be added.
optlist_chainWhere to store the chain of options.
create_port_host_opt1 if port/host option to be added (if non-default) else 0
bufParameter ignored. Can be NULL.
buflenParameter ignored.
Returns
0 on success, or < 0 on error.

◆ coap_uri_into_optlist()

int coap_uri_into_optlist ( const coap_uri_t uri,
const coap_address_t dst,
coap_optlist_t **  optlist_chain,
int  create_port_host_opt 
)

Takes a coap_uri_t and then adds CoAP options into the optlist_chain.

If the port is not the default port and create_port_host_opt is not 0, then the Uri-Port option is added to the optlist_chain. If the dst defines an address that does not match the host in uri->host and is not 0, then the Uri-Host option is added to the optlist_chain. Any path or query are broken down into the individual segment Uri-Path or Uri-Query options and added to the optlist_chain.

Parameters
uriThe coap_uri_t object.
dstThe destination, or NULL if URI_HOST not to be added.
optlist_chainWhere to store the chain of options.
create_port_host_opt1 if port/host option to be added (if non-default) else 0.
Returns
1 on success, 0 if error.

Definition at line 304 of file coap_uri.c.

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