Simple encoding and decoding of CoRE Link Format (RFC 6690) strings. More...
Simple encoding and decoding of CoRE Link Format (RFC 6690) strings.
clif provides a high-level API for CoRE Link Format encoding and decoding of links, through the clif_encode_link and clif_decode_link respectively.
The high-level API is built on top of low-level functions provided by clif, such as clif_add_target, clif_add_attr, and clif_get_attr. Also, some convenience functions like clif_get_attr_type, clif_attr_type_to_str and clif_init_attr are provided, to facilitate the work with links.
clif_decode_link takes a buffer which contains an encoded link and returns the information of it in a clif_t structure and each attribute in a clif_attr_t structure of a given array.
clif_encode_link encodes a given link into a buffer, it can be called with a NULL pointer, in that case it will only calculate the amount of bytes needed to encode the link. After every call to this function a separator needs to be added to the buffer.
Files | |
| file | clif_internal.h | 
| Internal definitions for CoRE Link format module.  | |
| file | clif.h | 
| CoRE Link Format encoding and decoding library public definitions.  | |
Data Structures | |
| struct | clif_attr_t | 
| Link format attribute descriptor.  More... | |
| struct | clif_t | 
| Link format descriptor.  More... | |
Enumerations | |
| enum | { CLIF_OK = 0, CLIF_NO_SPACE = -1, CLIF_NOT_FOUND = -2 } | 
| Return types for the CoRE Link Format API.  More... | |
| enum | clif_attr_type_t {  CLIF_ATTR_ANCHOR = 0, CLIF_ATTR_REL = 1, CLIF_ATTR_LANG = 2, CLIF_ATTR_MEDIA = 3, CLIF_ATTR_TITLE = 4, CLIF_ATTR_TITLE_EXT = 5, CLIF_ATTR_TYPE = 6, CLIF_ATTR_RT = 7, CLIF_ATTR_IF = 8, CLIF_ATTR_SZ = 9, CLIF_ATTR_CT = 10, CLIF_ATTR_OBS = 11, CLIF_ATTR_EXT = 12 }  | 
| Types of link format attributes.  More... | |
Functions | |
| ssize_t | clif_encode_link (const clif_t *link, char *buf, size_t maxlen) | 
| Encodes a given link in link format into a given buffer.  More... | |
| ssize_t | clif_decode_link (clif_t *link, clif_attr_t *attrs, unsigned attrs_len, const char *buf, size_t maxlen) | 
| Decodes a string of link format.  More... | |
| ssize_t | clif_add_target (const char *target, char *buf, size_t maxlen) | 
Adds a given target to a given buffer buf using link format.  More... | |
| ssize_t | clif_add_attr (clif_attr_t *attr, char *buf, size_t maxlen) | 
Adds a given attr to a given buffer buf using link format.  More... | |
| ssize_t | clif_add_link_separator (char *buf, size_t maxlen) | 
Adds the link separator character to a given buf, using link format.  More... | |
| ssize_t | clif_get_target (const char *input, size_t input_len, char **output) | 
| Looks for a the target URI of a given link.  More... | |
| ssize_t | clif_get_attr (const char *input, size_t input_len, clif_attr_t *attr) | 
| Looks for the first attribute in a given link.  More... | |
| clif_attr_type_t | clif_get_attr_type (const char *input, size_t input_len) | 
| Returns the attribute type of a given string.  More... | |
| ssize_t | clif_attr_type_to_str (clif_attr_type_t type, const char **str) | 
| Returns a constant string of a given attribute type.  More... | |
| int | clif_init_attr (clif_attr_t *attr, clif_attr_type_t type) | 
| Initializes the key of a given attribute according to a given type.  More... | |
| anonymous enum | 
Return types for the CoRE Link Format API.
| Enumerator | |
|---|---|
| CLIF_OK | success  | 
| CLIF_NO_SPACE | not enough space in the buffer  | 
| CLIF_NOT_FOUND | could not find a component in a buffer  | 
| enum clif_attr_type_t | 
Types of link format attributes.
| ssize_t clif_add_attr | ( | clif_attr_t * | attr, | 
| char * | buf, | ||
| size_t | maxlen | ||
| ) | 
Adds a given attr to a given buffer buf using link format. 
(attr != NULL) && (attr->key != NULL)| [in] | attr | pointer to the attribute to add. Must not be NULL, and must contain a key. | 
| [out] | buf | buffer to add the attribute to. Can be NULL | 
| [in] | maxlen | size of buf  | 
buf is NULL this will return the amount of bytes that would be needed.| ssize_t clif_add_link_separator | ( | char * | buf, | 
| size_t | maxlen | ||
| ) | 
Adds the link separator character to a given buf, using link format. 
| [out] | buf | buffer to add the separator to. Can be NULL | 
| [in] | maxlen | size of buf  | 
buf is NULL this will return the amount of bytes that would be needed| ssize_t clif_add_target | ( | const char * | target, | 
| char * | buf, | ||
| size_t | maxlen | ||
| ) | 
Adds a given target to a given buffer buf using link format. 
target != NULL| [in] | target | string containing the path to the resource. Must not be NULL. | 
| [out] | buf | buffer to output the formatted path. Can be NULL | 
| [in] | maxlen | size of buf  | 
buf is NULL this will return the amount of bytes that would be needed| ssize_t clif_attr_type_to_str | ( | clif_attr_type_t | type, | 
| const char ** | str | ||
| ) | 
Returns a constant string of a given attribute type.
| [in] | type | type of the attribute | 
| [out] | str | pointer to store the string pointer | 
| ssize_t clif_decode_link | ( | clif_t * | link, | 
| clif_attr_t * | attrs, | ||
| unsigned | attrs_len, | ||
| const char * | buf, | ||
| size_t | maxlen | ||
| ) | 
Decodes a string of link format.
It decodes the first occurrence of a link.
(link != NULL) && (buf != NULL)| [out] | link | link to populate. Must not be NULL. | 
| [out] | attrs | array of attrs to populate | 
| [in] | attrs_len | length of attrs  | 
| [in] | buf | string to decode. Must not be NULL. | 
| [in] | maxlen | size of buf  | 
buf in success | ssize_t clif_encode_link | ( | const clif_t * | link, | 
| char * | buf, | ||
| size_t | maxlen | ||
| ) | 
Encodes a given link in link format into a given buffer.
link != NULL| [in] | link | link to encode.Must not be NULL. | 
| [out] | buf | buffer to output the encoded link. Can be NULL | 
| [in] | maxlen | size of buf  | 
buf is NULL this will return the amount of bytes that would be neededbuf in success | ssize_t clif_get_attr | ( | const char * | input, | 
| size_t | input_len, | ||
| clif_attr_t * | attr | ||
| ) | 
Looks for the first attribute in a given link.
(input != NULL) && (attr != NULL)input should start with the attribute separator character ';'.| [in] | input | string where to look for the attribute. It should only be ONE link. Must not be NULL. | 
| [in] | input_len | length of input  | 
| [out] | attr | pointer to store the found attribute information. Must not be NULL. | 
| clif_attr_type_t clif_get_attr_type | ( | const char * | input, | 
| size_t | input_len | ||
| ) | 
Returns the attribute type of a given string.
(input != NULL) && (input_len > 0)| [in] | input | string containing the attribute name. Must not be NULL. | 
| [in] | input_len | length of input. Must be greater than 0. | 
| ssize_t clif_get_target | ( | const char * | input, | 
| size_t | input_len, | ||
| char ** | output | ||
| ) | 
Looks for a the target URI of a given link.
input != NULL| [in] | input | string where to look for the target. It should only be ONE link. Must not be NULL. | 
| [in] | input_len | length of input.  | 
| [out] | output | if a target is found this will point to the beginning of it | 
| int clif_init_attr | ( | clif_attr_t * | attr, | 
| clif_attr_type_t | type | ||
| ) | 
Initializes the key of a given attribute according to a given type.
| [out] | attr | attribute to initialize | 
| [in] | type | type of the attribute |