X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fconnection.c;h=408ef6c0fab827af40776a1cc67e74aa260e1fba;hb=fb0cfccf7dc2240b576011edcf74fd5b058916cb;hp=b6ce517e152cb69570c13c1a41f5f4320fb8daf4;hpb=3730156165fd1aa7c8810cd8e390aba6a8badcfa;p=tinc diff --git a/src/connection.c b/src/connection.c index b6ce517e..408ef6c0 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1,6 +1,6 @@ /* connection.c -- connection list management - Copyright (C) 2000-2006 Guus Sliepen , + Copyright (C) 2000-2007 Guus Sliepen , 2000-2005 Ivo Timmermans This program is free software; you can redistribute it and/or modify @@ -22,7 +22,7 @@ #include "system.h" -#include "avl_tree.h" +#include "splay_tree.h" #include "conf.h" #include "list.h" #include "logger.h" @@ -32,34 +32,30 @@ #include "utils.h" #include "xalloc.h" -avl_tree_t *connection_tree; /* Meta connections */ +splay_tree_t *connection_tree; /* Meta connections */ connection_t *broadcast; -static int connection_compare(const connection_t *a, const connection_t *b) -{ +static int connection_compare(const connection_t *a, const connection_t *b) { return (void *)a - (void *)b; } -void init_connections(void) -{ +void init_connections(void) { cp(); - connection_tree = avl_alloc_tree((avl_compare_t) connection_compare, (avl_action_t) free_connection); + connection_tree = splay_alloc_tree((splay_compare_t) connection_compare, (splay_action_t) free_connection); broadcast = new_connection(); broadcast->name = xstrdup(_("everyone")); broadcast->hostname = xstrdup(_("BROADCAST")); } -void exit_connections(void) -{ +void exit_connections(void) { cp(); - avl_delete_tree(connection_tree); + splay_delete_tree(connection_tree); free_connection(broadcast); } -connection_t *new_connection(void) -{ +connection_t *new_connection(void) { connection_t *c; cp(); @@ -75,13 +71,15 @@ connection_t *new_connection(void) return c; } -void free_connection(connection_t *c) -{ +void free_connection(connection_t *c) { cp(); if(!c) return; + if(c->name) + free(c->name); + if(c->hostname) free(c->hostname); @@ -101,23 +99,20 @@ void free_connection(connection_t *c) free(c); } -void connection_add(connection_t *c) -{ +void connection_add(connection_t *c) { cp(); - avl_insert(connection_tree, c); + splay_insert(connection_tree, c); } -void connection_del(connection_t *c) -{ +void connection_del(connection_t *c) { cp(); - avl_delete(connection_tree, c); + splay_delete(connection_tree, c); } -void dump_connections(void) -{ - avl_node_t *node; +void dump_connections(void) { + splay_node_t *node; connection_t *c; cp(); @@ -134,8 +129,7 @@ void dump_connections(void) logger(LOG_DEBUG, _("End of connections.")); } -bool read_connection_config(connection_t *c) -{ +bool read_connection_config(connection_t *c) { char *fname; int x;