Libecoli  0.9.1
Extensible COmmand LIne library
config.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
3  */
4 
12 #pragma once
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <stdio.h>
17 #include <sys/queue.h>
18 
19 struct ec_config;
20 struct ec_dict;
21 
26  EC_CONFIG_TYPE_NONE = 0,
27  EC_CONFIG_TYPE_BOOL,
28  EC_CONFIG_TYPE_INT64,
29  EC_CONFIG_TYPE_UINT64,
30  EC_CONFIG_TYPE_STRING,
31  EC_CONFIG_TYPE_NODE,
32  EC_CONFIG_TYPE_LIST,
33  EC_CONFIG_TYPE_DICT,
34 };
35 
44  const char *key;
45  const char *desc;
46  enum ec_config_type type;
47  /* XXX flags: mandatory */
48  /* XXX default */
49 
52  const struct ec_config_schema *subschema;
53 };
54 
55 TAILQ_HEAD(ec_config_list, ec_config);
56 
60 struct ec_config {
62  enum ec_config_type type;
63 
64  union {
65  bool boolean;
66  int64_t i64;
67  uint64_t u64;
68  char *string;
69  struct ec_node *node;
70  struct ec_dict *dict;
71  struct ec_config_list list;
72  };
73 
77  TAILQ_ENTRY(ec_config) next;
78 };
79 
80 /* schema */
81 
91 int ec_config_schema_validate(const struct ec_config_schema *schema);
92 
102 void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema);
103 
117 const struct ec_config_schema *
118 ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key);
119 
128 enum ec_config_type ec_config_schema_type(const struct ec_config_schema *schema_elt);
129 
138 const struct ec_config_schema *ec_config_schema_sub(const struct ec_config_schema *schema_elt);
139 
150 bool ec_config_key_is_reserved(const char *name);
151 
155 extern const char *ec_config_reserved_keys[];
156 
157 /* config */
158 
167 enum ec_config_type ec_config_get_type(const struct ec_config *config);
168 
177 struct ec_config *ec_config_bool(bool boolean);
178 
187 struct ec_config *ec_config_i64(int64_t i64);
188 
197 struct ec_config *ec_config_u64(uint64_t u64);
198 
208 struct ec_config *ec_config_string(const char *string);
209 
221 struct ec_config *ec_config_node(struct ec_node *node);
222 
230 struct ec_config *ec_config_dict(void);
231 
239 struct ec_config *ec_config_list(void);
240 
253 int ec_config_list_add(struct ec_config *list, struct ec_config *value);
254 
267 int ec_config_list_del(struct ec_config *list, struct ec_config *config);
268 
277 ssize_t ec_config_count(const struct ec_config *config);
278 
290 int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema);
291 
305 int ec_config_dict_set(struct ec_config *dict, const char *key, struct ec_config *value);
306 
319 int ec_config_dict_del(struct ec_config *dict, const char *key);
320 
324 int ec_config_cmp(const struct ec_config *config1, const struct ec_config *config2);
325 
329 struct ec_config *ec_config_dict_get(const struct ec_config *config, const char *key);
330 
348 
359 struct ec_config *ec_config_list_next(struct ec_config *list, struct ec_config *config);
360 
367 void ec_config_free(struct ec_config *config);
368 
375 int ec_config_cmp(const struct ec_config *value1, const struct ec_config *value2);
376 
385 struct ec_config *ec_config_dup(const struct ec_config *config);
386 
395 void ec_config_dump(FILE *out, const struct ec_config *config);
396 
int ec_config_list_del(struct ec_config *list, struct ec_config *config)
struct ec_config * ec_config_list(void)
struct ec_config * ec_config_u64(uint64_t u64)
int ec_config_schema_validate(const struct ec_config_schema *schema)
struct ec_config * ec_config_list_next(struct ec_config *list, struct ec_config *config)
enum ec_config_type ec_config_schema_type(const struct ec_config_schema *schema_elt)
int ec_config_cmp(const struct ec_config *config1, const struct ec_config *config2)
int ec_config_dict_del(struct ec_config *dict, const char *key)
const struct ec_config_schema * ec_config_schema_sub(const struct ec_config_schema *schema_elt)
struct ec_config * ec_config_dict(void)
void ec_config_free(struct ec_config *config)
ssize_t ec_config_count(const struct ec_config *config)
const char * ec_config_reserved_keys[]
struct ec_config * ec_config_dup(const struct ec_config *config)
struct ec_config * ec_config_node(struct ec_node *node)
struct ec_config * ec_config_list_first(struct ec_config *list)
struct ec_config * ec_config_bool(bool boolean)
ec_config_type
Definition: config.h:25
void ec_config_dump(FILE *out, const struct ec_config *config)
int ec_config_dict_set(struct ec_config *dict, const char *key, struct ec_config *value)
int ec_config_list_add(struct ec_config *list, struct ec_config *value)
struct ec_config * ec_config_dict_get(const struct ec_config *config, const char *key)
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema)
int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema)
struct ec_config * ec_config_i64(int64_t i64)
struct ec_config * ec_config_string(const char *string)
const struct ec_config_schema * ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key)
enum ec_config_type ec_config_get_type(const struct ec_config *config)
bool ec_config_key_is_reserved(const char *name)
struct ec_dict * ec_dict(void)
struct ec_node * ec_node(const char *typename, const char *id)