From 7d5a8eb24104b8da6e5002cc985b170766019f4c Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Mon, 4 May 2015 05:30:57 +0000 Subject: [PATCH] To read from config files. FossilOrigin-Name: 64f13dcc2f360af07ba4d443b4a58b7b291ec75bde478d8a5648e63ae0a54d37 --- src/capwap/bstr16_create_from_str.c | 31 +++++++++++++++++++++++++++++ src/capwap/bstr_create_from_str.c | 31 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/capwap/bstr16_create_from_str.c create mode 100644 src/capwap/bstr_create_from_str.c diff --git a/src/capwap/bstr16_create_from_str.c b/src/capwap/bstr16_create_from_str.c new file mode 100644 index 00000000..b594acc5 --- /dev/null +++ b/src/capwap/bstr16_create_from_str.c @@ -0,0 +1,31 @@ +#include "bstr.h" +#include "format.h" + + +uint8_t * bstr16_create_from_str(const char *s) +{ + int l = strlen(s); + if (s[0]!='.') + return bstr16_create((uint8_t*)s,l); + + if (l<=2) + return bstr16_create((uint8_t*)s,l); + + if (s[1]=='.') + return bstr16_create((uint8_t*)s+1,l-1); + + if (s[1]!='x') + return bstr16_create((uint8_t*)s,l); + + /* the string starts with ".x" - read hexbytes */ + l-=2; + int msize=l/2; + if(l&1) + msize++; + uint8_t * mem = malloc(2+msize); + *((uint16_t*)mem)=msize; + cw_format_scan_hex_bytes(mem+2,s+2,l); + return mem; +} + + diff --git a/src/capwap/bstr_create_from_str.c b/src/capwap/bstr_create_from_str.c new file mode 100644 index 00000000..6fde0e25 --- /dev/null +++ b/src/capwap/bstr_create_from_str.c @@ -0,0 +1,31 @@ +#include "bstr.h" +#include "format.h" + + +uint8_t * bstr_create_from_str(const char *s) +{ + int l = strlen(s); + if (s[0]!='.') + return bstr_create((uint8_t*)s,l); + + if (l<=2) + return bstr_create((uint8_t*)s,l); + + if (s[1]=='.') + return bstr_create((uint8_t*)s+1,l-1); + + if (s[1]!='x') + return bstr_create((uint8_t*)s,l); + + /* the string starts with ".x" - read hexbytes */ + l-=2; + int msize=l/2; + if(l&1) + msize++; + uint8_t * mem = malloc(1+msize); + *((uint8_t*)mem)=msize; + cw_format_scan_hex_bytes(mem+2,s+2,l); + return mem; +} + +