wsd: add fetch external method

After file server has been initialized,
it fetches external logo image.

Change-Id: I5d47287d5fa875c3e5825567d4ff284abe2ff500
Signed-off-by: Henry Castro <hcastro@collabora.com>
This commit is contained in:
Henry Castro 2022-06-07 09:08:23 -04:00 committed by Michael Meeks
parent ccd15ce9a6
commit 19ed2aa2b4
3 changed files with 48 additions and 0 deletions

View file

@ -2396,6 +2396,9 @@ void COOLWSD::innerInitialize(Application& self)
<< getServiceURI("/hosting/discovery") << '\n';
std::cerr << std::endl;
#else
// ---------------- from here on we start getting external messages ----------------
FileServerRequestHandler::fetchExternal();
#endif
#endif

View file

@ -58,6 +58,10 @@ using Poco::Net::HTTPResponse;
using Poco::Net::NameValueCollection;
using Poco::Util::Application;
#define DEFAULT_LOGO "https://www.collaboraoffice.com/downloads/images/lokit-extra-img.svg"
std::string FileServerRequestHandler::LogoData;
std::map<std::string, std::pair<std::string, std::string>> FileServerRequestHandler::FileHash;
namespace {
@ -811,6 +815,43 @@ void FileServerRequestHandler::initialize()
}
}
void FileServerRequestHandler::fetchExternal()
{
try {
Poco::URI uriLogo(DEFAULT_LOGO);
auto sessionLogo = http::Session::create(uriLogo.getHost(),
http::Session::Protocol::HttpSsl,
uriLogo.getPort());
sessionLogo->setTimeout(std::chrono::seconds(10));
http::Request requestLogo(uriLogo.getPathAndQuery());
http::Session::FinishedCallback logoCallback =
[](const std::shared_ptr<http::Session>& httpSession)
{
const std::shared_ptr<const http::Response> httpResponse = httpSession->response();
if (httpResponse->statusLine().statusCode() == Poco::Net::HTTPResponse::HTTP_OK)
{
LogoData = httpResponse->getBody();
}
};
sessionLogo->setFinishedHandler(logoCallback);
sessionLogo->asyncRequest(requestLogo, *COOLWSD::getWebServerPoll());
}
catch(const Poco::Exception& exc)
{
LOG_DBG("Fetch External: " << exc.displayText());
}
catch(std::exception& exc)
{
LOG_DBG("Fetch External: " << exc.what());
}
catch(...)
{
LOG_DBG("Fetch External: Unknown exception");
}
}
const std::string *FileServerRequestHandler::getCompressedFile(const std::string &path)
{
return &FileHash[path].second;

View file

@ -62,6 +62,10 @@ public:
static void readDirToHash(const std::string &basePath, const std::string &path, const std::string &prefix = std::string());
static void fetchExternal();
static std::string LogoData;
static const std::string *getCompressedFile(const std::string &path);
static const std::string *getUncompressedFile(const std::string &path);