Loading...
Searching...
No Matches
config.h
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/queue.h>
struct ec_config;
struct ec_dict;
enum ec_config_type {
EC_CONFIG_TYPE_NONE = 0,
EC_CONFIG_TYPE_BOOL,
EC_CONFIG_TYPE_INT64,
EC_CONFIG_TYPE_UINT64,
EC_CONFIG_TYPE_STRING,
EC_CONFIG_TYPE_NODE,
EC_CONFIG_TYPE_LIST,
EC_CONFIG_TYPE_DICT,
};
enum ec_config_flags {
EC_CONFIG_F_MANDATORY = 1 << 0,
};
struct ec_config_schema {
const char *key;
const char *desc;
enum ec_config_type type;
enum ec_config_flags flags;
const struct ec_config_schema *subschema;
};
TAILQ_HEAD(ec_config_list, ec_config);
struct ec_config {
enum ec_config_type type;
union {
bool boolean;
int64_t i64;
uint64_t u64;
char *string;
struct ec_node *node;
struct ec_dict *dict;
struct ec_config_list list;
};
TAILQ_ENTRY(ec_config) next;
};
int ec_config_schema_validate(const struct ec_config_schema *schema);
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema, const char *name);
const struct ec_config_schema *
ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key);
enum ec_config_type ec_config_schema_type(const struct ec_config_schema *schema_elt);
const struct ec_config_schema *ec_config_schema_sub(const struct ec_config_schema *schema_elt);
bool ec_config_key_is_reserved(const char *name);
extern const char *ec_config_reserved_keys[];
enum ec_config_type ec_config_get_type(const struct ec_config *config);
struct ec_config *ec_config_bool(bool boolean);
struct ec_config *ec_config_i64(int64_t i64);
struct ec_config *ec_config_u64(uint64_t u64);
struct ec_config *ec_config_string(const char *string);
struct ec_config *ec_config_node(struct ec_node *node);
struct ec_config *ec_config_dict(void);
struct ec_config *ec_config_list(void);
int ec_config_list_add(struct ec_config *list, struct ec_config *value);
int ec_config_list_del(struct ec_config *list, struct ec_config *config);
ssize_t ec_config_count(const struct ec_config *config);
int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema);
int ec_config_dict_set(struct ec_config *dict, const char *key, struct ec_config *value);
int ec_config_dict_del(struct ec_config *dict, const char *key);
int ec_config_cmp(const struct ec_config *config1, const struct ec_config *config2);
struct ec_config *ec_config_dict_get(const struct ec_config *config, const char *key);
struct ec_config *ec_config_list_first(struct ec_config *list);
struct ec_config *ec_config_list_next(struct ec_config *list, struct ec_config *config);
void ec_config_free(struct ec_config *config);
int ec_config_cmp(const struct ec_config *value1, const struct ec_config *value2);
struct ec_config *ec_config_dup(const struct ec_config *config);
void ec_config_dump(FILE *out, const struct ec_config *config);
ec_config_list_del
int ec_config_list_del(struct ec_config *list, struct ec_config *config)
Remove an element from a list.
ec_config_flags
ec_config_flags
Flags related to a configuration schema.
Definition config.h:39
ec_config_dup
struct ec_config * ec_config_dup(const struct ec_config *config)
Duplicate a configuration.
ec_config_schema_validate
int ec_config_schema_validate(const struct ec_config_schema *schema)
Validate a configuration schema array.
ec_config_list
struct ec_config * ec_config_list(void)
Create a list configuration value.
ec_config_schema_type
enum ec_config_type ec_config_schema_type(const struct ec_config_schema *schema_elt)
Get the type of a schema entry.
ec_config_cmp
int ec_config_cmp(const struct ec_config *config1, const struct ec_config *config2)
Compare two configurations.
ec_config_node
struct ec_config * ec_config_node(struct ec_node *node)
Create a node configuration value.
ec_config_dict_del
int ec_config_dict_del(struct ec_config *dict, const char *key)
Remove an element from a hash table configuration.
ec_config_schema_sub
const struct ec_config_schema * ec_config_schema_sub(const struct ec_config_schema *schema_elt)
Get the subschema of a schema entry.
ec_config_schema_dump
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema, const char *name)
Dump a configuration schema array.
ec_config_free
void ec_config_free(struct ec_config *config)
Free a configuration.
ec_config_count
ssize_t ec_config_count(const struct ec_config *config)
Count the number of elements in a list or dict.
ec_config_reserved_keys
const char * ec_config_reserved_keys[]
Array of reserved key names.
ec_config_schema_lookup
const struct ec_config_schema * ec_config_schema_lookup(const struct ec_config_schema *schema, const char *key)
Find a schema entry matching the key.
ec_config_type
ec_config_type
The type identifier for a config value.
Definition config.h:25
ec_config_dump
void ec_config_dump(FILE *out, const struct ec_config *config)
Dump a configuration.
ec_config_dict_set
int ec_config_dict_set(struct ec_config *dict, const char *key, struct ec_config *value)
Set a value in a hash table configuration.
ec_config_dict_get
struct ec_config * ec_config_dict_get(const struct ec_config *config, const char *key)
Get configuration value.
ec_config_dict
struct ec_config * ec_config_dict(void)
Create a hash table configuration value.
ec_config_list_add
int ec_config_list_add(struct ec_config *list, struct ec_config *value)
Add a config object into a list.
ec_config_validate
int ec_config_validate(const struct ec_config *dict, const struct ec_config_schema *schema)
Validate a configuration.
ec_config_list_next
struct ec_config * ec_config_list_next(struct ec_config *list, struct ec_config *config)
Get next element in list.
ec_config_list_first
struct ec_config * ec_config_list_first(struct ec_config *list)
Get the first element of a list.
ec_config_i64
struct ec_config * ec_config_i64(int64_t i64)
Create a signed integer configuration value.
ec_config_bool
struct ec_config * ec_config_bool(bool boolean)
Create a boolean configuration value.
ec_config_get_type
enum ec_config_type ec_config_get_type(const struct ec_config *config)
Get the type of the configuration.
ec_config_u64
struct ec_config * ec_config_u64(uint64_t u64)
Create an unsigned configuration value.
ec_config_string
struct ec_config * ec_config_string(const char *string)
Create a string configuration value.
ec_config_key_is_reserved
bool ec_config_key_is_reserved(const char *name)
Check if a key name is reserved in a config dict.
ec_dict
struct ec_dict * ec_dict(void)
Create a hash table.
ec_node
struct ec_node * ec_node(const char *typename, const char *id)
Create a new node from its type name.
ec_config_schema
Structure describing the format of a configuration value.
Definition config.h:50
ec_config_schema::flags
enum ec_config_flags flags
Flags, see ec_config_flags.
Definition config.h:54
ec_config
Structure storing the configuration data.
Definition config.h:66