diff --git a/src/ctype/zimAccessor/zimAccessor.cpp b/src/ctype/zimAccessor/zimAccessor.cpp deleted file mode 100644 index ad72458..0000000 --- a/src/ctype/zimAccessor/zimAccessor.cpp +++ /dev/null @@ -1,220 +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 "zimAccessor.h" - -ZimAccessor::ZimAccessor(int x) : reader(NULL) {} - -/* Instanciate the ZIM file handler */ -bool ZimAccessor::LoadFile(string path) { - try { - this->reader = new kiwix::Reader(path); - return true; - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Unload the ZIM file */ -bool ZimAccessor::Unload() { - if (this->reader != NULL) { - delete this->reader; - this->reader = NULL; - return true; - } - - return false; -} - -/* Reset the cursor for GetNextArticle() */ -bool ZimAccessor::Reset() { - try { - this->reader->reset(); - return true; - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Get the count of articles which can be indexed/displayed */ -bool ZimAccessor::GetArticleCount(unsigned int &count) { - try { - if (this->reader != NULL) { - count = this->reader->getArticleCount(); - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Return the UID of the ZIM file */ -bool ZimAccessor::GetId(string &id) { - try { - if (this->reader != NULL) { - id = this->reader->getId(); - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Return a random article URL */ -bool ZimAccessor::GetRandomPageUrl(string &url) { - try { - if (this->reader != NULL) { - url = this->reader->getRandomPageUrl(); - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Return a page url fronm title */ -bool ZimAccessor::GetPageUrlFromTitle(const string &title, string &url) { - try { - if (this->reader != NULL) { - if (this->reader->getPageUrlFromTitle(title, url)) { - return true; - } - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Return the welcome page URL */ -bool ZimAccessor::GetMainPageUrl(string &url) { - try { - if (this->reader != NULL) { - url = this->reader->getMainPageUrl(); - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Get a metatag value */ -bool ZimAccessor::GetMetatag(const string &name, string &value) { - try { - if (this->reader != NULL) { - if (this->reader->getMetatag(name, value)) { - return true; - } - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Get a content from a zim file */ -bool ZimAccessor::GetContent(string url, string &content, unsigned int &contentLength, string &contentType) { - - /* default value */ - content = ""; - contentType = ""; - contentLength = 0; - - try { - if (this->reader != NULL) { - if (this->reader->getContentByUrl(url, content, contentLength, contentType)) { - return true; - } - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Search titles by prefix*/ -bool ZimAccessor::SearchSuggestions(const string &prefix, unsigned int suggestionsCount) { - try { - if (this->reader != NULL) { - if (this->reader->searchSuggestions(prefix.c_str(), suggestionsCount)) { - return true; - } - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Get next suggestion */ -bool ZimAccessor::GetNextSuggestion(string &title) { - try { - if (this->reader != NULL) { - if (this->reader->getNextSuggestion(title)) { - return true; - } - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Can I check the integrity - for old ZIM file without checksum */ -bool ZimAccessor::CanCheckIntegrity() { - try { - if (this->reader != NULL) { - return this->reader->canCheckIntegrity(); - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -/* Return true if corrupted, false otherwise */ -bool ZimAccessor::IsCorrupted() { - try { - if (this->reader != NULL) { - return this->reader->isCorrupted(); - } - } catch (exception &e) { - cerr << e.what() << endl; - } - - return true; -} diff --git a/src/ctype/zimAccessor/zimAccessor.h b/src/ctype/zimAccessor/zimAccessor.h deleted file mode 100644 index cada3cb..0000000 --- a/src/ctype/zimAccessor/zimAccessor.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -class ZimAccessor { - public: - ZimAccessor(int); - bool LoadFile(string path); - bool GetArticleCount(unsigned int &count); - bool Reset(); - bool Unload(); - bool GetId(string &id); - bool GetPageUrlFromTitle(const string &title, string &url); - bool GetMainPageUrl(string &url); - bool GetRandomPageUrl(string &url); - bool GetMetatag(const string &tag, string &value); - bool GetContent(string url, string &content, unsigned int &contentLength, string &contentType); - bool SearchSuggestions(const string &prefix, unsigned int suggestionsCount); - bool GetNextSuggestion(string &title); - bool CanCheckIntegrity(); - bool IsCorrupted(); - kiwix::Reader *reader; -}; diff --git a/src/ctype/zimAccessor/zimAccessorWrapper.cpp b/src/ctype/zimAccessor/zimAccessorWrapper.cpp deleted file mode 100644 index 70078ab..0000000 --- a/src/ctype/zimAccessor/zimAccessorWrapper.cpp +++ /dev/null @@ -1,197 +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 "zimAccessorWrapper.h" - -/* creates instance of ZimAccessor */ -HZIMCLASS ZimAccessor_Create(void) { - ZimAccessor * zimAccessor = new ZimAccessor(0); - - // Return its pointer (opaque) - return (HZIMCLASS)zimAccessor; -} - -/* Delete instance of ZimAccessor */ -void ZimAccessor_Destroy( HZIMCLASS h ) { - assert(h != NULL); - - // Convert from handle to ZimAccessor pointer - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - delete zimAccessor; -} - -int ZimAccessor_LoadFile( HZIMCLASS h, char* zimPath) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - if (zimAccessor->LoadFile( zimPath )) - return true; - else - return false; -} - -/* Reset the cursor for GetNextArticle() */ -int ZimAccessor_Reset( HZIMCLASS h) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - if (zimAccessor->Reset()) - return true; - else - return false; -} - -/* Reset the cursor for GetNextArticle() */ -int ZimAccessor_Unload( HZIMCLASS h) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - if (zimAccessor->Unload()) - return true; - else - return false; -} - -/* Get the count of articles which can be indexed/displayed */ -unsigned int ZimAccessor_GetArticleCount( HZIMCLASS h) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - unsigned int count = 0; - zimAccessor->GetArticleCount(count); - return count; -} - -/* Return the UID of the ZIM file */ -const char* ZimAccessor_GetId( HZIMCLASS h) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string id = ""; - zimAccessor->GetId(id); - return id.c_str(); -} - -/* Return a page url fronm title */ -const char* ZimAccessor_GetPageUrlFromTitle( HZIMCLASS h, char* title) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string cptitle = string(title); - string url = ""; - zimAccessor->GetPageUrlFromTitle(cptitle, url); - return url.c_str(); -} - -/* Return the welcome page URL */ -const char* ZimAccessor_GetMainPageUrl( HZIMCLASS h ) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string hp = ""; - zimAccessor->GetMainPageUrl( hp ); - return hp.c_str(); -} - -/* Return the welcome page URL */ -const char* ZimAccessor_GetRandomPageUrl( HZIMCLASS h ) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string hp = ""; - zimAccessor->GetRandomPageUrl( hp ); - return hp.c_str(); -} - -/* Get a metatag value */ -const char* ZimAccessor_GetMetatag( HZIMCLASS h, char* name) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string cpname = string(name); - string value = ""; - zimAccessor->GetMetatag(cpname, value); - return value.c_str(); -} - -/* Get a content from a zim file */ -const char* ZimAccessor_GetContent(HZIMCLASS h, char* url) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string cpurl = string(url); - string content = ""; - unsigned int contentLength = 0; - string contentType = ""; - zimAccessor->GetContent( cpurl, content, contentLength, contentType ); - return content.c_str(); -} - -/* Search titles by prefix*/ -unsigned int ZimAccessor_SearchSuggestions( HZIMCLASS h, char* prefix) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string cpprefix = string(prefix); - unsigned int suggestionsCount; - zimAccessor->SearchSuggestions(cpprefix, suggestionsCount); - return suggestionsCount; -} - -/* Get next suggestion */ -const char* ZimAccessor_GetNextSuggestion( HZIMCLASS h ) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - string title = ""; - zimAccessor->GetNextSuggestion( title ); - return title.c_str(); -} - -/* Can I check the integrity - for old ZIM file without checksum */ -int ZimAccessor_CanCheckIntegrity( HZIMCLASS h ) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - return zimAccessor->CanCheckIntegrity(); -} - -/* Return true if corrupted, false otherwise */ -int ZimAccessor_IsCorrupted( HZIMCLASS h ) { - assert(h != NULL); - - ZimAccessor * zimAccessor = (ZimAccessor *)h; - - return zimAccessor->IsCorrupted(); -} - diff --git a/src/ctype/zimAccessor/zimAccessorWrapper.h b/src/ctype/zimAccessor/zimAccessorWrapper.h deleted file mode 100644 index 4288b4d..0000000 --- a/src/ctype/zimAccessor/zimAccessorWrapper.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#ifdef __cplusplus -#include -#include -#include -#include -#include "zimAccessor.h" - -extern "C" { -#endif - -typedef void * HZIMCLASS; - -HZIMCLASS ZimAccessor_Create(void); - -void ZimAccessor_Destroy(HZIMCLASS h); - -int ZimAccessor_LoadFile( HZIMCLASS h, char* zimPath ); -int ZimAccessor_Reset( HZIMCLASS h ); -int ZimAccessor_Unload( HZIMCLASS h ); -unsigned int ZimAccessor_GetArticleCount( HZIMCLASS h ); -const char* ZimAccessor_GetId( HZIMCLASS h ); -const char* ZimAccessor_GetPageUrlFromTitle( HZIMCLASS h, char* url); -const char* ZimAccessor_GetMainPageUrl( HZIMCLASS h ); -const char* ZimAccessor_GetRandomPageUrl( HZIMCLASS h ); -const char* ZimAccessor_GetMetatag( HZIMCLASS h, char* name); -const char* ZimAccessor_GetContent( HZIMCLASS h, char* url); -unsigned int ZimAccessor_SearchSuggestions( HZIMCLASS h, char* prefix); -const char* ZimAccessor_GetNextSuggestion( HZIMCLASS h ); -int ZimAccessor_CanCheckIntegrity( HZIMCLASS h ); -int ZimAccessor_IsCorrupted( HZIMCLASS h ); - -#ifdef __cplusplus -}; -#endif