Skip to content

Commit c9496a6

Browse files
mgautierfrkelson42
authored andcommitted
Adapt kiwix-tools to new libkiwix API.
1 parent 252e3bc commit c9496a6

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

src/manager/kiwix-manage.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ using namespace std;
2929

3030
enum supportedAction { NONE, ADD, SHOW, REMOVE };
3131

32-
void show(kiwix::Library* library, const std::string& bookId)
32+
void show(const kiwix::Library& library, const std::string& bookId)
3333
{
3434
try {
35-
auto& book = library->getBookById(bookId);
35+
auto& book = library.getBookById(bookId);
3636
std::cout << "id:\t\t" << book.getId() << std::endl
3737
<< "path:\t\t" << book.getPath() << std::endl
3838
<< "url:\t\t" << book.getUrl() << std::endl
@@ -96,7 +96,7 @@ void usage()
9696
<< std::endl;
9797
}
9898

99-
int handle_show(kiwix::Library* library, const std::string& libraryPath,
99+
int handle_show(const kiwix::Library& library, const std::string& libraryPath,
100100
int argc, char* argv[])
101101
{
102102
if (argc > 3 ) {
@@ -105,15 +105,15 @@ int handle_show(kiwix::Library* library, const std::string& libraryPath,
105105
show(library, bookId);
106106
}
107107
} else {
108-
auto booksIds = library->getBooksIds();
108+
auto booksIds = library.getBooksIds();
109109
for(auto& bookId: booksIds) {
110110
show(library, bookId);
111111
}
112112
}
113113
return(0);
114114
}
115115

116-
int handle_add(kiwix::Library* library, const std::string& libraryPath,
116+
int handle_add(std::shared_ptr<kiwix::Library> library, const std::string& libraryPath,
117117
int argc, char* argv[])
118118
{
119119
string zimPath;
@@ -182,7 +182,7 @@ int handle_add(kiwix::Library* library, const std::string& libraryPath,
182182
return(resultCode);
183183
}
184184

185-
int handle_remove(kiwix::Library* library, const std::string& libraryPath,
185+
int handle_remove(std::shared_ptr<kiwix::Library> library, const std::string& libraryPath,
186186
int argc, char* argv[])
187187
{
188188
std::string bookId;
@@ -216,7 +216,7 @@ int main(int argc, char** argv)
216216
{
217217
string libraryPath = "";
218218
supportedAction action = NONE;
219-
kiwix::Library library;
219+
auto library = std::make_shared<kiwix::Library>();
220220

221221
/* General argument parsing */
222222
static struct option long_options[] = {
@@ -261,7 +261,7 @@ int main(int argc, char** argv)
261261
libraryPath = kiwix::isRelativePath(libraryPath)
262262
? kiwix::computeAbsolutePath(kiwix::getCurrentDirectory(), libraryPath)
263263
: libraryPath;
264-
kiwix::Manager manager(&library);
264+
kiwix::Manager manager(library);
265265
if (!manager.readFile(libraryPath, false)) {
266266
if (kiwix::fileExists(libraryPath) || action!=ADD) {
267267
std::cerr << "Cannot read the library " << libraryPath << std::endl;
@@ -273,13 +273,13 @@ int main(int argc, char** argv)
273273
int exitCode = 0;
274274
switch (action) {
275275
case SHOW:
276-
exitCode = handle_show(&library, libraryPath, argc, argv);
276+
exitCode = handle_show(*library, libraryPath, argc, argv);
277277
break;
278278
case ADD:
279-
exitCode = handle_add(&library, libraryPath, argc, argv);
279+
exitCode = handle_add(library, libraryPath, argc, argv);
280280
break;
281281
case REMOVE:
282-
exitCode = handle_remove(&library, libraryPath, argc, argv);
282+
exitCode = handle_remove(library, libraryPath, argc, argv);
283283
break;
284284
case NONE:
285285
break;
@@ -292,7 +292,7 @@ int main(int argc, char** argv)
292292
/* Rewrite the library file */
293293
if (action == REMOVE || action == ADD) {
294294
// writeToFile return true (1) if everything is ok => exitCode is 0
295-
if (!library.writeToFile(libraryPath)) {
295+
if (!library->writeToFile(libraryPath)) {
296296
std::cerr << "Cannot write the library " << libraryPath << std::endl;
297297
return 1;
298298
}

src/server/kiwix-serve.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int main(int argc, char** argv)
197197
#endif
198198

199199
std::string rootLocation = "/";
200-
kiwix::Library library;
200+
auto library = std::make_shared<kiwix::Library>();
201201
unsigned int nb_threads = DEFAULT_THREADS;
202202
std::vector<std::string> zimPathes;
203203
std::string libraryPath;
@@ -331,7 +331,7 @@ int main(int argc, char** argv)
331331
}
332332

333333
/* Setup the library manager and get the list of books */
334-
kiwix::Manager manager(&library);
334+
kiwix::Manager manager(library);
335335
std::vector<std::string> libraryPaths;
336336
if (libraryFlag) {
337337
libraryPaths = kiwix::split(libraryPath, ";");
@@ -340,7 +340,7 @@ int main(int argc, char** argv)
340340
}
341341

342342
/* Check if the library is not empty (or only remote books)*/
343-
if (library.getBookCount(true, false) == 0) {
343+
if (library->getBookCount(true, false) == 0) {
344344
std::cerr << "The XML library file '" << libraryPath
345345
<< "' is empty (or has only remote books)." << std::endl;
346346
}
@@ -376,8 +376,8 @@ int main(int argc, char** argv)
376376
}
377377
#endif
378378

379-
kiwix::UpdatableNameMapper nameMapper(library, noDateAliasesFlag);
380-
kiwix::Server server(&library, &nameMapper);
379+
auto nameMapper = std::make_shared<kiwix::UpdatableNameMapper>(library, noDateAliasesFlag);
380+
kiwix::Server::Configuration configuration(library, nameMapper);
381381

382382
if (!customIndexPath.empty()) {
383383
try {
@@ -388,17 +388,18 @@ int main(int argc, char** argv)
388388
}
389389
}
390390

391-
server.setAddress(address);
392-
server.setRoot(rootLocation);
393-
server.setPort(serverPort);
394-
server.setNbThreads(nb_threads);
395-
server.setVerbose(isVerboseFlag);
396-
server.setTaskbar(!noSearchBarFlag, !noLibraryButtonFlag);
397-
server.setBlockExternalLinks(blockExternalLinks);
398-
server.setIndexTemplateString(indexTemplateString);
399-
server.setIpConnectionLimit(ipConnectionLimit);
400-
server.setMultiZimSearchLimit(searchLimit);
401-
391+
configuration.setAddress(address);
392+
configuration.setRoot(rootLocation);
393+
configuration.setPort(serverPort);
394+
configuration.setNbThreads(nb_threads);
395+
configuration.setVerbose(isVerboseFlag);
396+
configuration.setTaskbar(!noSearchBarFlag, !noLibraryButtonFlag);
397+
configuration.setBlockExternalLinks(blockExternalLinks);
398+
configuration.setIndexTemplateString(indexTemplateString);
399+
configuration.setIpConnectionLimit(ipConnectionLimit);
400+
configuration.setMultiZimSearchLimit(searchLimit);
401+
402+
kiwix::Server server(configuration);
402403
if (! server.start()) {
403404
exit(1);
404405
}
@@ -447,7 +448,7 @@ int main(int argc, char** argv)
447448
if ( libraryMustBeReloaded && !libraryPaths.empty() ) {
448449
libraryFileTimestamp = curLibraryFileTimestamp;
449450
reloadLibrary(manager, libraryPaths);
450-
nameMapper.update();
451+
nameMapper->update();
451452
libraryMustBeReloaded = false;
452453
}
453454
} while (waiting);

0 commit comments

Comments
 (0)