mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-27 06:10:52 -04:00
+ kiwix-serve able to deal with library XML files
This commit is contained in:
parent
61dd14a2f3
commit
049ad722b1
@ -46,6 +46,7 @@ typedef int off_t;
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
|
#include <kiwix/manager.h>
|
||||||
#include <kiwix/xapianSearcher.h>
|
#include <kiwix/xapianSearcher.h>
|
||||||
#include <pathTools.h>
|
#include <pathTools.h>
|
||||||
#include <regexTools.h>
|
#include <regexTools.h>
|
||||||
@ -344,10 +345,13 @@ static int accessHandlerCallback(void *cls,
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct MHD_Daemon *daemon;
|
struct MHD_Daemon *daemon;
|
||||||
string zimPath;
|
string zimPath;
|
||||||
|
string libraryPath;
|
||||||
string indexPath;
|
string indexPath;
|
||||||
string rootPath;
|
string rootPath;
|
||||||
int serverPort = 80;
|
int serverPort = 80;
|
||||||
int daemonFlag = false;
|
int daemonFlag = false;
|
||||||
|
int libraryFlag = false;
|
||||||
|
kiwix::Manager libraryManager;
|
||||||
|
|
||||||
/* Argument parsing */
|
/* Argument parsing */
|
||||||
while (42) {
|
while (42) {
|
||||||
@ -355,13 +359,14 @@ int main(int argc, char **argv) {
|
|||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"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'},
|
||||||
{"index", required_argument, 0, 'i'},
|
{"index", required_argument, 0, 'i'},
|
||||||
{"port", required_argument, 0, 'p'},
|
{"port", required_argument, 0, 'p'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = getopt_long(argc, argv, "dvi:p:", long_options, &option_index);
|
int c = getopt_long(argc, argv, "dvli:p:", long_options, &option_index);
|
||||||
|
|
||||||
if (c != -1) {
|
if (c != -1) {
|
||||||
|
|
||||||
@ -374,6 +379,10 @@ int main(int argc, char **argv) {
|
|||||||
verboseFlag = true;
|
verboseFlag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
libraryFlag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
indexPath = optarg;
|
indexPath = optarg;
|
||||||
break;
|
break;
|
||||||
@ -384,7 +393,10 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
zimPath = argv[optind++];
|
if (libraryFlag)
|
||||||
|
libraryPath = argv[optind++];
|
||||||
|
else
|
||||||
|
zimPath = argv[optind++];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -392,13 +404,41 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print usage)) if necessary */
|
/* Print usage)) if necessary */
|
||||||
if (zimPath == "") {
|
if (zimPath.empty() && libraryPath.empty()) {
|
||||||
cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] [--daemon] ZIM_PATH" << endl;
|
cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] [--daemon] ZIM_PATH" << endl;
|
||||||
|
cerr << " kiwix-serve --library [--port=PORT] [--verbose] [--daemon] LIBRARY_PATH" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *page;
|
void *page;
|
||||||
|
|
||||||
|
/* Setup the library manager */
|
||||||
|
if (libraryFlag) {
|
||||||
|
try {
|
||||||
|
libraryManager.readFile(libraryPath, true);
|
||||||
|
} catch (...) {
|
||||||
|
cerr << "Unable to open the XML library file '" << libraryPath << "'." << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get a ZIM file path */
|
||||||
|
/* TODO: This currently work only with one content in the library */
|
||||||
|
kiwix::Book currentBook;
|
||||||
|
if (libraryManager.getCurrentBook(currentBook)) {
|
||||||
|
zimPath = currentBook.path;
|
||||||
|
indexPath = currentBook.indexPath;
|
||||||
|
} else {
|
||||||
|
cerr << "The XML library file '" << libraryPath << "' is empty." << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!libraryManager.addBookFromPath(zimPath, zimPath, "", false)) {
|
||||||
|
cerr << "Unable to add the ZIM file '" << libraryPath << "' to the internal library." << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Instanciate the ZIM file handler */
|
/* Instanciate the ZIM file handler */
|
||||||
try {
|
try {
|
||||||
reader = new kiwix::Reader(zimPath);
|
reader = new kiwix::Reader(zimPath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user