libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Functions
URI Parsing Functions

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

Data Structures

struct  coap_parse_iterator_t
 Iterator to for tokenizing a URI path or query. More...
 

Functions

coap_parse_iterator_tcoap_parse_iterator_init (unsigned char *s, size_t n, unsigned char separator, unsigned char *delim, size_t dlen, coap_parse_iterator_t *pi)
 Initializes the given iterator pi. More...
 
unsigned char * coap_parse_next (coap_parse_iterator_t *pi)
 Updates the iterator pi to point to the next token. More...
 
int coap_split_uri (unsigned char *str_var, size_t len, coap_uri_t *uri)
 Parses a given string into URI components. More...
 
int coap_split_path (const unsigned char *s, size_t length, unsigned char *buf, size_t *buflen)
 Splits the given URI path into segments. More...
 
int coap_split_query (const unsigned char *s, size_t length, unsigned char *buf, size_t *buflen)
 Splits the given URI query into segments. 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_parse_iterator_t* coap_parse_iterator_init ( unsigned char *  s,
size_t  n,
unsigned char  separator,
unsigned char *  delim,
size_t  dlen,
coap_parse_iterator_t pi 
)

Initializes the given iterator pi.

Parameters
sThe string to tokenize.
nThe length of s.
separatorThe separator character that delimits tokens.
delimA set of characters that delimit .
dlenThe length of delim.
piThe iterator object to initialize.
Returns
The initialized iterator object pi.

Definition at line 472 of file uri.c.

unsigned char* coap_parse_next ( coap_parse_iterator_t pi)

Updates the iterator pi to point to the next token.

This function returns a pointer to that token or NULL if no more tokens exist. The contents of pi will be updated. In particular, pi->segment_length specifies the length of the current token, pi->pos points to its beginning.

Parameters
piThe iterator to update.
Returns
The next token or NULL if no more tokens exist.

Definition at line 490 of file uri.c.

int coap_split_path ( const unsigned char *  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 354 of file uri.c.

int coap_split_query ( const unsigned char *  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.
Bug:
This function does not reserve additional space for delta > 12.

Definition at line 368 of file uri.c.

int coap_split_uri ( unsigned char *  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 COAP_DEFAULT_PORT. 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.
Note
The host name part will be converted to lower case by this function.

Definition at line 45 of file uri.c.