clif.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 HAW Hamburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
94 #include <sys/types.h>
95 
96 #include "clif_internal.h"
97 
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101 
105 enum {
106  CLIF_OK = 0,
108  CLIF_NOT_FOUND = -2
109 };
110 
114 typedef enum {
127  CLIF_ATTR_EXT = 12
129 
133 typedef struct {
134  char *value;
135  unsigned value_len;
136  const char *key;
137  unsigned key_len;
138 } clif_attr_t;
139 
143 typedef struct {
144  char *target;
145  unsigned target_len;
147  unsigned attrs_len;
148 } clif_t;
149 
165 ssize_t clif_encode_link(const clif_t *link, char *buf, size_t maxlen);
166 
182 ssize_t clif_decode_link(clif_t *link, clif_attr_t *attrs, unsigned attrs_len,
183  const char *buf, size_t maxlen);
184 
202 ssize_t clif_add_target_from_buffer(const char *target, size_t target_len,
203  char *buf, size_t maxlen);
204 
221 ssize_t clif_add_target(const char *target, char *buf, size_t maxlen);
222 
241 ssize_t clif_add_attr(clif_attr_t *attr, char *buf, size_t maxlen);
242 
256 ssize_t clif_add_link_separator(char *buf, size_t maxlen);
257 
272 ssize_t clif_get_target(const char *input, size_t input_len, char **output);
290 ssize_t clif_get_attr(const char *input, size_t input_len, clif_attr_t *attr);
291 
302 clif_attr_type_t clif_get_attr_type(const char *input, size_t input_len);
303 
313 ssize_t clif_attr_type_to_str(clif_attr_type_t type, const char **str);
314 
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
Internal definitions for CoRE Link format module.
ssize_t clif_attr_type_to_str(clif_attr_type_t type, const char **str)
Returns a constant string of a given attribute type.
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.
clif_attr_type_t
Types of link format attributes.
Definition: clif.h:114
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.
ssize_t clif_add_target_from_buffer(const char *target, size_t target_len, char *buf, size_t maxlen)
Adds a given target to a given buffer buf using link format.
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.
ssize_t clif_get_target(const char *input, size_t input_len, char **output)
Looks for a the target URI of a given link.
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.
clif_attr_type_t clif_get_attr_type(const char *input, size_t input_len)
Returns the attribute type of a given string.
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.
ssize_t clif_add_link_separator(char *buf, size_t maxlen)
Adds the link separator character to a given buf, using link format.
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.
@ CLIF_ATTR_CT
ct
Definition: clif.h:125
@ CLIF_ATTR_SZ
sz
Definition: clif.h:124
@ CLIF_ATTR_LANG
hreflang
Definition: clif.h:117
@ CLIF_ATTR_RT
rt
Definition: clif.h:122
@ CLIF_ATTR_OBS
obs
Definition: clif.h:126
@ CLIF_ATTR_REL
rel
Definition: clif.h:116
@ CLIF_ATTR_ANCHOR
anchor
Definition: clif.h:115
@ CLIF_ATTR_TITLE
title
Definition: clif.h:119
@ CLIF_ATTR_IF
if
Definition: clif.h:123
@ CLIF_ATTR_TYPE
type
Definition: clif.h:121
@ CLIF_ATTR_MEDIA
media
Definition: clif.h:118
@ CLIF_ATTR_EXT
extensions
Definition: clif.h:127
@ CLIF_ATTR_TITLE_EXT
title*
Definition: clif.h:120
@ CLIF_NOT_FOUND
could not find a component in a buffer
Definition: clif.h:108
@ CLIF_NO_SPACE
not enough space in the buffer
Definition: clif.h:107
@ CLIF_OK
success
Definition: clif.h:106
Link format attribute descriptor.
Definition: clif.h:133
unsigned key_len
length of the attribute name
Definition: clif.h:137
unsigned value_len
length of the value
Definition: clif.h:135
const char * key
attribute name
Definition: clif.h:136
char * value
string with the value
Definition: clif.h:134
Link format descriptor.
Definition: clif.h:143
unsigned target_len
length of target string
Definition: clif.h:145
unsigned attrs_len
size of array of attributes
Definition: clif.h:147
char * target
target string
Definition: clif.h:144
clif_attr_t * attrs
array of attributes
Definition: clif.h:146