diff --git a/c/tlv_box.c b/c/tlv_box.c index e1a245e..33f458b 100644 --- a/c/tlv_box.c +++ b/c/tlv_box.c @@ -14,6 +14,8 @@ #include #include "tlv_box.h" +int tlv_box_putobject(tlv_box_t *box, int type, void *value, int length); + static void tlv_box_release_tlv(value_t value) { tlv_t *tlv = (tlv_t *)value.value; @@ -37,7 +39,7 @@ tlv_box_t *tlv_box_parse(unsigned char *buffer, int buffersize) unsigned char *cached = (unsigned char*) malloc(buffersize); memcpy(cached, buffer, buffersize); - int offset = 0, length = 0; + int offset = 0; while (offset < buffersize) { int type = (*(int *)(cached + offset)); offset += sizeof(int); @@ -103,21 +105,41 @@ int tlv_box_put_char(tlv_box_t *box, int type, char value) return tlv_box_putobject(box, type, &value, sizeof(char)); } +int tlv_box_put_uchar(tlv_box_t *box, int type, unsigned char value) +{ + return tlv_box_putobject(box, type, &value, sizeof(unsigned char)); +} + int tlv_box_put_short(tlv_box_t *box, int type, short value) { return tlv_box_putobject(box, type, &value, sizeof(short)); } +int tlv_box_put_ushort(tlv_box_t *box, int type, unsigned short value) +{ + return tlv_box_putobject(box, type, &value, sizeof(unsigned short)); +} + int tlv_box_put_int(tlv_box_t *box, int type, int value) { return tlv_box_putobject(box, type, &value, sizeof(int)); } +int tlv_box_put_uint(tlv_box_t *box, int type, unsigned int value) +{ + return tlv_box_putobject(box, type, &value, sizeof(unsigned int)); +} + int tlv_box_put_long(tlv_box_t *box, int type, long value) { return tlv_box_putobject(box, type, &value, sizeof(long)); } +int tlv_box_put_ulong(tlv_box_t *box, int type, unsigned long value) +{ + return tlv_box_putobject(box, type, &value, sizeof(unsigned long)); +} + int tlv_box_put_longlong(tlv_box_t *box, int type, long long value) { return tlv_box_putobject(box, type, &value, sizeof(long long)); @@ -182,6 +204,17 @@ int tlv_box_get_char(tlv_box_t *box, int type, char *value) return 0; } +int tlv_box_get_uchar(tlv_box_t *box, int type, unsigned char *value) +{ + value_t object; + if (key_list_get(box->m_list, type, &object) != 0) { + return -1; + } + tlv_t *tlv = (tlv_t *) object.value; + *value = (*(unsigned char *)(tlv->value)); + return 0; +} + int tlv_box_get_short(tlv_box_t *box, int type, short *value) { value_t object; @@ -193,6 +226,17 @@ int tlv_box_get_short(tlv_box_t *box, int type, short *value) return 0; } +int tlv_box_get_ushort(tlv_box_t *box, int type, unsigned short *value) +{ + value_t object; + if (key_list_get(box->m_list, type, &object) != 0) { + return -1; + } + tlv_t *tlv = (tlv_t *) object.value; + *value = (*(unsigned short *)(tlv->value)); + return 0; +} + int tlv_box_get_int(tlv_box_t *box, int type, int *value) { value_t object; @@ -204,6 +248,17 @@ int tlv_box_get_int(tlv_box_t *box, int type, int *value) return 0; } +int tlv_box_get_uint(tlv_box_t *box, int type, unsigned int *value) +{ + value_t object; + if (key_list_get(box->m_list, type, &object) != 0) { + return -1; + } + tlv_t *tlv = (tlv_t *) object.value; + *value = (*(unsigned int *)(tlv->value)); + return 0; +} + int tlv_box_get_long(tlv_box_t *box, int type, long *value) { value_t object; @@ -215,6 +270,17 @@ int tlv_box_get_long(tlv_box_t *box, int type, long *value) return 0; } +int tlv_box_get_ulong(tlv_box_t *box, int type, unsigned long *value) +{ + value_t object; + if (key_list_get(box->m_list, type, &object) != 0) { + return -1; + } + tlv_t *tlv = (tlv_t *) object.value; + *value = (*(unsigned long *)(tlv->value)); + return 0; +} + int tlv_box_get_longlong(tlv_box_t *box, int type, long long *value) { value_t object; @@ -250,7 +316,7 @@ int tlv_box_get_double(tlv_box_t *box, int type, double *value) int tlv_box_get_string(tlv_box_t *box, int type, char *value, int* length) { - return tlv_box_get_bytes(box,type,value,length); + return tlv_box_get_bytes(box,type,(unsigned char *)value,length); } int tlv_box_get_bytes(tlv_box_t *box, int type, unsigned char *value, int* length) @@ -290,4 +356,5 @@ int tlv_box_get_object(tlv_box_t *box, int type, tlv_box_t **object) tlv_t *tlv = (tlv_t *) value.value; *object = (tlv_box_t *)tlv_box_parse(tlv->value, tlv->length); return 0; -} \ No newline at end of file +} + diff --git a/c/tlv_box.h b/c/tlv_box.h index 7631929..55447a4 100644 --- a/c/tlv_box.h +++ b/c/tlv_box.h @@ -35,9 +35,13 @@ unsigned char *tlv_box_get_buffer(tlv_box_t *box); int tlv_box_get_size(tlv_box_t *box); int tlv_box_put_char(tlv_box_t *box,int type,char value); +int tlv_box_put_uchar(tlv_box_t *box,int type,unsigned char value); int tlv_box_put_short(tlv_box_t *box,int type,short value); +int tlv_box_put_ushort(tlv_box_t *box,int type,unsigned short value); int tlv_box_put_int(tlv_box_t *box,int type,int value); +int tlv_box_put_uint(tlv_box_t *box,int type,unsigned int value); int tlv_box_put_long(tlv_box_t *box,int type,long value); +int tlv_box_put_ulong(tlv_box_t *box,int type,unsigned long value); int tlv_box_put_longlong(tlv_box_t *box,int type,long long value); int tlv_box_put_float(tlv_box_t *box,int type,float value); int tlv_box_put_double(tlv_box_t *box,int type,double value); @@ -47,9 +51,13 @@ int tlv_box_put_object(tlv_box_t *box,int type,tlv_box_t *object); int tlv_box_serialize(tlv_box_t *box); int tlv_box_get_char(tlv_box_t *box,int type,char *value); +int tlv_box_get_uchar(tlv_box_t *box,int type,unsigned char *value); int tlv_box_get_short(tlv_box_t *box,int type,short *value); +int tlv_box_get_ushort(tlv_box_t *box,int type,unsigned short *value); int tlv_box_get_int(tlv_box_t *box,int type,int *value); +int tlv_box_get_uint(tlv_box_t *box,int type,unsigned int *value); int tlv_box_get_long(tlv_box_t *box,int type,long *value); +int tlv_box_get_ulong(tlv_box_t *box,int type,unsigned long *value); int tlv_box_get_longlong(tlv_box_t *box,int type,long long *value); int tlv_box_get_float(tlv_box_t *box,int type,float *value); int tlv_box_get_double(tlv_box_t *box,int type,double *value);