2001-10-10 08:49:47 +00:00
|
|
|
/*
|
2001-10-28 08:41:19 +00:00
|
|
|
edge.c -- edge tree management
|
2001-10-10 08:49:47 +00:00
|
|
|
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
|
|
|
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
$Id: edge.c,v 1.1.2.1 2001/10/28 08:41:19 guus Exp $
|
2001-10-10 08:49:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <avl_tree.h>
|
|
|
|
#include <list.h>
|
|
|
|
|
|
|
|
#include "net.h" /* Don't ask. */
|
|
|
|
#include "netutl.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "conf.h"
|
|
|
|
#include <utils.h>
|
|
|
|
#include "subnet.h"
|
|
|
|
|
|
|
|
#include "xalloc.h"
|
|
|
|
#include "system.h"
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
avl_tree_t *edge_tree; /* Tree with all known vertices (replaces active_tree) */
|
2001-10-10 08:49:47 +00:00
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
int edge_compare(edge_t *a, edge_t *b)
|
2001-10-10 08:49:47 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = strcmp(a->from->name, b->from->name);
|
|
|
|
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
else
|
|
|
|
return strcmp(a->to->name, b->to->name);
|
|
|
|
}
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
/* Evil edge_compare() from a parallel universe ;)
|
2001-10-10 08:49:47 +00:00
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
int edge_compare(edge_t *a, edge_t *b)
|
2001-10-10 08:49:47 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
return (result = strcmp(a->from->name, b->from->name)) || (result = strcmp(a->to->name, b->to->name)), result;
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void init_vertices(void)
|
|
|
|
{
|
|
|
|
cp
|
2001-10-28 08:41:19 +00:00
|
|
|
edge_tree = avl_alloc_tree((avl_compare_t)edge_compare, NULL);
|
2001-10-10 08:49:47 +00:00
|
|
|
cp
|
|
|
|
}
|
|
|
|
|
|
|
|
void exit_vertices(void)
|
|
|
|
{
|
|
|
|
cp
|
2001-10-28 08:41:19 +00:00
|
|
|
avl_delete_tree(edge_tree);
|
2001-10-10 08:49:47 +00:00
|
|
|
cp
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Creation and deletion of connection elements */
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
edge_t *new_edge(void)
|
2001-10-10 08:49:47 +00:00
|
|
|
{
|
|
|
|
cp
|
2001-10-28 08:41:19 +00:00
|
|
|
edge_t *v = (edge_t *)xmalloc_and_zero(sizeof(*v));
|
2001-10-10 08:49:47 +00:00
|
|
|
cp
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
void free_edge(edge_t *v)
|
2001-10-10 08:49:47 +00:00
|
|
|
{
|
|
|
|
cp
|
|
|
|
free(v);
|
|
|
|
cp
|
|
|
|
}
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
void edge_add(edge_t *v)
|
2001-10-27 12:13:17 +00:00
|
|
|
{
|
|
|
|
cp
|
2001-10-28 08:41:19 +00:00
|
|
|
avl_insert(edge_tree, v);
|
2001-10-27 12:13:17 +00:00
|
|
|
cp
|
|
|
|
}
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
void edge_del(edge_t *v)
|
2001-10-27 12:13:17 +00:00
|
|
|
{
|
|
|
|
cp
|
2001-10-28 08:41:19 +00:00
|
|
|
avl_delete(edge_tree, v);
|
2001-10-27 12:13:17 +00:00
|
|
|
cp
|
|
|
|
}
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
edge_t *lookup_edge(node_t *from, node_t *to)
|
2001-10-10 08:49:47 +00:00
|
|
|
{
|
2001-10-28 08:41:19 +00:00
|
|
|
edge_t v, *result;
|
2001-10-10 08:49:47 +00:00
|
|
|
cp
|
2001-10-27 12:13:17 +00:00
|
|
|
v.from = from;
|
|
|
|
v.to = to;
|
2001-10-10 08:49:47 +00:00
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
result = avl_search(edge_tree, &v);
|
2001-10-10 08:49:47 +00:00
|
|
|
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
cp
|
2001-10-27 12:13:17 +00:00
|
|
|
v.from = to;
|
|
|
|
v.to = from;
|
2001-10-10 08:49:47 +00:00
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
return avl_search(edge_tree, &v);
|
2001-10-10 08:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dump_vertices(void)
|
|
|
|
{
|
|
|
|
avl_node_t *node;
|
2001-10-28 08:41:19 +00:00
|
|
|
edge_t *v;
|
2001-10-10 08:49:47 +00:00
|
|
|
cp
|
|
|
|
syslog(LOG_DEBUG, _("Vertices:"));
|
|
|
|
|
2001-10-28 08:41:19 +00:00
|
|
|
for(node = edge_tree->head; node; node = node->next)
|
2001-10-10 08:49:47 +00:00
|
|
|
{
|
2001-10-28 08:41:19 +00:00
|
|
|
v = (edge_t *)node->data;
|
2001-10-10 08:49:47 +00:00
|
|
|
syslog(LOG_DEBUG, _(" %s - %s options %ld"),
|
2001-10-27 12:13:17 +00:00
|
|
|
v->from->name, v->to->name, v->options);
|
2001-10-10 08:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
syslog(LOG_DEBUG, _("End of vertices."));
|
|
|
|
cp
|
|
|
|
}
|