Permanant fix for bug651.

Kiwix manager class is back to original state, additional function for obtaining origID has been added to Kiwix::Reader class.
Kiwix-manage and Kiwix-serve back to normal.
This commit is contained in:
Kiran Mathew Koshy 2013-09-20 18:35:20 +05:30
parent 2f89926616
commit 14a4394f6d
4 changed files with 138 additions and 79 deletions

View File

@ -225,7 +225,7 @@ namespace kiwix {
/* Add a book to the library. Return empty string if failed, book id otherwise */
string Manager::addBookFromPathAndGetId(const string pathToOpen, const string pathToSave,
const string url, const bool checkMetaData, const string origId) {
const string url, const bool checkMetaData) {
kiwix::Book book;
if (this->readBookFromPath(pathToOpen, &book)) {
@ -239,7 +239,6 @@ namespace kiwix {
if (!checkMetaData ||
(checkMetaData && !book.title.empty() && !book.language.empty() && !book.date.empty())) {
book.url = url;
book.origID=origId;
library.addBook(book);
return book.id;
}
@ -249,8 +248,8 @@ namespace kiwix {
}
/* Wrapper over Manager::addBookFromPath which return a bool instead of a string */
bool Manager::addBookFromPath(const string pathToOpen, const string pathToSave, const string url, const bool checkMetaData, const string origId) {
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, checkMetaData, origId).empty());
bool Manager::addBookFromPath(const string pathToOpen, const string pathToSave, const string url, const bool checkMetaData) {
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, checkMetaData).empty());
}
bool Manager::readBookFromPath(const string path, kiwix::Book *book) {
@ -267,7 +266,7 @@ namespace kiwix {
book->creator = reader->getCreator();
book->publisher = reader->getPublisher();
book->title = reader->getTitle();
book->origID=reader->getOrigID();
std::ostringstream articleCountStream;
articleCountStream << reader->getArticleCount();
book->articleCount = articleCountStream.str();

View File

@ -56,9 +56,9 @@ namespace kiwix {
bool setBookIndex(const string id, const string path, const supportedIndexType type);
bool setBookPath(const string id, const string path);
string addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "",
const bool checkMetaData = false, const string origID="");
const bool checkMetaData = false);
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "",
const bool checkMetaData = false, const string origID="");
const bool checkMetaData = false);
Library cloneLibrary();
bool getBookById(const string id, Book &book);
bool getCurrentBook(Book &book);

View File

@ -19,6 +19,38 @@
#include "reader.h"
inline char hi(char v) {
char hex[] = "0123456789abcdef";
return hex[(v >> 4) & 0xf];
}
inline char lo(char v) {
char hex[] = "0123456789abcdef";
return hex[v & 0xf];
}
std::string hexUUID (std::string in) {
std::ostringstream out;
for (unsigned n = 0; n < 4; ++n)
out << hi(in[n]) << lo(in[n]);
out << '-';
for (unsigned n = 4; n < 6; ++n)
out << hi(in[n]) << lo(in[n]);
out << '-';
for (unsigned n = 6; n < 8; ++n)
out << hi(in[n]) << lo(in[n]);
out << '-';
for (unsigned n = 8; n < 10; ++n)
out << hi(in[n]) << lo(in[n]);
out << '-';
for (unsigned n = 10; n < 16; ++n)
out << hi(in[n]) << lo(in[n]);
std::string op=out.str();
return op;
}
static char charFromHex(std::string a) {
std::istringstream Blat (a);
int Z;
@ -289,6 +321,33 @@ namespace kiwix {
return value;
}
string Reader::getOrigID() {
string value;
this->getMetatag("startfileuid", value);
if(value.empty())
return "";
std::string id=value;
std::string origID;
std::string temp="";
unsigned int k=0;
char tempArray[16]="";
for(unsigned int i=0; i<id.size(); i++)
{
if(id[i]=='\n')
{
tempArray[k]= atoi(temp.c_str());
temp="";
k++;
}
else
{
temp+=id[i];
}
}
origID=hexUUID(tempArray);
return origID;
}
/* Return the first page URL */
string Reader::getFirstPageUrl() {
string url;

View File

@ -58,6 +58,7 @@ namespace kiwix {
string getDate();
string getCreator();
string getPublisher();
string getOrigID();
bool getFavicon(string &content, string &mimeType);
bool getPageUrlFromTitle(const string &title, string &url);
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);