Almost all ktv stuff deleted

shell
7u83 6 months ago
parent 14354039e1
commit 6dc8d80102
  1. 7
      src/ac/ac_main.c
  2. 8
      src/ac/conf.c
  3. 45
      src/ac/shell.c
  4. 6
      src/ac/wtpman.c
  5. 47
      src/cw/Makefile
  6. 43
      src/cw/cfg.c
  7. 4
      src/cw/cfg.h
  8. 1
      src/cw/conn.c
  9. 5
      src/cw/cw_in_generic_with_index.c
  10. 43
      src/cw/cw_ktv_add.c
  11. 45
      src/cw/cw_ktv_add_from_str.c
  12. 29
      src/cw/cw_ktv_base_exists.c
  13. 14
      src/cw/cw_ktv_cast.c
  14. 32
      src/cw/cw_ktv_get.c
  15. 11
      src/cw/cw_ktv_get_bool.c
  16. 13
      src/cw/cw_ktv_get_bstr16.c
  17. 11
      src/cw/cw_ktv_get_byte.c
  18. 11
      src/cw/cw_ktv_get_dword.c
  19. 11
      src/cw/cw_ktv_get_str.c
  20. 11
      src/cw/cw_ktv_get_sysptr.c
  21. 11
      src/cw/cw_ktv_get_word.c
  22. 126
      src/cw/cw_ktv_idx_get.c
  23. 67
      src/cw/cw_ktv_mavlcmp.c
  24. 8
      src/cw/cw_ktv_mavlcmp_type_by_name.c
  25. 14
      src/cw/cw_ktv_mavldel.c
  26. 359
      src/cw/cw_ktv_parser.c
  27. 40
      src/cw/cw_ktv_read_file.c
  28. 62
      src/cw/cw_ktv_read_struct.c
  29. 306
      src/cw/cw_ktv_readline.c
  30. 32
      src/cw/cw_ktv_replace.c
  31. 58
      src/cw/cw_ktv_save.c
  32. 6
      src/cw/cw_ktv_set_byte.c
  33. 6
      src/cw/cw_ktv_set_dword.c
  34. 6
      src/cw/cw_ktv_set_word.c
  35. 13
      src/cw/cw_ktv_std_types.c
  36. 77
      src/cw/cw_ktv_write_struct.c
  37. 32
      src/cw/cw_out_generic_with_index.c
  38. 3
      src/cw/cw_setup_dtls.c
  39. 2
      src/cw/message.c
  40. 36
      src/cw/msgset.c
  41. 6
      src/mod/capwap/capwap_actions.c
  42. 3
      src/mod/capwap/mod_capwap_ac.c
  43. 23
      src/mod/cisco/capwap_cisco.h
  44. 365
      src/mod/cisco/cisco_actions.c
  45. 4
      src/mod/cisco/lwapp_cisco.h
  46. 185
      src/wtp/cisco.ckv
  47. 18
      src/wtp/configure.c
  48. 7
      src/wtp/join.c
  49. 225
      src/wtp/run.c
  50. 12
      src/wtp/wtp.h
  51. 19
      src/wtp/wtp_main.c

@ -282,6 +282,7 @@ int ac_run(cw_Cfg_t * cfg)
{
struct cw_Cfg_iter cfi;
const char *s;
struct cw_Cfg_entry *e;
int i;
@ -292,11 +293,12 @@ int ac_run(cw_Cfg_t * cfg)
* good unicast reply socket */
cw_cfg_iter_init(cfg, &cfi, "actube/listen");
for (i=0; (s = cw_cfg_iter_next(&cfi, NULL)) != NULL; i++) {
for (i=0; (e = cw_cfg_iter_next(&cfi, NULL)) != NULL; i++) {
char addr[100];
char port[50];
int proto;
s=e->val;
conf_parse_listen_addr (s, addr, port, &proto);
socklist_add_unicast (addr, port, proto,
@ -337,11 +339,12 @@ int ac_run(cw_Cfg_t * cfg)
//mavl_print(cfg,pcb,180);
cw_cfg_iter_init(cfg, &cfi, "actube/bcast");
for (i=0; (s = cw_cfg_iter_next(&cfi, NULL)) != NULL; i++) {
for (i=0; (e = cw_cfg_iter_next(&cfi, NULL)) != NULL; i++) {
// for (i = 0; i < conf_bcast_addrs_len; i++) {
char addr[50], port[50];
int proto;
s=e->val;
conf_parse_listen_addr (s, addr, port, &proto);
socklist_add_broadcast (addr, port, proto);

@ -498,6 +498,7 @@ char *conf_mods_dir = NULL;
static int init_mods(cw_Cfg_t *cfg){
int n, i;
struct cw_Cfg_entry *e;
const char * modname;
struct cw_Cfg_iter cfi;
@ -511,11 +512,8 @@ static int init_mods(cw_Cfg_t *cfg){
// cw_mod_set_path(conf_mods_dir);
cw_cfg_iter_init(cfg, &cfi, "actube/mod");
printf("iter mods\n");
for (i=0; (modname = cw_cfg_iter_next(&cfi, NULL)) != NULL; i++) {
printf("init mod name: %s\n",modname);
for (i=0; (e = cw_cfg_iter_next(&cfi, NULL)) != NULL; i++) {
modname = e->val;
struct cw_Mod * mod = cw_mod_load(modname, cfg, CW_ROLE_AC);
if (!mod)

@ -33,7 +33,7 @@ void set_cmd(struct shelldata *sd, const char * cmd);
void del_cmd(struct shelldata *sd, const char * cmd);
void send_cmd(struct shelldata *sd, const char * cmd);
void wlan0_cmd(struct shelldata *sd, const char * cmd);
void show_cfg (FILE *out, mavl_t ktv);
//void show_cfg (FILE *out, mavl_t ktv);
void show_aps (FILE *out);
struct cw_Conn * find_ap(const char *name);
@ -79,7 +79,8 @@ void cfg_cmd(struct shelldata *sd, const char *cmd)
fprintf(sd->out,"WTP '%s' not found\n",sd->prompt);
}
else {
show_cfg(sd->out,conn->remote_cfg);
stop();
// show_cfg(sd->out,conn->remote_cfg);
}
wtplist_unlock();
}
@ -87,7 +88,8 @@ void cfg_cmd(struct shelldata *sd, const char *cmd)
void ucfg_cmd(struct shelldata *sd, const char *cmd)
{
struct cw_Conn * conn;
show_cfg(sd->out,sd->update_cfg);
stop();
// show_cfg(sd->out,sd->update_cfg);
}
@ -157,7 +159,7 @@ void del_cmd(struct shelldata *sd, const char *str)
}
/*
void show_cfg (FILE *out, mavl_t ktv)
{
char value[500];
@ -179,10 +181,12 @@ void show_cfg (FILE *out, mavl_t ktv)
}
*/
void show_aps (FILE *out)
{
struct connlist * cl;
stop();
/* struct connlist * cl;
mavliter_t it;
wtplist_lock();
@ -199,8 +203,9 @@ void show_aps (FILE *out)
conn = mavliter_get_ptr (&it);
sock_addr2str_p (&conn->addr, addr);
result = cw_ktv_get (conn->remote_cfg, "wtp-name", NULL);
stop();
// result = cw_ktv_get (conn->remote_cfg, "wtp-name", NULL);
if (result == NULL) {
strcpy (wtp_name, "");
@ -213,16 +218,18 @@ void show_aps (FILE *out)
fprintf (out, "%s\t\t%s\n", addr, wtp_name);
}
wtplist_unlock();
*/
}
struct cw_Conn * find_ap(const char *name)
{
stop();
/*
struct connlist * cl;
mavliter_t it;
/*wtplist_lock();*/
cl = wtplist_get_connlist();
@ -250,12 +257,16 @@ struct cw_Conn * find_ap(const char *name)
}
return NULL;
*/
/*wtplist_unlock();*/
}
void con (FILE *out)
{
stop();
/*
struct connlist * cl;
mavliter_t it;
@ -290,10 +301,12 @@ void con (FILE *out)
fprintf (out, "Con!! %s\t\t%s\n", addr, wtp_name);
{
stop();
mavl_t update;
update = cw_ktv_create();
cw_ktv_set_byte(update,"radio.255/admin-state",1);
conn->update_cfg=update;
// update = cw_ktv_create();
// cw_ktv_set_byte(update,"radio.255/admin-state",1);
// conn->update_cfg=update;
}
@ -301,6 +314,7 @@ void con (FILE *out)
}
wtplist_unlock();
*/
}
@ -355,8 +369,10 @@ void execute_cmd (struct shelldata * sd, const char *str)
key[0]=0;
type[0]=0;
val[0]=0;
cw_ktv_init_str_reader(&reader,str, strlen(str));
n = cw_ktv_parse_string(&reader, key,type,val);
stop();
// cw_ktv_init_str_reader(&reader,str, strlen(str));
// n = cw_ktv_parse_string(&reader, key,type,val);
if (n==-1){
int i;
@ -403,7 +419,8 @@ void shell_loop (FILE *file)
*/
char str[2048];
sd.update_cfg = cw_ktv_create();
stop();
// sd.update_cfg = cw_ktv_create();

@ -631,7 +631,7 @@ static int join_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, in
copy(params);
const char * wtpname = cw_cfg_get(conn->local_cfg,"wtp-name","default");
sprintf(filename,"wtp-join-%s.ckv",wtpname);
cw_cfg_save(filename,params->cfg);
cw_cfg_save(filename,params->cfg,NULL);
cw_cfg_clear(params->cfg);
return 0;
}
@ -648,8 +648,8 @@ static int update_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr,
const char * wtpname = cw_cfg_get(conn->local_cfg,"wtp-name","default");
sprintf(filename,"wtp-status-%s.ckv",wtpname);
cw_cfg_save(filename,params->cfg);
cw_cfg_save(filename,params->cfg,NULL);
stop();
return 0;
}

@ -79,36 +79,43 @@ CWSRC=\
# cw_process_element.c\
KTVSRC=\
cw_ktv_add.c\
cw_ktv_cast.c\
cw_ktv_replace.c\
cfg.c\
# cw_ktv_add.c\
cw_ktv_idx_get.c\
cw_ktv_mavlcmp.c\
cw_ktv_mavlcmp_type_by_name.c\
cw_ktv_mavldel.c\
# cw_ktv_parser.c\
# cw_ktv_del_sub.c\
# cw_ktv_base_exists.c\
cw_ktv_add_from_str.c\
cw_ktv_get_byte.c\
cw_ktv_read_file.c\
cw_ktv_readline.c\
cw_ktv_save.c\
cw_ktv_std_types.c\
cw_ktv_read_struct.c\
cw_ktv_write_struct.c\
# cw_ktv_get_byte.c\
cw_ktv_get_bool.c\
cw_ktv_get_bstr16.c\
cw_ktv_set_byte.c\
cw_ktv_set_word.c\
cw_ktv_set_dword.c\
cw_ktv_get.c\
cw_ktv_get_word.c\
# cw_ktv_get_word.c\
cw_ktv_get_dword.c\
cw_ktv_get_sysptr.c\
cw_ktv_get_str.c\
cw_ktv_idx_get.c\
cw_ktv_mavlcmp.c\
cw_ktv_mavlcmp_type_by_name.c\
cw_ktv_mavldel.c\
cw_ktv_read_file.c\
cw_ktv_readline.c\
cw_ktv_read_struct.c\
cw_ktv_write_struct.c\
cw_ktv_std_types.c\
cw_ktv_save.c\
cfg.c\
# cw_ktv_parser.c\
# cw_ktv_del_sub.c\
# cw_ktv_base_exists.c\
# cw_ktv_cast.c\
cw_ktv_replace.c\
cw_ktv_get.c\
LWSRC=\
lw_addelem.c\

@ -495,12 +495,18 @@ int cw_cfg_write_to_file(FILE *f, cw_Cfg_t * cfg)
}
int cw_cfg_save(const char *filename, cw_Cfg_t *cfg)
int cw_cfg_save(const char *filename, cw_Cfg_t *cfg, const char *format, ...)
{
int rc;
FILE *f = fopen(filename, "wb");
if (!f)
return errno;
if (format !=NULL){
va_list args;
va_start(args,format);
vfprintf(f,format,args);
va_end(args);
}
rc = cw_cfg_write_to_file(f, cfg);
fclose(f);
@ -519,7 +525,7 @@ void cw_cfg_iter_init(cw_Cfg_t * cfg, struct cw_Cfg_iter *cfi, const char *base)
}
const char *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *key)
struct cw_Cfg_entry *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *nnkey)
{
struct cw_Cfg_entry *e;
int bl, kl;
@ -541,7 +547,7 @@ const char *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *key)
return NULL;
else {
mavliter_next(&(cfi->it));
return e->val;
return e;
}
}
@ -556,7 +562,7 @@ const char *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *key)
return NULL;
mavliter_next(&(cfi->it));
return e->val;
return e;
}
@ -686,22 +692,45 @@ void cw_cfg_copy(cw_Cfg_t *src, cw_Cfg_t *dst)
int exists;
struct cw_Cfg_entry * old_elem,*e, new_elem;
e = mavliter_get(&it);
new_elem.key = cw_strdup(e->key);
new_elem.val = cw_strdup(e->val);
/* if (1){
const char *ov;
ov = cw_cfg_get(dst,e->key,NULL);
cw_dbg(DBG_X, " REAL OV HERE: %s",ov);
}
*/
old_elem = mavl_insert(dst,&new_elem,&exists);
/* cw_dbg(DBG_X, "CPY: %s: %s -> %s [%d]",new_elem.key,new_elem.val,old_elem->val,exists);
if (exists){
const char *ov;
ov = cw_cfg_get(dst,e->key,NULL);
cw_dbg(DBG_X, " OV HERE: %s",ov);
}
*/
if (!exists){
cw_dbg(DBG_X, "New: %s: %s",new_elem.key,new_elem.val);
cw_dbg(DBG_CFG_SET, "New: %s: %s",new_elem.key,new_elem.val);
continue;
}
if (strcmp(new_elem.val,old_elem->val)==0){
free((void*)new_elem.key);
free((void*)new_elem.val);
continue;
}
cw_dbg(DBG_X, "Replace: %s: %s (old: %s)",new_elem.key, new_elem.val, old_elem->val);
cw_dbg(DBG_CFG_SET, "Replace: %s: %s (old: %s)",new_elem.key, new_elem.val, old_elem->val);
if(dst->del){
dst->del(old_elem);
}
@ -753,7 +782,7 @@ int cw_cfg_base_exists_l(cw_Cfg_t ** cfgs, const char *key)
if (cw_cfg_base_exists(cfgs[i],key))
return 1;
}
cw_dbg(DBG_X,"NOX EXISIS: %s in %d",key,i);
// cw_dbg(DBG_X,"NOX EXISIS: %s in %d",key,i);
return 0;
}

@ -28,7 +28,7 @@ struct cw_Cfg_iter{
const char * cw_cfg_get(cw_Cfg_t * cfg, const char *key, const char *def);
const char *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *key);
struct cw_Cfg_entry *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *key);
void cw_cfg_iter_init(cw_Cfg_t * cfg, struct cw_Cfg_iter *cfi, const char *base);
int cw_cfg_get_bool(cw_Cfg_t * cfg, const char * key, int def);
@ -46,7 +46,7 @@ int cw_cfg_base_exists(cw_Cfg_t * cfg, const char *key);
uint8_t cw_cfg_get_byte_l(cw_Cfg_t ** cfgs, char *key, uint8_t def);
cw_Val_t * cw_cfg_get_val_l(cw_Cfg_t ** cfgs, const char *key, const struct cw_Type *type);
int cw_cfg_base_exists_l(cw_Cfg_t ** cfgs, const char *key);
int cw_cfg_save(const char *filename, cw_Cfg_t *cfg);
int cw_cfg_save(const char *filename, cw_Cfg_t *cfg, const char *format, ...);

@ -59,7 +59,6 @@ void cw_conn_init(struct cw_Conn * conn)
conn->msg_callbacks = mavl_create(msg_callback_cmp,NULL,sizeof(struct msg_callback));
conn->update_cfg = cw_cfg_create();
cw_dbg(DBG_X,"Update CFG ist %p",conn->update_cfg);
conn->remote_cfg = cw_cfg_create();
conn->local_cfg = cw_cfg_create();
}

@ -7,12 +7,11 @@ int cw_in_generic_with_index(struct cw_ElemHandler *eh,
{
char key[CW_CFG_MAX_KEY_LEN];
int idx;
struct cw_Type * type = (struct cw_Type*)eh->type;
cw_dbg(DBG_X,"Fix cw_in_generic_with_index");
stop();
idx = cw_get_byte(data);
sprintf(key,"%s.%d",eh->key,idx);
// cw_cfg_add(params->cfg,key,eh->type,NULL,data+1,len-1);
type->read(params->cfg,key,data+1,len-1,eh->param);
return 1;
}

@ -1,43 +0,0 @@
#include "val.h"
#include "cw.h"
#include "log.h"
#include "dbg.h"
cw_Val_t * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *type,
const void * valguard,
const uint8_t * data, int len)
{
cw_Val_t mdata, *mresult;
int exists;
mdata.key=cw_strdup(key);
mdata.valguard=valguard;
if (!mdata.key){
cw_log(LOG_ERR, "Can't allocate memory for KTV key %s: %s",
key,strerror(errno));
return NULL;
}
mresult = type->get(&mdata,data,len);
if (!mresult){
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
key,type->name, strerror(errno));
free(mdata.key);
return NULL;
}
mavl_del(kvtstore,&mdata);
mresult = mavl_insert(kvtstore, &mdata, &exists);
if (exists){
cw_log(LOG_ERR, "Element already exists %s", key);
/* element already exists */
free(mdata.key);
if (type->del)
type->del(&mdata);
return mresult;
}
return mresult;
}

@ -1,45 +0,0 @@
#include "val.h"
#include "cw.h"
#include "log.h"
#include "dbg.h"
const char * cw_ktv_add_from_str(mavl_t kvtstore, const char *key,
const struct cw_Type *type,
const void * valguard,
const char * str)
{
cw_Val_t mdata, *mresult;
int exists;
/* cw_dbg(DBG_ELEM,"KVStore (%p,%d) add elem (%s): %s", kvstore, kvstore->count,
type->name, key );
*/
mdata.key=cw_strdup(key);
mdata.valguard=valguard;
if (!mdata.key){
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
key,strerror(errno));
return NULL;
}
mresult = type->from_str(&mdata,str);
if (!mresult){
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
key,type->name, strerror(errno));
free(mdata.key);
return NULL;
}
mresult = mavl_insert(kvtstore, &mdata, &exists);
if (exists){
cw_log(LOG_ERR, "Element already exists %s", key);
/* element already exists */
free(mdata.key);
if (type->del)
type->del(&mdata);
return key;
}
return mdata.key;
}

@ -1,29 +0,0 @@
#include "val.h"
/**
* @file
* @description Implementation of cw_ktv_base_exisits
*/
/**
* @brief Check if elements with e certain baskey can be found in
* in ktvstore.
* @param ktvstore ktvstore to search in
* @param basekey basekey to search for
* @return The first ktv element belonging to the base eky,
* otherwise NULL if no element was found.
*
*/
cw_Val_t * cw_ktv_base_exists(mavl_t ktvstore, const char *basekey)
{
cw_Val_t * result, search;
search.key=(char*)basekey;
result = mavl_get_first(ktvstore,&search);
if (result == NULL)
return NULL;
if (strncmp(result->key,basekey,strlen(basekey))==0)
return result;
return NULL;
}

@ -1,14 +0,0 @@
#include "val.h"
cw_Val_t * cw_ktv_cast(cw_Val_t *v,const cw_Type_t * type)
{
if (strcmp(v->type->name,type->name)==0)
return v;
if (type->cast==NULL)
return NULL;
if (!type->cast(v))
return NULL;
return v;
}

@ -1,32 +0,0 @@
#include "val.h"
#include "mavl.h"
/**
* @brief Get a ktv value from a ktv store
* @param ktv ktv store
* @param key key to search for
* @param type type to match
* @return A pointer to a #cw_Val_t element, found in the ktv store or
* NULL if no element with matching key/type is found.
*/
cw_Val_t * cw_ktv_get(mavl_t ktv, const char *key, const cw_Type_t * type)
{
cw_Val_t search, *result;
/* we can safely cast from const char * to char *, because
* we never will use the search varaiable to store ktv values */
search.key=(char*)key;
result = mavl_get(ktv,&search);
if (result == NULL){
return NULL;
}
if (type == NULL){
return result;
}
if (strcmp(type->name,result->type->name)==0){
return result;
}
return NULL;
}

@ -1,11 +0,0 @@
#include "val.h"
uint8_t cw_ktv_get_bool(mavl_t ktv,const char *key, uint8_t def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_BOOL);
if (k != NULL){
return k->val.boolean;
}
return def;
}

@ -1,13 +0,0 @@
#include "val.h"
#include "bstr.h"
bstr16_t cw_ktv_get_bstr16(mavl_t ktv,const char *key, bstr16_t def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_BSTR16);
if (k != NULL){
return bstr16_create(k->type->data(k),k->type->len(k));
}
return def;
}

@ -1,11 +0,0 @@
#include "val.h"
uint8_t cw_ktv_get_byte(mavl_t ktv,const char *key, uint8_t def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_BYTE);
if (k != NULL){
return k->val.byte;
}
return def;
}

@ -1,11 +0,0 @@
#include "val.h"
uint32_t cw_ktv_get_dword(mavl_t ktv,const char *key, uint32_t def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_DWORD);
if (k != NULL){
return k->val.dword;
}
return def;
}

@ -1,11 +0,0 @@
#include "val.h"
char * cw_ktv_get_str(mavl_t ktv,const char *key, char * def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_STR);
if (k != NULL){
return k->val.ptr;
}
return def;
}

@ -1,11 +0,0 @@
#include "val.h"
void * cw_ktv_get_sysptr(mavl_t ktv,const char *key, void * def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_SYSPTR);
if (k != NULL){
return k->val.ptr;
}
return def;
}

@ -1,11 +0,0 @@
#include "val.h"
uint16_t cw_ktv_get_word(mavl_t ktv,const char *key, uint16_t def)
{
cw_Val_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_WORD);
if (k != NULL){
return k->val.word;
}
return def;
}

@ -1,126 +0,0 @@
#include "val.h"
#include "cfg.h"
void * ktvn(struct mavl *t ,const void *search)
{
struct mavlnode *n,/**lastl,*/*lastb;
lastb = NULL; /*lastl=NULL;*/
n = t->root;
while(n){
int rc;
/* const cw_Val_t;*//* *c1,*c2;*/
/*c1=search;
c2=mavlnode_dataptr(n);
*/
rc = t->cmp(search,mavlnode_dataptr(n));
/*printf("Compare: %s %s = %d\n",c1->key,c2->key, rc);*/
if (rc==0){
return NULL;
}
if (rc<0){
/*lastl = n;*/
if (n->s[0]==NULL){
return mavlnode_dataptr(lastb);
}
n=n->s[0];
}
else{
lastb=n;
if(n->s[1]==NULL){
return mavlnode_dataptr(lastb);
}
n=n->s[1];
}
}
return NULL;
}
int cw_ktv_idx_get(mavl_t ktv, const char *key)
{
char ikey[CW_CFG_MAX_KEY_LEN];
cw_Val_t search, * result;
char *d;
sprintf(ikey,"%s.%d",key,65536);
search.key=ikey;
/*//result = ktvn(ktv,&search);*/
result = mavl_get_last(ktv,&search);
if (result == NULL){
return -1;
}
d = strchr(result->key,'.');
if (d==NULL){
return -1;
}
if (strncmp(result->key,ikey,d-result->key)!=0)
return -1;
return atoi(d+1);
}
int cw_ktv_idx_get_next(mavl_t ktv, const char *key, int n)
{
char ikey[CW_CFG_MAX_KEY_LEN];
cw_Val_t search, * result;
char *d;
int i;
sprintf(ikey,"%s.%d",key,n);
search.key=ikey;
/*//result = ktvn(ktv,&search);*/
result = mavl_get_first(ktv,&search);
if (result == NULL){
return -1;
}
/*d = strchr(result->key,'.');*/
d=NULL;
/* for (i = strlen(result->key); i>=0; i--){
if (result->key[i]=='/')
break;
}
*/ for (i = strlen(ikey); i>=0; i--){
if (ikey[i]=='.'){
d = result->key+i;
break;
}
}
if (d==NULL){
return -1;
}
if(result->key[i]!='.'){
return -1;
}
/* if (strncmp(result->key,ikey,d-result->key)!=0)
return -1;
*/
if (strncmp(result->key,ikey,i)!=0)
return -1;
return atoi(result->key+i+1);
}

@ -1,67 +0,0 @@
#include <ctype.h>
#include "val.h"
/**
* @brief Default function to compare two values of type #cw_Val_t.
*
* @param v1
* @param v2
* @return
*/
int cw_ktv_mavlcmp (const void *v1, const void *v2)
{
char *d1, *d2, *k1, *k2;
int l1, l2, rc, i1, i2;
k1 = ( (cw_Val_t *) v1)->key;
k2 = ( (cw_Val_t *) v2)->key;
while (1) {
/* Find dots in both keys */
d1 = strchr (k1, '.');
d2 = strchr (k2, '.');
/* if there are no dots, compare keys as normal */
if (d1 == NULL || d2 == NULL)
return strcmp (k1, k2);
/* calculate the length of the key till dots */
l1 = d1 - k1; /*((cw_Val_t *) v1)->key;*/
l2 = d2 - k2; /*((cw_Val_t *) v2)->key;*/
/* if length differs do a normal compare */
if (l1 != l2) {
return strcmp (k1, k2); /*((cw_Val_t *) v1)->key, ((cw_Val_t *) v2)->key);*/
}
rc = strncmp (k1, k2, l1); /*((cw_Val_t *) v1)->key,((cw_Val_t *) v2)->key,l1);*/
if (rc != 0) {
return rc;
}
d1++;
d2++;
i1 = atoi (d1);
i2 = atoi (d2);
rc = i1 - i2;
if (rc != 0)
return rc;
while (isdigit (*d1))
d1++;
while (isdigit (*d2))
d2++;
k1=d1;
k2=d2;
/*return strcmp(d1,d2);*/
/*return cw_ktv_mavlcmp(d1,d2);*/
}
}

@ -1,8 +0,0 @@
#include "val.h"
int cw_ktv_mavlcmp_type_by_name (const void *v1, const void *v2)
{
return strcmp ( (*((struct cw_Type**) v1))->name,
(*((struct cw_Type**) v2))->name);
}

@ -1,14 +0,0 @@
#include <stdlib.h>
#include "val.h"
void cw_ktv_mavldel(void *data)
{
struct cw_Val *ktv = data;
if (ktv->type->del) {
ktv->type->del(data);
}
free(ktv->key);
}

@ -1,359 +0,0 @@
#include <stdint.h>
#include "val.h"
static int str_getc(struct cw_Val_Reader * r)
{
if (r->next==r->maxlen)
return EOF;
return *((uint8_t*)(r->data)+r->next++);
}
static void str_ungetc(struct cw_Val_Reader * r, int c)
{
if (r->next>0)
r->next--;
}
void cw_ktv_init_str_reader(struct cw_Val_Reader *r, const char * str, int len)
{
memset(r,0,sizeof(struct cw_Val_Reader));
r->data = str;
r->xgetchar=str_getc;
r->ungetchar=str_ungetc;
r->maxlen=len;
}
#include <ctype.h>
#include "val.h"
/*
struct parser {
int line;
int pos;
int prevpos;
char error[256];
int quote;
FILE *f;
int (*getc)(struct parser *);
void (*ungetc)(struct parser *)
};
*/
static int get_char(struct cw_Val_Reader *r)
{
int c;
c = r->xgetchar (r);
r->pos++;
if (c=='\n'){
r->prevpos=r->pos;
r->line ++;
r->pos=0;
}
return c;
}
static void unget_char(struct cw_Val_Reader * r,int c){
r->ungetchar(r,c);
if (c=='\n'){
r->line--;
r->pos=r->prevpos;
}
else
r->pos--;
}
static int get_char_q(struct cw_Val_Reader *p)
{
int c;
while(1) {
c = get_char(p);
if (c==EOF || c=='\n')
return c;
if(c=='"' && !p->quote){
p->quote=1;
continue;
}
if(c=='"' && p->quote){
p->quote=0;
continue;
}
break;
}
if (!p->quote)
return c;
if (c!='\\')
return c;
c = get_char(p);
switch(c){
case EOF:
return c;
case 'n':
return '\n';
case '\\':
return '\\';
case '"':
return '"';
default:
unget_char(p,c);
return '\\';
}
/* We will never reach here */
/* return c;*/
}
static int skip_chars (struct cw_Val_Reader *r, const char * chars)
{
int c;
while ( (c = get_char (r)) != EOF) {
if (strchr (chars, c))
continue;
return c;
}
return c;
}
static int skip_to_chars (struct cw_Val_Reader *r, const char *chars)
{
int c;
while ( (c = get_char (r)) != EOF) {
if (strchr (chars, c))
return c;
}
return c;
}
static int read_key (struct cw_Val_Reader *r, char *key, int max_len)
{
int c,n;
do {
c = skip_chars (r, " \t\n\a\v");
if (c == '#') {
c = skip_to_chars (r, "\n\a");
} else {
break;
}
} while (c != EOF);
unget_char(r,c);
c=get_char_q(r);
n=0;
while(c!=EOF && n<max_len){
if (!r->quote && !isalnum(c) && !strchr("._/-()@#|{}[]\\",c)){
unget_char(r,c);
break;
}
key[n]=c;
c=get_char_q(r);
n++;
}
key[n]=0;
return n;
}
static int skip_to_colon(struct cw_Val_Reader * r)
{
int c;
c = skip_chars (r, " \t");
if (c!=':' && c!='='){
if (c=='\n'){
unget_char(r,c);
sprintf(r->error,"Unexpected EOL, colon or equal sign expected.");
return -1;
}
sprintf(r->error,"Colon or equal sign expected.");
return -1;
}
return c;
}
static int read_type(struct cw_Val_Reader * r, char *type, int max_len)
{
int c,n;
c = skip_to_colon(r);
if (c==-1)
return -1;
if (c=='='){
unget_char(r,c);
return sprintf(type,"%s","Str");
}
c = skip_chars (r, " \t");
if (c==':'){
unget_char(r,c);
sprintf(type,"%s","Str");
return 0;
}
if (!isalpha(c)){
if (c=='\n'){
unget_char(r,c);
/*sprintf(p->error,"Error at line %d, pos %d: Unexpected EOL.", p->line, p->pos);*/
return -1;
}
/*sprintf(p->error,"Error at line %d, pos %d: Letter expected.", p->line, p->pos);*/
return -1;
}
n=0;
while(c!=EOF && n<max_len){
if (!isalnum(c) && !strchr("_/-.()@#|{}[]",c)/*strchr(": \t\n\a",c)*/){
unget_char(r,c);
break;
}
type[n]=c;
c=get_char(r);
n++;
}
type[n]=0;
return n;
}
static int read_val(struct cw_Val_Reader *r, char *val, int max_len){
int c,n,quote;
c = skip_to_colon(r);
if (c==-1)
return -1;
c = skip_chars (r, " \t");
if (c=='"'){
quote=1;
c=get_char(r);
}
else{
quote=0;
}
n=0;
while(c!=EOF && n<max_len){
if (quote && c=='"'){
break;
}
if (c=='\n'){
break;
}
if (quote){
if (c=='\\'){
c = get_char(r);
switch(c){
case 'n':
c='\n';
break;
case '\\':
break;
case '"':
break;
default:
unget_char(r,c);
c='\\';
}
}
}
val[n++]=c;
c=get_char(r);
}
if(!quote && n>0){
while(n>0){
if (isspace(val[n-1]))
n--;
else
break;
}
}
val[n]=0;
return n;
}
/*
int cw_ktv_parse_line (FILE *f, char * key, char * type, char *val)
{
int n;
struct parser p;
p.line=1;
p.pos=0;
p.prevpos=0;
p.quote=0;
p.f=f;
n = read_key (&p,key,CW_KTV_MAX_KEY_LEN);
n = read_type (&p,type,CW_KTV_MAX_KEY_LEN);
if (n==-1){
return -1;
}
n = read_val (&p,val,CW_KTV_MAX_KEY_LEN);
if (n==-1){
return -1;
}
return 0;
}
*/
int cw_ktv_parse_line(struct cw_Val_Reader * r)
{
}
int cw_ktv_parse_string(struct cw_Val_Reader *r, char *key, char *type, char *val)
{
int n;
n = read_key (r,key,CW_KTV_MAX_KEY_LEN);
n = read_type(r,type,200);
if (n==1)
return -1;
n = read_val(r,val,200);
return n;
}

@ -1,40 +0,0 @@
#include "val.h"
#include "cfg.h"
int cw_ktv_read_file(FILE * file, mavl_t ktv, mavl_t types)
{
char key[CW_CFG_MAX_KEY_LEN];
char type[256];
char val[2048];
int rc;
struct cw_Type typesearch, *cwtype;
do {
rc = cw_ktv_read_line(file,key,type,val);
if (rc != 0){
continue;
}