mirror of https://github.com/kiwix/libkiwix.git
Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix
Conflicts: CHANGELOG
This commit is contained in:
commit
78db06e127
|
@ -376,6 +376,60 @@ namespace kiwix {
|
|||
return true;
|
||||
}
|
||||
|
||||
/* Return article by url */
|
||||
bool Reader::getArticleObjectByDecodedUrl(const string &url, zim::Article &article) {
|
||||
bool retVal = false;
|
||||
|
||||
if (this->zimFileHandler != NULL) {
|
||||
|
||||
/* Parse the url */
|
||||
char ns = 0;
|
||||
string titleStr;
|
||||
this->parseUrl(url, &ns, titleStr);
|
||||
|
||||
/* Main page */
|
||||
if (titleStr.empty() && ns == 0) {
|
||||
this->parseUrl(this->getMainPageUrl(), &ns, titleStr);
|
||||
}
|
||||
|
||||
/* Extract the content from the zim file */
|
||||
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns, titleStr);
|
||||
|
||||
/* Test if the article was found */
|
||||
if (resultPair.first == true) {
|
||||
article = zimFileHandler->getArticle(resultPair.second.getIndex());
|
||||
retVal = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/* Return the mimeType without the content */
|
||||
bool Reader::getMimeTypeByUrl(const string &url, string &mimeType) {
|
||||
bool retVal = false;
|
||||
|
||||
if (this->zimFileHandler != NULL) {
|
||||
|
||||
zim::Article article;
|
||||
if (this->getArticleObjectByDecodedUrl(url, article)) {
|
||||
try {
|
||||
mimeType = string(article.getMimeType().data(), article.getMimeType().size());
|
||||
} catch (exception &e) {
|
||||
cerr << "Unable to get the mimetype for "<< url << ":" << e.what() << endl;
|
||||
mimeType = "application/octet-stream";
|
||||
}
|
||||
retVal = true;
|
||||
} else {
|
||||
mimeType = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/* Get a content from a zim file */
|
||||
bool Reader::getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType) {
|
||||
return this->getContentByEncodedUrl(url, content, contentLength, contentType);
|
||||
|
@ -402,24 +456,8 @@ namespace kiwix {
|
|||
contentLength = 0;
|
||||
if (this->zimFileHandler != NULL) {
|
||||
|
||||
/* Parse the url */
|
||||
char ns = 0;
|
||||
string titleStr;
|
||||
this->parseUrl(url, &ns, titleStr);
|
||||
|
||||
/* Main page */
|
||||
if (titleStr.empty() && ns == 0) {
|
||||
this->parseUrl(this->getMainPageUrl(), &ns, titleStr);
|
||||
}
|
||||
|
||||
/* Extract the content from the zim file */
|
||||
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns, titleStr);
|
||||
|
||||
/* Test if the article was found */
|
||||
if (resultPair.first == true) {
|
||||
|
||||
/* Get the article */
|
||||
zim::Article article = zimFileHandler->getArticle(resultPair.second.getIndex());
|
||||
zim::Article article;
|
||||
if (this->getArticleObjectByDecodedUrl(url, article)) {
|
||||
|
||||
/* If redirect */
|
||||
unsigned int loopCounter = 0;
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace kiwix {
|
|||
string getOrigId();
|
||||
bool getFavicon(string &content, string &mimeType);
|
||||
bool getPageUrlFromTitle(const string &title, string &url);
|
||||
bool getMimeTypeByUrl(const string &url, string &mimeType);
|
||||
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);
|
||||
|
@ -89,7 +90,7 @@ namespace kiwix {
|
|||
|
||||
private:
|
||||
std::map<std::string, unsigned int> parseCounterMetadata();
|
||||
|
||||
bool getArticleObjectByDecodedUrl(const string &url, zim::Article &article);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ namespace kiwix {
|
|||
oData["pages"] = pagesCDT;
|
||||
|
||||
oData["count"] = kiwix::beautifyInteger(this->estimatedResultCount);
|
||||
oData["searchPattern"] = this->searchPattern;
|
||||
oData["searchPattern"] = kiwix::encodeDiples(this->searchPattern);
|
||||
oData["searchPatternEncoded"] = urlEncode(this->searchPattern);
|
||||
oData["resultStart"] = this->resultStart + 1;
|
||||
oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount ? this->estimatedResultCount : this->resultEnd);
|
||||
|
|
|
@ -104,6 +104,14 @@ void kiwix::stringReplacement(std::string& str, const std::string& oldStr, const
|
|||
}
|
||||
}
|
||||
|
||||
/* Encode string to avoid XSS attacks */
|
||||
std::string kiwix::encodeDiples(const std::string& str) {
|
||||
std::string result = str;
|
||||
kiwix::stringReplacement(result, "<", "<");
|
||||
kiwix::stringReplacement(result, ">", ">");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Urlencode
|
||||
//based on javascript encodeURIComponent()
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ namespace kiwix {
|
|||
void printStringInHexadecimal(const char *s);
|
||||
void printStringInHexadecimal(UnicodeString s);
|
||||
void stringReplacement(std::string& str, const std::string& oldStr, const std::string& newStr);
|
||||
std::string encodeDiples(const std::string& str);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue