From 87e9b562361a6fe5235e46c5986dc35f487a573f Mon Sep 17 00:00:00 2001 From: Kiran Mathew Koshy Date: Fri, 6 Sep 2013 04:09:35 +0530 Subject: [PATCH 01/10] Modified Kiwix-manage to incorporate origID parameter for diff files in the kiwix library. Book class and Manager class modified. -Kiran --- src/manager/kiwix-manage.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index 5f5b6d9..b0b323f 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -34,8 +34,8 @@ void show(kiwix::Library library) { std::vector::iterator itr; unsigned int inc = 1; for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) { - std::cout << "#" << inc++ - << std::endl << "id:\t\t" << itr->id + std::cout << "#" << inc++ + << std::endl << "id:\t\t" << itr->id << std::endl << "path:\t\t" << itr->path << std::endl << "url:\t\t" << itr->url << std::endl << "title:\t\t" << itr->title @@ -77,7 +77,7 @@ int main(int argc, char **argv) { else if (actionString == "remove" || actionString == "delete") action = REMOVE; } - + /* Print usage)) if necessary */ if (libraryPath == "" || action == NONE) { usage(); @@ -96,8 +96,9 @@ int main(int argc, char **argv) { string indexPath; kiwix::supportedIndexType indexBackend = kiwix::XAPIAN; string url; + string origID=""; bool setCurrent = false; - + if (argc>3) { zimPath = argv[3]; } @@ -105,25 +106,30 @@ int main(int argc, char **argv) { /* Options parsing */ optind = 2; while (42) { - + static struct option long_options[] = { {"url", required_argument, 0, 'u'}, + {"origId", required_argument, 0, 'o'}, {"indexPath", required_argument, 0, 'i'}, {"indexBackend", required_argument, 0, 'b'}, {"zimPathToSave", required_argument, 0, 'z'}, {"current", no_argument, 0, 'c'}, {0, 0, 0, 0} }; - - c = getopt_long(argc, argv, "cz:u:i:b:", long_options, &option_index); - + + c = getopt_long(argc, argv, "cz:u:o:i:b:", long_options, &option_index); + if (c != -1) { - + switch (c) { case 'u': url = optarg; break; + case 'o': + origID = optarg; + break; + case 'c': setCurrent = true; break; @@ -131,7 +137,7 @@ int main(int argc, char **argv) { case 'i': indexPath = optarg; break; - + case 'b': if (!strcmp(optarg, "clucene")) { indexBackend = kiwix::CLUCENE; @@ -141,7 +147,7 @@ int main(int argc, char **argv) { usage(); } break; - + case 'z': zimPathToSave = optarg; break; @@ -154,10 +160,10 @@ int main(int argc, char **argv) { if (zimPath != "") { zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave; - string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false); + string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url,origID, false); if (!bookId.empty()) { - + if (setCurrent) libraryManager.setCurrentBookId(bookId); From 50c6004204360701cf6bdfff3bb1da48c77750bd Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 11 Sep 2013 20:38:57 +0200 Subject: [PATCH 02/10] + useless --- src/contentManager/ContentManagerWrapper.cpp | 215 ------------- src/contentManager/ContentManagerWrapper.h | 52 ---- src/contentManager/Makefile | 21 -- src/contentManager/contentCTester.c | 137 --------- src/contentManager/contentManager.cpp | 303 ------------------- src/contentManager/contentManager.h | 37 --- src/contentManager/contentManagerTester.cpp | 143 --------- 7 files changed, 908 deletions(-) delete mode 100644 src/contentManager/ContentManagerWrapper.cpp delete mode 100644 src/contentManager/ContentManagerWrapper.h delete mode 100644 src/contentManager/Makefile delete mode 100644 src/contentManager/contentCTester.c delete mode 100644 src/contentManager/contentManager.cpp delete mode 100644 src/contentManager/contentManager.h delete mode 100644 src/contentManager/contentManagerTester.cpp diff --git a/src/contentManager/ContentManagerWrapper.cpp b/src/contentManager/ContentManagerWrapper.cpp deleted file mode 100644 index b3399f6..0000000 --- a/src/contentManager/ContentManagerWrapper.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include "ContentManagerWrapper.h" -#include "contentManager.h" - -/* creates instance of ContentManager */ -HCONTCLASS ContentManager_Create( void ) { - ContentManager * contentManager = new ContentManager(0); - - // Return its pointer (opaque) - return (HCONTCLASS)contentManager; -} - -/* Delete instance of ZimAccessor */ -void ContentManager_Destroy( HCONTCLASS h ) { - assert(h != NULL); - - // Convert from handle to ContentManager pointer - ContentManager * contentManager = (ContentManager *)h; - - delete contentManager; -} - -int ContentManager_OpenLibraryFromFile( HCONTCLASS h, char* path, int readOnly) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->OpenLibraryFromFile( string(path), readOnly ); -} - -int ContentManager_OpenLibraryFromText( HCONTCLASS h, char* xml, int readOnly) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string xml_str = string(xml); - return contentManager->OpenLibraryFromText( xml_str, readOnly ); -} - -int ContentManager_WriteLibrary( HCONTCLASS h) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->WriteLibrary(); -} - -int ContentManager_WriteLibraryToFile( HCONTCLASS h, char* path) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string path_str = string(path); - return contentManager->WriteLibraryToFile( path_str ); -} - -int ContentManager_AddBookFromPath( HCONTCLASS h, char* path) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string path_str = string(path); - return contentManager->AddBookFromPath( path_str ); -} - -int ContentManager_RemoveBookById( HCONTCLASS h, char* id) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - return contentManager->RemoveBookById( id_str ); -} - -int ContentManager_SetCurrentBookId( HCONTCLASS h, char* id) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - return contentManager->SetCurrentBookId( id_str ); -} - -const char* ContentManager_GetCurrentBookId( HCONTCLASS h ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = contentManager->GetCurrentBookId(); - return id_str.c_str(); -} - -CMBook ContentManager_GetBookById( HCONTCLASS h, char* id ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - CMBook book; - string path, title, indexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url; - string id_str = string(id); - - contentManager->GetBookById(id_str, path, title, indexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url); - book.path = path.c_str(); - book.title = title.c_str(); - book.indexPath = indexPath.c_str(); - book.indexType = indexType.c_str(); - book.description = description.c_str(); - book.articleCount = articleCount.c_str(); - book.mediaCount = mediaCount.c_str(); - book.size = size.c_str(); - book.creator = creator.c_str(); - book.date = date.c_str(); - book.language = language.c_str(); - book.favicon = favicon.c_str(); - book.url = url.c_str(); - return book; -} - -int ContentManager_UpdateBookLastOpenDateById( HCONTCLASS h, char* id) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - return contentManager->UpdateBookLastOpenDateById( id_str ); -} - -unsigned int ContentManager_GetBookCount( HCONTCLASS h, int remote, int local) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->GetBookCount( remote, local ); -} - -const char* ContentManager_GetListNextBookId( HCONTCLASS h) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->GetListNextBookId(); -} - -int ContentManager_SetBookIndex( HCONTCLASS h, char* id, char* path, char* type) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - string path_str = string(path); - string type_str = string(type); - return contentManager->SetBookIndex( id_str, path_str, type_str ); -} - -int ContentManager_SetBookPath( HCONTCLASS h, char* id, char* path) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - string path_str = string(path); - return contentManager->SetBookPath( id_str, path_str ); -} - -const char* ContentManager_GetBooksLanguages( HCONTCLASS h ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string languages = contentManager->GetBooksLanguages(); - return languages.c_str(); -} - -const char* ContentManager_GetBooksPublishers( HCONTCLASS h ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string publishers = contentManager->GetBooksPublishers(); - return publishers.c_str(); -} - -int ContentManager_ListBooks( HCONTCLASS h, char* mode, char* sortBy, unsigned int maxSize, char* language, char* publisher, char* search ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string mode_str = string(mode); - string sort_str = string(sortBy); - string lang_str = string(language); - string pub_str = string(publisher); - string search_str = string(search); - return contentManager->ListBooks( mode_str, sort_str, maxSize, lang_str, pub_str, search_str ); -} diff --git a/src/contentManager/ContentManagerWrapper.h b/src/contentManager/ContentManagerWrapper.h deleted file mode 100644 index 93ca57b..0000000 --- a/src/contentManager/ContentManagerWrapper.h +++ /dev/null @@ -1,52 +0,0 @@ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef void * HCONTCLASS; - -typedef struct { - const char* path; - const char* title; - const char* indexPath; - const char* indexType; - const char* description; - const char* articleCount; - const char* mediaCount; - const char* size; - const char* creator; - const char* date; - const char* language; - const char* favicon; - const char* url; -} CMBook; - -HCONTCLASS ContentManager_Create( void ); - -void ContentManager_Destroy( HCONTCLASS h ); - -int ContentManager_OpenLibraryFromFile( HCONTCLASS h, char* path, int readOnly ); -int ContentManager_OpenLibraryFromText( HCONTCLASS h, char* xml, int readOnly ); -int ContentManager_WriteLibrary( HCONTCLASS h ); -int ContentManager_WriteLibraryToFile( HCONTCLASS h, char* path ); -int ContentManager_AddBookFromPath( HCONTCLASS h, char* path ); -int ContentManager_RemoveBookById( HCONTCLASS h, char* id ); -int ContentManager_SetCurrentBookId( HCONTCLASS h, char* id ); -const char* ContentManager_GetCurrentBookId( HCONTCLASS h ); -CMBook ContentManager_GetBookById( HCONTCLASS h, char* id ); -int ContentManager_UpdateBookLastOpenDateById( HCONTCLASS h, char* id ); -unsigned int ContentManager_GetBookCount(HCONTCLASS h, int remote, int local ); -const char* ContentManager_GetListNextBookId( HCONTCLASS h ); -int ContentManager_SetBookIndex( HCONTCLASS h, char* id, char* path, char* type ); -int ContentManager_SetBookPath( HCONTCLASS h, char* id, char* path ); -const char* ContentManager_GetBooksLanguages( HCONTCLASS h ); -const char* ContentManager_GetBooksPublishers( HCONTCLASS h ); -int ContentManager_ListBooks( HCONTCLASS h, char* mode, char* sortBy, unsigned int maxSize, char* language, char* publisher, char* search ); - -#ifdef __cplusplus -}; -#endif diff --git a/src/contentManager/Makefile b/src/contentManager/Makefile deleted file mode 100644 index 4f4d27c..0000000 --- a/src/contentManager/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -all: contentTester - -wrapperlib: - g++ -shared ContentManagerWrapper.cpp -o libContentCManager.so contentManager.cpp ../common/kiwix/library.cpp ../common/kiwix/manager.cpp ../common/kiwix/reader.cpp ../common/base64.cpp ../common/pathTools.cpp ../common/componentTools.cpp ../common/regexTools.cpp ../common/kiwix/library.h ../common/kiwix/manager.h ../common/kiwix/reader.h ../pugixml/pugixml.hpp ../common/base64.h ../common/pathTools.h ../common/componentTools.h ../common/regexTools.h -I . -I ../common/ -I ../pugixml/ -I ../zimlib/include/ -I /usr/include/ -L ../zimlib/src/.libs/ -lzim ../pugixml/.libs/libpugixml.a ../dependences/xz/src/liblzma/.libs/liblzma.a - -contentTester: - g++ contentManagerTester.cpp contentManager.cpp ../common/kiwix/library.cpp ../common/kiwix/manager.cpp ../common/kiwix/reader.cpp ../common/base64.cpp ../common/pathTools.cpp ../common/componentTools.cpp ../common/regexTools.cpp ../common/kiwix/library.h ../common/kiwix/manager.h ../common/kiwix/reader.h ../pugixml/pugixml.hpp ../common/base64.h ../common/pathTools.h ../common/componentTools.h ../common/regexTools.h -o contentTester -I ../common/ -I ../pugixml/ -I ../zimlib/include/ -I /usr/include/ -L ../zimlib/src/.libs/ -lzim ../pugixml/.libs/libpugixml.a ../dependences/xz/src/liblzma/.libs/liblzma.a - -contentCTester: wrapperlib - gcc -o contentCTester contentCTester.c -I . -L . -lContentCManager -ldl -lm -L/usr/lib -licui18n -licuuc -licudata -ldl -lm - -cleanc: - find . -name 'contentCTester' -delete - -cleancpp: - find . -name 'contentTester' -delete - -clean: cleanc cleancpp - find . -name 'libContentCManager.so' -delete - find . -name '*.o' -delete diff --git a/src/contentManager/contentCTester.c b/src/contentManager/contentCTester.c deleted file mode 100644 index b69bf11..0000000 --- a/src/contentManager/contentCTester.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include "ContentManagerWrapper.h" - - -int main(int argc, char* argv[]) -{ - if (argc < 2) { - printf("Usage: %s zimPath\n", argv[0]); - printf("No ZIM file path provided.\n"); - exit(0); - } - char* zimPath = argv[1]; - printf("Content Manager C Tester.\nLoading %s...\n", zimPath); - - HCONTCLASS contM = NULL; - contM = ContentManager_Create(); - if (contM == NULL) { - printf("Error creating ContentManager class\n"); - exit(1); - } - - int readOnly = 1; - if (ContentManager_OpenLibraryFromFile( contM, zimPath, readOnly )) - printf("Successfully opened library from %s\n", zimPath); - else - printf("Unable to open library from %s\n", zimPath); - - char * xmltext = ""; - if (ContentManager_OpenLibraryFromText( contM, xmltext, readOnly )) - printf("Successfully opened library from text.\n"); - else - printf("Unable to open library from text.\n"); - - if (ContentManager_WriteLibrary( contM )) - printf("Successfully wrote library.\n"); - else - printf("Unable to write library\n"); - - char* libPath = "/tmp/totoc"; - if (ContentManager_WriteLibraryToFile( contM, libPath )) - printf("Successfully wrote library to %s\n", libPath); - else - printf("Unable to write library to %s\n", libPath); - - if (ContentManager_AddBookFromPath( contM, zimPath )) - printf("Successfully added book from %s\n", zimPath); - else - printf("Unable to add book from %s\n", zimPath); - - char* bookId = "57b0b7c3-25a5-431e-431e-dce1771ee052963f"; - if (ContentManager_SetCurrentBookId( contM, bookId )) - printf("Successfully set book %s\n", bookId); - else - printf("Unable to set book %s\n", bookId); - - const char* currBookId = ContentManager_GetCurrentBookId( contM ); - printf("Current Book: %s\n", currBookId); - - if (ContentManager_UpdateBookLastOpenDateById( contM, bookId )) - printf("Successfully updated last open date for book %s\n", bookId); - else - printf("Unable to update last open date for book %s\n", bookId); - - unsigned int bookCount = 0; - bookCount = ContentManager_GetBookCount( contM, 1, 1 ); - printf("Book count: %d\n", bookCount); - - char* indexPath = "/home/reg/wksw.index"; - char* indexType = "xapian"; - if (ContentManager_SetBookIndex( contM, bookId, indexPath, indexType )) - printf("Successfully added index for book %s\n", bookId); - else - printf("Unable to add index for book %s\n", bookId); - - if (ContentManager_SetBookPath( contM, bookId, zimPath )) - printf("Successfully set path for book %s\n", bookId); - else - printf("Unable to set path for book %s\n", bookId); - - const char* langs; - langs = ContentManager_GetBooksLanguages( contM ); - printf("Languages: %s\n", langs); - - const char* pubs; - langs = ContentManager_GetBooksPublishers( contM ); - printf("Publishers: %s\n", langs); - - char* mode = "lastOpen"; - char* lsortBy = "size"; - unsigned int lmaxSize = 0; - char* llanguage = ""; - char* lpublisher = ""; - char* lsearch = ""; - if (ContentManager_ListBooks( contM, mode, lsortBy, lmaxSize, llanguage, lpublisher, lsearch )) - printf("Successfully listed books\n"); - else - printf("Unable to list books\n"); - - const char* nextBookId; - nextBookId = ContentManager_GetListNextBookId( contM ); - printf("Next book id: %s\n", nextBookId); - - CMBook book = ContentManager_GetBookById( contM, bookId ); - printf("Book: %s\n\tarticles: %s\n\tlangs: %s\n", book.title, book.articleCount, book.language); - - if (ContentManager_RemoveBookById( contM, bookId )) - printf("Successfully removed book %s\n", bookId); - else - printf("Unable to remove book %s\n", bookId); - - ContentManager_WriteLibraryToFile( contM, libPath ); - - ContentManager_Destroy( contM ); - contM = NULL; - - return 0; -} diff --git a/src/contentManager/contentManager.cpp b/src/contentManager/contentManager.cpp deleted file mode 100644 index 7c45a41..0000000 --- a/src/contentManager/contentManager.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright 2011 Emmanuel Engelhart - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include "contentManager.h" - -ContentManager::ContentManager(int x) : manager() {} - -bool ContentManager::OpenLibraryFromFile(string path, bool readOnly) { - try { - return this->manager.readFile(path, readOnly); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return true; -} - -bool ContentManager::OpenLibraryFromText(string &xml, bool readOnly) { - - bool returnValue = true; - const char *cXml; - cXml = xml.c_str(); - - try { - return this->manager.readXml(cXml, readOnly); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::WriteLibrary() { - - try { - return this->manager.writeFile(this->manager.writableLibraryPath); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::WriteLibraryToFile(string &path) { - - try { - return this->manager.writeFile(path.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::AddBookFromPath(string &path) { - - try { - return this->manager.addBookFromPath(path.c_str(), path); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::RemoveBookById(string &id) { - - try { - return this->manager.removeBookById(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -bool ContentManager::SetCurrentBookId(string &id) { - - try { - return this->manager.setCurrentBookId(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; - } - -string ContentManager::GetCurrentBookId() { - string none = ""; - try { - return this->manager.getCurrentBookId(); - } catch (exception &e) { - cerr << e.what() << endl; - return none; - } - - return none; -} - -bool ContentManager::GetBookById(string &id, - string &path, - string &title, - string &indexPath, - string &indexType, - string &description, - string &articleCount, - string &mediaCount, - string &size, - string &creator, - string &date, - string &language, - string &favicon, - string &url) { - - try { - kiwix::Book book; - - if (this->manager.getBookById(id.c_str(), book)) { - path = book.pathAbsolute.data(); - title = book.title.data(); - indexPath = book.indexPathAbsolute.data(); - articleCount = book.articleCount.data(); - mediaCount = book.mediaCount.data(); - size = book.size.data(); - creator = book.creator.data(); - date = book.date.data(); - language = book.language.data(); - url = book.url.data(); - - string faviconUrl = ""; - if (!book.faviconMimeType.empty()) { - faviconUrl = "url(data:" + book.faviconMimeType + ";base64," + book.favicon + ")"; - } - favicon = faviconUrl.data(); - - string indexTypeString = ""; - if (book.indexType == kiwix::XAPIAN) { - indexTypeString = "xapian"; - } else if (book.indexType == kiwix::CLUCENE) { - indexTypeString = "clucene"; - } - indexType = indexTypeString.data(); - - description = book.description.data(); - - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -bool ContentManager::UpdateBookLastOpenDateById(string &id) { - try { - return this->manager.updateBookLastOpenDateById(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -unsigned int ContentManager::GetBookCount(const bool localBooks, const bool remoteBooks) { - int count = 0; - - try { - return this->manager.getBookCount(localBooks, remoteBooks); - } catch (exception &e) { - cerr << e.what() << endl; - return count; - } - - return count; -} - -bool ContentManager::ListBooks(string &mode, string &sortBy, unsigned int maxSize, - string &language, string &publisher, string &search) { - try { - - // Set the mode enum - kiwix::supportedListMode listMode; - if (mode == "lastOpen") { - listMode = kiwix::LASTOPEN; - } else if ( mode == "remote") { - listMode = kiwix::REMOTE; - } else { - listMode = kiwix::LOCAL; - } - - // Set the sortBy enum - kiwix::supportedListSortBy listSortBy; - if (sortBy == "publisher") { - listSortBy = kiwix::PUBLISHER; - } else if ( sortBy == "date") { - listSortBy = kiwix::DATE; - } else if ( sortBy == "size") { - listSortBy = kiwix::SIZE; - } else { - listSortBy = kiwix::TITLE; - } - - return this->manager.listBooks(listMode, listSortBy, maxSize, language.c_str(), publisher.c_str(), search.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -const char* ContentManager::GetListNextBookId() { - - string id; - try { - if (!this->manager.bookIdList.empty()) { - id = *(this->manager.bookIdList.begin()); - this->manager.bookIdList.erase(this->manager.bookIdList.begin()); - } - } catch (exception &e) { - cerr << e.what() << endl; - } - return id.c_str(); -} - -bool ContentManager::SetBookIndex(string &id, string &path, string &indexType) { - try { - kiwix::supportedIndexType iType; - if (indexType == "clucene") { - iType = kiwix::CLUCENE; - } else { - iType = kiwix::XAPIAN; - } - - return this->manager.setBookIndex(id.c_str(), path.c_str(), iType); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::SetBookPath(string &id, string &path) { - try { - return this->manager.setBookPath(id.c_str(), path.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -string ContentManager::GetBooksLanguages() { - string languagesStr = ""; - - vector booksLanguages = this->manager.getBooksLanguages(); - vector::iterator itr; - for ( itr = booksLanguages.begin(); itr != booksLanguages.end(); ++itr ) { - languagesStr += *itr + ";"; - } - return languagesStr; -} - -string ContentManager::GetBooksPublishers() { - string publishersStr = ""; - - vector booksPublishers = this->manager.getBooksPublishers(); - vector::iterator itr; - for ( itr = booksPublishers.begin(); itr != booksPublishers.end(); ++itr ) { - publishersStr += *itr + ";"; - } - return publishersStr; -} diff --git a/src/contentManager/contentManager.h b/src/contentManager/contentManager.h deleted file mode 100644 index c6ba26c..0000000 --- a/src/contentManager/contentManager.h +++ /dev/null @@ -1,37 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -class ContentManager -{ - public: - ContentManager(int); - bool OpenLibraryFromFile(string, bool); - bool OpenLibraryFromText(string&, bool); - bool WriteLibrary(); - bool WriteLibraryToFile(string&); - bool AddBookFromPath(string&); - bool RemoveBookById(string&); - bool SetCurrentBookId(string&); - string GetCurrentBookId(); - bool GetBookById(string&, string&, string&, - string&, string&, string&, - string&, string&, string&, - string&, string&, string&, - string&, string&); - bool UpdateBookLastOpenDateById(string&); - unsigned int GetBookCount(bool, bool); - const char* GetListNextBookId(); - bool SetBookIndex(string&, string&, string&); - bool SetBookPath(string&, string&); - string GetBooksLanguages(); - string GetBooksPublishers(); - bool ListBooks(string&, string&, unsigned int, string&, string&, string&); - protected: - kiwix::Manager manager; - -}; diff --git a/src/contentManager/contentManagerTester.cpp b/src/contentManager/contentManagerTester.cpp deleted file mode 100644 index d2a31fa..0000000 --- a/src/contentManager/contentManagerTester.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include "contentManager.h" - - -int main(int argc, char* argv[]) -{ - ContentManager cont_man(0); - ContentManager* cont = new ContentManager(0); - - if (argc < 2) { - cout << "Usage: " << argv[0] << " zimPath" << endl << endl; - cout << "No ZIM file path provided." << endl; - exit(0); - } - string zimPath = (string) argv[1]; - cout << "Kiwix Tester." << endl << "Loading " << zimPath << "..." << endl; - - if (cont->OpenLibraryFromFile(zimPath, true)) - cout << "Successfully opened ZIM file." << endl; - else - cout << "Unable to open ZIM file." << endl; - - string xmltext = ""; - if (cont->OpenLibraryFromText(xmltext, true)) - cout << "Successfully opened XML library." << endl; - else - cout << "Unable to open XML library." << endl; - - if (cont->WriteLibrary()) - cout << "Successfully wrote library." << endl; - else - cout << "Unable to write library." << endl; - - if (cont->AddBookFromPath(zimPath)) - cout << "Successfully added book " << zimPath << endl; - else - cout << "Unable to add book " << zimPath << endl; - - string lpath = "/tmp/toto"; - if (cont->WriteLibraryToFile(lpath)) - cout << "Successfully wrote library to " << lpath << endl; - else - cout << "Unable to write library to " << lpath << endl; - - string bookid = "57b0b7c3-25a5-431e-431e-dce1771ee052963f"; - /*if (cont->RemoveBookById(bookid)) - cout << "Successfully removed book " << bookid << endl; - else - cout << "Unable to remove book " << bookid << endl;*/ - - if (cont->SetCurrentBookId(bookid)) - cout << "Successfully set current book " << bookid << endl; - else - cout << "Unable to set current book " << bookid << endl; - - cout << "Current Book ID: " << cont->GetCurrentBookId() << endl; - - if (cont->UpdateBookLastOpenDateById(bookid)) - cout << "Successfully updated last open date for book " << bookid << endl; - else - cout << "Unable to update last open date for book " << bookid << endl; - - cout << "Total book count: " << cont->GetBookCount(true, true) << endl; - - string indexPath = "/home/reg/wksw.index"; - string indexMethod = "xapian"; - if (cont->SetBookIndex(bookid, indexPath, indexMethod)) - cout << "Successfully set index for book " << bookid << endl; - else - cout << "Unable to set index for book " << bookid << endl; - - if (cont->SetBookPath(bookid, zimPath)) - cout << "Successfully set path for book " << bookid << endl; - else - cout << "Unable to set path for book " << bookid << endl; - - cout << "Languages: " << cont->GetBooksLanguages() << endl; - - cout << "Publishers: " << cont->GetBooksPublishers() << endl; - - string id; - string path; - string title; - string rindexPath; - string indexType; - string description; - string articleCount; - string mediaCount; - string size; - string creator; - string date; - string language; - string favicon; - string url; - if (cont->GetBookById(bookid, path, title, rindexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url)) { - cout << "Successfully retrieved book " << bookid << endl; - cout << "\ttitle: " << title << endl; - cout << "\tURL: " << url << endl; - cout << "\tarticleCount: " << articleCount << endl; - } else - cout << "Unable to set path for book " << bookid << endl; - - string lmode = "lastOpen"; - string lsortBy = "size"; - unsigned int lmaxSize = 0; - string llanguage = ""; - string lpublisher = ""; - string lsearch = ""; - if (cont->ListBooks(lmode, lsortBy, lmaxSize, llanguage, lpublisher, lsearch)) { - cout << "Successfully listed books" << endl; - cout << "Next Book: " << cont->GetListNextBookId() << endl; - } else - cout << "Unable to list books " << endl; - - cont->WriteLibraryToFile(lpath); - - delete cont; - - return 0; -} From 11897437f953ab9107380ad528f6e1e455de1ef2 Mon Sep 17 00:00:00 2001 From: Kiran Mathew Koshy Date: Wed, 18 Sep 2013 00:28:35 +0530 Subject: [PATCH 03/10] Kiwix manage now adds origID tag automatically if it detects a diff_file. --- src/manager/kiwix-manage.cpp | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index b0b323f..b3fe23b 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -24,12 +24,46 @@ #include #include #include +#include #include using namespace std; enum supportedAction { NONE, ADD, SHOW, REMOVE }; +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; + } + void show(kiwix::Library library) { std::vector::iterator itr; unsigned int inc = 1; @@ -160,6 +194,29 @@ int main(int argc, char **argv) { if (zimPath != "") { zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave; + zim::File zimFile(zimPath); + if(zimFile.getArticleByUrl("M/startfileuid").getIndex()!=std::numeric_limits::max()) + { + std::string id=zimFile.getArticleByUrl("M/endfileuid").getPage(); + std::string temp=""; + unsigned int k=0; + char tempArray[16]=""; + for(unsigned int i=0; i Date: Fri, 20 Sep 2013 02:32:37 +0530 Subject: [PATCH 04/10] Fixed kiwix-serve incompatibility after modification to manager class --- src/server/kiwix-serve.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index d865a34..8d6b922 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -27,9 +27,9 @@ #ifdef _WIN32 -#if (_MSC_VER < 1600) -#include "stdint4win.h" -#endif +#if (_MSC_VER < 1600) +#include "stdint4win.h" +#endif #include #include // otherwise socklen_t is not a recognized type //#include // otherwise int is not a recognized type @@ -274,7 +274,7 @@ static int accessHandlerCallback(void *cls, } else { if (isVerbose()) cout << "Failed to find " << urlStr << endl; - + content = "\nContent not found

Not Found

The requested URL " + urlStr + " was not found on this server.

"; mimeType = "text/html"; httpResponseCode = MHD_HTTP_NOT_FOUND; @@ -312,11 +312,11 @@ static int accessHandlerCallback(void *cls, contentLength = content.size(); /* Should be deflate */ - bool deflated = + bool deflated = contentLength > KIWIX_MIN_CONTENT_SIZE_TO_DEFLATE && contentLength < COMPRESSOR_BUFFER_SIZE && acceptEncodingDeflate && - mimeType.find("text/") != string::npos; + mimeType.find("text/") != string::npos; /* Compress the content if necessary */ if (deflated) { @@ -357,7 +357,7 @@ static int accessHandlerCallback(void *cls, if (deflated) { MHD_add_response_header(response, "Content-encoding", "deflate"); } - + /* Specify the mime type */ MHD_add_response_header(response, "Content-Type", mimeType.c_str()); } @@ -481,7 +481,7 @@ int main(int argc, char **argv) { cerr << "The XML library file '" << libraryPath << "' is empty (or has only remote books)." << endl; } } else { - if (!libraryManager.addBookFromPath(zimPath, zimPath, "", false)) { + if (!libraryManager.addBookFromPath(zimPath, zimPath, "","", false)) { cerr << "Unable to add the ZIM file '" << zimPath << "' to the internal library." << endl; exit(1); } else if (!indexPath.empty()) { From b198e5671735b1e3295c09d3022163aed2077fa0 Mon Sep 17 00:00:00 2001 From: Kiran Mathew Koshy Date: Fri, 20 Sep 2013 02:52:29 +0530 Subject: [PATCH 05/10] Updated Kiwix::Manager class to accept origID as the last optional parameter, so as not to break existing tools which use Kiwix::Manager --- src/manager/kiwix-manage.cpp | 2 +- src/server/kiwix-serve.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index b3fe23b..4ef6998 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -217,7 +217,7 @@ int main(int argc, char **argv) { origID=hexUUID(tempArray); } //std::cout<<"\nORIGID: "< Date: Fri, 20 Sep 2013 18:35:20 +0530 Subject: [PATCH 06/10] 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. --- src/manager/kiwix-manage.cpp | 58 +----------------------------------- src/server/kiwix-serve.cpp | 2 +- 2 files changed, 2 insertions(+), 58 deletions(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index 4ef6998..2f61134 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -24,45 +24,12 @@ #include #include #include -#include #include using namespace std; enum supportedAction { NONE, ADD, SHOW, REMOVE }; -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; - } void show(kiwix::Library library) { std::vector::iterator itr; @@ -194,30 +161,7 @@ int main(int argc, char **argv) { if (zimPath != "") { zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave; - zim::File zimFile(zimPath); - if(zimFile.getArticleByUrl("M/startfileuid").getIndex()!=std::numeric_limits::max()) - { - std::string id=zimFile.getArticleByUrl("M/endfileuid").getPage(); - std::string temp=""; - unsigned int k=0; - char tempArray[16]=""; - for(unsigned int i=0; i Date: Sun, 22 Sep 2013 17:02:08 +0200 Subject: [PATCH 07/10] + small beautifying of the code --- src/server/kiwix-serve.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 412b1b3..8e735b6 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -541,7 +541,7 @@ int main(int argc, char **argv) { /* Instanciate the ZIM index (if necessary) */ kiwix::Searcher *searcher = NULL; - if (indexPath != "") { + if (!indexPath.empty()) { bool hasSearchIndex = false; /* Try to load the search */ From 77dfd3e03f69bea5b3e750dc46764faaaffe824c Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sun, 22 Sep 2013 17:03:16 +0200 Subject: [PATCH 08/10] + small beautifying of the code --- src/manager/kiwix-manage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index 2f61134..b90ee35 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -159,7 +159,7 @@ int main(int argc, char **argv) { } } - if (zimPath != "") { + if (!zimPath.empty()) { zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave; string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false); From 27a6e645ed487de9b32dd53177f4090eddfac0bb Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 18 Nov 2013 15:57:34 +0100 Subject: [PATCH 09/10] + implement --nosearchbar option for kiwix-serve --- src/server/kiwix-serve.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 8e735b6..0672630 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -74,6 +74,7 @@ extern "C" { using namespace std; +static bool nosearchbarFlag = false; static string welcomeHTML; static bool verboseFlag = false; static std::map readers; @@ -88,12 +89,14 @@ static pthread_mutex_t verboseFlagLock = PTHREAD_MUTEX_INITIALIZER; void introduceTaskbar(string &content, const string &humanReadableBookId) { pthread_mutex_lock(&resourceLock); - content = appendToFirstOccurence(content, "", getResourceAsString("jqueryui/include.html.part")); - content = appendToFirstOccurence(content, "", ""); - std::string HTMLDivRewrited = replaceRegex(getResourceAsString("server/taskbar.html.part"), - humanReadableBookId, "__CONTENT__"); - content = appendToFirstOccurence(content, "]*>", HTMLDivRewrited); + if (!nosearchbarFlag) { + content = appendToFirstOccurence(content, "", getResourceAsString("jqueryui/include.html.part")); + content = appendToFirstOccurence(content, "", ""); + std::string HTMLDivRewrited = replaceRegex(getResourceAsString("server/taskbar.html.part"), + humanReadableBookId, "__CONTENT__"); + content = appendToFirstOccurence(content, "]*>", HTMLDivRewrited); + } pthread_mutex_unlock(&resourceLock); } @@ -400,6 +403,7 @@ int main(int argc, char **argv) { {"daemon", no_argument, 0, 'd'}, {"verbose", no_argument, 0, 'v'}, {"library", no_argument, 0, 'l'}, + {"nosearchbar", no_argument, 0, 'n'}, {"index", required_argument, 0, 'i'}, {"attachToProcess", required_argument, 0, 'a'}, {"port", required_argument, 0, 'p'}, @@ -407,7 +411,7 @@ int main(int argc, char **argv) { }; int option_index = 0; - int c = getopt_long(argc, argv, "dvli:a:p:", long_options, &option_index); + int c = getopt_long(argc, argv, "ndvli:a:p:", long_options, &option_index); if (c != -1) { @@ -424,6 +428,10 @@ int main(int argc, char **argv) { libraryFlag = true; break; + case 'n': + nosearchbarFlag = true; + break; + case 'i': indexPath = optarg; break; @@ -451,8 +459,8 @@ int main(int argc, char **argv) { /* Print usage)) if necessary */ if (zimPath.empty() && libraryPath.empty()) { - cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] [--daemon] [--attachToProcess=PID] ZIM_PATH" << endl; - cerr << " kiwix-serve --library [--port=PORT] [--verbose] [--daemon] [--attachToProcess=PID] LIBRARY_PATH" << endl; + cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] [--nosearchbar] [--daemon] [--attachToProcess=PID] ZIM_PATH" << endl; + cerr << " kiwix-serve --library [--port=PORT] [--verbose] [--daemon] [--nosearchbar] [--attachToProcess=PID] LIBRARY_PATH" << endl; exit(1); } From 3406052ac299b675fb5006e82be5528ace1d0615 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 18 Nov 2013 17:11:50 +0100 Subject: [PATCH 10/10] + allow rewriting of urls also with quotes --- src/server/kiwix-serve.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 0672630..9e187a3 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -292,9 +292,9 @@ static int accessHandlerCallback(void *cls, /* Special rewrite URL in case of ZIM file use intern *asbolute* url like /A/Kiwix */ content = replaceRegex(content, "$1$2" + humanReadableBookId + "/$3/", - "(href|src)(=[\"|\']/)([A-Z|\\-])/"); + "(href|src)(=[\"|\']{0,1}/)([A-Z|\\-])/"); content = replaceRegex(content, "$1$2" + humanReadableBookId + "/$3/", - "(@import[ ]+)([\"|\']/)([A-Z|\\-])/"); + "(@import[ ]+)([\"|\']{0,1}/)([A-Z|\\-])/"); } }