From: Guus Sliepen Date: Sat, 26 Apr 2014 08:00:37 +0000 (+0200) Subject: Stop using global variable mesh in conf.[ch]. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=d959cb6c3232507db9ef0cb0873a934255e70bf0;p=meshlink Stop using global variable mesh in conf.[ch]. --- diff --git a/src/conf.c b/src/conf.c index ed51fc75..a53db046 100644 --- a/src/conf.c +++ b/src/conf.c @@ -290,7 +290,7 @@ bool read_config_file(splay_tree_t *config_tree, const char *fname) { return result; } -bool read_server_config(void) { +bool read_server_config(meshlink_handle_t *mesh) { char filename[PATH_MAX]; bool x; @@ -304,7 +304,7 @@ bool read_server_config(void) { return x; } -bool read_host_config(splay_tree_t *config_tree, const char *name) { +bool read_host_config(meshlink_handle_t *mesh, splay_tree_t *config_tree, const char *name) { char filename[PATH_MAX]; bool x; @@ -314,7 +314,7 @@ bool read_host_config(splay_tree_t *config_tree, const char *name) { return x; } -bool append_config_file(const char *name, const char *key, const char *value) { +bool append_config_file(meshlink_handle_t *mesh, const char *name, const char *key, const char *value) { char filename[PATH_MAX]; snprintf(filename,PATH_MAX, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name); diff --git a/src/conf.h b/src/conf.h index 39eb056c..b7d8cb2b 100644 --- a/src/conf.h +++ b/src/conf.h @@ -20,8 +20,9 @@ #ifndef __TINC_CONF_H__ #define __TINC_CONF_H__ -#include "splay_tree.h" #include "list.h" +#include "meshlink_internal.h" +#include "splay_tree.h" typedef struct config_t { char *variable; @@ -30,7 +31,6 @@ typedef struct config_t { int line; } config_t; - extern void init_configuration(struct splay_tree_t **); extern void exit_configuration(struct splay_tree_t **); extern config_t *new_config(void) __attribute__ ((__malloc__)); @@ -45,9 +45,9 @@ extern bool get_config_address(const config_t *, struct addrinfo **); extern config_t *parse_config_line(char *, const char *, int); extern bool read_config_file(struct splay_tree_t *, const char *); -extern void read_config_options(struct splay_tree_t *, const char *); -extern bool read_server_config(void); -extern bool read_host_config(struct splay_tree_t *, const char *); -extern bool append_config_file(const char *, const char *, const char *); + +extern bool read_server_config(struct meshlink_handle *mesh); +extern bool read_host_config(struct meshlink_handle *mesh, struct splay_tree_t *, const char *); +extern bool append_config_file(struct meshlink_handle *mesh, const char *, const char *, const char *); #endif /* __TINC_CONF_H__ */ diff --git a/src/meshlink.c b/src/meshlink.c index f018bd02..6f4bff4f 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -237,7 +237,7 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { init_configuration(&mesh->config); - if(!read_server_config()) + if(!read_server_config(mesh)) return meshlink_close(mesh), NULL; // Setup up everything diff --git a/src/net.c b/src/net.c index 878a2f99..0f5908e0 100644 --- a/src/net.c +++ b/src/net.c @@ -276,7 +276,7 @@ int reload_configuration(void) { exit_configuration(&mesh->config); init_configuration(&mesh->config); - if(!read_server_config()) { + if(!read_server_config(mesh)) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to reread configuration file."); return EINVAL; } diff --git a/src/net_setup.c b/src/net_setup.c index ba17b099..5390d804 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -42,7 +42,7 @@ bool node_read_ecdsa_public_key(node_t *n) { char *p; init_configuration(&config_tree); - if(!read_host_config(config_tree, n->name)) + if(!read_host_config(mesh, config_tree, n->name)) goto exit; /* First, check for simple ECDSAPublicKey statement */ @@ -65,7 +65,7 @@ bool read_ecdsa_public_key(connection_t *c) { if(!c->config_tree) { init_configuration(&c->config_tree); - if(!read_host_config(c->config_tree, c->name)) + if(!read_host_config(mesh, c->config_tree, c->name)) return false; } @@ -278,7 +278,7 @@ bool setup_myself(void) { mesh->self->connection = new_connection(); mesh->self->name = name; mesh->self->connection->name = xstrdup(name); - read_host_config(mesh->config, name); + read_host_config(mesh, mesh->config, name); if(!get_config_string(lookup_config(mesh->config, "Port"), &mesh->myport)) mesh->myport = xstrdup("655"); diff --git a/src/net_socket.c b/src/net_socket.c index 84985587..84270499 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -515,7 +515,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) { } init_configuration(&outgoing->config_tree); - read_host_config(outgoing->config_tree, outgoing->name); + read_host_config(mesh, outgoing->config_tree, outgoing->name); outgoing->cfg = lookup_config(outgoing->config_tree, "Address"); if(!outgoing->cfg) { diff --git a/src/protocol_auth.c b/src/protocol_auth.c index fa71874f..7864ee58 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -317,7 +317,7 @@ bool id_h(connection_t *c, const char *request) { if(!c->config_tree) { init_configuration(&c->config_tree); - if(!read_host_config(c->config_tree, c->name)) { + if(!read_host_config(mesh, c->config_tree, c->name)) { logger(DEBUG_ALWAYS, LOG_ERR, "Peer %s had unknown identity (%s)", c->hostname, c->name); return false; } diff --git a/src/protocol_key.c b/src/protocol_key.c index 887ccd0d..6ffc7ce9 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -123,7 +123,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in } logger(DEBUG_PROTOCOL, LOG_INFO, "Learned ECDSA public key from %s (%s)", from->name, from->hostname); - append_config_file(from->name, "ECDSAPublicKey", pubkey); + append_config_file(mesh, from->name, "ECDSAPublicKey", pubkey); return true; }