aboutsummaryrefslogtreecommitdiff
path: root/c/data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/data.cpp')
-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
{