mirror of https://github.com/kiwix/libkiwix.git
+ better default page loading
This commit is contained in:
parent
fb1d0893e3
commit
d0d08c4f96
|
@ -216,6 +216,42 @@ namespace kiwix {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Reader::parseUrl(const string &urlStr, char *ns, string &titleStr) {
|
||||||
|
const char *url = urlStr.c_str();
|
||||||
|
|
||||||
|
/* Offset to visit the url */
|
||||||
|
unsigned int urlLength = strlen(url);
|
||||||
|
unsigned int offset = 0;
|
||||||
|
|
||||||
|
/* Ignore the '/' */
|
||||||
|
while ((offset < urlLength) && (url[offset] == '/')) offset++;
|
||||||
|
|
||||||
|
/* Get namespace */
|
||||||
|
while ((offset < urlLength) && (url[offset] != '/')) {
|
||||||
|
*ns= url[offset];
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ignore the '/' */
|
||||||
|
while ((offset < urlLength) && (url[offset] == '/')) offset++;
|
||||||
|
|
||||||
|
/* Get content title */
|
||||||
|
char title[1024];
|
||||||
|
unsigned int titleOffset = 0;
|
||||||
|
while (offset < urlLength) {
|
||||||
|
title[titleOffset] = url[offset];
|
||||||
|
offset++;
|
||||||
|
titleOffset++;
|
||||||
|
}
|
||||||
|
title[titleOffset] = 0;
|
||||||
|
|
||||||
|
/* unescape url */
|
||||||
|
titleStr = string(title);
|
||||||
|
unescapeUrl(titleStr);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get a content from a zim file */
|
/* Get a content from a zim file */
|
||||||
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
|
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
|
@ -224,53 +260,19 @@ namespace kiwix {
|
||||||
contentLength = 0;
|
contentLength = 0;
|
||||||
|
|
||||||
if (this->zimFileHandler != NULL) {
|
if (this->zimFileHandler != NULL) {
|
||||||
const char *url = urlStr.c_str();
|
|
||||||
|
|
||||||
/* Offset to visit the url */
|
|
||||||
unsigned int urlLength = strlen(url);
|
|
||||||
unsigned int offset = 0;
|
|
||||||
|
|
||||||
/* Ignore the '/' */
|
|
||||||
while ((offset < urlLength) && (url[offset] == '/')) offset++;
|
|
||||||
|
|
||||||
/* Get namespace */
|
|
||||||
char ns[1024];
|
|
||||||
unsigned int nsOffset = 0;
|
|
||||||
while ((offset < urlLength) && (url[offset] != '/')) {
|
|
||||||
ns[nsOffset] = url[offset];
|
|
||||||
offset++;
|
|
||||||
nsOffset++;
|
|
||||||
}
|
|
||||||
ns[nsOffset] = 0;
|
|
||||||
|
|
||||||
/* Ignore the '/' */
|
|
||||||
while ((offset < urlLength) && (url[offset] == '/')) offset++;
|
|
||||||
|
|
||||||
/* Get content title */
|
|
||||||
char title[1024];
|
|
||||||
unsigned int titleOffset = 0;
|
|
||||||
while (offset < urlLength) {
|
|
||||||
title[titleOffset] = url[offset];
|
|
||||||
offset++;
|
|
||||||
titleOffset++;
|
|
||||||
}
|
|
||||||
title[titleOffset] = 0;
|
|
||||||
|
|
||||||
/* unescape url */
|
|
||||||
string titleStr = string(title);
|
|
||||||
unescapeUrl(titleStr);
|
|
||||||
|
|
||||||
|
/* Parse the url */
|
||||||
|
char ns = 0;
|
||||||
|
string titleStr;
|
||||||
|
this->parseUrl(urlStr, &ns, titleStr);
|
||||||
|
|
||||||
/* Main page */
|
/* Main page */
|
||||||
if (titleStr == "" && strcmp(ns, "") == 0) {
|
if (titleStr.empty() && ns == 0) {
|
||||||
if (zimFileHandler->getFileheader().hasMainPage()) {
|
this->parseUrl(this->getMainPageUrl(), &ns, titleStr);
|
||||||
zim::Article article = zimFileHandler->getArticle(zimFileHandler->getFileheader().getMainPage());
|
|
||||||
ns[0] = article.getNamespace();
|
|
||||||
titleStr = article.getUrl();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the content from the zim file */
|
/* Extract the content from the zim file */
|
||||||
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns[0], titleStr);
|
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns, titleStr);
|
||||||
|
|
||||||
/* Test if the article was found */
|
/* Test if the article was found */
|
||||||
if (resultPair.first == true) {
|
if (resultPair.first == true) {
|
||||||
|
|
|
@ -59,6 +59,7 @@ namespace kiwix {
|
||||||
bool getNextSuggestion(string &title);
|
bool getNextSuggestion(string &title);
|
||||||
bool canCheckIntegrity();
|
bool canCheckIntegrity();
|
||||||
bool isCorrupted();
|
bool isCorrupted();
|
||||||
|
bool parseUrl(const string &urlStr, char *ns, string &titleStr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
zim::File* zimFileHandler;
|
zim::File* zimFileHandler;
|
||||||
|
|
Loading…
Reference in New Issue