clif.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
95 #ifndef CLIF_H
96 #define CLIF_H
97 
98 #include <sys/types.h>
99 
100 #include "clif_internal.h"
101 
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
109 enum {
110  CLIF_OK = 0,
113 };
114 
118 typedef enum {
133 
137 typedef struct {
138  char *value;
139  unsigned value_len;
140  const char *key;
141  unsigned key_len;
142 } clif_attr_t;
143 
147 typedef struct {
148  char *target;
149  unsigned target_len;
151  unsigned attrs_len;
152 } clif_t;
153 
169 ssize_t clif_encode_link(const clif_t *link, char *buf, size_t maxlen);
170 
186 ssize_t clif_decode_link(clif_t *link, clif_attr_t *attrs, unsigned attrs_len,
187  const char *buf, size_t maxlen);
188 
205 ssize_t clif_add_target(const char *target, char *buf, size_t maxlen);
206 
227 ssize_t clif_add_attr(clif_attr_t *attr, char *buf, size_t maxlen);
228 
242 ssize_t clif_add_link_separator(char *buf, size_t maxlen);
243 
258 ssize_t clif_get_target(const char *input, size_t input_len, char **output);
276 ssize_t clif_get_attr(const char *input, size_t input_len, clif_attr_t *attr);
277 
288 clif_attr_type_t clif_get_attr_type(const char *input, size_t input_len);
289 
299 ssize_t clif_attr_type_to_str(clif_attr_type_t type, const char **str);
300 
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 
316 #endif /* CLIF_H */
317 
clif_add_attr
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_add_target
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.
clif_decode_link
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_to_str
ssize_t clif_attr_type_to_str(clif_attr_type_t type, const char **str)
Returns a constant string of a given attribute type.
clif_attr_t::key_len
unsigned key_len
length of the attribute name
Definition: clif.h:141
CLIF_ATTR_TYPE
@ CLIF_ATTR_TYPE
type
Definition: clif.h:125
CLIF_NOT_FOUND
@ CLIF_NOT_FOUND
could not find a component in a buffer
Definition: clif.h:112
clif_attr_type_t
clif_attr_type_t
Types of link format attributes.
Definition: clif.h:118
clif_t::attrs_len
unsigned attrs_len
size of array of attributes
Definition: clif.h:151
CLIF_ATTR_MEDIA
@ CLIF_ATTR_MEDIA
media
Definition: clif.h:122
clif_get_attr_type
clif_attr_type_t clif_get_attr_type(const char *input, size_t input_len)
Returns the attribute type of a given string.
CLIF_ATTR_ANCHOR
@ CLIF_ATTR_ANCHOR
anchor
Definition: clif.h:119
clif_encode_link
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.
clif_attr_t
Link format attribute descriptor.
Definition: clif.h:137
CLIF_ATTR_SZ
@ CLIF_ATTR_SZ
sz
Definition: clif.h:128
clif_get_target
ssize_t clif_get_target(const char *input, size_t input_len, char **output)
Looks for a the target URI of a given link.
clif_t::attrs
clif_attr_t * attrs
array of attributes
Definition: clif.h:150
clif_init_attr
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.
clif_attr_t::key
const char * key
attribute name
Definition: clif.h:140
clif_get_attr
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_t::value
char * value
string with the value
Definition: clif.h:138
CLIF_NO_SPACE
@ CLIF_NO_SPACE
not enough space in the buffer
Definition: clif.h:111
CLIF_OK
@ CLIF_OK
success
Definition: clif.h:110
CLIF_ATTR_TITLE
@ CLIF_ATTR_TITLE
title
Definition: clif.h:123
clif_attr_t::value_len
unsigned value_len
length of the value
Definition: clif.h:139
clif_t::target
char * target
target string
Definition: clif.h:148
CLIF_ATTR_LANG
@ CLIF_ATTR_LANG
hreflang
Definition: clif.h:121
clif_t::target_len
unsigned target_len
length of target string
Definition: clif.h:149
CLIF_ATTR_IF
@ CLIF_ATTR_IF
if
Definition: clif.h:127
CLIF_ATTR_TITLE_EXT
@ CLIF_ATTR_TITLE_EXT
title*
Definition: clif.h:124
clif_internal.h
Internal definitions for CoRE Link format module.
clif_add_link_separator
ssize_t clif_add_link_separator(char *buf, size_t maxlen)
Adds the link separator character to a given buf, using link format.
CLIF_ATTR_RT
@ CLIF_ATTR_RT
rt
Definition: clif.h:126
CLIF_ATTR_EXT
@ CLIF_ATTR_EXT
extensions
Definition: clif.h:131
CLIF_ATTR_OBS
@ CLIF_ATTR_OBS
obs
Definition: clif.h:130
clif_t
Link format descriptor.
Definition: clif.h:147
CLIF_ATTR_CT
@ CLIF_ATTR_CT
ct
Definition: clif.h:129
CLIF_ATTR_REL
@ CLIF_ATTR_REL
rel
Definition: clif.h:120