X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fconf.c;h=a40fdfa836af48b15973d1034c657d389b9e7415;hb=28b7a53b6;hp=90bd3697b9f0ae46b2af7fc63d34a6ec1a8e2262;hpb=0871c3095151bce6a4031a2662aa51b7193b855c;p=tinc diff --git a/src/conf.c b/src/conf.c index 90bd3697..a40fdfa8 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,8 +34,6 @@ #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 */ @@ -72,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) { @@ -96,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;