2018-04-04 09:03:08 +02:00
|
|
|
/*
|
|
|
|
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"
|
2022-07-31 17:15:32 +02:00
|
|
|
#include "val.h"
|
2018-04-04 09:03:08 +02:00
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static cw_Val_t *get(cw_Val_t * data, const uint8_t * src, int len)
|
2018-04-04 09:03:08 +02:00
|
|
|
{
|
2018-04-04 09:59:19 +02:00
|
|
|
data->type = &cw_type_bool;
|
|
|
|
data->val.boolean = cw_get_byte(src);
|
2018-04-04 09:03:08 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static int put(const cw_Val_t *data, uint8_t * dst)
|
2018-04-04 09:03:08 +02:00
|
|
|
{
|
2018-04-04 09:59:19 +02:00
|
|
|
return cw_put_byte(dst, data->val.boolean);
|
2018-04-04 09:03:08 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static int to_str(const cw_Val_t *data, char *dst, int max_len)
|
2018-04-04 09:03:08 +02:00
|
|
|
{
|
|
|
|
/*if (max_len<3){
|
|
|
|
return 0;
|
|
|
|
}*/
|
|
|
|
if(data->val.boolean)
|
|
|
|
return sprintf(dst, "%s", "true");
|
|
|
|
else
|
|
|
|
return sprintf(dst, "%s", "false");
|
|
|
|
}
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static cw_Val_t *from_str(cw_Val_t * data, const char *src)
|
2018-04-04 09:03:08 +02:00
|
|
|
{
|
2018-04-04 09:59:19 +02:00
|
|
|
data->type = &cw_type_bool;
|
2018-04-04 09:03:08 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static int len (cw_Val_t * data)
|
2018-04-04 09:03:08 +02:00
|
|
|
{
|
|
|
|
return sizeof(int);
|
|
|
|
}
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static void * data( cw_Val_t * data)
|
2018-04-04 09:03:08 +02:00
|
|
|
{
|
|
|
|
return & data->val.boolean;
|
|
|
|
}
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
static const char * get_type_name(cw_Val_t *data)
|
2018-04-25 10:43:27 +02:00
|
|
|
{
|
|
|
|
return CW_TYPE_BOOL->name;
|
|
|
|
}
|
|
|
|
|
2018-04-04 09:03:08 +02:00
|
|
|
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 */
|
2018-04-25 10:43:27 +02:00
|
|
|
data, /* data */
|
|
|
|
get_type_name /* get_type_name */
|
2018-04-04 09:03:08 +02:00
|
|
|
};
|