From ea04fbb22cd1e7aca222f500117b1c40edc24421 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 29 Dec 2010 01:59:41 +0000 Subject: [PATCH] support CDATA in xml parser --- ChangeLog | 1 + include/libtorrent/xml_parse.hpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68c4b23e7..b6f33ce03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * supporr CDATA tags in xml parser * use a python python dictionary for settings instead of session_settings object (in python bindings) * optimized metadata transfer (magnet link) startup time (shaved off about 1 second) * optimized swarm startup time (shaved off about 1 second) diff --git a/include/libtorrent/xml_parse.hpp b/include/libtorrent/xml_parse.hpp index 087a12e02..07ac2402a 100644 --- a/include/libtorrent/xml_parse.hpp +++ b/include/libtorrent/xml_parse.hpp @@ -80,7 +80,30 @@ namespace libtorrent if (p == end) break; // skip '<' - ++p; + ++p; + if (p != end && p+8 < end && string_begins_no_case("![CDATA[", p)) + { + // CDATA. match '![CDATA[' + p += 8; + start = p; + while (p != end && !string_begins_no_case("]]>", p-2)) ++p; + + // parse error + if (p == end) + { + token = xml_parse_error; + start = "unexpected end of file"; + callback(token, start, val_start); + break; + } + + token = xml_string; + char tmp = p[-2]; + p[-2] = 0; + callback(token, start, val_start); + p[-2] = tmp; + continue; + } // parse the name of the tag. for (start = p; p != end && *p != '>' && !isspace(*p); ++p); @@ -202,7 +225,6 @@ namespace libtorrent *i = save; } } - } }