+ kiwix-server uses now kiwix::Reader

This commit is contained in:
kelson42 2010-01-20 20:01:44 +00:00
parent fb2dfdd677
commit c9778c9097
1 changed files with 47 additions and 46 deletions

View File

@ -5,17 +5,14 @@ namespace kiwix {
/* Constructor */ /* Constructor */
Reader::Reader(const string &zimFilePath) Reader::Reader(const string &zimFilePath)
: zimFileHandler(NULL) { : zimFileHandler(NULL) {
try { this->zimFileHandler = new zim::File(zimFilePath);
this->zimFileHandler = new zim::File(zimFilePath);
if (this->zimFileHandler != NULL) {
if (this->zimFileHandler != NULL) { this->firstArticleOffset = this->zimFileHandler->getNamespaceBeginOffset('A');
this->firstArticleOffset = this->zimFileHandler->getNamespaceBeginOffset('A'); this->lastArticleOffset = this->zimFileHandler->getNamespaceEndOffset('A');
this->lastArticleOffset = this->zimFileHandler->getNamespaceEndOffset('A'); this->currentArticleOffset = this->firstArticleOffset;
this->currentArticleOffset = this->firstArticleOffset; this->articleCount = this->zimFileHandler->getNamespaceCount('A');
this->articleCount = this->zimFileHandler->getNamespaceCount('A');
}
} catch(...) {
} }
} }
@ -66,7 +63,6 @@ string Reader::getMainPageUrl() {
/* Get a content from a zim file */ /* Get a content from a zim file */
bool Reader::getContent(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) { bool Reader::getContent(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
bool retVal = false; bool retVal = false;
const char *url = urlStr.c_str(); const char *url = urlStr.c_str();
@ -100,41 +96,46 @@ string Reader::getMainPageUrl() {
} }
title[titleOffset] = 0; title[titleOffset] = 0;
/* Extract the content from the zim file */ /* Main page */
try { if (strcmp(title, "") == 0 && strcmp(ns, "") == 0) {
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns[0], title); if (zimFileHandler->getFileheader().hasMainPage()) {
zim::Article article = zimFileHandler->getArticle(zimFileHandler->getFileheader().getMainPage());
/* Test if the article was found */ ns[0] = article.getNamespace();
if (resultPair.first == true) { strcpy(title, article.getUrl().c_str());
/* Get the article */
zim::Article article = zimFileHandler->getArticle(resultPair.second.getIndex());
/* If redirect */
unsigned int loopCounter = 0;
while (article.isRedirect() && loopCounter++<42) {
article = article.getRedirectArticle();
}
/* Get the content mime-type */
contentType = string(article.getMimeType().data(), article.getMimeType().size());
/* Get the data */
content = string(article.getData().data(), article.getArticleSize());
/* Get the data length */
contentLength = article.getArticleSize();
/* Set return value */
retVal = true;
} else {
/* The found article is not the good one */
content="";
contentType="";
contentLength = 0;
retVal = false;
} }
} catch(...) { }
/* Extract the content from the zim file */
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns[0], title);
/* Test if the article was found */
if (resultPair.first == true) {
/* Get the article */
zim::Article article = zimFileHandler->getArticle(resultPair.second.getIndex());
/* If redirect */
unsigned int loopCounter = 0;
while (article.isRedirect() && loopCounter++<42) {
article = article.getRedirectArticle();
}
/* Get the content mime-type */
contentType = string(article.getMimeType().data(), article.getMimeType().size());
/* Get the data */
content = string(article.getData().data(), article.getArticleSize());
/* Get the data length */
contentLength = article.getArticleSize();
/* Set return value */
retVal = true;
} else {
/* The found article is not the good one */
content="";
contentType="";
contentLength = 0;
retVal = false; retVal = false;
} }