diff --git a/src/cw/Makefile b/src/cw/Makefile index 475d5621..f3a2643d 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -105,6 +105,7 @@ CWSRC=\ cw_strlist_get_str.c\ cw_type_bstr16.c\ cw_type_byte.c\ + cw_type_str.c\ cw_type_dword.c\ cw_type_ipaddress.c\ cw_type_word.c\ @@ -126,6 +127,7 @@ LWSRC=\ lw_put_80211_wtp_wlan_radio_configuration.c\ lw_put_ac_descriptor.c\ lw_put_bstr.c\ + lw_put_str.c\ lw_put_cisco_path_mtu.c\ lw_put_image_data.c\ lw_put_sockaddr.c\ diff --git a/src/cw/cw.h b/src/cw/cw.h index eb2566ec..74569c56 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -49,6 +49,12 @@ */ #define cw_put_data lw_put_data + +/** + * Put a 0-terminated string + */ +#define cw_put_str lw_put_str + /** * Put a bstr_t object * see #lw_put_bstr diff --git a/src/cw/cw_type_str.c b/src/cw/cw_type_str.c new file mode 100644 index 00000000..f4c9c2f7 --- /dev/null +++ b/src/cw/cw_type_str.c @@ -0,0 +1,85 @@ +/* + 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 . + +*/ + +#include + +#include "format.h" +#include "cw.h" +#include "ktv.h" + + +static void del ( struct cw_KTV * data ) +{ + free ( data->val.str ); +} + +static struct cw_KTV *get ( struct cw_KTV * data, const uint8_t * src, int len ) +{ + uint8_t * s; + s = malloc (len+1); + if ( !s ) + return NULL; + + memcpy(s,src,len); + s[len]=0; + + data->type = &cw_type_str; + data->val.str = s; + return data; +} + +static int put ( const struct cw_KTV *data, uint8_t * dst ) +{ + return cw_put_str ( dst, data->val.str ); +} + +static int to_str ( const struct cw_KTV *data, char *dst, int max_len ) +{ + int l; + + strncpy(dst,data->val.str,max_len-1); + dst[max_len]=0; + return strlen(data->val.str)+1; +} + +static struct cw_KTV *from_str ( struct cw_KTV * data, const char *src ) +{ + uint8_t * s; + s = cw_strdup(src); + + if ( !s ) + return NULL; + + data->type = &cw_type_str; + data->val.str = s; + return data; +} + +static int len ( struct cw_KTV * data ){ + return strlen (data->val.str); +} + +const struct cw_Type cw_type_str = { + "Str", /* name */ + del, /* del */ + put, /* put */ + get, /* get */ + to_str, /* to_str */ + from_str, /* from_str */ + len /* len */ +}; diff --git a/src/cw/ktv.h b/src/cw/ktv.h index 927eae53..e7ca3576 100644 --- a/src/cw/ktv.h +++ b/src/cw/ktv.h @@ -36,6 +36,7 @@ struct cw_KTV { uint16_t word; uint8_t byte; void *ptr; + char *str; int boolean; } val; }; @@ -95,6 +96,7 @@ extern const struct cw_Type cw_type_byte; 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_str; extern const struct cw_Type cw_type_ipaddress; extern const struct cw_Type cw_type_sysptr; @@ -104,6 +106,7 @@ extern const struct cw_Type cw_type_sysptr; #define CW_TYPE_BSTR16 (&cw_type_bstr16) #define CW_TYPE_IPADDRESS (&cw_type_ipaddress) #define CW_TYPE_SYSPTR (&cw_type_sysptr) +#define CW_TYPE_STR (&cw_type_str) /* void cw_kvstore_mavl_delete(const void *data); diff --git a/src/cw/lw_inline.c b/src/cw/lw_inline.c index 9c749406..52ddd07b 100644 --- a/src/cw/lw_inline.c +++ b/src/cw/lw_inline.c @@ -27,16 +27,6 @@ int lw_put_bstr16(uint8_t * dst, const bstr16_t b){ } -/** - * Put a string to an output buffer - * @param dst Output buffer - * @param str zero-terminated string to put - * @return number of bytes put - */ -int lw_put_str(uint8_t*dst,const uint8_t *str) { - return lw_put_data(dst,str,strlen((char*)str)); -} - int lw_put_elem_hdr(uint8_t *dst,uint8_t type,uint16_t len) { diff --git a/src/mod/capwap/mod_capwap_ac.c b/src/mod/capwap/mod_capwap_ac.c index 8ebcf113..8f165fbc 100644 --- a/src/mod/capwap/mod_capwap_ac.c +++ b/src/mod/capwap/mod_capwap_ac.c @@ -12,10 +12,6 @@ static int init(struct cw_Mod * mod, mavl_t global_cfg, int role) { cw_dbg(DBG_INFO,"CAPWAP: Inititalizing mod_capwap."); - - - - switch (role){ case CW_ROLE_AC:{ cw_dbg(DBG_MOD, "CAPWAP: Initialiazing mod_capwap in AC mode"); @@ -52,7 +48,6 @@ int static setup_cfg(struct conn * conn) return 0; - }