We don't have to tell GCC how to cast.
[tinc] / src / edge.c
index f9d4d98..bf43d30 100644 (file)
@@ -1,7 +1,7 @@
 /*
     edge.c -- edge tree management
-    Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.eu.org>,
-                  2000-2002 Ivo Timmermans <ivo@o2w.nl>
+    Copyright (C) 2000-2003 Guus Sliepen <guus@sliepen.eu.org>,
+                  2000-2003 Ivo Timmermans <ivo@o2w.nl>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: edge.c,v 1.1.2.19 2003/07/06 22:11:31 guus Exp $
+    $Id: edge.c,v 1.1.2.27 2003/08/28 21:05:10 guus Exp $
 */
 
-#include "config.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include <avl_tree.h>
-#include <list.h>
+#include "system.h"
 
-#include "net.h"                               /* Don't ask. */
-#include "netutl.h"
-#include "conf.h"
-#include <utils.h>
-#include "subnet.h"
+#include "avl_tree.h"
 #include "edge.h"
-#include "node.h"
 #include "logger.h"
-
+#include "netutl.h"
+#include "node.h"
+#include "utils.h"
 #include "xalloc.h"
-#include "system.h"
 
 avl_tree_t *edge_weight_tree;  /* Tree with all edges, sorted on weight */
 
-int edge_compare(edge_t *a, edge_t *b)
+static int edge_compare(const edge_t *a, const edge_t *b)
 {
        return strcmp(a->to->name, b->to->name);
 }
 
-int edge_weight_compare(edge_t *a, edge_t *b)
+static int edge_weight_compare(const edge_t *a, const edge_t *b)
 {
        int result;
 
@@ -68,15 +58,14 @@ void init_edges(void)
 {
        cp();
 
-       edge_weight_tree =
-               avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL);
+       edge_weight_tree = avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL);
 }
 
 avl_tree_t *new_edge_tree(void)
 {
        cp();
 
-       return avl_alloc_tree((avl_compare_t) edge_compare, NULL);
+       return avl_alloc_tree((avl_compare_t) edge_compare, (avl_action_t) free_edge);
 }
 
 void free_edge_tree(avl_tree_t *edge_tree)
@@ -99,12 +88,14 @@ edge_t *new_edge(void)
 {
        cp();
 
-       return (edge_t *) xmalloc_and_zero(sizeof(edge_t));
+       return xmalloc_and_zero(sizeof(edge_t));
 }
 
 void free_edge(edge_t *e)
 {
        cp();
+       
+       sockaddrfree(&e->address);
 
        free(e);
 }
@@ -129,14 +120,14 @@ void edge_del(edge_t *e)
        if(e->reverse)
                e->reverse->reverse = NULL;
 
-       avl_delete(e->from->edge_tree, e);
        avl_delete(edge_weight_tree, e);
+       avl_delete(e->from->edge_tree, e);
 }
 
 edge_t *lookup_edge(node_t *from, node_t *to)
 {
        edge_t v;
-
+       
        cp();
 
        v.from = from;
@@ -154,18 +145,18 @@ void dump_edges(void)
 
        cp();
 
-       logger(DEBUG_ALWAYS, LOG_DEBUG, _("Edges:"));
+       logger(LOG_DEBUG, _("Edges:"));
 
        for(node = node_tree->head; node; node = node->next) {
-               n = (node_t *) node->data;
+               n = node->data;
                for(node2 = n->edge_tree->head; node2; node2 = node2->next) {
-                       e = (edge_t *) node2->data;
+                       e = node2->data;
                        address = sockaddr2hostname(&e->address);
-                       logger(DEBUG_ALWAYS, LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
+                       logger(LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
                                   e->from->name, e->to->name, address, e->options, e->weight);
                        free(address);
                }
        }
 
-       logger(DEBUG_ALWAYS, LOG_DEBUG, _("End of edges."));
+       logger(LOG_DEBUG, _("End of edges."));
 }