2015-03-14 21:41:50 +01: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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Definitions for bstr functions
|
|
|
|
*/
|
|
|
|
|
2015-03-14 10:15:12 +01:00
|
|
|
#ifndef __BSTR_H
|
|
|
|
#define __BSTR_H
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
#include <string.h>
|
2015-01-31 10:17:34 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
* bstr typeS
|
|
|
|
*
|
|
|
|
* bstr_t serves as binary string where the first byte cponntains
|
|
|
|
* the length of the string.
|
|
|
|
*/
|
2015-03-14 10:15:12 +01:00
|
|
|
typedef uint8_t* bstr_t;
|
2015-01-31 10:17:34 +01:00
|
|
|
|
|
|
|
extern uint8_t * bstr_create(uint8_t *data, uint8_t len);
|
2015-01-31 12:29:27 +01:00
|
|
|
extern uint8_t * bstr_create_from_cfgstr(const char * s);
|
2015-03-15 20:53:21 +01:00
|
|
|
extern uint8_t * bstr_replace( bstr_t * dst, uint8_t * bstr);
|
2015-01-31 12:29:27 +01:00
|
|
|
|
2015-03-14 21:41:50 +01:00
|
|
|
extern int bstr_to_str(char *dst, bstr_t str,char * def);
|
|
|
|
|
2015-01-31 10:17:34 +01:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
* Return the length of a bstr_t string.
|
|
|
|
*/
|
2015-01-31 16:35:07 +01:00
|
|
|
#define bstr_len(s) (*(s))
|
2015-03-15 20:53:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the data of a bstr_t string.
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
#define bstr_data(s) ((s)+1)
|
2015-03-15 20:53:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the actual size in memory a bstr_t string needs.
|
|
|
|
*/
|
2015-03-14 21:41:50 +01:00
|
|
|
#define bstr_size(len) (len+1)
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
* Max. length of a bstr_t string.
|
|
|
|
*/
|
2015-03-14 21:41:50 +01:00
|
|
|
#define BSTR_MAX_LEN 254
|
2015-03-14 10:15:12 +01:00
|
|
|
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
typedef uint8_t *bstr16_t;
|
|
|
|
#define bstr16_len(s) ( *((uint16_t*)(s)) )
|
|
|
|
#define bstr16_data(s) ((s)+2)
|
|
|
|
#define bstr16_size(l) (l+2)
|
|
|
|
#define BSTR16_MAX_LEN (0xffff-2)
|
|
|
|
|
|
|
|
static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len)
|
|
|
|
{
|
|
|
|
*((uint16_t*)dst)=len;
|
|
|
|
memcpy(dst+2,src,len);
|
|
|
|
return len+2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-14 10:15:12 +01:00
|
|
|
#endif
|
|
|
|
|