mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-26 05:41:18 -04:00
catching up with master
This commit is contained in:
commit
e0062f948c
@ -1,215 +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 "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 );
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
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
|
|
@ -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
|
|
@ -1,137 +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 "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 = "<library current='dummy'><book id='dummy' path='blabla.zim' indexPath='blabla.idx' indexType='xapian'/></library>";
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <kiwix/manager.h>
|
|
||||||
#include <pathTools.h>
|
|
||||||
#include <regexTools.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
};
|
|
@ -1,143 +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 <kiwix/manager.h>
|
|
||||||
#include <pathTools.h>
|
|
||||||
#include <regexTools.h>
|
|
||||||
#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 = "<library current='e04bcf41-eae8-b04b-b04b-da2d0c00f4220000'><book id='e04bcf41-eae8-b04b-b04b-da2d0c00f4220000' path='ubuntudoc_fr_01_2009.zim' indexPath='ubuntudoc_fr_01_2009.zim.idx' indexType='xapian'/></library>";
|
|
||||||
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;
|
|
||||||
}
|
|
@ -30,6 +30,7 @@ using namespace std;
|
|||||||
|
|
||||||
enum supportedAction { NONE, ADD, SHOW, REMOVE };
|
enum supportedAction { NONE, ADD, SHOW, REMOVE };
|
||||||
|
|
||||||
|
|
||||||
void show(kiwix::Library library) {
|
void show(kiwix::Library library) {
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
unsigned int inc = 1;
|
unsigned int inc = 1;
|
||||||
@ -96,6 +97,7 @@ int main(int argc, char **argv) {
|
|||||||
string indexPath;
|
string indexPath;
|
||||||
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
|
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
|
||||||
string url;
|
string url;
|
||||||
|
string origID="";
|
||||||
bool setCurrent = false;
|
bool setCurrent = false;
|
||||||
|
|
||||||
if (argc>3) {
|
if (argc>3) {
|
||||||
@ -108,6 +110,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"url", required_argument, 0, 'u'},
|
{"url", required_argument, 0, 'u'},
|
||||||
|
{"origId", required_argument, 0, 'o'},
|
||||||
{"indexPath", required_argument, 0, 'i'},
|
{"indexPath", required_argument, 0, 'i'},
|
||||||
{"indexBackend", required_argument, 0, 'b'},
|
{"indexBackend", required_argument, 0, 'b'},
|
||||||
{"zimPathToSave", required_argument, 0, 'z'},
|
{"zimPathToSave", required_argument, 0, 'z'},
|
||||||
@ -124,6 +127,10 @@ int main(int argc, char **argv) {
|
|||||||
url = optarg;
|
url = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'o':
|
||||||
|
origID = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
setCurrent = true;
|
setCurrent = true;
|
||||||
break;
|
break;
|
||||||
@ -150,7 +157,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zimPath != "") {
|
if (!zimPath.empty()) {
|
||||||
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
|
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
|
||||||
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
|
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ extern "C" {
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static bool nosearchbarFlag = false;
|
||||||
static string welcomeHTML;
|
static string welcomeHTML;
|
||||||
static bool verboseFlag = false;
|
static bool verboseFlag = false;
|
||||||
static std::map<std::string, kiwix::Reader*> readers;
|
static std::map<std::string, kiwix::Reader*> readers;
|
||||||
@ -87,12 +88,14 @@ static pthread_mutex_t verboseFlagLock = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
|
|
||||||
void introduceTaskbar(string &content, const string &humanReadableBookId) {
|
void introduceTaskbar(string &content, const string &humanReadableBookId) {
|
||||||
pthread_mutex_lock(&resourceLock);
|
pthread_mutex_lock(&resourceLock);
|
||||||
|
if (!nosearchbarFlag) {
|
||||||
content = appendToFirstOccurence(content, "<head>", getResourceAsString("jqueryui/include.html.part"));
|
content = appendToFirstOccurence(content, "<head>", getResourceAsString("jqueryui/include.html.part"));
|
||||||
content = appendToFirstOccurence(content, "<head>", "<style>" +
|
content = appendToFirstOccurence(content, "<head>", "<style>" +
|
||||||
getResourceAsString("server/taskbar.css") + "</style>");
|
getResourceAsString("server/taskbar.css") + "</style>");
|
||||||
std::string HTMLDivRewrited = replaceRegex(getResourceAsString("server/taskbar.html.part"),
|
std::string HTMLDivRewrited = replaceRegex(getResourceAsString("server/taskbar.html.part"),
|
||||||
humanReadableBookId, "__CONTENT__");
|
humanReadableBookId, "__CONTENT__");
|
||||||
content = appendToFirstOccurence(content, "<body[^>]*>", HTMLDivRewrited);
|
content = appendToFirstOccurence(content, "<body[^>]*>", HTMLDivRewrited);
|
||||||
|
}
|
||||||
pthread_mutex_unlock(&resourceLock);
|
pthread_mutex_unlock(&resourceLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,9 +291,9 @@ static int accessHandlerCallback(void *cls,
|
|||||||
|
|
||||||
/* Special rewrite URL in case of ZIM file use intern *asbolute* url like /A/Kiwix */
|
/* Special rewrite URL in case of ZIM file use intern *asbolute* url like /A/Kiwix */
|
||||||
content = replaceRegex(content, "$1$2" + humanReadableBookId + "/$3/",
|
content = replaceRegex(content, "$1$2" + humanReadableBookId + "/$3/",
|
||||||
"(href|src)(=[\"|\']/)([A-Z|\\-])/");
|
"(href|src)(=[\"|\']{0,1}/)([A-Z|\\-])/");
|
||||||
content = replaceRegex(content, "$1$2" + humanReadableBookId + "/$3/",
|
content = replaceRegex(content, "$1$2" + humanReadableBookId + "/$3/",
|
||||||
"(@import[ ]+)([\"|\']/)([A-Z|\\-])/");
|
"(@import[ ]+)([\"|\']{0,1}/)([A-Z|\\-])/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,6 +402,7 @@ int main(int argc, char **argv) {
|
|||||||
{"daemon", no_argument, 0, 'd'},
|
{"daemon", no_argument, 0, 'd'},
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{"verbose", no_argument, 0, 'v'},
|
||||||
{"library", no_argument, 0, 'l'},
|
{"library", no_argument, 0, 'l'},
|
||||||
|
{"nosearchbar", no_argument, 0, 'n'},
|
||||||
{"index", required_argument, 0, 'i'},
|
{"index", required_argument, 0, 'i'},
|
||||||
{"attachToProcess", required_argument, 0, 'a'},
|
{"attachToProcess", required_argument, 0, 'a'},
|
||||||
{"port", required_argument, 0, 'p'},
|
{"port", required_argument, 0, 'p'},
|
||||||
@ -406,7 +410,7 @@ int main(int argc, char **argv) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int option_index = 0;
|
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) {
|
if (c != -1) {
|
||||||
|
|
||||||
@ -423,6 +427,10 @@ int main(int argc, char **argv) {
|
|||||||
libraryFlag = true;
|
libraryFlag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'n':
|
||||||
|
nosearchbarFlag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
indexPath = optarg;
|
indexPath = optarg;
|
||||||
break;
|
break;
|
||||||
@ -450,8 +458,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* Print usage)) if necessary */
|
/* Print usage)) if necessary */
|
||||||
if (zimPath.empty() && libraryPath.empty()) {
|
if (zimPath.empty() && libraryPath.empty()) {
|
||||||
cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] [--daemon] [--attachToProcess=PID] ZIM_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] [--attachToProcess=PID] LIBRARY_PATH" << endl;
|
cerr << " kiwix-serve --library [--port=PORT] [--verbose] [--daemon] [--nosearchbar] [--attachToProcess=PID] LIBRARY_PATH" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +535,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* Instanciate the ZIM index (if necessary) */
|
/* Instanciate the ZIM index (if necessary) */
|
||||||
kiwix::Searcher *searcher = NULL;
|
kiwix::Searcher *searcher = NULL;
|
||||||
if (indexPath != "") {
|
if (!indexPath.empty()) {
|
||||||
bool hasSearchIndex = false;
|
bool hasSearchIndex = false;
|
||||||
|
|
||||||
/* Try to load the search */
|
/* Try to load the search */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user