From 26b2e504f32daed80318b60ea37a5f5a520cb1ad Mon Sep 17 00:00:00 2001 From: rgaudin Date: Sun, 4 May 2014 20:11:48 +0000 Subject: [PATCH 1/5] fixed includes for CTPP2 --- src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp | 10 +++++----- src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp | 2 +- src/common/kiwix/searcher.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp index fa54c3ca0..a08bffd68 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp +++ b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp @@ -19,11 +19,11 @@ #include "CTPP2VMStringLoader.hpp" -#include "CTPP2Util.hpp" -#include "CTPP2Exception.hpp" -#include "CTPP2VMExecutable.hpp" -#include "CTPP2VMInstruction.hpp" -#include "CTPP2VMMemoryCore.hpp" +#include "ctpp2/CTPP2Util.hpp" +#include "ctpp2/CTPP2Exception.hpp" +#include "ctpp2/CTPP2VMExecutable.hpp" +#include "ctpp2/CTPP2VMInstruction.hpp" +#include "ctpp2/CTPP2VMMemoryCore.hpp" #include #include diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp index 665e31edb..05b34d04d 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp +++ b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp @@ -20,7 +20,7 @@ #ifndef _CTPP2_VM_STRING_LOADER_HPP__ #define _CTPP2_VM_STRING_LOADER_HPP__ 1 -#include "CTPP2VMLoader.hpp" +#include "ctpp2/CTPP2VMLoader.hpp" /** @file VMStringLoader.hpp diff --git a/src/common/kiwix/searcher.h b/src/common/kiwix/searcher.h index efe4167d0..3cf2c6cbb 100644 --- a/src/common/kiwix/searcher.h +++ b/src/common/kiwix/searcher.h @@ -32,9 +32,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "kiwix/ctpp2/CTPP2VMStringLoader.hpp" From 4e05d0dea6330a1f6217401c452c2df2dbbe8958 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 5 May 2014 14:14:11 +0200 Subject: [PATCH 2/5] Change CTPP2 #include paths (add 'ctpp2/') --- src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp | 17 ----------------- src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp | 18 +++++++++++++++++- src/common/kiwix/searcher.h | 6 +++--- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp index fa54c3ca0..e52387d50 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp +++ b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.cpp @@ -19,23 +19,6 @@ #include "CTPP2VMStringLoader.hpp" -#include "CTPP2Util.hpp" -#include "CTPP2Exception.hpp" -#include "CTPP2VMExecutable.hpp" -#include "CTPP2VMInstruction.hpp" -#include "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 665e31edb..7220133ae 100644 --- a/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp +++ b/src/common/kiwix/ctpp2/CTPP2VMStringLoader.hpp @@ -20,7 +20,23 @@ #ifndef _CTPP2_VM_STRING_LOADER_HPP__ #define _CTPP2_VM_STRING_LOADER_HPP__ 1 -#include "CTPP2VMLoader.hpp" +#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/searcher.h b/src/common/kiwix/searcher.h index efe4167d0..3cf2c6cbb 100644 --- a/src/common/kiwix/searcher.h +++ b/src/common/kiwix/searcher.h @@ -32,9 +32,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "kiwix/ctpp2/CTPP2VMStringLoader.hpp" From f1dc03d5aa3feb1f576d4b4b0afc2e244813135a Mon Sep 17 00:00:00 2001 From: rgaudin Date: Tue, 6 May 2014 08:08:23 +0000 Subject: [PATCH 3/5] removed duplicate type declaration on OSX (needed by c++11) --- src/common/componentTools.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/componentTools.h b/src/common/componentTools.h index a7b5c1e1a..692fc8926 100644 --- a/src/common/componentTools.h +++ b/src/common/componentTools.h @@ -24,10 +24,9 @@ #ifdef __APPLE__ #include - typedef uint16_t char16_t; #endif -#ifdef _WIN32 +#ifdef _WIN32 #include #endif From 005b75f7ab7bb9a15f3c2da9295045dcc3bd5c02 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 7 May 2014 16:08:43 +0200 Subject: [PATCH 4/5] + Introduction of base url in kiwix-serve (to handle relative urls in ZIM files) --- src/common/kiwix/reader.cpp | 8 ++++++++ src/common/kiwix/reader.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 2036d0c75..e6e7f2e42 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -380,6 +380,11 @@ namespace kiwix { } 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 +416,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..a63d55006 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -63,6 +63,7 @@ namespace kiwix { 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); + 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); From 587b76bf6d9ae2483abc82667a3614ee58c3f230 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 7 May 2014 17:33:38 +0200 Subject: [PATCH 5/5] + Fix deal with relative urls --- src/common/kiwix/reader.cpp | 7 ++++++- src/common/kiwix/reader.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index e6e7f2e42..be99bdbe4 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -375,8 +375,13 @@ 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) { diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index a63d55006..f35cfc0b0 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -62,6 +62,7 @@ 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);