summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c60
1 files changed, 41 insertions, 19 deletions
diff --git a/src/bplist.c b/src/bplist.c
index 2a82b9f..6b2d2f3 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -24,6 +24,8 @@
24#include <stdio.h> 24#include <stdio.h>
25#include <string.h> 25#include <string.h>
26 26
27#include <libxml/tree.h>
28
27#include <plist/plist.h> 29#include <plist/plist.h>
28#include "plist.h" 30#include "plist.h"
29 31
@@ -184,13 +186,28 @@ static plist_t parse_unicode_node(char *bnode, uint64_t size)
184{ 186{
185 plist_data_t data = plist_new_plist_data(); 187 plist_data_t data = plist_new_plist_data();
186 uint64_t i = 0; 188 uint64_t i = 0;
187 data->type = PLIST_UNICODE; 189 gunichar2 *unicodestr = NULL;
188 data->unicodeval = (gunichar2 *) malloc(sizeof(gunichar2) * (size + 1)); 190 gchar *tmpstr = NULL;
189 memcpy(data->unicodeval, bnode, sizeof(gunichar2) * size); 191 int type = 0;
190 data->unicodeval[sizeof(gunichar2) * size] = '\0'; 192 glong items_read = 0;
191 data->length = size; 193 glong items_written = 0;
192 for (i = 0; i <= size; i++) 194 GError *error = NULL;
193 byte_convert((uint8_t*)(data->unicodeval + i), sizeof(gunichar2)); 195
196 data->type = PLIST_STRING;
197 unicodestr = (gunichar2 *) malloc(sizeof(gunichar2) * size);
198 memcpy(unicodestr, bnode, sizeof(gunichar2) * size);
199 for (i = 0; i < size; i++)
200 byte_convert((uint8_t*)(unicodestr + i), sizeof(gunichar2));
201
202 tmpstr = g_utf16_to_utf8(unicodestr, size, &items_read, &items_written, &error);
203 free(unicodestr);
204
205 data->type = PLIST_STRING;
206 data->strval = (char *) malloc(sizeof(char) * (items_written + 1));
207 memcpy(data->strval, tmpstr, items_written);
208 data->strval[items_written] = '\0';
209 data->length = strlen(data->strval);
210 g_free(tmpstr);
194 return g_node_new(data); 211 return g_node_new(data);
195} 212}
196 213
@@ -364,10 +381,6 @@ static gpointer copy_plist_data(gconstpointer src, gpointer data)
364 case PLIST_STRING: 381 case PLIST_STRING:
365 dstdata->strval = strdup(srcdata->strval); 382 dstdata->strval = strdup(srcdata->strval);
366 break; 383 break;
367 case PLIST_UNICODE:
368 dstdata->unicodeval = (gunichar2 *) malloc(srcdata->length * sizeof(gunichar2));
369 memcpy(dstdata->unicodeval, srcdata->unicodeval, srcdata->length * sizeof(gunichar2));
370 break;
371 case PLIST_DATA: 384 case PLIST_DATA:
372 case PLIST_ARRAY: 385 case PLIST_ARRAY:
373 dstdata->buff = (uint8_t *) malloc(sizeof(uint8_t *) * srcdata->length); 386 dstdata->buff = (uint8_t *) malloc(sizeof(uint8_t *) * srcdata->length);
@@ -520,10 +533,6 @@ static guint plist_data_hash(gconstpointer key)
520 buff = data->strval; 533 buff = data->strval;
521 size = strlen(buff); 534 size = strlen(buff);
522 break; 535 break;
523 case PLIST_UNICODE:
524 buff = (char *) data->unicodeval;
525 size = data->length;
526 break;
527 case PLIST_DATA: 536 case PLIST_DATA:
528 case PLIST_ARRAY: 537 case PLIST_ARRAY:
529 case PLIST_DICT: 538 case PLIST_DICT:
@@ -752,6 +761,13 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
752 uint64_t *offsets = NULL; 761 uint64_t *offsets = NULL;
753 uint8_t pad[6] = { 0, 0, 0, 0, 0, 0 }; 762 uint8_t pad[6] = { 0, 0, 0, 0, 0, 0 };
754 uint8_t trailer[BPLIST_TRL_SIZE]; 763 uint8_t trailer[BPLIST_TRL_SIZE];
764 //for string
765 glong len = 0;
766 int type = 0;
767 glong items_read = 0;
768 glong items_written = 0;
769 GError *error = NULL;
770 gunichar2 *unicodestr = NULL;
755 771
756 //check for valid input 772 //check for valid input
757 if (!plist || !plist_bin || *plist_bin || !length) 773 if (!plist || !plist_bin || *plist_bin || !length)
@@ -806,10 +822,16 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
806 822
807 case PLIST_KEY: 823 case PLIST_KEY:
808 case PLIST_STRING: 824 case PLIST_STRING:
809 write_string(bplist_buff, data->strval); 825 len = strlen(data->strval);
810 break; 826 type = xmlDetectCharEncoding(data->strval, len);
811 case PLIST_UNICODE: 827 if (XML_CHAR_ENCODING_UTF8 == type) {
812 write_unicode(bplist_buff, data->unicodeval, data->length); 828 unicodestr = g_utf8_to_utf16(data->strval, len, &items_read, &items_written, &error);
829 write_unicode(bplist_buff, unicodestr, items_written);
830 g_free(unicodestr);
831 }
832 else if (XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type) {
833 write_string(bplist_buff, data->strval);
834 }
813 break; 835 break;
814 case PLIST_DATA: 836 case PLIST_DATA:
815 write_data(bplist_buff, data->buff, data->length); 837 write_data(bplist_buff, data->buff, data->length);