Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #314 from kiwix/trust_library #314

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions include/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Manager
* updated content.
* @return True if file has been properly parsed.
*/
bool readFile(const std::string& path, const bool readOnly = true);
bool readFile(const std::string& path, bool readOnly = true, bool trustLibrary = true);

/**
* Load a library content store in the string.
Expand All @@ -87,7 +87,8 @@ class Manager
*/
bool readXml(const std::string& xml,
const bool readOnly = true,
const std::string& libraryPath = "");
const std::string& libraryPath = "",
bool trustLibrary = true);

/**
* Load a library content stored in a OPDS stream.
Expand Down Expand Up @@ -154,8 +155,9 @@ class Manager

bool readBookFromPath(const std::string& path, Book* book);
bool parseXmlDom(const pugi::xml_document& doc,
const bool readOnly,
const std::string& libraryPath);
bool readOnly,
const std::string& libraryPath,
bool trustLibrary);
bool parseOpdsDom(const pugi::xml_document& doc,
const std::string& urlHost);

Expand Down
1 change: 1 addition & 0 deletions src/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir)
path = computeAbsolutePath(baseDir, path);
}
m_path = path;
m_pathValid = fileExists(path);
m_title = ATTR("title");
m_description = ATTR("description");
m_language = ATTR("language");
Expand Down
27 changes: 14 additions & 13 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ Manager::~Manager()
}
}
bool Manager::parseXmlDom(const pugi::xml_document& doc,
const bool readOnly,
const std::string& libraryPath)
bool readOnly,
const std::string& libraryPath,
bool trustLibrary)
{
pugi::xml_node libraryNode = doc.child("library");

Expand All @@ -63,12 +64,8 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
book.updateFromXml(bookNode,
removeLastPathElement(libraryPath));

/* Update the book properties with the new importer */
if (libraryVersion.empty()
|| atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) {
if (!book.getPath().empty()) {
this->readBookFromPath(book.getPath(), &book);
}
if (!trustLibrary && !book.getPath().empty()) {
this->readBookFromPath(book.getPath(), &book);
}
manipulator->addBookToLibrary(book);
}
Expand All @@ -77,15 +74,16 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
}

bool Manager::readXml(const std::string& xml,
const bool readOnly,
const std::string& libraryPath)
bool readOnly,
const std::string& libraryPath,
bool trustLibrary)
{
pugi::xml_document doc;
pugi::xml_parse_result result
= doc.load_buffer_inplace((void*)xml.data(), xml.size());

if (result) {
this->parseXmlDom(doc, readOnly, libraryPath);
this->parseXmlDom(doc, readOnly, libraryPath, trustLibrary);
}

return true;
Expand Down Expand Up @@ -136,7 +134,10 @@ bool Manager::readOpds(const std::string& content, const std::string& urlHost)
return false;
}

bool Manager::readFile(const std::string& path, const bool readOnly)
bool Manager::readFile(
const std::string& path,
bool readOnly,
bool trustLibrary)
{
bool retVal = true;
pugi::xml_document doc;
Expand All @@ -148,7 +149,7 @@ bool Manager::readFile(const std::string& path, const bool readOnly)
#endif

if (result) {
this->parseXmlDom(doc, readOnly, path);
this->parseXmlDom(doc, readOnly, path, trustLibrary);
} else {
retVal = false;
}
Expand Down