]> git.meshlink.io Git - meshlink/blob - src/connection.c
Remove everything GPL that is not copyright Guus Sliepen, update copyright statements.
[meshlink] / src / connection.c
1 /*
2     connection.c -- connection list management
3     Copyright (C) 2000-2013 Guus Sliepen <guus@meshlink.io>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "system.h"
21
22 #include "list.h"
23 #include "cipher.h"
24 #include "conf.h"
25 #include "connection.h"
26 #include "list.h"
27 #include "logger.h"
28 #include "rsa.h"
29 #include "utils.h"
30 #include "xalloc.h"
31
32 list_t *connection_list;
33 connection_t *everyone;
34
35 void init_connections(void) {
36         connection_list = list_alloc((list_action_t) free_connection);
37         everyone = new_connection();
38         everyone->name = xstrdup("everyone");
39         everyone->hostname = xstrdup("BROADCAST");
40 }
41
42 void exit_connections(void) {
43         list_delete_list(connection_list);
44         free_connection(everyone);
45 }
46
47 connection_t *new_connection(void) {
48         return xzalloc(sizeof(connection_t));
49 }
50
51 void free_connection(connection_t *c) {
52         if(!c)
53                 return;
54
55         cipher_close(c->incipher);
56         digest_close(c->indigest);
57         cipher_close(c->outcipher);
58         digest_close(c->outdigest);
59
60         sptps_stop(&c->sptps);
61         ecdsa_free(c->ecdsa);
62         rsa_free(c->rsa);
63
64         free(c->hischallenge);
65
66         buffer_clear(&c->inbuf);
67         buffer_clear(&c->outbuf);
68
69         io_del(&c->io);
70
71         if(c->socket > 0)
72                 closesocket(c->socket);
73
74         free(c->name);
75         free(c->hostname);
76
77         if(c->config_tree)
78                 exit_configuration(&c->config_tree);
79
80         free(c);
81 }
82
83 void connection_add(connection_t *c) {
84         list_insert_tail(connection_list, c);
85 }
86
87 void connection_del(connection_t *c) {
88         list_delete(connection_list, c);
89 }