2 node.c -- node tree management
3 Copyright (C) 2001 Guus Sliepen <guus@sliepen.warande.net>,
4 2001 Ivo Timmermans <itimmermans@bigfoot.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: node.c,v 1.1.2.1 2001/10/10 08:49:47 guus Exp $
23 avl_tree_t *node_tree; /* Known nodes, sorted by name */
25 int node_compare(connection_t *a, connection_t *b)
27 return strcmp(a->name, b->name);
33 node_tree = avl_alloc_tree((avl_compare_t)node_compare, NULL);
40 avl_delete_tree(node_tree);
44 node_t *new_node(void)
46 node_t *n = (node_t *)xmalloc_and_zero(sizeof(*n));
48 n->subnet_tree = avl_alloc_tree((avl_compare_t)subnet_compare, NULL);
49 n->queue = list_alloc((list_action_t)free);
54 void free_node(node_t *n)
58 list_delete_list(n->queue);
66 clear_config(&n->config);
71 node_t *lookup_node(char *name)
76 return avl_search(node_tree, &n);
80 int read_host_config(nodet *n)
85 asprintf(&fname, "%s/hosts/%s", confbase, n->name);
86 x = read_config_file(&n->config, fname);
97 syslog(LOG_DEBUG, _("Nodes:"));
99 for(node = node_tree->head; node; node = node->next)
101 n = (connection_t *)node->data;
102 syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld sockets %d, %d status %04x"),
103 n->name, n->hostname, n->port, n->options,
104 n->socket, n->meta_socket, n->status);
107 syslog(LOG_DEBUG, _("End of nodes."));