new type cw_type_str
FossilOrigin-Name: 4ed9b74635d04e6691d964a6a5503be3f878591d5d23ec62d4a5e5e93933fc03
This commit is contained in:
parent
b5a0e21141
commit
8910504b4b
@ -105,6 +105,7 @@ CWSRC=\
|
||||
cw_strlist_get_str.c\
|
||||
cw_type_bstr16.c\
|
||||
cw_type_byte.c\
|
||||
cw_type_str.c\
|
||||
cw_type_dword.c\
|
||||
cw_type_ipaddress.c\
|
||||
cw_type_word.c\
|
||||
@ -126,6 +127,7 @@ LWSRC=\
|
||||
lw_put_80211_wtp_wlan_radio_configuration.c\
|
||||
lw_put_ac_descriptor.c\
|
||||
lw_put_bstr.c\
|
||||
lw_put_str.c\
|
||||
lw_put_cisco_path_mtu.c\
|
||||
lw_put_image_data.c\
|
||||
lw_put_sockaddr.c\
|
||||
|
@ -49,6 +49,12 @@
|
||||
*/
|
||||
#define cw_put_data lw_put_data
|
||||
|
||||
|
||||
/**
|
||||
* Put a 0-terminated string
|
||||
*/
|
||||
#define cw_put_str lw_put_str
|
||||
|
||||
/**
|
||||
* Put a bstr_t object
|
||||
* see #lw_put_bstr
|
||||
|
85
src/cw/cw_type_str.c
Normal file
85
src/cw/cw_type_str.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
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 <stdio.h>
|
||||
|
||||
#include "format.h"
|
||||
#include "cw.h"
|
||||
#include "ktv.h"
|
||||
|
||||
|
||||
static void del ( struct cw_KTV * data )
|
||||
{
|
||||
free ( data->val.str );
|
||||
}
|
||||
|
||||
static struct cw_KTV *get ( struct cw_KTV * data, const uint8_t * src, int len )
|
||||
{
|
||||
uint8_t * s;
|
||||
s = malloc (len+1);
|
||||
if ( !s )
|
||||
return NULL;
|
||||
|
||||
memcpy(s,src,len);
|
||||
s[len]=0;
|
||||
|
||||
data->type = &cw_type_str;
|
||||
data->val.str = s;
|
||||
return data;
|
||||
}
|
||||
|
||||
static int put ( const struct cw_KTV *data, uint8_t * dst )
|
||||
{
|
||||
return cw_put_str ( dst, data->val.str );
|
||||
}
|
||||
|
||||
static int to_str ( const struct cw_KTV *data, char *dst, int max_len )
|
||||
{
|
||||
int l;
|
||||
|
||||
strncpy(dst,data->val.str,max_len-1);
|
||||
dst[max_len]=0;
|
||||
return strlen(data->val.str)+1;
|
||||
}
|
||||
|
||||
static struct cw_KTV *from_str ( struct cw_KTV * data, const char *src )
|
||||
{
|
||||
uint8_t * s;
|
||||
s = cw_strdup(src);
|
||||
|
||||
if ( !s )
|
||||
return NULL;
|
||||
|
||||
data->type = &cw_type_str;
|
||||
data->val.str = s;
|
||||
return data;
|
||||
}
|
||||
|
||||
static int len ( struct cw_KTV * data ){
|
||||
return strlen (data->val.str);
|
||||
}
|
||||
|
||||
const struct cw_Type cw_type_str = {
|
||||
"Str", /* name */
|
||||
del, /* del */
|
||||
put, /* put */
|
||||
get, /* get */
|
||||
to_str, /* to_str */
|
||||
from_str, /* from_str */
|
||||
len /* len */
|
||||
};
|
@ -36,6 +36,7 @@ struct cw_KTV {
|
||||
uint16_t word;
|
||||
uint8_t byte;
|
||||
void *ptr;
|
||||
char *str;
|
||||
int boolean;
|
||||
} val;
|
||||
};
|
||||
@ -95,6 +96,7 @@ 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;
|
||||
extern const struct cw_Type cw_type_str;
|
||||
extern const struct cw_Type cw_type_ipaddress;
|
||||
extern const struct cw_Type cw_type_sysptr;
|
||||
|
||||
@ -104,6 +106,7 @@ extern const struct cw_Type cw_type_sysptr;
|
||||
#define CW_TYPE_BSTR16 (&cw_type_bstr16)
|
||||
#define CW_TYPE_IPADDRESS (&cw_type_ipaddress)
|
||||
#define CW_TYPE_SYSPTR (&cw_type_sysptr)
|
||||
#define CW_TYPE_STR (&cw_type_str)
|
||||
|
||||
/*
|
||||
void cw_kvstore_mavl_delete(const void *data);
|
||||
|
@ -27,16 +27,6 @@ int lw_put_bstr16(uint8_t * dst, const bstr16_t b){
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put a string to an output buffer
|
||||
* @param dst Output buffer
|
||||
* @param str zero-terminated string to put
|
||||
* @return number of bytes put
|
||||
*/
|
||||
int lw_put_str(uint8_t*dst,const uint8_t *str) {
|
||||
return lw_put_data(dst,str,strlen((char*)str));
|
||||
}
|
||||
|
||||
|
||||
int lw_put_elem_hdr(uint8_t *dst,uint8_t type,uint16_t len)
|
||||
{
|
||||
|
@ -12,10 +12,6 @@ static int init(struct cw_Mod * mod, mavl_t global_cfg, int role)
|
||||
{
|
||||
cw_dbg(DBG_INFO,"CAPWAP: Inititalizing mod_capwap.");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
switch (role){
|
||||
case CW_ROLE_AC:{
|
||||
cw_dbg(DBG_MOD, "CAPWAP: Initialiazing mod_capwap in AC mode");
|
||||
@ -52,7 +48,6 @@ int static setup_cfg(struct conn * conn)
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user