dded cw_type_bool
FossilOrigin-Name: 68578d9bfec30e3b66798a90c1412629c4769b2de16e5ecf3ad86dba8961c001
This commit is contained in:
parent
fd893751ee
commit
8912eb025c
@ -8,5 +8,6 @@ const cw_Type_t * cw_ktv_std_types[] = {
|
||||
CW_TYPE_IPADDRESS,
|
||||
CW_TYPE_STR,
|
||||
CW_TYPE_SYSPTR,
|
||||
CW_TYPE_BOOL,
|
||||
NULL
|
||||
};
|
||||
|
90
src/cw/cw_type_bool.c
Normal file
90
src/cw/cw_type_bool.c
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
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 "cw.h"
|
||||
#include "ktv.h"
|
||||
|
||||
static cw_KTV_t *get(cw_KTV_t * data, const uint8_t * src, int len)
|
||||
{
|
||||
data->type = &cw_type_byte;
|
||||
data->val.byte = cw_get_byte(src);
|
||||
return data;
|
||||
}
|
||||
|
||||
static int put(const cw_KTV_t *data, uint8_t * dst)
|
||||
{
|
||||
return cw_put_byte(dst, data->val.byte);
|
||||
}
|
||||
|
||||
static int to_str(const cw_KTV_t *data, char *dst, int max_len)
|
||||
{
|
||||
/*if (max_len<3){
|
||||
return 0;
|
||||
}*/
|
||||
if(data->val.boolean)
|
||||
return sprintf(dst, "%s", "true");
|
||||
else
|
||||
return sprintf(dst, "%s", "false");
|
||||
}
|
||||
|
||||
static cw_KTV_t *from_str(cw_KTV_t * data, const char *src)
|
||||
{
|
||||
if (cw_stricmp(src,"true") == 0){
|
||||
data->val.boolean=1;
|
||||
return data;
|
||||
}
|
||||
if (cw_stricmp(src,"yes") == 0){
|
||||
data->val.boolean=1;
|
||||
return data;
|
||||
}
|
||||
if (cw_stricmp(src,"on") == 0){
|
||||
data->val.boolean=1;
|
||||
return data;
|
||||
}
|
||||
if (atoi(src)==1){
|
||||
data->val.boolean=1;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
data->val.boolean=0;
|
||||
return data;
|
||||
}
|
||||
|
||||
static int len (cw_KTV_t * data)
|
||||
{
|
||||
return sizeof(int);
|
||||
}
|
||||
|
||||
static void * data( cw_KTV_t * data)
|
||||
{
|
||||
return & data->val.boolean;
|
||||
}
|
||||
|
||||
const struct cw_Type cw_type_bool = {
|
||||
"Bool", /* name */
|
||||
NULL, /* del */
|
||||
put, /* put */
|
||||
get, /* get */
|
||||
to_str, /* to_str */
|
||||
from_str, /* from_str */
|
||||
len, /* len */
|
||||
data /* data */
|
||||
};
|
@ -101,6 +101,7 @@ 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;
|
||||
extern const struct cw_Type cw_type_bool;
|
||||
|
||||
#define CW_TYPE_BYTE (&cw_type_byte)
|
||||
#define CW_TYPE_WORD (&cw_type_word)
|
||||
@ -109,7 +110,7 @@ extern const struct cw_Type cw_type_sysptr;
|
||||
#define CW_TYPE_IPADDRESS (&cw_type_ipaddress)
|
||||
#define CW_TYPE_SYSPTR (&cw_type_sysptr)
|
||||
#define CW_TYPE_STR (&cw_type_str)
|
||||
|
||||
#define CW_TYPE_BOOL (&cw_type_bool)
|
||||
/*
|
||||
void cw_kvstore_mavl_delete(const void *data);
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user