aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-24 02:56:26 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-24 02:56:26 +0200
commit9c237e1537238ebe95289ed6df82f6d43c482944 (patch)
tree30d26083790cdf789532c40c531f29bf0d9c5f6c
parent6248b63041d8d5e8ae5b15fe58ccde897b3cfb6e (diff)
downloadEpisodeBrowser-9c237e1537238ebe95289ed6df82f6d43c482944.tar.gz
Fix bug in ParsedDoc.
The parser context wants its own buffer, apparently. (The documentation is a little ... sub-par.)
-rw-r--r--c/data.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/c/data.cpp b/c/data.cpp
index 7c0fcb7..7722cd0 100644
--- a/c/data.cpp
+++ b/c/data.cpp
@@ -25,37 +25,39 @@ using XmlXPathObjectPtr = Managed<xmlXPathObjectPtr, xmlXPathFreeObject, XmlErro
static inline void XmlFree(void* p) { xmlFree(p); }
using XmlCharPtr = Managed<xmlChar*, XmlFree, XmlError>;
+using InternetHandle = Managed<HINTERNET, InternetCloseHandle, InternetError>;
+static InternetHandle s_hi = InternetOpen(L"Episode Browser", INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0);
+
struct ParsedDoc
{
- using InternetHandle = Managed<HINTERNET, InternetCloseHandle, InternetError>;
using HtmlParserCtxtPtr = Managed<htmlParserCtxtPtr, xmlFreeParserCtxt, XmlError>;
using HtmlDocPtr = Managed<htmlDocPtr, xmlFreeDoc, XmlError>;
- InternetHandle hi;
InternetHandle hiUrl;
HtmlParserCtxtPtr ctxt;
- char buf[1024];
+ char bufI[1024];
+ char bufX[1024];
ParsedDoc(const wchar_t* wszUrl, const char* szUrl)
- : hi(InternetOpen(L"Episode Browser", INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0)),
- hiUrl(InternetOpenUrl(hi, wszUrl, nullptr, 0, INTERNET_FLAG_NO_UI, 0)),
- ctxt(htmlCreatePushParserCtxt(nullptr, nullptr, buf, sizeof(buf), szUrl, XML_CHAR_ENCODING_UTF8))
+ : hiUrl(InternetOpenUrl(s_hi, wszUrl, nullptr, 0, INTERNET_FLAG_NO_UI, 0)),
+ ctxt(htmlCreatePushParserCtxt(nullptr, nullptr, bufX, sizeof(bufX), szUrl, XML_CHAR_ENCODING_UTF8))
{
htmlCtxtUseOptions(ctxt, HTML_PARSE_RECOVER|HTML_PARSE_NOERROR|HTML_PARSE_NOWARNING);
BOOL r;
DWORD cbRead;
- while (r = InternetReadFile(hiUrl, buf, sizeof(buf), &cbRead), cbRead) {
+ while (r = InternetReadFile(hiUrl, bufI, sizeof(bufI), &cbRead), cbRead) {
if (!r)
throw InternetError();
- if (!htmlParseChunk(ctxt, buf, cbRead, 0))
+ if (!htmlParseChunk(ctxt, bufI, cbRead, 0))
throw XmlError();
}
- htmlParseChunk(ctxt, buf, 0, 1); /* Stop parsing. */
+ htmlParseChunk(ctxt, bufI, 0, 1); /* Stop parsing. */
}
operator htmlDocPtr() { return ctxt->myDoc; }
};
+
template <size_t N>
bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8) noexcept
{