Libecoli 0.10.1
Extensible COmmand LIne library
Loading...
Searching...
No Matches
config.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
3 */
4
11
12#pragma once
13
14#include <stdbool.h>
15#include <stdint.h>
16#include <stdio.h>
17#include <sys/queue.h>
18
19struct ec_config;
20struct 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
40 EC_CONFIG_F_MANDATORY = 1 << 0,
41};
42
51 const char *key;
52 const char *desc;
53 enum ec_config_type type;
55
58 const struct ec_config_schema *subschema;
59};
60
61TAILQ_HEAD(ec_config_list, ec_config);
62
66struct ec_config {
68 enum ec_config_type type;
69
70 union {
71 bool boolean;
72 int64_t i64;
73 uint64_t u64;
74 char *string;
75 struct ec_node *node;
76 struct ec_dict *dict;
77 struct ec_config_list list;
78 };
79
83 TAILQ_ENTRY(ec_config) next;
84};
85
86/* schema */
87
98
110void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema, const char *name);
111
125const struct ec_config_schema *
126ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key);
127
137
146const struct ec_config_schema *ec_config_schema_sub(const struct ec_config_schema *schema_elt);
147
158bool ec_config_key_is_reserved(const char *name);
159
163extern const char *ec_config_reserved_keys[];
164
165/* config */
166
175enum ec_config_type ec_config_get_type(const struct ec_config *config);
176
185struct ec_config *ec_config_bool(bool boolean);
186
195struct ec_config *ec_config_i64(int64_t i64);
196
205struct ec_config *ec_config_u64(uint64_t u64);
206
216struct ec_config *ec_config_string(const char *string);
217
229struct ec_config *ec_config_node(struct ec_node *node);
230
239
248
261int ec_config_list_add(struct ec_config *list, struct ec_config *value);
262
275int ec_config_list_del(struct ec_config *list, struct ec_config *config);
276
285ssize_t ec_config_count(const struct ec_config *config);
286
298int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema);
299
313int ec_config_dict_set(struct ec_config *dict, const char *key, struct ec_config *value);
314
327int ec_config_dict_del(struct ec_config *dict, const char *key);
328
332int ec_config_cmp(const struct ec_config *config1, const struct ec_config *config2);
333
337struct ec_config *ec_config_dict_get(const struct ec_config *config, const char *key);
338
356
367struct ec_config *ec_config_list_next(struct ec_config *list, struct ec_config *config);
368
375void ec_config_free(struct ec_config *config);
376
383int ec_config_cmp(const struct ec_config *value1, const struct ec_config *value2);
384
393struct ec_config *ec_config_dup(const struct ec_config *config);
394
403void ec_config_dump(FILE *out, const struct ec_config *config);
404
int ec_config_list_del(struct ec_config *list, struct ec_config *config)
ec_config_flags
Definition config.h:39
struct ec_config * ec_config_dup(const struct ec_config *config)
int ec_config_schema_validate(const struct ec_config_schema *schema)
struct ec_config * ec_config_list(void)
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)
struct ec_config * ec_config_node(struct ec_node *node)
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)
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema, const char *name)
void ec_config_free(struct ec_config *config)
ssize_t ec_config_count(const struct ec_config *config)
const char * ec_config_reserved_keys[]
const struct ec_config_schema * ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key)
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)
struct ec_config * ec_config_dict_get(const struct ec_config *config, const char *key)
struct ec_config * ec_config_dict(void)
int ec_config_list_add(struct ec_config *list, struct ec_config *value)
int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema)
struct ec_config * ec_config_list_next(struct ec_config *list, struct ec_config *config)
struct ec_config * ec_config_list_first(struct ec_config *list)
struct ec_config * ec_config_i64(int64_t i64)
struct ec_config * ec_config_bool(bool boolean)
enum ec_config_type ec_config_get_type(const struct ec_config *config)
struct ec_config * ec_config_u64(uint64_t u64)
struct ec_config * ec_config_string(const char *string)
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)
enum ec_config_flags flags
Definition config.h:54