Moved out from mbag.c and added methods.
FossilOrigin-Name: 95705056262cb62fac9d8d31a8bca2051332555f6d5521f9d5f0f30229369dd7
This commit is contained in:
parent
c69570713e
commit
350b62a49b
43
src/capwap/mbag_type_bstr16.c
Normal file
43
src/capwap/mbag_type_bstr16.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
#include "mbag.h"
|
||||||
|
#include "format.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int to_str(void *item,char *dst)
|
||||||
|
{
|
||||||
|
mbag_item_t *i= item;
|
||||||
|
|
||||||
|
// bstr16_t src = i->data;
|
||||||
|
// printf("From str resul: '%.*s'\n",bstr16_len(src),bstr16_data(src));
|
||||||
|
|
||||||
|
// exit(0);
|
||||||
|
|
||||||
|
|
||||||
|
char *d = dst;
|
||||||
|
int utf8 = cw_is_utf8(bstr16_data(i->data), bstr16_len(i->data));
|
||||||
|
|
||||||
|
|
||||||
|
if (utf8) {
|
||||||
|
d += sprintf(d, "%.*s", bstr16_len(i->data), bstr16_data(i->data));
|
||||||
|
} else {
|
||||||
|
d += sprintf(d, ".x");
|
||||||
|
d += cw_format_hex(d, bstr16_data(i->data), bstr16_len(i->data));
|
||||||
|
}
|
||||||
|
return d-dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct mbag_item * from_str(const char *src)
|
||||||
|
{
|
||||||
|
mbag_item_t * i = mbag_item_new(MBAG_BSTR16);
|
||||||
|
if (!i)
|
||||||
|
return NULL;
|
||||||
|
i->data=bstr16_create_from_str(src);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct mbag_typedef mbag_type_bstr16 = {
|
||||||
|
"Bstr16",free,to_str,from_str
|
||||||
|
};
|
44
src/capwap/mbag_type_byte.c
Normal file
44
src/capwap/mbag_type_byte.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
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 "mbag.h"
|
||||||
|
|
||||||
|
|
||||||
|
static struct mbag_item * from_str(const char *src)
|
||||||
|
{
|
||||||
|
mbag_item_t * i = mbag_item_new(MBAG_BYTE);
|
||||||
|
if (!i)
|
||||||
|
return NULL;
|
||||||
|
i->byte=atoi(src);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int to_str(void *item,char *dst)
|
||||||
|
{
|
||||||
|
mbag_item_t *i= item;
|
||||||
|
return sprintf(dst, "%d", i->byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Defines a word, two bytes. */
|
||||||
|
const struct mbag_typedef mbag_type_byte = {
|
||||||
|
"Byte",NULL,to_str,from_str
|
||||||
|
};
|
||||||
|
|
||||||
|
|
43
src/capwap/mbag_type_dword.c
Normal file
43
src/capwap/mbag_type_dword.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
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 "mbag.h"
|
||||||
|
|
||||||
|
|
||||||
|
static struct mbag_item * from_str(const char *src)
|
||||||
|
{
|
||||||
|
mbag_item_t * i = mbag_item_new(MBAG_DWORD);
|
||||||
|
if (!i)
|
||||||
|
return NULL;
|
||||||
|
i->word=atoi(src);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int to_str(void *item,char *dst)
|
||||||
|
{
|
||||||
|
mbag_item_t *i= item;
|
||||||
|
return sprintf(dst, "%d", i->dword);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const struct mbag_typedef mbag_type_dword = {
|
||||||
|
"DWORD",NULL,to_str,from_str
|
||||||
|
};
|
||||||
|
|
||||||
|
|
36
src/capwap/mbag_type_mbag.c
Normal file
36
src/capwap/mbag_type_mbag.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
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 "mbag.h"
|
||||||
|
|
||||||
|
static void del_fun(void *i)
|
||||||
|
{
|
||||||
|
mbag_t x = (mbag_t)i;
|
||||||
|
mavl_destroy(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct mbag_typedef mbag_type_mbag = {
|
||||||
|
"Mbag",del_fun
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct mbag_typedef mbag_type_mbag_dyn = {
|
||||||
|
"Mbag_Dyn",del_fun
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
|||||||
#include "mbag.h"
|
#include "mbag.h"
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
|
||||||
|
/*
|
||||||
static struct mbag_item * from_str(const char *src)
|
static struct mbag_item * from_str(const char *src)
|
||||||
{
|
{
|
||||||
struct mbag_item *i= malloc(sizeof(struct sockaddr_storage));
|
struct mbag_item *i= malloc(sizeof(struct sockaddr_storage));
|
||||||
@ -48,7 +49,7 @@ static int to_str(void *item,char *dst)
|
|||||||
mbag_item_t *i= item;
|
mbag_item_t *i= item;
|
||||||
return sprintf(dst, "%d", i->word);
|
return sprintf(dst, "%d", i->word);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MBAG items of this type hold an struct sockaddr element.
|
* MBAG items of this type hold an struct sockaddr element.
|
||||||
|
80
src/capwap/mbag_type_vendorstr.c
Normal file
80
src/capwap/mbag_type_vendorstr.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
This file is part of libcapwap.
|
||||||
|
|
||||||
|
libcapwap is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
libcapwap is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@file
|
||||||
|
*@brief Implementation of mbag_type vendorstr
|
||||||
|
*@addtogroup MbagFunctions
|
||||||
|
*@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mbag.h"
|
||||||
|
#include "format.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int to_str(void *item,char *dst)
|
||||||
|
{
|
||||||
|
|
||||||
|
mbag_item_t *i= item;
|
||||||
|
|
||||||
|
char *d=dst;
|
||||||
|
d+=sprintf(d,"%d,",vendorstr_get_vendor_id(i->data));
|
||||||
|
|
||||||
|
if (cw_is_utf8(vendorstr_data(i->data), vendorstr_len(i->data))) {
|
||||||
|
d += sprintf(d, "%.*s", vendorstr_len(i->data),
|
||||||
|
vendorstr_data(i->data));
|
||||||
|
} else {
|
||||||
|
d += sprintf(d, ".x");
|
||||||
|
d += cw_format_hex(d, vendorstr_data(i->data), vendorstr_len(i->data));
|
||||||
|
}
|
||||||
|
|
||||||
|
return d-dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct mbag_item * from_str(const char *src)
|
||||||
|
{
|
||||||
|
mbag_item_t * i = mbag_item_new(MBAG_VENDORSTR);
|
||||||
|
if (!i)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
uint32_t vendor_id=atoi(src);
|
||||||
|
const char *s = strchr(src,',');
|
||||||
|
|
||||||
|
|
||||||
|
if (s){
|
||||||
|
i->data=vendorstr_create_from_str(vendor_id,s+1);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
i->data=vendorstr_create_from_str(vendor_id,"");
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the VendorStr type.
|
||||||
|
*
|
||||||
|
* MBAG items of this type containing a variable of type #vendorstr_t.
|
||||||
|
*/
|
||||||
|
const struct mbag_typedef mbag_type_vendorstr = {
|
||||||
|
"VendorStr",free,to_str,from_str
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**@}*/
|
@ -18,16 +18,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "mbag.h"
|
#include "mbag.h"
|
||||||
#include "format.h"
|
|
||||||
|
|
||||||
|
|
||||||
static struct mbag_item * from_str(const char *src)
|
static struct mbag_item * from_str(const char *src)
|
||||||
{
|
{
|
||||||
struct mbag_item *i= malloc(sizeof(mbag_item_t));
|
mbag_item_t * i = mbag_item_new(MBAG_WORD);
|
||||||
if (!i)
|
if (!i)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
i->type = MBAG_WORD;
|
|
||||||
i->word=atoi(src);
|
i->word=atoi(src);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user