diff --git a/include/opds_dumper.h b/include/opds_dumper.h index 23cc94ae2..b6ed2e85b 100644 --- a/include/opds_dumper.h +++ b/include/opds_dumper.h @@ -42,7 +42,7 @@ class OPDSDumper { public: OPDSDumper() = default; - OPDSDumper(std::shared_ptr library, NameMapper* NameMapper); + OPDSDumper(std::shared_ptr library, std::shared_ptr NameMapper); ~OPDSDumper(); /** @@ -111,7 +111,7 @@ class OPDSDumper protected: std::shared_ptr library; - kiwix::NameMapper* nameMapper; + std::shared_ptr nameMapper; std::string libraryId; std::string rootLocation; int m_totalResults; diff --git a/include/search_renderer.h b/include/search_renderer.h index fec854a1d..bd434517d 100644 --- a/include/search_renderer.h +++ b/include/search_renderer.h @@ -46,7 +46,7 @@ class SearchRenderer * @param start The start offset used for the srs. * @param estimatedResultCount The estimatedResultCount of the whole search */ - SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, + SearchRenderer(zim::SearchResultSet srs, std::shared_ptr mapper, unsigned int start, unsigned int estimatedResultCount); /** @@ -58,7 +58,7 @@ class SearchRenderer * @param start The start offset used for the srs. * @param estimatedResultCount The estimatedResultCount of the whole search */ - SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, std::shared_ptr library, + SearchRenderer(zim::SearchResultSet srs, std::shared_ptr mapper, std::shared_ptr library, unsigned int start, unsigned int estimatedResultCount); ~SearchRenderer(); @@ -106,7 +106,7 @@ class SearchRenderer protected: std::string beautifyInteger(const unsigned int number); zim::SearchResultSet m_srs; - NameMapper* mp_nameMapper; + std::shared_ptr mp_nameMapper; std::shared_ptr mp_library; std::string searchBookQuery; std::string searchPattern; diff --git a/include/server.h b/include/server.h index 39cacc994..19d776ef6 100644 --- a/include/server.h +++ b/include/server.h @@ -34,7 +34,7 @@ namespace kiwix public: class Configuration { public: - explicit Configuration(std::shared_ptr library, NameMapper* nameMapper=nullptr) + explicit Configuration(std::shared_ptr library, std::shared_ptr nameMapper=nullptr) : mp_library(library), mp_nameMapper(nameMapper) {} @@ -87,7 +87,7 @@ namespace kiwix } std::shared_ptr mp_library; - NameMapper* mp_nameMapper; + std::shared_ptr mp_nameMapper; std::string m_root = ""; std::string m_addr = ""; std::string m_indexTemplateString = ""; diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index 456b260b3..683e1af1e 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -30,7 +30,7 @@ namespace kiwix { /* Constructor */ -OPDSDumper::OPDSDumper(std::shared_ptr library, NameMapper* nameMapper) +OPDSDumper::OPDSDumper(std::shared_ptr library, std::shared_ptr nameMapper) : library(library), nameMapper(nameMapper) { diff --git a/src/search_renderer.cpp b/src/search_renderer.cpp index a8f2e31cb..91cafe4a5 100644 --- a/src/search_renderer.cpp +++ b/src/search_renderer.cpp @@ -36,12 +36,12 @@ namespace kiwix { /* Constructor */ -SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, +SearchRenderer::SearchRenderer(zim::SearchResultSet srs, std::shared_ptr mapper, unsigned int start, unsigned int estimatedResultCount) : SearchRenderer(srs, mapper, nullptr, start, estimatedResultCount) {} -SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, std::shared_ptr library, +SearchRenderer::SearchRenderer(zim::SearchResultSet srs, std::shared_ptr mapper, std::shared_ptr library, unsigned int start, unsigned int estimatedResultCount) : m_srs(srs), mp_nameMapper(mapper), diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index ecb3722b4..58dbc1d50 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -333,7 +333,7 @@ zim::Query SearchInfo::getZimQuery(bool verbose) const { return query; } -static IdNameMapper defaultNameMapper; +static std::shared_ptr defaultNameMapper = std::make_shared(); static MHD_Result staticHandlerCallback(void* cls, struct MHD_Connection* connection, @@ -370,7 +370,7 @@ InternalServer::InternalServer(const Server::Configuration& configuration) : m_configuration(configuration), m_root(normalizeRootUrl(configuration.m_root)), m_indexTemplateString(configuration.m_indexTemplateString.empty() ? RESOURCE::templates::index_html : configuration.m_indexTemplateString), - mp_nameMapper(configuration.mp_nameMapper ? configuration.mp_nameMapper : &defaultNameMapper), + mp_nameMapper(configuration.mp_nameMapper ? configuration.mp_nameMapper : defaultNameMapper), mp_daemon(nullptr), searchCache(getEnvVar("KIWIX_SEARCH_CACHE_SIZE", DEFAULT_CACHE_SIZE)), suggestionSearcherCache(getEnvVar("KIWIX_SUGGESTION_SEARCHER_CACHE_SIZE", std::max((unsigned int) (m_configuration.mp_library->getBookCount(true, true)*0.1), 1U))), diff --git a/src/server/internalServer.h b/src/server/internalServer.h index 9f9acfd1e..0b26fd9bb 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -153,7 +153,7 @@ class InternalServer { std::string m_addr; std::string m_root; std::string m_indexTemplateString; - NameMapper* mp_nameMapper; + std::shared_ptr mp_nameMapper; struct MHD_Daemon* mp_daemon; SearchCache searchCache; diff --git a/test/server_testing_tools.h b/test/server_testing_tools.h index 6ecf02f06..ad3099b26 100644 --- a/test/server_testing_tools.h +++ b/test/server_testing_tools.h @@ -94,7 +94,7 @@ private: private: // data kiwix::Library library; kiwix::Manager manager; - std::unique_ptr nameMapper; + std::shared_ptr nameMapper; std::unique_ptr server; std::unique_ptr client; const Options options = DEFAULT_OPTIONS; @@ -132,7 +132,7 @@ void ZimFileServer::run(int serverPort, std::string indexTemplateString) } else { nameMapper.reset(new kiwix::HumanReadableNameMapper(library, false)); } - kiwix::Server::Configuration configuration(NotOwned(library), nameMapper.get()); + kiwix::Server::Configuration configuration(NotOwned(library), nameMapper); configuration.setRoot("ROOT") .setAddress(address) .setPort(serverPort)