X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fconf.c;h=c8cb141413a9629e82c0dcfd30caf4574f685b00;hb=e62fd508158749a0d55eae06c2e361df5d6da6e0;hp=a0107d0249d85414c9a535210f2036dcf2f83705;hpb=2c6b2d70e6640f39563ad7bb0aa0ba87f883848c;p=tinc diff --git a/src/conf.c b/src/conf.c index a0107d02..c8cb1414 100644 --- a/src/conf.c +++ b/src/conf.c @@ -4,7 +4,7 @@ 1998-2005 Ivo Timmermans 2000 Cris van Pelt 2010-2011 Julien Muchembled - 2000-2021 Guus Sliepen + 2000-2022 Guus Sliepen 2013 Florent Clairambault This program is free software; you can redistribute it and/or modify @@ -34,11 +34,16 @@ #include "protocol.h" #include "xalloc.h" -splay_tree_t *config_tree = NULL; - int pinginterval = 0; /* seconds between pings */ int pingtimeout = 0; /* seconds to wait for response */ -list_t *cmdline_conf = NULL; /* global/host configuration values given at the command line */ + +/* global/host configuration values given at the command line */ +list_t cmdline_conf = { + .head = NULL, + .tail = NULL, + .count = 0, + .delete = (list_action_t)free_config, +}; static int config_compare(const config_t *a, const config_t *b) { int result; @@ -65,8 +70,21 @@ static int config_compare(const config_t *a, const config_t *b) { } } -void init_configuration(splay_tree_t **config_tree) { - *config_tree = splay_alloc_tree((splay_compare_t) config_compare, (splay_action_t) free_config); +splay_tree_t config_tree = { + .compare = (splay_compare_t) config_compare, + .delete = (splay_action_t) free_config, +}; + +splay_tree_t *create_configuration(void) { + splay_tree_t *tree = splay_alloc_tree(NULL, NULL); + init_configuration(tree); + return tree; +} + +void init_configuration(splay_tree_t *tree) { + memset(tree, 0, sizeof(*tree)); + tree->compare = (splay_compare_t) config_compare; + tree->delete = (splay_action_t) free_config; } void exit_configuration(splay_tree_t **config_tree) { @@ -80,7 +98,7 @@ config_t *new_config(void) { void free_config(config_t *cfg) { free(cfg->variable); - free(cfg->value); + free_string(cfg->value); free(cfg->file); free(cfg); } @@ -89,14 +107,14 @@ void config_add(splay_tree_t *config_tree, config_t *cfg) { splay_insert(config_tree, cfg); } -config_t *lookup_config(splay_tree_t *config_tree, char *variable) { - config_t cfg, *found; - - cfg.variable = variable; - cfg.file = NULL; - cfg.line = 0; +config_t *lookup_config(splay_tree_t *config_tree, const char *variable) { + const config_t cfg = { + .variable = (char *)variable, + .file = NULL, + .line = 0, + }; - found = splay_search_closest_greater(config_tree, &cfg); + config_t *found = splay_search_closest_greater(config_tree, &cfg); if(!found) { return NULL; @@ -334,13 +352,9 @@ bool read_config_file(splay_tree_t *config_tree, const char *fname, bool verbose } void read_config_options(splay_tree_t *config_tree, const char *prefix) { - if(!cmdline_conf) { - return; - } - size_t prefix_len = prefix ? strlen(prefix) : 0; - for(const list_node_t *node = cmdline_conf->tail; node; node = node->prev) { + for(const list_node_t *node = cmdline_conf.tail; node; node = node->prev) { const config_t *cfg = node->data; config_t *new;