From 8d09b1d596e0894d8bd9894b0975f9d3a40aa2e6 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Mon, 18 Jul 2022 01:15:17 +0200 Subject: [PATCH] Moved out most ob mavl_ into libmavl. Current libmavl is here: https://svn.planix.org/rsrch/trunk/libmavl --- src/cw/Makefile | 41 ++-- src/cw/conn_process_packet.c | 4 +- src/cw/connlist.c | 4 +- src/cw/cw_ktv_add.c | 5 +- src/cw/cw_ktv_add_from_str.c | 2 +- src/cw/cw_ktv_idx_get.c | 8 +- src/cw/cw_process_element.c | 2 +- src/cw/dtls_openssl.c | 25 ++- src/cw/dtls_openssl_bio.c | 2 +- src/cw/dtls_openssl_connect.c | 4 +- src/cw/intavltree.c | 2 +- src/cw/intavltree.h | 2 +- src/cw/ktv.h | 4 +- src/cw/mavl.h | 298 ------------------------- src/cw/mavl_add.c | 233 ------------------- src/cw/mavl_add_ptr.c | 9 - src/cw/mavl_cmpstr.c | 1 + src/cw/mavl_create.c | 50 ----- src/cw/mavl_del.c | 248 -------------------- src/cw/mavl_del_all.c | 44 ---- src/cw/mavl_destroy.c | 9 - src/cw/mavl_foreach.c | 39 ---- src/cw/mavl_foreach_lr.c | 17 -- src/cw/mavl_freeptr.c | 5 - src/cw/mavl_get.c | 47 ---- src/cw/mavl_get_ext.c | 49 ---- src/cw/mavl_get_node.c | 36 --- src/cw/mavl_get_node_cmp..c | 18 -- src/cw/mavl_get_ptr.c | 3 +- src/cw/mavl_merge.c | 10 +- src/cw/mavl_replace.c | 4 +- src/cw/mavl_replace_data.c | 12 - src/cw/mavliter_get.c | 14 -- src/cw/mavliter_get_ptr.c | 1 + src/cw/mavliter_init.c | 18 -- src/cw/mavliter_next.c | 68 ------ src/cw/mavliter_seek.c | 69 ------ src/cw/mavliter_seek_set.c | 8 - src/cw/mod.c | 6 +- src/cw/msgset.c | 19 +- src/cw/strheap.c | 2 +- src/mod/capwap/capwap_actions_ac.c | 9 +- src/mod/capwap/capwap_out_ac_ip_list.c | 2 +- src/wtp/Makefile | 6 +- src/wtp/join.c | 2 +- src/wtp/wtp_main.c | 3 +- 46 files changed, 94 insertions(+), 1370 deletions(-) delete mode 100644 src/cw/mavl.h delete mode 100644 src/cw/mavl_add.c delete mode 100644 src/cw/mavl_add_ptr.c delete mode 100644 src/cw/mavl_create.c delete mode 100644 src/cw/mavl_del.c delete mode 100644 src/cw/mavl_del_all.c delete mode 100644 src/cw/mavl_destroy.c delete mode 100644 src/cw/mavl_foreach.c delete mode 100644 src/cw/mavl_foreach_lr.c delete mode 100644 src/cw/mavl_freeptr.c delete mode 100644 src/cw/mavl_get.c delete mode 100644 src/cw/mavl_get_ext.c delete mode 100644 src/cw/mavl_get_node.c delete mode 100644 src/cw/mavl_get_node_cmp..c delete mode 100644 src/cw/mavl_replace_data.c delete mode 100644 src/cw/mavliter_get.c delete mode 100644 src/cw/mavliter_init.c delete mode 100644 src/cw/mavliter_next.c delete mode 100644 src/cw/mavliter_seek.c delete mode 100644 src/cw/mavliter_seek_set.c diff --git a/src/cw/Makefile b/src/cw/Makefile index bb34fba1..163a16a5 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -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) diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index d1014a03..f67abdc9 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -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; diff --git a/src/cw/connlist.c b/src/cw/connlist.c index 2722711f..c07b5316 100644 --- a/src/cw/connlist.c +++ b/src/cw/connlist.c @@ -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 ) diff --git a/src/cw/cw_ktv_add.c b/src/cw/cw_ktv_add.c index 8cf1c721..66e81c13 100644 --- a/src/cw/cw_ktv_add.c +++ b/src/cw/cw_ktv_add.c @@ -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 */ diff --git a/src/cw/cw_ktv_add_from_str.c b/src/cw/cw_ktv_add_from_str.c index 7b1cd240..5fdf2a48 100644 --- a/src/cw/cw_ktv_add_from_str.c +++ b/src/cw/cw_ktv_add_from_str.c @@ -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 */ diff --git a/src/cw/cw_ktv_idx_get.c b/src/cw/cw_ktv_idx_get.c index 022968ee..9f7ec74a 100644 --- a/src/cw/cw_ktv_idx_get.c +++ b/src/cw/cw_ktv_idx_get.c @@ -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; diff --git a/src/cw/cw_process_element.c b/src/cw/cw_process_element.c index e08630a1..84f5fdbc 100644 --- a/src/cw/cw_process_element.c +++ b/src/cw/cw_process_element.c @@ -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); diff --git a/src/cw/dtls_openssl.c b/src/cw/dtls_openssl.c index be532375..d4afea05 100644 --- a/src/cw/dtls_openssl.c +++ b/src/cw/dtls_openssl.c @@ -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,7 +319,17 @@ 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){ dtls_openssl_log_error(0,rc,"DTLS setup cipher error:"); @@ -372,7 +382,6 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS rc = SSL_CTX_load_verify_locations(d->ctx,"../../ssl/root-ca.pem",NULL); - /*// SSL_CTX_set_session_cache_mode(d->ctx, SSL_SESS_CACHE_BOTH);*/ @@ -381,10 +390,10 @@ struct dtls_openssl_data * dtls_openssl_data_create(struct conn * conn, const SS 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); diff --git a/src/cw/dtls_openssl_bio.c b/src/cw/dtls_openssl_bio.c index 27339292..6a6c50a3 100644 --- a/src/cw/dtls_openssl_bio.c +++ b/src/cw/dtls_openssl_bio.c @@ -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; diff --git a/src/cw/dtls_openssl_connect.c b/src/cw/dtls_openssl_connect.c index c56ba430..1384b26e 100644 --- a/src/cw/dtls_openssl_connect.c +++ b/src/cw/dtls_openssl_connect.c @@ -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!"); diff --git a/src/cw/intavltree.c b/src/cw/intavltree.c index 8332d442..ad11937a 100644 --- a/src/cw/intavltree.c +++ b/src/cw/intavltree.c @@ -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); } diff --git a/src/cw/intavltree.h b/src/cw/intavltree.h index c47a37f8..7b88a473 100644 --- a/src/cw/intavltree.h +++ b/src/cw/intavltree.h @@ -1,7 +1,7 @@ #ifndef __INTAVLTREE_H #define __INTAVLTREE_H -#include "mavl.h" +#include extern struct mavl * intavltree_create(); typedef struct mavl * intavltree_t; diff --git a/src/cw/ktv.h b/src/cw/ktv.h index 4680d8d7..e1537720 100644 --- a/src/cw/ktv.h +++ b/src/cw/ktv.h @@ -4,7 +4,9 @@ #include #include -#include "mavl.h" +#include +#include "mavltypes.h" + #include "bstr.h" diff --git a/src/cw/mavl.h b/src/cw/mavl.h deleted file mode 100644 index 77f3d3b6..00000000 --- a/src/cw/mavl.h +++ /dev/null @@ -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 . -*/ - -/** - * @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 -#include -#include - -#include - - - -/** 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 diff --git a/src/cw/mavl_add.c b/src/cw/mavl_add.c deleted file mode 100644 index 5dc21502..00000000 --- a/src/cw/mavl_add.c +++ /dev/null @@ -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; -} diff --git a/src/cw/mavl_add_ptr.c b/src/cw/mavl_add_ptr.c deleted file mode 100644 index 00bba563..00000000 --- a/src/cw/mavl_add_ptr.c +++ /dev/null @@ -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; -} diff --git a/src/cw/mavl_cmpstr.c b/src/cw/mavl_cmpstr.c index e021d096..7e745a3c 100644 --- a/src/cw/mavl_cmpstr.c +++ b/src/cw/mavl_cmpstr.c @@ -1,4 +1,5 @@ #include "mavl.h" +#include "mavltypes.h" int mavl_cmpstr (const void *s1, const void *s2) { diff --git a/src/cw/mavl_create.c b/src/cw/mavl_create.c deleted file mode 100644 index 646c544a..00000000 --- a/src/cw/mavl_create.c +++ /dev/null @@ -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 . - -*/ - -/** - *@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; -} - - - diff --git a/src/cw/mavl_del.c b/src/cw/mavl_del.c deleted file mode 100644 index 9720e41d..00000000 --- a/src/cw/mavl_del.c +++ /dev/null @@ -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; -} - - diff --git a/src/cw/mavl_del_all.c b/src/cw/mavl_del_all.c deleted file mode 100644 index 9d1f3bc7..00000000 --- a/src/cw/mavl_del_all.c +++ /dev/null @@ -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 . - -*/ - -/** - * @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; -} - diff --git a/src/cw/mavl_destroy.c b/src/cw/mavl_destroy.c deleted file mode 100644 index 391fa649..00000000 --- a/src/cw/mavl_destroy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "mavl.h" - -void mavl_destroy(struct mavl *t) -{ - mavl_del_all(t); - free (t); -} - - diff --git a/src/cw/mavl_foreach.c b/src/cw/mavl_foreach.c deleted file mode 100644 index a599212f..00000000 --- a/src/cw/mavl_foreach.c +++ /dev/null @@ -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 . - -*/ - -#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); -} - diff --git a/src/cw/mavl_foreach_lr.c b/src/cw/mavl_foreach_lr.c deleted file mode 100644 index f1ab3695..00000000 --- a/src/cw/mavl_foreach_lr.c +++ /dev/null @@ -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); - -} - - diff --git a/src/cw/mavl_freeptr.c b/src/cw/mavl_freeptr.c deleted file mode 100644 index a1893433..00000000 --- a/src/cw/mavl_freeptr.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "mavl.h" - -void mavl_freeptr(void *ptr){ - free( *((void**)ptr) ); -} diff --git a/src/cw/mavl_get.c b/src/cw/mavl_get.c deleted file mode 100644 index aded1f56..00000000 --- a/src/cw/mavl_get.c +++ /dev/null @@ -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 . -*/ - -/** - * @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; -} - - diff --git a/src/cw/mavl_get_ext.c b/src/cw/mavl_get_ext.c deleted file mode 100644 index 53e5fbe4..00000000 --- a/src/cw/mavl_get_ext.c +++ /dev/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; -} - diff --git a/src/cw/mavl_get_node.c b/src/cw/mavl_get_node.c deleted file mode 100644 index b09bf92b..00000000 --- a/src/cw/mavl_get_node.c +++ /dev/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 . - -*/ - - -#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; -} diff --git a/src/cw/mavl_get_node_cmp..c b/src/cw/mavl_get_node_cmp..c deleted file mode 100644 index d45a2e05..00000000 --- a/src/cw/mavl_get_node_cmp..c +++ /dev/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; -} diff --git a/src/cw/mavl_get_ptr.c b/src/cw/mavl_get_ptr.c index 102a70cd..ca1ca846 100644 --- a/src/cw/mavl_get_ptr.c +++ b/src/cw/mavl_get_ptr.c @@ -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; diff --git a/src/cw/mavl_merge.c b/src/cw/mavl_merge.c index c6594faa..a9bc5189 100644 --- a/src/cw/mavl_merge.c +++ b/src/cw/mavl_merge.c @@ -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); } diff --git a/src/cw/mavl_replace.c b/src/cw/mavl_replace.c index a416abb2..3ff270c1 100644 --- a/src/cw/mavl_replace.c +++ b/src/cw/mavl_replace.c @@ -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); */ } diff --git a/src/cw/mavl_replace_data.c b/src/cw/mavl_replace_data.c deleted file mode 100644 index 4e8e8c7f..00000000 --- a/src/cw/mavl_replace_data.c +++ /dev/null @@ -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; -} - - diff --git a/src/cw/mavliter_get.c b/src/cw/mavliter_get.c deleted file mode 100644 index 07b433f1..00000000 --- a/src/cw/mavliter_get.c +++ /dev/null @@ -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); -} diff --git a/src/cw/mavliter_get_ptr.c b/src/cw/mavliter_get_ptr.c index c9415b6a..87302758 100644 --- a/src/cw/mavliter_get_ptr.c +++ b/src/cw/mavliter_get_ptr.c @@ -1,4 +1,5 @@ #include "mavl.h" +#include "mavltypes.h" /** * Get the element, where AVL Iterator currently is positioned. diff --git a/src/cw/mavliter_init.c b/src/cw/mavliter_init.c deleted file mode 100644 index 174dee77..00000000 --- a/src/cw/mavliter_init.c +++ /dev/null @@ -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; -} diff --git a/src/cw/mavliter_next.c b/src/cw/mavliter_next.c deleted file mode 100644 index 117eb4a9..00000000 --- a/src/cw/mavliter_next.c +++ /dev/null @@ -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 . - -*/ - -/** - *@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 ); - -} diff --git a/src/cw/mavliter_seek.c b/src/cw/mavliter_seek.c deleted file mode 100644 index ac3cfb06..00000000 --- a/src/cw/mavliter_seek.c +++ /dev/null @@ -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 . - -*/ - -/** - *@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; -} - - diff --git a/src/cw/mavliter_seek_set.c b/src/cw/mavliter_seek_set.c deleted file mode 100644 index d841a60b..00000000 --- a/src/cw/mavliter_seek_set.c +++ /dev/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 ); -} diff --git a/src/cw/mod.c b/src/cw/mod.c index a052c83d..8a551f46 100644 --- a/src/cw/mod.c +++ b/src/cw/mod.c @@ -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; diff --git a/src/cw/msgset.c b/src/cw/msgset.c index f2a3a289..8626d377 100644 --- a/src/cw/msgset.c +++ b/src/cw/msgset.c @@ -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); } diff --git a/src/cw/strheap.c b/src/cw/strheap.c index e13cb69d..c095326a 100644 --- a/src/cw/strheap.c +++ b/src/cw/strheap.c @@ -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) diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index dbb10cb9..b331615e 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -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; diff --git a/src/mod/capwap/capwap_out_ac_ip_list.c b/src/mod/capwap/capwap_out_ac_ip_list.c index e8f50a26..4f15ac49 100644 --- a/src/mod/capwap/capwap_out_ac_ip_list.c +++ b/src/mod/capwap/capwap_out_ac_ip_list.c @@ -5,7 +5,7 @@ #include "cw/cw.h" -#include "cw/mavl.h" +#include "mavl.h" diff --git a/src/wtp/Makefile b/src/wtp/Makefile index 467ed4da..2954a52a 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -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\ diff --git a/src/wtp/join.c b/src/wtp/join.c index e2c02955..0dc099bb 100644 --- a/src/wtp/join.c +++ b/src/wtp/join.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" diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index cf3bda26..5b4e00e7 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -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 */