/// Create a fresh configuration directory
bool config_init(meshlink_handle_t *mesh) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
if(mkdir(mesh->confbase, 0700) && errno != EEXIST) {
logger(mesh, MESHLINK_DEBUG, "Could not create directory %s: %s\n", mesh->confbase, strerror(errno));
return false;
/// Check the presence of the main configuration file.
bool main_config_exists(meshlink_handle_t *mesh) {
+ if(!mesh->confbase) {
+ return false;
+ }
+
char path[PATH_MAX];
make_main_path(mesh, path, sizeof(path));
/// Lock the main configuration file.
bool main_config_lock(meshlink_handle_t *mesh) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
char path[PATH_MAX];
make_main_path(mesh, path, sizeof(path));
/// Read a configuration file from a FILE handle.
bool config_read_file(meshlink_handle_t *mesh, FILE *f, config_t *config) {
+ if(!mesh->confbase) {
+ return false;
+ }
+
(void)mesh;
long len;
/// Write a configuration file to a FILE handle.
bool config_write_file(meshlink_handle_t *mesh, FILE *f, const config_t *config) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
if(mesh->config_key) {
uint8_t buf[config->len + 16];
size_t len = sizeof(buf);
/// Check the presence of a host configuration file.
bool config_exists(meshlink_handle_t *mesh, const char *name) {
+ if(!mesh->confbase) {
+ return false;
+ }
+
char path[PATH_MAX];
make_host_path(mesh, name, path, sizeof(path));
/// Read a host configuration file.
bool config_read(meshlink_handle_t *mesh, const char *name, config_t *config) {
+ if(!mesh->confbase) {
+ return false;
+ }
+
char path[PATH_MAX];
make_host_path(mesh, name, path, sizeof(path));
return true;
}
+void config_scan_all(meshlink_handle_t *mesh, config_scan_action_t action) {
+ if(!mesh->confbase) {
+ return;
+ }
+
+ DIR *dir;
+ struct dirent *ent;
+ char dname[PATH_MAX];
+ make_host_path(mesh, NULL, dname, sizeof(dname));
+
+ dir = opendir(dname);
+
+ if(!dir) {
+ logger(mesh, MESHLINK_ERROR, "Could not open %s: %s", dname, strerror(errno));
+ meshlink_errno = MESHLINK_ESTORAGE;
+ return;
+ }
+
+ while((ent = readdir(dir))) {
+ action(mesh, ent->d_name);
+ }
+
+ closedir(dir);
+}
+
/// Write a host configuration file.
bool config_write(meshlink_handle_t *mesh, const char *name, const config_t *config) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
char path[PATH_MAX];
make_host_path(mesh, name, path, sizeof(path));
/// Read the main configuration file.
bool main_config_read(meshlink_handle_t *mesh, config_t *config) {
+ if(!mesh->confbase) {
+ return false;
+ }
+
char path[PATH_MAX];
make_main_path(mesh, path, sizeof(path));
/// Write the main configuration file.
bool main_config_write(meshlink_handle_t *mesh, const config_t *config) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
char path[PATH_MAX];
make_main_path(mesh, path, sizeof(path));
/// Read an invitation file, and immediately delete it.
bool invitation_read(meshlink_handle_t *mesh, const char *name, config_t *config) {
+ if(!mesh->confbase) {
+ return false;
+ }
+
char path[PATH_MAX];
char used_path[PATH_MAX];
make_invitation_path(mesh, name, path, sizeof(path));
/// Write an invitation file.
bool invitation_write(meshlink_handle_t *mesh, const char *name, const config_t *config) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
char path[PATH_MAX];
make_invitation_path(mesh, name, path, sizeof(path));
/// Purge old invitation files
size_t invitation_purge_old(meshlink_handle_t *mesh, time_t deadline) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
char path[PATH_MAX];
make_invitation_path(mesh, "", path, sizeof(path));