wsd: WopiStorage cleanup

Remove MOBILEAPP directives and create
stub WopiStorage and WOPIFileInfo.

Change-Id: I57cd5a008d625ac53ef23c4bb3872381af35560c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
pull/8503/head
Ashod Nakashian 2024-03-06 08:50:24 -05:00 committed by Ashod Nakashian
parent dacfb65965
commit c121488a67
9 changed files with 72 additions and 293 deletions

View File

@ -26,7 +26,6 @@
#include <FileServer.hpp>
#if !MOBILEAPP
#include <HostUtil.hpp>
#include <wopi/WopiProxy.hpp>
#endif // !MOBILEAPP
#include <RequestDetails.hpp>
#include <ProxyRequestHandler.hpp>

View File

@ -14,7 +14,9 @@
#include <RequestVettingStation.hpp>
#include <RequestDetails.hpp>
#include <Socket.hpp>
#if !MOBILEAPP
#include <wopi/WopiProxy.hpp>
#endif // !MOBILEAPP
#include <string>
#include <memory>
@ -110,8 +112,10 @@ private:
std::weak_ptr<StreamSocket> _socket;
std::string _id;
#if !MOBILEAPP
/// WASM document request handler. Used only when WASM is enabled.
std::unique_ptr<WopiProxy> _wopiProxy;
#endif // !MOBILEAPP
/// The private RequestVettingStation. Held privately after the
/// WS is created and as long as it is connected.

View File

@ -769,9 +769,9 @@ void DocumentBroker::stop(const std::string& reason)
_poll->wakeup();
}
bool DocumentBroker::download(const std::shared_ptr<ClientSession>& session,
const std::string& jailId,
std::unique_ptr<WopiStorage::WOPIFileInfo> wopiFileInfo)
bool DocumentBroker::download(
const std::shared_ptr<ClientSession>& session, const std::string& jailId,
[[maybe_unused]] std::unique_ptr<WopiStorage::WOPIFileInfo> wopiFileInfo)
{
ASSERT_CORRECT_THREAD();

View File

@ -36,6 +36,34 @@
#if !MOBILEAPP
#include "Admin.hpp"
#include <wopi/WopiStorage.hpp>
#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.

View File

@ -40,6 +40,7 @@
#include <HostUtil.hpp>
#include <ProofKey.hpp>
#include <HttpRequest.hpp>
#include <wopi/WopiStorage.hpp>
#endif

View File

@ -556,230 +556,4 @@ private:
static std::atomic<unsigned> 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<bool>("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/<id>/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<http::Session> _uploadHttpSession;
/// Whether or not this is a legacy server.
const bool _legacyServer;
#endif // !MOBILEAPP
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -17,11 +17,12 @@
#include "HttpHelper.hpp"
#include "HttpRequest.hpp"
#include <COOLWSD.hpp>
#include <wopi/StorageConnectionManager.hpp>
#include <Exceptions.hpp>
#include <Log.hpp>
#include <common/JsonUtil.hpp>
#include <Util.hpp>
#include <common/JsonUtil.hpp>
#include <wopi/StorageConnectionManager.hpp>
#include <wopi/WopiStorage.hpp>
#include <Poco/JSON/Object.h>

View File

@ -11,17 +11,26 @@
#include <config.h>
#include <chrono>
#include <memory>
#include <iconv.h>
#include <string>
#include "WopiStorage.hpp"
#include <Auth.hpp>
#include <CommandControl.hpp>
#include <Common.hpp>
#include <Exceptions.hpp>
#include <HostUtil.hpp>
#include <HttpRequest.hpp>
#include <Log.hpp>
#include <NetUtil.hpp>
#include <ProofKey.hpp>
#include <Unit.hpp>
#include <Util.hpp>
#include <common/FileUtil.hpp>
#include <common/JsonUtil.hpp>
#include <common/TraceEvent.hpp>
#include <Poco/Exception.h>
#include <Poco/JSON/Object.h>
#include <Poco/JSON/Parser.h>
#if !MOBILEAPP
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/DNS.h>
@ -32,41 +41,14 @@
#include <Poco/Net/KeyConsoleHandler.h>
#include <Poco/Net/NameValueCollection.h>
#include <Poco/Net/SSLManager.h>
#include <cassert>
#include <errno.h>
#include <Auth.hpp>
#include <HostUtil.hpp>
#include <ProofKey.hpp>
#include <HttpRequest.hpp>
#endif
#include <Poco/StreamCopier.h>
#include <Poco/URI.h>
#include <Common.hpp>
#include <Exceptions.hpp>
#include <Storage.hpp>
#include <Log.hpp>
#include <Unit.hpp>
#include <Util.hpp>
#include <common/FileUtil.hpp>
#include <common/JsonUtil.hpp>
#include <common/TraceEvent.hpp>
#include <NetUtil.hpp>
#include <CommandControl.hpp>
#ifdef IOS
#include <ios.h>
#elif defined(__ANDROID__)
#include "androidapp.hpp"
#elif defined(GTKAPP)
#include "gtk.hpp"
#elif WASMAPP
#include "wasmapp.hpp"
#endif // IOS
#include <cassert>
#include <chrono>
#include <iconv.h>
#include <memory>
#include <string>
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<std::string, std::string> 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: */

View File

@ -11,20 +11,21 @@
#pragma once
#include <memory>
#include <string>
#include <chrono>
#include <Poco/URI.h>
#include <Poco/Util/Application.h>
#include <Poco/JSON/Object.h>
#include "HttpRequest.hpp"
#include "COOLWSD.hpp"
#include "Log.hpp"
#include <COOLWSD.hpp>
#include <HttpRequest.hpp>
#include <Log.hpp>
#include <Storage.hpp>
#include <common/Authorization.hpp>
#include <net/HttpRequest.hpp>
#include <Poco/JSON/Object.h>
#include <Poco/URI.h>
#include <Poco/Util/Application.h>
#include <chrono>
#include <memory>
#include <string>
/// 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: */