Not neede enymore.

FossilOrigin-Name: d215621f3aa09dbdf16c617fe91d730e6ffcd5ad404153fd5f910fa954095bb3
This commit is contained in:
7u83@mail.ru 2015-04-20 17:21:52 +00:00
parent c5da64789d
commit 32fa2ae608
4 changed files with 0 additions and 973 deletions

View File

@ -1,674 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief Yet another AVL tree implementation
*/
#include <stdlib.h>
#include <stdio.h>
#include "avltree.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 #avltree struct
*/
struct avltree *avltree_create(int (*cmp) (const void *, const void *),
void (*del) (void *))
{
struct avltree *t = malloc(sizeof(struct avltree));
if (!t)
return NULL;
t->root = 0;
t->count = 0;
t->cmp = cmp;
t->del = del;
return t;
}
struct avlnode *avlnode_create(void *data)
{
struct avlnode *n = malloc(sizeof(struct avlnode));
if (!n)
return NULL;
n->left = n->right = 0;
n->bal = 0;
n->data = data;
return n;
}
void avlnode_destroy(struct avltree *t, struct avlnode *n)
{
if (t->del) {
t->del(n->data);
}
free(n);
t->count--;
}
static int avltree_add0(struct avltree *t, struct avlnode **parent, void **data)
{
// struct avlnode * rn;
struct avlnode *tmp;
struct avlnode *n = *parent;
int rc = t->cmp(*data, n->data);
int bal;
if (rc == 0) {
*data = n->data;
return 2;
}
if (rc < 0) {
if (n->left) {
bal = avltree_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;
}
//printf("!!!!left bal = %i\n",n->left->bal);
//exit(0);
}
return bal;
}
/* n->left is 0 */
n->left = avlnode_create(*data);
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 = avltree_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;
}
//printf("!!!!iright bal = %i\n",n->left->bal);
//exit(0);
}
return bal;
}
/* n->right is 0 */
n->right = avlnode_create(*data);
if (!n->right)
return 3;
t->count++;
if (n->left == 0) {
n->bal = 1;
return 1;
}
n->bal = 0;
return 0;
}
}
/**
* Add an element to an AVL tree
* @t avltree
* @data pointer to element
* @return added alement or NULL if error.
*/
void *avltree_add(struct avltree *t, void *data)
{
if (t->root == 0) {
t->root = avlnode_create(data);
if (t->root)
t->count++;
return t->root->data;
}
void *d = data;
int rc = avltree_add0(t, &t->root, &d);
if (rc > 3)
return NULL;
return d;
}
static void rot_l(struct avlnode *n, struct avlnode **parent)
{
struct avlnode *tmp;
*parent = n->right;
tmp = n->right->left;
n->right->left = n;
n->right = tmp;
}
static void rot_r(struct avlnode *n, struct avlnode **parent)
{
struct avlnode *tmp;
*parent = n->left;
tmp = n->left->right;
n->left->right = n;
n->left = tmp;
}
/*
* Delete the node with the highest value
* returns the rebalancing factor
*/
/*
static int avltree_delete_hi(struct avlnode **parent, void **data)
{
struct avlnode * n = *parent;
if(n->right!=0){
int bal = avltree_delete_hi(&n->right,data);
n->bal-=bal;
if (n->bal==-2){
// if (rotate_r(n,parent))
// return 0;
}
return bal;
}
*parent=n->left;
*data = n->data;
if (n->left){
free(n);
return 0;
}
free(n);
return 1;
}
*/
//struct avltree * trrr;
static void rot_rl(struct avlnode *n, struct avlnode **parent)
{
struct avlnode *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 avlnode *n, struct avlnode **parent)
{
struct avlnode *tmp;
*parent = n->left->right;
n->left->right = (*parent)->left;
(*parent)->left = n->left;
tmp = (*parent)->right;
(*parent)->right = n;
n->left = tmp;
}
static int adj_bal_l(struct avlnode *n, struct avlnode **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) {
// int rb;
n->bal = 0;
n->right->bal = 0;
// rb = n->right->left->bal;
n->right->left->bal = 0;
rot_rl(n, parent);
return 1;
}
// printf("adj bal l not handled \n");
// exit(0);
return -11; /* that should never happen */
}
int adj_bal_r(struct avlnode *n, struct avlnode **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) {
// int rb;
n->bal = 0;
n->left->bal = 0;
// rb = n->left->right->bal;
n->left->right->bal = 0;
rot_lr(n, parent);
return 1;
}
// printf("adj bal li left not handled \n");
// exit(0);
return -11; /* that should never happen */
}
static int avltree_del_lo(struct avlnode **parent, void **data)
{
struct avlnode *n = *parent;
if (n->left != 0) {
int bal = avltree_del_lo(&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;
free(n);
return 1;
if (n->right) {
free(n);
return 1;
}
free(n);
return 1;
}
int avltree_del0(struct avltree *t, struct avlnode **parent, void **data)
{
struct avlnode *n = *parent;
int rc;
int bal;
rc = t->cmp(*data, n->data);
if (rc == 0) {
if (n->right == 0 && n->left == 0) {
*parent = 0;
avlnode_destroy(t, n);
return 1;
}
if (n->right && n->left == 0) {
*parent = n->right;
avlnode_destroy(t, n);
return 1;
}
if (n->left && n->right == 0) {
avlnode_destroy(t, n);
*parent = n->left;
return 1;
}
/* node has two childs */
if (t->del) {
t->del(n->data);
}
t->count--;
bal = avltree_del_lo(&n->right, &n->data);
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 = avltree_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 = avltree_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 *avltree_del(struct avltree *t, void *data)
{
if (!t->root)
return NULL;
void *d = data;
int rc = avltree_del0(t, &t->root, &d);
if (rc == 2)
return NULL;
return data;
}
/*
static int cmp(const void *k1,const void *k2)
{
int x1 = *((int*)k1);
int x2 = *((int*)k2);
return x1-x2;
}
*/
//int data[]={10,37,60,10,5,35,36,26,3,11,18};
//int data[] = {100,50,75};
//int data[]={100,200,150,300,400};
//int data[]={100,200,150,170,470};
//int data[]={10,20,15,17,47,50,60,70,80};
//int data[]={9,8,7,6,5,4,3,2,1,0};
//int data[]={10,37,60,10,5,35,19,26,3,11,18};
//int data[]={0,11,14,33,37,20};
//int data[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//int data[]={1,4,3,7,5,6,7,8,9,10};
//int data[]={11,4,5,6,3,4,3,2,1,0};
//int data[]={20,16,10,11,5,4,3,2,1,0};
/*
struct avlnode * ar[10000];
int tpw = 80;
static void print_tree0(struct avlnode * n,int d,int l,int r)
{
int pos = l+(r-l)/2;
ar[d*tpw+pos]=n;
if (n->right)
print_tree0(n->right,d+1,l+(r-l)/2,r);
if(n->left)
print_tree0(n->left,d+1,l,r-(r-l)/2);
}
void avltree_print(struct avlnode * n )
{
int y;
int i=0;
for(i=0; i<10000; i++)
ar[i]=0;
if (n==0){
printf("Empty Tree\n");
return ;
}
print_tree0(n,0,0,tpw);
for (i=0; i<10; i++) {
for (y=0; y<tpw; y++){
struct avlnode *r=ar[tpw*i+y];
if(r){
printf("%i(%i)",*(int*)(r->data),r->bal);
}
else{
printf(".");
}
}
printf("\n");
}
}
void walk(struct avlnode *n)
{
if (n == 0)
return;
walk(n->left);
int x = *((int*)(n->data));
printf("VAL: %i\n",x);
walk(n->right);
// x = *((int*)(n->data));
// printf("VALR: %i\n",x);
}
*/
/*
void avltree_destroy(struct avltree *t)
{
avltree_del_all(t);
free (t);
}
*/
//#include <time.h>
/*
//int data[]={5,1,9,7,0,10,8,0,4,3};
//int data[]={50,10,90,70,00,100,80,00,40,30,1,2,3};
int data[]={10,20,30,45,1,50,11,51,60,70,80,90,99,25,50,10,90,70,00,100,80,00,40,30,1,2,3};
int main()
{
struct avltree *t = avltree_create(cmp,0);
trrr=t;
printf("T: %p\n",t);
srand(time(NULL));
int i=0;
for (i=0; i<6; i++)
{
int r = rand()%0x3f; // % 0xiff;
// int r = rand(); //%0x3f; // % 0xiff;
// r = data[7-i];
r = data[i];
int * dr = malloc(sizeof(int));
*dr = r;
printf("Insert %i\n",*dr);
void * d = avltree_insert(t,dr);
printf("After insert %i\n",r);
print_tree(t->root);
if (d!=dr){
// printf("exists\n");
}
}
printf("Here it is\n");
print_tree(t->root);
// walk(t->root);
void * da;
int x = 110;
// void * drc = avltree_delete(t,&x);
avltree_delete_all(t);
// printf("Delete 110 rc = %p\n",drc);
print_tree(t->root);
printf("Count: %i\n",t->count);
return 0;
}
*/

View File

@ -1,100 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include "capwap.h"
#include "capwap_80211.h"
#include "cw_log.h"
#include "cw_util.h"
struct eparm {
int *mand;
struct wtpinfo *wtpinfo;
};
static int wtpinfo_readelem_discovery_req(void *eparm, int type,
uint8_t * msgelem, int len)
{
struct eparm *e = (struct eparm *) eparm;
cw_dbg_msgelem(CW_MSG_DISCOVERY_REQUEST, type, msgelem, len);
/* mandatory message elements */
if (wtpinfo_readelem_discovery_type
(e->wtpinfo, type, msgelem, len))
goto foundX;
if (wtpinfo_readelem_wtp_board_data
(e->wtpinfo, type, msgelem, len))
goto foundX;
if (wtpinfo_readelem_wtp_descriptor
(e->wtpinfo, type, msgelem, len))
goto foundX;
if (wtpinfo_readelem_wtp_frame_tunnel_mode
(e->wtpinfo, type, msgelem, len))
goto foundX;
if (wtpinfo_readelem_wtp_mac_type(e->wtpinfo, type, msgelem, len))
goto foundX;
if (wtpinfo_readelem_wtp_radio_info
(e->wtpinfo, type, msgelem, len))
goto foundX;
/* non-mandatory mesage lements */
if (cw_readelem_mtu_discovery_padding(type, msgelem, len))
return 1;
if (cw_readelem_vendor_specific_payload
(e->wtpinfo, CW_MSG_DISCOVERY_REQUEST, type, msgelem, len))
return 1;
return 0;
foundX:
cw_mand_elem_found(e->mand, type);
return 1;
}
void cwread_discovery_request(struct wtpinfo *wtpinfo, uint8_t * msg,
int len)
{
int mand[] = {
CW_ELEM_DISCOVERY_TYPE,
CW_ELEM_WTP_BOARD_DATA,
CW_ELEM_WTP_DESCRIPTOR,
CW_ELEM_WTP_FRAME_TUNNEL_MODE,
CW_ELEM_WTP_MAC_TYPE,
CWMSGELEM_80211_WTP_RADIO_INFO,
-1
};
struct eparm eparm;
eparm.wtpinfo = wtpinfo;
eparm.mand = mand;
cw_foreach_msgelem(msg, len, wtpinfo_readelem_discovery_req,
&eparm);
cw_dbg_missing_mand_elems_(0, CW_MSG_DISCOVERY_REQUEST, eparm.mand);
}

View File

@ -1,91 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include "capwap.h"
#include "acinfo.h"
#include "cw_util.h"
#include "cw_log.h"
#include <sys/socket.h>
#include <netinet/in.h>
struct eparm {
int *mand;
struct ac_info *acinfo;
};
static int acinfo_readelem_discovery_resp(void * eparm,int type,uint8_t* msgelem,int len)
{
cw_dbg_msgelem(CW_MSG_DISCOVERY_RESPONSE, type, msgelem, len);
struct eparm *e = (struct eparm *) eparm;
if (cw_readelem_ac_descriptor(e->acinfo,type,msgelem,len))
goto foundX;
if (acinfo_readelem_ac_name(e->acinfo,type,msgelem,len))
goto foundX;
if (acinfo_readelem_ctrl_ip_addr(e->acinfo,type,msgelem,len)){
cw_mand_elem_found(e->mand, XCWMSGELEM_CAPWAP_CONTROL_IP_ADDRESS);
return 1;
}
return 0;
foundX:
cw_mand_elem_found(e->mand, type);
return 1;
}
void cwread_discovery_response(struct ac_info * acinfo, uint8_t * msg, int len)
{
int mand[] = {
CW_ELEM_AC_DESCRIPTOR,
CW_ELEM_AC_NAME,
XCWMSGELEM_CAPWAP_CONTROL_IP_ADDRESS,
XCWMSGELEM_CAPWAP_RADIO_INFO,
-1
};
struct eparm eparm;
eparm.acinfo = acinfo;
eparm.mand = mand;
cw_foreach_msgelem(msg,len,acinfo_readelem_discovery_resp,&eparm);
cw_dbg_missing_mand_elems_(0, CW_MSG_DISCOVERY_RESPONSE, eparm.mand);
}

View File

@ -1,108 +0,0 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "wtpinfo.h"
#include "capwap.h"
#include "log.h"
/*
int wtpinfo_readelem_ecn_support(struct wtpinfo * wtpinfo, int type, uint8_t * msgelem, int len)
{
if (type != CWMSGELEM_ECN_SUPPORT)
return 0;
if (len!=1){
cw_log_debug0("Discarding ECN_SUPPORT msgelem, wrong size, type=%d,len=%d",type,len);
return 1;
}
wtpinfo->ecn_support=*msgelem;
return 1;
}
*/
int cw_readelem_cw_local_ip_addr(struct sockaddr * local_ip, int type, uint8_t * msgelem, int len)
{
switch (type){
case CW_ELEM_CAPWAP_LOCAL_IPV4_ADDRESS:
{
if (len!=4)
return -1;
struct sockaddr_in * sain = (struct sockaddr_in*)local_ip;
memset(sain,0,sizeof(struct sockaddr_in));
#ifdef HAVE_SIN_LEN
sain->sa_len=sizeof(struct sockaddr_in);
#endif
memcpy(&sain->sin_addr,msgelem,len);
sain->sin_family=AF_INET;
return 1;
}
#ifdef WITH_IPV6
case CW_ELEM_CAPWAP_LOCAL_IPV6_ADDRESS:
{
if (len!=16)
return -1;
struct sockaddr_in6 * sain = (struct sockaddr_in6*)local_ip;
memset(sain,0,sizeof(struct sockaddr_in6));
#ifdef HAVE_SIN6_LEN
sain->sa_len=sizeof(struct sockaddr_in);
#endif
memcpy(&sain->sin6_addr,msgelem,len);
sain->sin6_family=AF_INET6;
return 1;
}
#endif
}
return 0;
}
int wtpinfo_readelem_cw_local_ip_addr(struct wtpinfo * wtpinfo, int type, uint8_t * msgelem, int len)
{
switch (type){
case CW_ELEM_CAPWAP_LOCAL_IPV4_ADDRESS:
{
if (len!=4)
return -1;
struct sockaddr_in * sain = (struct sockaddr_in*)&wtpinfo->local_ip;
memset(sain,0,sizeof(struct sockaddr_in));
#ifdef HAVE_SIN_LEN
sain->sa_len=sizeof(struct sockaddr_in);
#endif
memcpy(&sain->sin_addr,msgelem,len);
sain->sin_family=AF_INET;
return 1;
}
#ifdef WITH_IPV6
case CW_ELEM_CAPWAP_LOCAL_IPV6_ADDRESS:
{
if (len!=16)
return -1;
struct sockaddr_in6 * sain = (struct sockaddr_in6*)&wtpinfo->local_ip;
memset(sain,0,sizeof(struct sockaddr_in6));
#ifdef HAVE_SIN6_LEN
sain->sa_len=sizeof(struct sockaddr_in);
#endif
memcpy(&sain->sin6_addr,msgelem,len);
sain->sin6_family=AF_INET6;
return 1;
}
#endif
}
return 0;
}