From 5f4c04e79e0f1b49aa7c7c688084b15e19ae4a41 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 2 Nov 2018 17:03:03 +0100 Subject: [PATCH 1/3] Fix use of getAsI when parsing download rpc. The value is store as a string in in the xml, so we cannot use getAsI. We have to get the string and parse it to an int. We cannot use strtoull because android stdc++ lib doesn't have it. We have to implement our how parseFromString function using a istringstream. --- include/common/stringTools.h | 8 ++++++++ src/downloader.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/common/stringTools.h b/include/common/stringTools.h index 1c8a29bf5..ad04dc1a2 100644 --- a/include/common/stringTools.h +++ b/include/common/stringTools.h @@ -71,5 +71,13 @@ std::string to_string(T value) oss << value; return oss.str(); } + +template +T extractFromString(const std::string& str) { + std::istringstream iss(str); + T ret; + iss >> ret; + return ret; +} } //namespace kiwix #endif diff --git a/src/downloader.cpp b/src/downloader.cpp index 2f9a70cd1..778ad3fb8 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -72,12 +72,12 @@ void Download::updateStatus(bool follow) } catch (InvalidRPCNode& e) { } } m_status = status; - m_totalLength = structNode.getMember("totalLength").getValue().getAsI(); - m_completedLength = structNode.getMember("completedLength").getValue().getAsI(); - m_downloadSpeed = structNode.getMember("downloadSpeed").getValue().getAsI(); + m_totalLength = extractFromString(structNode.getMember("totalLength").getValue().getAsS()); + m_completedLength = extractFromString(structNode.getMember("completedLength").getValue().getAsS()); + m_downloadSpeed = extractFromString(structNode.getMember("downloadSpeed").getValue().getAsS()); try { auto verifiedLengthValue = structNode.getMember("verifiedLength").getValue(); - m_verifiedLength = verifiedLengthValue.getAsI(); + m_verifiedLength = extractFromString(verifiedLengthValue.getAsS()); } catch (InvalidRPCNode& e) { m_verifiedLength = 0; } auto filesMember = structNode.getMember("files"); auto fileStruct = filesMember.getValue().getArray().getValue(0).getStruct(); From 9ab44e6a5f6f7f8ea2ead592da227c2f7bed2138 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 2 Nov 2018 17:04:55 +0100 Subject: [PATCH 2/3] Get information about the total number of book of a search. When we do a search and paging the result, we need to display to the user the total number of book, not only the `itemsPerPage`. So, we need to parse correctly the xml to keep information of the total number of book. --- include/manager.h | 5 ++++- src/manager.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/manager.h b/include/manager.h index 0e980b341..718bfb3a0 100644 --- a/include/manager.h +++ b/include/manager.h @@ -196,7 +196,10 @@ class Manager std::string writableLibraryPath; - std::vector bookIdList; + bool m_hasSearchResult = false; + uint64_t m_totalBooks = 0; + uint64_t m_startIndex = 0; + uint64_t m_itemsPerPage = 0; protected: kiwix::LibraryManipulator* manipulator; diff --git a/src/manager.cpp b/src/manager.cpp index 582d8ec49..4fb0637e2 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -95,6 +95,15 @@ bool Manager::parseOpdsDom(const pugi::xml_document& doc, const std::string& url { pugi::xml_node libraryNode = doc.child("feed"); + try { + m_totalBooks = strtoull(libraryNode.child("totalResults").child_value(), 0, 0); + m_startIndex = strtoull(libraryNode.child("startIndex").child_value(), 0, 0); + m_itemsPerPage = strtoull(libraryNode.child("itemsPerPage").child_value(), 0, 0); + m_hasSearchResult = true; + } catch(...) { + m_hasSearchResult = false; + } + for (pugi::xml_node entryNode = libraryNode.child("entry"); entryNode; entryNode = entryNode.next_sibling("entry")) { kiwix::Book book; From 4d904c4d8b87e96e5bc75259f0cd8716faa5da86 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 2 Nov 2018 17:10:05 +0100 Subject: [PATCH 3/3] New version 3.0.1 --- ChangeLog | 5 +++++ meson.build | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b813d196a..17afe53e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +kiwix-lib 3.0.1 +=============== + + * Small fix about parsing the opdsStream. + kiwix-lib 3.0.0 =============== diff --git a/meson.build b/meson.build index f621784ba..f696cccaa 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('kiwix-lib', 'cpp', - version : '3.0.0', + version : '3.0.1', license : 'GPL', default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true'])