cw_select_ac function is done
FossilOrigin-Name: 664aa92562692cc3d73e2540649b3896fac26401247a2a9d0059aa874c2ef914
This commit is contained in:
@ -105,6 +105,7 @@ CWSRC=\
|
||||
cw_type_dword.c\
|
||||
cw_type_ipaddress.c\
|
||||
cw_type_word.c\
|
||||
cw_type_sysptr.c\
|
||||
cw_util.c\
|
||||
cw_write_descriptor_subelem.c\
|
||||
cw_read_from.c \
|
||||
|
@ -1,5 +1,11 @@
|
||||
#include "ktv.h"
|
||||
|
||||
/**
|
||||
* @brief Default function to compare two values of type #cw_KTV_t.
|
||||
*
|
||||
* @param v1
|
||||
* @param v2
|
||||
* @return
|
||||
*/
|
||||
int cw_ktv_mavlcmp(const void *v1, const void *v2)
|
||||
{
|
||||
char *d1,*d2;
|
||||
|
@ -7,12 +7,14 @@ struct parser {
|
||||
int pos;
|
||||
int prevpos;
|
||||
char error[256];
|
||||
int quote;
|
||||
FILE *f;
|
||||
};
|
||||
|
||||
static int get_char(FILE * f, struct parser *p)
|
||||
static int get_char(struct parser *p)
|
||||
{
|
||||
int c;
|
||||
c = fgetc (f);
|
||||
c = fgetc (p->f);
|
||||
p->pos++;
|
||||
if (c=='\n'){
|
||||
p->prevpos=p->pos;
|
||||
@ -22,8 +24,9 @@ static int get_char(FILE * f, struct parser *p)
|
||||
return c;
|
||||
}
|
||||
|
||||
static void unget_char(int c, FILE *f, struct parser *p){
|
||||
ungetc(c,f);
|
||||
|
||||
static void unget_char(struct parser *p,int c){
|
||||
ungetc(c,p->f);
|
||||
if (c=='\n'){
|
||||
p->line--;
|
||||
p->pos=p->prevpos;
|
||||
@ -32,11 +35,71 @@ static void unget_char(int c, FILE *f, struct parser *p){
|
||||
p->pos--;
|
||||
}
|
||||
|
||||
static int skip_chars (FILE *f, const char * chars, struct parser * p )
|
||||
|
||||
|
||||
static int get_char_q(struct parser *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 parser *p, const char * chars)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ( (c = get_char (f, p)) != EOF) {
|
||||
while ( (c = get_char (p)) != EOF) {
|
||||
if (strchr (chars, c))
|
||||
continue;
|
||||
return c;
|
||||
@ -44,11 +107,11 @@ static int skip_chars (FILE *f, const char * chars, struct parser * p )
|
||||
return c;
|
||||
}
|
||||
|
||||
static int skip_to_chars (FILE *f, const char *chars, struct parser * p)
|
||||
static int skip_to_chars (struct parser *p, const char *chars)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ( (c = get_char (f, p)) != EOF) {
|
||||
while ( (c = get_char (p)) != EOF) {
|
||||
if (strchr (chars, c))
|
||||
return c;
|
||||
}
|
||||
@ -57,30 +120,32 @@ static int skip_to_chars (FILE *f, const char *chars, struct parser * p)
|
||||
|
||||
|
||||
|
||||
static int read_key (FILE *f, char *key, int max_len, struct parser * p)
|
||||
static int read_key (struct parser *p, char *key, int max_len)
|
||||
{
|
||||
int c,n;
|
||||
|
||||
do {
|
||||
c = skip_chars (f, " \t\n\a\v", p);
|
||||
c = skip_chars (p, " \t\n\a\v");
|
||||
if (c == '#') {
|
||||
c = skip_to_chars (f, "\n\a",p);
|
||||
c = skip_to_chars (p, "\n\a");
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (c != EOF);
|
||||
|
||||
|
||||
unget_char(p,c);
|
||||
c=get_char_q(p);
|
||||
|
||||
n=0;
|
||||
while(c!=EOF && n<max_len){
|
||||
if (!isalnum(c) && !strchr("._/-()@#|{}[]",c)/*strchr(": \t\n\a",c)*/){
|
||||
unget_char(c,f,p);
|
||||
if (!p->quote && !isalnum(c) && !strchr("._/-()@#|{}[]\\",c)/*strchr(": \t\n\a",c)*/){
|
||||
unget_char(p,c);
|
||||
break;
|
||||
}
|
||||
|
||||
key[n]=c;
|
||||
c=get_char(f,p);
|
||||
c=get_char_q(p);
|
||||
n++;
|
||||
|
||||
}
|
||||
@ -92,10 +157,10 @@ static int read_key (FILE *f, char *key, int max_len, struct parser * p)
|
||||
static int skip_to_colon(FILE *f,struct parser * p)
|
||||
{
|
||||
int c;
|
||||
c = skip_chars (f, " \t", p);
|
||||
c = skip_chars (p, " \t");
|
||||
if (c!=':'){
|
||||
if (c=='\n'){
|
||||
unget_char(c,f,p);
|
||||
unget_char(p,c);
|
||||
sprintf(p->error,"Error at line %d, pos %d: Unexpected EOL, collon expected.", p->line, p->pos);
|
||||
return 0;
|
||||
}
|
||||
@ -106,24 +171,24 @@ static int skip_to_colon(FILE *f,struct parser * p)
|
||||
}
|
||||
|
||||
|
||||
static int read_type(FILE *f, char *type, int max_len, struct parser *p)
|
||||
static int read_type(struct parser *p, char *type, int max_len)
|
||||
{
|
||||
int c,n;
|
||||
|
||||
if (!skip_to_colon(f,p))
|
||||
if (!skip_to_colon(p->f,p))
|
||||
return -1;
|
||||
|
||||
c = skip_chars (f, " \t", p);
|
||||
c = skip_chars (p, " \t");
|
||||
|
||||
if (c==':'){
|
||||
unget_char(c,f,p);
|
||||
unget_char(p,c);
|
||||
sprintf(type,"%s","");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!isalpha(c)){
|
||||
if (c=='\n'){
|
||||
unget_char(c,f,p);
|
||||
unget_char(p,c);
|
||||
sprintf(p->error,"Error at line %d, pos %d: Unexpected EOL.", p->line, p->pos);
|
||||
return -1;
|
||||
}
|
||||
@ -135,26 +200,27 @@ static int read_type(FILE *f, char *type, int max_len, struct parser *p)
|
||||
n=0;
|
||||
while(c!=EOF && n<max_len){
|
||||
if (!isalnum(c) && !strchr("_/-.()@#|{}[]",c)/*strchr(": \t\n\a",c)*/){
|
||||
unget_char(c,f,p);
|
||||
unget_char(p,c);
|
||||
break;
|
||||
}
|
||||
|
||||
type[n]=c;
|
||||
c=get_char(f,p);
|
||||
c=get_char(p);
|
||||
n++;
|
||||
}
|
||||
type[n]=0;
|
||||
return n;
|
||||
}
|
||||
|
||||
static int read_val(FILE *f, char *val, int max_len, struct parser *p){
|
||||
|
||||
static int read_val(struct parser *p, char *val, int max_len){
|
||||
int c,n,quote;
|
||||
if (!skip_to_colon(f,p))
|
||||
if (!skip_to_colon(p->f,p))
|
||||
return -1;
|
||||
c = skip_chars (f, " \t", p);
|
||||
c = skip_chars (p, " \t");
|
||||
if (c=='"'){
|
||||
quote=1;
|
||||
c=get_char(f,p);
|
||||
c=get_char(p);
|
||||
}
|
||||
else{
|
||||
quote=0;
|
||||
@ -169,7 +235,7 @@ static int read_val(FILE *f, char *val, int max_len, struct parser *p){
|
||||
}
|
||||
if (quote){
|
||||
if (c=='\\'){
|
||||
c = get_char(f,p);
|
||||
c = get_char(p);
|
||||
switch(c){
|
||||
case 'n':
|
||||
c='\n';
|
||||
@ -179,13 +245,13 @@ static int read_val(FILE *f, char *val, int max_len, struct parser *p){
|
||||
case '"':
|
||||
break;
|
||||
default:
|
||||
unget_char(c,f,p);
|
||||
unget_char(p,c);
|
||||
c='\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
val[n++]=c;
|
||||
c=get_char(f,p);
|
||||
c=get_char(p);
|
||||
}
|
||||
|
||||
|
||||
@ -214,14 +280,16 @@ int cw_ktv_read_line (FILE *f, char * key, char * type, char *val)
|
||||
p.line=1;
|
||||
p.pos=0;
|
||||
p.prevpos=0;
|
||||
p.quote=0;
|
||||
p.f=f;
|
||||
|
||||
n = read_key (f,key,CW_KTV_MAX_KEY_LEN,&p);
|
||||
n = read_type (f,type,CW_KTV_MAX_KEY_LEN,&p);
|
||||
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 (f,val,CW_KTV_MAX_KEY_LEN,&p);
|
||||
n = read_val (&p,val,CW_KTV_MAX_KEY_LEN);
|
||||
if (n==-1){
|
||||
return -1;
|
||||
}
|
||||
|
@ -6,5 +6,6 @@ const cw_Type_t * cw_ktv_std_types[] = {
|
||||
CW_TYPE_DWORD,
|
||||
CW_TYPE_BSTR16,
|
||||
CW_TYPE_IPADDRESS,
|
||||
CW_TYPE_SYSPTR,
|
||||
NULL
|
||||
};
|
||||
|
75
src/cw/cw_type_sysptr.c
Normal file
75
src/cw/cw_type_sysptr.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 "format.h"
|
||||
#include "cw.h"
|
||||
#include "ktv.h"
|
||||
|
||||
|
||||
static void del ( struct cw_KTV * data )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static struct cw_KTV *get ( struct cw_KTV * data, const uint8_t * src, int len )
|
||||
{
|
||||
data->type = &cw_type_sysptr;
|
||||
data->val.ptr = ((void**)(src))[0];
|
||||
return data;
|
||||
}
|
||||
|
||||
static int put ( const struct cw_KTV *data, uint8_t * dst )
|
||||
{
|
||||
((void**)dst)[0] = data->val.ptr ;
|
||||
return sizeof(void*);
|
||||
}
|
||||
|
||||
static int to_str ( const struct cw_KTV *data, char *dst, int max_len )
|
||||
{
|
||||
return sprintf(dst,"%p",data->val.ptr);
|
||||
}
|
||||
|
||||
static struct cw_KTV *from_str ( struct cw_KTV * data, const char *src )
|
||||
{
|
||||
uint8_t * s;
|
||||
s = bstr16_create_from_str(src);
|
||||
|
||||
if ( !s )
|
||||
return NULL;
|
||||
|
||||
data->type = &cw_type_bstr16;
|
||||
data->val.ptr = s;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
static int len ( struct cw_KTV * data ){
|
||||
return sizeof(void*);
|
||||
}
|
||||
|
||||
const struct cw_Type cw_type_sysptr = {
|
||||
"Sysptr", /* name */
|
||||
del, /* del */
|
||||
put, /* put */
|
||||
get, /* get */
|
||||
to_str, /* to_str */
|
||||
from_str, /* from_str */
|
||||
len /* len */
|
||||
};
|
@ -96,12 +96,14 @@ extern const struct cw_Type cw_type_word;
|
||||
extern const struct cw_Type cw_type_dword;
|
||||
extern const struct cw_Type cw_type_bstr16;
|
||||
extern const struct cw_Type cw_type_ipaddress;
|
||||
extern const struct cw_Type cw_type_sysptr;
|
||||
|
||||
#define CW_TYPE_BYTE (&cw_type_byte)
|
||||
#define CW_TYPE_WORD (&cw_type_word)
|
||||
#define CW_TYPE_DWORD (&cw_type_dword)
|
||||
#define CW_TYPE_BSTR16 (&cw_type_bstr16)
|
||||
#define CW_TYPE_IPADDRESS (&cw_type_ipaddress)
|
||||
#define CW_TYPE_SYSPTR (&cw_type_sysptr)
|
||||
|
||||
/*
|
||||
void cw_kvstore_mavl_delete(const void *data);
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @file mavl.h
|
||||
* @brief MAVL, Mini AVL Tree,
|
||||
* Yet another AVL Tree implementation
|
||||
*/
|
||||
|
Reference in New Issue
Block a user