mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-12-23 14:38:01 -05:00
Implement a function which returns server access url
This commit is contained in:
@@ -69,6 +69,7 @@ namespace kiwix
|
|||||||
int getPort() const;
|
int getPort() const;
|
||||||
IpAddress getAddress() const;
|
IpAddress getAddress() const;
|
||||||
IpMode getIpMode() const;
|
IpMode getIpMode() const;
|
||||||
|
std::vector<std::string> getServerAccessUrls() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<Library> mp_library;
|
std::shared_ptr<Library> mp_library;
|
||||||
|
|||||||
@@ -29,6 +29,22 @@
|
|||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
std::string makeServerUrl(std::string host, int port, std::string root)
|
||||||
|
{
|
||||||
|
const int httpDefaultPort = 80;
|
||||||
|
|
||||||
|
if (port == httpDefaultPort) {
|
||||||
|
return "http://" + host + root;
|
||||||
|
} else {
|
||||||
|
return "http://" + host + ":" + std::to_string(port) + root;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
Server::Server(LibraryPtr library, std::shared_ptr<NameMapper> nameMapper) :
|
Server::Server(LibraryPtr library, std::shared_ptr<NameMapper> nameMapper) :
|
||||||
mp_library(library),
|
mp_library(library),
|
||||||
mp_nameMapper(nameMapper),
|
mp_nameMapper(nameMapper),
|
||||||
@@ -112,4 +128,16 @@ IpMode Server::getIpMode() const
|
|||||||
return mp_server->getIpMode();
|
return mp_server->getIpMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Server::getServerAccessUrls() const
|
||||||
|
{
|
||||||
|
std::vector<std::string> result;
|
||||||
|
if (!m_addr.addr.empty()) {
|
||||||
|
result.push_back(makeServerUrl(m_addr.addr, m_port, m_root));
|
||||||
|
}
|
||||||
|
if (!m_addr.addr6.empty()) {
|
||||||
|
result.push_back(makeServerUrl("[" + m_addr.addr6 + "]", m_port, m_root));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user