X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnet_setup.c;h=68b8ed7499d92209573e5aeb582bc991e753b0d4;hb=326a86ef927e1f161a6742edfca041a945c7a547;hp=190eafa3b53303402b764ef75143c9a0b80c53c4;hpb=1da7f28315be17a4ed854cdceb97a870f16a511e;p=meshlink diff --git a/src/net_setup.c b/src/net_setup.c index 190eafa3..68b8ed74 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -124,6 +124,61 @@ static bool read_invitation_key(meshlink_handle_t *mesh) { return mesh->invitation_key; } +bool node_read_dclass(meshlink_handle_t *mesh, node_t *n) { + if(n->dclass != 0) + return true; + + splay_tree_t *config_tree; + char *p; + + init_configuration(&config_tree); + if(!read_host_config(mesh, config_tree, n->name)) + goto exit; + + if(get_config_string(lookup_config(config_tree, "DeviceClass"), &p)) { + n->dclass = atoi(p); + free(p); + } + +exit: + exit_configuration(&config_tree); + return n->dclass != 0; +} + +bool node_write_dclass(meshlink_handle_t *mesh, node_t *n) { + + if(n->dclass == 0) + return false; + + bool result = false; + + splay_tree_t *config_tree; + init_configuration(&config_tree); + + // ignore read errors; in case the file does not exist we will create it + read_host_config(mesh, config_tree, n->name); + + config_t* cnf = lookup_config(config_tree, "DeviceClass"); + + if(!cnf) + { + cnf = new_config(); + cnf->variable = xstrdup("DeviceClass"); + config_add(config_tree, cnf); + } + + set_config_int(cnf, n->dclass); + + if(!write_host_config(mesh, config_tree, n->name)) + goto fail; + + result = true; + +fail: + exit_configuration(&config_tree); + return result; +} + void load_all_nodes(meshlink_handle_t *mesh) { DIR *dir; struct dirent *ent; @@ -146,6 +201,7 @@ void load_all_nodes(meshlink_handle_t *mesh) { n = new_node(); n->name = xstrdup(ent->d_name); + node_read_dclass(mesh, n); node_add(mesh, n); } @@ -276,6 +332,7 @@ bool setup_myself(meshlink_handle_t *mesh) { mesh->self = new_node(); mesh->self->connection = new_connection(); mesh->self->name = name; + mesh->self->dclass = mesh->dclass; mesh->self->connection->name = xstrdup(name); read_host_config(mesh, mesh->config, name);