Make the Server keep a shared_ptr instead of a raw NameMapper pointer.

Same as for `Library`, we want to be sure that the `NameMapper`
actually exists when the server is using it.
This commit is contained in:
Matthieu Gautier
2023-09-25 16:44:28 +02:00
parent a5557eeb25
commit 1316dec37c
6 changed files with 21 additions and 16 deletions

View File

@ -100,7 +100,7 @@ private:
private: // data
std::shared_ptr<kiwix::Library> library;
kiwix::Manager manager;
std::unique_ptr<kiwix::NameMapper> nameMapper;
std::shared_ptr<kiwix::NameMapper> nameMapper;
std::unique_ptr<kiwix::Server> server;
std::unique_ptr<httplib::Client> client;
const Cfg cfg;
@ -140,7 +140,7 @@ void ZimFileServer::run(int serverPort, std::string indexTemplateString)
} else {
nameMapper.reset(new kiwix::HumanReadableNameMapper(*library, false));
}
server.reset(new kiwix::Server(library, nameMapper.get()));
server.reset(new kiwix::Server(library, nameMapper));
server->setRoot(cfg.root);
server->setAddress(address);
server->setPort(serverPort);