diff options
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | src/bplist.c | 66 | ||||
| -rw-r--r-- | src/plist.h | 2 | ||||
| -rw-r--r-- | src/xplist.c | 91 |
4 files changed, 94 insertions, 67 deletions
diff --git a/configure.ac b/configure.ac index 4af0e49..2f171e1 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -45,7 +45,7 @@ if test "$no_debug_code" = true; then | |||
| 45 | AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code]) | 45 | AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code]) |
| 46 | fi | 46 | fi |
| 47 | 47 | ||
| 48 | AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default") | 48 | AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter") |
| 49 | AC_SUBST(GLOBAL_CFLAGS) | 49 | AC_SUBST(GLOBAL_CFLAGS) |
| 50 | 50 | ||
| 51 | AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc) | 51 | AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc) |
diff --git a/src/bplist.c b/src/bplist.c index ed381db..7a7225d 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -27,10 +27,10 @@ | |||
| 27 | #include <string.h> | 27 | #include <string.h> |
| 28 | 28 | ||
| 29 | /* Magic marker and size. */ | 29 | /* Magic marker and size. */ |
| 30 | #define BPLIST_MAGIC "bplist" | 30 | #define BPLIST_MAGIC ((uint8_t*)"bplist") |
| 31 | #define BPLIST_MAGIC_SIZE 6 | 31 | #define BPLIST_MAGIC_SIZE 6 |
| 32 | 32 | ||
| 33 | #define BPLIST_VERSION "00" | 33 | #define BPLIST_VERSION ((uint8_t*)"00") |
| 34 | #define BPLIST_VERSION_SIZE 2 | 34 | #define BPLIST_VERSION_SIZE 2 |
| 35 | 35 | ||
| 36 | 36 | ||
| @@ -59,11 +59,11 @@ enum { | |||
| 59 | BPLIST_MASK = 0xF0 | 59 | BPLIST_MASK = 0xF0 |
| 60 | }; | 60 | }; |
| 61 | 61 | ||
| 62 | static void byte_convert(char *address, size_t size) | 62 | static void byte_convert(uint8_t *address, size_t size) |
| 63 | { | 63 | { |
| 64 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN | 64 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
| 65 | uint8_t i = 0, j = 0; | 65 | uint8_t i = 0, j = 0; |
| 66 | char tmp = '\0'; | 66 | uint8_t tmp = 0; |
| 67 | 67 | ||
| 68 | for (i = 0; i < (size / 2); i++) { | 68 | for (i = 0; i < (size / 2); i++) { |
| 69 | tmp = address[i]; | 69 | tmp = address[i]; |
| @@ -75,13 +75,18 @@ static void byte_convert(char *address, size_t size) | |||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | #define swap_n_bytes(x, n) \ | 77 | #define swap_n_bytes(x, n) \ |
| 78 | n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \ | 78 | (n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \ |
| 79 | (n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \ | 79 | (n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \ |
| 80 | (n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : *(uint8_t *)(x) )) | 80 | (n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : \ |
| 81 | *(uint8_t *)(x) ))) | ||
| 81 | 82 | ||
| 82 | #define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) ) | 83 | #define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) ) |
| 83 | 84 | ||
| 84 | #define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= (uint64_t)1<<32 ? 4 : 8))) | 85 | #define get_needed_bytes(x) \ |
| 86 | ( ((uint64_t)x) < (1ULL << 8) ? 1 : \ | ||
| 87 | ( ((uint64_t)x) < (1ULL << 16) ? 2 : \ | ||
| 88 | ( ((uint64_t)x) < (1ULL << 32) ? 4 : 8))) | ||
| 89 | |||
| 85 | #define get_real_bytes(x) (x >> 32 ? 4 : 8) | 90 | #define get_real_bytes(x) (x >> 32 ? 4 : 8) |
| 86 | 91 | ||
| 87 | 92 | ||
| @@ -118,12 +123,8 @@ static plist_t parse_real_node(char *bnode, uint8_t size) | |||
| 118 | size = 1 << size; // make length less misleading | 123 | size = 1 << size; // make length less misleading |
| 119 | switch (size) { | 124 | switch (size) { |
| 120 | case sizeof(float): | 125 | case sizeof(float): |
| 121 | memcpy(&data->realval, bnode, size); | ||
| 122 | byte_convert((char *) &data->realval, size); | ||
| 123 | break; | ||
| 124 | case sizeof(double): | 126 | case sizeof(double): |
| 125 | memcpy(&data->realval, bnode, size); | 127 | data->realval = swap_n_bytes(bnode, size); |
| 126 | byte_convert((char *) &data->realval, size); | ||
| 127 | break; | 128 | break; |
| 128 | default: | 129 | default: |
| 129 | free(data); | 130 | free(data); |
| @@ -163,8 +164,8 @@ static plist_t parse_data_node(char *bnode, uint64_t size) | |||
| 163 | 164 | ||
| 164 | data->type = PLIST_DATA; | 165 | data->type = PLIST_DATA; |
| 165 | data->length = size; | 166 | data->length = size; |
| 166 | data->buff = (char *) malloc(sizeof(char) * size); | 167 | data->buff = (uint8_t *) malloc(sizeof(uint8_t) * size); |
| 167 | memcpy(data->buff, bnode, sizeof(char) * size); | 168 | memcpy(data->buff, bnode, sizeof(uint8_t) * size); |
| 168 | 169 | ||
| 169 | return g_node_new(data); | 170 | return g_node_new(data); |
| 170 | } | 171 | } |
| @@ -175,8 +176,8 @@ static plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) | |||
| 175 | 176 | ||
| 176 | data->type = PLIST_DICT; | 177 | data->type = PLIST_DICT; |
| 177 | data->length = size; | 178 | data->length = size; |
| 178 | data->buff = (char *) malloc(sizeof(char) * size * ref_size * 2); | 179 | data->buff = (uint8_t *) malloc(sizeof(uint8_t) * size * ref_size * 2); |
| 179 | memcpy(data->buff, bnode, sizeof(char) * size * ref_size * 2); | 180 | memcpy(data->buff, bnode, sizeof(uint8_t) * size * ref_size * 2); |
| 180 | 181 | ||
| 181 | return g_node_new(data); | 182 | return g_node_new(data); |
| 182 | } | 183 | } |
| @@ -187,8 +188,8 @@ static plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) | |||
| 187 | 188 | ||
| 188 | data->type = PLIST_ARRAY; | 189 | data->type = PLIST_ARRAY; |
| 189 | data->length = size; | 190 | data->length = size; |
| 190 | data->buff = (char *) malloc(sizeof(char) * size * ref_size); | 191 | data->buff = (uint8_t *) malloc(sizeof(uint8_t) * size * ref_size); |
| 191 | memcpy(data->buff, bnode, sizeof(char) * size * ref_size); | 192 | memcpy(data->buff, bnode, sizeof(uint8_t) * size * ref_size); |
| 192 | 193 | ||
| 193 | return g_node_new(data); | 194 | return g_node_new(data); |
| 194 | } | 195 | } |
| @@ -321,12 +322,12 @@ static gpointer copy_plist_data(gconstpointer src, gpointer data) | |||
| 321 | break; | 322 | break; |
| 322 | case PLIST_DATA: | 323 | case PLIST_DATA: |
| 323 | case PLIST_ARRAY: | 324 | case PLIST_ARRAY: |
| 324 | dstdata->buff = (char *) malloc(sizeof(char *) * srcdata->length); | 325 | dstdata->buff = (uint8_t *) malloc(sizeof(uint8_t *) * srcdata->length); |
| 325 | memcpy(dstdata->buff, srcdata->buff, sizeof(char *) * srcdata->length); | 326 | memcpy(dstdata->buff, srcdata->buff, sizeof(uint8_t *) * srcdata->length); |
| 326 | break; | 327 | break; |
| 327 | case PLIST_DICT: | 328 | case PLIST_DICT: |
| 328 | dstdata->buff = (char *) malloc(sizeof(char *) * srcdata->length * 2); | 329 | dstdata->buff = (uint8_t *) malloc(sizeof(uint8_t *) * srcdata->length * 2); |
| 329 | memcpy(dstdata->buff, srcdata->buff, sizeof(char *) * srcdata->length * 2); | 330 | memcpy(dstdata->buff, srcdata->buff, sizeof(uint8_t *) * srcdata->length * 2); |
| 330 | break; | 331 | break; |
| 331 | default: | 332 | default: |
| 332 | break; | 333 | break; |
| @@ -561,7 +562,9 @@ static void serialize_plist(GNode * node, gpointer data) | |||
| 561 | return; | 562 | return; |
| 562 | } | 563 | } |
| 563 | //insert new ref | 564 | //insert new ref |
| 564 | g_hash_table_insert(ser->ref_table, node, GUINT_TO_POINTER(current_index)); | 565 | uint64_t* index_val = (uint64_t*) malloc(sizeof(uint64_t)); |
| 566 | *index_val = current_index; | ||
| 567 | g_hash_table_insert(ser->ref_table, node, index_val); | ||
| 565 | 568 | ||
| 566 | //now append current node to object array | 569 | //now append current node to object array |
| 567 | g_ptr_array_add(ser->objects, node); | 570 | g_ptr_array_add(ser->objects, node); |
| @@ -571,6 +574,12 @@ static void serialize_plist(GNode * node, gpointer data) | |||
| 571 | return; | 574 | return; |
| 572 | } | 575 | } |
| 573 | 576 | ||
| 577 | static gboolean free_index (gpointer key, gpointer value, gpointer user_data) | ||
| 578 | { | ||
| 579 | free((uint64_t*)value); | ||
| 580 | return TRUE; | ||
| 581 | } | ||
| 582 | |||
| 574 | #define Log2(x) (x == 8 ? 3 : (x == 4 ? 2 : (x == 2 ? 1 : 0))) | 583 | #define Log2(x) (x == 8 ? 3 : (x == 4 ? 2 : (x == 2 ? 1 : 0))) |
| 575 | 584 | ||
| 576 | static void write_int(GByteArray * bplist, uint64_t val) | 585 | static void write_int(GByteArray * bplist, uint64_t val) |
| @@ -619,7 +628,7 @@ static void write_data(GByteArray * bplist, uint8_t * val, uint64_t size) | |||
| 619 | static void write_string(GByteArray * bplist, char *val) | 628 | static void write_string(GByteArray * bplist, char *val) |
| 620 | { | 629 | { |
| 621 | uint64_t size = strlen(val); | 630 | uint64_t size = strlen(val); |
| 622 | write_raw_data(bplist, BPLIST_STRING, val, size); | 631 | write_raw_data(bplist, BPLIST_STRING, (uint8_t*) val, size); |
| 623 | } | 632 | } |
| 624 | 633 | ||
| 625 | static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) | 634 | static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) |
| @@ -640,7 +649,7 @@ static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_tabl | |||
| 640 | GNode *cur = NULL; | 649 | GNode *cur = NULL; |
| 641 | uint64_t i = 0; | 650 | uint64_t i = 0; |
| 642 | for (i = 0, cur = node->children; cur && i < size; cur = cur->next, i++) { | 651 | for (i = 0, cur = node->children; cur && i < size; cur = cur->next, i++) { |
| 643 | idx = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur)); | 652 | idx = *(uint64_t*)(g_hash_table_lookup(ref_table, cur)); |
| 644 | memcpy(buff + i * dict_param_size, &idx, dict_param_size); | 653 | memcpy(buff + i * dict_param_size, &idx, dict_param_size); |
| 645 | byte_convert(buff + i * dict_param_size, dict_param_size); | 654 | byte_convert(buff + i * dict_param_size, dict_param_size); |
| 646 | } | 655 | } |
| @@ -747,7 +756,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 747 | //TODO | 756 | //TODO |
| 748 | break; | 757 | break; |
| 749 | case PLIST_DATA: | 758 | case PLIST_DATA: |
| 750 | write_data(bplist_buff, data->strval, data->length); | 759 | write_data(bplist_buff, data->buff, data->length); |
| 751 | case PLIST_ARRAY: | 760 | case PLIST_ARRAY: |
| 752 | write_array(bplist_buff, g_ptr_array_index(objects, i), ref_table, dict_param_size); | 761 | write_array(bplist_buff, g_ptr_array_index(objects, i), ref_table, dict_param_size); |
| 753 | break; | 762 | break; |
| @@ -762,6 +771,9 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 762 | } | 771 | } |
| 763 | } | 772 | } |
| 764 | 773 | ||
| 774 | //free intermediate objects | ||
| 775 | g_hash_table_foreach_remove (ref_table, free_index, NULL); | ||
| 776 | |||
| 765 | //write offsets | 777 | //write offsets |
| 766 | offset_size = get_needed_bytes(bplist_buff->len); | 778 | offset_size = get_needed_bytes(bplist_buff->len); |
| 767 | offset_table_index = bplist_buff->len; | 779 | offset_table_index = bplist_buff->len; |
| @@ -778,7 +790,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 778 | root_object = GUINT64_FROM_BE(root_object); | 790 | root_object = GUINT64_FROM_BE(root_object); |
| 779 | offset_table_index = GUINT64_FROM_BE(offset_table_index); | 791 | offset_table_index = GUINT64_FROM_BE(offset_table_index); |
| 780 | 792 | ||
| 781 | char trailer[BPLIST_TRL_SIZE]; | 793 | uint8_t trailer[BPLIST_TRL_SIZE]; |
| 782 | memcpy(trailer + BPLIST_TRL_OFFSIZE_IDX, &offset_size, sizeof(uint8_t)); | 794 | memcpy(trailer + BPLIST_TRL_OFFSIZE_IDX, &offset_size, sizeof(uint8_t)); |
| 783 | memcpy(trailer + BPLIST_TRL_PARMSIZE_IDX, &dict_param_size, sizeof(uint8_t)); | 795 | memcpy(trailer + BPLIST_TRL_PARMSIZE_IDX, &dict_param_size, sizeof(uint8_t)); |
| 784 | memcpy(trailer + BPLIST_TRL_NUMOBJ_IDX, &num_objects, sizeof(uint64_t)); | 796 | memcpy(trailer + BPLIST_TRL_NUMOBJ_IDX, &num_objects, sizeof(uint64_t)); |
diff --git a/src/plist.h b/src/plist.h index a637118..8428597 100644 --- a/src/plist.h +++ b/src/plist.h | |||
| @@ -43,7 +43,7 @@ struct plist_data_s { | |||
| 43 | double realval; | 43 | double realval; |
| 44 | char *strval; | 44 | char *strval; |
| 45 | wchar_t *unicodeval; | 45 | wchar_t *unicodeval; |
| 46 | char *buff; | 46 | uint8_t *buff; |
| 47 | }; | 47 | }; |
| 48 | uint64_t length; | 48 | uint64_t length; |
| 49 | plist_type type; | 49 | plist_type type; |
diff --git a/src/xplist.c b/src/xplist.c index abc448d..3487f96 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -32,6 +32,17 @@ | |||
| 32 | #include <libxml/parser.h> | 32 | #include <libxml/parser.h> |
| 33 | #include <libxml/tree.h> | 33 | #include <libxml/tree.h> |
| 34 | 34 | ||
| 35 | #define XPLIST_TEXT BAD_CAST("text") | ||
| 36 | #define XPLIST_KEY BAD_CAST("key") | ||
| 37 | #define XPLIST_FALSE BAD_CAST("false") | ||
| 38 | #define XPLIST_TRUE BAD_CAST("true") | ||
| 39 | #define XPLIST_INT BAD_CAST("integer") | ||
| 40 | #define XPLIST_REAL BAD_CAST("real") | ||
| 41 | #define XPLIST_DATE BAD_CAST("date") | ||
| 42 | #define XPLIST_DATA BAD_CAST("data") | ||
| 43 | #define XPLIST_STRING BAD_CAST("string") | ||
| 44 | #define XPLIST_ARRAY BAD_CAST("array") | ||
| 45 | #define XPLIST_DICT BAD_CAST("dict") | ||
| 35 | 46 | ||
| 36 | const char *plist_base = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ | 47 | const char *plist_base = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ |
| 37 | <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n\ | 48 | <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n\ |
| @@ -125,56 +136,56 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 125 | xmlNodePtr child_node = NULL; | 136 | xmlNodePtr child_node = NULL; |
| 126 | char isStruct = FALSE; | 137 | char isStruct = FALSE; |
| 127 | 138 | ||
| 128 | const gchar *tag = NULL; | 139 | const xmlChar *tag = NULL; |
| 129 | const gchar *val = NULL; | 140 | gchar *val = NULL; |
| 130 | 141 | ||
| 131 | switch (node_data->type) { | 142 | switch (node_data->type) { |
| 132 | case PLIST_BOOLEAN: | 143 | case PLIST_BOOLEAN: |
| 133 | { | 144 | { |
| 134 | if (node_data->boolval) | 145 | if (node_data->boolval) |
| 135 | tag = "true"; | 146 | tag = XPLIST_TRUE; |
| 136 | else | 147 | else |
| 137 | tag = "false"; | 148 | tag = XPLIST_FALSE; |
| 138 | } | 149 | } |
| 139 | break; | 150 | break; |
| 140 | 151 | ||
| 141 | case PLIST_UINT: | 152 | case PLIST_UINT: |
| 142 | tag = "integer"; | 153 | tag = XPLIST_INT; |
| 143 | val = g_strdup_printf("%lu", (long unsigned int) node_data->intval); | 154 | val = g_strdup_printf("%lu", (long unsigned int) node_data->intval); |
| 144 | break; | 155 | break; |
| 145 | 156 | ||
| 146 | case PLIST_REAL: | 157 | case PLIST_REAL: |
| 147 | tag = "real"; | 158 | tag = XPLIST_REAL; |
| 148 | val = g_strdup_printf("%Lf", (long double) node_data->realval); | 159 | val = g_strdup_printf("%Lf", (long double) node_data->realval); |
| 149 | break; | 160 | break; |
| 150 | 161 | ||
| 151 | case PLIST_STRING: | 162 | case PLIST_STRING: |
| 152 | tag = "string"; | 163 | tag = XPLIST_STRING; |
| 153 | val = g_strdup(node_data->strval); | 164 | val = g_strdup(node_data->strval); |
| 154 | break; | 165 | break; |
| 155 | 166 | ||
| 156 | case PLIST_UNICODE: | 167 | case PLIST_UNICODE: |
| 157 | tag = "string"; | 168 | tag = XPLIST_STRING; |
| 158 | val = g_strdup((gchar *) node_data->unicodeval); | 169 | val = g_strdup((gchar *) node_data->unicodeval); |
| 159 | break; | 170 | break; |
| 160 | 171 | ||
| 161 | case PLIST_KEY: | 172 | case PLIST_KEY: |
| 162 | tag = "key"; | 173 | tag = XPLIST_KEY; |
| 163 | val = g_strdup((gchar *) node_data->strval); | 174 | val = g_strdup((gchar *) node_data->strval); |
| 164 | break; | 175 | break; |
| 165 | 176 | ||
| 166 | case PLIST_DATA: | 177 | case PLIST_DATA: |
| 167 | tag = "data"; | 178 | tag = XPLIST_DATA; |
| 168 | gchar *valtmp = g_base64_encode(node_data->buff, node_data->length); | 179 | gchar *valtmp = g_base64_encode(node_data->buff, node_data->length); |
| 169 | val = format_string(valtmp, 68, xstruct->depth); | 180 | val = format_string(valtmp, 68, xstruct->depth); |
| 170 | g_free(valtmp); | 181 | g_free(valtmp); |
| 171 | break; | 182 | break; |
| 172 | case PLIST_ARRAY: | 183 | case PLIST_ARRAY: |
| 173 | tag = "array"; | 184 | tag = XPLIST_ARRAY; |
| 174 | isStruct = TRUE; | 185 | isStruct = TRUE; |
| 175 | break; | 186 | break; |
| 176 | case PLIST_DICT: | 187 | case PLIST_DICT: |
| 177 | tag = "dict"; | 188 | tag = XPLIST_DICT; |
| 178 | isStruct = TRUE; | 189 | isStruct = TRUE; |
| 179 | break; | 190 | break; |
| 180 | case PLIST_DATE: //TODO : handle date tag | 191 | case PLIST_DATE: //TODO : handle date tag |
| @@ -182,17 +193,17 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 182 | break; | 193 | break; |
| 183 | } | 194 | } |
| 184 | 195 | ||
| 185 | int i = 0; | 196 | uint32_t i = 0; |
| 186 | for (i = 0; i < xstruct->depth; i++) { | 197 | for (i = 0; i < xstruct->depth; i++) { |
| 187 | xmlNodeAddContent(xstruct->xml, "\t"); | 198 | xmlNodeAddContent(xstruct->xml, BAD_CAST("\t")); |
| 188 | } | 199 | } |
| 189 | child_node = xmlNewChild(xstruct->xml, NULL, tag, val); | 200 | child_node = xmlNewChild(xstruct->xml, NULL, tag, BAD_CAST(val)); |
| 190 | xmlNodeAddContent(xstruct->xml, "\n"); | 201 | xmlNodeAddContent(xstruct->xml, BAD_CAST("\n")); |
| 191 | g_free(val); | 202 | g_free(val); |
| 192 | 203 | ||
| 193 | //add return for structured types | 204 | //add return for structured types |
| 194 | if (node_data->type == PLIST_ARRAY || node_data->type == PLIST_DICT) | 205 | if (node_data->type == PLIST_ARRAY || node_data->type == PLIST_DICT) |
| 195 | xmlNodeAddContent(child_node, "\n"); | 206 | xmlNodeAddContent(child_node, BAD_CAST("\n")); |
| 196 | 207 | ||
| 197 | if (isStruct) { | 208 | if (isStruct) { |
| 198 | struct xml_node child = { child_node, xstruct->depth + 1 }; | 209 | struct xml_node child = { child_node, xstruct->depth + 1 }; |
| @@ -202,20 +213,20 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 202 | if (node_data->type == PLIST_ARRAY || node_data->type == PLIST_DICT) { | 213 | if (node_data->type == PLIST_ARRAY || node_data->type == PLIST_DICT) { |
| 203 | 214 | ||
| 204 | for (i = 0; i < xstruct->depth; i++) { | 215 | for (i = 0; i < xstruct->depth; i++) { |
| 205 | xmlNodeAddContent(child_node, "\t"); | 216 | xmlNodeAddContent(child_node, BAD_CAST("\t")); |
| 206 | } | 217 | } |
| 207 | } | 218 | } |
| 208 | 219 | ||
| 209 | return; | 220 | return; |
| 210 | } | 221 | } |
| 211 | 222 | ||
| 212 | void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | 223 | static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) |
| 213 | { | 224 | { |
| 214 | xmlNodePtr node = NULL; | 225 | xmlNodePtr node = NULL; |
| 215 | 226 | ||
| 216 | for (node = xml_node->children; node; node = node->next) { | 227 | for (node = xml_node->children; node; node = node->next) { |
| 217 | 228 | ||
| 218 | while (node && !xmlStrcmp(node->name, "text")) | 229 | while (node && !xmlStrcmp(node->name, XPLIST_TEXT)) |
| 219 | node = node->next; | 230 | node = node->next; |
| 220 | if (!node) | 231 | if (!node) |
| 221 | break; | 232 | break; |
| @@ -227,68 +238,68 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 227 | else | 238 | else |
| 228 | *plist_node = subnode; | 239 | *plist_node = subnode; |
| 229 | 240 | ||
| 230 | if (!xmlStrcmp(node->name, "true")) { | 241 | if (!xmlStrcmp(node->name, XPLIST_TRUE)) { |
| 231 | data->boolval = 1; | 242 | data->boolval = TRUE; |
| 232 | data->type = PLIST_BOOLEAN; | 243 | data->type = PLIST_BOOLEAN; |
| 233 | data->length = 1; | 244 | data->length = 1; |
| 234 | continue; | 245 | continue; |
| 235 | } | 246 | } |
| 236 | 247 | ||
| 237 | if (!xmlStrcmp(node->name, "false")) { | 248 | if (!xmlStrcmp(node->name, XPLIST_FALSE)) { |
| 238 | data->boolval = 0; | 249 | data->boolval = FALSE; |
| 239 | data->type = PLIST_BOOLEAN; | 250 | data->type = PLIST_BOOLEAN; |
| 240 | data->length = 1; | 251 | data->length = 1; |
| 241 | continue; | 252 | continue; |
| 242 | } | 253 | } |
| 243 | 254 | ||
| 244 | if (!xmlStrcmp(node->name, "integer")) { | 255 | if (!xmlStrcmp(node->name, XPLIST_INT)) { |
| 245 | char *strval = xmlNodeGetContent(node); | 256 | char *strval = (char*)xmlNodeGetContent(node); |
| 246 | data->intval = g_ascii_strtoull(strval, NULL, 0); | 257 | data->intval = g_ascii_strtoull(strval, NULL, 0); |
| 247 | data->type = PLIST_UINT; | 258 | data->type = PLIST_UINT; |
| 248 | data->length = 8; | 259 | data->length = 8; |
| 249 | continue; | 260 | continue; |
| 250 | } | 261 | } |
| 251 | 262 | ||
| 252 | if (!xmlStrcmp(node->name, "real")) { | 263 | if (!xmlStrcmp(node->name, XPLIST_REAL)) { |
| 253 | char *strval = xmlNodeGetContent(node); | 264 | char *strval = (char*)xmlNodeGetContent(node); |
| 254 | data->realval = atof(strval); | 265 | data->realval = atof(strval); |
| 255 | data->type = PLIST_REAL; | 266 | data->type = PLIST_REAL; |
| 256 | data->length = 8; | 267 | data->length = 8; |
| 257 | continue; | 268 | continue; |
| 258 | } | 269 | } |
| 259 | 270 | ||
| 260 | if (!xmlStrcmp(node->name, "date")) | 271 | if (!xmlStrcmp(node->name, XPLIST_DATE)) |
| 261 | continue; //TODO : handle date tag | 272 | continue; //TODO : handle date tag |
| 262 | 273 | ||
| 263 | if (!xmlStrcmp(node->name, "string")) { | 274 | if (!xmlStrcmp(node->name, XPLIST_STRING)) { |
| 264 | data->strval = strdup(xmlNodeGetContent(node)); | 275 | data->strval = strdup( (char*) xmlNodeGetContent(node)); |
| 265 | data->type = PLIST_STRING; | 276 | data->type = PLIST_STRING; |
| 266 | data->length = strlen(data->strval); | 277 | data->length = strlen(data->strval); |
| 267 | continue; | 278 | continue; |
| 268 | } | 279 | } |
| 269 | 280 | ||
| 270 | if (!xmlStrcmp(node->name, "key")) { | 281 | if (!xmlStrcmp(node->name, XPLIST_KEY)) { |
| 271 | data->strval = strdup(xmlNodeGetContent(node)); | 282 | data->strval = strdup( (char*) xmlNodeGetContent(node)); |
| 272 | data->type = PLIST_KEY; | 283 | data->type = PLIST_KEY; |
| 273 | data->length = strlen(data->strval); | 284 | data->length = strlen(data->strval); |
| 274 | continue; | 285 | continue; |
| 275 | } | 286 | } |
| 276 | 287 | ||
| 277 | if (!xmlStrcmp(node->name, "data")) { | 288 | if (!xmlStrcmp(node->name, XPLIST_DATA)) { |
| 278 | gsize size = 0; | 289 | gsize size = 0; |
| 279 | data->buff = g_base64_decode(xmlNodeGetContent(node), &size); | 290 | data->buff = g_base64_decode((char*)xmlNodeGetContent(node), &size); |
| 280 | data->length = size; | 291 | data->length = size; |
| 281 | data->type = PLIST_DATA; | 292 | data->type = PLIST_DATA; |
| 282 | continue; | 293 | continue; |
| 283 | } | 294 | } |
| 284 | 295 | ||
| 285 | if (!xmlStrcmp(node->name, "array")) { | 296 | if (!xmlStrcmp(node->name, XPLIST_ARRAY)) { |
| 286 | data->type = PLIST_ARRAY; | 297 | data->type = PLIST_ARRAY; |
| 287 | xml_to_node(node, &subnode); | 298 | xml_to_node(node, &subnode); |
| 288 | continue; | 299 | continue; |
| 289 | } | 300 | } |
| 290 | 301 | ||
| 291 | if (!xmlStrcmp(node->name, "dict")) { | 302 | if (!xmlStrcmp(node->name, XPLIST_DICT)) { |
| 292 | data->type = PLIST_DICT; | 303 | data->type = PLIST_DICT; |
| 293 | xml_to_node(node, &subnode); | 304 | xml_to_node(node, &subnode); |
| 294 | continue; | 305 | continue; |
| @@ -306,7 +317,11 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) | |||
| 306 | 317 | ||
| 307 | node_to_xml(plist, &root); | 318 | node_to_xml(plist, &root); |
| 308 | 319 | ||
| 309 | xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, length); | 320 | int size = 0; |
| 321 | xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, &size); | ||
| 322 | if (size >=0 ) | ||
| 323 | *length = size; | ||
| 324 | free_plist(plist_doc); | ||
| 310 | } | 325 | } |
| 311 | 326 | ||
| 312 | void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist) | 327 | void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist) |
