diff --git a/wsd/ClientRequestDispatcher.cpp b/wsd/ClientRequestDispatcher.cpp index 9c3c302108..4e2129257b 100644 --- a/wsd/ClientRequestDispatcher.cpp +++ b/wsd/ClientRequestDispatcher.cpp @@ -26,7 +26,6 @@ #include #if !MOBILEAPP #include -#include #endif // !MOBILEAPP #include #include diff --git a/wsd/ClientRequestDispatcher.hpp b/wsd/ClientRequestDispatcher.hpp index f23f7f62f4..1f49832cff 100644 --- a/wsd/ClientRequestDispatcher.hpp +++ b/wsd/ClientRequestDispatcher.hpp @@ -14,7 +14,9 @@ #include #include #include +#if !MOBILEAPP #include +#endif // !MOBILEAPP #include #include @@ -110,8 +112,10 @@ private: std::weak_ptr _socket; std::string _id; +#if !MOBILEAPP /// WASM document request handler. Used only when WASM is enabled. std::unique_ptr _wopiProxy; +#endif // !MOBILEAPP /// The private RequestVettingStation. Held privately after the /// WS is created and as long as it is connected. diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index a01103e6c2..4b6f39eaf4 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -769,9 +769,9 @@ void DocumentBroker::stop(const std::string& reason) _poll->wakeup(); } -bool DocumentBroker::download(const std::shared_ptr& session, - const std::string& jailId, - std::unique_ptr wopiFileInfo) +bool DocumentBroker::download( + const std::shared_ptr& session, const std::string& jailId, + [[maybe_unused]] std::unique_ptr wopiFileInfo) { ASSERT_CORRECT_THREAD(); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 0ae8087d3f..52015d893f 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -36,6 +36,34 @@ #if !MOBILEAPP #include "Admin.hpp" +#include +#else +//FIXME: Move to a stub file. +class WopiStorage : public StorageBase +{ +public: + class WOPIFileInfo : public FileInfo + { + public: + enum class TriState + { + False, + True, + Unset + }; + + std::string getTemplateSource() const { return std::string(); } + + bool getDisablePrint() const { return false; } + bool getDisableExport() const { return false; } + bool getDisableCopy() const { return false; } + bool getEnableOwnerTermination() const { return false; } + + TriState getDisableChangeTrackingShow() const { return TriState::Unset; } + TriState getDisableChangeTrackingRecord() const { return TriState::Unset; } + TriState getHideChangeTrackingControls() const { return TriState::Unset; } + }; +}; #endif // Forwards. diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 1ea9f5f974..2444420fe1 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #endif diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp index 785d58b484..c7ac04aa2f 100644 --- a/wsd/Storage.hpp +++ b/wsd/Storage.hpp @@ -556,230 +556,4 @@ private: static std::atomic LastLocalStorageId; }; -/// WOPI protocol backed storage. -class WopiStorage : public StorageBase -{ -public: - class WOPIFileInfo : public FileInfo - { - void init(); - public: - enum class TriState - { - False, - True, - Unset - }; - - /// warning - removes items from object. - WOPIFileInfo(const FileInfo& fileInfo, Poco::JSON::Object::Ptr& object, - const Poco::URI& uriObject); - - const std::string& getUserId() const { return _userId; } - const std::string& getUsername() const { return _username; } - const std::string& getUserExtraInfo() const { return _userExtraInfo; } - const std::string& getUserPrivateInfo() const { return _userPrivateInfo; } - const std::string& getWatermarkText() const { return _watermarkText; } - const std::string& getTemplateSaveAs() const { return _templateSaveAs; } - const std::string& getTemplateSource() const { return _templateSource; } - const std::string& getBreadcrumbDocName() const { return _breadcrumbDocName; } - const std::string& getFileUrl() const { return _fileUrl; } - const std::string& getPostMessageOrigin() { return _postMessageOrigin; } - const std::string& getHideUserList() { return _hideUserList; } - - bool getUserCanWrite() const { return _userCanWrite; } - void setHidePrintOption(bool hidePrintOption) { _hidePrintOption = hidePrintOption; } - bool getHidePrintOption() const { return _hidePrintOption; } - bool getHideSaveOption() const { return _hideSaveOption; } - void setHideExportOption(bool hideExportOption) { _hideExportOption = hideExportOption; } - bool getHideExportOption() const { return _hideExportOption; } - void setHideRepairOption(bool hideRepairOption) { _hideRepairOption = hideRepairOption; } - bool getHideRepairOption() const { return _hideRepairOption; } - bool getEnableOwnerTermination() const { return _enableOwnerTermination; } - bool getDisablePrint() const { return _disablePrint; } - bool getDisableExport() const { return _disableExport; } - bool getDisableCopy() const { return _disableCopy; } - bool getDisableInactiveMessages() const { return _disableInactiveMessages; } - bool getDownloadAsPostMessage() const { return _downloadAsPostMessage; } - bool getUserCanNotWriteRelative() const { return _userCanNotWriteRelative; } - bool getEnableInsertRemoteImage() const { return _enableInsertRemoteImage; } - bool getDisableInsertLocalImage() const { return _disableInsertLocalImage; } - bool getEnableRemoteLinkPicker() const { return _enableRemoteLinkPicker; } - bool getEnableShare() const { return _enableShare; } - bool getSupportsRename() const { return _supportsRename; } - bool getSupportsLocks() const { return _supportsLocks; } - bool getUserCanRename() const { return _userCanRename; } - - TriState getDisableChangeTrackingShow() const { return _disableChangeTrackingShow; } - TriState getDisableChangeTrackingRecord() const { return _disableChangeTrackingRecord; } - TriState getHideChangeTrackingControls() const { return _hideChangeTrackingControls; } - - private: - /// User id of the user accessing the file - std::string _userId; - /// Obfuscated User id used for logging the UserId. - std::string _obfuscatedUserId; - /// Display Name of user accessing the file - std::string _username; - /// Extra public info per user, typically mail and other links, as json, shared with everyone. - std::string _userExtraInfo; - /// Private info per user, for API keys and other non-public information. - std::string _userPrivateInfo; - /// In case a watermark has to be rendered on each tile. - std::string _watermarkText; - /// In case we want to use this file as a template, it should be first re-saved under this name (using PutRelativeFile). - std::string _templateSaveAs; - /// In case we want to use this file as a template. - std::string _templateSource; - /// User readable string of document name to show in UI, if present. - std::string _breadcrumbDocName; - /// The optional FileUrl, used to download the document if provided. - std::string _fileUrl; - /// WOPI Post message property - std::string _postMessageOrigin; - /// If set to "true", user list on the status bar will be hidden - /// If set to "mobile" | "tablet" | "desktop", will be hidden on a specified device - /// (may be joint, delimited by commas eg. "mobile,tablet") - std::string _hideUserList; - /// If we should disable change-tracking visibility by default (meaningful at loading). - TriState _disableChangeTrackingShow = WOPIFileInfo::TriState::Unset; - /// If we should disable change-tracking ability by default (meaningful at loading). - TriState _disableChangeTrackingRecord = WOPIFileInfo::TriState::Unset; - /// If we should hide change-tracking commands for this user. - TriState _hideChangeTrackingControls = WOPIFileInfo::TriState::Unset; - /// If user accessing the file has write permission - bool _userCanWrite = false; - /// Hide print button from UI - bool _hidePrintOption = false; - /// Hide save button from UI - bool _hideSaveOption = false; - /// Hide 'Download as' button/menubar item from UI - bool _hideExportOption = false; - /// Hide the 'Repair' button/item from the UI - bool _hideRepairOption = false; - /// If WOPI host has enabled owner termination feature on - bool _enableOwnerTermination = false; - /// If WOPI host has allowed the user to print the document - bool _disablePrint = false; - /// If WOPI host has allowed the user to export the document - bool _disableExport = false; - /// If WOPI host has allowed the user to copy to/from the document - bool _disableCopy = false; - /// If WOPI host has allowed the cool to show texts on the overlay informing about - /// inactivity, or if the integration is handling that. - bool _disableInactiveMessages = false; - /// For the (mobile) integrations, to indicate that the downloading for printing, exporting, - /// or slideshows should be intercepted and sent as a postMessage instead of handling directly. - bool _downloadAsPostMessage = false; - /// If set to false, users can access the save-as functionality - bool _userCanNotWriteRelative = true; - /// If set to true, users can access the insert remote image functionality - bool _enableInsertRemoteImage = false; - /// If set to true, users can't insert an image from the local machine - bool _disableInsertLocalImage = false; - /// If set to true, users can access the remote link picker functionality - bool _enableRemoteLinkPicker = false; - /// If set to true, users can access the file share functionality - bool _enableShare = false; - /// If WOPI host supports locking - bool _supportsLocks = false; - /// If WOPI host supports rename - bool _supportsRename = false; - /// If user is allowed to rename the document - bool _userCanRename = false; - }; - -#if !MOBILEAPP - - WopiStorage(const Poco::URI& uri, const std::string& localStorePath, - const std::string& jailPath) - : StorageBase(uri, localStorePath, jailPath) - , _wopiSaveDuration(std::chrono::milliseconds::zero()) - , _legacyServer(COOLWSD::getConfigValue("storage.wopi.is_legacy_server", false)) - { - LOG_INF("WopiStorage ctor with localStorePath: [" - << localStorePath << "], jailPath: [" << jailPath << "], uri: [" - << COOLWSD::anonymizeUrl(uri.toString()) << "], legacy server: " << _legacyServer); - } - - /// Signifies if the server is legacy or not, based on the headers - /// it sent us on first contact. - bool isLegacyServer() const { return _legacyServer; } - - /// Handles the response from CheckFileInfo, as converted into WOPIFileInfo. - /// Also extracts the basic file information from the response - /// which can then be obtained using getFileInfo() - /// Also sets up the locking context for future operations. - void handleWOPIFileInfo(const WOPIFileInfo& wopiFileInfo, LockContext& lockCtx); - - /// Update the locking state (check-in/out) of the associated file - LockUpdateResult updateLockState(const Authorization& auth, LockContext& lockCtx, bool lock, - const Attributes& attribs) override; - - /// uri format: http://server/<...>/wopi*/files//content - std::string downloadStorageFileToLocal(const Authorization& auth, LockContext& lockCtx, - const std::string& templateUri) override; - - void uploadLocalFileToStorageAsync(const Authorization& auth, LockContext& lockCtx, - const std::string& saveAsPath, - const std::string& saveAsFilename, const bool isRename, - const Attributes&, SocketPoll& socketPoll, - const AsyncUploadCallback& asyncUploadCallback) override; - - /// Total time taken for making WOPI calls during uploading. - std::chrono::milliseconds getWopiSaveDuration() const { return _wopiSaveDuration; } - - virtual AsyncUpload queryLocalFileToStorageAsyncUploadState() override - { - if (_uploadHttpSession) - return AsyncUpload(AsyncUpload::State::Running, UploadResult(UploadResult::Result::OK)); - else - return AsyncUpload(AsyncUpload::State::None, UploadResult(UploadResult::Result::OK)); - } - -protected: - struct WopiUploadDetails - { - const std::string filePathAnonym; - const std::string uriAnonym; - const std::string httpResponseReason; - const http::StatusCode httpResponseCode; - const std::size_t size; - const bool isSaveAs; - const bool isRename; - }; - - /// Handles the response from the server when uploading the document. - UploadResult handleUploadToStorageResponse(const WopiUploadDetails& details, - std::string responseString); - -private: - /// Initialize an HTTPRequest instance with the common settings and headers. - /// Older Poco versions don't support copying HTTPRequest objects, so we can't generate them. - void initHttpRequest(Poco::Net::HTTPRequest& request, const Poco::URI& uri, - const Authorization& auth) const; - - /// Create an http::Request with the common headers. - http::Request initHttpRequest(const Poco::URI& uri, const Authorization& auth) const; - - /// Download the document from the given URI. - /// Does not add authorization tokens or any other logic. - std::string downloadDocument(const Poco::URI& uriObject, const std::string& uriAnonym, - const Authorization& auth, unsigned redirectLimit); - -private: - /// A URl provided by the WOPI host to use for GetFile. - std::string _fileUrl; - - // Time spend in saving the file from storage - std::chrono::milliseconds _wopiSaveDuration; - - /// The http::Session used for uploading asynchronously. - std::shared_ptr _uploadHttpSession; - - /// Whether or not this is a legacy server. - const bool _legacyServer; -#endif // !MOBILEAPP -}; - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/wsd/wopi/WopiProxy.cpp b/wsd/wopi/WopiProxy.cpp index 7907007af5..eeb562f223 100644 --- a/wsd/wopi/WopiProxy.cpp +++ b/wsd/wopi/WopiProxy.cpp @@ -17,11 +17,12 @@ #include "HttpHelper.hpp" #include "HttpRequest.hpp" #include -#include #include #include -#include #include +#include +#include +#include #include diff --git a/wsd/wopi/WopiStorage.cpp b/wsd/wopi/WopiStorage.cpp index 9d0d3bbd46..cd978aaf21 100644 --- a/wsd/wopi/WopiStorage.cpp +++ b/wsd/wopi/WopiStorage.cpp @@ -11,17 +11,26 @@ #include -#include -#include -#include -#include +#include "WopiStorage.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include - -#if !MOBILEAPP - #include #include #include @@ -32,41 +41,14 @@ #include #include #include - -#include -#include - -#include -#include -#include -#include - -#endif - #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef IOS -#include -#elif defined(__ANDROID__) -#include "androidapp.hpp" -#elif defined(GTKAPP) -#include "gtk.hpp" -#elif WASMAPP -#include "wasmapp.hpp" -#endif // IOS +#include +#include +#include +#include +#include bool isTemplate(const std::string& filename) { @@ -80,8 +62,6 @@ bool isTemplate(const std::string& filename) return false; } -#if !MOBILEAPP - namespace { @@ -124,10 +104,6 @@ std::map GetQueryParams(const Poco::URI& uri) } // anonymous namespace -#endif // !MOBILEAPP - -#if !MOBILEAPP - void WopiStorage::initHttpRequest(Poco::Net::HTTPRequest& request, const Poco::URI& uri, const Authorization& auth) const { @@ -958,6 +934,4 @@ WopiStorage::handleUploadToStorageResponse(const WopiUploadDetails& details, return result; } -#endif // !MOBILEAPP - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/wsd/wopi/WopiStorage.hpp b/wsd/wopi/WopiStorage.hpp index 11c94ca2f0..5b5f52edaa 100644 --- a/wsd/wopi/WopiStorage.hpp +++ b/wsd/wopi/WopiStorage.hpp @@ -11,20 +11,21 @@ #pragma once -#include -#include -#include - -#include -#include -#include - -#include "HttpRequest.hpp" -#include "COOLWSD.hpp" -#include "Log.hpp" +#include +#include +#include +#include #include #include +#include +#include +#include + +#include +#include +#include + /// WOPI protocol backed storage. class WopiStorage : public StorageBase { @@ -159,8 +160,6 @@ public: bool _userCanRename = false; }; -#if !MOBILEAPP - WopiStorage(const Poco::URI& uri, const std::string& localStorePath, const std::string& jailPath) : StorageBase(uri, localStorePath, jailPath) @@ -249,7 +248,6 @@ private: /// Whether or not this is a legacy server. const bool _legacyServer; -#endif // !MOBILEAPP }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */