+ better default page loading

This commit is contained in:
kelson42 2011-12-22 11:54:19 +00:00
parent fb1d0893e3
commit d0d08c4f96
2 changed files with 45 additions and 42 deletions

View File

@ -216,14 +216,7 @@ namespace kiwix {
return url; return url;
} }
/* Get a content from a zim file */ bool Reader::parseUrl(const string &urlStr, char *ns, string &titleStr) {
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
bool retVal = false;
content="";
contentType="";
contentLength = 0;
if (this->zimFileHandler != NULL) {
const char *url = urlStr.c_str(); const char *url = urlStr.c_str();
/* Offset to visit the url */ /* Offset to visit the url */
@ -234,14 +227,10 @@ namespace kiwix {
while ((offset < urlLength) && (url[offset] == '/')) offset++; while ((offset < urlLength) && (url[offset] == '/')) offset++;
/* Get namespace */ /* Get namespace */
char ns[1024];
unsigned int nsOffset = 0;
while ((offset < urlLength) && (url[offset] != '/')) { while ((offset < urlLength) && (url[offset] != '/')) {
ns[nsOffset] = url[offset]; *ns= url[offset];
offset++; offset++;
nsOffset++;
} }
ns[nsOffset] = 0;
/* Ignore the '/' */ /* Ignore the '/' */
while ((offset < urlLength) && (url[offset] == '/')) offset++; while ((offset < urlLength) && (url[offset] == '/')) offset++;
@ -257,20 +246,33 @@ namespace kiwix {
title[titleOffset] = 0; title[titleOffset] = 0;
/* unescape url */ /* unescape url */
string titleStr = string(title); titleStr = string(title);
unescapeUrl(titleStr); unescapeUrl(titleStr);
/* Main page */ return true;
if (titleStr == "" && strcmp(ns, "") == 0) {
if (zimFileHandler->getFileheader().hasMainPage()) {
zim::Article article = zimFileHandler->getArticle(zimFileHandler->getFileheader().getMainPage());
ns[0] = article.getNamespace();
titleStr = article.getUrl();
} }
/* Get a content from a zim file */
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
bool retVal = false;
content="";
contentType="";
contentLength = 0;
if (this->zimFileHandler != NULL) {
/* Parse the url */
char ns = 0;
string titleStr;
this->parseUrl(urlStr, &ns, titleStr);
/* Main page */
if (titleStr.empty() && ns == 0) {
this->parseUrl(this->getMainPageUrl(), &ns, titleStr);
} }
/* 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) {

View File

@ -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;