Loading...
Searching...
No Matches
Node configuration

Configure nodes behavior through generic API. More...

## Data Structures

struct | ec_config_schema
| Structure describing the format of a configuration value. More...
struct | ec_config
| Structure storing the configuration data. More...

## Enumerations

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 }
| The type identifier for a config value. More...
enum | ec_config_flags { EC_CONFIG_F_MANDATORY = 1 << 0 }
| Flags related to a configuration schema. More...

## Functions

int | ec_config_schema_validate (const struct ec_config_schema *schema)
| Validate a configuration schema array.
void | ec_config_schema_dump (FILE *out, const struct ec_config_schema *schema, const char *name)
| Dump a configuration schema array.
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.
enum ec_config_type | ec_config_schema_type (const struct ec_config_schema *schema_elt)
| Get the type of a schema entry.
const struct ec_config_schema * | ec_config_schema_sub (const struct ec_config_schema *schema_elt)
| Get the subschema of a schema entry.
bool | ec_config_key_is_reserved (const char *name)
| Check if a key name is reserved in a config dict.
enum ec_config_type | ec_config_get_type (const struct ec_config *config)
| Get the type of the configuration.
struct ec_config * | ec_config_bool (bool boolean)
| Create a boolean configuration value.
struct ec_config * | ec_config_i64 (int64_t i64)
| Create a signed integer configuration value.
struct ec_config * | ec_config_u64 (uint64_t u64)
| Create an unsigned configuration value.
struct ec_config * | ec_config_string (const char *string)
| Create a string configuration value.
struct ec_config * | ec_config_node (struct ec_node *node)
| Create a node configuration value.
struct ec_config * | ec_config_dict (void)
| Create a hash table configuration value.
struct ec_config * | ec_config_list (void)
| Create a list configuration value.
int | ec_config_list_add (struct ec_config *list, struct ec_config *value)
| Add a config object into a list.
int | ec_config_list_del (struct ec_config *list, struct ec_config *config)
| Remove an element from a list.
ssize_t | ec_config_count (const struct ec_config *config)
| Count the number of elements in a list or dict.
int | ec_config_validate (const struct ec_config *dict, const struct ec_config_schema *schema)
| Validate a configuration.
int | ec_config_dict_set (struct ec_config *dict, const char *key, struct ec_config *value)
| Set a value in a hash table configuration.
int | ec_config_dict_del (struct ec_config *dict, const char *key)
| Remove an element from a hash table configuration.
int | ec_config_cmp (const struct ec_config *config1, const struct ec_config *config2)
| Compare two configurations.
struct ec_config * | ec_config_dict_get (const struct ec_config *config, const char *key)
| Get configuration value.
struct ec_config * | ec_config_list_first (struct ec_config *list)
| Get the first element of a list.
struct ec_config * | ec_config_list_next (struct ec_config *list, struct ec_config *config)
| Get next element in list.
void | ec_config_free (struct ec_config *config)
| Free a configuration.
struct ec_config * | ec_config_dup (const struct ec_config *config)
| Duplicate a configuration.
void | ec_config_dump (FILE *out, const struct ec_config *config)
| Dump a configuration.
struct ec_node ** | ec_node_config_node_list_to_table (const struct ec_config *config, size_t *len)
| Build a node table from a node list in an ec_config.
struct ec_config * | ec_node_config_node_list_from_vargs (va_list ap)
| Build a list of config nodes from variable arguments.

## Variables

const char * | ec_config_reserved_keys []
| Array of reserved key names.

## Detailed Description

Configure nodes behavior through generic API.

Helpers that are commonly used in nodes.

## Enumeration Type Documentation

## ec_config_type

enum ec_config_type

The type identifier for a config value.

Definition at line 25 of file config.h.

## ec_config_flags

enum ec_config_flags

Flags related to a configuration schema.

Definition at line 39 of file config.h.

## Function Documentation

## ec_config_schema_validate()

int ec_config_schema_validate | ( | const struct ec_config_schema * | schema | ) |

Validate a configuration schema array.

Parameters

  schema | Pointer to the first element of the schema array. The array must be terminated by a sentinel entry {.type = EC_CONFIG_TYPE_NONE}.

Returns
  0 if the schema is valid, or -1 on error (errno is set).

## 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.

Parameters

  out | Output stream on which the dump will be sent.
  schema | Pointer to the first element of the schema array. The array must be terminated by a sentinel entry {.type == EC_CONFIG_TYPE_NONE}.
  name | The name of the schema.

## 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.

Browse the schema array and look up the given key.

Parameters

  schema | Pointer to the first element of the schema array. The array must be terminated by a sentinel entry {.type == EC_CONFIG_TYPE_NONE}.
  key | Schema key name.

Returns
  The schema entry if it matches a key, or NULL if not found.

## 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.

Parameters

  schema_elt | Pointer to an element of the schema array.

Returns
  The type of the schema entry.

## 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.

Parameters

  schema_elt | Pointer to an element of the schema array.

Returns
  The subschema if any, or NULL.

## 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.

Some key names are reserved and should not be used in configs.

Parameters

  name | The name of the key to test.

Returns
  True if the key name is reserved and must not be used, else false.

## ec_config_get_type()

enum ec_config_type ec_config_get_type | ( | const struct ec_config * | config | ) |

Get the type of the configuration.

Parameters

  config | The configuration.

Returns
  The configuration type.

## ec_config_bool()

struct ec_config * ec_config_bool | ( | bool | boolean | ) |

Create a boolean configuration value.

Parameters

  boolean | The boolean value to be set.

Returns
  The configuration object, or NULL on error (errno is set).

## ec_config_i64()

struct ec_config * ec_config_i64 | ( | int64_t | i64 | ) |

Create a signed integer configuration value.

Parameters

  i64 | The signed integer value to be set.

Returns
  The configuration object, or NULL on error (errno is set).

## ec_config_u64()

struct ec_config * ec_config_u64 | ( | uint64_t | u64 | ) |

Create an unsigned configuration value.

Parameters

  u64 | The unsigned integer value to be set.

Returns
  The configuration object, or NULL on error (errno is set).

## ec_config_string()

struct ec_config * ec_config_string | ( | const char * | string | ) |

Create a string configuration value.

Parameters

  string | The string value to be set. The string is copied into the configuration object.

Returns
  The configuration object, or NULL on error (errno is set).

## ec_config_node()

struct ec_config * ec_config_node | ( | struct ec_node * | node | ) |

Create a node configuration value.

Parameters

  node | The node pointer to be set. The node is "consumed" by the function and should not be used by the caller, even on error. The caller can use ec_node_clone() to keep a reference on the node.

Returns
  The configuration object, or NULL on error (errno is set).

## ec_config_dict()

struct ec_config * ec_config_dict | ( | void |  | ) |

Create a hash table configuration value.

Returns
  A configuration object containing an empty hash table, or NULL on error (errno is set).

## ec_config_list()

struct ec_config * ec_config_list | ( | void |  | ) |

Create a list configuration value.

Returns
  The configuration object containing an empty list, or NULL on error (errno is set).

## ec_config_list_add()

int ec_config_list_add | ( | struct ec_config * | list,
|  | struct ec_config * | value )

Add a config object into a list.

Parameters

  list | The list configuration in which the value will be added.
  value | The value configuration to add in the list. The value object will be freed when freeing the list object. On error, the value object is also freed.

Returns
  0 on success, else -1 (errno is set).

## ec_config_list_del()

int ec_config_list_del | ( | struct ec_config * | list,
|  | struct ec_config * | config )

Remove an element from a list.

The element is freed and should not be accessed.

Parameters

  list | The list configuration.
  config | The element to remove from the list.

Returns
  0 on success, -1 on error (errno is set).

## ec_config_count()

ssize_t ec_config_count | ( | const struct ec_config * | config | ) |

Count the number of elements in a list or dict.

Parameters

  config | The configuration that must be a list or a dict.

Returns
  The number of elements, or -1 on error (errno is set).

## ec_config_validate()

int ec_config_validate | ( | const struct ec_config * | dict,
|  | const struct ec_config_schema * | schema )

Validate a configuration.

Parameters

  dict | A hash table configuration to validate.
  schema | Pointer to the first element of the schema array. The array must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE).

Returns
  0 on success, -1 on error (errno is set).

## 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.

Parameters

  dict | The hash table configuration.
  key | The key to update.
  value | The value to set. The value object will be freed when freeing the dict object. On error, the value object is also freed.

Returns
  0 on success, -1 on error (errno is set).

## ec_config_dict_del()

int ec_config_dict_del | ( | struct ec_config * | dict,
|  | const char * | key )

Remove an element from a hash table configuration.

The element is freed and should not be accessed.

Parameters

  dict | The hash table configuration.
  key | The key of the configuration to delete.

Returns
  0 on success, -1 on error (errno is set).

## ec_config_cmp()

int ec_config_cmp | ( | const struct ec_config * | value1,
|  | const struct ec_config * | value2 )

Compare two configurations.

Returns
  0 if the configurations are equal, else -1.

## ec_config_list_first()

struct ec_config * ec_config_list_first | ( | struct ec_config * | list | ) |

Get the first element of a list.

Example of use:

for (config = ec_config_list_first(list);
config != NULL;
config = ec_config_list_next(list, config)) {
...
}
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.

Parameters

  list | The list configuration to iterate.

Returns
  The first configuration element, or NULL on error (errno is set).

## ec_config_list_next()

struct ec_config * ec_config_list_next | ( | struct ec_config * | list,
|  | struct ec_config * | config )

Get next element in list.

Parameters

  list | The list configuration being iterated.
  config | The current configuration element.

Returns
  The next configuration element, or NULL if there is no more element.

## ec_config_free()

void ec_config_free | ( | struct ec_config * | config | ) |

Free a configuration.

Parameters

  config | The element to free.

## ec_config_dup()

struct ec_config * ec_config_dup | ( | const struct ec_config * | config | ) |

Duplicate a configuration.

Parameters

  config | The configuration to duplicate.

Returns
  The duplicated configuration, or NULL on error (errno is set).

## ec_config_dump()

void ec_config_dump | ( | FILE * | out,
|  | const struct ec_config * | config )

Dump a configuration.

Parameters

  out | Output stream on which the dump will be sent.
  config | The configuration to dump.

## ec_node_config_node_list_to_table()

struct ec_node ** ec_node_config_node_list_to_table | ( | const struct ec_config * | config,
|  | size_t * | len )

Build a node table from a node list in an ec_config.

The function takes a node configuration as parameter, which must be a node list. From it, a node table is built. A reference is taken for each node.

On error, no reference is taken.

Parameters

  config | The configuration (type must be a list of nodes). If it is NULL, an error is returned.
  len | The length of the allocated table on success, or 0 on error.

Returns
  The allocated node table, that must be freed by the caller: each entry must be freed with ec_node_free() and the table with free(). On error, NULL is returned and errno is set.

## ec_node_config_node_list_from_vargs()

struct ec_config * ec_node_config_node_list_from_vargs | ( | va_list | ap | ) |

Build a list of config nodes from variable arguments.

The va_list argument is a list of pointer to ec_node structures, terminated with EC_VA_END.

This helper is used by nodes that contain a list of nodes, like "seq", "or", ...

Parameters

  ap | List of pointer to ec_node structures, terminated with EC_VA_END.

Returns
  A pointer to an ec_config structure. In this case, the nodes will be freed when the config structure will be freed. On error, NULL is returned (and errno is set), and the nodes are freed.