Moved out most ob mavl_ into libmavl.
Current libmavl is here: https://svn.planix.org/rsrch/trunk/libmavl
This commit is contained in:
		@ -121,32 +121,6 @@ LWSRC=\
 | 
			
		||||
	lw_put_sockaddr.c\
 | 
			
		||||
	lw_readelem_wtp_name.c\
 | 
			
		||||
 | 
			
		||||
MAVLSRC=\
 | 
			
		||||
	mavl_add.c\
 | 
			
		||||
	mavl_add_ptr.c\
 | 
			
		||||
	mavl_cmpstr.c\
 | 
			
		||||
	mavl_create.c\
 | 
			
		||||
	mavl_del_all.c\
 | 
			
		||||
	mavl_del.c\
 | 
			
		||||
	mavl_destroy.c\
 | 
			
		||||
	mavl_foreach.c\
 | 
			
		||||
	mavl_foreach_lr.c\
 | 
			
		||||
	mavl_freeptr.c\
 | 
			
		||||
	mavl_get.c\
 | 
			
		||||
	mavl_get_ext.c\
 | 
			
		||||
	mavl_get_node.c\
 | 
			
		||||
	mavl_get_node_cmp..c\
 | 
			
		||||
	mavl_get_ptr.c\
 | 
			
		||||
	mavliter_get.c\
 | 
			
		||||
	mavliter_get_ptr.c\
 | 
			
		||||
	mavliter_init.c\
 | 
			
		||||
	mavliter_next.c\
 | 
			
		||||
	mavliter_seek.c\
 | 
			
		||||
	mavliter_seek_set.c\
 | 
			
		||||
	mavl_merge.c\
 | 
			
		||||
	mavl_replace.c\
 | 
			
		||||
	mavl_replace_data.c\
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
MLISTSRC=\
 | 
			
		||||
	mlist_append.c\
 | 
			
		||||
@ -240,6 +214,15 @@ RADIOSRC=\
 | 
			
		||||
	cw_out_radio_generic_struct.c\
 | 
			
		||||
	cw_read_radio_generic.c\
 | 
			
		||||
 | 
			
		||||
MAVLSRC=\
 | 
			
		||||
	mavl_get_ptr.c\
 | 
			
		||||
	mavl_insert_ptr.c\
 | 
			
		||||
	mavl_replace.c\
 | 
			
		||||
	mavl_merge.c\
 | 
			
		||||
	mavliter_get_ptr.c\
 | 
			
		||||
	mavl_cmpstr.c\
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
DTLSSRC += dtls_openssl.c \
 | 
			
		||||
	dtls_openssl_accept.c \
 | 
			
		||||
@ -258,7 +241,8 @@ LIBS+=-lssl
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#SRC=$(wildcard *.c)
 | 
			
		||||
SOURCES = $(CWSRC) $(LWSRC) $(MAVLSRC) $(MLISTSRC) $(SOCKSRC) $(LOGSRC) $(DTLSSRC) $(RADIOSRC) $(KTVSRC) $(MISCSRC)
 | 
			
		||||
SOURCES = $(CWSRC) $(LWSRC) $(MAVLSRC) $(MLISTSRC) $(SOCKSRC) \
 | 
			
		||||
	  $(LOGSRC) $(DTLSSRC) $(RADIOSRC) $(KTVSRC) $(MISCSRC) 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -270,7 +254,8 @@ OBJDIR          := ../../obj/cw/$(KERNEL)/$(ARCH)
 | 
			
		||||
SNAME           := $(LIBARCHDIR)/libcw.a
 | 
			
		||||
DNAME           := $(LIBARCHDIR)/libcw.so
 | 
			
		||||
 | 
			
		||||
CFLAGS+=-fPIC -DUSE_OPENSSL
 | 
			
		||||
CFLAGS+=-fPIC -DUSE_OPENSSL -I../contrib/openssl-1.1.1f/include/ -O0 
 | 
			
		||||
CFLAGS+=-g -I/home/tube/v/rsrch/libmavl
 | 
			
		||||
 | 
			
		||||
all: $(SNAME) $(DNAME) 
 | 
			
		||||
static: $(SNAME)
 | 
			
		||||
 | 
			
		||||
@ -206,7 +206,7 @@ void cw_read_elem(struct cw_ElemHandler * handler, struct conn * conn,
 | 
			
		||||
	
 | 
			
		||||
	handler->type->to_str(result,str,30);
 | 
			
		||||
	printf("Read %d-%s: %s %s\n", handler->id, handler->name, handler->key, str);
 | 
			
		||||
	//mavl_add(conn->remote_cfg
 | 
			
		||||
	//mavl_insert(conn->remote_cfg
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
@ -290,7 +290,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
 | 
			
		||||
	
 | 
			
		||||
	/* Search message */
 | 
			
		||||
	
 | 
			
		||||
	message = mavl_find(conn->msgset->msgdata,&search);
 | 
			
		||||
	message = mavl_get(conn->msgset->msgdata,&search);
 | 
			
		||||
		
 | 
			
		||||
	result_code = 0;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
@ -155,7 +155,7 @@ struct conn * connlist_add ( struct connlist * cl, struct conn * conn )
 | 
			
		||||
			return NULL;
 | 
			
		||||
			
 | 
			
		||||
	conn->connlist = cl;
 | 
			
		||||
	return mavl_add_ptr ( cl->by_addr, conn );
 | 
			
		||||
	return mavl_insert_ptr ( cl->by_addr, conn );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct conn * connlist_get_by_session_id ( struct connlist *cl, struct conn * conn )
 | 
			
		||||
@ -165,7 +165,7 @@ struct conn * connlist_get_by_session_id ( struct connlist *cl, struct conn * co
 | 
			
		||||
 | 
			
		||||
struct conn * connlist_add_by_session_id ( struct connlist * cl, struct conn * conn )
 | 
			
		||||
{
 | 
			
		||||
	return mavl_add_ptr ( cl->by_session_id, conn );
 | 
			
		||||
	return mavl_insert_ptr ( cl->by_session_id, conn );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void connlist_remove ( struct connlist *cl, struct conn * conn )
 | 
			
		||||
 | 
			
		||||
@ -10,6 +10,7 @@ cw_KTV_t * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *ty
 | 
			
		||||
{
 | 
			
		||||
	cw_KTV_t mdata, *mresult;
 | 
			
		||||
	int exists;
 | 
			
		||||
printf("KTV ADD: %s\n",key);
 | 
			
		||||
 | 
			
		||||
	mdata.key=cw_strdup(key);
 | 
			
		||||
	mdata.valguard=valguard;
 | 
			
		||||
@ -29,8 +30,10 @@ cw_KTV_t * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *ty
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
printf("MAVLCOUNT: %d - %s\n",kvtstore->count, mdata.key);
 | 
			
		||||
 | 
			
		||||
	mavl_del(kvtstore,&mdata);
 | 
			
		||||
	mresult = mavl_add(kvtstore, &mdata, &exists);
 | 
			
		||||
	mresult = mavl_insert(kvtstore, &mdata, &exists);
 | 
			
		||||
	if (exists){
 | 
			
		||||
		cw_log(LOG_ERR, "Element already exists %s", key);
 | 
			
		||||
		/* element already exists */
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,7 @@ const char * cw_ktv_add_from_str(mavl_t kvtstore, const char *key,
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	mresult = mavl_add(kvtstore, &mdata, &exists);
 | 
			
		||||
	mresult = mavl_insert(kvtstore, &mdata, &exists);
 | 
			
		||||
	if (exists){
 | 
			
		||||
		cw_log(LOG_ERR, "Element already exists %s", key);
 | 
			
		||||
		/* element already exists */
 | 
			
		||||
 | 
			
		||||
@ -24,19 +24,19 @@ void * ktvn(struct mavl *t ,const void *search)
 | 
			
		||||
		
 | 
			
		||||
		if (rc<0){
 | 
			
		||||
			/*lastl = n;*/
 | 
			
		||||
			if (n->left==NULL){
 | 
			
		||||
			if (n->s[0]==NULL){
 | 
			
		||||
				return mavlnode_dataptr(lastb);
 | 
			
		||||
				
 | 
			
		||||
			}
 | 
			
		||||
			n=n->left;
 | 
			
		||||
			n=n->s[0];
 | 
			
		||||
		}
 | 
			
		||||
		else{
 | 
			
		||||
			lastb=n;
 | 
			
		||||
			if(n->right==NULL){
 | 
			
		||||
			if(n->s[1]==NULL){
 | 
			
		||||
				return mavlnode_dataptr(lastb);
 | 
			
		||||
				
 | 
			
		||||
			}
 | 
			
		||||
			n=n->right;
 | 
			
		||||
			n=n->s[1];
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
 | 
			
		||||
	elem_data_search.id=elem_id;
 | 
			
		||||
	elem_data_search.proto=proto;
 | 
			
		||||
	elem_data_search.vendor=vendor;
 | 
			
		||||
	elem_data = mavl_find(params->msgdata->elements_tree,&elem_data_search);
 | 
			
		||||
	elem_data = mavl_get(params->msgdata->elements_tree,&elem_data_search);
 | 
			
		||||
	if (!elem_data){
 | 
			
		||||
		cw_dbg(DBG_ELEM_ERR, "Element %d - %s, not allowed here", 
 | 
			
		||||
			elem_id, handler->name);
 | 
			
		||||
 | 
			
		||||
@ -48,8 +48,8 @@ static const char * ssl_version2str(int version)
 | 
			
		||||
			return "TLSv1";
 | 
			
		||||
		case DTLS1_VERSION:
 | 
			
		||||
			return "DTLSv1";
 | 
			
		||||
/*		case DTLS1_2_VERSION:
 | 
			
		||||
			return "DTLSv1.2"; */
 | 
			
		||||
		case DTLS1_2_VERSION:
 | 
			
		||||
			return "DTLSv1.2";
 | 
			
		||||
	}
 | 
			
		||||
	return "Version unknown";
 | 
			
		||||
}
 | 
			
		||||
@ -65,7 +65,7 @@ static void dtls_debug_cb(int write_p,int version,int type, const void * buf,siz
 | 
			
		||||
		s += sprintf(s,"SSL msg in: ");
 | 
			
		||||
 | 
			
		||||
	s+=sprintf(s,"type = %d (0x%02X), %s (%08x), len = %d",type,type,ssl_version2str(version),version,(int)len);
 | 
			
		||||
/*	cw_dbg(DBG_DTLS_DETAIL,buffer); */
 | 
			
		||||
	cw_dbg(DBG_DTLS_DETAIL,buffer); 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -319,6 +319,16 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	rc = SSL_CTX_get_security_level(d->ctx);
 | 
			
		||||
	printf("Security Level is %d\n");
 | 
			
		||||
 | 
			
		||||
	SSL_CTX_set_security_level(d->ctx,0);
 | 
			
		||||
	printf("Security Level is %d\n");
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
/*	SSL_CTX_set_min_proto_version	(d->ctx,  DTLS1_VERSION);*/
 | 
			
		||||
	SSL_CTX_set_max_proto_version	(d->ctx,  DTLS1_VERSION);
 | 
			
		||||
 | 
			
		||||
	rc = SSL_CTX_set_cipher_list(d->ctx, conn->dtls_cipher);
 | 
			
		||||
	if (!rc){
 | 
			
		||||
@ -374,17 +384,16 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*//	SSL_CTX_set_session_cache_mode(d->ctx, SSL_SESS_CACHE_BOTH);*/
 | 
			
		||||
	SSL_CTX_set_options(d->ctx, SSL_OP_NO_SSLv2 |SSL_OP_NO_SSLv3 );
 | 
			
		||||
/*//	SSL_CTX_set_generate_session_id(d->ctx,generate_session_id);*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	SSL_CTX_set_timeout(d->ctx,30);
 | 
			
		||||
/*
 | 
			
		||||
//	rc =SSL_CTX_set_max_proto_version (d->ctx,DTLS1_VERSION);
 | 
			
		||||
//	printf("MAXMAMX = %d\n",rc);
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
	rc =SSL_CTX_set_max_proto_version (d->ctx,DTLS1_VERSION);
 | 
			
		||||
	printf("MAXMAMX = %d\n",rc);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
//	SSL_CTX_set_verify(d->ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, dtls_verify_callback);
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,7 @@
 | 
			
		||||
BIO_METHOD *dtls_openssl_bio_method()
 | 
			
		||||
{
 | 
			
		||||
	int index = BIO_get_new_index() ;
 | 
			
		||||
	index = BIO_TYPE_DGRAM;
 | 
			
		||||
/*	index = BIO_TYPE_DGRAM;*/
 | 
			
		||||
	cw_dbg(DBG_DTLS_BIO, "Creating new OpenSSL BIO Methods");
 | 
			
		||||
 | 
			
		||||
	BIO_METHOD * bio_methods;
 | 
			
		||||
 | 
			
		||||
@ -46,7 +46,7 @@ dtls_openssl_connect(struct conn *conn)
 | 
			
		||||
	
 | 
			
		||||
	if (!conn->dtls_data)
 | 
			
		||||
		conn->dtls_data =
 | 
			
		||||
		    dtls_openssl_data_create(conn, DTLSv1_client_method(),
 | 
			
		||||
		    dtls_openssl_data_create(conn, DTLS_client_method(),
 | 
			
		||||
					     biomethod);
 | 
			
		||||
 | 
			
		||||
	cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 2");
 | 
			
		||||
@ -68,7 +68,7 @@ dtls_openssl_connect(struct conn *conn)
 | 
			
		||||
		rc = SSL_connect(d->ssl);
 | 
			
		||||
	}while(rc!=1 && errno==EAGAIN && !cw_timer_timeout(timer));
 | 
			
		||||
 | 
			
		||||
	cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 4");
 | 
			
		||||
	cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 4 %d ",rc);
 | 
			
		||||
 | 
			
		||||
	if (rc == 1) {
 | 
			
		||||
		cw_dbg(DBG_DTLS,"SSL connect successfull!");
 | 
			
		||||
 | 
			
		||||
@ -31,5 +31,5 @@ int * intavltree_add(struct mavl * t, int val)
 | 
			
		||||
	if (!v)
 | 
			
		||||
		return NULL;
 | 
			
		||||
	*v=val;
 | 
			
		||||
	return mavl_add(t,v,NULL);
 | 
			
		||||
	return mavl_insert(t,v,NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
#ifndef __INTAVLTREE_H
 | 
			
		||||
#define __INTAVLTREE_H
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
#include <mavl.h>
 | 
			
		||||
 | 
			
		||||
extern struct mavl * intavltree_create();
 | 
			
		||||
typedef struct mavl * intavltree_t;
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,9 @@
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
#include <mavl.h>
 | 
			
		||||
#include "mavltypes.h"
 | 
			
		||||
 | 
			
		||||
#include "bstr.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										298
									
								
								src/cw/mavl.h
									
									
									
									
									
								
							
							
						
						
									
										298
									
								
								src/cw/mavl.h
									
									
									
									
									
								
							@ -1,298 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file mavl.h
 | 
			
		||||
 * @brief MAVL, Mini AVL Tree,
 | 
			
		||||
 * Yet another AVL Tree implementation
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @addtogroup ALGOS
 | 
			
		||||
 * @{
 | 
			
		||||
 * 
 | 
			
		||||
 * @defgroup MAVL Mavl Tree
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef __MAVL_H
 | 
			
		||||
#define __MAVL_H
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** Maximum AVL Tree depth.
 | 
			
		||||
    The number of nodes is calculated by 2^depth.
 | 
			
		||||
    So a value of 32 should be enough for around 4
 | 
			
		||||
    billion nodes. */
 | 
			
		||||
#define MAVL_MAX_DEPTH	32
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Defines the structure of an AVL Node.
 | 
			
		||||
 */
 | 
			
		||||
struct mavlnode {
 | 
			
		||||
	/** Pointer to data, that belongs to the node */
 | 
			
		||||
	
 | 
			
		||||
	/*	union mavldata data; */
 | 
			
		||||
	
 | 
			
		||||
	/** Pointer to left son*/
 | 
			
		||||
	struct mavlnode *left;
 | 
			
		||||
	/** Pointer to right son*/
 | 
			
		||||
	struct mavlnode *right;
 | 
			
		||||
	/** AVL balance */
 | 
			
		||||
	int bal;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * AVL Tree
 | 
			
		||||
 */
 | 
			
		||||
struct mavl {
 | 
			
		||||
	/** Pointer to root node */
 | 
			
		||||
	struct mavlnode *root;
 | 
			
		||||
	/** Compare function */
 | 
			
		||||
	int ( *cmp ) ( const void *, const void * );
 | 
			
		||||
	/** Delete element function */
 | 
			
		||||
	void ( *del ) ( void * );
 | 
			
		||||
	/** Number of elements currently stored in the tree */
 | 
			
		||||
	int count;
 | 
			
		||||
	/** size of data appended to each mavlnode element.
 | 
			
		||||
	 * used to allocate space in #mavl_add. */
 | 
			
		||||
	size_t data_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * MAVL AVL Tree type
 | 
			
		||||
 */
 | 
			
		||||
typedef struct mavl * mavl_t;
 | 
			
		||||
 | 
			
		||||
#define MAVL_FIND_FIRST 1
 | 
			
		||||
#define MAVL_FIND_LAST  2
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param node node 
 | 
			
		||||
 */
 | 
			
		||||
#define mavlnode_dataptr(node) ((void*)(((uint8_t*)(node))+sizeof(struct mavlnode)))
 | 
			
		||||
 | 
			
		||||
struct mavl *mavl_create ( int ( *cmp ) ( const void *, const void * ),
 | 
			
		||||
                           void ( *del ) ( void * ), size_t data_size );
 | 
			
		||||
 | 
			
		||||
void *mavl_add ( struct mavl *t, const void *data, int *exists );
 | 
			
		||||
 | 
			
		||||
/*void *mavl_add ( struct mavl *t,  const void *data );*/
 | 
			
		||||
void * mavl_get ( struct mavl *t , const void *data );
 | 
			
		||||
void * mavl_get_ext(struct mavl *t ,const void *search, int mode);
 | 
			
		||||
 | 
			
		||||
void *mavl_del ( struct mavl *t, const void *data );
 | 
			
		||||
void *mavl_replace ( struct mavl *t, const void *data, int * result );
 | 
			
		||||
void mavl_destroy ( struct mavl *t );
 | 
			
		||||
void mavl_del_all ( struct mavl *t );
 | 
			
		||||
void mavl_merge ( mavl_t target, mavl_t source );
 | 
			
		||||
void mavlnode_destroy ( struct mavl *t, struct mavlnode *n );
 | 
			
		||||
struct mavlnode *mavlnode_get ( struct mavl *t, void *data );
 | 
			
		||||
struct mavlnode * mavl_get_node_cmp(struct mavl *t ,void *data,
 | 
			
		||||
	int ( *cmp ) ( const void *, const void * ));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define mavl_get_first(tree,search) mavl_get_ext(tree,search,MAVL_FIND_FIRST)
 | 
			
		||||
#define mavl_get_last(tree,search) mavl_get_ext(tree,search,MAVL_FIND_LAST)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
extern int mavl_foreach_lr ( struct mavlnode *n, int ( *callback ) ( void *, void * ),
 | 
			
		||||
                             void *cbpriv );
 | 
			
		||||
extern int mavl_foreach_rl ( struct mavlnode *n, int ( *callback ) ( void *, void * ),
 | 
			
		||||
                             void *cbpriv );
 | 
			
		||||
int mavl_foreach_from_lr ( struct mavl *t, struct mavlnode *n, void *data,
 | 
			
		||||
                           int ( *callback ) ( void *, void * ), void *cbpriv );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void *mavl_replace_data ( struct mavl *t, void *data, int len );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This macro is an alias for #mavl_get
 | 
			
		||||
 */
 | 
			
		||||
#define mavl_find(t,d) mavl_get(t,d)
 | 
			
		||||
 | 
			
		||||
#define mavl_find_ptr(tree,search_ptr) mavl_get_ptr(tree,search_ptr)
 | 
			
		||||
#define mavl_insert(t,d) mavl_add(t,d)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define mavl_foreach_asc(t,cb,priv) mavl_foreach_lr((t)->root,cb,priv)
 | 
			
		||||
#define mavl_foreach_desc(t,cb,priv) mavl_foreach_rl((t)->root,cb,priv)
 | 
			
		||||
 | 
			
		||||
#define mavl_foreach_from_asc(t,d,cb,priv) mavl_foreach_from_lr(t,(t)->root,d,cb,priv);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct mavliter {
 | 
			
		||||
	struct mavlnode *stack[MAVL_MAX_DEPTH * 2];
 | 
			
		||||
	
 | 
			
		||||
	struct mavlnode *cur;
 | 
			
		||||
	int stack_ptr;
 | 
			
		||||
	struct mavlnode * root;
 | 
			
		||||
	int ( *cmp ) ( const void *, const void * );
 | 
			
		||||
	
 | 
			
		||||
};
 | 
			
		||||
typedef struct mavliter mavliter_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void * mavliter_next ( mavliter_t *i );
 | 
			
		||||
 | 
			
		||||
void * mavliter_seek_set ( struct mavliter *i );
 | 
			
		||||
 | 
			
		||||
void mavliter_init ( mavliter_t *i, mavl_t t );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void * mavliter_get ( mavliter_t *i );
 | 
			
		||||
 | 
			
		||||
void * mavliter_get_ptr(mavliter_t *i);
 | 
			
		||||
 | 
			
		||||
void * mavliter_seek ( mavliter_t *i, void *d );
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Define a AVL Iterator varialble and accociate it with
 | 
			
		||||
 * an AVL Tree.
 | 
			
		||||
 * @param i Name of the variable to define
 | 
			
		||||
 * @param t #mavl_t Tree to associate
 | 
			
		||||
 * @see #mavliter_get #mavliter_foreach
 | 
			
		||||
 *
 | 
			
		||||
 * Example:
 | 
			
		||||
 * \code
 | 
			
		||||
   mavl_t datatree = mavl_create();
 | 
			
		||||
 | 
			
		||||
   // fill up datatree with some values
 | 
			
		||||
 | 
			
		||||
   MAVLITER_DEFINE (i,datatree);
 | 
			
		||||
   mavliter_foreach(&i) {
 | 
			
		||||
	// Get the current value
 | 
			
		||||
	void * value = mavliter_get(&i);
 | 
			
		||||
 | 
			
		||||
   }
 | 
			
		||||
   \endcode
 | 
			
		||||
 */
 | 
			
		||||
#define MAVLITER_DEFINE(iterator,mavl_obj)\
 | 
			
		||||
	mavliter_t iterator; mavliter_init(&iterator,mavl_obj)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Iterate through all elements of an MAVL Object using a MAVL Iterator.
 | 
			
		||||
 * @param i pointer to MAVL Interator object
 | 
			
		||||
 */
 | 
			
		||||
#define mavliter_foreach(iterator)\
 | 
			
		||||
	for (mavliter_seek_set(iterator); NULL != mavliter_get(iterator); mavliter_next(iterator))
 | 
			
		||||
 | 
			
		||||
#define mavliter_foreach_from(i,from)\
 | 
			
		||||
	for (mavliter_seek(i,from); NULL != mavliter_get(i); mavliter_next(i))
 | 
			
		||||
 | 
			
		||||
#define mavliter_foreach_asc(iter,val) \
 | 
			
		||||
	while(NULL != (val = mavliter_next(iter)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the number of elements stored in a mavl object
 | 
			
		||||
 * @param m mavl object
 | 
			
		||||
 * @return Number of elemenst
 | 
			
		||||
 */
 | 
			
		||||
#define mavl_get_count(m) (m->count)
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
#typedef mavl_t mavl_conststr_t;
 | 
			
		||||
#extern mavl_conststr_t mavl_create_conststr();
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
//int mavl_cmp_str ( const union mavldata *e1, const union mavldata *e2 );
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
static inline void *mavl_replace_data(struct mavl *t, void *data, int len)
 | 
			
		||||
{
 | 
			
		||||
	void *df = mavl_get(t, data);
 | 
			
		||||
	if (!df)
 | 
			
		||||
		return NULL;
 | 
			
		||||
	memcpy(df, data, len);
 | 
			
		||||
	return df;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void *mavl_replace(struct mavl *t,void *data){
 | 
			
		||||
	struct mavlnode * node = mavl_get_node(t,data);
 | 
			
		||||
	if (node){
 | 
			
		||||
		t->del(node->data);
 | 
			
		||||
		return node->data=data;
 | 
			
		||||
	}
 | 
			
		||||
	return mavl_add(t,data);
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void mavl_freeptr(void *ptr);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Create a mavl_t object which stores pointers. 
 | 
			
		||||
 * @param cmp a pointer to the compare function
 | 
			
		||||
 * @param del a pointer to a delete function
 | 
			
		||||
 * @return The mavl_t object or NULL if an error has occured.
 | 
			
		||||
 */
 | 
			
		||||
#define mavl_create_ptr(cmp,del)\
 | 
			
		||||
	mavl_create(cmp,del,sizeof(void*))
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
int mavl_cmpstr(const void *p1, const void *p2);
 | 
			
		||||
#define mavl_create_str() mavl_create_ptr(mavl_cmpstr,mavl_freeptr)
 | 
			
		||||
#define mavl_create_conststr() mavl_create_ptr(mavl_cmpstr,NULL)
 | 
			
		||||
 | 
			
		||||
void * mavl_get_ptr ( mavl_t tree, void * search );
 | 
			
		||||
void * mavl_add_ptr ( mavl_t tree, const void *ptr );
 | 
			
		||||
 | 
			
		||||
#define mavl_add_str(tree,str) mavl_add_ptr(tree,str)
 | 
			
		||||
#define mavl_get_str(tree,search) ((char *)(mavl_get_ptr(tree,search)))
 | 
			
		||||
#define mavliter_get_str(iter) ((char*)(mavliter_get_ptr(iter)))
 | 
			
		||||
#define mavliter_get_conststr(iter) ((const char*)(mavliter_get_ptr(iter)))
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @} MAVL
 | 
			
		||||
 * 
 | 
			
		||||
 * @} ALGOS
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,233 +0,0 @@
 | 
			
		||||
/**
 | 
			
		||||
 * @file
 | 
			
		||||
 * @brief Implementation of mavl_add
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
static struct mavlnode *mavlnode_create ( struct mavl *t, const void *data )
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *n = malloc ( sizeof ( struct mavlnode ) + t->data_size );
 | 
			
		||||
	
 | 
			
		||||
	if ( !n )
 | 
			
		||||
		return NULL;
 | 
			
		||||
		
 | 
			
		||||
	n->left = n->right = NULL;
 | 
			
		||||
	n->bal = 0;
 | 
			
		||||
	
 | 
			
		||||
	/*n->data = *data;*/
 | 
			
		||||
	memcpy ( mavlnode_dataptr ( n ), data, t->data_size );
 | 
			
		||||
	
 | 
			
		||||
	return n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static int mavl_add0 ( struct mavl *t, struct mavlnode **parent, const void ** data )
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *tmp;
 | 
			
		||||
	struct mavlnode *n = *parent;
 | 
			
		||||
	int rc = t->cmp ( *data, mavlnode_dataptr ( n ) );
 | 
			
		||||
	
 | 
			
		||||
	int bal;
 | 
			
		||||
	
 | 
			
		||||
	if ( rc == 0 ) {
 | 
			
		||||
		/*		*data = &n->data;*/
 | 
			
		||||
		
 | 
			
		||||
		/*		memcpy(data,mavlnode_dataptr(n),t->data_size);*/
 | 
			
		||||
		*data = mavlnode_dataptr ( n );
 | 
			
		||||
		return 2;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if ( rc < 0 ) {
 | 
			
		||||
		if ( n->left ) {
 | 
			
		||||
			bal = mavl_add0 ( t, &n->left, data );
 | 
			
		||||
			
 | 
			
		||||
			if ( bal > 1 )
 | 
			
		||||
				return bal;
 | 
			
		||||
				
 | 
			
		||||
			n->bal -= bal;
 | 
			
		||||
			
 | 
			
		||||
			if ( n->bal == 0 )
 | 
			
		||||
				return 0;
 | 
			
		||||
				
 | 
			
		||||
			if ( n->bal == -2 ) {
 | 
			
		||||
				if ( n->left->bal == -1 ) {
 | 
			
		||||
					n->bal = 0;
 | 
			
		||||
					n->left->bal = 0;
 | 
			
		||||
					*parent = n->left;
 | 
			
		||||
					tmp = n->left->right;
 | 
			
		||||
					n->left->right = n;
 | 
			
		||||
					n->left = tmp;
 | 
			
		||||
					return 0;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if ( n->left->bal == 1 ) {
 | 
			
		||||
					*parent = n->left->right;
 | 
			
		||||
					
 | 
			
		||||
					if ( ( *parent )->bal == 1 ) {
 | 
			
		||||
						n->bal = 0;
 | 
			
		||||
						n->left->bal = -1;
 | 
			
		||||
						
 | 
			
		||||
					} else if ( ( *parent )->bal == -1 ) {
 | 
			
		||||
						n->bal = 1;
 | 
			
		||||
						n->left->bal = 0;
 | 
			
		||||
						
 | 
			
		||||
					} else {
 | 
			
		||||
						n->bal = 0;
 | 
			
		||||
						n->left->bal = 0;
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					( *parent )->bal = 0;
 | 
			
		||||
					n->left->right = ( *parent )->left;
 | 
			
		||||
					( *parent )->left = n->left;
 | 
			
		||||
					tmp = ( *parent )->right;
 | 
			
		||||
					( *parent )->right = n;
 | 
			
		||||
					n->left = tmp;
 | 
			
		||||
					return 0;
 | 
			
		||||
					
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			return bal;
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		/* n->left is 0 */
 | 
			
		||||
		n->left = mavlnode_create ( t, *data );
 | 
			
		||||
		*data = mavlnode_dataptr(n->left);
 | 
			
		||||
		
 | 
			
		||||
		if ( !n->left )
 | 
			
		||||
			return 3;
 | 
			
		||||
			
 | 
			
		||||
		t->count++;
 | 
			
		||||
		
 | 
			
		||||
		if ( n->right == 0 ) {
 | 
			
		||||
			n->bal = -1;
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		n->bal = 0;
 | 
			
		||||
		return 0;
 | 
			
		||||
		
 | 
			
		||||
	} else {
 | 
			
		||||
		if ( n->right ) {
 | 
			
		||||
			bal = mavl_add0 ( t, &n->right, data );
 | 
			
		||||
			
 | 
			
		||||
			if ( bal > 1 )
 | 
			
		||||
				return bal;
 | 
			
		||||
				
 | 
			
		||||
			n->bal += bal;
 | 
			
		||||
			
 | 
			
		||||
			if ( n->bal == 0 )
 | 
			
		||||
				return 0;
 | 
			
		||||
				
 | 
			
		||||
			if ( n->bal == 2 ) {
 | 
			
		||||
				if ( n->right->bal == 1 ) {
 | 
			
		||||
					n->bal = 0;
 | 
			
		||||
					n->right->bal = 0;
 | 
			
		||||
					*parent = n->right;
 | 
			
		||||
					tmp = n->right->left;
 | 
			
		||||
					n->right->left = n;
 | 
			
		||||
					n->right = tmp;
 | 
			
		||||
					return 0;
 | 
			
		||||
					
 | 
			
		||||
				} else if ( n->right->bal == -1 ) {
 | 
			
		||||
					*parent = n->right->left;
 | 
			
		||||
					
 | 
			
		||||
					if ( ( *parent )->bal == -1 ) {
 | 
			
		||||
						n->bal = 0;
 | 
			
		||||
						n->right->bal = 1;
 | 
			
		||||
						
 | 
			
		||||
					} else if ( ( *parent )->bal == 1 ) {
 | 
			
		||||
						n->bal = -1;
 | 
			
		||||
						n->right->bal = 0;
 | 
			
		||||
						
 | 
			
		||||
					} else {
 | 
			
		||||
						n->bal = 0;
 | 
			
		||||
						n->right->bal = 0;
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					( *parent )->bal = 0;
 | 
			
		||||
					n->right->left = ( *parent )->right;
 | 
			
		||||
					( *parent )->right = n->right;
 | 
			
		||||
					tmp = ( *parent )->left;
 | 
			
		||||
					( *parent )->left = n;
 | 
			
		||||
					n->right = tmp;
 | 
			
		||||
					return 0;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			return bal;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		/* n->right is 0 */
 | 
			
		||||
		
 | 
			
		||||
		n->right = mavlnode_create ( t, *data );
 | 
			
		||||
		*data = mavlnode_dataptr(n->right);
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
		if ( !n->right )
 | 
			
		||||
			return 3;
 | 
			
		||||
			
 | 
			
		||||
		t->count++;
 | 
			
		||||
		
 | 
			
		||||
		if ( n->left == 0 ) {
 | 
			
		||||
			n->bal = 1;
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		n->bal = 0;
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief mavl add function
 | 
			
		||||
 * Add an element to an AVL tree
 | 
			
		||||
 * @param t mavl
 | 
			
		||||
 * @param data pointer to the element to add
 | 
			
		||||
 * @param exists pointer to an interger vairable which wil be set to 1, if
 | 
			
		||||
 * the element to add already exists in the tree. If the element did't
 | 
			
		||||
 * exist, the variable ist to 0.
 | 
			
		||||
 | 
			
		||||
 * @return A pointer to the element in the tree. If the element was added, 
 | 
			
		||||
 * it the pointer to newly created element. If the element had already existed,
 | 
			
		||||
 * the pointer points to the existing element. mavl_add returns thero, if 
 | 
			
		||||
 * something else went wrong. Therefore consult errno.
 | 
			
		||||
 * 
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
void *mavl_add ( struct mavl *t, const void *data, int *exists )
 | 
			
		||||
{
 | 
			
		||||
	const void * d;
 | 
			
		||||
	int rc;
 | 
			
		||||
	
 | 
			
		||||
	if ( t->root == NULL ) {
 | 
			
		||||
		t->root = mavlnode_create ( t, data );
 | 
			
		||||
		
 | 
			
		||||
		if ( t->root )
 | 
			
		||||
			t->count++;
 | 
			
		||||
			
 | 
			
		||||
		/* return &t->root->data; */
 | 
			
		||||
		if (exists != NULL)
 | 
			
		||||
			*exists=0;
 | 
			
		||||
		return mavlnode_dataptr(t->root);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	d = data;
 | 
			
		||||
	
 | 
			
		||||
	rc = mavl_add0 ( t, &t->root, &d );
 | 
			
		||||
	
 | 
			
		||||
	if ( rc >= 3 )
 | 
			
		||||
		return NULL;
 | 
			
		||||
		
 | 
			
		||||
	if ( exists != NULL){
 | 
			
		||||
		if (rc==2) 
 | 
			
		||||
			*exists=1;
 | 
			
		||||
		else
 | 
			
		||||
			*exists=0;
 | 
			
		||||
	}
 | 
			
		||||
	return (void*)d;
 | 
			
		||||
}
 | 
			
		||||
@ -1,9 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
void *mavl_add_ptr(mavl_t tree, const void *ptr){
 | 
			
		||||
	void * result;
 | 
			
		||||
	result = mavl_add(tree,&ptr,NULL);
 | 
			
		||||
	if (result)
 | 
			
		||||
		return *(void**)result;
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
#include "mavltypes.h"
 | 
			
		||||
 | 
			
		||||
int mavl_cmpstr (const void *s1, const void *s2)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -1,50 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *@file
 | 
			
		||||
 *@brief Implementation of mavl_create
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Create an AVL tree
 | 
			
		||||
 * @param cmp pointer to compare function
 | 
			
		||||
 * @param del pointer to delete function which is called when an element 
 | 
			
		||||
 * will be deletet
 | 
			
		||||
 * @param dta_size size of a data element
 | 
			
		||||
 * @return pointer to a #mavl struct. If the return value is NULL something
 | 
			
		||||
 * went wrong, and you should consult errno to get details.
 | 
			
		||||
 */
 | 
			
		||||
struct mavl *mavl_create(int (*cmp) (const void *, const void  *),
 | 
			
		||||
			       void (*del) (void *), size_t data_size)
 | 
			
		||||
{
 | 
			
		||||
	struct mavl *t = malloc(sizeof(struct mavl));
 | 
			
		||||
	if (!t)
 | 
			
		||||
		return NULL;
 | 
			
		||||
	t->root = NULL;
 | 
			
		||||
	t->count = 0;
 | 
			
		||||
	t->cmp = cmp;
 | 
			
		||||
	t->del = del;
 | 
			
		||||
	t->data_size=data_size;
 | 
			
		||||
	return t;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,248 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
void mavlnode_destroy(struct mavl *t, struct mavlnode *n)
 | 
			
		||||
{
 | 
			
		||||
	if (t->del) {
 | 
			
		||||
		t->del(mavlnode_dataptr(n));
 | 
			
		||||
	}
 | 
			
		||||
	free(n);
 | 
			
		||||
	t->count--;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void rot_rl(struct mavlnode *n, struct mavlnode **parent)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *tmp;
 | 
			
		||||
	*parent = n->right->left;
 | 
			
		||||
	n->right->left = (*parent)->right;
 | 
			
		||||
	(*parent)->right = n->right;
 | 
			
		||||
	tmp = (*parent)->left;
 | 
			
		||||
	(*parent)->left = n;
 | 
			
		||||
	n->right = tmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void rot_lr(struct mavlnode *n, struct mavlnode **parent)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *tmp;
 | 
			
		||||
	*parent = n->left->right;
 | 
			
		||||
	n->left->right = (*parent)->left;
 | 
			
		||||
	(*parent)->left = n->left;
 | 
			
		||||
	tmp = (*parent)->right;
 | 
			
		||||
	(*parent)->right = n;
 | 
			
		||||
	n->left = tmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void rot_l(struct mavlnode *n, struct mavlnode **parent)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *tmp;
 | 
			
		||||
	*parent = n->right;
 | 
			
		||||
	tmp = n->right->left;
 | 
			
		||||
	n->right->left = n;
 | 
			
		||||
	n->right = tmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void rot_r(struct mavlnode *n, struct mavlnode **parent)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *tmp;
 | 
			
		||||
	*parent = n->left;
 | 
			
		||||
	tmp = n->left->right;
 | 
			
		||||
	n->left->right = n;
 | 
			
		||||
	n->left = tmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static int adj_bal_l(struct mavlnode *n, struct mavlnode **parent)
 | 
			
		||||
{
 | 
			
		||||
	if (n->right->bal == 1) {
 | 
			
		||||
		n->bal = 0;
 | 
			
		||||
		n->right->bal = 0;
 | 
			
		||||
		rot_l(n, parent);
 | 
			
		||||
		return 1;
 | 
			
		||||
	} else if (n->right->bal == 0) {
 | 
			
		||||
		n->bal = 1;
 | 
			
		||||
		n->right->bal = -1;
 | 
			
		||||
		rot_l(n, parent);
 | 
			
		||||
		return 0;
 | 
			
		||||
	} else if (n->right->bal == -1) {
 | 
			
		||||
		n->bal = 0;
 | 
			
		||||
		n->right->bal = 0;
 | 
			
		||||
		n->right->left->bal = 0;
 | 
			
		||||
		rot_rl(n, parent);
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return -11;		/* that should never happen */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int adj_bal_r(struct mavlnode *n, struct mavlnode **parent)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	if (n->left->bal == -1) {
 | 
			
		||||
		n->bal = 0;
 | 
			
		||||
		n->left->bal = 0;
 | 
			
		||||
		rot_r(n, parent);
 | 
			
		||||
		return 1;
 | 
			
		||||
	} else if (n->left->bal == 0) {
 | 
			
		||||
		n->bal = -1;
 | 
			
		||||
		n->left->bal = 1;
 | 
			
		||||
		rot_r(n, parent);
 | 
			
		||||
		return 0;
 | 
			
		||||
	} else if (n->left->bal == 1) {
 | 
			
		||||
		n->bal = 0;
 | 
			
		||||
		n->left->bal = 0;
 | 
			
		||||
		n->left->right->bal = 0;
 | 
			
		||||
		rot_lr(n, parent);
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
	return -11;		/* that should never happen */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static int mavl_del_lo(mavl_t t, struct mavlnode **parent, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *n = *parent;
 | 
			
		||||
 | 
			
		||||
	if (n->left != 0) {
 | 
			
		||||
		int bal = mavl_del_lo(t, &n->left, data);
 | 
			
		||||
		n->bal += bal;
 | 
			
		||||
		if (n->bal == 1) {
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
		if (n->bal != 2)
 | 
			
		||||
			return bal;
 | 
			
		||||
		adj_bal_l(n, parent);
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* found the lowest element */
 | 
			
		||||
 | 
			
		||||
	*parent = n->right;
 | 
			
		||||
/*	*data = n->data;*/
 | 
			
		||||
	memcpy(data,mavlnode_dataptr(n),t->data_size);
 | 
			
		||||
	
 | 
			
		||||
	free(n);
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	if (n->right) {
 | 
			
		||||
		free(n);
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
	free(n);
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int mavl_del0(struct mavl *t, struct mavlnode **parent, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *n = *parent;
 | 
			
		||||
	int rc;
 | 
			
		||||
	int bal;
 | 
			
		||||
	rc = t->cmp(data, mavlnode_dataptr(n));
 | 
			
		||||
 | 
			
		||||
	if (rc == 0) {
 | 
			
		||||
		if (n->right == 0 && n->left == 0) {
 | 
			
		||||
			*parent = 0;
 | 
			
		||||
			mavlnode_destroy(t, n);
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (n->right && n->left == 0) {
 | 
			
		||||
			*parent = n->right;
 | 
			
		||||
			mavlnode_destroy(t, n);
 | 
			
		||||
			return 1;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (n->left && n->right == 0) {
 | 
			
		||||
			mavlnode_destroy(t, n);
 | 
			
		||||
			*parent = n->left;
 | 
			
		||||
			return 1;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/* node has two childs */
 | 
			
		||||
 | 
			
		||||
		if (t->del) {
 | 
			
		||||
			t->del(mavlnode_dataptr(n));
 | 
			
		||||
		}
 | 
			
		||||
		t->count--;
 | 
			
		||||
		bal = mavl_del_lo(t,&n->right, mavlnode_dataptr(n));
 | 
			
		||||
		n->bal -= bal;
 | 
			
		||||
		if (n->bal == -1)
 | 
			
		||||
			return 0;
 | 
			
		||||
 | 
			
		||||
		if (n->bal != -2)
 | 
			
		||||
			return bal;
 | 
			
		||||
 | 
			
		||||
		return adj_bal_r(n, parent);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (rc < 0) {
 | 
			
		||||
		if (n->left) {
 | 
			
		||||
			bal = mavl_del0(t, &n->left, data);
 | 
			
		||||
			if (bal == 2)
 | 
			
		||||
				return 2;
 | 
			
		||||
 | 
			
		||||
			n->bal += bal;
 | 
			
		||||
			if (n->bal == 1)
 | 
			
		||||
				return 0;
 | 
			
		||||
 | 
			
		||||
			if (n->bal != 2)
 | 
			
		||||
				return bal;
 | 
			
		||||
 | 
			
		||||
			return adj_bal_l(n, parent);
 | 
			
		||||
		}
 | 
			
		||||
		return 2;	/* not found */
 | 
			
		||||
	} else {		/* rc must be > 0 */
 | 
			
		||||
		if (n->right) {
 | 
			
		||||
			bal = mavl_del0(t, &n->right, data);
 | 
			
		||||
			if (bal == 2)
 | 
			
		||||
				return 2;
 | 
			
		||||
 | 
			
		||||
			n->bal -= bal;
 | 
			
		||||
			if (n->bal == -1)
 | 
			
		||||
				return 0;
 | 
			
		||||
 | 
			
		||||
			if (n->bal != -2)
 | 
			
		||||
				return bal;
 | 
			
		||||
 | 
			
		||||
			return adj_bal_r(n, parent);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		return 2;	/* not found */
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *mavl_del(struct mavl *t, const void *data)
 | 
			
		||||
{
 | 
			
		||||
	void *d;
 | 
			
		||||
	int rc;
 | 
			
		||||
	
 | 
			
		||||
	if (!t->root)
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	d = (void*)data;
 | 
			
		||||
	rc = mavl_del0(t, &t->root, d);
 | 
			
		||||
	if (rc == 2)
 | 
			
		||||
		return NULL;
 | 
			
		||||
	return (void*)data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,44 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file
 | 
			
		||||
 * @brief Implements mavl_del_all 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
static void mavl_del_all0(struct mavl *t ,struct mavlnode * n)
 | 
			
		||||
{
 | 
			
		||||
	if (!n)
 | 
			
		||||
		return;
 | 
			
		||||
	mavl_del_all0(t,n->left);
 | 
			
		||||
	mavl_del_all0(t,n->right);
 | 
			
		||||
	mavlnode_destroy(t,n);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Delete all elemets of a mavl object
 | 
			
		||||
 * @parm t mavl object 
 | 
			
		||||
 */
 | 
			
		||||
void mavl_del_all(struct mavl *t)
 | 
			
		||||
{
 | 
			
		||||
	mavl_del_all0(t,t->root);
 | 
			
		||||
	t->root=NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,9 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
void mavl_destroy(struct mavl *t)
 | 
			
		||||
{
 | 
			
		||||
	mavl_del_all(t);
 | 
			
		||||
	free (t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,39 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
int mavl_foreach_rl(struct mavlnode *n, int (*callback)(void *,void *),void *cbpriv)
 | 
			
		||||
{
 | 
			
		||||
	if (!n)
 | 
			
		||||
		return 1;
 | 
			
		||||
	if (!mavl_foreach_rl(n->right,callback,cbpriv))
 | 
			
		||||
		return 0;
 | 
			
		||||
	if (!callback(cbpriv,mavlnode_dataptr(n)))
 | 
			
		||||
		return 0;
 | 
			
		||||
	return mavl_foreach_rl(n->left,callback,cbpriv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mavl_foreach(struct mavl *t, int (*callback)(void *,void *),void * cbpriv,int dir)
 | 
			
		||||
{
 | 
			
		||||
	if (dir)
 | 
			
		||||
		mavl_foreach_lr(t->root,callback,cbpriv);
 | 
			
		||||
	else
 | 
			
		||||
		mavl_foreach_rl(t->root,callback,cbpriv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,17 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int mavl_foreach_lr(struct mavlnode *n, int (*callback)(void *,void *),void *cbpriv)
 | 
			
		||||
{
 | 
			
		||||
	if (!n)
 | 
			
		||||
		return 1;
 | 
			
		||||
	if (!mavl_foreach_lr(n->left,callback,cbpriv))
 | 
			
		||||
		return 0;
 | 
			
		||||
	if (!callback(cbpriv,mavlnode_dataptr(n)))
 | 
			
		||||
		return 0;
 | 
			
		||||
	return mavl_foreach_lr(n->right,callback,cbpriv);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
void mavl_freeptr(void *ptr){
 | 
			
		||||
	free( *((void**)ptr) );
 | 
			
		||||
}
 | 
			
		||||
@ -1,47 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file
 | 
			
		||||
 * @brief Implementation of mavl_get
 | 
			
		||||
 */ 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get an AVL tree element.
 | 
			
		||||
 * @param t pointer to mavl_t
 | 
			
		||||
 * @param data Element to get
 | 
			
		||||
 * @return pointer to element or NULL if not found. 
 | 
			
		||||
 */ 
 | 
			
		||||
void * mavl_get(struct mavl *t ,const void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *n = t->root;
 | 
			
		||||
	while(n){
 | 
			
		||||
		int rc=t->cmp(data,mavlnode_dataptr(n));
 | 
			
		||||
		if (rc==0)
 | 
			
		||||
			return mavlnode_dataptr(n);
 | 
			
		||||
		if (rc<0)
 | 
			
		||||
			n=n->left;
 | 
			
		||||
		else
 | 
			
		||||
			n=n->right;
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,49 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void * mavl_get_ext(struct mavl *t ,const void *search, int mode)
 | 
			
		||||
{
 | 
			
		||||
	
 | 
			
		||||
	struct mavlnode *n,/**lastl,*/*last;
 | 
			
		||||
	last = NULL; /*lastl=NULL;*/
 | 
			
		||||
	n = t->root;
 | 
			
		||||
	while(n){
 | 
			
		||||
		int rc;
 | 
			
		||||
		
 | 
			
		||||
		rc = t->cmp(search,mavlnode_dataptr(n));
 | 
			
		||||
		
 | 
			
		||||
		/*printf("Compare: %s %s = %d\n",c1->key,c2->key, rc);*/
 | 
			
		||||
		
 | 
			
		||||
		if (rc==0){
 | 
			
		||||
			return mavlnode_dataptr(n);
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (rc<0){
 | 
			
		||||
			if (mode == MAVL_FIND_FIRST)
 | 
			
		||||
				last = n;
 | 
			
		||||
			if (n->left==NULL){
 | 
			
		||||
				if (last == NULL)
 | 
			
		||||
					return NULL;
 | 
			
		||||
				return mavlnode_dataptr(last);
 | 
			
		||||
				
 | 
			
		||||
			}
 | 
			
		||||
			n=n->left;
 | 
			
		||||
		}
 | 
			
		||||
		else{
 | 
			
		||||
			if (mode == MAVL_FIND_LAST)
 | 
			
		||||
				last=n;
 | 
			
		||||
			
 | 
			
		||||
			if(n->right==NULL){
 | 
			
		||||
				if (last == NULL)
 | 
			
		||||
					return NULL;
 | 
			
		||||
				return mavlnode_dataptr(last);
 | 
			
		||||
				
 | 
			
		||||
			}
 | 
			
		||||
			n=n->right;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,36 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct mavlnode * mavlnode_get(struct mavl *t ,void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *n = t->root;
 | 
			
		||||
	while(n){
 | 
			
		||||
		int rc=t->cmp(data,mavlnode_dataptr(n));
 | 
			
		||||
		if (rc==0)
 | 
			
		||||
			return n;
 | 
			
		||||
		if (rc<0)
 | 
			
		||||
			n=n->left;
 | 
			
		||||
		else
 | 
			
		||||
			n=n->right;
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
@ -1,18 +0,0 @@
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
struct mavlnode * mavl_get_node_cmp(struct mavl *t ,void *data,
 | 
			
		||||
	int ( *cmp ) ( const void *, const void * ))
 | 
			
		||||
{
 | 
			
		||||
	struct mavlnode *n = t->root;
 | 
			
		||||
	while(n){
 | 
			
		||||
		int rc=cmp(data,mavlnode_dataptr(n));
 | 
			
		||||
		if (rc==0)
 | 
			
		||||
			return n;
 | 
			
		||||
		if (rc<0)
 | 
			
		||||
			n=n->left;
 | 
			
		||||
		else
 | 
			
		||||
			n=n->right;
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
@ -1,10 +1,11 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
#include "mavltypes.h"
 | 
			
		||||
 | 
			
		||||
void * mavl_get_ptr(mavl_t tree, void * search)
 | 
			
		||||
{
 | 
			
		||||
	void * result;
 | 
			
		||||
	
 | 
			
		||||
	result = mavl_find(tree,&search);
 | 
			
		||||
	result = mavl_get(tree,&search);
 | 
			
		||||
	if (result)
 | 
			
		||||
		return *(void**)result;
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
#include "mavltypes.h"
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
 * @file
 | 
			
		||||
@ -36,8 +36,8 @@ static void mavlnode_move(mavl_t m,mavl_t t, struct mavlnode *n)
 | 
			
		||||
		memcpy(mavlnode_dataptr(mn),mavlnode_dataptr(n),t->data_size);
 | 
			
		||||
	}
 | 
			
		||||
	else{
 | 
			
		||||
		/*mavl_add(m,&n->data);*/
 | 
			
		||||
		mavl_add(m,mavlnode_dataptr(n),NULL);
 | 
			
		||||
		/*mavl_insert(m,&n->data);*/
 | 
			
		||||
		mavl_insert(m,mavlnode_dataptr(n),NULL);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	free(n);
 | 
			
		||||
@ -50,8 +50,8 @@ static void mavl_merge0(mavl_t m, mavl_t t ,struct mavlnode * n)
 | 
			
		||||
{
 | 
			
		||||
	if (!n)
 | 
			
		||||
		return;
 | 
			
		||||
	mavl_merge0(m,t,n->left);
 | 
			
		||||
	mavl_merge0(m,t,n->right);
 | 
			
		||||
	mavl_merge0(m,t,n->s[0]);
 | 
			
		||||
	mavl_merge0(m,t,n->s[1]);
 | 
			
		||||
	mavlnode_move(m,t,n);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,7 @@
 | 
			
		||||
void *mavl_replace(struct mavl *t,const void  *data, int * replaced){
 | 
			
		||||
	
 | 
			
		||||
	int exists;
 | 
			
		||||
	void * add = mavl_add(t,data,&exists);
 | 
			
		||||
	void * add = mavl_insert(t,data,&exists);
 | 
			
		||||
	
 | 
			
		||||
	if (replaced != NULL){
 | 
			
		||||
		*replaced = exists;
 | 
			
		||||
@ -31,7 +31,7 @@ void *mavl_replace(struct mavl *t,const void  *data, int * replaced){
 | 
			
		||||
//		return &node->data;
 | 
			
		||||
		return mavlnode_dataptr(node);
 | 
			
		||||
	}
 | 
			
		||||
	return mavl_add(t,data);
 | 
			
		||||
	return mavl_insert(t,data);
 | 
			
		||||
*/
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,12 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
void *mavl_replace_data(struct mavl *t, void *data, int len)
 | 
			
		||||
{
 | 
			
		||||
	void *df = mavl_get(t, data);
 | 
			
		||||
	if (!df)
 | 
			
		||||
		return NULL;
 | 
			
		||||
	memcpy(df, data, len);
 | 
			
		||||
	return df;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,14 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the element, where AVL Iterator currently is positioned.
 | 
			
		||||
 * @param i AVL Iterator
 | 
			
		||||
 * @return element or NULL if not found.
 | 
			
		||||
 */
 | 
			
		||||
void * mavliter_get(mavliter_t *i)
 | 
			
		||||
{
 | 
			
		||||
	if (!i->cur)
 | 
			
		||||
		return NULL;
 | 
			
		||||
		
 | 
			
		||||
	return mavlnode_dataptr(i->cur);
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
#include "mavltypes.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the element, where AVL Iterator currently is positioned.
 | 
			
		||||
 | 
			
		||||
@ -1,18 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Init an AVL Tree Iterator.
 | 
			
		||||
 *
 | 
			
		||||
 * After initialization #mavliter_next would return the first element.
 | 
			
		||||
 * The behavior of #mavliter_get would still be undefined.
 | 
			
		||||
 * @param i AVL Iterator to initialize
 | 
			
		||||
 * @param t correspondending AVL Tree
 | 
			
		||||
 *
 | 
			
		||||
 * @See mavliter_t,
 | 
			
		||||
 */
 | 
			
		||||
void mavliter_init ( mavliter_t *i, mavl_t t )
 | 
			
		||||
{
 | 
			
		||||
	i->root = t->root;
 | 
			
		||||
	i->stack_ptr = 0;
 | 
			
		||||
	i->cmp = t->cmp;
 | 
			
		||||
}
 | 
			
		||||
@ -1,68 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *@file
 | 
			
		||||
 *@brief Implementation of mavliter_next
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the next element within an AVL Tree.
 | 
			
		||||
 * @param i pointer to AVL Iterator
 | 
			
		||||
 * @return the element or NULL if there is no next elemeent.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
void * mavliter_next ( mavliter_t *i )
 | 
			
		||||
{
 | 
			
		||||
	while ( i->stack_ptr ) {
 | 
			
		||||
		i->stack_ptr--;
 | 
			
		||||
		i->cur = i->stack[i->stack_ptr];
 | 
			
		||||
		
 | 
			
		||||
		if ( !i->cur )
 | 
			
		||||
			continue;
 | 
			
		||||
			
 | 
			
		||||
		if ( ( i->stack_ptr ) & 1 ) {
 | 
			
		||||
			/*return &i->cur->data;*/
 | 
			
		||||
			return mavlnode_dataptr ( i->cur );
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if ( !i->cur ) {
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	while ( i->cur->left ) {
 | 
			
		||||
		/* push right branch */
 | 
			
		||||
		i->stack[i->stack_ptr++] = i->cur->right;
 | 
			
		||||
		
 | 
			
		||||
		/* push node */
 | 
			
		||||
		i->stack[i->stack_ptr++] = i->cur;
 | 
			
		||||
		
 | 
			
		||||
		i->cur = i->cur->left;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	i->stack[i->stack_ptr++] = i->cur->right;
 | 
			
		||||
	
 | 
			
		||||
	/*	return &i->cur->data;*/
 | 
			
		||||
	return mavlnode_dataptr ( i->cur );
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@ -1,69 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *@file
 | 
			
		||||
 *@brief Implementation of mavliter_seek
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set an AVL Iterator to a specific position.
 | 
			
		||||
 * @param i AVL Iterator
 | 
			
		||||
 * @param d element to search for
 | 
			
		||||
 * @return element found or NULL if not found
 | 
			
		||||
 */
 | 
			
		||||
void * mavliter_seek(mavliter_t *i,void *d)
 | 
			
		||||
{
 | 
			
		||||
	int rc;
 | 
			
		||||
	if (!i->root)
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	i->cur=i->root;
 | 
			
		||||
	i->stack_ptr=0;
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
	while(i->cur) {
 | 
			
		||||
 | 
			
		||||
/*		rc = i->cmp(d,&i->cur->data); */
 | 
			
		||||
		rc = i->cmp(d,mavlnode_dataptr(i->cur));
 | 
			
		||||
		if (rc==0){
 | 
			
		||||
			i->stack[i->stack_ptr++]=i->cur->right;
 | 
			
		||||
			i->stack[i->stack_ptr++]=i->cur;
 | 
			
		||||
			return mavliter_next(i);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (rc<0) {
 | 
			
		||||
			i->stack[i->stack_ptr++]=i->cur->right;
 | 
			
		||||
			i->stack[i->stack_ptr++]=i->cur;
 | 
			
		||||
 | 
			
		||||
			i->cur=i->cur->left;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		if (rc>0) {
 | 
			
		||||
 | 
			
		||||
			i->cur=i->cur->right;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,8 +0,0 @@
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
void * mavliter_seek_set ( struct mavliter *i )
 | 
			
		||||
{
 | 
			
		||||
	i->stack_ptr = 0;
 | 
			
		||||
	i->cur = i->root;
 | 
			
		||||
	return mavliter_next ( i );
 | 
			
		||||
}
 | 
			
		||||
@ -163,7 +163,7 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
 | 
			
		||||
//	if (actions_registered_cb)
 | 
			
		||||
//		actions_registered_cb(capwap_mod, bindings_mod, &(cached_set->actions));
 | 
			
		||||
*/
 | 
			
		||||
	mavl_add_ptr(msgset_cache, cached_set);
 | 
			
		||||
	mavl_insert_ptr(msgset_cache, cached_set);
 | 
			
		||||
	return cached_set->msgset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -228,7 +228,7 @@ struct cw_Mod *cw_mod_load(const char *mod_name, mavl_t global_cfg, int role)
 | 
			
		||||
	memset(&search, 0, sizeof(search));
 | 
			
		||||
	search.name = mod_name;
 | 
			
		||||
 | 
			
		||||
	mod = mavl_find_ptr(mods_loaded, &search);
 | 
			
		||||
	mod = mavl_get_ptr(mods_loaded, &search);
 | 
			
		||||
	if (mod) {
 | 
			
		||||
		cw_dbg(DBG_MOD, "MOD: Module already loaded '%s'", mod_name);
 | 
			
		||||
		return mod;
 | 
			
		||||
@ -267,7 +267,7 @@ struct cw_Mod *cw_mod_load(const char *mod_name, mavl_t global_cfg, int role)
 | 
			
		||||
 | 
			
		||||
	mod->dll_handle = handle;
 | 
			
		||||
 | 
			
		||||
	if (!mavl_add_ptr(mods_loaded, mod)) {
 | 
			
		||||
	if (!mavl_insert_ptr(mods_loaded, mod)) {
 | 
			
		||||
		dlclose(handle);
 | 
			
		||||
		cw_log(LOG_ERR, "Can' add module %s", mod_name);
 | 
			
		||||
		goto errX;
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@
 | 
			
		||||
 | 
			
		||||
#include "msgset.h"
 | 
			
		||||
#include "ktv.h"
 | 
			
		||||
#include "mavltypes.h"
 | 
			
		||||
 | 
			
		||||
static int cmp_cw_elemhandler_by_id(const void *elem1, const void *elem2)
 | 
			
		||||
{
 | 
			
		||||
@ -148,6 +149,9 @@ struct cw_MsgSet *cw_msgset_create()
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	set->types_tree = cw_ktv_create_types_tree();
 | 
			
		||||
	
 | 
			
		||||
	printf("TYPES TREE %p\n",set->types_tree);
 | 
			
		||||
 | 
			
		||||
	if (set->types_tree == NULL){
 | 
			
		||||
		cw_msgset_destroy(set);
 | 
			
		||||
		return NULL;
 | 
			
		||||
@ -170,7 +174,7 @@ struct cw_ElemHandler *cw_msgset_get_elemhandler(struct cw_MsgSet *set,
 | 
			
		||||
	search.proto = proto;
 | 
			
		||||
	search.vendor = vendor;
 | 
			
		||||
	search.id = id;
 | 
			
		||||
	return mavl_find(set->handlers_by_id, &search);
 | 
			
		||||
	return mavl_get(set->handlers_by_id, &search);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -197,7 +201,7 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
/*		if (handler->type != NULL){
 | 
			
		||||
			if (mavl_add_ptr( set->types_tree, handler->type ) == NULL){
 | 
			
		||||
			if (mavl_insert_ptr( set->types_tree, handler->type ) == NULL){
 | 
			
		||||
				cw_log(LOG_ERR, "Can't add type from handler: %s", strerror(errno));
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
@ -290,7 +294,10 @@ int cw_msgset_add(struct cw_MsgSet *set,
 | 
			
		||||
 | 
			
		||||
		/* add the message */
 | 
			
		||||
		search.type = msgdef->type;
 | 
			
		||||
		msg = mavl_add(set->msgdata, &search, &exists);
 | 
			
		||||
 | 
			
		||||
		printf("Msg type name %s\n",msgdef->name);
 | 
			
		||||
 | 
			
		||||
		msg = mavl_insert(set->msgdata, &search, &exists);
 | 
			
		||||
		if (msg == NULL) {
 | 
			
		||||
			cw_log(LOG_ERR, "Can't create messae");
 | 
			
		||||
			return 0;
 | 
			
		||||
@ -331,6 +338,10 @@ int cw_msgset_add(struct cw_MsgSet *set,
 | 
			
		||||
	{
 | 
			
		||||
		mavliter_t it;
 | 
			
		||||
		cw_dbg(DBG_MOD,"  Known types:");
 | 
			
		||||
 | 
			
		||||
		printf("TYPES TREE ITER %p\n",set->types_tree);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		mavliter_init(&it,set->types_tree);
 | 
			
		||||
		mavliter_foreach(&it){
 | 
			
		||||
			struct cw_Type * t = mavliter_get_ptr(&it);
 | 
			
		||||
@ -377,5 +388,5 @@ struct cw_MsgData *cw_msgset_get_msgdata(struct cw_MsgSet *set, int type)
 | 
			
		||||
{
 | 
			
		||||
	struct cw_MsgData search;
 | 
			
		||||
	search.type = type;
 | 
			
		||||
	return mavl_find(set->msgdata, &search);
 | 
			
		||||
	return mavl_get(set->msgdata, &search);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,7 @@ cw_strheap_t cw_strheap_create()
 | 
			
		||||
const char * cw_strheap_add(cw_strheap_t t, struct cw_StrListElem *s)
 | 
			
		||||
{
 | 
			
		||||
	mavl_del(t,s);
 | 
			
		||||
	return mavl_add(t,s,NULL);
 | 
			
		||||
	return mavl_insert(t,s,NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int cw_strheap_register_strings(cw_strheap_t h, struct cw_StrListElem *s) 
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,7 @@
 | 
			
		||||
 | 
			
		||||
#include "mod_capwap.h"
 | 
			
		||||
 | 
			
		||||
#include "cw/mavltypes.h"
 | 
			
		||||
 | 
			
		||||
static int postprocess_join_request(struct conn *conn);
 | 
			
		||||
 | 
			
		||||
@ -836,10 +837,10 @@ struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){
 | 
			
		||||
	
 | 
			
		||||
	cw_msgset_add_states(set,statemachine_states);
 | 
			
		||||
	
 | 
			
		||||
	mavl_add_ptr(set->types_tree,CW_TYPE_BSTR16);
 | 
			
		||||
	mavl_add_ptr(set->types_tree,CW_TYPE_BYTE);
 | 
			
		||||
	mavl_add_ptr(set->types_tree,CW_TYPE_DWORD);
 | 
			
		||||
	mavl_add_ptr(set->types_tree,CW_TYPE_WORD);
 | 
			
		||||
	mavl_insert_ptr(set->types_tree,CW_TYPE_BSTR16);
 | 
			
		||||
	mavl_insert_ptr(set->types_tree,CW_TYPE_BYTE);
 | 
			
		||||
	mavl_insert_ptr(set->types_tree,CW_TYPE_DWORD);
 | 
			
		||||
	mavl_insert_ptr(set->types_tree,CW_TYPE_WORD);
 | 
			
		||||
 | 
			
		||||
	cw_dbg(DBG_INFO,"CAPWAP: Done register messages");
 | 
			
		||||
	return set;
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "cw/cw.h"
 | 
			
		||||
#include "cw/mavl.h"
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -5,9 +5,9 @@ OBJDIR=./o
 | 
			
		||||
LIBDIR		:= ../../lib
 | 
			
		||||
LIBARCHDIR	:= $(LIBDIR)/$(KERNEL)/$(ARCH)
 | 
			
		||||
 | 
			
		||||
CFLAGS+=-I../ -DUSE_OPENSSL
 | 
			
		||||
LDFLAGS=-L$(LIBARCHDIR) 
 | 
			
		||||
LIBS+=-lcw -lnettle -lssl -ldl 
 | 
			
		||||
CFLAGS+=-I../ -DUSE_OPENSSL -I../contrib/openssl-1.1.1f/include/ -I/home/tube/v/rsrch/libmavl
 | 
			
		||||
LDFLAGS+=-L$(LIBARCHDIR) 
 | 
			
		||||
LIBS+=-lcw -lnettle -lssl -lcrypto -ldl -lpthread -lmavl
 | 
			
		||||
 | 
			
		||||
SOURCES=\
 | 
			
		||||
     	wtp_main.c\
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,7 @@
 | 
			
		||||
#include "cw/log.h"
 | 
			
		||||
#include "cw/dbg.h"
 | 
			
		||||
#include "cw/sock.h"
 | 
			
		||||
#include "cw/mavl.h"
 | 
			
		||||
#include "mavl.h"
 | 
			
		||||
 | 
			
		||||
#include "wtp.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@
 | 
			
		||||
 | 
			
		||||
#include "cw/dtls.h"
 | 
			
		||||
#include "wtp.h"
 | 
			
		||||
#include "cw/mavltypes.h"
 | 
			
		||||
 | 
			
		||||
#define MAX_MODS 32
 | 
			
		||||
struct bootcfg{
 | 
			
		||||
@ -127,7 +128,7 @@ int main (int argc, char **argv)
 | 
			
		||||
	/* create a types tree with default types */
 | 
			
		||||
	types_tree = cw_ktv_create_types_tree();
 | 
			
		||||
	for (ti=CW_KTV_STD_TYPES;*ti;ti++){
 | 
			
		||||
		mavl_add_ptr(types_tree,*ti);
 | 
			
		||||
		mavl_insert_ptr(types_tree,*ti);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* read the initial config file */
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user