diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp index a08bffd68..e52387d50 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp +++ b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp @@ -19,23 +19,6 @@ #include "CTPP2VMStringLoader.hpp" -#include "ctpp2/CTPP2Util.hpp" -#include "ctpp2/CTPP2Exception.hpp" -#include "ctpp2/CTPP2VMExecutable.hpp" -#include "ctpp2/CTPP2VMInstruction.hpp" -#include "ctpp2/CTPP2VMMemoryCore.hpp" - -#include -#include - -#include -#include -#include - -#include -#include -#include - namespace CTPP // C++ Template Engine { diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp index 05b34d04d..7220133ae 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp +++ b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp @@ -21,6 +21,22 @@ #define _CTPP2_VM_STRING_LOADER_HPP__ 1 #include "ctpp2/CTPP2VMLoader.hpp" +#include "ctpp2/CTPP2Util.hpp" +#include "ctpp2/CTPP2Exception.hpp" +#include "ctpp2/CTPP2VMExecutable.hpp" +#include "ctpp2/CTPP2VMInstruction.hpp" +#include "ctpp2/CTPP2VMMemoryCore.hpp" + +#include +#include + +#include +#include +#include + +#include +#include +#include /** @file VMStringLoader.hpp diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 2036d0c75..be99bdbe4 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -375,11 +375,21 @@ namespace kiwix { return this->getContentByEncodedUrl(url, content, contentLength, contentType); } + bool Reader::getContentByEncodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType, string &baseUrl) { + return this->getContentByDecodedUrl(kiwix::urlDecode(url), content, contentLength, contentType, baseUrl); + } + bool Reader::getContentByEncodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType) { - return this->getContentByDecodedUrl(kiwix::urlDecode(url), content, contentLength, contentType); + std::string stubRedirectUrl; + return this->getContentByEncodedUrl(kiwix::urlDecode(url), content, contentLength, contentType, stubRedirectUrl); } bool Reader::getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType) { + std::string stubRedirectUrl; + return this->getContentByDecodedUrl(kiwix::urlDecode(url), content, contentLength, contentType, stubRedirectUrl); + } + + bool Reader::getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType, string &baseUrl) { bool retVal = false; content=""; contentType=""; @@ -411,6 +421,9 @@ namespace kiwix { article = article.getRedirectArticle(); } + /* Compute base url (might be different from the url if redirects */ + baseUrl = "/" + std::string(1, article.getNamespace()) + "/" + article.getUrl(); + /* Get the content mime-type */ contentType = string(article.getMimeType().data(), article.getMimeType().size()); diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index b140fe5bf..f35cfc0b0 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -62,7 +62,9 @@ namespace kiwix { bool getFavicon(string &content, string &mimeType); bool getPageUrlFromTitle(const string &title, string &url); bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); + bool getContentByEncodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType, string &baseUrl); bool getContentByEncodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); + bool getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType, string &baseUrl); bool getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); bool searchSuggestions(const string &prefix, unsigned int suggestionsCount, const bool reset = true); bool searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount);