2018-03-03 08:15:19 +01: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"
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "ktv.h"
|
2018-03-03 08:15:19 +01:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
static struct cw_KTV *get(struct cw_KTV * data, const uint8_t * src, int len)
|
2018-03-06 03:08:14 +01:00
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
data->type = &cw_type_dword;
|
|
|
|
data->val.dword = cw_get_dword(src);
|
2018-03-06 03:08:14 +01:00
|
|
|
return data;
|
2018-03-03 08:15:19 +01:00
|
|
|
}
|
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
static int put(const struct cw_KTV *data, uint8_t * dst)
|
2018-03-03 08:15:19 +01:00
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
return cw_put_dword(dst, data->val.dword);
|
2018-03-03 08:15:19 +01:00
|
|
|
}
|
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
static int to_str(const struct cw_KTV *data, char *dst, int max_len)
|
2018-03-03 08:15:19 +01:00
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
return sprintf(dst, "%d", data->val.dword);
|
2018-03-03 08:15:19 +01:00
|
|
|
}
|
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
static struct cw_KTV *from_str(struct cw_KTV * data, const char *src)
|
2018-03-03 08:15:19 +01:00
|
|
|
{
|
2018-03-15 20:07:17 +01:00
|
|
|
data->type = &cw_type_dword;
|
2018-03-11 00:56:41 +01:00
|
|
|
data->val.dword = atoi(src);
|
2018-03-06 03:08:14 +01:00
|
|
|
return data;
|
2018-03-03 08:15:19 +01:00
|
|
|
}
|
|
|
|
|
2018-04-25 10:43:27 +02:00
|
|
|
static const char * get_type_name(cw_KTV_t *data)
|
|
|
|
{
|
|
|
|
return CW_TYPE_DWORD->name;
|
|
|
|
}
|
|
|
|
|
2018-05-14 23:30:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
static int cast(cw_KTV_t * data)
|
|
|
|
{
|
|
|
|
if (strcmp(data->type->name,CW_TYPE_BYTE->name)==0)
|
|
|
|
return 1;
|
|
|
|
if (strcmp(data->type->name,CW_TYPE_STR->name)==0){
|
|
|
|
char *src = data->val.ptr;
|
|
|
|
CW_TYPE_DWORD->from_str(data,src);
|
|
|
|
free(src);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-06 03:08:14 +01:00
|
|
|
const struct cw_Type cw_type_dword = {
|
2018-03-07 10:30:40 +01:00
|
|
|
"Dword", /* name */
|
2018-03-11 00:56:41 +01:00
|
|
|
NULL, /* del */
|
2018-03-07 10:30:40 +01:00
|
|
|
put, /* put */
|
|
|
|
get, /* get */
|
|
|
|
to_str, /* to_str */
|
2018-04-25 10:43:27 +02:00
|
|
|
from_str, /* from_str */
|
|
|
|
NULL, /* len */
|
|
|
|
NULL, /* data */
|
2018-05-14 23:30:48 +02:00
|
|
|
get_type_name, /* get_type_name */
|
|
|
|
cast
|
2018-03-06 03:08:14 +01:00
|
|
|
};
|
2018-03-03 08:15:19 +01:00
|
|
|
|