2 connection.c -- connection list management
3 Copyright (C) 2000 Guus Sliepen <guus@sliepen.warande.net>,
4 2000 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: connection.c,v 1.1.2.1 2000/11/20 19:12:11 guus Exp $
30 #include "net.h" /* Don't ask. */
39 /* Root of the connection list */
41 rbltree_t *connection_tree;
42 connection_t *myself = NULL;
44 /* Initialization and callbacks */
46 int connection_compare(connection_t *a, connection_t *b)
48 return strcmp(a->name, b->name);
51 void init_connections(void)
53 connection_tree = new_rbltree((rbl_compare_t)connection_compare, (rbl_action_t)free_connection);
56 /* Creation and deletion of connection elements */
58 connection_t *new_connection(void)
60 connection_t *p = (connection_t *)xmalloc(sizeof(*p));
62 /* initialise all those stupid pointers at once */
63 memset(p, '\0', sizeof(*p));
68 void free_connection(connection_t *p)
75 if(p->name && p->name!=unknown)
82 free(p->cipher_pktkey);
86 clear_config(&p->config);
92 remove all marked connections
94 void prune_connection_tree(void)
99 RBL_FOREACH(connection_tree, rbl)
101 cl = (connection_t *) rbl->data;
102 if(cl->status.remove)
109 free all elements of connection
111 void destroy_connection_tree(void)
114 rbl_delete_rbltree(connection_tree);
118 /* Linked list management */
120 void connection_add(connection_t *cl)
123 rbl_insert(connection_tree, cl);
127 void connection_del(connection_t *cl)
130 rbl_delete(connection_tree, cl);
134 /* Lookup functions */
136 connection_t *lookup_id(char *name)
141 return rbl_search(connection_tree, &cl);
147 void dump_connection_list(void)
152 syslog(LOG_DEBUG, _("Connection list:"));
154 syslog(LOG_DEBUG, _(" %s at %s port %hd flags %d sockets %d, %d status %04x"),
155 myself->name, myself->hostname, myself->port, myself->flags,
156 myself->socket, myself->meta_socket, myself->status);
158 RBL_FOREACH(connection_tree, rbl)
160 cl = (connection_t *)rbl->data;
161 syslog(LOG_DEBUG, _(" %s at %s port %hd flags %d sockets %d, %d status %04x"),
162 cl->name, cl->hostname, cl->port, cl->flags,
163 cl->socket, cl->meta_socket, cl->status);
166 syslog(LOG_DEBUG, _("End of connection list."));
170 int read_host_config(connection_t *cl)
175 asprintf(&fname, "%s/hosts/%s", confbase, cl->name);
176 x = read_config_file(&cl->config, fname);