forked from kiwix/kiwix-tools
commit
394a0d8af2
@ -1,9 +0,0 @@
|
||||
|
||||
all: wrapperlib
|
||||
|
||||
wrapperlib:
|
||||
g++ -shared -o libZimCAccessor.so ZimAccessorWrapper.cpp zimAccessor.cpp ../common/kiwix/reader.cpp -I . -I ../zimAccessor/ -I ../common/ -I ../zimlib/include/ -L ../zimlib/src/.libs/ -lzim ../dependences/xz/src/liblzma/.libs/liblzma.a -I /usr/include/
|
||||
|
||||
clean:
|
||||
find . -name 'libZimCAccessor.so' -delete
|
||||
find . -name '*.o' -delete
|
@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 Renaud Gaudin <reg@kiwix.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "ZimAccessorWrapper.h"
|
||||
#include "zimAccessor.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;
|
||||
}
|
||||
|
||||
/* 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();
|
||||
}
|
||||
|
||||
/* 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();
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
typedef void * HZIMCLASS;
|
||||
|
||||
HZIMCLASS ZimAccessor_Create( void );
|
||||
|
||||
void ZimAccessor_Destroy( HZIMCLASS h );
|
||||
|
||||
int ZimAccessor_LoadFile( HZIMCLASS h, char* zimPath );
|
||||
int ZimAccessor_Reset( 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_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
|
@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 Renaud Gaudin <reg@kiwix.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <kiwix/reader.h>
|
||||
#include "zimAccessor.h"
|
||||
|
||||
ZimAccessor::ZimAccessor(int x) : reader(NULL) {}
|
||||
|
||||
bool ZimAccessor::LoadFile(string path) {
|
||||
try {
|
||||
this->reader = new kiwix::Reader(path);
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Reset the cursor for GetNextArticle() */
|
||||
bool ZimAccessor::Reset() {
|
||||
try {
|
||||
this->reader->reset();
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 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 false;
|
||||
}
|
||||
|
||||
/* Return the UID of the ZIM file */
|
||||
bool ZimAccessor::GetId(string &id) {
|
||||
try {
|
||||
if (this->reader != NULL) {
|
||||
id = this->reader->getId().c_str();
|
||||
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) {
|
||||
string urlstr;
|
||||
|
||||
try {
|
||||
if (this->reader != NULL) {
|
||||
if (this->reader->getPageUrlFromTitle(title.c_str(), urlstr)) {
|
||||
url = urlstr.c_str();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Return the welcome page URL */
|
||||
bool ZimAccessor::GetMainPageUrl(string &url) {
|
||||
try {
|
||||
if (this->reader != NULL) {
|
||||
string urlstr = this->reader->getMainPageUrl();
|
||||
|
||||
url = urlstr.c_str();
|
||||
return true;
|
||||
}
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get a metatag value */
|
||||
bool ZimAccessor::GetMetatag(const string &name, string &value) {
|
||||
string valueStr;
|
||||
|
||||
try {
|
||||
if (this->reader != NULL) {
|
||||
if (this->reader->getMetatag(name.c_str(), valueStr)) {
|
||||
value = valueStr.data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get a content from a zim file */
|
||||
bool ZimAccessor::GetContent(string url, string &content, unsigned int &contentLength, string &contentType) {
|
||||
|
||||
/* strings */
|
||||
string contentStr;
|
||||
string contentTypeStr;
|
||||
unsigned int contentLengthInt;
|
||||
|
||||
/* default value */
|
||||
content = "";
|
||||
contentLength = 0;
|
||||
|
||||
try {
|
||||
if (this->reader != NULL) {
|
||||
if (this->reader->getContentByUrl(url, contentStr, contentLength, contentTypeStr)) {
|
||||
contentType = contentTypeStr.data();
|
||||
content = contentStr.data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get next suggestion */
|
||||
bool ZimAccessor::GetNextSuggestion(string &title) {
|
||||
string titleStr;
|
||||
|
||||
try {
|
||||
if (this->reader != NULL) {
|
||||
if (this->reader->getNextSuggestion(titleStr)) {
|
||||
title = titleStr.c_str();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (exception &e) {
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <kiwix/reader.h>
|
||||
|
||||
class ZimAccessor
|
||||
{
|
||||
public:
|
||||
ZimAccessor(int);
|
||||
bool LoadFile(string);
|
||||
bool GetArticleCount(unsigned int&);
|
||||
bool Reset();
|
||||
bool GetId(string&);
|
||||
bool GetPageUrlFromTitle(const string &, string &);
|
||||
bool GetMainPageUrl(string &);
|
||||
bool GetMetatag(const string &, string &);
|
||||
// WARNING: previous API expected an nsIURI instead of string
|
||||
bool GetContent(string, string &, unsigned int &, string &);
|
||||
bool SearchSuggestions(const string &, unsigned int);
|
||||
bool GetNextSuggestion(string &);
|
||||
bool CanCheckIntegrity();
|
||||
bool IsCorrupted();
|
||||
|
||||
public:
|
||||
kiwix::Reader *reader;
|
||||
};
|
Loading…
Reference in new issue