#include "system.h"
#include "avl_tree.h"
+#include "connection.h"
#include "conf.h"
#include "logger.h"
#include "netutl.h" /* for str2address */
return result;
}
-bool read_server_config() {
+void read_config_options(avl_tree_t *config_tree, const char *prefix) {
list_node_t *node, *next;
- char *fname;
- bool x;
+ size_t prefix_len = strlen(prefix);
for(node = cmdline_conf->tail; node; node = next) {
config_t *cfg = (config_t *)node->data;
next = node->prev;
- if (!strchr(cfg->variable, '.')) {
- config_add(config_tree, cfg);
- node->data = NULL;
- list_unlink_node(cmdline_conf, node);
- }
+
+ if(!prefix && strchr(cfg->variable, '.'))
+ continue;
+
+ if(prefix && (strncmp(prefix, cfg->variable, prefix_len) || cfg->variable[prefix_len] != '.'))
+ continue;
+
+ config_add(config_tree, cfg);
+ node->data = NULL;
+ list_unlink_node(cmdline_conf, node);
}
+}
+
+bool read_server_config() {
+ list_node_t *node, *next;
+ char *fname;
+ bool x;
+
+ read_config_options(config_tree, NULL);
xasprintf(&fname, "%s/tinc.conf", confbase);
x = read_config_file(config_tree, fname);
return x;
}
+bool read_connection_config(connection_t *c) {
+ list_node_t *node, *next;
+ size_t name_len = strlen(c->name);
+ char *fname;
+ bool x;
+
+ read_config_options(c->config_tree, c->name);
+
+ xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
+ x = read_config_file(c->config_tree, fname);
+ free(fname);
+
+ return x;
+}
+
FILE *ask_and_open(const char *filename, const char *what) {
FILE *r;
char *directory;