2 connlist.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: connlist.c,v 1.1.2.15 2000/11/04 22:57:30 guus Exp $
28 #include "net.h" /* Don't ask. */
37 /* Root of the connection list */
39 conn_list_t *conn_list = NULL;
40 conn_list_t *myself = NULL;
42 /* Creation and deletion of conn_list elements */
44 conn_list_t *new_conn_list(void)
46 conn_list_t *p = (conn_list_t *)xmalloc(sizeof(*p));
48 /* initialise all those stupid pointers at once */
49 memset(p, '\0', sizeof(*p));
54 void free_conn_list(conn_list_t *p)
61 if(p->name && p->name!=unknown)
68 free(p->cipher_pktkey);
72 clear_config(&p->config);
78 remove all marked connections
80 void prune_conn_list(void)
82 conn_list_t *p, *prev = NULL, *next = NULL;
84 for(p = conn_list; p != NULL; )
99 free all elements of conn_list
101 void destroy_conn_list(void)
103 conn_list_t *p, *next;
105 for(p = conn_list; p != NULL; )
116 /* Linked list management */
118 void conn_list_add(conn_list_t *cl)
121 cl->next = conn_list;
131 void conn_list_del(conn_list_t *cl)
135 cl->prev->next = cl->next;
137 conn_list = cl->next;
140 cl->next->prev = cl->prev;
146 /* Lookup functions */
148 conn_list_t *lookup_id(char *name)
152 for(p = conn_list; p != NULL; p = p->next)
154 if(strcmp(name, p->name) == 0)
162 void dump_conn_list(void)
166 syslog(LOG_DEBUG, _("Connection list:"));
168 syslog(LOG_DEBUG, _(" %s at %s port %hd flags %d sockets %d, %d status %04x"),
169 myself->name, myself->hostname, myself->port, myself->flags,
170 myself->socket, myself->meta_socket, myself->status);
172 for(p = conn_list; p != NULL; p = p->next)
174 syslog(LOG_DEBUG, _(" %s at %s port %hd flags %d sockets %d, %d status %04x"),
175 p->name, p->hostname, p->port, p->flags,
176 p->socket, p->meta_socket, p->status);
179 syslog(LOG_DEBUG, _("End of connection list."));
183 int read_host_config(conn_list_t *cl)
188 asprintf(&fname, "%s/hosts/%s", confbase, cl->name);
189 x = read_config_file(&cl->config, fname);