new mavl is working now

FossilOrigin-Name: 65a4eefffea57509c0d7fd573e53b15bf4a730ce297b7db182aaac796ea92448
This commit is contained in:
7u83@mail.ru
2018-03-10 23:56:41 +00:00
parent e4d65ef470
commit 4171d208d0
79 changed files with 1296 additions and 1112 deletions

View File

@ -32,10 +32,10 @@
#include "sock.h"
static int acip_cmp(const mavldata_t *x1, const mavldata_t *x2)
static int acip_cmp(const void *x1, const void *x2)
{
struct cw_acip *ip1 = (struct cw_acip *) x1->ptr;
struct cw_acip *ip2 = (struct cw_acip *) x2->ptr;
struct cw_acip *ip1 = *((struct cw_acip **) x1);
struct cw_acip *ip2 = *((struct cw_acip **) x2);
int r = ip1->index - ip2->index;
if (r!=0)
@ -68,9 +68,9 @@ static int acip_cmp(const mavldata_t *x1, const mavldata_t *x2)
return -1;
}
static void acip_del(mavldata_t *d)
static void acip_del(void *d)
{
free(d->ptr);
free(*(void**)d);
}
/**
@ -79,6 +79,6 @@ static void acip_del(mavldata_t *d)
*/
cw_aciplist_t cw_aciplist_create()
{
return mavl_create(acip_cmp, acip_del);
return mavl_create(acip_cmp, acip_del,1312);
}

View File

@ -15,10 +15,10 @@ typedef struct mavl * cw_aciplist_t;
extern cw_aciplist_t cw_aciplist_create();
#define cw_aciplist_destroy(l) mavl_destroy(l)
#define cw_aciplist_add(l,elem) mavl_add(l,elem)
#define cw_aciplist_add(l,elem) mavl_add(l,elem,NULL)
#define cw_aciplist_del(l,elem) mavl_del(l,elem)
#define cw_aciplist_foreach(l,callback,cbpriv) mavl_foreach_asc(l,callback,cbpriv)
#define cw_aciplist_replace(l,r) mavl_replace(l,r)
#define cw_aciplist_replace(l,r) mavl_replace(l,r,NULL)
#endif

View File

@ -53,7 +53,7 @@ const struct mbag_typedef mbag_type_acprio = {
cw_acpriolist_t cw_acpriolist_create()
{
return mavl_create(acprio_cmp, acprio_del);
return mavl_create(acprio_cmp, acprio_del,4);
}
cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio)
@ -66,7 +66,7 @@ cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len
s->prio=prio;
cw_acpriolist_del(l,s);
return mavl_add(l,s);
return mavl_add(l,s,NULL);
}

View File

@ -67,7 +67,7 @@ static int cw_action_in_cmp(const void *elem1, const void *elem2)
*/
cw_actionlist_in_t cw_actionlist_in_create()
{
return mavl_create(cw_action_in_cmp, free);
return mavl_create(cw_action_in_cmp, free,1312);
}
/**
@ -89,7 +89,7 @@ cw_action_in_t *cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in *
return NULL;
memcpy(an, a, s);
return mavl_add(t, an);
return mavl_add(t, an,NULL);
}
/**
@ -217,7 +217,7 @@ cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_o
if (!o) {
return NULL;
}
mavl_add(t,o);
mavl_add(t,o,NULL);
}
struct mlist_elem * e = mlist_replace(o->mlist,NULL,a);
@ -273,7 +273,7 @@ void *cw_actionlist_add(struct mavl *t, void *a, size_t s)
return NULL;
memcpy(an, a, s);
return mavl_add(t, an);
return mavl_add(t, an,NULL);
}
@ -284,7 +284,7 @@ void *cw_actionlist_add(struct mavl *t, void *a, size_t s)
*/
cw_actionlist_out_t cw_actionlist_out_create()
{
return mavl_create(cw_action_out_cmp, free);
return mavl_create(cw_action_out_cmp, free,1312);
}

View File

@ -30,10 +30,9 @@
#include "stravltree.h"
#include "mod.h"
#include "message_set.h"
#include "cw_types.h"
#include "msget.h"
#include "kvt.h"
int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
@ -301,7 +300,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
/* Search message */
struct cw_MsgData * message;
message = mavl_find_ptr(conn->msgset->messages,&search);
message = mavl_find(conn->msgset->msgdata,&search);
int result_code = 0;
@ -509,12 +508,12 @@ exit(0);
mavliter_foreach(&it){
char value[500];
mavldata_t * data;
struct cw_KVT * data;
data = mavliter_get(&it);
type = data->kv.priv;
type = data->type;
type->to_str(data,value,0);
printf("Got %s (%s): %s\n",data->kv.key,type->name, value);
printf("Got %s (%s): %s\n",data->key,type->name, value);
}

View File

@ -37,110 +37,109 @@
static int cmp_by_addr(const mavldata_t * d1,const mavldata_t *d2)
static int cmp_by_addr ( const void * d1, const void *d2 )
{
struct conn * c1=(struct conn *) d1->ptr;
struct conn * c2=(struct conn *) d2->ptr;
return sock_cmpaddr((struct sockaddr*)&c1->addr,(struct sockaddr*)&c2->addr,1);
struct conn * c1 = * ( void ** ) d1 ;
struct conn * c2 = * ( void ** ) d2 ;
return sock_cmpaddr ( ( struct sockaddr* ) &c1->addr, ( struct sockaddr* ) &c2->addr, 1 );
}
static int cmp_by_session_id(const mavldata_t *d1, const mavldata_t *d2)
static int cmp_by_session_id ( const void *d1, const void *d2 )
{
struct conn * c1=(struct conn *) d1->ptr;
struct conn * c2=(struct conn *) d2->ptr;
return memcmp(c1->session_id,c2->session_id,16);
struct conn * c1 = *( void ** ) d1;
struct conn * c2 = *( void ** ) d2;
return memcmp ( c1->session_id, c2->session_id, 16 );
}
struct connlist * connlist_create(int len)
struct connlist * connlist_create ( int len )
{
struct connlist * cl = malloc(sizeof(struct connlist));
if (!cl)
struct connlist * cl = malloc ( sizeof ( struct connlist ) );
if ( !cl )
return 0;
cl->by_addr = mavl_create(cmp_by_addr,0);
if (!cl->by_addr){
free(cl);
cl->by_addr = mavl_create_ptr ( cmp_by_addr, NULL );
if ( !cl->by_addr ) {
free ( cl );
return 0;
}
cl->by_session_id = mavl_create(cmp_by_session_id,0);
if (pthread_mutex_init(&cl->connlist_mutex,NULL)){
mavl_destroy(cl->by_addr);
free(cl);
cl->by_session_id = mavl_create_ptr ( cmp_by_session_id, NULL );
if ( pthread_mutex_init ( &cl->connlist_mutex, NULL ) ) {
mavl_destroy ( cl->by_addr );
free ( cl );
return 0;
};
cl->len=len;
cl->len = len;
return cl;
}
void connlist_lock(struct connlist * cl)
void connlist_lock ( struct connlist * cl )
{
pthread_mutex_lock(&cl->connlist_mutex);
pthread_mutex_lock ( &cl->connlist_mutex );
}
void connlist_unlock(struct connlist * cl)
void connlist_unlock ( struct connlist * cl )
{
pthread_mutex_unlock(&cl->connlist_mutex);
pthread_mutex_unlock ( &cl->connlist_mutex );
}
void connlist_destroy(struct connlist * cl)
void connlist_destroy ( struct connlist * cl )
{
if (!cl)
if ( !cl )
return;
if (cl->by_addr)
mavl_destroy(cl->by_addr);
pthread_mutex_destroy(&cl->connlist_mutex);
free(cl);
if ( cl->by_addr )
mavl_destroy ( cl->by_addr );
pthread_mutex_destroy ( &cl->connlist_mutex );
free ( cl );
}
struct conn * connlist_get(struct connlist * cl, const struct sockaddr * addr)
struct conn * connlist_get ( struct connlist * cl, const struct sockaddr * addr )
{
struct conn search;
sock_copyaddr(&search.addr,addr);
return mavl_get_ptr(cl->by_addr,&search);
sock_copyaddr ( &search.addr, addr );
return mavl_get_ptr ( cl->by_addr, &search );
}
struct conn * connlist_add(struct connlist * cl, struct conn * conn)
struct conn * connlist_add ( struct connlist * cl, struct conn * conn )
{
if ( cl->len!=0)
if (cl->by_addr->count>=cl->len)
if ( cl->len != 0 )
if ( cl->by_addr->count >= cl->len )
return NULL;
conn->connlist=cl;
return mavl_add_ptr(cl->by_addr,conn);
conn->connlist = cl;
return mavl_add_ptr ( cl->by_addr, conn );
}
struct conn * connlist_get_by_session_id(struct connlist *cl, struct conn * conn)
struct conn * connlist_get_by_session_id ( struct connlist *cl, struct conn * conn )
{
return mavl_get_ptr(cl->by_session_id,conn);
return mavl_get_ptr ( cl->by_session_id, conn );
}
struct conn * connlist_add_by_session_id(struct connlist * cl, struct conn * conn)
struct conn * connlist_add_by_session_id ( struct connlist * cl, struct conn * conn )
{
return mavl_add_ptr(cl->by_session_id,conn);
return mavl_add_ptr ( cl->by_session_id, conn );
}
void connlist_remove(struct connlist *cl,struct conn * conn)
void connlist_remove ( struct connlist *cl, struct conn * conn )
{
mavldata_t md;
md.ptr=conn;
mavl_del(cl->by_session_id,&md);
md.ptr=conn;
mavl_del(cl->by_addr,&md);
void * md;
md = conn;
mavl_del ( cl->by_session_id, &md );
md = conn;
mavl_del ( cl->by_addr, &md );
}

View File

@ -10,7 +10,7 @@
#include "lw.h"
#include "capwap.h"
#include "message_set.h"
#include "msget.h"
/**
* @defgroup CW CW

View File

@ -24,7 +24,7 @@ int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8
prio->prio=cw_get_byte(data);
prio->name=strndup((char*)data+1,len-1);
mavl_replace(prios,prio);
mavl_replace(prios,prio,NULL);
return 1;
}

View File

@ -1,6 +1,5 @@
#include "message_set.h"
#include "cw_types.h"
#include "kvstore.h"
#include "msget.h"
#include "kvt.h"
#include "log.h"
int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
@ -13,7 +12,7 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams *
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
return 0;
}
cw_kvstore_add(params->conn->remote_cfg, handler->key, handler->type, elem_data,elem_len);
cw_kvt_add(params->conn->remote_cfg, handler->key, handler->type, elem_data,elem_len);
/*

View File

@ -1,13 +0,0 @@
#include <stdlib.h>
#include "cw_types.h"
#include "kvstore.h"
void cw_types_kvstore_mavl_delete(mavldata_t *data){
const struct cw_Type * type = data->kv.priv;
if (type->del)
type->del(data);
free(data->kv.key);
}

View File

@ -1,42 +1,42 @@
#include "kvstore.h"
#include "cw_types.h"
#include "kvt.h"
#include "cw.h"
#include "log.h"
#include "dbg.h"
const char * cw_kvstore_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
const char * cw_kvt_add(mavl_t kvtstore, const char *key, const struct cw_Type *type,
const uint8_t * data, int len)
{
mavldata_t mdata, *mresult;
cw_KVT_t mdata, *mresult;
int exists;
/* cw_dbg(DBG_ELEM,"KVStore (%p,%d) add elem (%s): %s", kvstore, kvstore->count,
type->name, key );
*/
mdata.kv.key=cw_strdup(key);
if (!mdata.kv.key){
mdata.key=cw_strdup(key);
if (!mdata.key){
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
key,strerror(errno));
return NULL;
}
mresult = type->get(&mdata,data,len);
if (!mresult){
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
key,type->name, strerror(errno));
free(mdata.kv.key);
free(mdata.key);
return NULL;
}
mresult = mavl_add(kvstore, &mdata);
if (mresult != &mdata){
mresult = mavl_add(kvtstore, &mdata, &exists);
if (exists){
cw_log(LOG_ERR, "Element already exists %s", key);
/* element already exists */
free(mdata.kv.key);
type->del(&mdata);
free(mdata.key);
if (type->del)
type->del(&mdata);
return key;
}
return mdata.kv.key;
return mdata.key;
}

6
src/cw/cw_kvt_mavlcmp.c Normal file
View File

@ -0,0 +1,6 @@
#include "kvt.h"
int cw_kvt_mavlcmp(const void *v1, const void *v2)
{
return strcmp(((cw_KVT_t *) v1)->key, ((cw_KVT_t *) v2)->key);
}

15
src/cw/cw_kvt_mavldel.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdlib.h>
#include "kvt.h"
void cw_kvt_mavldel(void *data)
{
struct cw_KVT *kvt = data;
if (kvt->type->del)
kvt->type->del(data);
free(kvt->key);
}

View File

@ -30,7 +30,7 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
elem_data_search.id=elem_id;
elem_data_search.proto=0;
elem_data_search.vendor=0;
elem_data = mavl_find_ptr(params->msgdata->elements_tree,&elem_data_search);
elem_data = mavl_find(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);

View File

@ -17,10 +17,10 @@
*/
#include "cw.h"
#include "cw_types.h"
#include "kvt.h"
#include "dbg.h"
#include "keys.h"
#include "kvstore.h"
int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
uint8_t * data, int len,
@ -69,11 +69,11 @@ int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
/* vendor */
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VENDOR);
cw_kvstore_add(cfg,key,CW_TYPE_DWORD,data + sub,4);
cw_kvt_add(cfg,key,CW_TYPE_DWORD,data + sub,4);
/* version */
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VERSION);
cw_kvstore_add(cfg,key,CW_TYPE_BSTR16,data+sub+8,l);
cw_kvt_add(cfg,key,CW_TYPE_BSTR16,data+sub+8,l);
sprintf(dbgstr, "%s", key);
cw_dbg_version_subelem(DBG_SUBELEM, dbgstr, subtype, vendor_id, data+sub+8,l);

View File

@ -3,7 +3,7 @@
#include "capwap.h"
#include "capwap_items.h"
#include "dbg.h"
#include "cw_types.h"
#include "kvt.h"
static struct cw_DescriptorSubelemDef allowed_default[] = {
@ -19,6 +19,10 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
struct cw_ElemHandler *eh, uint8_t * data, int len,
struct cw_DescriptorSubelemDef *allowed)
{
printf( "toto here cw_read_wtp_descriptor\n");
exit(0);
/*
int ncrypt, pos,i;
mavldata_t md;
char key[64];
@ -30,13 +34,12 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
sprintf(key,"%s/%s",eh->key, "radios_in_use");
md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
/* mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1));
*/
/* Get number of encryption elements */
/*
ncrypt = cw_get_byte(data + 2);
if (ncrypt == 0) {
if (conn->strict_capwap) {
@ -49,15 +52,18 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
}
pos = 3;
for (i = 0; i < ncrypt; i++) {
/* // It's a dummy for now */
pos += 3;
}
*/
//
// for (i = 0; i < ncrypt; i++) {
///* // It's a dummy for now *
// pos += 3;
// }
/*
if (!allowed) {
allowed=allowed_default;
}
printf("call read subelems\n");
return cw_read_descriptor_subelems(cfg,eh->key , data + pos, len - pos, allowed);
*/
}

View File

@ -2,9 +2,9 @@
#include "capwap.h"
#include "capwap_items.h"
#include "cw_types.h"
#include "kvt.h"
#include "keys.h"
#include "kvstore.h"
static struct cw_DescriptorSubelemDef allowed_default[] = {
@ -24,18 +24,18 @@ int cw_read_wtp_descriptor_7(mavl_t cfg, struct conn *conn,
struct cw_ElemHandler *eh, uint8_t * data, int len,
struct cw_DescriptorSubelemDef *allowed)
{
int ncrypt, pos,i;
mavldata_t md;
int ncrypt, pos;
char key[64];
sprintf(key,"%s/%s",eh->key, "max_radios");
/* md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data,1));
*/
cw_kvstore_add(cfg,key,CW_TYPE_BYTE,data,1);
cw_kvt_add(cfg,key,CW_TYPE_BYTE,data,1);
sprintf(key,"%s/%s",eh->key, "radios_in_use");
cw_kvstore_add(cfg,key,CW_TYPE_BYTE,data+1,1);
cw_kvt_add(cfg,key,CW_TYPE_BYTE,data+1,1);
/* md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));

View File

@ -1,6 +1,11 @@
#include <string.h>
#include <stdlib.h>
/**
* @brief Duplicate a string
* @param s string to duplicate
* @return duplicated string, the memory acllocated has to be freed by #free.
*/
char *cw_strdup(const char *s) {
size_t size = strlen(s) + 1;
char *p = malloc(size);

View File

View File

@ -20,47 +20,50 @@
#include "format.h"
#include "cw.h"
#include "cw_types.h"
#include "kvt.h"
static void del(mavldata_t * data){
free (data->kv.val.ptr);
static void del ( struct cw_KVT * data )
{
free ( data->val.ptr );
}
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
static struct cw_KVT *get ( struct cw_KVT * data, const uint8_t * src, int len )
{
uint8_t * s;
s = bstr16_create(src,len);
if (!s)
s = bstr16_create ( src, len );
if ( !s )
return NULL;
data->kv.priv = &cw_type_bstr16;
data->kv.val.ptr=s;
data->type = &cw_type_bstr16;
data->val.ptr = s;
return data;
}
static int put(mavldata_t *data, uint8_t * dst)
static int put ( const struct cw_KVT *data, uint8_t * dst )
{
return cw_put_bstr16(dst, data->kv.val.ptr);
return cw_put_bstr16 ( dst, data->val.ptr );
}
static int to_str(const mavldata_t *data, char *dst, int max_len)
static int to_str ( const struct cw_KVT *data, char *dst, int max_len )
{
char *d;
d=dst;
if (format_is_utf8(bstr16_data(data->kv.val.ptr), bstr16_len(data->kv.val.ptr))) {
d += sprintf(d, "%.*s", bstr16_len(data->kv.val.ptr),
bstr16_data(data->kv.val.ptr));
d = dst;
if ( format_is_utf8 ( bstr16_data ( data->val.ptr ), bstr16_len ( data->val.ptr ) ) ) {
d += sprintf ( d, "%.*s", bstr16_len ( data->val.ptr ),
bstr16_data ( data->val.ptr ) );
} else {
d += sprintf(d, ".x");
d += format_hex(d, bstr16_data(data->kv.val.ptr), bstr16_len(data->kv.val.ptr));
d += sprintf ( d, ".x" );
d += format_hex ( d, bstr16_data ( data->val.ptr ), bstr16_len ( data->val.ptr ) );
}
return d-dst;
return d - dst;
}
static mavldata_t *from_str(mavldata_t * data, const char *src)
static struct cw_KVT *from_str ( struct cw_KVT * data, const char *src )
{
return NULL;
}
@ -72,6 +75,5 @@ const struct cw_Type cw_type_bstr16 = {
put, /* put */
get, /* get */
to_str, /* to_str */
from_str /* from_str */
from_str /* from_str */
};

View File

@ -19,35 +19,35 @@
#include <stdio.h>
#include "cw.h"
#include "cw_types.h"
#include "kvt.h"
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
static cw_KVT_t *get(cw_KVT_t * data, const uint8_t * src, int len)
{
data->kv.priv = &cw_type_byte;
data->kv.val.byte = cw_get_byte(src);
data->type = &cw_type_byte;
data->val.byte = cw_get_byte(src);
return data;
}
static int put(mavldata_t *data, uint8_t * dst)
static int put(cw_KVT_t *data, uint8_t * dst)
{
return cw_put_byte(dst, data->kv.val.byte);
return cw_put_byte(dst, data->val.byte);
}
static int to_str(const mavldata_t *data, char *dst, int max_len)
static int to_str(const cw_KVT_t *data, char *dst, int max_len)
{
return sprintf(dst, "%d", data->kv.val.byte);
return sprintf(dst, "%d", data->val.byte);
}
static mavldata_t *from_str(mavldata_t * data, const char *src)
static cw_KVT_t *from_str(cw_KVT_t * data, const char *src)
{
data->kv.val.byte = atoi(src);
data->val.byte = atoi(src);
return data;
}
const struct cw_Type cw_type_byte = {
"Byte", /* name */
cw_types_del_null, /* del */
NULL, /* del */
put, /* put */
get, /* get */
to_str, /* to_str */

View File

@ -19,34 +19,34 @@
#include <stdio.h>
#include "cw.h"
#include "cw_types.h"
#include "kvt.h"
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
static struct cw_KVT *get(struct cw_KVT * data, const uint8_t * src, int len)
{
data->kv.priv = &cw_type_dword;
data->kv.val.dword = cw_get_dword(src);
data->type = &cw_type_dword;
data->val.dword = cw_get_dword(src);
return data;
}
static int put(mavldata_t *data, uint8_t * dst)
static int put(struct cw_KVT *data, uint8_t * dst)
{
return cw_put_dword(dst, data->kv.val.dword);
return cw_put_dword(dst, data->val.dword);
}
static int to_str(const mavldata_t *data, char *dst, int max_len)
static int to_str(const struct cw_KVT *data, char *dst, int max_len)
{
return sprintf(dst, "%d", data->kv.val.dword);
return sprintf(dst, "%d", data->val.dword);
}
static mavldata_t *from_str(mavldata_t * data, const char *src)
static struct cw_KVT *from_str(struct cw_KVT * data, const char *src)
{
data->kv.val.dword = atoi(src);
data->val.dword = atoi(src);
return data;
}
const struct cw_Type cw_type_dword = {
"Dword", /* name */
cw_types_del_null, /* del */
NULL, /* del */
put, /* put */
get, /* get */
to_str, /* to_str */

View File

@ -18,36 +18,36 @@
#include <stdio.h>
#include "cw_types.h"
#include "kvt.h"
#include "cw.h"
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
static struct cw_KVT *get(struct cw_KVT * data, const uint8_t * src, int len)
{
data->kv.priv = &cw_type_word;
data->kv.val.word = cw_get_word(src);
data->type = &cw_type_word;
data->val.word = cw_get_word(src);
return data;
}
static int put(mavldata_t *data, uint8_t * dst)
static int put(cw_KVT_t *data, uint8_t * dst)
{
return cw_put_word(dst, data->kv.val.word);
return cw_put_word(dst, data->val.word);
}
static int to_str(const mavldata_t *data, char *dst, int max_len)
static int to_str(const cw_KVT_t *data, char *dst, int max_len)
{
return sprintf(dst, "%d", data->kv.val.word);
return sprintf(dst, "%d", data->val.word);
}
static mavldata_t *from_str(mavldata_t * data, const char *src)
static cw_KVT_t *from_str(cw_KVT_t * data, const char *src)
{
data->kv.val.word = atoi(src);
data->val.word = atoi(src);
return data;
}
const struct cw_Type cw_type_word = {
"Word", /* name */
cw_types_del_null, /* del */
NULL, /* del */
put, /* put */
get, /* get */
to_str, /* to_str */

View File

@ -1,48 +0,0 @@
#ifndef __CW_TYPES_H
#define __CW_TYPES_H
#include "mavl.h"
struct cw_Type{
/** A human readable name for this type */
const char *name;
/** A pointer to a function to delete elements of this type */
void (*del)(mavldata_t *data);
/** A method to put this object to a buffer */
int (*put)(mavldata_t * data, uint8_t*dst);
/** The get emthod */
mavldata_t * (*get)(mavldata_t *data, const uint8_t*src, int len);
/** A pointer to a function to convert elements of this type to a string.
This function is mainly used to store elements to an SQL database
or to json strings */
int (*to_str)(const mavldata_t * data, char *dst, int max_len);
/** Cereate an item of this type from a string, which was previously
created by the #del function. */
mavldata_t * (*from_str)(mavldata_t * data, const char *src);
/*
int (*def)(void *, void *);
*/
};
extern const struct cw_Type cw_type_byte;
extern const struct cw_Type cw_type_word;
extern const struct cw_Type cw_type_dword;
extern const struct cw_Type cw_type_bstr16;
#define CW_TYPE_BYTE (&cw_type_byte)
#define CW_TYPE_WORD (&cw_type_word)
#define CW_TYPE_DWORD (&cw_type_dword)
#define CW_TYPE_BSTR16 (&cw_type_bstr16)
void cw_types_del_null(mavldata_t *data);
#endif /* __CW_TYPES_H */

View File

@ -1,6 +0,0 @@
#include "mavl.h"
#include "cw_types.h"
void cw_types_del_null(mavldata_t *data){
return;
}

View File

@ -36,7 +36,7 @@
#include "capwap_cisco.h"
#include "lwapp_cisco.h"
#include "cw.h"
#include "message_set.h"
#include "msget.h"
@ -314,7 +314,7 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
search.type = msg_id;
message = mavl_get_ptr(conn->msgset->messages,&search);
message = mavl_get(conn->msgset->msgdata,&search);
if (!message)

View File

@ -18,7 +18,7 @@ static void del(void* d)
struct mavl * intavltree_create()
{
return mavl_create(cmp,del);
return mavl_create(cmp,del,100);
}
int * intavltree_add(struct mavl * t, int val)
@ -31,5 +31,5 @@ int * intavltree_add(struct mavl * t, int val)
if (!v)
return NULL;
*v=val;
return mavl_add(t,v);
return mavl_add(t,v,NULL);
}

View File

@ -61,14 +61,14 @@ const cw_itemdef_t * cw_itemdef_get(cw_itemdefheap_t t, const char *id, const ch
cw_itemdefheap_t cw_itemdefheap_create()
{
return mavl_create(cmp, NULL);
return mavl_create(cmp, NULL,1312);
}
int cw_itemdefheap_register(cw_itemdefheap_t t, cw_itemdef_t * defs)
{
int n = 0;
while (defs->id != CW_ITEM_NONE) {
cw_itemdef_t *a = mavl_add(t, defs);
cw_itemdef_t *a = mavl_add(t, defs,NULL);
if (a != defs) {
cw_log(LOG_ERR, "Duplicated item: %s", defs->id);
} else

View File

@ -1,15 +0,0 @@
#ifndef __CW_KVSTORE_H
#define __CW_KVSTORE_H
#include "mavl.h"
#include "cw_types.h"
void cw_kvstore_mavl_delete(mavldata_t *data);
const char * cw_kvstore_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
const uint8_t * data, int len);
#define cw_kvstore_create()\
mavl_create(mavl_cmp_kv, cw_kvstore_mavl_delete)
#endif /* __CW_KVSTORE_H */

70
src/cw/kvt.h Normal file
View File

@ -0,0 +1,70 @@
#ifndef __KVT_H
#define __KVT_H
#include <stdint.h>
#include "mavl.h"
struct cw_KVT {
char *key;
union {
uint32_t dword;
uint16_t word;
uint8_t byte;
void *ptr;
} val;
const struct cw_Type *type;
};
typedef struct cw_KVT cw_KVT_t;
struct cw_Type {
/** A human readable name for this type */
const char *name;
/** A pointer to a function to delete elements of this type */
void (*del) (struct cw_KVT * data);
/** A method to put this object to a buffer */
int (*put) (struct cw_KVT * data, uint8_t * dst);
/** The get method */
struct cw_KVT *(*get) (struct cw_KVT * data, const uint8_t * src, int len);
/** A pointer to a function to convert elements of this type to a string.
This function is mainly used to store elements to an SQL database
or to json strings */
int (*to_str) (const struct cw_KVT * data, char *dst, int max_len);
/** Cereate an item of this type from a string, which was previously
created by the #del function. */
struct cw_KVT *(*from_str) (struct cw_KVT * data, const char *src);
/*
int (*def)(void *, void *);
*/
};
extern const struct cw_Type cw_type_byte;
extern const struct cw_Type cw_type_word;
extern const struct cw_Type cw_type_dword;
extern const struct cw_Type cw_type_bstr16;
#define CW_TYPE_BYTE (&cw_type_byte)
#define CW_TYPE_WORD (&cw_type_word)
#define CW_TYPE_DWORD (&cw_type_dword)
#define CW_TYPE_BSTR16 (&cw_type_bstr16)
/*
void cw_kvstore_mavl_delete(const void *data);
*/
const char *cw_kvt_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
const uint8_t * data, int len);
int cw_kvt_mavlcmp(const void *v1, const void *v2);
void cw_kvt_mavldel(void *data);
#define cw_kvt_create()\
mavl_create(cw_kvt_mavlcmp, cw_kvt_mavldel, sizeof(cw_KVT_t))
#endif /* __KVT_H */

View File

@ -17,17 +17,18 @@
/**
* @file
* @brief MAVL, Mini AVL Tree,
* Yet another AVL Tree implementation!
* @brief MAVL, Mini AVL Tree,
* Yet another AVL Tree implementation
*/
/**
* @defgroup MAVL MAVL
/**
* @addtogroup DATAMGMT
* @{
*/
#ifndef __MAVL_H
#define __MAVL_H
@ -38,43 +39,27 @@
#include <stdint.h>
/**
* @defgroup MAV_CONSTANTS Constants
* @defgroup MAVL_CONSTANTS Constants
* @{
*/
/** Maximum AVL Tree depth.
/** Maximum AVL Tree depth.
The number of nodes is calculated by 2^depth.
So a value of 32 should be enough for around 4
So a value of 32 should be enough for around 4
billion nodes. */
#define MAVL_MAX_DEPTH 32
/**
* @}
*/
struct mavl_KeyVal{
char *key;
const void *priv;
union{
void * ptr;
uint32_t dword;
uint16_t word;
uint8_t byte;
char * str;
}val;
};
union mavldata {
void *ptr;
uint32_t dword;
uint16_t word;
uint8_t byte;
char *str;
struct mavl_KeyVal kv;
};
typedef union mavldata mavldata_t;
/**
* @addtogroup MAVLStructures Structures
* @{
*/
/**
@ -82,8 +67,8 @@ typedef union mavldata mavldata_t;
*/
struct mavlnode {
/** Pointer to data, that belongs to the node */
/* union mavldata data; */
/* union mavldata data; */
/** Pointer to left son*/
struct mavlnode *left;
@ -93,30 +78,32 @@ struct mavlnode {
int bal;
};
#define mavlnode_data(node) ((node)+sizeof(struct mavlnode))
#define mavlnode_copy_data(tree,dst,src)\
memcpy(mavlnode_data(dst),mavlnode_data(src),\
(tree)->data_size)
/**
* AVL Tree
*/
*/
struct mavl {
/** Pointer to root node */
struct mavlnode *root;
/** Compare function */
int (*cmp) (const union mavldata *, const union mavldata *);
int ( *cmp ) ( const void *, const void * );
/** Delete element function */
void (*del) (union mavldata *);
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;
@ -125,33 +112,40 @@ typedef struct mavl * mavl_t;
* @{
*/
/**
* @param node node
*/
#define mavlnode_dataptr(node) (((uint8_t*)(node))+sizeof(struct mavlnode))
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
void (*del) (void *), size_t data_size);
struct mavl *mavl_create ( int ( *cmp ) ( const void *, const void * ),
void ( *del ) ( void * ), size_t data_size );
void mavlnode_destroy(struct mavl *t, struct mavlnode *n);
void mavl_del_all(struct mavl *t);
union mavldata *mavl_del(struct mavl *t, union mavldata *data);
union mavldata *mavl_add(struct mavl *t, union mavldata *data);
union mavldata * mavl_get(struct mavl *t ,union mavldata *data);
struct mavlnode *mavl_get_node(struct mavl *t, void *data);
void * mavl_get_ptr(mavl_t tree, void * search);
void *mavl_add_ptr(mavl_t tree, void *ptr);
int mavl_cmp_kv(const union mavldata *e1, const union mavldata *e2);
union mavldata *mavl_add_kv_byte(mavl_t tree, const char *key, uint8_t val);
void mavl_merge(mavl_t m, mavl_t t);
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 , void *data );
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 m, mavl_t t );
void mavlnode_destroy ( struct mavl *t, struct mavlnode *n );
struct mavlnode *mavl_get_node ( struct mavl *t, void *data );
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 );
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);
/**
* @}
@ -159,12 +153,8 @@ int mavl_foreach_from_lr(struct mavl *t, struct mavlnode *n, void *data,
void *mavl_replace_data(struct mavl *t, void *data, int len);
void *mavl_replace_data ( struct mavl *t, void *data, int len );
union mavldata *mavl_replace(struct mavl *t,union mavldata *data);
void mavl_destroy(struct mavl *t);
@ -179,50 +169,52 @@ void mavl_destroy(struct mavl *t);
#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 mavliter {
struct mavlnode *stack[MAVL_MAX_DEPTH * 2];
struct mavlnode *cur;
int stack_ptr;
struct mavlnode * root;
int (*cmp) (const union mavldata *, const union mavldata *);
int ( *cmp ) ( const void *, const void * );
};
typedef struct mavliter mavliter_t;
union mavldata * mavliter_next(mavliter_t *i);
union mavldata * mavliter_next ( mavliter_t *i );
union mavldata * mavliter_seek_set(struct mavliter *i);
union mavldata * mavliter_seek_set ( struct mavliter *i );
void mavliter_init(mavliter_t *i, mavl_t t);
void mavliter_init ( mavliter_t *i, mavl_t t );
void * mavliter_get(mavliter_t *i);
extern union mavldata * mavliter_seek(mavliter_t *i,void *d);
void * mavliter_get ( mavliter_t *i );
/**
* Define a AVL Iterator varialble and accociate it with
void * mavliter_get_ptr(mavliter_t *i);
extern union mavldata * 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
* \code
mavl_t datatree = mavl_create();
// fill up datatree with some values
// 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)
@ -230,7 +222,7 @@ extern union mavldata * mavliter_seek(mavliter_t *i,void *d);
/**
* 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))
@ -252,11 +244,9 @@ extern union mavldata * mavliter_seek(mavliter_t *i,void *d);
typedef mavl_t mavl_conststr_t;
extern mavl_conststr_t mavl_create_conststr();
int mavl_cmp_dword(const union mavldata *e1, const union mavldata *e2);
int mavl_cmp_str(const union mavldata *e1, const union mavldata *e2);
void mavl_free_bin(union mavldata *data);
void mavl_free_str(union mavldata *data);
/*
//int mavl_cmp_str ( const union mavldata *e1, const union mavldata *e2 );
*/
/*
@ -273,16 +263,34 @@ 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 node->data=data;
}
return mavl_add(t,data);
}
*/
/** @} */
void mavl_freeptr(void *ptr);
#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)
void * mavl_get_ptr ( mavl_t tree, void * search );
void * mavl_add_ptr ( mavl_t tree, 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)))
/**
*
* @}
* datamanag
*/
#endif

View File

@ -1,45 +1,52 @@
#include "mavl.h"
static struct mavlnode *mavlnode_create(const union mavldata *data)
static struct mavlnode *mavlnode_create ( struct mavl *t, const void *data )
{
struct mavlnode *n = malloc(sizeof(struct mavlnode));
if (!n)
struct mavlnode *n = malloc ( sizeof ( struct mavlnode ) + t->data_size );
if ( !n )
return NULL;
n->left = n->right = 0;
n->left = n->right = NULL;
n->bal = 0;
n->data = *data;
/*n->data = *data;*/
memcpy ( mavlnode_dataptr ( n ), data, t->data_size );
return n;
}
static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata ** data)
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, &n->data);
int rc = t->cmp ( *data, mavlnode_dataptr ( n ) );
int bal;
if (rc == 0) {
*data = &n->data;
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)
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)
if ( n->bal == 0 )
return 0;
if (n->bal == -2) {
if (n->left->bal == -1) {
if ( n->bal == -2 ) {
if ( n->left->bal == -1 ) {
n->bal = 0;
n->left->bal = 0;
*parent = n->left;
@ -48,61 +55,70 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
n->left = tmp;
return 0;
}
if (n->left->bal == 1) {
if ( n->left->bal == 1 ) {
*parent = n->left->right;
if ((*parent)->bal == 1) {
if ( ( *parent )->bal == 1 ) {
n->bal = 0;
n->left->bal = -1;
} else if ((*parent)->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;
( *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(*data);
if (!n->left)
n->left = mavlnode_create ( t, *data );
*data = mavlnode_dataptr(n->left);
if ( !n->left )
return 3;
t->count++;
if (n->right == 0) {
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)
if ( n->right ) {
bal = mavl_add0 ( t, &n->right, data );
if ( bal > 1 )
return bal;
n->bal += bal;
if (n->bal == 0)
if ( n->bal == 0 )
return 0;
if (n->bal == 2) {
if (n->right->bal == 1) {
if ( n->bal == 2 ) {
if ( n->right->bal == 1 ) {
n->bal = 0;
n->right->bal = 0;
*parent = n->right;
@ -110,45 +126,52 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
n->right->left = n;
n->right = tmp;
return 0;
} else if (n->right->bal == -1) {
} else if ( n->right->bal == -1 ) {
*parent = n->right->left;
if ((*parent)->bal == -1) {
if ( ( *parent )->bal == -1 ) {
n->bal = 0;
n->right->bal = 1;
} else if ((*parent)->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;
( *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);
n->right = mavlnode_create(*data);
if (!n->right)
if ( !n->right )
return 3;
t->count++;
if (n->left == 0) {
if ( n->left == 0 ) {
n->bal = 1;
return 1;
}
n->bal = 0;
return 0;
}
@ -157,41 +180,54 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
/**
* Add an element to an AVL tree
*
*
* @param t mavl
* @param data pointer to element
*
* @return A pointer to the element in the tree. If teh returned pointer
*
* @return A pointer to the element in the tree. If teh returned pointer
* equals to the pointer given in the data argument, the element has already
* been in the tree. If the function returns NULL, there was en error, e.g.
* no memory left. Consult therefore errno.
* no memory left. Consult therefore errno.
*
* @example mavl_add_example.c
*/
union mavldata *mavl_add(struct mavl *t, union mavldata *data)
void *mavl_add ( struct mavl *t, const void *data, int *exists )
{
union mavldata * d;
const void * d;
int rc;
if (t->root == NULL) {
t->root = mavlnode_create(data);
if (t->root)
t->count++;
if ( t->root == NULL ) {
t->root = mavlnode_create ( t, data );
if ( t->root )
t->count++;
/* return &t->root->data; */
return data;
if (exists != NULL)
*exists=0;
return mavlnode_dataptr(t->root);
}
d = data;
rc = mavl_add0(t, &t->root, &d);
if (rc > 3)
rc = mavl_add0 ( t, &t->root, &d );
if ( rc >= 3 )
return NULL;
if ( exists != NULL){
if (rc==2)
*exists=1;
else
*exists=0;
}
return d;
}
/*
void *mavl_add ( struct mavl *t, const void *data)
{
return mavl_add_exists(t,data,NULL);
}
*/

View File

@ -1,9 +0,0 @@
#include "mavl.h"
union mavldata *mavl_add_kv_byte(mavl_t tree, const char *key, uint8_t val)
{
mavldata_t data;
data.kv.key = key;
data.kv.val.byte = val;
return mavl_add(tree, &data);
}

View File

@ -1,10 +1,9 @@
#include "mavl.h"
void *mavl_add_ptr(mavl_t tree, void *ptr){
mavldata_t data, *result;
data.ptr = ptr;
result = mavl_add(tree,&data);
void * result;
result = mavl_add(tree,&ptr,NULL);
if (result)
return result->ptr;
return *(void**)result;
return NULL;
}

View File

@ -1,17 +0,0 @@
#include "mavl.h"
const char * mavl_add_strdup(mavl_t t, const char * str)
{
mavldata_t s, *result;
s.str = strdup(str);
if (!s.str)
return NULL;
result = mavl_add(t,&s);
if (!result){
free(s.str);
return NULL;
}
return result->str;
}

View File

@ -1,5 +0,0 @@
#include "mavl.h"
int mavl_cmp_dword(const union mavldata *e1, const union mavldata *e2){
return e1->dword - e2->dword;
}

View File

@ -1,5 +0,0 @@
#include "mavl.h"
int mavl_cmp_kv(const union mavldata *e1, const union mavldata *e2){
return strcmp(e1->kv.key, e2->kv.key);
}

View File

@ -1,6 +0,0 @@
#include "mavl.h"
int mavl_cmp_str(const union mavldata *e1, const union mavldata *e2){
return strcmp (e1->str,e2->str);
}

6
src/cw/mavl_cmpstr.c Normal file
View File

@ -0,0 +1,6 @@
#include "mavl.h"
int mavl_cmpstr (const void *s1, const void *s2)
{
return strcmp( *((const char**)s1), *((const char**)s2));
}

View File

@ -18,19 +18,21 @@
/**
*@file
*@Implementation of mavl_create
*@brief Implementation of mavl_create
*@addtogroup MavlFunctions
*@{
*/
*/
#include "mavl.h"
/**
* Create an AVL tree
* @param cmp pointer compare function
* @param del pointer to delete function which is called when an element will be deletet
* @return pointer to an #mavl struct
* @param cmp pointer to compare function
* @param del pointer to delete function which is called when an element
* will be deletet
* @return pointer to a #mavl struct
*/
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
void (*del) (void *), size_t data_size)
{
struct mavl *t = malloc(sizeof(struct mavl));
@ -40,6 +42,7 @@
t->count = 0;
t->cmp = cmp;
t->del = del;
t->data_size=data_size;
return t;
}

View File

@ -39,5 +39,5 @@ static int cmp(const void *v1,const void*v2)
mavl_conststr_t mavl_create_conststr()
{
return mavl_create(cmp,NULL);
return mavl_create(cmp,NULL,1312);
}

View File

@ -3,7 +3,7 @@
void mavlnode_destroy(struct mavl *t, struct mavlnode *n)
{
if (t->del) {
t->del(&n->data);
t->del(mavlnode_dataptr(n));
}
free(n);
t->count--;
@ -107,12 +107,12 @@ static int adj_bal_r(struct mavlnode *n, struct mavlnode **parent)
static int mavl_del_lo(struct mavlnode **parent, union mavldata *data)
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(&n->left, data);
int bal = mavl_del_lo(t, &n->left, data);
n->bal += bal;
if (n->bal == 1) {
return 0;
@ -126,7 +126,9 @@ static int mavl_del_lo(struct mavlnode **parent, union mavldata *data)
/* found the lowest element */
*parent = n->right;
*data = n->data;
/* *data = n->data;*/
memcpy(data,mavlnode_dataptr(n),t->data_size);
free(n);
return 1;
@ -143,12 +145,12 @@ static int mavl_del_lo(struct mavlnode **parent, union mavldata *data)
int mavl_del0(struct mavl *t, struct mavlnode **parent, union mavldata *data)
int mavl_del0(struct mavl *t, struct mavlnode **parent, void *data)
{
struct mavlnode *n = *parent;
int rc;
int bal;
rc = t->cmp(data, &n->data);
rc = t->cmp(data, mavlnode_dataptr(n));
if (rc == 0) {
if (n->right == 0 && n->left == 0) {
@ -174,10 +176,10 @@ int mavl_del0(struct mavl *t, struct mavlnode **parent, union mavldata *data)
/* node has two childs */
if (t->del) {
t->del(&n->data);
t->del(mavlnode_dataptr(n));
}
t->count--;
bal = mavl_del_lo(&n->right, &n->data);
bal = mavl_del_lo(t,&n->right, mavlnode_dataptr(n));
n->bal -= bal;
if (n->bal == -1)
return 0;
@ -228,9 +230,9 @@ int mavl_del0(struct mavl *t, struct mavlnode **parent, union mavldata *data)
}
union mavldata *mavl_del(struct mavl *t, union mavldata *data)
void *mavl_del(struct mavl *t, const void *data)
{
union mavldata *d;
void *d;
int rc;
if (!t->root)

View File

@ -24,7 +24,7 @@ int mavl_foreach_rl(struct mavlnode *n, int (*callback)(void *,void *),void *cbp
return 1;
if (!mavl_foreach_rl(n->right,callback,cbpriv))
return 0;
if (!callback(cbpriv,&n->data))
if (!callback(cbpriv,mavlnode_dataptr(n)))
return 0;
return mavl_foreach_rl(n->left,callback,cbpriv);
}

View File

@ -8,7 +8,7 @@ int mavl_foreach_lr(struct mavlnode *n, int (*callback)(void *,void *),void *cbp
return 1;
if (!mavl_foreach_lr(n->left,callback,cbpriv))
return 0;
if (!callback(cbpriv,&n->data))
if (!callback(cbpriv,mavlnode_dataptr(n)))
return 0;
return mavl_foreach_lr(n->right,callback,cbpriv);

View File

@ -1,7 +0,0 @@
#include "mavl.h"
void mavl_free_bin(union mavldata *data){
free(data->ptr);
}

View File

@ -1,7 +0,0 @@
#include "mavl.h"
void mavl_free_str(union mavldata *data){
free(data->str);
}

5
src/cw/mavl_freeptr.c Normal file
View File

@ -0,0 +1,5 @@
#include "mavl.h"
void mavl_freeptr(void *ptr){
free( *((void**)ptr) );
}

View File

@ -29,13 +29,13 @@
* @param data Element to get
* @return pointer to element or NULL if not found.
*/
union mavldata * mavl_get(struct mavl *t ,union mavldata *data)
void * mavl_get(struct mavl *t ,void *data)
{
struct mavlnode *n = t->root;
while(n){
int rc=t->cmp(data,&n->data);
int rc=t->cmp(data,mavlnode_dataptr(n));
if (rc==0)
return &n->data;
return mavlnode_dataptr(n);
if (rc<0)
n=n->left;
else

View File

@ -26,7 +26,7 @@ struct mavlnode * mavl_get_node(struct mavl *t ,void *data)
{
struct mavlnode *n = t->root;
while(n){
int rc=t->cmp(data,&n->data);
int rc=t->cmp(data,mavlnode_dataptr(n));
if (rc==0)
return n;
if (rc<0)

View File

@ -2,10 +2,10 @@
void * mavl_get_ptr(mavl_t tree, void * search)
{
mavldata_t search_data, *result;
search_data.ptr=search;
result = mavl_find(tree,&search_data);
void * result;
result = mavl_find(tree,&search);
if (result)
return result->ptr;
return *(void**)result;
return NULL;
}

View File

@ -27,17 +27,17 @@
static void mavlnode_move(mavl_t m,mavl_t t, struct mavlnode *n)
{
struct mavlnode * mn = mavl_get_node(m,mavlnode_data(n));
struct mavlnode * mn = mavl_get_node(m,mavlnode_dataptr(n));
if (mn) {
if (m->del) {
m->del(mavlnode_data(mn));
m->del(mavlnode_dataptr(mn));
}
/*mn->data=n->data;*/
mavlnode_copy_data(m,mn,n);
memcpy(mavlnode_dataptr(mn),mavlnode_dataptr(n),t->data_size);
}
else{
/*mavl_add(m,&n->data);*/
mavl_add(m,mavlnode_data(n));
mavl_add(m,mavlnode_dataptr(n),NULL);
}
free(n);

View File

@ -1,15 +1,38 @@
#include "mavl.h"
union mavldata *mavl_replace(struct mavl *t,void *data){
void *mavl_replace(struct mavl *t,const void *data, int * replaced){
int exists;
void * add = mavl_add(t,data,&exists);
if (replaced != NULL){
*replaced = exists;
}
if (!exists){
return add;
}
if(t->del){
t->del(add);
}
memcpy(add,data,t->data_size);
return add;
/*
struct mavlnode * node = mavl_get_node(t,data);
if (node){
if (t->del)
t->del(node+sizeof(struct mavlnode));
/* node->data=*data;
*/ mavlnode_copy_data(node+sizeof(struct mavlnode), data);
return &node->data;
// node->data=*data;
memcpy(mavlnode_dataptr(node), data, t->data_size);
// return &node->data;
return mavlnode_dataptr(node);
}
return mavl_add(t,data);
*/
}

View File

@ -5,10 +5,10 @@
* @param i AVL Iterator
* @return element or NULL if not found.
*/
void * mavliter_get(mavliter_t *i){
if(!i->cur)
void * mavliter_get(mavliter_t *i)
{
if (!i->cur)
return NULL;
/*return &i->cur->data; */
return mavlnode_dataptr(i->cur);
}

15
src/cw/mavliter_get_ptr.c Normal file
View File

@ -0,0 +1,15 @@
#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_ptr(mavliter_t *i)
{
/*void * data;*/
if (!i->cur)
return NULL;
return *(void**)(mavlnode_dataptr(i->cur));
}

View File

@ -8,12 +8,11 @@
* @param i AVL Iterator to initialize
* @param t correspondending AVL Tree
*
* @See mavliter_t,
* @See mavliter_t,
*/
void mavliter_init(mavliter_t *i, mavl_t t){
void mavliter_init ( mavliter_t *i, mavl_t t )
{
i->root = t->root;
i->stack_ptr=0;
i->cmp=t->cmp;
i->stack_ptr = 0;
i->cmp = t->cmp;
}

View File

@ -17,7 +17,7 @@
*/
/**
*@file
*@file
*@brief Implementation of mavliter_next
*/
@ -27,44 +27,42 @@
* 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.
*/
*/
union mavldata * mavliter_next(mavliter_t *i)
union mavldata * mavliter_next ( mavliter_t *i )
{
while ( i->stack_ptr) {
while ( i->stack_ptr ) {
i->stack_ptr--;
i->cur=i->stack[i->stack_ptr];
if (!i->cur)
i->cur = i->stack[i->stack_ptr];
if ( !i->cur )
continue;
if ((i->stack_ptr)&1) {
return &i->cur->data;
if ( ( i->stack_ptr ) & 1 ) {
/*return &i->cur->data;*/
return mavlnode_dataptr ( i->cur );
}
break;
break;
}
if (!i->cur){
if ( !i->cur ) {
return NULL;
}
while(i->cur->left) {
while ( i->cur->left ) {
/* push right branch */
i->stack[i->stack_ptr++]=i->cur->right;
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;
i->cur = i->cur->left;
}
i->stack[i->stack_ptr++]=i->cur->right;
return &i->cur->data;
i->stack[i->stack_ptr++] = i->cur->right;
/* return &i->cur->data;*/
return mavlnode_dataptr ( i->cur );
}

View File

@ -43,7 +43,8 @@ union mavldata * mavliter_seek(mavliter_t *i,void *d)
while(i->cur) {
rc = i->cmp(d,&i->cur->data);
/* 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;

View File

@ -1,10 +1,8 @@
#include "mavl.h"
union mavldata * mavliter_seek_set(struct mavliter *i)
union mavldata * mavliter_seek_set ( struct mavliter *i )
{
i->stack_ptr=0;
i->cur=i->root;
return mavliter_next(i);
i->stack_ptr = 0;
i->cur = i->root;
return mavliter_next ( i );
}

View File

@ -146,13 +146,13 @@ static int mbag_i_cmp_fun(const void *x1, const void *x2)
mbag_t mbag_i_create()
{
return mavl_create(mbag_i_cmp_fun, mbag_i_del_fun);
return mavl_create(mbag_i_cmp_fun, mbag_i_del_fun,1312);
}
mbag_t mbag_create()
{
return mavl_create(mbag_cmp_fun, mbag_del_fun);
return mavl_create(mbag_cmp_fun, mbag_del_fun,1312);
}
@ -186,7 +186,7 @@ struct mbag_item *mbag_item_create(mbag_t s, const char *id)
return NULL;
i->u1.id = id;
i->dynid=0;
return mavl_add(s, i);
return mavl_add(s, i,NULL);
}
@ -207,7 +207,7 @@ struct mbag_item *mbag_i_item_create(mbag_t s, uint32_t id)
return NULL;
i->u1.iid = id;
i->dynid=0;
return mavl_add(s, i);
return mavl_add(s, i,NULL);
}
@ -253,7 +253,7 @@ struct mbag_item *strmbag_item_create(mbag_t s, char *name)
int mbag_set(mbag_t t,mbag_item_t *is)
{
mavl_del(t,is);
mavl_add(t,is);
mavl_add(t,is,NULL);
return 1;
/*

View File

@ -18,7 +18,7 @@
/**
* @file
* @brief
*/
*/
#include <stdio.h>
#include <errno.h>
@ -30,29 +30,28 @@
#define BLOCK_SIZE 4096
/**
* Calculate MD5 checksum for an opened file.
* @param digest destination buffer for calculated
* Calculate MD5 checksum for an opened file.
* @param digest destination buffer for calculated
* checksum (16 bytes, for a predifned constant use #CW_MD5_DIGEST_SIZE)
* @param infile file hanle
*
* @param infile file hanle
*
* Remember to set the file pointer to the beginning of the file, before
* calling this function. Therefore use fseek(file,0,SEEK_SET).
*/
int cw_fgetmd5sum(uint8_t *digest, FILE *infile)
int cw_fgetmd5sum ( uint8_t *digest, FILE *infile )
{
struct md5_ctx ctx;
uint8_t buffer[BLOCK_SIZE];
md5_init(&ctx);
while (!feof(infile)){
int bytes = fread(buffer,1,sizeof(buffer),infile);
md5_update(&ctx,bytes,buffer);
}
if (ferror(infile))
return errno;
md5_init ( &ctx );
md5_digest(&ctx, MD5_DIGEST_SIZE, digest);
while ( !feof ( infile ) ) {
int bytes = fread ( buffer, 1, sizeof ( buffer ), infile );
md5_update ( &ctx, bytes, buffer );
}
if ( ferror ( infile ) )
return errno;
md5_digest ( &ctx, MD5_DIGEST_SIZE, digest );
return 0;
}

View File

@ -51,7 +51,7 @@ struct mlist {
struct mlist_elem *first;
struct mlist_elem *last;
int count;
//size_t elem_size;
/* //size_t elem_size;*/
};
typedef struct mlist * mlist_t;

View File

@ -31,7 +31,7 @@
#include "log.h"
#include "file.h"
#include "cw.h"
#include "cw/message_set.h"
#include "cw/msget.h"
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
struct cw_actiondef * actions) = NULL;
@ -77,10 +77,10 @@ struct cw_Mod mod_null = {
static int cmp(const mavldata_t *p1, const mavldata_t *p2)
static int cmp(const void *p1, const void *p2)
{
struct cache_item *c1 = (struct cache_item *) p1->ptr;
struct cache_item *c2 = (struct cache_item *) p2->ptr;
struct cache_item *c1 = ((struct cache_item **) p1)[0];
struct cache_item *c2 = ((struct cache_item **) p2)[0];
int r;
r = strcmp(c1->capwap, c2->capwap);
@ -104,7 +104,7 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
struct cw_MsgSet * set;
if (!msgset_cache) {
msgset_cache = mavl_create(cmp, NULL);
msgset_cache = mavl_create(cmp, NULL,1312);
if (!msgset_cache) {
cw_log(LOG_ERR, "Can't initialize msgset cache: %s",
strerror(errno));
@ -164,9 +164,9 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
/* static mavl to store modules */
static struct mavl * mods_loaded = NULL;
static int mod_cmp_mavl(const mavldata_t *e1, const mavldata_t *e2){
const struct cw_Mod * m1 = e1->ptr;
const struct cw_Mod * m2 = e2->ptr;
static int mod_cmp_mavl(const void *e1, const void *e2){
const struct cw_Mod * m1 = *((const struct cw_Mod**)e1);
const struct cw_Mod * m2 = *((const struct cw_Mod**)e2);
return strcmp(m1->name,m2->name);
}
@ -199,7 +199,7 @@ struct cw_Mod * cw_mod_load(const char * mod_name){
/* if modlist is not initialized, initialize ... */
if (mods_loaded==NULL){
mods_loaded=mavl_create(mod_cmp_mavl,NULL);
mods_loaded=mavl_create(mod_cmp_mavl,NULL,1312);
if (mods_loaded==NULL){
cw_log(LOG_ERROR, "Can't init modlist, no memory");
return NULL;

View File

@ -102,6 +102,8 @@ struct cw_Mod * cw_mod_detect(struct conn *conn,
struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
struct cw_Mod * capwap_mod, struct cw_Mod *bindings_mod);
void cw_mod_set_mod_path(const char * path);
#define CW_MOD_MAX_MOD_NAME_LEN 128
#define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface"

View File

@ -7,7 +7,7 @@
#include "conn.h"
struct cw_MsgSet {
mavl_t messages;
mavl_t msgdata;
mavl_t handlers_by_id;
mavl_t handlers_by_key;

View File

@ -6,11 +6,11 @@
#include "dbg.h"
#include "log.h"
#include "message_set.h"
#include "msget.h"
static int cmp_cw_elemhandler_by_id(const mavldata_t * elem1, const mavldata_t *elem2){
struct cw_ElemHandler * e1 = elem1->ptr;
struct cw_ElemHandler * e2 = elem2->ptr;
static int cmp_cw_elemhandler_by_id(const void * elem1, const void *elem2){
const struct cw_ElemHandler * e1 = elem1;
const struct cw_ElemHandler * e2 = elem2;
int r;
r = e1->id - e2->id;
if (r!=0)
@ -24,23 +24,23 @@ static int cmp_cw_elemhandler_by_id(const mavldata_t * elem1, const mavldata_t *
return 0;
}
static int cmp_cw_elemhandler_by_key(const mavldata_t *elem1, const mavldata_t *elem2){
struct cw_ElemHandler * e1 = elem1->ptr;
struct cw_ElemHandler * e2 = elem2->ptr;
static int cmp_cw_elemhandler_by_key(const void *elem1, const void *elem2){
const struct cw_ElemHandler * e1 = elem1;
const struct cw_ElemHandler * e2 = elem2;
return strcmp(e1->key,e2->key);
}
static int cmp_msgdata(const mavldata_t * elem1, const mavldata_t *elem2)
static int cmp_msgdata(const void * elem1, const void *elem2)
{
struct cw_MsgData * e1 = elem1->ptr;
struct cw_MsgData * e2 = elem2->ptr;
const struct cw_MsgData * e1 = elem1;
const struct cw_MsgData * e2 = elem2;
return e1->type - e2->type;
}
static int cmp_elemdata(const mavldata_t * elem1, const mavldata_t *elem2)
static int cmp_elemdata(const void * elem1, const void *elem2)
{
struct cw_ElemData * e1 = elem1->ptr;
struct cw_ElemData * e2 = elem2->ptr;
const struct cw_ElemData * e1 = elem1;
const struct cw_ElemData * e2 = elem2;
int r;
r = e1->id - e2->id;
if (r!=0)
@ -66,26 +66,9 @@ static void msgdata_destroy(struct cw_MsgData *data){
free(data);
}
static struct cw_MsgData * msgdata_create(int type){
struct cw_MsgData * msg;
msg = malloc( sizeof(struct cw_MsgData));
if (!msg)
return NULL;
msg->elements_tree = mavl_create(cmp_elemdata,mavl_free_bin);
if (!msg->elements_tree){
msgdata_destroy(msg);
return NULL;
}
msg->type=type;
return msg;
}
static void del_mavl_msdgdata( mavldata_t * d ){
msgdata_destroy(d->ptr);
static void del_mavl_msdgdata( void * d ){
msgdata_destroy(d);
}
@ -94,8 +77,8 @@ static void del_mavl_msdgdata( mavldata_t * d ){
* @param set Message set to destroy
*/
void cw_msgset_destroy(struct cw_MsgSet * set){
if (set->messages)
mavl_destroy(set->messages);
if (set->msgdata)
mavl_destroy(set->msgdata);
if (set->handlers_by_id)
mavl_destroy(set->handlers_by_id);
if (set->handlers_by_key)
@ -118,22 +101,25 @@ struct cw_MsgSet * cw_msgset_create(){
memset(set,0,sizeof(struct cw_MsgSet));
/* create mavl for all_elems by id */
set->handlers_by_id = mavl_create(cmp_cw_elemhandler_by_id,mavl_free_bin);
set->handlers_by_id = mavl_create(cmp_cw_elemhandler_by_id,NULL,
sizeof(struct cw_ElemHandler));
if (set->handlers_by_id==NULL){
cw_msgset_destroy(set);
return NULL;
}
/* create mavl for all_elems by id */
set->handlers_by_key = mavl_create(cmp_cw_elemhandler_by_key,NULL);
/* create mavl for all_elems by key */
set->handlers_by_key = mavl_create(cmp_cw_elemhandler_by_key,NULL,
sizeof(struct cw_ElemHandler));
if (set->handlers_by_key==NULL){
cw_msgset_destroy(set);
return NULL;
}
/* create mavl for messages */
set->messages = mavl_create(cmp_msgdata,del_mavl_msdgdata);
if (set->messages==NULL){
set->msgdata = mavl_create(cmp_msgdata,del_mavl_msdgdata,
sizeof(struct cw_MsgData));
if (set->msgdata==NULL){
cw_msgset_destroy(set);
return NULL;
}
@ -148,7 +134,7 @@ struct cw_ElemHandler * cw_msgset_get_elemhandler(struct cw_MsgSet * set,
search.proto=proto;
search.vendor=vendor;
search.id=id;
return mavl_find_ptr(set->handlers_by_id,&search);
return mavl_find(set->handlers_by_id,&search);
}
@ -156,11 +142,12 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
struct cw_MsgDef * msgdef)
{
struct cw_ElemDef * elemdef;
mavldata_t mavldata, *result;
struct cw_ElemData ed, *result;
/* iterate through all defined elements */
for(elemdef = msgdef->elements; elemdef->id; elemdef++){
struct cw_ElemHandler * handler;
int replaced;
handler = cw_msgset_get_elemhandler(set,
elemdef->proto,
@ -175,18 +162,15 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
continue;
}
mavldata.ptr = malloc(sizeof(struct cw_ElemData));
if (!mavldata.ptr){
cw_log(LOG_ERR,"Can't create ElemData element: %s",strerror(errno));
}
((struct cw_ElemData *)(mavldata.ptr))->id=elemdef->id;
((struct cw_ElemData *)(mavldata.ptr))->proto=elemdef->proto;
((struct cw_ElemData *)(mavldata.ptr))->vendor=elemdef->vendor;
((struct cw_ElemData *)(mavldata.ptr))->mand=elemdef->mand;
ed.id=elemdef->id;
ed.proto=elemdef->proto;
ed.vendor=elemdef->vendor;
ed.mand=elemdef->mand;
result = mavl_replace(msgdata->elements_tree, &mavldata);
if (result != &mavldata){
result = mavl_replace(msgdata->elements_tree, &ed, &replaced);
if (!replaced){
cw_dbg(DBG_MOD, " adding message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor,
@ -194,7 +178,7 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
handler->name);
}
else{
cw_dbg(DBG_MOD, " replaceing message element %d %d %d - %s",
cw_dbg(DBG_MOD, " replacing message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor,
elemdef->id,
@ -217,46 +201,34 @@ int cw_msgset_add(struct cw_MsgSet * set,
/* Create mavl for all handlers */
for(handler = handlers; handler->id; handler++){
mavldata_t copy;
copy.ptr = malloc(sizeof(struct cw_ElemHandler));
if (!copy.ptr){
cw_log(LOG_ERR,"Can't alloc mem:", strerror(errno));
continue;
}
cw_dbg(DBG_MOD,"Adding handler for element %d - %s - with key: %s",
handler->id,
handler->name,
handler->key);
memcpy(copy.ptr,handler,sizeof(struct cw_ElemHandler));
mavl_replace(set->handlers_by_id,&copy);
mavl_replace(set->handlers_by_key,&copy);
mavl_replace(set->handlers_by_id,handler,NULL);
mavl_replace(set->handlers_by_key,handler,NULL);
}
for (msgdef=messages; msgdef->type !=0; msgdef++){
struct cw_MsgData search, *msg;
struct cw_MsgData search;
struct cw_MsgData *msg;
int exists;
/* Look if message already exists */
search.type=msgdef->type;
msg = mavl_find_ptr(set->messages,&search);
msg = mavl_add(set->msgdata,&search,&exists);
if (!msg){
msg = msgdata_create(msgdef->type);
if (!msg){
if (msg == NULL){
cw_log(LOG_ERR,"Can't create messae");
return 0;
}
mavl_add_ptr(set->messages,msg);
}
if (!exists){
msg->elements_tree = mavl_create(cmp_elemdata,NULL,
sizeof(struct cw_ElemData));
}
/* Overwrite the found message */
if (msgdef->name)
msg->name=msgdef->name;
@ -283,5 +255,5 @@ int cw_msgset_add(struct cw_MsgSet * set,
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type){
struct cw_MsgData search;
search.type=type;
return mavl_find_ptr(set->messages,&search);
return mavl_find_ptr(set->msgdata,&search);
}

View File

@ -18,7 +18,7 @@ static void del(void* d)
struct avltree * stravltree_create()
{
return mavl_create(cmp,del);
return mavl_create(cmp,del,100);
}
const char * stravltree_add(struct avltree * t, const char * str)
@ -26,5 +26,5 @@ const char * stravltree_add(struct avltree * t, const char * str)
char * s = strdup(str);
if (!s)
return 0;
return mavl_add(t,s);
return mavl_add(t,s,NULL);
}

View File

@ -14,13 +14,13 @@ static void del(void* d)
cw_strheap_t cw_strheap_create()
{
return mavl_create(cmp,del);
return mavl_create(cmp,del,1312);
}
const char * cw_strheap_add(cw_strheap_t t, struct cw_strlist_elem *s)
{
mavl_del(t,s);
return mavl_add(t,s);
return mavl_add(t,s,NULL);
}
int cw_strheap_register_strings(cw_strheap_t h, struct cw_strlist_elem *s)