15 #define DISABLE_DEBUGLOG
19 #include <gwenhywfar/debug.h>
20 #include <gwenhywfar/inherit.h>
21 #include <gwenhywfar/misc.h>
22 #include <gwenhywfar/text.h>
28 #define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS 0b00011111
29 #define BER_TLV_TAG_SECOND_BYTE_BYTE_FOLLOWS 0b10000000
30 #define BER_TLV_TAG_IS_CONSTRUCTED 0b00100000
85 tlv->isBerTlv=isBerTlv;
89 tlv->tagData=malloc(dlen);
91 memmove(tlv->tagData, p, dlen);
101 return tlv->isBerTlv;
115 return tlv->tagLength;
136 unsigned int tagMode;
137 unsigned int tagType;
138 unsigned int tagLength;
153 tagMode=tagType=tagLength=0;
164 j=(
unsigned char)(p[pos]);
167 if ((j & 0x1f)==0x1f) {
173 j=(
unsigned char)(p[pos]);
179 isBerTlv?
" (BER-TLV)":
"");
188 j=(
unsigned char)(p[pos]);
197 j=(
unsigned char)(p[pos]);
205 j=((
unsigned char)(p[pos]))<<8;
207 j+=(
unsigned char)(p[pos]);
222 j=((
unsigned char)(p[pos]))<<8;
224 j+=(
unsigned char)(p[pos]);
240 tlv->isBerTlv=isBerTlv;
241 tlv->tagMode=tagMode;
242 tlv->tagType=tagType;
243 tlv->tagLength=tagLength;
245 tlv->tagData=(
void*)malloc(tagLength);
246 memmove(tlv->tagData, tagData, tagLength);
258 return (tlv->tagMode & 0x20);
265 return (tlv->tagMode & 0xc0);
283 unsigned int tagMode,
289 tagLength=strlen(tagData);
313 else if (tagLength>127) {
350 tagMode=tagType=tagLength=0;
359 j=(
unsigned char)(p[pos]);
362 if ((j & 0x1f)==0x1f) {
368 j=(
unsigned char)(p[pos]);
374 isBerTlv?
" (BER-TLV)":
"");
383 j=(
unsigned char)(p[pos]);
392 j=(
unsigned char)(p[pos]);
400 j=((
unsigned char)(p[pos]))<<8;
402 j+=(
unsigned char)(p[pos]);
410 j=((
unsigned char)(p[pos]))<<16;
412 j+=((
unsigned char)(p[pos]))<<8;
414 j+=(
unsigned char)(p[pos]);
422 j=((
unsigned char)(p[pos]))<<24;
424 j+=((
unsigned char)(p[pos]))<<16;
426 j+=((
unsigned char)(p[pos]))<<8;
428 j+=(
unsigned char)(p[pos]);
436 j=((uint64_t) ((
unsigned char)(p[pos])))<<32;
438 j+=((uint64_t) ((
unsigned char)(p[pos])))<<24;
440 j+=((uint64_t) ((
unsigned char)(p[pos])))<<16;
442 j+=((uint64_t) ((
unsigned char)(p[pos])))<<8;
444 j+=(
unsigned char)(p[pos]);
459 j=((
unsigned char)(p[pos]))<<8;
461 j+=(
unsigned char)(p[pos]);
469 tlv->isBerTlv=isBerTlv;
470 tlv->tagMode=tagMode;
471 tlv->tagType=tagType;
472 tlv->tagLength=tagLength;
474 tlv->tagSize=pos+tagLength;
481 unsigned int tagMode,
501 if (tagLength>0xffffffffLL) {
510 else if (tagLength>0xffffffL) {
518 else if (tagLength>0xffff) {
525 else if (tagLength>0xff) {
531 else if (tagLength>127) {
555 nibbles[0]=(byte>>4) &0x0f;
556 nibbles[1]=byte & 0x0f;
558 for ( i = 0 ; i < 2 ; i++ )
617 unsigned int tag_len=0;
618 unsigned int data_len;
627 while (tlv_len < len)
631 memset(tag,
'\0',128);
642 anotherByte= byte > 127;
657 data_len+= (uint8_t) byte;
661 data_len+= (uint8_t) byte;
667 data_len= (uint8_t) byte;
683 buffer, data_len*2+1);
693 assert(len==tlv_len);
uint32_t GWEN_Buffer_GetBytesLeft(GWEN_BUFFER *bf)
int GWEN_TLV_IsBerTlv(const GWEN_TLV *tlv)
struct GWEN_DB_NODE GWEN_DB_NODE
static void hex2char(char byte, char *character)
void GWEN_TLV_free(GWEN_TLV *tlv)
GWEN_TLV * GWEN_TLV_create(unsigned int tagType, unsigned int tagMode, const void *p, unsigned int dlen, int isBerTlv)
#define GWEN_FREE_OBJECT(varname)
void GWEN_Memory_dealloc(void *p)
int GWEN_TLV_ReadHeader(GWEN_TLV *tlv, const uint8_t *p, uint32_t size, int isBerTlv)
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
int GWEN_TLV_DirectlyToBuffer(unsigned int tagType, unsigned int tagMode, const void *tagData, int tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
char * GWEN_Buffer_GetPosPointer(const GWEN_BUFFER *bf)
int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i)
unsigned int GWEN_TLV_GetTagType(const GWEN_TLV *tlv)
#define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS
#define GWEN_ERROR_BAD_DATA
int GWEN_DB_AddGroup(GWEN_DB_NODE *n, GWEN_DB_NODE *nn)
int GWEN_DB_SetBinValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const void *val, unsigned int valSize)
#define GWEN_NEW_OBJECT(typ, varname)
#define DBG_DEBUG(dbg_logger, format, args...)
unsigned int GWEN_TLV_GetClass(const GWEN_TLV *tlv)
void * GWEN_Memory_malloc(size_t wsize)
#define BER_TLV_TAG_IS_CONSTRUCTED
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
GWEN_TLV * GWEN_TLV_new(void)
int GWEN_TLV_IsContructed(const GWEN_TLV *tlv)
const void * GWEN_TLV_GetTagData(const GWEN_TLV *tlv)
unsigned int GWEN_TLV_GetTagSize(const GWEN_TLV *tlv)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
int GWEN_TLV_WriteHeader(unsigned int tagType, unsigned int tagMode, uint64_t tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
#define DBG_ERROR(dbg_logger, format, args...)
char * GWEN_Text_ToHex(const char *src, unsigned l, char *buffer, unsigned int maxsize)
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
unsigned int GWEN_TLV_GetTagLength(const GWEN_TLV *tlv)
int GWEN_TLV_toBuffer(GWEN_TLV *tlv, GWEN_BUFFER *mbuf)
int GWEN_Buffer_ReadByte(GWEN_BUFFER *bf)
#define GWEN_LIST_INIT(t, element)
GWEN_TLV * GWEN_TLV_fromBuffer(GWEN_BUFFER *mbuf, int isBerTlv)
int GWEN_TLV_Buffer_To_DB(GWEN_DB_NODE *dbRecord, GWEN_BUFFER *mbuf, int len)
int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
#define GWEN_LIST_FUNCTIONS(t, pr)
#define GWEN_LIST_FINI(t, element)