diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index 3bc3d94f2..99ff865e4 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -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 diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 773d24eb3..b1885bae0 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -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> 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& httpSession) + { + const std::shared_ptr 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; diff --git a/wsd/FileServer.hpp b/wsd/FileServer.hpp index 4a46cdd4e..d6c17fe6b 100644 --- a/wsd/FileServer.hpp +++ b/wsd/FileServer.hpp @@ -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);