2018-01-25 16:24:33 +00:00
|
|
|
#ifndef LLARP_CONFIG_H_
|
|
|
|
#define LLARP_CONFIG_H_
|
|
|
|
|
2018-07-27 04:25:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-07-27 04:25:34 +00:00
|
|
|
#endif
|
|
|
|
/**
|
|
|
|
* config.h
|
|
|
|
*
|
|
|
|
* library configuration utilties
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct llarp_config;
|
|
|
|
|
|
|
|
/// allocate config
|
|
|
|
void
|
|
|
|
llarp_new_config(struct llarp_config **conf);
|
|
|
|
|
|
|
|
/// deallocate config
|
|
|
|
void
|
|
|
|
llarp_free_config(struct llarp_config **conf);
|
|
|
|
|
|
|
|
/// @brief return -1 on fail otherwiwse 0
|
|
|
|
int
|
|
|
|
llarp_load_config(struct llarp_config *conf, const char *fname);
|
|
|
|
|
|
|
|
/// config iterator configuration
|
|
|
|
struct llarp_config_iterator
|
|
|
|
{
|
|
|
|
/// a customizable pointer to pass data to iteration functor
|
|
|
|
void *user;
|
|
|
|
/// set by llarp_config_iter
|
|
|
|
struct llarp_config *conf;
|
|
|
|
/// visit (self, section, key, value)
|
|
|
|
void (*visit)(struct llarp_config_iterator *, const char *, const char *,
|
|
|
|
const char *);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// iterator over "conf" and call visit functor defined in "iter"
|
|
|
|
void
|
|
|
|
llarp_config_iter(struct llarp_config *conf,
|
|
|
|
struct llarp_config_iterator *iter);
|
|
|
|
|
|
|
|
/// ensure configuration exists
|
2018-09-19 13:02:55 +00:00
|
|
|
/// populate with defaults
|
2018-07-27 04:25:34 +00:00
|
|
|
/// return if this succeeded
|
2018-09-19 13:02:55 +00:00
|
|
|
/// if overwrite is true then overwrite old config file
|
|
|
|
/// if basedir is not nullptr then use basedir as an absolute
|
|
|
|
/// base path for all files in config
|
2018-07-27 04:25:34 +00:00
|
|
|
bool
|
2018-09-19 13:02:55 +00:00
|
|
|
llarp_ensure_config(const char *fname, const char *basedir = nullptr,
|
|
|
|
bool overwrite = false);
|
2018-07-27 04:25:34 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-25 16:24:33 +00:00
|
|
|
#endif
|