14#define DISABLE_DEBUGLOG
18#include <gwenhywfar/debug.h>
19#include <gwenhywfar/inherit.h>
20#include <gwenhywfar/misc.h>
21#include <gwenhywfar/text.h>
22#include <gwenhywfar/portable_endian.h>
66 tag->tagLength=tagLength;
72 tag->tagSize=tagLength+3;
84 tag->tagLength=tagLength;
89 memmove(p, tagData, tagLength);
90 tag->tagData=(
const uint8_t*)p;
94 tag->tagSize=tagLength+3;
107 free((uint8_t*)(tag->tagData));
117 return tag?(tag->tagType):0;
124 return tag?(tag->tagLength):0;
131 return tag?(tag->tagSize):0;
138 return tag?(tag->tagData):
NULL;
158 unsigned int tagType;
159 unsigned int tagLength;
166 tagType=*(bufferPtr++);
168 tagLength=(uint16_t)(bufferPtr[0])+(bufferPtr[1]<<8);
171 if (bufferLen<tagLength) {
172 DBG_ERROR(
GWEN_LOGDOMAIN,
"Buffer too small to contain complete TAG16 object with data (%d < %d)", bufferLen, tagLength);
190 uint32_t dataInLittleEndian;
192 dataInLittleEndian=htole32(data);
193 _writeTagToBuffer(tagType, (
const uint8_t*) &dataInLittleEndian,
sizeof(uint32_t), buf);
200 uint64_t dataInLittleEndian;
202 dataInLittleEndian=htole64(data);
203 _writeTagToBuffer(tagType, (
const uint8_t*) &dataInLittleEndian,
sizeof(uint64_t), buf);
220 if (tag && tag->tagLength>=
sizeof(uint32_t))
221 return le32toh(*(uint32_t*)(tag->tagData));
229 if (tag && tag->tagLength>=
sizeof(uint64_t))
230 return le64toh(*(uint64_t*)(tag->tagData));
238 if (tag && tag->tagLength)
240 return defaultValue?strdup(defaultValue):
NULL;
251 if (tag->tagType==tagType)
266 if (tag->tagType==tagType)
292 if (l<tag->tagSize) {
324 *(posPtr++)=tagType & 0xff;
325 *(posPtr++)=size & 0xff;
326 *(posPtr++)=(size>>8) & 0xff;
328 memmove(posPtr, p, size);
351 *(posPtr++)=tagType & 0xff;
377 payloadSize=currentPos-startPos-3;
386 *(posPtr++)=payloadSize & 0xff;
387 *(posPtr++)=(payloadSize>>8) & 0xff;
int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i)
int GWEN_Buffer_AdjustUsedBytes(GWEN_BUFFER *bf)
char * GWEN_Buffer_GetPosPointer(const GWEN_BUFFER *bf)
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
int GWEN_Buffer_AllocRoom(GWEN_BUFFER *bf, uint32_t size)
#define DBG_INFO(dbg_logger, format,...)
#define DBG_ERROR(dbg_logger, format,...)
#define GWEN_ERROR_INVALID
#define GWEN_ERROR_GENERIC
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)
GWEN_TAG16 * GWEN_Tag16_List_First(const GWEN_TAG16_LIST *l)
void GWEN_Tag16_List_free(GWEN_TAG16_LIST *l)
uint32_t GWEN_Tag16_List_GetCount(const GWEN_TAG16_LIST *l)
void GWEN_Tag16_List_Add(GWEN_TAG16 *element, GWEN_TAG16_LIST *list)
GWEN_TAG16 * GWEN_Tag16_List_Next(const GWEN_TAG16 *element)
GWEN_TAG16_LIST * GWEN_Tag16_List_new()
#define GWEN_FREE_OBJECT(varname)
#define GWEN_NEW_OBJECT(typ, varname)
void GWEN_Tag16_WriteTagToBuffer(unsigned int tagType, const uint8_t *s, int size, GWEN_BUFFER *buf)
void GWEN_Tag16_WriteStringTagToBuffer(unsigned int tagType, const char *s, GWEN_BUFFER *buf)
GWEN_TAG16 * GWEN_Tag16_new(void)
GWEN_TAG16 * GWEN_Tag16_newNoCopy(unsigned int tagType, unsigned int tagLength, const uint8_t *tagData)
const GWEN_TAG16 * GWEN_Tag16_List_FindNextByTagType(const GWEN_TAG16 *tag, unsigned int tagType)
uint64_t GWEN_Tag16_GetTagDataAsUint64(const GWEN_TAG16 *tag, uint64_t defaultValue)
void GWEN_Tag16_DirectlyToBuffer(unsigned int tagType, const char *p, int size, GWEN_BUFFER *buf)
GWEN_TAG16 * GWEN_Tag16_fromBuffer(GWEN_BUFFER *mbuf, GWEN_UNUSED int isBerTlv)
char * GWEN_Tag16_GetTagDataAsNewString(const GWEN_TAG16 *tag, const char *defaultValue)
unsigned int GWEN_Tag16_GetTagLength(const GWEN_TAG16 *tag)
GWEN_TAG16 * GWEN_Tag16_newCopy(unsigned int tagType, unsigned int tagLength, const uint8_t *tagData)
const void * GWEN_Tag16_GetTagData(const GWEN_TAG16 *tag)
void GWEN_Tag16_free(GWEN_TAG16 *tag)
int GWEN_Tag16_StartTagInBuffer(unsigned int tagType, GWEN_BUFFER *buf)
void GWEN_Tag16_WriteUint32TagToBuffer(unsigned int tagType, uint32_t data, GWEN_BUFFER *buf)
unsigned int GWEN_Tag16_GetTagType(const GWEN_TAG16 *tag)
uint32_t GWEN_Tag16_GetTagDataAsUint32(const GWEN_TAG16 *tag, uint32_t defaultValue)
GWEN_TAG16_LIST * GWEN_Tag16_List_fromBuffer(const uint8_t *p, uint32_t l, int doCopy)
static void _writeTagToBuffer(unsigned int tagType, const uint8_t *p, int size, GWEN_BUFFER *buf)
int GWEN_Tag16_EndTagInBuffer(int startPos, GWEN_BUFFER *buf)
GWEN_TAG16 * GWEN_Tag16_fromBuffer2(const uint8_t *bufferPtr, uint32_t bufferLen, int doCopy)
unsigned int GWEN_Tag16_GetTagSize(const GWEN_TAG16 *tag)
const GWEN_TAG16 * GWEN_Tag16_List_FindFirstByTagType(const GWEN_TAG16_LIST *tagList, unsigned int tagType)
void GWEN_Tag16_WriteUint64TagToBuffer(unsigned int tagType, uint64_t data, GWEN_BUFFER *buf)
struct GWEN_TAG16 GWEN_TAG16
char * GWEN_Text_strndup(const char *s, size_t n)