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 
9 #pragma once
10 
97 #include <sys/types.h>
98 
99 #include "clif_internal.h"
100 
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104 
108 enum {
109  CLIF_OK = 0,
111  CLIF_NOT_FOUND = -2
112 };
113 
117 typedef enum {
130  CLIF_ATTR_EXT = 12
132 
136 typedef struct {
137  char *value;
138  unsigned value_len;
139  const char *key;
140  unsigned key_len;
141 } clif_attr_t;
142 
146 typedef struct {
147  char *target;
148  unsigned target_len;
150  unsigned attrs_len;
151 } clif_t;
152 
168 ssize_t clif_encode_link(const clif_t *link, char *buf, size_t maxlen);
169 
185 ssize_t clif_decode_link(clif_t *link, clif_attr_t *attrs, unsigned attrs_len,
186  const char *buf, size_t maxlen);
187 
205 ssize_t clif_add_target_from_buffer(const char *target, size_t target_len,
206  char *buf, size_t maxlen);
207 
224 ssize_t clif_add_target(const char *target, char *buf, size_t maxlen);
225 
244 ssize_t clif_add_attr(clif_attr_t *attr, char *buf, size_t maxlen);
245 
259 ssize_t clif_add_link_separator(char *buf, size_t maxlen);
260 
275 ssize_t clif_get_target(const char *input, size_t input_len, char **output);
293 ssize_t clif_get_attr(const char *input, size_t input_len, clif_attr_t *attr);
294 
305 clif_attr_type_t clif_get_attr_type(const char *input, size_t input_len);
306 
316 ssize_t clif_attr_type_to_str(clif_attr_type_t type, const char **str);
317 
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
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:117
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:128
@ CLIF_ATTR_SZ
sz
Definition: clif.h:127
@ CLIF_ATTR_LANG
hreflang
Definition: clif.h:120
@ CLIF_ATTR_RT
rt
Definition: clif.h:125
@ CLIF_ATTR_OBS
obs
Definition: clif.h:129
@ CLIF_ATTR_REL
rel
Definition: clif.h:119
@ CLIF_ATTR_ANCHOR
anchor
Definition: clif.h:118
@ CLIF_ATTR_TITLE
title
Definition: clif.h:122
@ CLIF_ATTR_IF
if
Definition: clif.h:126
@ CLIF_ATTR_TYPE
type
Definition: clif.h:124
@ CLIF_ATTR_MEDIA
media
Definition: clif.h:121
@ CLIF_ATTR_EXT
extensions
Definition: clif.h:130
@ CLIF_ATTR_TITLE_EXT
title*
Definition: clif.h:123
@ CLIF_NOT_FOUND
could not find a component in a buffer
Definition: clif.h:111
@ CLIF_NO_SPACE
not enough space in the buffer
Definition: clif.h:110
@ CLIF_OK
success
Definition: clif.h:109
Link format attribute descriptor.
Definition: clif.h:136
unsigned key_len
length of the attribute name
Definition: clif.h:140
unsigned value_len
length of the value
Definition: clif.h:138
const char * key
attribute name
Definition: clif.h:139
char * value
string with the value
Definition: clif.h:137
Link format descriptor.
Definition: clif.h:146
unsigned target_len
length of target string
Definition: clif.h:148
unsigned attrs_len
size of array of attributes
Definition: clif.h:150
char * target
target string
Definition: clif.h:147
clif_attr_t * attrs
array of attributes
Definition: clif.h:149