2015-03-31 08:07:41 +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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __CFGSTORE_H
|
|
|
|
#define __CFGSTORE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "avltree.h"
|
2015-03-31 19:26:25 +02:00
|
|
|
#include "bstr.h"
|
2015-03-31 08:07:41 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/**
|
|
|
|
* Item types supported in item store
|
|
|
|
*/
|
|
|
|
enum cw_cfgtem_types {
|
|
|
|
CW_ITEMTYPE_NONE = 0,
|
2015-03-31 08:07:41 +02:00
|
|
|
CW_ITEMTYPE_BYTE,
|
|
|
|
CW_ITEMTYPE_WORD,
|
|
|
|
CW_ITEMTYPE_DWORD,
|
|
|
|
CW_ITEMTYPE_DATA,
|
2015-04-05 02:07:59 +02:00
|
|
|
CW_ITEMTYPE_CONST_DATA,
|
|
|
|
CW_ITEMTYPE_STR,
|
|
|
|
CW_ITEMTYPE_BSTR,
|
2015-04-07 07:42:36 +02:00
|
|
|
CW_ITEMTYPE_BSTR16,
|
|
|
|
/** Vendor string contains a Vendor ID, followed by bstr16 data, containing
|
|
|
|
the string. */
|
|
|
|
CW_ITEMTYPE_VENDORSTR,
|
2015-04-05 02:07:59 +02:00
|
|
|
CW_ITEMTYPE_AVLTREE,
|
|
|
|
CW_ITEMTYPE_FUN,
|
|
|
|
|
2015-03-31 08:07:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cw_item {
|
|
|
|
uint32_t id;
|
|
|
|
uint8_t type;
|
|
|
|
union {
|
|
|
|
void *data;
|
|
|
|
uint8_t byte;
|
|
|
|
uint16_t word;
|
|
|
|
uint32_t dword;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
typedef struct avltree *cw_itemstore_t;
|
2015-03-31 08:07:41 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
static inline struct cw_item *cw_itemstore_get(cw_itemstore_t s, uint32_t id)
|
2015-03-31 08:07:41 +02:00
|
|
|
{
|
|
|
|
struct cw_item i;
|
2015-04-07 07:42:36 +02:00
|
|
|
i.id = id;
|
|
|
|
return avltree_get(s, &i);
|
2015-03-31 08:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern cw_itemstore_t cw_itemstore_create();
|
2015-04-07 07:42:36 +02:00
|
|
|
extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n);
|
|
|
|
extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str);
|
|
|
|
extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr);
|
|
|
|
extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
|
|
|
|
extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword);
|
|
|
|
extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word);
|
|
|
|
extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte);
|
|
|
|
extern int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id,
|
|
|
|
uint32_t vendor_id, uint8_t * vendorstr,
|
|
|
|
int len);
|
|
|
|
int cw_itemstore_set_avltree(cw_itemstore_t s, uint32_t id, struct avltree *t);
|
|
|
|
int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
|
|
|
|
|
|
|
|
|
|
|
|
extern int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t * data,
|
|
|
|
int len);
|
|
|
|
|
|
|
|
static inline char * cw_itemstore_get_str(cw_itemstore_t s,uint32_t id) {
|
|
|
|
struct cw_item *i = cw_itemstore_get(s,id);
|
|
|
|
if (!i)
|
|
|
|
return NULL;
|
|
|
|
return i->data;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct avltree * cw_itemstore_get_avltree(cw_itemstore_t s,uint32_t id){
|
|
|
|
struct cw_item *i = cw_itemstore_get(s,id);
|
|
|
|
if (!i)
|
|
|
|
return NULL;
|
|
|
|
if (i->type!=CW_ITEMTYPE_AVLTREE)
|
|
|
|
return NULL;
|
|
|
|
return i->data;
|
|
|
|
}
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
|
|
|
extern void *cw_item_get_data_ptr(struct cw_item *item);
|
|
|
|
extern void cw_item_release_data_ptr(struct cw_item *item, void *data);
|
|
|
|
|
|
|
|
|
|
|
|
int cw_itemstore_set_fun(cw_itemstore_t s, uint32_t id,
|
|
|
|
void *(*funget) (void *arg),
|
|
|
|
void (*funfree) (void *arg, void *data), void *arg);
|
2015-03-31 14:03:21 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len);
|
2015-03-31 08:07:41 +02:00
|
|
|
|
|
|
|
#endif
|