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.
2020-04-18 03:39:50 -05:00
# pragma once
2016-02-19 15:19:15 -06:00
2016-04-16 17:12:10 -05:00
# include <set>
2016-10-29 20:15:00 -05:00
# include <string>
2019-11-27 02:43:05 -06:00
# include <chrono>
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>
2019-10-07 06:51:30 -05:00
# include <Poco/Net/HTTPClientSession.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
2019-11-19 16:51:45 -06:00
/// Represents whether the underlying file is locked
/// and with what token.
struct LockContext
{
/// Do we have support for locking for a storage.
bool _supportsLocks ;
/// Do we own the (leased) lock currently
bool _isLocked ;
/// Name if we need it to use consistently for locking
std : : string _lockToken ;
2019-11-27 02:43:05 -06:00
/// Time of last successful lock (re-)acquisition
std : : chrono : : steady_clock : : time_point _lastLockTime ;
2019-11-19 16:51:45 -06:00
LockContext ( ) : _supportsLocks ( false ) , _isLocked ( false ) { }
/// one-time setup for supporting locks & create token
void initSupportsLocks ( ) ;
2019-11-27 02:43:05 -06:00
/// do we need to refresh our lock ?
bool needsRefresh ( const std : : chrono : : steady_clock : : time_point & now ) const ;
2019-12-16 01:33:16 -06:00
void dumpState ( std : : ostream & os ) const ;
2019-11-19 16:51:45 -06:00
} ;
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 ,
2019-08-30 12:37:55 -05:00
const std : : chrono : : system_clock : : time_point & 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 ; }
2019-08-30 12:37:55 -05:00
void setModifiedTime ( const std : : chrono : : system_clock : : time_point & modifiedTime ) { _modifiedTime = modifiedTime ; }
2018-11-29 01:42:43 -06:00
2019-08-30 12:37:55 -05:00
const std : : chrono : : system_clock : : time_point & getModifiedTime ( ) const { return _modifiedTime ; }
2018-11-29 01:42:43 -06:00
private :
2016-04-19 02:10:07 -05:00
std : : string _filename ;
2016-11-08 02:14:14 -06:00
std : : string _ownerId ;
2019-08-30 12:37:55 -05:00
std : : chrono : : system_clock : : time_point _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 ) ,
2019-08-30 12:37:55 -05:00
_fileInfo ( " " , " lool " , std : : chrono : : system_clock : : time_point ( ) , 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 ) ,
2019-08-21 02:06:44 -05:00
_isAutosave ( false ) ,
_isExitSave ( 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 ;
}
2018-12-07 06:39:10 -06:00
void setLoaded ( bool loaded ) { _isLoaded = loaded ; }
2018-11-28 02:07:29 -06:00
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.
2018-12-07 06:39:10 -06:00
void setUserModified ( bool userModified ) { _isUserModified = userModified ; }
2017-09-25 12:16:48 -05:00
2018-11-28 02:07:29 -06:00
bool isUserModified ( ) const { return _isUserModified ; }
2018-12-04 01:49:49 -06:00
/// To be able to set the WOPI 'is autosave/is exitsave?' headers appropriately.
2017-10-03 04:59:39 -05:00
void setIsAutosave ( bool isAutosave ) { _isAutosave = isAutosave ; }
2018-11-28 02:07:29 -06:00
bool getIsAutosave ( ) const { return _isAutosave ; }
2018-12-07 06:39:10 -06:00
void setIsExitSave ( bool exitSave ) { _isExitSave = exitSave ; }
2018-12-04 01:49:49 -06:00
bool isExitSave ( ) const { return _isExitSave ; }
2019-06-16 13:42:11 -05:00
void setExtendedData ( const std : : string & extendedData ) { _extendedData = extendedData ; }
2018-11-28 02:07:29 -06:00
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
2019-11-19 16:51:45 -06:00
/// Update the locking state (check-in/out) of the associated file
2020-01-18 15:04:26 -06:00
virtual bool updateLockState ( const Authorization & auth , const std : : string & cookies ,
LockContext & lockCtx , bool lock )
= 0 ;
2019-11-19 16:51:45 -06:00
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.
2020-01-18 15:04:26 -06:00
virtual std : : string loadStorageFileToLocal ( const Authorization & auth ,
const std : : string & /*cookies*/ , LockContext & lockCtx ,
const std : : string & templateUri )
= 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.
2020-01-18 15:04:26 -06:00
/// @param cookies A string representing key=value pairs that are set as cookies.
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.
2020-01-18 15:04:26 -06:00
virtual SaveResult
saveLocalFileToStorage ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx , const std : : string & saveAsPath ,
const std : : string & saveAsFilename , const bool isRename )
= 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 ) ;
2019-10-07 06:51:30 -05:00
static Poco : : Net : : HTTPClientSession * getHTTPClientSession ( const Poco : : URI & uri ) ;
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
2019-06-16 13:42:11 -05:00
/// Returns the client-provided extended data to send to the WOPI host.
const std : : string & getExtendedData ( ) const { return _extendedData ; }
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 ;
2018-12-04 01:49:49 -06:00
/// Saving on exit (when the document is cleaned up from memory)
bool _isExitSave ;
2019-06-16 13:42:11 -05:00
/// The client-provided saving extended data to send to the WOPI host.
std : : string _extendedData ;
2017-10-03 04:59:39 -05:00
2016-06-07 02:18:49 -05:00
static bool FilesystemEnabled ;
static bool WopiEnabled ;
2019-10-07 06:51:30 -05:00
static bool SSLEnabled ;
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
2020-01-18 15:04:26 -06:00
bool updateLockState ( const Authorization & , const std : : string & , LockContext & , bool ) override
{
return true ;
}
2019-11-19 16:51:45 -06:00
2020-01-18 15:04:26 -06:00
std : : string loadStorageFileToLocal ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx ,
const std : : string & templateUri ) override ;
2016-03-05 09:27:30 -06:00
2020-01-18 15:04:26 -06:00
SaveResult saveLocalFileToStorage ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx , const std : : string & saveAsPath ,
const std : : string & saveAsFilename ,
const bool isRename ) 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 ) ,
2019-08-26 20:16:54 -05:00
_wopiLoadDuration ( 0 ) ,
2019-11-12 03:50:33 -06:00
_wopiSaveDuration ( 0 ) ,
2019-08-26 20:16:54 -05:00
_reuseCookies ( false )
2016-03-03 20:05:30 -06:00
{
2019-08-26 20:16:54 -05:00
const auto & app = Poco : : Util : : Application : : instance ( ) ;
_reuseCookies = app . config ( ) . getBool ( " storage.wopi.reuse_cookies " , false ) ;
LOG_INF ( " WopiStorage ctor with localStorePath: [ "
< < localStorePath < < " ], jailPath: [ " < < jailPath < < " ], uri: [ "
< < LOOLWSD : : anonymizeUrl ( uri . toString ( ) ) < < " ], reuseCookies: [ " < < _reuseCookies
< < " ]. " ) ;
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 ,
2018-11-14 13:16:26 -06:00
const std : : string & templateSaveAs ,
2019-05-21 22:33:26 -05:00
const std : : string & templateSource ,
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 ,
2019-06-04 06:57:53 -05:00
const bool downloadAsPostMessage ,
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-12-12 07:51:37 -06:00
const std : : string & hideUserList ,
2018-04-24 11:09:37 -05:00
const TriState disableChangeTrackingShow ,
const TriState disableChangeTrackingRecord ,
const TriState hideChangeTrackingControls ,
2019-11-19 14:54:29 -06:00
const bool supportsLocks ,
2019-04-30 09:21:44 -05:00
const bool supportsRename ,
const bool userCanRename ,
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 ) ,
2018-11-14 13:16:26 -06:00
_templateSaveAs ( templateSaveAs ) ,
2019-05-21 22:33:26 -05:00
_templateSource ( templateSource ) ,
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 ) ,
2019-06-04 06:57:53 -05:00
_downloadAsPostMessage ( downloadAsPostMessage ) ,
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-12-12 04:05:31 -06:00
_hideUserList ( hideUserList ) ,
2018-04-24 11:09:37 -05:00
_disableChangeTrackingShow ( disableChangeTrackingShow ) ,
_disableChangeTrackingRecord ( disableChangeTrackingRecord ) ,
_hideChangeTrackingControls ( hideChangeTrackingControls ) ,
2019-11-19 14:54:29 -06:00
_supportsLocks ( supportsLocks ) ,
2019-04-30 09:21:44 -05:00
_supportsRename ( supportsRename ) ,
_userCanRename ( userCanRename ) ,
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 ; }
2018-11-14 13:16:26 -06:00
const std : : string & getTemplateSaveAs ( ) const { return _templateSaveAs ; }
2019-05-21 22:33:26 -05:00
const std : : string & getTemplateSource ( ) const { return _templateSource ; }
2018-11-21 02:07:52 -06:00
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 ; }
2019-06-04 06:57:53 -05:00
bool getDownloadAsPostMessage ( ) const { return _downloadAsPostMessage ; }
2018-11-21 02:07:52 -06:00
bool getUserCanNotWriteRelative ( ) const { return _userCanNotWriteRelative ; }
bool getEnableInsertRemoteImage ( ) const { return _enableInsertRemoteImage ; }
bool getEnableShare ( ) const { return _enableShare ; }
2019-04-30 09:21:44 -05:00
bool getSupportsRename ( ) const { return _supportsRename ; }
2019-11-19 14:54:29 -06:00
bool getSupportsLocks ( ) const { return _supportsLocks ; }
2019-04-30 09:21:44 -05:00
bool getUserCanRename ( ) const { return _userCanRename ; }
2018-12-15 08:57:57 -06:00
std : : string & getHideUserList ( ) { return _hideUserList ; }
2018-12-15 08:23:58 -06:00
2018-11-21 02:07:52 -06:00
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 ;
2018-11-14 13:16:26 -06:00
/// 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 ;
2019-05-21 22:33:26 -05:00
/// In case we want to use this file as a template.
std : : string _templateSource ;
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 ;
2019-06-04 06:57:53 -05:00
/// 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 ;
2017-10-03 10:06:02 -05:00
/// If set to false, users can access the save-as functionality
bool _userCanNotWriteRelative ;
2018-12-12 04:05:31 -06:00
/// If set to true, users can access the insert remote image functionality
2018-08-17 16:33:15 -05:00
bool _enableInsertRemoteImage ;
2018-12-12 04:05:31 -06:00
/// If set to true, users can access the file share functionality
2018-08-18 19:17:25 -05:00
bool _enableShare ;
2018-12-12 07:51:37 -06:00
/// 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 ;
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 ;
2019-11-19 14:54:29 -06:00
/// If WOPI host supports locking
bool _supportsLocks ;
2019-04-30 09:21:44 -05:00
/// If WOPI host supports rename
bool _supportsRename ;
/// If user is allowed to rename the document
bool _userCanRename ;
2018-04-24 11:09:37 -05:00
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()
2019-11-19 16:51:45 -06:00
/// Also sets up the locking context for future operations.
std : : unique_ptr < WOPIFileInfo > getWOPIFileInfo ( const Authorization & auth ,
2020-01-18 15:04:26 -06:00
const std : : string & cookies , LockContext & lockCtx ) ;
2019-11-19 16:51:45 -06:00
/// Update the locking state (check-in/out) of the associated file
2020-01-18 15:04:26 -06:00
bool updateLockState ( const Authorization & auth , const std : : string & cookies ,
LockContext & lockCtx , bool lock ) override ;
2016-03-21 18:12:00 -05:00
2016-03-03 20:05:30 -06:00
/// uri format: http://server/<...>/wopi*/files/<id>/content
2020-01-18 15:04:26 -06:00
std : : string loadStorageFileToLocal ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx ,
const std : : string & templateUri ) override ;
2016-03-11 12:45:13 -06:00
2020-01-18 15:04:26 -06:00
SaveResult saveLocalFileToStorage ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx , const std : : string & saveAsPath ,
const std : : string & saveAsFilename ,
const bool isRename ) 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 ; }
2019-11-12 03:50:33 -06:00
std : : chrono : : duration < double > getWopiSaveDuration ( ) const { return _wopiSaveDuration ; }
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 ;
2019-11-12 03:50:33 -06:00
std : : chrono : : duration < double > _wopiSaveDuration ;
2019-08-26 20:16:54 -05:00
/// Whether or not to re-use cookies from the browser for the WOPI requests.
bool _reuseCookies ;
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
2020-01-18 15:04:26 -06:00
bool updateLockState ( const Authorization & , const std : : string & , LockContext & , bool ) override
{
return true ;
}
2019-11-19 16:51:45 -06:00
2020-01-18 15:04:26 -06:00
std : : string loadStorageFileToLocal ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx ,
const std : : string & templateUri ) override ;
2016-02-19 15:19:15 -06:00
2020-01-18 15:04:26 -06:00
SaveResult saveLocalFileToStorage ( const Authorization & auth , const std : : string & /*cookies*/ ,
LockContext & lockCtx , const std : : string & saveAsPath ,
const std : : string & saveAsFilename ,
const bool isRename ) override ;
2016-04-16 11:53:42 -05:00
2016-02-19 15:19:15 -06:00
private :
std : : unique_ptr < AuthBase > _authAgent ;
} ;
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */