diff options
author | Nikias Bassen | 2017-01-03 22:49:39 +0100 |
---|---|---|
committer | Nikias Bassen | 2017-01-03 22:49:39 +0100 |
commit | bbd33793d62ef9c9dbd6f69aa2fd0ced1b163e2f (patch) | |
tree | 0176766b87bd4c60aff107e2b97fe2dfae567b67 | |
parent | 5b0184aa95f916dc1fc2d5948d0e8c655d998dd4 (diff) | |
download | libplist-bbd33793d62ef9c9dbd6f69aa2fd0ced1b163e2f.tar.gz libplist-bbd33793d62ef9c9dbd6f69aa2fd0ced1b163e2f.tar.bz2 |
xplist: Refine XML parsing error messages
-rw-r--r-- | src/xplist.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/xplist.c b/src/xplist.c index ff065a9..98d7375 100644 --- a/src/xplist.c +++ b/src/xplist.c @@ -589,14 +589,14 @@ static text_part_t* get_text_parts(parse_ctx ctx, const char* tag, size_t tag_le } else { p = ctx->pos; find_next(ctx, " \r\n\t>", 5, 1); - PLIST_XML_ERR("Invalid special tag '<[%.*s>' encountered inside '<%s>' tag\n", (int)(ctx->pos - p), p, tag); + PLIST_XML_ERR("Invalid special tag <[%.*s> encountered inside <%s> tag\n", (int)(ctx->pos - p), p, tag); ctx->err++; return NULL; } } else { p = ctx->pos; find_next(ctx, " \r\n\t>", 5, 1); - PLIST_XML_ERR("Invalid special tag '<!%.*s>' encountered inside '<%s>' tag\n", (int)(ctx->pos - p), p, tag); + PLIST_XML_ERR("Invalid special tag <!%.*s> encountered inside <%s> tag\n", (int)(ctx->pos - p), p, tag); ctx->err++; return NULL; } @@ -605,7 +605,7 @@ static text_part_t* get_text_parts(parse_ctx ctx, const char* tag, size_t tag_le } else { p = ctx->pos; find_next(ctx, " \r\n\t>", 5, 1); - PLIST_XML_ERR("Invalid tag '<%.*s>' encountered inside '<%s>' tag\n", (int)(ctx->pos - p), p, tag); + PLIST_XML_ERR("Invalid tag <%.*s> encountered inside <%s> tag\n", (int)(ctx->pos - p), p, tag); ctx->err++; return NULL; } @@ -788,16 +788,16 @@ static char* text_parts_get_content(text_part_t *tp, int unesc_entities, size_t static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) { char *keyname = NULL; + const char *p = NULL; while (ctx->pos < ctx->end && !ctx->err) { -#ifdef DEBUG - const char *start = ctx->pos; -#endif parse_skip_ws(ctx); if (ctx->pos >= ctx->end) { break; } if (*ctx->pos != '<') { - PLIST_XML_ERR("Failed to parse XML. Expected: opening tag, found: '%s', pos: %s\n", start, ctx->pos); + p = ctx->pos; + find_next(ctx, " \t\r\n", 4, 0); + PLIST_XML_ERR("Expected: opening tag, found: %.*s\n", (int)(ctx->pos - p), p); ctx->pos = ctx->end; ctx->err++; break; @@ -856,14 +856,16 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) ctx->pos += 2; } } else { - PLIST_XML_ERR("Unknown ! special tag encountered\n"); + p = ctx->pos; + find_next(ctx, " \r\n\t>", 5, 1); + PLIST_XML_ERR("Invalid special tag <%.*s> encountered\n", (int)(ctx->pos - p), p); ctx->err++; } continue; } else { int is_empty = 0; int closing_tag = 0; - const char *p = ctx->pos; + p = ctx->pos; find_next(ctx," \r\n\t<>", 6, 0); if (ctx->pos >= ctx->end) { PLIST_XML_ERR("Unexpected EOF while parsing XML\n"); @@ -888,7 +890,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) return; } if (*ctx->pos != '>') { - PLIST_XML_ERR("Missing '>' for tag '%s'\n", tag); + PLIST_XML_ERR("Missing '>' for tag <%s\n", tag); ctx->pos = ctx->end; ctx->err++; free(tag); @@ -905,6 +907,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) if (!strcmp(tag, "plist")) { free(tag); if (is_empty) { + PLIST_XML_ERR("Empty plist tag\n"); return; } if (!*plist) { @@ -920,7 +923,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) free(keyname); return; } else if (depth == 1 && *plist) { - PLIST_XML_ERR("Unexpected tag %s found while /plist is expected\n", tag); + PLIST_XML_ERR("Unexpected tag <%s> found while </plist> is expected\n", tag); ctx->err++; free(tag); free(keyname); @@ -1151,7 +1154,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) } else if (tag[0] == '/') { closing_tag = 1; } else { - PLIST_XML_ERR("Unexpected tag '<%s%s>' encountered while parsing XML\n", tag, (is_empty) ? "/" : ""); + PLIST_XML_ERR("Unexpected tag <%s%s> encountered\n", tag, (is_empty) ? "/" : ""); ctx->pos = ctx->end; ctx->err++; free(tag); @@ -1219,13 +1222,13 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) PLIST_XML_ERR("missing value node in dict\n"); ctx->err++; } else if (strcmp(tag+1, XPLIST_DICT) != 0) { - PLIST_XML_ERR("closing tag mismatch, expected: /%s found: %s\n", XPLIST_DICT, tag); + PLIST_XML_ERR("closing tag mismatch, expected: </%s> found: <%s>\n", XPLIST_DICT, tag); ctx->err++; } break; case PLIST_ARRAY: if (strcmp(tag+1, XPLIST_ARRAY) != 0) { - PLIST_XML_ERR("closing tag mismatch, expected: /%s found: %s\n", XPLIST_ARRAY, tag); + PLIST_XML_ERR("closing tag mismatch, expected: </%s> found: <%s>\n", XPLIST_ARRAY, tag); ctx->err++; } break; @@ -1246,7 +1249,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth) } } if (depth == 1) { - PLIST_XML_ERR("EOF while /plist tag is expected\n"); + PLIST_XML_ERR("EOF while </plist> tag is expected\n"); ctx->err++; } if (ctx->err) { |