2016-02-19 15:19:15 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Storage abstraction.
|
|
|
|
#ifndef INCLUDED_STORAGE_HPP
|
|
|
|
#define INCLUDED_STORAGE_HPP
|
|
|
|
|
2016-04-16 17:12:10 -05:00
|
|
|
#include <set>
|
2016-10-29 20:15:00 -05:00
|
|
|
#include <string>
|
2016-02-19 15:19:15 -06:00
|
|
|
|
2016-03-31 01:48:34 -05:00
|
|
|
#include <Poco/URI.h>
|
2016-10-29 20:15:00 -05:00
|
|
|
#include <Poco/Util/Application.h>
|
2016-03-03 20:05:30 -06:00
|
|
|
|
2016-02-19 15:19:15 -06:00
|
|
|
#include "Auth.hpp"
|
2018-06-15 08:54:44 -05:00
|
|
|
#include "LOOLWSD.hpp"
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "Log.hpp"
|
2016-02-19 15:19:15 -06:00
|
|
|
#include "Util.hpp"
|
2018-11-22 05:03:42 -06:00
|
|
|
#include <common/Authorization.hpp>
|
2016-02-19 15:19:15 -06:00
|
|
|
|
|
|
|
/// Base class of all Storage abstractions.
|
|
|
|
class StorageBase
|
|
|
|
{
|
|
|
|
public:
|
2016-10-26 06:15:28 -05:00
|
|
|
/// Represents basic file's attributes.
|
2016-08-13 23:01:13 -05:00
|
|
|
/// Used for local and network files.
|
2016-03-21 18:12:00 -05:00
|
|
|
class FileInfo
|
|
|
|
{
|
|
|
|
public:
|
2016-09-26 01:44:40 -05:00
|
|
|
FileInfo(const std::string& filename,
|
2016-11-08 02:14:14 -06:00
|
|
|
const std::string& ownerId,
|
2016-09-26 01:44:40 -05:00
|
|
|
const Poco::Timestamp& modifiedTime,
|
2018-11-29 01:42:43 -06:00
|
|
|
size_t /*size*/)
|
2016-09-26 01:44:40 -05:00
|
|
|
: _filename(filename),
|
2016-11-08 02:14:14 -06:00
|
|
|
_ownerId(ownerId),
|
2018-11-29 01:42:43 -06:00
|
|
|
_modifiedTime(modifiedTime)
|
2016-09-26 01:44:40 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-06 23:32:28 -05:00
|
|
|
bool isValid() const
|
|
|
|
{
|
2017-01-15 22:06:27 -06:00
|
|
|
// 0-byte files are valid; LO will open them as new docs.
|
|
|
|
return !_filename.empty();
|
2016-04-06 23:32:28 -05:00
|
|
|
}
|
|
|
|
|
2018-11-29 01:42:43 -06:00
|
|
|
const std::string& getFilename() const { return _filename; }
|
|
|
|
|
|
|
|
const std::string& getOwnerId() const { return _ownerId; }
|
|
|
|
|
|
|
|
void setModifiedTime(const Poco::Timestamp& modifiedTime) { _modifiedTime = modifiedTime; }
|
|
|
|
|
|
|
|
const Poco::Timestamp& getModifiedTime() const { return _modifiedTime; }
|
|
|
|
|
|
|
|
private:
|
2016-04-19 02:10:07 -05:00
|
|
|
std::string _filename;
|
2016-11-08 02:14:14 -06:00
|
|
|
std::string _ownerId;
|
2016-04-19 02:10:07 -05:00
|
|
|
Poco::Timestamp _modifiedTime;
|
2016-03-21 18:12:00 -05:00
|
|
|
};
|
|
|
|
|
2017-10-25 07:09:27 -05:00
|
|
|
class SaveResult
|
2016-11-23 06:09:54 -06:00
|
|
|
{
|
2017-10-25 07:09:27 -05:00
|
|
|
public:
|
|
|
|
enum Result
|
|
|
|
{
|
|
|
|
OK,
|
|
|
|
DISKFULL,
|
|
|
|
UNAUTHORIZED,
|
|
|
|
DOC_CHANGED, /**< Document changed in storage */
|
|
|
|
CONFLICT,
|
|
|
|
FAILED
|
|
|
|
};
|
|
|
|
|
|
|
|
SaveResult(Result result) : _result(result)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void setResult(Result result)
|
|
|
|
{
|
|
|
|
_result = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result getResult() const
|
|
|
|
{
|
|
|
|
return _result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSaveAsResult(const std::string& name, const std::string& url)
|
|
|
|
{
|
|
|
|
_saveAsName = name;
|
|
|
|
_saveAsUrl = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getSaveAsName() const
|
|
|
|
{
|
|
|
|
return _saveAsName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getSaveAsUrl() const
|
|
|
|
{
|
|
|
|
return _saveAsUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Result _result;
|
|
|
|
std::string _saveAsName;
|
|
|
|
std::string _saveAsUrl;
|
2016-11-23 06:09:54 -06:00
|
|
|
};
|
|
|
|
|
Inform all clients when document changed behind our back
Introduce a new header X-LOOL-WOPI-Timestamp
This is a WOPI header extension to detect any external document change. For
example, when the file that is already opened by LOOL is changed
in storage.
The WOPI host sends LastModifiedTime field (in WOPI specs) as part
of the CheckFileInfo response. It also expects wsd to send the
same timestamp in X-LOOL-WOPI-Timestamp header during WOPI::PutFile. If
this header is present, then WOPI host checks, before saving the
document, if the timestamp in the header is equal to the timestamp of
the file in its storage. Only upon meeting this condition, it saves the
file back to storage, otherwise it informs us about some change
to the document.
We are supposed to inform the user accordingly. If user is okay
with over-writing the document, then we can omit sending
X-LOOL-WOPI-Timestamp header, in which case, no check as mentioned above
would be performed while saving the file and document will be
overwritten.
Also, use a separate list of LOOL status codes to denote such a change.
It would be wrong to use HTTP_CONFLICT status code for denoting doc
changed in storage scenario. WOPI specs reserves that for WOPI locks
which are not yet implemented. Better to use a separate LOOL specific
status codes synced across WOPI hosts and us to denote scenario that we
expect and are not covered in WOPI specs.
Change-Id: I61539dfae672bc104b8008f030f96e90f9ff48a5
2017-05-31 12:48:33 -05:00
|
|
|
enum class LOOLStatusCode
|
|
|
|
{
|
|
|
|
DOC_CHANGED = 1010 // Document changed externally in storage
|
|
|
|
};
|
|
|
|
|
2016-03-05 09:27:30 -06:00
|
|
|
/// localStorePath the absolute root path of the chroot.
|
|
|
|
/// jailPath the path within the jail that the child uses.
|
2016-10-14 05:09:43 -05:00
|
|
|
StorageBase(const Poco::URI& uri,
|
|
|
|
const std::string& localStorePath,
|
|
|
|
const std::string& jailPath) :
|
|
|
|
_uri(uri),
|
2016-03-05 09:27:30 -06:00
|
|
|
_localStorePath(localStorePath),
|
2016-03-09 17:36:25 -06:00
|
|
|
_jailPath(jailPath),
|
2016-12-19 06:14:00 -06:00
|
|
|
_fileInfo("", "lool", Poco::Timestamp::fromEpochTime(0), 0),
|
2017-06-01 07:56:54 -05:00
|
|
|
_isLoaded(false),
|
2017-09-25 12:16:48 -05:00
|
|
|
_forceSave(false),
|
2017-10-03 04:59:39 -05:00
|
|
|
_isUserModified(false),
|
|
|
|
_isAutosave(false)
|
2016-03-03 20:05:30 -06:00
|
|
|
{
|
2018-06-15 08:54:44 -05:00
|
|
|
LOG_DBG("Storage ctor: " << LOOLWSD::anonymizeUrl(uri.toString()));
|
2016-03-03 20:05:30 -06:00
|
|
|
}
|
|
|
|
|
2017-09-12 03:03:26 -05:00
|
|
|
virtual ~StorageBase() {}
|
|
|
|
|
2018-11-28 02:07:29 -06:00
|
|
|
const Poco::URI& getUri() const { return _uri; }
|
|
|
|
|
|
|
|
const std::string getUriString() const { return _uri.toString(); }
|
|
|
|
|
|
|
|
const std::string& getJailPath() const { return _jailPath; };
|
2016-03-09 17:36:25 -06:00
|
|
|
|
2017-03-21 21:56:16 -05:00
|
|
|
/// Returns the root path to the jailed file.
|
2017-02-05 18:35:54 -06:00
|
|
|
const std::string& getRootFilePath() const { return _jailedFilePath; };
|
|
|
|
|
2017-11-07 07:15:36 -06:00
|
|
|
/// Set the root path of the jailed file, only for use in cases where we actually have converted
|
|
|
|
/// it to another format, in the same directory
|
|
|
|
void setRootFilePath(const std::string& newPath)
|
|
|
|
{
|
|
|
|
// Could assert here that it is in the same directory?
|
|
|
|
_jailedFilePath = newPath;
|
2018-01-14 17:59:11 -06:00
|
|
|
}
|
2017-11-07 07:15:36 -06:00
|
|
|
|
2018-11-28 02:07:29 -06:00
|
|
|
const std::string& getRootFilePathAnonym() const { return _jailedFilePathAnonym; };
|
|
|
|
|
|
|
|
void setRootFilePathAnonym(const std::string& newPath)
|
|
|
|
{
|
|
|
|
_jailedFilePathAnonym = newPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLoaded(bool isLoaded) { _isLoaded = isLoaded; }
|
|
|
|
|
2016-10-14 05:09:43 -05:00
|
|
|
bool isLoaded() const { return _isLoaded; }
|
|
|
|
|
2017-06-01 07:56:54 -05:00
|
|
|
/// Asks the storage object to force overwrite to storage upon next save
|
|
|
|
/// even if document turned out to be changed in storage
|
2018-11-28 02:07:29 -06:00
|
|
|
void forceSave(bool newSave = true) { _forceSave = newSave; }
|
|
|
|
|
|
|
|
bool getForceSave() const { return _forceSave; }
|
2017-06-01 07:56:54 -05:00
|
|
|
|
2017-09-25 12:16:48 -05:00
|
|
|
/// To be able to set the WOPI extension header appropriately.
|
|
|
|
void setUserModified(bool isUserModified) { _isUserModified = isUserModified; }
|
|
|
|
|
2018-11-28 02:07:29 -06:00
|
|
|
bool isUserModified() const { return _isUserModified; }
|
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
/// To be able to set the WOPI 'is autosave?' header appropriately.
|
|
|
|
void setIsAutosave(bool isAutosave) { _isAutosave = isAutosave; }
|
|
|
|
|
2018-11-28 02:07:29 -06:00
|
|
|
bool getIsAutosave() const { return _isAutosave; }
|
|
|
|
|
|
|
|
void setFileInfo(const FileInfo& fileInfo) { _fileInfo = fileInfo; }
|
|
|
|
|
2016-10-26 06:15:28 -05:00
|
|
|
/// Returns the basic information about the file.
|
2018-11-28 02:07:29 -06:00
|
|
|
FileInfo& getFileInfo() { return _fileInfo; }
|
2017-06-06 22:43:48 -05:00
|
|
|
|
2018-11-29 01:42:43 -06:00
|
|
|
std::string getFileExtension() const { return Poco::Path(_fileInfo.getFilename()).getExtension(); }
|
2016-03-21 18:12:00 -05:00
|
|
|
|
|
|
|
/// Returns a local file path for the given URI.
|
2016-02-19 15:19:15 -06:00
|
|
|
/// If necessary copies the file locally first.
|
2017-08-16 09:38:00 -05:00
|
|
|
virtual std::string loadStorageFileToLocal(const Authorization& auth) = 0;
|
2016-02-19 15:19:15 -06:00
|
|
|
|
2016-03-03 20:05:30 -06:00
|
|
|
/// Writes the contents of the file back to the source.
|
2017-10-20 11:12:05 -05:00
|
|
|
/// @param savedFile When the operation was saveAs, this is the path to the file that was saved.
|
|
|
|
virtual SaveResult saveLocalFileToStorage(const Authorization& auth, const std::string& saveAsPath, const std::string& saveAsFilename) = 0;
|
2016-02-19 15:19:15 -06:00
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
static size_t getFileSize(const std::string& filename);
|
2016-03-11 12:45:13 -06:00
|
|
|
|
2016-04-16 07:13:59 -05:00
|
|
|
/// Must be called at startup to configure.
|
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
/// Storage object creation factory.
|
2016-10-14 05:09:43 -05:00
|
|
|
static std::unique_ptr<StorageBase> create(const Poco::URI& uri,
|
|
|
|
const std::string& jailRoot,
|
|
|
|
const std::string& jailPath);
|
2018-10-20 05:57:53 -05:00
|
|
|
|
2018-10-20 06:26:38 -05:00
|
|
|
static bool allowedWopiHost(const std::string& host);
|
2017-03-21 21:56:16 -05:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/// Returns the root path of the jail directory of docs.
|
|
|
|
std::string getLocalRootPath() const;
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2018-11-28 02:07:29 -06:00
|
|
|
private:
|
2016-10-14 04:28:19 -05:00
|
|
|
const Poco::URI _uri;
|
2016-10-14 05:09:43 -05:00
|
|
|
std::string _localStorePath;
|
|
|
|
std::string _jailPath;
|
2016-03-09 17:36:25 -06:00
|
|
|
std::string _jailedFilePath;
|
2018-06-10 19:24:04 -05:00
|
|
|
std::string _jailedFilePathAnonym;
|
2016-03-21 18:12:00 -05:00
|
|
|
FileInfo _fileInfo;
|
2016-10-14 05:09:43 -05:00
|
|
|
bool _isLoaded;
|
2017-06-01 09:16:03 -05:00
|
|
|
bool _forceSave;
|
2016-04-16 07:13:59 -05:00
|
|
|
|
2017-09-25 12:16:48 -05:00
|
|
|
/// The document has been modified by the user.
|
|
|
|
bool _isUserModified;
|
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
/// This save operation is an autosave.
|
|
|
|
bool _isAutosave;
|
|
|
|
|
2016-06-07 02:18:49 -05:00
|
|
|
static bool FilesystemEnabled;
|
|
|
|
static bool WopiEnabled;
|
2016-04-18 20:13:17 -05:00
|
|
|
/// Allowed/denied WOPI hosts, if any and if WOPI is enabled.
|
2016-06-07 02:18:49 -05:00
|
|
|
static Util::RegexListMatcher WopiHosts;
|
2016-02-19 15:19:15 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Trivial implementation of local storage that does not need do anything.
|
|
|
|
class LocalStorage : public StorageBase
|
|
|
|
{
|
|
|
|
public:
|
2016-10-14 05:09:43 -05:00
|
|
|
LocalStorage(const Poco::URI& uri,
|
|
|
|
const std::string& localStorePath,
|
|
|
|
const std::string& jailPath) :
|
|
|
|
StorageBase(uri, localStorePath, jailPath),
|
2016-10-26 06:15:28 -05:00
|
|
|
_isCopy(false)
|
2016-03-05 09:27:30 -06:00
|
|
|
{
|
2016-12-22 15:41:05 -06:00
|
|
|
LOG_INF("LocalStorage ctor with localStorePath: [" << localStorePath <<
|
2018-06-15 08:54:44 -05:00
|
|
|
"], jailPath: [" << jailPath << "], uri: [" << LOOLWSD::anonymizeUrl(uri.toString()) << "].");
|
2016-03-05 09:27:30 -06:00
|
|
|
}
|
2016-02-19 15:19:15 -06:00
|
|
|
|
2016-12-22 15:41:05 -06:00
|
|
|
class LocalFileInfo
|
|
|
|
{
|
2016-10-26 06:15:28 -05:00
|
|
|
public:
|
2018-07-08 21:50:09 -05:00
|
|
|
LocalFileInfo(const std::string& userId,
|
2016-10-26 06:15:28 -05:00
|
|
|
const std::string& username)
|
2018-07-08 21:50:09 -05:00
|
|
|
: _userId(userId),
|
2016-10-26 06:15:28 -05:00
|
|
|
_username(username)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-27 02:09:21 -06:00
|
|
|
const std::string& getUserId() const { return _userId; }
|
|
|
|
const std::string& getUsername() const { return _username; }
|
|
|
|
|
|
|
|
private:
|
2018-07-08 21:50:09 -05:00
|
|
|
std::string _userId;
|
2016-10-26 06:15:28 -05:00
|
|
|
std::string _username;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns the URI specific file data
|
|
|
|
/// Also stores the basic file information which can then be
|
|
|
|
/// obtained using getFileInfo method
|
2017-05-12 10:42:03 -05:00
|
|
|
std::unique_ptr<LocalFileInfo> getLocalFileInfo();
|
2016-03-05 09:27:30 -06:00
|
|
|
|
2017-08-16 09:38:00 -05:00
|
|
|
std::string loadStorageFileToLocal(const Authorization& auth) override;
|
2016-03-05 09:27:30 -06:00
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
SaveResult saveLocalFileToStorage(const Authorization& auth, const std::string& saveAsPath, const std::string& saveAsFilename) override;
|
2016-03-09 17:36:25 -06:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// True if the jailed file is not linked but copied.
|
|
|
|
bool _isCopy;
|
2016-10-26 07:47:42 -05:00
|
|
|
static std::atomic<unsigned> LastLocalStorageId;
|
2016-02-19 15:19:15 -06:00
|
|
|
};
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// WOPI protocol backed storage.
|
2016-03-03 20:05:30 -06:00
|
|
|
class WopiStorage : public StorageBase
|
|
|
|
{
|
|
|
|
public:
|
2016-10-14 05:09:43 -05:00
|
|
|
WopiStorage(const Poco::URI& uri,
|
|
|
|
const std::string& localStorePath,
|
|
|
|
const std::string& jailPath) :
|
2016-10-14 07:46:49 -05:00
|
|
|
StorageBase(uri, localStorePath, jailPath),
|
|
|
|
_wopiLoadDuration(0)
|
2016-03-03 20:05:30 -06:00
|
|
|
{
|
2016-12-22 15:41:05 -06:00
|
|
|
LOG_INF("WopiStorage ctor with localStorePath: [" << localStorePath <<
|
2018-06-15 08:54:44 -05:00
|
|
|
"], jailPath: [" << jailPath << "], uri: [" << LOOLWSD::anonymizeUrl(uri.toString()) << "].");
|
2016-03-03 20:05:30 -06:00
|
|
|
}
|
|
|
|
|
2017-05-19 03:32:24 -05:00
|
|
|
class WOPIFileInfo
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
2016-10-26 06:15:28 -05:00
|
|
|
public:
|
2018-04-24 11:09:37 -05:00
|
|
|
enum class TriState
|
|
|
|
{
|
|
|
|
False,
|
|
|
|
True,
|
|
|
|
Unset
|
|
|
|
};
|
|
|
|
|
2017-05-19 03:32:24 -05:00
|
|
|
WOPIFileInfo(const std::string& userid,
|
2018-07-08 21:50:09 -05:00
|
|
|
const std::string& obfuscatedUserId,
|
2016-10-26 06:15:28 -05:00
|
|
|
const std::string& username,
|
2017-05-28 11:20:49 -05:00
|
|
|
const std::string& userExtraInfo,
|
2017-09-04 08:40:04 -05:00
|
|
|
const std::string& watermarkText,
|
2016-10-26 06:15:28 -05:00
|
|
|
const bool userCanWrite,
|
2016-10-25 02:13:00 -05:00
|
|
|
const std::string& postMessageOrigin,
|
2016-11-10 06:21:39 -06:00
|
|
|
const bool hidePrintOption,
|
|
|
|
const bool hideSaveOption,
|
|
|
|
const bool hideExportOption,
|
2016-11-08 07:37:28 -06:00
|
|
|
const bool enableOwnerTermination,
|
2016-12-13 05:30:43 -06:00
|
|
|
const bool disablePrint,
|
|
|
|
const bool disableExport,
|
|
|
|
const bool disableCopy,
|
2017-08-29 11:59:14 -05:00
|
|
|
const bool disableInactiveMessages,
|
2017-10-03 10:06:02 -05:00
|
|
|
const bool userCanNotWriteRelative,
|
2018-08-17 16:33:15 -05:00
|
|
|
const bool enableInsertRemoteImage,
|
2018-08-18 19:17:25 -05:00
|
|
|
const bool enableShare,
|
2018-04-24 11:09:37 -05:00
|
|
|
const TriState disableChangeTrackingShow,
|
|
|
|
const TriState disableChangeTrackingRecord,
|
|
|
|
const TriState hideChangeTrackingControls,
|
2016-10-26 06:15:28 -05:00
|
|
|
const std::chrono::duration<double> callDuration)
|
2018-07-08 21:50:09 -05:00
|
|
|
: _userId(userid),
|
|
|
|
_obfuscatedUserId(obfuscatedUserId),
|
2016-10-26 06:15:28 -05:00
|
|
|
_username(username),
|
2017-09-04 08:40:04 -05:00
|
|
|
_watermarkText(watermarkText),
|
2016-10-26 06:15:28 -05:00
|
|
|
_userCanWrite(userCanWrite),
|
2016-10-25 02:13:00 -05:00
|
|
|
_postMessageOrigin(postMessageOrigin),
|
2016-11-10 06:21:39 -06:00
|
|
|
_hidePrintOption(hidePrintOption),
|
|
|
|
_hideSaveOption(hideSaveOption),
|
|
|
|
_hideExportOption(hideExportOption),
|
2016-11-08 07:37:28 -06:00
|
|
|
_enableOwnerTermination(enableOwnerTermination),
|
2016-12-13 05:30:43 -06:00
|
|
|
_disablePrint(disablePrint),
|
|
|
|
_disableExport(disableExport),
|
|
|
|
_disableCopy(disableCopy),
|
2017-08-29 11:59:14 -05:00
|
|
|
_disableInactiveMessages(disableInactiveMessages),
|
2017-10-03 10:06:02 -05:00
|
|
|
_userCanNotWriteRelative(userCanNotWriteRelative),
|
2018-08-17 16:33:15 -05:00
|
|
|
_enableInsertRemoteImage(enableInsertRemoteImage),
|
2018-08-18 19:17:25 -05:00
|
|
|
_enableShare(enableShare),
|
2018-04-24 11:09:37 -05:00
|
|
|
_disableChangeTrackingShow(disableChangeTrackingShow),
|
|
|
|
_disableChangeTrackingRecord(disableChangeTrackingRecord),
|
|
|
|
_hideChangeTrackingControls(hideChangeTrackingControls),
|
2016-10-26 06:15:28 -05:00
|
|
|
_callDuration(callDuration)
|
|
|
|
{
|
2017-05-28 11:20:49 -05:00
|
|
|
_userExtraInfo = userExtraInfo;
|
2016-10-26 06:15:28 -05:00
|
|
|
}
|
|
|
|
|
2018-11-21 02:07:52 -06:00
|
|
|
const std::string& getUserId() const { return _userId; }
|
|
|
|
|
|
|
|
const std::string& getUsername() const { return _username; }
|
|
|
|
|
|
|
|
const std::string& getUserExtraInfo() const { return _userExtraInfo; }
|
|
|
|
|
|
|
|
const std::string& getWatermarkText() const { return _watermarkText; }
|
|
|
|
|
|
|
|
bool getUserCanWrite() const { return _userCanWrite; }
|
|
|
|
|
|
|
|
std::string& getPostMessageOrigin() { return _postMessageOrigin; }
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
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 getUserCanNotWriteRelative() const { return _userCanNotWriteRelative; }
|
|
|
|
|
|
|
|
bool getEnableInsertRemoteImage() const { return _enableInsertRemoteImage; }
|
|
|
|
|
|
|
|
bool getEnableShare() const { return _enableShare; }
|
|
|
|
|
|
|
|
TriState getDisableChangeTrackingShow() const { return _disableChangeTrackingShow; }
|
|
|
|
|
|
|
|
TriState getDisableChangeTrackingRecord() const { return _disableChangeTrackingRecord; }
|
|
|
|
|
|
|
|
TriState getHideChangeTrackingControls() const { return _hideChangeTrackingControls; }
|
|
|
|
|
|
|
|
std::chrono::duration<double> getCallDuration() const { return _callDuration; }
|
|
|
|
|
|
|
|
private:
|
2016-10-26 06:15:28 -05:00
|
|
|
/// User id of the user accessing the file
|
2018-07-08 21:50:09 -05:00
|
|
|
std::string _userId;
|
|
|
|
/// Obfuscated User id used for logging the UserId.
|
|
|
|
std::string _obfuscatedUserId;
|
2016-10-26 06:15:28 -05:00
|
|
|
/// Display Name of user accessing the file
|
|
|
|
std::string _username;
|
2017-05-28 11:20:49 -05:00
|
|
|
/// Extra info per user, typically mail and other links, as json.
|
|
|
|
std::string _userExtraInfo;
|
2017-09-04 08:40:04 -05:00
|
|
|
/// In case a watermark has to be rendered on each tile.
|
|
|
|
std::string _watermarkText;
|
2016-10-26 06:15:28 -05:00
|
|
|
/// If user accessing the file has write permission
|
|
|
|
bool _userCanWrite;
|
2016-10-25 02:13:00 -05:00
|
|
|
/// WOPI Post message property
|
|
|
|
std::string _postMessageOrigin;
|
2016-11-10 06:21:39 -06:00
|
|
|
/// Hide print button from UI
|
|
|
|
bool _hidePrintOption;
|
|
|
|
/// Hide save button from UI
|
|
|
|
bool _hideSaveOption;
|
|
|
|
/// Hide 'Download as' button/menubar item from UI
|
|
|
|
bool _hideExportOption;
|
2016-11-08 07:37:28 -06:00
|
|
|
/// If WOPI host has enabled owner termination feature on
|
|
|
|
bool _enableOwnerTermination;
|
2016-12-13 05:30:43 -06:00
|
|
|
/// If WOPI host has allowed the user to print the document
|
|
|
|
bool _disablePrint;
|
|
|
|
/// If WOPI host has allowed the user to export the document
|
|
|
|
bool _disableExport;
|
|
|
|
/// If WOPI host has allowed the user to copy to/from the document
|
|
|
|
bool _disableCopy;
|
2017-08-29 11:59:14 -05:00
|
|
|
/// If WOPI host has allowed the loleaflet to show texts on the overlay informing about inactivity, or if the integration is handling that.
|
|
|
|
bool _disableInactiveMessages;
|
2017-10-03 10:06:02 -05:00
|
|
|
/// If set to false, users can access the save-as functionality
|
|
|
|
bool _userCanNotWriteRelative;
|
2018-08-17 16:33:15 -05:00
|
|
|
/// if set to true, users can access the insert remote image functionality
|
|
|
|
bool _enableInsertRemoteImage;
|
2018-08-18 19:17:25 -05:00
|
|
|
/// if set to true, users can access the file share functionality
|
|
|
|
bool _enableShare;
|
2018-04-24 11:09:37 -05:00
|
|
|
/// If we should disable change-tracking visibility by default (meaningful at loading).
|
|
|
|
TriState _disableChangeTrackingShow;
|
|
|
|
/// If we should disable change-tracking ability by default (meaningful at loading).
|
|
|
|
TriState _disableChangeTrackingRecord;
|
|
|
|
/// If we should hide change-tracking commands for this user.
|
|
|
|
TriState _hideChangeTrackingControls;
|
|
|
|
|
2016-10-26 06:15:28 -05:00
|
|
|
/// Time it took to call WOPI's CheckFileInfo
|
|
|
|
std::chrono::duration<double> _callDuration;
|
|
|
|
};
|
|
|
|
|
2017-05-12 10:42:03 -05:00
|
|
|
/// Returns the response of CheckFileInfo WOPI call for URI that was
|
|
|
|
/// provided during the initial creation of the WOPI storage.
|
2016-10-26 06:15:28 -05:00
|
|
|
/// Also extracts the basic file information from the response
|
|
|
|
/// which can then be obtained using getFileInfo()
|
2017-08-16 09:38:00 -05:00
|
|
|
std::unique_ptr<WOPIFileInfo> getWOPIFileInfo(const Authorization& auth);
|
2016-03-21 18:12:00 -05:00
|
|
|
|
2016-03-03 20:05:30 -06:00
|
|
|
/// uri format: http://server/<...>/wopi*/files/<id>/content
|
2017-08-16 09:38:00 -05:00
|
|
|
std::string loadStorageFileToLocal(const Authorization& auth) override;
|
2016-03-11 12:45:13 -06:00
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
SaveResult saveLocalFileToStorage(const Authorization& auth, const std::string& saveAsPath, const std::string& saveAsFilename) override;
|
2016-10-14 07:46:49 -05:00
|
|
|
|
2016-10-23 07:05:46 -05:00
|
|
|
/// Total time taken for making WOPI calls during load
|
|
|
|
std::chrono::duration<double> getWopiLoadDuration() const { return _wopiLoadDuration; }
|
2016-10-14 07:46:49 -05:00
|
|
|
|
|
|
|
private:
|
2016-10-23 07:05:46 -05:00
|
|
|
// Time spend in loading the file from storage
|
2016-10-14 07:46:49 -05:00
|
|
|
std::chrono::duration<double> _wopiLoadDuration;
|
2016-03-03 20:05:30 -06:00
|
|
|
};
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// WebDAV protocol backed storage.
|
2016-02-19 15:19:15 -06:00
|
|
|
class WebDAVStorage : public StorageBase
|
|
|
|
{
|
|
|
|
public:
|
2016-10-14 05:09:43 -05:00
|
|
|
WebDAVStorage(const Poco::URI& uri,
|
|
|
|
const std::string& localStorePath,
|
2016-03-05 09:27:30 -06:00
|
|
|
const std::string& jailPath,
|
2016-03-03 20:05:30 -06:00
|
|
|
std::unique_ptr<AuthBase> authAgent) :
|
2016-10-14 05:09:43 -05:00
|
|
|
StorageBase(uri, localStorePath, jailPath),
|
2016-02-19 15:19:15 -06:00
|
|
|
_authAgent(std::move(authAgent))
|
|
|
|
{
|
2016-12-22 15:41:05 -06:00
|
|
|
LOG_INF("WebDAVStorage ctor with localStorePath: [" << localStorePath <<
|
2018-06-15 08:54:44 -05:00
|
|
|
"], jailPath: [" << jailPath << "], uri: [" << LOOLWSD::anonymizeUrl(uri.toString()) << "].");
|
2016-02-19 15:19:15 -06:00
|
|
|
}
|
|
|
|
|
2016-10-26 06:15:28 -05:00
|
|
|
// Implement me
|
|
|
|
// WebDAVFileInfo getWebDAVFileInfo(const Poco::URI& uriPublic);
|
2016-03-21 18:12:00 -05:00
|
|
|
|
2017-08-16 09:38:00 -05:00
|
|
|
std::string loadStorageFileToLocal(const Authorization& auth) override;
|
2016-02-19 15:19:15 -06:00
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
SaveResult saveLocalFileToStorage(const Authorization& auth, const std::string& saveAsPath, const std::string& saveAsFilename) override;
|
2016-04-16 11:53:42 -05:00
|
|
|
|
2016-02-19 15:19:15 -06:00
|
|
|
private:
|
|
|
|
std::unique_ptr<AuthBase> _authAgent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2016-04-08 03:08:41 -05:00
|
|
|
|
2016-02-19 15:19:15 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|