summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/xplist.c b/src/xplist.c
index 4833a92..66e1dba 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -133,7 +133,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
133 return len; 133 return len;
134} 134}
135 135
136static int node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth) 136static plist_err_t node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth)
137{ 137{
138 plist_data_t node_data = NULL; 138 plist_data_t node_data = NULL;
139 139
@@ -366,7 +366,7 @@ static int node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth)
366 } 366 }
367 node_t ch; 367 node_t ch;
368 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 368 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
369 int res = node_to_xml(ch, outbuf, depth+1); 369 plist_err_t res = node_to_xml(ch, outbuf, depth+1);
370 if (res < 0) return res; 370 if (res < 0) return res;
371 } 371 }
372 372
@@ -444,7 +444,7 @@ static int num_digits_u(uint64_t i)
444 return n; 444 return n;
445} 445}
446 446
447static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth) 447static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
448{ 448{
449 plist_data_t data; 449 plist_data_t data;
450 if (!node) { 450 if (!node) {
@@ -532,13 +532,13 @@ static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
532plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) 532plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
533{ 533{
534 uint64_t size = 0; 534 uint64_t size = 0;
535 int res; 535 plist_err_t res;
536 536
537 if (!plist || !plist_xml || !length) { 537 if (!plist || !plist_xml || !length) {
538 return PLIST_ERR_INVALID_ARG; 538 return PLIST_ERR_INVALID_ARG;
539 } 539 }
540 540
541 res = node_estimate_size(plist, &size, 0); 541 res = node_estimate_size((node_t)plist, &size, 0);
542 if (res < 0) { 542 if (res < 0) {
543 return res; 543 return res;
544 } 544 }
@@ -552,7 +552,7 @@ plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
552 552
553 str_buf_append(outbuf, XML_PLIST_PROLOG, sizeof(XML_PLIST_PROLOG)-1); 553 str_buf_append(outbuf, XML_PLIST_PROLOG, sizeof(XML_PLIST_PROLOG)-1);
554 554
555 res = node_to_xml(plist, &outbuf, 0); 555 res = node_to_xml((node_t)plist, &outbuf, 0);
556 if (res < 0) { 556 if (res < 0) {
557 str_buf_free(outbuf); 557 str_buf_free(outbuf);
558 *plist_xml = NULL; 558 *plist_xml = NULL;
@@ -562,7 +562,7 @@ plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
562 562
563 str_buf_append(outbuf, XML_PLIST_EPILOG, sizeof(XML_PLIST_EPILOG)); 563 str_buf_append(outbuf, XML_PLIST_EPILOG, sizeof(XML_PLIST_EPILOG));
564 564
565 *plist_xml = outbuf->data; 565 *plist_xml = (char*)outbuf->data;
566 *length = outbuf->len - 1; 566 *length = outbuf->len - 1;
567 567
568 outbuf->data = NULL; 568 outbuf->data = NULL;
@@ -671,14 +671,14 @@ static void text_parts_free(text_part_t *tp)
671{ 671{
672 while (tp) { 672 while (tp) {
673 text_part_t *tmp = tp; 673 text_part_t *tmp = tp;
674 tp = tp->next; 674 tp = (text_part_t*)tp->next;
675 free(tmp); 675 free(tmp);
676 } 676 }
677} 677}
678 678
679static text_part_t* text_part_append(text_part_t* parts, const char *begin, size_t length, int is_cdata) 679static text_part_t* text_part_append(text_part_t* parts, const char *begin, size_t length, int is_cdata)
680{ 680{
681 text_part_t* newpart = malloc(sizeof(text_part_t)); 681 text_part_t* newpart = (text_part_t*)malloc(sizeof(text_part_t));
682 assert(newpart); 682 assert(newpart);
683 parts->next = text_part_init(newpart, begin, length, is_cdata); 683 parts->next = text_part_init(newpart, begin, length, is_cdata);
684 return newpart; 684 return newpart;
@@ -930,9 +930,9 @@ static char* text_parts_get_content(text_part_t *tp, int unesc_entities, size_t
930 text_part_t *tmp = tp; 930 text_part_t *tmp = tp;
931 while (tp && tp->begin) { 931 while (tp && tp->begin) {
932 total_length += tp->length; 932 total_length += tp->length;
933 tp = tp->next; 933 tp = (text_part_t*)tp->next;
934 } 934 }
935 str = malloc(total_length + 1); 935 str = (char*)malloc(total_length + 1);
936 assert(str); 936 assert(str);
937 p = str; 937 p = str;
938 tp = tmp; 938 tp = tmp;
@@ -947,7 +947,7 @@ static char* text_parts_get_content(text_part_t *tp, int unesc_entities, size_t
947 } 947 }
948 } 948 }
949 p += len; 949 p += len;
950 tp = tp->next; 950 tp = (text_part_t*)tp->next;
951 } 951 }
952 *p = '\0'; 952 *p = '\0';
953 if (length) { 953 if (length) {
@@ -959,7 +959,7 @@ static char* text_parts_get_content(text_part_t *tp, int unesc_entities, size_t
959 return str; 959 return str;
960} 960}
961 961
962static int node_from_xml(parse_ctx ctx, plist_t *plist) 962static plist_err_t node_from_xml(parse_ctx ctx, plist_t *plist)
963{ 963{
964 char *tag = NULL; 964 char *tag = NULL;
965 char *keyname = NULL; 965 char *keyname = NULL;
@@ -1067,7 +1067,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1067 goto err_out; 1067 goto err_out;
1068 } 1068 }
1069 int taglen = ctx->pos - p; 1069 int taglen = ctx->pos - p;
1070 tag = malloc(taglen + 1); 1070 tag = (char*)malloc(taglen + 1);
1071 strncpy(tag, p, taglen); 1071 strncpy(tag, p, taglen);
1072 tag[taglen] = '\0'; 1072 tag[taglen] = '\0';
1073 if (*ctx->pos != '>') { 1073 if (*ctx->pos != '>') {
@@ -1105,7 +1105,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1105 goto err_out; 1105 goto err_out;
1106 } 1106 }
1107 1107
1108 struct node_path_item *path_item = malloc(sizeof(struct node_path_item)); 1108 struct node_path_item *path_item = (struct node_path_item*)malloc(sizeof(struct node_path_item));
1109 if (!path_item) { 1109 if (!path_item) {
1110 PLIST_XML_ERR("out of memory when allocating node path item\n"); 1110 PLIST_XML_ERR("out of memory when allocating node path item\n");
1111 ctx->err++; 1111 ctx->err++;
@@ -1133,7 +1133,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1133 goto err_out; 1133 goto err_out;
1134 } 1134 }
1135 struct node_path_item *path_item = node_path; 1135 struct node_path_item *path_item = node_path;
1136 node_path = node_path->prev; 1136 node_path = (struct node_path_item*)node_path->prev;
1137 free(path_item); 1137 free(path_item);
1138 1138
1139 free(tag); 1139 free(tag);
@@ -1156,7 +1156,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1156 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part); 1156 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
1157 if (!tp) { 1157 if (!tp) {
1158 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag); 1158 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
1159 text_parts_free(first_part.next); 1159 text_parts_free((text_part_t*)first_part.next);
1160 ctx->err++; 1160 ctx->err++;
1161 goto err_out; 1161 goto err_out;
1162 } 1162 }
@@ -1165,7 +1165,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1165 char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free); 1165 char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free);
1166 if (!str_content) { 1166 if (!str_content) {
1167 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag); 1167 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
1168 text_parts_free(first_part.next); 1168 text_parts_free((text_part_t*)first_part.next);
1169 ctx->err++; 1169 ctx->err++;
1170 goto err_out; 1170 goto err_out;
1171 } 1171 }
@@ -1194,7 +1194,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1194 } else { 1194 } else {
1195 is_empty = 1; 1195 is_empty = 1;
1196 } 1196 }
1197 text_parts_free(tp->next); 1197 text_parts_free((text_part_t*)tp->next);
1198 } 1198 }
1199 if (is_empty) { 1199 if (is_empty) {
1200 data->intval = 0; 1200 data->intval = 0;
@@ -1207,7 +1207,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1207 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part); 1207 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
1208 if (!tp) { 1208 if (!tp) {
1209 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag); 1209 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
1210 text_parts_free(first_part.next); 1210 text_parts_free((text_part_t*)first_part.next);
1211 ctx->err++; 1211 ctx->err++;
1212 goto err_out; 1212 goto err_out;
1213 } 1213 }
@@ -1216,7 +1216,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1216 char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free); 1216 char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free);
1217 if (!str_content) { 1217 if (!str_content) {
1218 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag); 1218 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
1219 text_parts_free(first_part.next); 1219 text_parts_free((text_part_t*)first_part.next);
1220 ctx->err++; 1220 ctx->err++;
1221 goto err_out; 1221 goto err_out;
1222 } 1222 }
@@ -1225,7 +1225,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1225 free(str_content); 1225 free(str_content);
1226 } 1226 }
1227 } 1227 }
1228 text_parts_free(tp->next); 1228 text_parts_free((text_part_t*)tp->next);
1229 } 1229 }
1230 data->type = PLIST_REAL; 1230 data->type = PLIST_REAL;
1231 data->length = 8; 1231 data->length = 8;
@@ -1251,12 +1251,12 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1251 size_t length = 0; 1251 size_t length = 0;
1252 if (!tp) { 1252 if (!tp) {
1253 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag); 1253 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
1254 text_parts_free(first_part.next); 1254 text_parts_free((text_part_t*)first_part.next);
1255 ctx->err++; 1255 ctx->err++;
1256 goto err_out; 1256 goto err_out;
1257 } 1257 }
1258 str = text_parts_get_content(tp, 1, &length, NULL); 1258 str = text_parts_get_content(tp, 1, &length, NULL);
1259 text_parts_free(first_part.next); 1259 text_parts_free((text_part_t*)first_part.next);
1260 if (!str) { 1260 if (!str) {
1261 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag); 1261 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
1262 ctx->err++; 1262 ctx->err++;
@@ -1284,7 +1284,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1284 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part); 1284 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
1285 if (!tp) { 1285 if (!tp) {
1286 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag); 1286 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
1287 text_parts_free(first_part.next); 1287 text_parts_free((text_part_t*)first_part.next);
1288 ctx->err++; 1288 ctx->err++;
1289 goto err_out; 1289 goto err_out;
1290 } 1290 }
@@ -1293,7 +1293,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1293 char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free); 1293 char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free);
1294 if (!str_content) { 1294 if (!str_content) {
1295 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag); 1295 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
1296 text_parts_free(first_part.next); 1296 text_parts_free((text_part_t*)first_part.next);
1297 ctx->err++; 1297 ctx->err++;
1298 goto err_out; 1298 goto err_out;
1299 } 1299 }
@@ -1307,7 +1307,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1307 free(str_content); 1307 free(str_content);
1308 } 1308 }
1309 } 1309 }
1310 text_parts_free(tp->next); 1310 text_parts_free((text_part_t*)tp->next);
1311 } 1311 }
1312 data->type = PLIST_DATA; 1312 data->type = PLIST_DATA;
1313 } else if (!strcmp(tag, XPLIST_DATE)) { 1313 } else if (!strcmp(tag, XPLIST_DATE)) {
@@ -1316,7 +1316,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1316 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part); 1316 text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
1317 if (!tp) { 1317 if (!tp) {
1318 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag); 1318 PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
1319 text_parts_free(first_part.next); 1319 text_parts_free((text_part_t*)first_part.next);
1320 ctx->err++; 1320 ctx->err++;
1321 goto err_out; 1321 goto err_out;
1322 } 1322 }
@@ -1327,7 +1327,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1327 char *str_content = text_parts_get_content(tp, 0, &length, &requires_free); 1327 char *str_content = text_parts_get_content(tp, 0, &length, &requires_free);
1328 if (!str_content) { 1328 if (!str_content) {
1329 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag); 1329 PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
1330 text_parts_free(first_part.next); 1330 text_parts_free((text_part_t*)first_part.next);
1331 ctx->err++; 1331 ctx->err++;
1332 goto err_out; 1332 goto err_out;
1333 } 1333 }
@@ -1347,7 +1347,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1347 free(str_content); 1347 free(str_content);
1348 } 1348 }
1349 } 1349 }
1350 text_parts_free(tp->next); 1350 text_parts_free((text_part_t*)tp->next);
1351 data->realval = (double)(timev - MAC_EPOCH); 1351 data->realval = (double)(timev - MAC_EPOCH);
1352 } 1352 }
1353 data->length = sizeof(double); 1353 data->length = sizeof(double);
@@ -1391,7 +1391,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1391 } 1391 }
1392 } 1392 }
1393 if (!is_empty && (data->type == PLIST_DICT || data->type == PLIST_ARRAY)) { 1393 if (!is_empty && (data->type == PLIST_DICT || data->type == PLIST_ARRAY)) {
1394 struct node_path_item *path_item = malloc(sizeof(struct node_path_item)); 1394 struct node_path_item *path_item = (struct node_path_item*)malloc(sizeof(struct node_path_item));
1395 if (!path_item) { 1395 if (!path_item) {
1396 PLIST_XML_ERR("out of memory when allocating node path item\n"); 1396 PLIST_XML_ERR("out of memory when allocating node path item\n");
1397 ctx->err++; 1397 ctx->err++;
@@ -1416,7 +1416,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1416 goto err_out; 1416 goto err_out;
1417 } 1417 }
1418 struct node_path_item *path_item = node_path; 1418 struct node_path_item *path_item = node_path;
1419 node_path = node_path->prev; 1419 node_path = (struct node_path_item*)node_path->prev;
1420 free(path_item); 1420 free(path_item);
1421 1421
1422 parent = ((node_t)parent)->parent; 1422 parent = ((node_t)parent)->parent;
@@ -1447,7 +1447,7 @@ err_out:
1447 /* clean up node_path if required */ 1447 /* clean up node_path if required */
1448 while (node_path) { 1448 while (node_path) {
1449 struct node_path_item *path_item = node_path; 1449 struct node_path_item *path_item = node_path;
1450 node_path = path_item->prev; 1450 node_path = (struct node_path_item*)path_item->prev;
1451 free(path_item); 1451 free(path_item);
1452 } 1452 }
1453 1453