diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 231ff37..e93c3ba 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include #include @@ -122,6 +124,23 @@ static void appendToFirstOccurence(string &content, const string regex, const st regfree(®exp); } +static char charFromHex(std::string a) { + std::istringstream Blat (a); + int Z; + Blat >> std::hex >> Z; + return char (Z); +} + +static void unescapeUrl(string &url) { + std::string::size_type pos; + std::string hex; + while (std::string::npos != (pos = url.find('%'))) { + hex = url.substr(pos + 1, 2); + url.replace(pos, 3, 1, charFromHex(hex)); + } + return; +} + static int accessHandlerCallback(void *cls, struct MHD_Connection * connection, const char * url, @@ -175,13 +194,17 @@ static int accessHandlerCallback(void *cls, } else { + /* urlstr */ + std::string urlStr = string(url); + unescapeUrl(urlStr); + /* Mutex Lock */ pthread_mutex_lock(&readerLock); /* Load the article from the ZIM file */ - cout << "Loading '" << url << "'... " << endl; + cout << "Loading '" << urlStr << "'... " << endl; try { - reader->getContent(url, content, contentLength, mimeType); + reader->getContent(urlStr, content, contentLength, mimeType); cout << "content size: " << contentLength << endl; cout << "mimeType: " << mimeType << endl; } catch (const std::exception& e) {