Skip to content

Commit

Permalink
Merge pull request #314 from kiwix/trust_library
Browse files Browse the repository at this point in the history
Trust the library.xml information by default.
  • Loading branch information
mgautierfr authored Jan 30, 2020
2 parents 8f990fe + 34257cf commit d14ba0c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
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

0 comments on commit d14ba0c

Please sign in to comment.