Support large opds result listings without an OOM
This commit is contained in:
@@ -146,7 +146,6 @@ void OpdsParser::flush() {
|
||||
bool OpdsParser::error() const { return errorOccured; }
|
||||
|
||||
void OpdsParser::clear() {
|
||||
entries.clear();
|
||||
searchTemplate.clear();
|
||||
osdUrl.clear();
|
||||
nextPageUrl.clear();
|
||||
@@ -156,14 +155,6 @@ void OpdsParser::clear() {
|
||||
inEntry = inTitle = inAuthor = inAuthorName = inId = false;
|
||||
}
|
||||
|
||||
std::vector<OpdsEntry> OpdsParser::getBooks() const {
|
||||
std::vector<OpdsEntry> books;
|
||||
for (const auto& entry : entries) {
|
||||
if (entry.type == OpdsEntryType::BOOK) books.push_back(entry);
|
||||
}
|
||||
return books;
|
||||
}
|
||||
|
||||
const char* OpdsParser::findAttribute(const XML_Char** atts, const char* name) {
|
||||
for (int i = 0; atts[i]; i += 2) {
|
||||
if (strcmp(atts[i], name) == 0) return atts[i + 1];
|
||||
@@ -243,7 +234,7 @@ void XMLCALL OpdsParser::endElement(void* userData, const XML_Char* name) {
|
||||
|
||||
if (strcmp(name, "entry") == 0 || strstr(name, ":entry") != nullptr) {
|
||||
if (!self->currentEntry.title.empty() && !self->currentEntry.href.empty()) {
|
||||
self->entries.push_back(self->currentEntry);
|
||||
if (self->onEntryParsed) self->onEntryParsed(self->currentEntry);
|
||||
}
|
||||
self->inEntry = false;
|
||||
} else if (self->inEntry) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <Print.h>
|
||||
#include <expat.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -73,24 +74,13 @@ class OpdsParser final : public Print {
|
||||
|
||||
operator bool() { return !error(); }
|
||||
|
||||
/**
|
||||
* Get the parsed entries (both navigation and book entries).
|
||||
* @return Vector of OpdsEntry entries
|
||||
*/
|
||||
const std::vector<OpdsEntry>& getEntries() const& { return entries; }
|
||||
std::vector<OpdsEntry> getEntries() && { return std::move(entries); }
|
||||
|
||||
/**
|
||||
* Get only book entries (legacy compatibility).
|
||||
* @return Vector of book entries
|
||||
*/
|
||||
std::vector<OpdsEntry> getBooks() const;
|
||||
|
||||
/**
|
||||
* Clear all parsed entries.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
std::function<void(OpdsEntry)> onEntryParsed;
|
||||
|
||||
private:
|
||||
// Expat callbacks
|
||||
static void XMLCALL startElement(void* userData, const XML_Char* name, const XML_Char** atts);
|
||||
@@ -105,7 +95,6 @@ class OpdsParser final : public Print {
|
||||
static const char* findAttribute(const XML_Char** atts, const char* name);
|
||||
|
||||
XML_Parser parser = nullptr;
|
||||
std::vector<OpdsEntry> entries;
|
||||
OpdsEntry currentEntry;
|
||||
std::string currentText;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user