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);
197 uint16_t dataInLittleEndian;
199 dataInLittleEndian=htole16(data);
200 _writeTagToBuffer(tagType, (
const uint8_t*) &dataInLittleEndian,
sizeof(uint16_t), buf);
207 uint32_t dataInLittleEndian;
209 dataInLittleEndian=htole32(data);
210 _writeTagToBuffer(tagType, (
const uint8_t*) &dataInLittleEndian,
sizeof(uint32_t), buf);
217 uint64_t dataInLittleEndian;
219 dataInLittleEndian=htole64(data);
220 _writeTagToBuffer(tagType, (
const uint8_t*) &dataInLittleEndian,
sizeof(uint64_t), buf);
227 uint64_t dataInLittleEndian;
234 dataInLittleEndian=htole64(v.u);
235 _writeTagToBuffer(tagType, (
const uint8_t*) &dataInLittleEndian,
sizeof(uint64_t), buf);
252 if (tag && tag->tagLength>=
sizeof(uint8_t))
253 return *(uint8_t*)(tag->tagData);
261 if (tag && tag->tagLength>=
sizeof(uint16_t))
262 return le16toh(*(uint16_t*)(tag->tagData));
270 if (tag && tag->tagLength>=
sizeof(uint32_t))
271 return le32toh(*(uint32_t*)(tag->tagData));
279 if (tag && tag->tagLength>=
sizeof(uint64_t))
280 return le64toh(*(uint64_t*)(tag->tagData));
288 if (tag && tag->tagLength>=
sizeof(uint64_t)) {
294 v.u=le64toh(*(uint64_t*)(tag->tagData));
304 if (tag && tag->tagLength)
306 return defaultValue?strdup(defaultValue):
NULL;
317 if (tag->tagType==tagType)
332 if (tag->tagType==tagType)
358 if (l<tag->tagSize) {
390 *(posPtr++)=tagType & 0xff;
391 *(posPtr++)=size & 0xff;
392 *(posPtr++)=(size>>8) & 0xff;
394 memmove(posPtr, p, size);
417 *(posPtr++)=tagType & 0xff;
443 payloadSize=currentPos-startPos-3;
452 *(posPtr++)=payloadSize & 0xff;
453 *(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)
double GWEN_Tag16_GetTagDataAsDouble(const GWEN_TAG16 *tag, double defaultValue)
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)
uint16_t GWEN_Tag16_GetTagDataAsUint16(const GWEN_TAG16 *tag, uint16_t defaultValue)
void GWEN_Tag16_WriteUint8TagToBuffer(unsigned int tagType, uint8_t data, GWEN_BUFFER *buf)
uint8_t GWEN_Tag16_GetTagDataAsUint8(const GWEN_TAG16 *tag, uint8_t defaultValue)
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)
void GWEN_Tag16_WriteUint16TagToBuffer(unsigned int tagType, uint16_t data, GWEN_BUFFER *buf)
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)
void GWEN_Tag16_WriteDoubleTagToBuffer(unsigned int tagType, double data, 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)