2018-01-25 16:24:33 +00:00
|
|
|
#ifndef LLARP_CONFIG_H_
|
|
|
|
#define LLARP_CONFIG_H_
|
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/**
|
|
|
|
* config.h
|
|
|
|
*
|
|
|
|
* library configuration utilties
|
|
|
|
*/
|
|
|
|
|
2018-01-29 14:27:24 +00:00
|
|
|
struct llarp_config;
|
2018-01-25 16:24:33 +00:00
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/// allocate config
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_new_config(struct llarp_config **conf);
|
2018-05-25 09:17:08 +00:00
|
|
|
|
|
|
|
/// deallocate config
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_free_config(struct llarp_config **conf);
|
2018-01-25 16:24:33 +00:00
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/// @brief return -1 on fail otherwiwse 0
|
2018-05-22 15:54:19 +00:00
|
|
|
int
|
|
|
|
llarp_load_config(struct llarp_config *conf, const char *fname);
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/// config iterator configuration
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_config_iterator
|
|
|
|
{
|
2018-05-25 09:17:08 +00:00
|
|
|
/// a customizable pointer to pass data to iteration functor
|
2018-01-29 14:27:24 +00:00
|
|
|
void *user;
|
2018-05-25 09:17:08 +00:00
|
|
|
/// set by llarp_config_iter
|
2018-01-29 14:27:24 +00:00
|
|
|
struct llarp_config *conf;
|
2018-05-25 09:17:08 +00:00
|
|
|
/// visit (self, section, key, value)
|
2018-01-29 14:27:24 +00:00
|
|
|
void (*visit)(struct llarp_config_iterator *, const char *, const char *,
|
|
|
|
const char *);
|
|
|
|
};
|
|
|
|
|
2018-05-25 09:17:08 +00:00
|
|
|
/// iterator over "conf" and call visit functor defined in "iter"
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_config_iter(struct llarp_config *conf,
|
|
|
|
struct llarp_config_iterator *iter);
|
2018-01-25 16:24:33 +00:00
|
|
|
|
2018-07-27 00:21:57 +00:00
|
|
|
/// ensure configuration exists
|
|
|
|
/// populate with defaults if it does not exist
|
|
|
|
/// return if this succeeded
|
|
|
|
bool
|
|
|
|
llarp_ensure_config(const char *fname);
|
|
|
|
|
2018-01-25 16:24:33 +00:00
|
|
|
#endif
|