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
88 tlv->isBerTlv=isBerTlv;
92 tlv->tagData=malloc(dlen);
94 memmove(tlv->tagData, p, dlen);
105 return tlv->isBerTlv;
121 return tlv->tagLength;
145 unsigned int tagMode;
146 unsigned int tagType;
147 unsigned int tagLength;
162 tagMode=tagType=tagLength=0;
173 j=(
unsigned char)(p[pos]);
176 if ((j & 0x1f)==0x1f) {
182 j=(
unsigned char)(p[pos]);
188 isBerTlv?
" (BER-TLV)":
"");
197 j=(
unsigned char)(p[pos]);
206 j=(
unsigned char)(p[pos]);
214 j=((
unsigned char)(p[pos]))<<8;
216 j+=(
unsigned char)(p[pos]);
231 j=((
unsigned char)(p[pos]))<<8;
233 j+=(
unsigned char)(p[pos]);
249 tlv->isBerTlv=isBerTlv;
250 tlv->tagMode=tagMode;
251 tlv->tagType=tagType;
252 tlv->tagLength=tagLength;
254 tlv->tagData=(
void *)malloc(tagLength);
255 memmove(tlv->tagData, tagData, tagLength);
268 return (tlv->tagMode & 0x20);
276 return (tlv->tagMode & 0xc0);
295 unsigned int tagMode,
302 tagLength=strlen(tagData);
326 else if (tagLength>127) {
364 tagMode=tagType=tagLength=0;
373 j=(
unsigned char)(p[pos]);
376 if ((j & 0x1f)==0x1f) {
382 j=(
unsigned char)(p[pos]);
388 isBerTlv?
" (BER-TLV)":
"");
397 j=(
unsigned char)(p[pos]);
406 j=(
unsigned char)(p[pos]);
414 j=((
unsigned char)(p[pos]))<<8;
416 j+=(
unsigned char)(p[pos]);
424 j=((
unsigned char)(p[pos]))<<16;
426 j+=((
unsigned char)(p[pos]))<<8;
428 j+=(
unsigned char)(p[pos]);
436 j=((
unsigned char)(p[pos]))<<24;
438 j+=((
unsigned char)(p[pos]))<<16;
440 j+=((
unsigned char)(p[pos]))<<8;
442 j+=(
unsigned char)(p[pos]);
450 j=((uint64_t)((
unsigned char)(p[pos])))<<32;
452 j+=((uint64_t)((
unsigned char)(p[pos])))<<24;
454 j+=((uint64_t)((
unsigned char)(p[pos])))<<16;
456 j+=((uint64_t)((
unsigned char)(p[pos])))<<8;
458 j+=(
unsigned char)(p[pos]);
473 j=((
unsigned char)(p[pos]))<<8;
475 j+=(
unsigned char)(p[pos]);
483 tlv->isBerTlv=isBerTlv;
484 tlv->tagMode=tagMode;
485 tlv->tagType=tagType;
486 tlv->tagLength=tagLength;
488 tlv->tagSize=pos+tagLength;
495 unsigned int tagMode,
516 if (tagLength>0xffffffffL) {
525 else if (tagLength>0xffffffL) {
533 else if (tagLength>0xffff) {
540 else if (tagLength>0xff) {
546 else if (tagLength>127) {
570 nibbles[0]=(
byte>>4) &0x0f;
571 nibbles[1]=
byte & 0x0f;
573 for (i = 0 ; i < 2 ; i++) {
574 switch (nibbles[i]) {
632 unsigned int tag_len=0;
642 while (tlv_len < len) {
644 memset(tag,
'\0', 128);
650 while (anotherByte) {
654 anotherByte=
byte > 127;
660 uint8_t numLengthBytes=
byte-128;
663 while (numLengthBytes--) {
667 data_len+=(uint32_t)
byte;
671 data_len= (uint8_t)
byte;
683 buffer, data_len*2+1);
693 assert(len==tlv_len);
717 while (anotherByte) {
726 anotherByte=
byte > 127;
731 uint8_t numLengthBytes=
byte-128;
734 while (numLengthBytes--) {
744 data_len+=(uint32_t)
byte;
748 data_len= (uint8_t)
byte;
750 *tag_len_len=tlv_len;
int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i)
uint32_t GWEN_Buffer_GetBytesLeft(GWEN_BUFFER *bf)
char * GWEN_Buffer_GetPosPointer(const GWEN_BUFFER *bf)
int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
int GWEN_Buffer_ReadByte(GWEN_BUFFER *bf)
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
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)
int GWEN_DB_AddGroup(GWEN_DB_NODE *n, GWEN_DB_NODE *nn)
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
int GWEN_DB_SetBinValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const void *val, unsigned int valSize)
struct GWEN_DB_NODE GWEN_DB_NODE
#define DBG_INFO(dbg_logger, format,...)
#define DBG_ERROR(dbg_logger, format,...)
#define DBG_DEBUG(dbg_logger, format,...)
#define GWEN_ERROR_BAD_DATA
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
#define GWEN_LIST_FINI(t, element)
#define GWEN_LIST_FUNCTIONS(t, pr)
#define GWEN_LIST_INIT(t, element)
void * GWEN_Memory_malloc(size_t wsize)
void GWEN_Memory_dealloc(void *p)
#define GWEN_FREE_OBJECT(varname)
#define GWEN_NEW_OBJECT(typ, varname)
char * GWEN_Text_ToHex(const char *src, unsigned l, char *buffer, unsigned int maxsize)
int GWEN_TLV_IsBerTlv(const GWEN_TLV *tlv)
unsigned int GWEN_TLV_GetTagLength(const GWEN_TLV *tlv)
GWEN_TLV * GWEN_TLV_create(unsigned int tagType, unsigned int tagMode, const void *p, unsigned int dlen, int isBerTlv)
int GWEN_TLV_Buffer_To_DB(GWEN_DB_NODE *dbRecord, GWEN_BUFFER *mbuf, int len)
#define BER_TLV_TAG_IS_CONSTRUCTED
unsigned int GWEN_TLV_GetTagType(const GWEN_TLV *tlv)
static void hex2char(char byte, char *character)
const void * GWEN_TLV_GetTagData(const GWEN_TLV *tlv)
GWEN_TLV * GWEN_TLV_new(void)
int GWEN_TLV_ReadHeader(GWEN_TLV *tlv, const uint8_t *p, uint32_t size, int isBerTlv)
void GWEN_TLV_free(GWEN_TLV *tlv)
GWEN_TLV * GWEN_TLV_fromBuffer(GWEN_BUFFER *mbuf, int isBerTlv)
unsigned int GWEN_TLV_GetTagSize(const GWEN_TLV *tlv)
int GWEN_TLV_IsContructed(const GWEN_TLV *tlv)
int GWEN_TLV_toBuffer(GWEN_TLV *tlv, GWEN_BUFFER *mbuf)
uint32_t GWEN_TLV_ParseLength(GWEN_BUFFER *mbuf, uint32_t *tag_len_len)
int GWEN_TLV_DirectlyToBuffer(unsigned int tagType, unsigned int tagMode, const void *tagData, int tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
unsigned int GWEN_TLV_GetClass(const GWEN_TLV *tlv)
#define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS
int GWEN_TLV_WriteHeader(unsigned int tagType, unsigned int tagMode, uint64_t tagLength, int isBerTlv, GWEN_BUFFER *mbuf)