diff options
| author | 2009-02-09 20:39:14 +0100 | |
|---|---|---|
| committer | 2009-02-09 21:02:56 +0100 | |
| commit | fa4a22dde897c0e2a8cc89b7479f0513c9455d37 (patch) | |
| tree | 877b0140a133fb34c821ff70bde1a4a8c6ef5ab1 /src/xplist.c | |
| parent | ff1fa73f33e9223e69cbb71e70b084e3482dce3f (diff) | |
| download | libplist-fa4a22dde897c0e2a8cc89b7479f0513c9455d37.tar.gz libplist-fa4a22dde897c0e2a8cc89b7479f0513c9455d37.tar.bz2 | |
Make it compile on MSVC 2005.
Diffstat (limited to 'src/xplist.c')
| -rw-r--r-- | src/xplist.c | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/src/xplist.c b/src/xplist.c index 20b2795..b404e79 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -102,7 +102,7 @@ struct xml_node { | |||
| 102 | static xmlDocPtr new_xml_plist() | 102 | static xmlDocPtr new_xml_plist() |
| 103 | { | 103 | { |
| 104 | char *plist = strdup(plist_base); | 104 | char *plist = strdup(plist_base); |
| 105 | xmlDocPtr plist_xml = xmlReadMemory(plist, strlen(plist), NULL, NULL, 0); | 105 | xmlDocPtr plist_xml = xmlParseMemory(plist, strlen(plist)); |
| 106 | 106 | ||
| 107 | if (!plist_xml) | 107 | if (!plist_xml) |
| 108 | return NULL; | 108 | return NULL; |
| @@ -126,11 +126,8 @@ static void free_plist(xmlDocPtr plist) | |||
| 126 | 126 | ||
| 127 | static void node_to_xml(GNode * node, gpointer xml_struct) | 127 | static void node_to_xml(GNode * node, gpointer xml_struct) |
| 128 | { | 128 | { |
| 129 | if (!node) | 129 | struct xml_node *xstruct = NULL; |
| 130 | return; | 130 | plist_data_t node_data = NULL; |
| 131 | |||
| 132 | struct xml_node *xstruct = (struct xml_node *) xml_struct; | ||
| 133 | plist_data_t node_data = plist_get_data(node); | ||
| 134 | 131 | ||
| 135 | xmlNodePtr child_node = NULL; | 132 | xmlNodePtr child_node = NULL; |
| 136 | char isStruct = FALSE; | 133 | char isStruct = FALSE; |
| @@ -138,12 +135,23 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 138 | const xmlChar *tag = NULL; | 135 | const xmlChar *tag = NULL; |
| 139 | gchar *val = NULL; | 136 | gchar *val = NULL; |
| 140 | 137 | ||
| 138 | //for base64 | ||
| 139 | gchar *valtmp = NULL; | ||
| 140 | |||
| 141 | //for unicode | 141 | //for unicode |
| 142 | glong len = 0; | 142 | glong len = 0; |
| 143 | glong items_read = 0; | 143 | glong items_read = 0; |
| 144 | glong items_written = 0; | 144 | glong items_written = 0; |
| 145 | GError *error = NULL; | 145 | GError *error = NULL; |
| 146 | 146 | ||
| 147 | uint32_t i = 0; | ||
| 148 | |||
| 149 | if (!node) | ||
| 150 | return; | ||
| 151 | |||
| 152 | xstruct = (struct xml_node *) xml_struct; | ||
| 153 | node_data = plist_get_data(node); | ||
| 154 | |||
| 147 | switch (node_data->type) { | 155 | switch (node_data->type) { |
| 148 | case PLIST_BOOLEAN: | 156 | case PLIST_BOOLEAN: |
| 149 | { | 157 | { |
| @@ -182,7 +190,7 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 182 | 190 | ||
| 183 | case PLIST_DATA: | 191 | case PLIST_DATA: |
| 184 | tag = XPLIST_DATA; | 192 | tag = XPLIST_DATA; |
| 185 | gchar *valtmp = g_base64_encode(node_data->buff, node_data->length); | 193 | valtmp = g_base64_encode(node_data->buff, node_data->length); |
| 186 | val = format_string(valtmp, 60, xstruct->depth); | 194 | val = format_string(valtmp, 60, xstruct->depth); |
| 187 | g_free(valtmp); | 195 | g_free(valtmp); |
| 188 | break; | 196 | break; |
| @@ -202,7 +210,6 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 202 | break; | 210 | break; |
| 203 | } | 211 | } |
| 204 | 212 | ||
| 205 | uint32_t i = 0; | ||
| 206 | for (i = 0; i < xstruct->depth; i++) { | 213 | for (i = 0; i < xstruct->depth; i++) { |
| 207 | xmlNodeAddContent(xstruct->xml, BAD_CAST("\t")); | 214 | xmlNodeAddContent(xstruct->xml, BAD_CAST("\t")); |
| 208 | } | 215 | } |
| @@ -232,6 +239,16 @@ static void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 232 | static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | 239 | static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) |
| 233 | { | 240 | { |
| 234 | xmlNodePtr node = NULL; | 241 | xmlNodePtr node = NULL; |
| 242 | plist_data_t data = NULL; | ||
| 243 | plist_t subnode = NULL; | ||
| 244 | |||
| 245 | //for string | ||
| 246 | unsigned char *tmp = NULL; | ||
| 247 | glong len = 0; | ||
| 248 | glong items_read = 0; | ||
| 249 | glong items_written = 0; | ||
| 250 | GError *error = NULL; | ||
| 251 | int type = 0; | ||
| 235 | 252 | ||
| 236 | if (!xml_node) | 253 | if (!xml_node) |
| 237 | return; | 254 | return; |
| @@ -243,8 +260,8 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 243 | if (!node) | 260 | if (!node) |
| 244 | break; | 261 | break; |
| 245 | 262 | ||
| 246 | plist_data_t data = plist_new_plist_data(); | 263 | data = plist_new_plist_data(); |
| 247 | plist_t subnode = plist_new_node(data); | 264 | subnode = plist_new_node(data); |
| 248 | if (*plist_node) | 265 | if (*plist_node) |
| 249 | g_node_append(*plist_node, subnode); | 266 | g_node_append(*plist_node, subnode); |
| 250 | else | 267 | else |
| @@ -289,12 +306,12 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 289 | 306 | ||
| 290 | if (!xmlStrcmp(node->name, XPLIST_STRING)) { | 307 | if (!xmlStrcmp(node->name, XPLIST_STRING)) { |
| 291 | 308 | ||
| 292 | unsigned char *tmp = xmlNodeGetContent(node); | 309 | tmp = xmlNodeGetContent(node); |
| 293 | glong len = strlen((char *) tmp); | 310 | len = strlen((char *) tmp); |
| 294 | glong items_read = 0; | 311 | items_read = 0; |
| 295 | glong items_written = 0; | 312 | items_written = 0; |
| 296 | GError *error = NULL; | 313 | error = NULL; |
| 297 | int type = xmlDetectCharEncoding(tmp, len); | 314 | type = xmlDetectCharEncoding(tmp, len); |
| 298 | 315 | ||
| 299 | if (XML_CHAR_ENCODING_UTF8 == type) { | 316 | if (XML_CHAR_ENCODING_UTF8 == type) { |
| 300 | data->unicodeval = g_utf8_to_utf16((char *) tmp, len, &items_read, &items_written, &error); | 317 | data->unicodeval = g_utf8_to_utf16((char *) tmp, len, &items_read, &items_written, &error); |
| @@ -339,15 +356,19 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 339 | 356 | ||
| 340 | void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) | 357 | void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) |
| 341 | { | 358 | { |
| 359 | xmlDocPtr plist_doc = NULL; | ||
| 360 | xmlNodePtr root_node = NULL; | ||
| 361 | struct xml_node root = { NULL, 0 }; | ||
| 362 | int size = 0; | ||
| 363 | |||
| 342 | if (!plist || !plist_xml || *plist_xml) | 364 | if (!plist || !plist_xml || *plist_xml) |
| 343 | return; | 365 | return; |
| 344 | xmlDocPtr plist_doc = new_xml_plist(); | 366 | plist_doc = new_xml_plist(); |
| 345 | xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); | 367 | root_node = xmlDocGetRootElement(plist_doc); |
| 346 | struct xml_node root = { root_node, 0 }; | 368 | root.xml = root_node; |
| 347 | 369 | ||
| 348 | node_to_xml(plist, &root); | 370 | node_to_xml(plist, &root); |
| 349 | 371 | ||
| 350 | int size = 0; | ||
| 351 | xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, &size); | 372 | xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, &size); |
| 352 | if (size >= 0) | 373 | if (size >= 0) |
| 353 | *length = size; | 374 | *length = size; |
| @@ -356,7 +377,7 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) | |||
| 356 | 377 | ||
| 357 | void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist) | 378 | void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist) |
| 358 | { | 379 | { |
| 359 | xmlDocPtr plist_doc = xmlReadMemory(plist_xml, length, NULL, NULL, 0); | 380 | xmlDocPtr plist_doc = xmlParseMemory(plist_xml, length); |
| 360 | xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); | 381 | xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); |
| 361 | 382 | ||
| 362 | xml_to_node(root_node, plist); | 383 | xml_to_node(root_node, plist); |
