2016-03-10 20:42:33 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2016-03-10 20:42:33 -06:00
|
|
|
|
2016-08-30 02:06:39 -05:00
|
|
|
#include <csignal>
|
2016-04-03 20:40:14 -05:00
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
#include <atomic>
|
2016-04-10 21:07:09 -05:00
|
|
|
#include <chrono>
|
2016-05-16 22:02:05 -05:00
|
|
|
#include <condition_variable>
|
2017-03-06 09:05:11 -06:00
|
|
|
#include <deque>
|
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 <map>
|
|
|
|
#include <memory>
|
2016-03-10 20:42:33 -06:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2016-05-02 06:21:30 -05:00
|
|
|
#include <thread>
|
2020-11-29 22:57:19 -06:00
|
|
|
#include <utility>
|
2016-03-10 20:42:33 -06:00
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
#include <Poco/URI.h>
|
2016-03-25 21:56:18 -05:00
|
|
|
|
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-12-21 14:37:22 -06:00
|
|
|
#include "TileDesc.hpp"
|
2016-03-23 11:55:28 -05:00
|
|
|
#include "Util.hpp"
|
2017-03-04 17:07:17 -06:00
|
|
|
#include "net/Socket.hpp"
|
2017-03-06 13:50:06 -06:00
|
|
|
#include "net/WebSocketHandler.hpp"
|
2020-11-15 15:47:35 -06:00
|
|
|
#include "Storage.hpp"
|
2016-03-25 21:56:18 -05:00
|
|
|
|
2016-11-14 07:58:04 -06:00
|
|
|
#include "common/SigUtil.hpp"
|
2020-01-02 15:11:54 -06:00
|
|
|
#include "common/Session.hpp"
|
2016-11-14 07:58:04 -06:00
|
|
|
|
2019-11-28 10:09:58 -06:00
|
|
|
#if !MOBILEAPP
|
2019-11-12 03:50:33 -06:00
|
|
|
#include "Admin.hpp"
|
2019-11-28 10:09:58 -06:00
|
|
|
#endif
|
2019-11-12 03:50:33 -06:00
|
|
|
|
2016-03-25 21:56:18 -05:00
|
|
|
// Forwards.
|
2017-03-06 13:50:06 -06:00
|
|
|
class PrisonerRequestDispatcher;
|
2016-05-16 19:49:36 -05:00
|
|
|
class DocumentBroker;
|
2019-11-21 10:28:19 -06:00
|
|
|
struct LockContext;
|
2016-12-21 14:37:22 -06:00
|
|
|
class TileCache;
|
2017-01-22 22:18:37 -06:00
|
|
|
class Message;
|
2016-03-10 20:42:33 -06:00
|
|
|
|
2020-04-02 10:11:36 -05:00
|
|
|
#include "LOOLWSD.hpp"
|
|
|
|
|
2021-05-25 02:16:54 -05:00
|
|
|
/// A ChildProcess object represents a Kit process that hosts a document and manipulates the
|
2020-04-18 08:44:50 -05:00
|
|
|
/// document using the LibreOfficeKit API. It isn't actually a child of the WSD process, but a
|
|
|
|
/// grandchild. The comments loosely talk about "child" anyway.
|
|
|
|
|
2020-04-02 10:11:36 -05:00
|
|
|
class ChildProcess : public WSProcess
|
2016-04-03 20:40:14 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-04-29 05:06:45 -05:00
|
|
|
/// @param pid is the process ID of the child.
|
2020-10-31 14:08:08 -05:00
|
|
|
/// @param socket is the underlying Socket to the child.
|
2019-11-26 07:15:38 -06:00
|
|
|
ChildProcess(const pid_t pid,
|
2017-05-07 10:05:34 -05:00
|
|
|
const std::string& jailId,
|
|
|
|
const std::shared_ptr<StreamSocket>& socket,
|
|
|
|
const Poco::Net::HTTPRequest &request) :
|
2020-04-02 10:11:36 -05:00
|
|
|
WSProcess("ChildProcess", pid, socket, std::make_shared<WebSocketHandler>(socket, request)),
|
2020-04-23 05:35:42 -05:00
|
|
|
_jailId(jailId),
|
|
|
|
_smapsFD(-1)
|
2016-04-03 20:40:14 -05:00
|
|
|
{
|
|
|
|
}
|
2018-09-11 01:30:55 -05:00
|
|
|
|
2016-05-01 19:30:52 -05:00
|
|
|
ChildProcess(ChildProcess&& other) = delete;
|
2016-04-03 20:40:14 -05:00
|
|
|
|
2020-04-23 05:35:42 -05:00
|
|
|
virtual ~ChildProcess(){ ::close(_smapsFD); }
|
|
|
|
|
2016-05-01 19:30:52 -05:00
|
|
|
const ChildProcess& operator=(ChildProcess&& other) = delete;
|
2016-04-03 20:40:14 -05:00
|
|
|
|
2017-03-07 22:46:02 -06:00
|
|
|
void setDocumentBroker(const std::shared_ptr<DocumentBroker>& docBroker);
|
2017-03-12 18:18:12 -05:00
|
|
|
std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker.lock(); }
|
2017-05-07 10:05:34 -05:00
|
|
|
const std::string& getJailId() const { return _jailId; }
|
2020-04-23 05:35:42 -05:00
|
|
|
void setSMapsFD(int smapsFD) { _smapsFD = smapsFD;}
|
|
|
|
int getSMapsFD(){ return _smapsFD; }
|
2016-10-11 17:22:51 -05:00
|
|
|
|
2016-04-03 20:40:14 -05:00
|
|
|
private:
|
2017-05-07 10:05:34 -05:00
|
|
|
const std::string _jailId;
|
2016-05-02 06:21:30 -05:00
|
|
|
std::weak_ptr<DocumentBroker> _docBroker;
|
2020-04-23 05:35:42 -05:00
|
|
|
int _smapsFD;
|
2016-04-03 20:40:14 -05:00
|
|
|
};
|
|
|
|
|
2020-05-12 15:10:56 -05:00
|
|
|
class RequestDetails;
|
2016-05-16 06:46:27 -05:00
|
|
|
class ClientSession;
|
2016-05-16 06:37:02 -05:00
|
|
|
|
2020-04-18 02:41:39 -05:00
|
|
|
/// DocumentBroker is responsible for setting up a document in jail and brokering loading it from
|
|
|
|
/// Storage and saving it back.
|
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
/// Contains URI, physical path, etc.
|
2020-04-18 02:41:39 -05:00
|
|
|
|
|
|
|
/// There is one DocumentBroker object in the WSD process for each document that is open (in 1..n sessions).
|
|
|
|
|
2020-12-02 21:53:50 -06:00
|
|
|
/// The Document State:
|
|
|
|
///
|
|
|
|
/// The Document lifecycle is managed through
|
|
|
|
/// the DocumentState class, which encapsulates
|
|
|
|
/// the different stages of the Document's
|
|
|
|
/// main-sequence events:
|
|
|
|
///
|
2021-01-26 19:40:22 -06:00
|
|
|
/// To disambiguate between Storage and Core, we
|
|
|
|
/// use 'Download' for Reading from the Storage,
|
|
|
|
/// and 'Load' for Loading a document in Core.
|
|
|
|
/// Similarly, we 'Upload' to Storage after we
|
|
|
|
/// 'Save' the document in Core.
|
2020-12-02 21:53:50 -06:00
|
|
|
///
|
|
|
|
/// None: the Document doesn't exist, pending downloading.
|
|
|
|
/// Downloading: the Document is being downloaded from Storage.
|
|
|
|
/// Loading: the Document is being loaded into Core.
|
|
|
|
/// Live: Steady-state; the document is available (see below).
|
|
|
|
/// Destroying: End-of-life, marked to save/upload and destroy.
|
|
|
|
/// Destroyed: Unloading complete, destruction of class pending.
|
|
|
|
///
|
|
|
|
|
|
|
|
/// The Document Data State:
|
|
|
|
///
|
|
|
|
/// There are three locations to track:
|
|
|
|
/// 1) the Storage (wopi host)
|
|
|
|
/// 2) the Local file on disk (in jail)
|
|
|
|
/// 3) in memory (in Core).
|
|
|
|
///
|
|
|
|
/// We download the document from Storage to disk, then
|
|
|
|
/// we load it in memory (Core). From then on, we track the
|
|
|
|
/// state after modification (in memory), saving (to disk),
|
|
|
|
/// and uploading (to Storage).
|
|
|
|
///
|
|
|
|
/// Download: Storage -> Local
|
|
|
|
/// Load: Local -> Core
|
|
|
|
/// Save: Core -> Local
|
|
|
|
/// Upload: Local -> Storage
|
|
|
|
///
|
|
|
|
/// This is the state matrix during the key operations:
|
|
|
|
/// |-------------------------------------------|
|
|
|
|
/// | State | Storage | Local | Core |
|
|
|
|
/// |-------------|---------|---------|---------|
|
|
|
|
/// | Downloading | Reading | Writing | Idle |
|
|
|
|
/// | Loading | Idle | Reading | Writing |
|
|
|
|
/// | Saving | Idle | Writing | Reading |
|
|
|
|
/// | Uploading | Writing | Reading | Idle |
|
|
|
|
/// |-------------------------------------------|
|
|
|
|
///
|
|
|
|
/// Downloading is done synchronously, for now, but
|
|
|
|
/// is provisioned for async in the state machine.
|
|
|
|
/// Similarly, we could download asynchronously,
|
|
|
|
/// but there is little to gain by doing that,
|
|
|
|
/// since nothing much can happen without, or
|
|
|
|
/// before, loading a document.
|
|
|
|
///
|
|
|
|
/// The decision for Saving and Uploading are separate.
|
|
|
|
/// Without the user's intervention, we auto-save
|
|
|
|
/// when the user has been idle for some configurable
|
|
|
|
/// time, or when a certain configurable minimum time
|
|
|
|
/// has elapsed since the last save (regardless of user
|
|
|
|
/// activity). Once we get the save result from Core
|
|
|
|
/// (and ideally with success), we upload the document
|
|
|
|
/// immediately. Previously, this was a synchronous
|
|
|
|
/// process, which is now being reworked into an asynch.
|
|
|
|
///
|
|
|
|
/// The user can invoke both Save and Upload operations
|
|
|
|
/// however, and in more than one way.
|
|
|
|
/// Saving can of course be done by simply invoking the
|
|
|
|
/// command, which also uploads.
|
|
|
|
/// Forced Uploading has a narrower use-case: when the
|
|
|
|
/// Storage has a newer version of the document,
|
|
|
|
/// uploading fails with 'document conflict' error, which
|
|
|
|
/// the user can override by forcing uploading to Storage,
|
|
|
|
/// thereby overwriting the Storage version with the
|
|
|
|
/// current one.
|
|
|
|
/// Then there are the Save-As and Rename commands, which
|
|
|
|
/// only affect the document in Storage by invoking
|
|
|
|
/// the upload functionality with special headers.
|
|
|
|
///
|
|
|
|
/// When either of these operations fails, the next
|
|
|
|
/// opportunity to review potential actions is during
|
|
|
|
/// the next poll cycle.
|
|
|
|
/// To separate these two operations in code and in time,
|
|
|
|
/// we need to track the document version in each of
|
|
|
|
/// Core and Storage. That is, when the document is saved
|
|
|
|
/// a newer 'version number' is assigned, so that it would
|
|
|
|
/// be different from the 'version number' of the document
|
|
|
|
/// in Storage. The easiest way to achieve this is by
|
|
|
|
/// using the modified time on the file on disk. While
|
|
|
|
/// this has certain limitations, in practice it's a
|
|
|
|
/// good solution. We expect each time Core saves the
|
|
|
|
/// Document to disk, the file's timestamp will change.
|
|
|
|
/// Each time we Upload a version of the Document to
|
|
|
|
/// Storage, we track the local file's timestamp that we
|
|
|
|
/// uploaded. We then need to Upload only when the last
|
|
|
|
/// Uploaded timestamp is different from that on disk.
|
|
|
|
/// Although it's technically possible for the system
|
|
|
|
/// clock to change, it's unlikely for the timestamp to
|
|
|
|
/// be identical to the last Uploaded one, down to the
|
|
|
|
/// millisecond.
|
|
|
|
///
|
|
|
|
/// This way, if, say, Uploading fails after
|
|
|
|
/// Saving, if the subsequent Save fails, we don't skip
|
|
|
|
/// Uploading, since the Storage would still be outdated.
|
|
|
|
/// Similarly, if after Saving we fail to Upload, a
|
|
|
|
/// subsequent Save might yield 'unmodified' result and
|
|
|
|
/// fail to Save a new copy of the document. This should
|
|
|
|
/// not skip Uploading, since the document on disk is
|
|
|
|
/// still newer than the one in Storage.
|
|
|
|
///
|
|
|
|
/// Notice that we cannot compare the timestamp of the
|
|
|
|
/// file on disk to the timestamp returned from Storage.
|
|
|
|
/// For one, the Storage might not even provide a
|
|
|
|
/// timestamp (or a valid one). But more importantly,
|
|
|
|
/// the timestamp on disk might not be comparable to
|
|
|
|
/// that in Storage (due to timezone and/or precision
|
|
|
|
/// differences).
|
|
|
|
///
|
|
|
|
/// Two new managers are provisioned to mind about these
|
|
|
|
/// two domains: SaveManager and StorageManager.
|
|
|
|
/// SaveManager is reponsible for tracking the operations
|
|
|
|
/// between Core and local disk, while StorageManager
|
|
|
|
/// for those between Storage and local disk.
|
|
|
|
/// In practice, each represents and tracks the state of
|
|
|
|
/// the Document in Core and Storage, respectively.
|
|
|
|
///
|
2021-01-26 19:40:22 -06:00
|
|
|
|
2016-10-12 22:04:07 -05:00
|
|
|
class DocumentBroker : public std::enable_shared_from_this<DocumentBroker>
|
2016-03-10 20:42:33 -06:00
|
|
|
{
|
2017-03-07 11:34:01 -06:00
|
|
|
class DocumentBrokerPoll;
|
2020-05-02 13:13:14 -05:00
|
|
|
|
|
|
|
void setupPriorities();
|
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
public:
|
2020-05-02 13:13:14 -05:00
|
|
|
/// How to prioritize this document.
|
|
|
|
enum class ChildType {
|
|
|
|
Interactive, Batch
|
|
|
|
};
|
|
|
|
|
2016-04-13 03:05:00 -05:00
|
|
|
static Poco::URI sanitizeURI(const std::string& uri);
|
2016-03-19 17:49:36 -05:00
|
|
|
|
|
|
|
/// Returns a document-specific key based
|
|
|
|
/// on the URI of the document.
|
2016-10-29 20:15:00 -05:00
|
|
|
static std::string getDocKey(const Poco::URI& uri);
|
2016-09-15 05:41:57 -05:00
|
|
|
|
|
|
|
/// Dummy document broker that is marked to destroy.
|
|
|
|
DocumentBroker();
|
2016-03-12 18:29:17 -06:00
|
|
|
|
2020-05-02 13:13:14 -05:00
|
|
|
DocumentBroker(ChildType type,
|
|
|
|
const std::string& uri,
|
2017-02-05 20:59:08 -06:00
|
|
|
const Poco::URI& uriPublic,
|
2020-04-24 02:46:54 -05:00
|
|
|
const std::string& docKey,
|
|
|
|
unsigned mobileAppDocId = 0);
|
2017-03-09 13:23:21 -06:00
|
|
|
|
2019-03-01 15:25:44 -06:00
|
|
|
virtual ~DocumentBroker();
|
2016-03-12 18:29:17 -06:00
|
|
|
|
2019-10-04 04:30:49 -05:00
|
|
|
/// Called when removed from the DocBrokers list
|
|
|
|
virtual void dispose() {}
|
|
|
|
|
2020-12-04 11:43:47 -06:00
|
|
|
/// setup the transfer of a socket into this DocumentBroker poll.
|
|
|
|
void setupTransfer(SocketDisposition &disposition,
|
|
|
|
SocketDisposition::MoveFunction transferFn);
|
2017-03-13 07:00:31 -05:00
|
|
|
|
2018-02-02 01:47:45 -06:00
|
|
|
/// Flag for termination. Note that this doesn't save any unsaved changes in the document
|
2018-01-14 19:49:11 -06:00
|
|
|
void stop(const std::string& reason);
|
2017-03-29 21:50:29 -05:00
|
|
|
|
2019-07-04 04:50:33 -05:00
|
|
|
/// Hard removes a session by ID, only for ClientSession.
|
|
|
|
void finalRemoveSession(const std::string& id);
|
|
|
|
|
2020-03-04 15:56:48 -06:00
|
|
|
/// Create new client session
|
2020-03-06 11:43:46 -06:00
|
|
|
std::shared_ptr<ClientSession> createNewClientSession(
|
|
|
|
const std::shared_ptr<ProtocolHandlerInterface> &ws,
|
|
|
|
const std::string& id,
|
|
|
|
const Poco::URI& uriPublic,
|
|
|
|
const bool isReadOnly,
|
2020-05-12 15:10:56 -05:00
|
|
|
const RequestDetails &requestDetails);
|
2020-03-04 15:56:48 -06:00
|
|
|
|
2020-03-04 07:54:04 -06:00
|
|
|
/// Find or create a new client session for the PHP proxy
|
|
|
|
void handleProxyRequest(
|
|
|
|
const std::string& id,
|
|
|
|
const Poco::URI& uriPublic,
|
|
|
|
const bool isReadOnly,
|
2020-05-12 15:10:56 -05:00
|
|
|
const RequestDetails &requestDetails,
|
2020-05-09 13:41:40 -05:00
|
|
|
const std::shared_ptr<StreamSocket> &socket);
|
2020-03-04 07:54:04 -06:00
|
|
|
|
2017-03-31 14:58:33 -05:00
|
|
|
/// Thread safe termination of this broker if it has a lingering thread
|
|
|
|
void joinThread();
|
|
|
|
|
2019-12-11 23:09:35 -06:00
|
|
|
/// Notify that the load has completed
|
|
|
|
virtual void setLoaded();
|
2016-03-12 18:29:17 -06:00
|
|
|
|
2021-02-26 09:01:39 -06:00
|
|
|
/// Notify that the document has dialogs before load
|
|
|
|
virtual void setInteractive(bool value);
|
|
|
|
|
2020-07-14 14:19:14 -05:00
|
|
|
/// If not yet locked, try to lock
|
|
|
|
bool attemptLock(const ClientSession& session, std::string& failReason);
|
|
|
|
|
2017-06-01 07:56:54 -05:00
|
|
|
bool isDocumentChangedInStorage() { return _documentChangedInStorage; }
|
|
|
|
|
2021-02-09 22:25:42 -06:00
|
|
|
bool isLastStorageUploadSuccessful() { return _storageManager.lastUploadSuccessful(); }
|
2020-08-17 04:00:38 -05:00
|
|
|
|
2021-05-24 21:09:06 -05:00
|
|
|
/// Invoked by the client to rename the document filename.
|
|
|
|
/// Returns an error message in case of failure, otherwise an empty string.
|
|
|
|
std::string handleRenameFileCommand(std::string sessionId, std::string newFilename);
|
|
|
|
|
2021-01-30 17:31:29 -06:00
|
|
|
/// Handle the save response from Core and upload to storage as necessary.
|
|
|
|
/// Also notifies clients of the result.
|
|
|
|
void handleSaveResponse(const std::string& sessionId, bool success, const std::string& result);
|
|
|
|
|
2021-01-26 19:43:57 -06:00
|
|
|
/// Upload the document to Storage if it needs persisting.
|
2020-12-06 12:17:23 -06:00
|
|
|
/// Results are logged and broadcast to users.
|
2021-01-26 19:43:57 -06:00
|
|
|
void uploadToStorage(const std::string& sesionId, bool success, const std::string& result,
|
|
|
|
bool force);
|
2017-10-20 11:12:05 -05:00
|
|
|
|
2021-01-26 19:47:23 -06:00
|
|
|
/// UploadAs the document to Storage, with a new name.
|
|
|
|
/// @param uploadAsPath Absolute path to the jailed file.
|
2021-05-24 21:03:49 -05:00
|
|
|
void uploadAsToStorage(const std::string& sessionId, const std::string& uploadAsPath,
|
2021-01-26 19:47:23 -06:00
|
|
|
const std::string& uploadAsFilename, const bool isRename);
|
2017-10-20 11:12:05 -05:00
|
|
|
|
2021-05-26 21:08:57 -05:00
|
|
|
/// Uploads the document right after loading from a template.
|
|
|
|
/// Template-loading requires special handling because the
|
|
|
|
/// document changes once loaded into a non-template format.
|
|
|
|
void uploadAfterLoadingTemplate(const std::string& sessionId);
|
|
|
|
|
2016-04-24 10:08:08 -05:00
|
|
|
bool isModified() const { return _isModified; }
|
|
|
|
void setModified(const bool value);
|
2018-01-03 22:15:44 -06:00
|
|
|
|
2016-04-25 19:48:02 -05:00
|
|
|
/// Save the document if the document is modified.
|
2016-04-29 05:06:45 -05:00
|
|
|
/// @param force when true, will force saving if there
|
2016-04-25 19:48:02 -05:00
|
|
|
/// has been any recent activity after the last save.
|
2019-06-06 04:48:54 -05:00
|
|
|
/// @param dontSaveIfUnmodified when true, save will fail if the document is not modified.
|
2016-04-29 05:06:45 -05:00
|
|
|
/// @return true if attempts to save or it also waits
|
2016-04-25 19:48:02 -05:00
|
|
|
/// and receives save notification. Otherwise, false.
|
2019-06-06 04:48:54 -05:00
|
|
|
bool autoSave(const bool force, const bool dontSaveIfUnmodified = true);
|
2016-04-09 22:20:20 -05:00
|
|
|
|
2021-07-22 15:17:14 -05:00
|
|
|
bool isAsyncSaveInProgress() const;
|
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
Poco::URI getPublicUri() const { return _uriPublic; }
|
2016-03-12 18:29:17 -06:00
|
|
|
const std::string& getJailId() const { return _jailId; }
|
|
|
|
const std::string& getDocKey() const { return _docKey; }
|
2016-04-14 15:29:31 -05:00
|
|
|
const std::string& getFilename() const { return _filename; };
|
2016-03-25 21:56:18 -05:00
|
|
|
TileCache& tileCache() { return *_tileCache; }
|
wsd: avoid UB in DocumentBroker::cancelTileRequests()
With this, it's possible to open a document and type keys with
sanitizers enabled.
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:323:9: runtime error: reference binding to null pointer of type 'TileCache'
#0 0x911996 in std::unique_ptr<TileCache, std::default_delete<TileCache> >::operator*() const /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:323:2
#1 0x8ecb2a in DocumentBroker::tileCache() /home/vmiklos/lode/dev/online/./wsd/DocumentBroker.hpp:265:37
#2 0x8c6a63 in DocumentBroker::cancelTileRequests(std::shared_ptr<ClientSession> const&) /home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:1586:37
#3 0xb32b0e in ClientSession::_handleInput(char const*, int) /home/vmiklos/lode/dev/online/wsd/ClientSession.cpp:194:20
#4 0xd45d3c in Session::handleMessage(bool, WSOpCode, std::vector<char, std::allocator<char> >&) /home/vmiklos/lode/dev/online/common/Session.cpp:219:13
#5 0x768080 in WebSocketHandler::handleTCPStream(std::shared_ptr<StreamSocket> const&) /home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:368:13
#6 0x6f800d in WebSocketHandler::handleIncomingMessage(SocketDisposition&) /home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:419:20
#7 0xb2c644 in ClientSession::handleIncomingMessage(SocketDisposition&) /home/vmiklos/lode/dev/online/wsd/ClientSession.cpp:74:14
#8 0xa6f641 in StreamSocket::handlePoll(SocketDisposition&, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, int) /home/vmiklos/lode/dev/online/./net/Socket.hpp:1037:29
#9 0x6ec63d in SocketPoll::poll(int) /home/vmiklos/lode/dev/online/./net/Socket.hpp:570:34
#10 0x83af99 in DocumentBroker::pollThread() /home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:387:16
#11 0x8fc778 in DocumentBroker::DocumentBrokerPoll::pollingThread() /home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:165:20
#12 0xdff935 in SocketPoll::pollingThreadEntry() /home/vmiklos/lode/dev/online/net/Socket.cpp:184:9
#13 0xe487bd in void std::__invoke_impl<void, void (SocketPoll::*)(), SocketPoll*>(std::__invoke_memfun_deref, void (SocketPoll::*&&)(), SocketPoll*&&) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:73:14
#14 0xe482ca in std::__invoke_result<void (SocketPoll::*)(), SocketPoll*>::type std::__invoke<void (SocketPoll::*)(), SocketPoll*>(void (SocketPoll::*&&)(), SocketPoll*&&) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:95:14
#15 0xe4817d in decltype(std::__invoke(_S_declval<0ul>(), _S_declval<1ul>())) std::thread::_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:234:13
#16 0xe47f87 in std::thread::_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::operator()() /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:243:11
#17 0xe4734a in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> > >::_M_run() /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:186:13
#18 0x7f5c2ce55e2e in execute_native_thread_routine /home/vmiklos/lode/packages/gccbuild/x86_64-pc-linux-gnu/libstdc++-v3/src/c++11/../../../../../gcc-7.3.0/libstdc++-v3/src/c++11/thread.cc:83
#19 0x7f5c2c832558 in start_thread (/lib64/libpthread.so.0+0x7558)
#20 0x7f5c2bf4682e in clone (/lib64/libc.so.6+0xf882e)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:323:9 in
Change-Id: Ief574a11c838c77f7f159b1133beeef0deada201
2019-05-24 02:04:07 -05:00
|
|
|
bool hasTileCache() { return _tileCache != nullptr; }
|
2017-03-04 17:07:17 -06:00
|
|
|
bool isAlive() const;
|
2016-03-10 20:42:33 -06:00
|
|
|
|
2017-03-15 07:07:17 -05:00
|
|
|
/// Are we running in either shutdown, or the polling thread.
|
2017-04-05 07:48:49 -05:00
|
|
|
/// Asserts in the debug builds, otherwise just logs.
|
2018-01-14 10:16:10 -06:00
|
|
|
void assertCorrectThread() const;
|
2017-03-15 07:07:17 -05:00
|
|
|
|
|
|
|
/// Pretty print internal state to a stream.
|
2017-03-12 18:03:45 -05:00
|
|
|
void dumpState(std::ostream& os);
|
2017-03-06 09:45:34 -06:00
|
|
|
|
2016-03-23 07:41:18 -05:00
|
|
|
std::string getJailRoot() const;
|
2016-03-12 19:14:32 -06:00
|
|
|
|
2017-04-01 18:20:54 -05:00
|
|
|
/// Add a new session. Returns the new number of sessions.
|
2020-11-15 11:03:45 -06:00
|
|
|
std::size_t addSession(const std::shared_ptr<ClientSession>& session);
|
2017-03-06 09:05:11 -06:00
|
|
|
|
2016-04-16 16:18:51 -05:00
|
|
|
/// Removes a session by ID. Returns the new number of sessions.
|
2020-11-15 11:03:45 -06:00
|
|
|
std::size_t removeSession(const std::string& id);
|
2016-03-23 11:55:28 -05:00
|
|
|
|
2017-03-20 12:18:41 -05:00
|
|
|
/// Add a callback to be invoked in our polling thread.
|
2017-04-11 01:54:09 -05:00
|
|
|
void addCallback(const SocketPoll::CallbackFn& fn);
|
2017-03-20 12:18:41 -05:00
|
|
|
|
|
|
|
/// Transfer this socket into our polling thread / loop.
|
2017-03-07 11:34:01 -06:00
|
|
|
void addSocketToPoll(const std::shared_ptr<Socket>& socket);
|
2017-03-07 01:00:51 -06:00
|
|
|
|
2016-11-17 08:00:05 -06:00
|
|
|
void alertAllUsers(const std::string& msg);
|
|
|
|
|
|
|
|
void alertAllUsers(const std::string& cmd, const std::string& kind)
|
|
|
|
{
|
|
|
|
alertAllUsers("error: cmd=" + cmd + " kind=" + kind);
|
|
|
|
}
|
2016-09-28 14:07:07 -05:00
|
|
|
|
2020-11-23 05:07:44 -06:00
|
|
|
/// Sets the log level of kit.
|
|
|
|
void setKitLogLevel(const std::string& level);
|
2020-11-15 06:23:54 -06:00
|
|
|
|
2016-05-22 15:47:22 -05:00
|
|
|
/// Invalidate the cursor position.
|
2016-09-01 15:15:13 -05:00
|
|
|
void invalidateCursor(int x, int y, int w, int h)
|
2016-05-22 15:47:22 -05:00
|
|
|
{
|
|
|
|
_cursorPosX = x;
|
|
|
|
_cursorPosY = y;
|
2016-09-01 15:15:13 -05:00
|
|
|
_cursorWidth = w;
|
|
|
|
_cursorHeight = h;
|
2016-05-22 15:47:22 -05:00
|
|
|
}
|
|
|
|
|
2020-07-12 11:25:49 -05:00
|
|
|
void invalidateTiles(const std::string& tiles, int normalizedViewId)
|
|
|
|
{
|
|
|
|
// Remove from cache.
|
|
|
|
_tileCache->invalidateTiles(tiles, normalizedViewId);
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:21:08 -06:00
|
|
|
void handleTileRequest(const StringVector &tokens,
|
2016-05-16 19:49:36 -05:00
|
|
|
const std::shared_ptr<ClientSession>& session);
|
2016-05-22 10:45:28 -05:00
|
|
|
void handleTileCombinedRequest(TileCombined& tileCombined,
|
|
|
|
const std::shared_ptr<ClientSession>& session);
|
2018-06-07 06:13:36 -05:00
|
|
|
void sendRequestedTiles(const std::shared_ptr<ClientSession>& session);
|
2016-08-30 22:15:44 -05:00
|
|
|
void cancelTileRequests(const std::shared_ptr<ClientSession>& session);
|
2019-06-22 11:45:36 -05:00
|
|
|
|
|
|
|
enum ClipboardRequest {
|
|
|
|
CLIP_REQUEST_SET,
|
2019-06-25 19:43:07 -05:00
|
|
|
CLIP_REQUEST_GET,
|
|
|
|
CLIP_REQUEST_GET_RICH_HTML_ONLY
|
2019-06-22 11:45:36 -05:00
|
|
|
};
|
|
|
|
void handleClipboardRequest(ClipboardRequest type, const std::shared_ptr<StreamSocket> &socket,
|
|
|
|
const std::string &viewId, const std::string &tag,
|
|
|
|
const std::shared_ptr<std::string> &data);
|
2019-07-04 04:50:33 -05:00
|
|
|
static bool lookupSendClipboardTag(const std::shared_ptr<StreamSocket> &socket,
|
|
|
|
const std::string &tag, bool sendError = false);
|
2016-05-01 19:50:11 -05:00
|
|
|
|
2021-01-18 06:10:56 -06:00
|
|
|
bool isMarkedToDestroy() const { return _docState.isMarkedToDestroy() || _stop; }
|
2016-04-15 04:00:22 -05:00
|
|
|
|
2016-05-02 06:21:30 -05:00
|
|
|
bool handleInput(const std::vector<char>& payload);
|
|
|
|
|
2016-10-08 13:25:27 -05:00
|
|
|
/// Forward a message from client session to its respective child session.
|
2016-10-16 12:43:44 -05:00
|
|
|
bool forwardToChild(const std::string& viewId, const std::string& message);
|
2016-10-08 13:25:27 -05:00
|
|
|
|
2016-10-11 07:39:56 -05:00
|
|
|
int getRenderedTileCount() { return _debugRenderedTileCount; }
|
|
|
|
|
2018-02-02 01:47:45 -06:00
|
|
|
/// Ask the document broker to close. Makes sure that the document is saved.
|
2016-11-08 07:37:28 -06:00
|
|
|
void closeDocument(const std::string& reason);
|
|
|
|
|
2016-10-17 06:45:58 -05:00
|
|
|
/// Get the PID of the associated child process
|
2019-11-26 07:15:38 -06:00
|
|
|
pid_t getPid() const { return _childProcess ? _childProcess->getPid() : 0; }
|
2016-10-17 06:45:58 -05:00
|
|
|
|
2016-11-05 21:15:44 -05:00
|
|
|
std::unique_lock<std::mutex> getLock() { return std::unique_lock<std::mutex>(_mutex); }
|
|
|
|
|
2016-12-05 14:11:07 -06:00
|
|
|
void updateLastActivityTime();
|
|
|
|
|
2017-05-15 00:59:04 -05:00
|
|
|
/// Sends the .uno:Save command to LoKit.
|
2018-12-04 01:49:49 -06:00
|
|
|
bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = true,
|
|
|
|
bool dontSaveIfUnmodified = true, bool isAutosave = false,
|
2019-06-16 13:42:11 -05:00
|
|
|
bool isExitSave = false, const std::string& extendedData = std::string());
|
2017-05-15 00:59:04 -05:00
|
|
|
|
2017-06-01 11:11:11 -05:00
|
|
|
/// Sends a message to all sessions
|
2020-11-15 16:22:03 -06:00
|
|
|
void broadcastMessage(const std::string& message) const;
|
2017-06-01 11:11:11 -05:00
|
|
|
|
2021-06-07 12:32:53 -05:00
|
|
|
/// Sends a message to all sessions except for the session passed as the param
|
|
|
|
void broadcastMessageToOthers(const std::string& message, const std::shared_ptr<ClientSession>& _session) const;
|
|
|
|
|
2021-05-30 14:23:23 -05:00
|
|
|
/// Broadcasts 'blockui' command to all users with an optional message.
|
|
|
|
void blockUI(const std::string& msg)
|
|
|
|
{
|
|
|
|
broadcastMessage("blockui: " + msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Broadcasts 'unblockui' command to all users.
|
|
|
|
void unblockUI()
|
|
|
|
{
|
|
|
|
broadcastMessage("unblockui: ");
|
|
|
|
}
|
|
|
|
|
2018-04-24 11:09:37 -05:00
|
|
|
/// Returns true iff an initial setting by the given name is already initialized.
|
|
|
|
bool isInitialSettingSet(const std::string& name) const;
|
|
|
|
|
|
|
|
/// Sets the initialization flag of a given initial setting.
|
|
|
|
void setInitialSetting(const std::string& name);
|
|
|
|
|
2019-06-21 05:47:07 -05:00
|
|
|
/// For testing only [!]
|
|
|
|
std::vector<std::shared_ptr<ClientSession>> getSessionsTestOnlyUnsafe();
|
|
|
|
|
2019-10-28 08:26:15 -05:00
|
|
|
/// Estimate memory usage / bytes
|
2020-11-15 11:03:45 -06:00
|
|
|
std::size_t getMemorySize() const;
|
2019-10-28 08:26:15 -05:00
|
|
|
|
2020-09-03 04:34:13 -05:00
|
|
|
/// Get URL for corresponding download id if registered, or empty string otherwise
|
|
|
|
std::string getDownloadURL(const std::string& downloadId);
|
|
|
|
|
|
|
|
/// Remove download id mapping
|
|
|
|
void unregisterDownloadId(const std::string& downloadId);
|
|
|
|
|
2016-04-25 19:48:02 -05:00
|
|
|
private:
|
2019-11-27 02:43:05 -06:00
|
|
|
/// get the session id of a session that can write the document for save / locking.
|
|
|
|
std::string getWriteableSessionId() const;
|
|
|
|
|
|
|
|
void refreshLock();
|
2017-05-21 18:13:55 -05:00
|
|
|
|
2019-09-29 22:32:12 -05:00
|
|
|
/// Loads a document from the public URI into the jail.
|
2021-01-19 21:04:07 -06:00
|
|
|
bool download(const std::shared_ptr<ClientSession>& session, const std::string& jailId);
|
2021-01-23 13:11:37 -06:00
|
|
|
bool isLoaded() const { return _docState.hadLoaded(); }
|
2021-02-26 09:01:39 -06:00
|
|
|
bool isInteractive() const { return _docState.isInteractive(); }
|
2019-09-29 22:32:12 -05:00
|
|
|
|
|
|
|
std::size_t getIdleTimeSecs() const
|
|
|
|
{
|
|
|
|
const auto duration = (std::chrono::steady_clock::now() - _lastActivityTime);
|
|
|
|
return std::chrono::duration_cast<std::chrono::seconds>(duration).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> getDeferredLock() { return std::unique_lock<std::mutex>(_mutex, std::defer_lock); }
|
|
|
|
|
|
|
|
/// Called by the ChildProcess object to notify
|
|
|
|
/// that it has terminated on its own.
|
|
|
|
/// This happens either when the child exists
|
|
|
|
/// or upon failing to process an incoming message.
|
|
|
|
void childSocketTerminated();
|
|
|
|
void handleTileResponse(const std::vector<char>& payload);
|
|
|
|
void handleDialogPaintResponse(const std::vector<char>& payload, bool child);
|
|
|
|
void handleTileCombinedResponse(const std::vector<char>& payload);
|
|
|
|
void handleDialogRequest(const std::string& dialogCmd);
|
|
|
|
|
2021-05-24 21:09:06 -05:00
|
|
|
/// Invoked to issue a save before renaming the document filename.
|
|
|
|
void startRenameFileCommand();
|
|
|
|
|
2021-05-30 14:23:23 -05:00
|
|
|
/// Finish handling the renamefile command.
|
|
|
|
void endRenameFileCommand();
|
|
|
|
|
2017-05-21 18:13:55 -05:00
|
|
|
/// Shutdown all client connections with the given reason.
|
|
|
|
void shutdownClients(const std::string& closeReason);
|
|
|
|
|
2017-03-29 21:50:29 -05:00
|
|
|
/// This gracefully terminates the connection
|
|
|
|
/// with the child and cleans up ChildProcess etc.
|
2017-06-21 05:07:38 -05:00
|
|
|
void terminateChild(const std::string& closeReason);
|
2017-03-29 21:50:29 -05:00
|
|
|
|
2021-05-22 13:08:38 -05:00
|
|
|
/// Encodes whether or not uploading is needed.
|
|
|
|
enum class NeedToUpload
|
|
|
|
{
|
|
|
|
No, //< No need to upload, data up-to-date.
|
|
|
|
Yes, //< Data is out of date.
|
|
|
|
Force //< Force uploading, typically because always_save_on_exit is set.
|
|
|
|
};
|
|
|
|
|
2021-01-31 14:43:45 -06:00
|
|
|
/// Returns true iff the Document in Storage is
|
|
|
|
/// out-of-date and we must upload the last file on disk.
|
2021-05-22 13:08:38 -05:00
|
|
|
NeedToUpload needToUploadToStorage() const;
|
2021-01-31 14:43:45 -06:00
|
|
|
|
2021-01-26 19:50:21 -06:00
|
|
|
/// Upload the doc to the storage.
|
|
|
|
void uploadToStorageInternal(const std::string& sesionId, bool success,
|
2021-01-26 21:04:33 -06:00
|
|
|
const std::string& result, const std::string& saveAsPath,
|
|
|
|
const std::string& saveAsFilename, const bool isRename,
|
|
|
|
const bool force);
|
2017-03-09 22:50:36 -06:00
|
|
|
|
2021-05-22 13:10:13 -05:00
|
|
|
/// Handles the completion of uploading to storage, both success and failure cases.
|
2020-11-29 22:57:19 -06:00
|
|
|
void handleUploadToStorageResponse(const StorageBase::UploadResult& uploadResult);
|
2020-11-15 15:47:35 -06:00
|
|
|
|
2020-07-01 05:46:58 -05:00
|
|
|
/**
|
|
|
|
* Report back the save result to PostMessage users (Action_Save_Resp)
|
|
|
|
* @param success: Whether saving was successful
|
|
|
|
* @param result: Short message why saving was (not) successful
|
|
|
|
* @param errorMsg: Long error msg (Error message from WOPI host if any)
|
|
|
|
*/
|
2021-01-26 21:04:33 -06:00
|
|
|
void broadcastSaveResult(bool success, const std::string& result = std::string(),
|
|
|
|
const std::string& errorMsg = std::string());
|
2020-07-01 05:46:58 -05:00
|
|
|
|
2020-11-15 16:22:03 -06:00
|
|
|
/// Broadcasts to all sessions the last modification time of the document.
|
|
|
|
void broadcastLastModificationTime(const std::shared_ptr<ClientSession>& session = nullptr) const;
|
|
|
|
|
2018-01-14 23:49:14 -06:00
|
|
|
/// True if we know the doc is modified or
|
|
|
|
/// if there has been activity from a client after we last *requested* saving,
|
|
|
|
/// since there are race conditions vis-a-vis user activity while saving.
|
2020-12-02 23:00:13 -06:00
|
|
|
bool isPossiblyModified() const
|
|
|
|
{
|
|
|
|
return isModified() || (_saveManager.lastSaveRequestTime() < _lastActivityTime);
|
|
|
|
}
|
2018-01-14 23:49:14 -06:00
|
|
|
|
2018-01-14 16:17:00 -06:00
|
|
|
/// True iff there is at least one non-readonly session other than the given.
|
|
|
|
/// Since only editable sessions can save, we need to use the last to
|
|
|
|
/// save modified documents, otherwise we'll potentially have to save on
|
|
|
|
/// every editable session disconnect, lest we lose data due to racing.
|
|
|
|
bool haveAnotherEditableSession(const std::string& id) const;
|
|
|
|
|
2017-05-22 14:04:35 -05:00
|
|
|
/// Loads a new session and adds to the sessions container.
|
2020-11-15 11:03:45 -06:00
|
|
|
std::size_t addSessionInternal(const std::shared_ptr<ClientSession>& session);
|
2017-05-22 14:04:35 -05:00
|
|
|
|
2019-07-04 04:50:33 -05:00
|
|
|
/// Starts the Kit <-> DocumentBroker shutdown handshake
|
|
|
|
void disconnectSessionInternal(const std::string& id);
|
2016-04-25 19:48:02 -05:00
|
|
|
|
2016-10-08 17:21:35 -05:00
|
|
|
/// Forward a message from child session to its respective client session.
|
2017-01-22 22:18:37 -06:00
|
|
|
bool forwardToClient(const std::shared_ptr<Message>& payload);
|
2016-10-08 12:13:23 -05:00
|
|
|
|
2017-03-04 17:07:17 -06:00
|
|
|
/// The thread function that all of the I/O for all sessions
|
|
|
|
/// associated with this document.
|
2017-03-07 19:46:16 -06:00
|
|
|
void pollThread();
|
2017-03-04 17:07:17 -06:00
|
|
|
|
2017-06-03 16:53:57 -05:00
|
|
|
/// Sum the I/O stats from all connected sessions
|
2017-05-31 21:40:01 -05:00
|
|
|
void getIOStats(uint64_t &sent, uint64_t &recv);
|
|
|
|
|
2020-11-22 16:36:44 -06:00
|
|
|
/// Returns true iff this is a Convert-To request.
|
|
|
|
/// This is needed primarily for security reasons,
|
|
|
|
/// because we can't trust the given file-path is
|
|
|
|
/// a convert-to request or doctored to look like one.
|
|
|
|
virtual bool isConvertTo() const { return false; }
|
|
|
|
|
2020-12-02 22:17:04 -06:00
|
|
|
private:
|
2021-02-09 22:25:42 -06:00
|
|
|
/// Request manager.
|
2021-01-24 10:46:24 -06:00
|
|
|
/// Encapsulates common fields for
|
|
|
|
/// Save and Upload requests.
|
2021-02-09 22:25:42 -06:00
|
|
|
class RequestManager
|
2021-01-24 10:46:24 -06:00
|
|
|
{
|
|
|
|
public:
|
2021-02-09 22:25:42 -06:00
|
|
|
RequestManager()
|
2021-01-24 10:46:24 -06:00
|
|
|
: _lastRequestTime(now())
|
|
|
|
, _lastResponseTime(now())
|
2021-01-31 13:12:00 -06:00
|
|
|
, _lastRequestSuccessful(true)
|
2021-01-24 10:46:24 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-21 09:30:39 -06:00
|
|
|
/// Sets the time the last request was made to now.
|
|
|
|
void markLastRequestTime() { _lastRequestTime = now(); }
|
|
|
|
|
|
|
|
/// Returns the time the last request was made.
|
|
|
|
std::chrono::steady_clock::time_point lastRequestTime() const { return _lastRequestTime; }
|
|
|
|
|
|
|
|
/// How much time passed since the last request,
|
|
|
|
/// regardless of whether we got a response or not.
|
2021-01-24 10:46:24 -06:00
|
|
|
const std::chrono::milliseconds timeSinceLastRequest() const
|
|
|
|
{
|
2021-02-21 09:30:39 -06:00
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(now() - _lastRequestTime);
|
2021-01-24 10:46:24 -06:00
|
|
|
}
|
|
|
|
|
2021-02-21 09:30:39 -06:00
|
|
|
/// True iff there is an active request and it has timed out.
|
|
|
|
bool hasLastRequestTimedOut(std::chrono::milliseconds timeoutMs) const
|
|
|
|
{
|
|
|
|
return isActive() && timeSinceLastRequest() >= timeoutMs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Sets the time the last response was received to now.
|
|
|
|
void markLastResponseTime() { _lastResponseTime = now(); }
|
|
|
|
|
|
|
|
/// Returns the time the last response was received.
|
|
|
|
std::chrono::steady_clock::time_point lastResponseTime() const { return _lastResponseTime; }
|
|
|
|
|
|
|
|
/// How much time passed since the last response,
|
|
|
|
/// regardless of whether there is a newer request or not.
|
2021-01-24 10:46:24 -06:00
|
|
|
const std::chrono::milliseconds timeSinceLastResponse() const
|
|
|
|
{
|
2021-02-21 09:30:39 -06:00
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(now() - _lastResponseTime);
|
2021-01-24 10:46:24 -06:00
|
|
|
}
|
|
|
|
|
2021-02-21 09:30:39 -06:00
|
|
|
|
|
|
|
/// Returns true iff there is an active request in progress.
|
|
|
|
bool isActive() const { return _lastResponseTime < _lastRequestTime; }
|
|
|
|
|
2021-01-31 13:12:00 -06:00
|
|
|
|
|
|
|
/// Sets the last request's result, either to success or failure.
|
2021-01-31 14:11:38 -06:00
|
|
|
/// And marks the last response time.
|
|
|
|
void setLastRequestResult(bool success)
|
|
|
|
{
|
|
|
|
markLastResponseTime();
|
|
|
|
_lastRequestSuccessful = success;
|
|
|
|
}
|
2021-01-31 13:12:00 -06:00
|
|
|
|
2021-02-21 09:30:39 -06:00
|
|
|
/// Indicates whether the last request was successful or not.
|
|
|
|
bool lastRequestSuccessful() const { return _lastRequestSuccessful; }
|
|
|
|
|
2021-01-24 10:46:24 -06:00
|
|
|
|
2021-01-26 22:02:33 -06:00
|
|
|
/// Set the modified time of the document.
|
|
|
|
void setModifiedTime(std::chrono::system_clock::time_point time) { _modifiedTime = time; }
|
|
|
|
|
|
|
|
/// Returns the modified time of the document.
|
|
|
|
std::chrono::system_clock::time_point getModifiedTime() const { return _modifiedTime; }
|
|
|
|
|
2021-02-21 09:30:39 -06:00
|
|
|
|
2021-01-24 10:46:24 -06:00
|
|
|
/// Helper to get the current time.
|
|
|
|
static std::chrono::steady_clock::time_point now()
|
|
|
|
{
|
|
|
|
return std::chrono::steady_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// The last time we started an a request.
|
|
|
|
std::chrono::steady_clock::time_point _lastRequestTime;
|
|
|
|
|
|
|
|
/// The last time we received a response.
|
|
|
|
std::chrono::steady_clock::time_point _lastResponseTime;
|
2021-01-26 22:02:33 -06:00
|
|
|
|
|
|
|
/// The document's last-modified time.
|
|
|
|
std::chrono::system_clock::time_point _modifiedTime;
|
2021-01-31 13:12:00 -06:00
|
|
|
|
|
|
|
/// Indicates whether the last request resulted in success.
|
|
|
|
/// Note that this is interpretted by the request in question.
|
|
|
|
/// For example, Core's Save operation turns 'false' for success
|
|
|
|
/// when the file is unmodified, but that is still a successful result.
|
|
|
|
bool _lastRequestSuccessful;
|
2021-01-24 10:46:24 -06:00
|
|
|
};
|
|
|
|
|
2020-12-02 22:17:04 -06:00
|
|
|
/// Responsible for managing document saving.
|
|
|
|
/// Tracks auto-saveing and its frequency.
|
2020-12-02 23:00:13 -06:00
|
|
|
/// Tracks the last save request and response times.
|
2021-01-18 19:02:01 -06:00
|
|
|
/// Tracks the local file's last modified time.
|
2021-01-18 19:12:28 -06:00
|
|
|
/// Tracks the time a save response was received.
|
2021-02-09 22:25:42 -06:00
|
|
|
class SaveManager final
|
2020-12-02 22:17:04 -06:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SaveManager()
|
2021-05-29 14:12:48 -05:00
|
|
|
: _autosaveInterval(std::chrono::seconds(30))
|
|
|
|
, _lastAutosaveCheckTime(RequestManager::now())
|
2020-12-02 22:17:04 -06:00
|
|
|
, _isAutosaveEnabled(std::getenv("LOOL_NO_AUTOSAVE") == nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true iff auto save is enabled.
|
|
|
|
bool isAutosaveEnabled() const { return _isAutosaveEnabled; }
|
|
|
|
|
|
|
|
/// Returns true if we should issue an auto-save.
|
|
|
|
bool needAutosaveCheck() const
|
|
|
|
{
|
|
|
|
return isAutosaveEnabled()
|
2021-02-09 22:25:42 -06:00
|
|
|
&& std::chrono::duration_cast<std::chrono::seconds>(RequestManager::now()
|
2020-12-02 22:17:04 -06:00
|
|
|
- _lastAutosaveCheckTime)
|
2021-05-29 14:12:48 -05:00
|
|
|
>= _autosaveInterval;
|
2020-12-02 22:17:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Marks autosave check done.
|
2021-02-09 22:25:42 -06:00
|
|
|
void autosaveChecked() { _lastAutosaveCheckTime = RequestManager::now(); }
|
2020-12-02 22:17:04 -06:00
|
|
|
|
2021-05-29 14:12:48 -05:00
|
|
|
/// Called to postpone autosaving by at least the given duration.
|
|
|
|
void postponeAutosave(std::chrono::seconds seconds)
|
|
|
|
{
|
|
|
|
const auto now = RequestManager::now();
|
|
|
|
|
|
|
|
const auto nextAutosaveCheck = _lastAutosaveCheckTime + _autosaveInterval;
|
|
|
|
const auto postponeTime = now + seconds;
|
|
|
|
if (nextAutosaveCheck < postponeTime)
|
|
|
|
{
|
|
|
|
// Next autosave check will happen before the desired time.
|
|
|
|
// Let's postpone it by the difference.
|
|
|
|
const auto delay = postponeTime - nextAutosaveCheck;
|
|
|
|
_lastAutosaveCheckTime += delay;
|
|
|
|
LOG_TRC("Autosave check postponed by "
|
|
|
|
<< std::chrono::duration_cast<std::chrono::milliseconds>(delay));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:00:13 -06:00
|
|
|
/// Marks the last save request as now.
|
2021-02-09 22:25:42 -06:00
|
|
|
void markLastSaveRequestTime() { _request.markLastRequestTime(); }
|
|
|
|
|
|
|
|
/// Returns whether the last save was successful or not.
|
|
|
|
bool lastSaveSuccessful() const { return _request.lastRequestSuccessful(); }
|
|
|
|
|
|
|
|
/// Sets whether the last save was successful or not.
|
|
|
|
void setLastSaveResult(bool success) { _request.setLastRequestResult(success); }
|
2020-12-02 23:00:13 -06:00
|
|
|
|
|
|
|
/// Returns the last save request time.
|
|
|
|
/// TODO: Remove: temporary for logging only.
|
|
|
|
std::chrono::steady_clock::time_point lastSaveRequestTime() const
|
|
|
|
{
|
2021-02-09 22:25:42 -06:00
|
|
|
return _request.lastRequestTime();
|
2020-12-02 23:00:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Marks the last save response as now.
|
2021-02-09 22:25:42 -06:00
|
|
|
void markLastSaveResponseTime() { _request.markLastResponseTime(); }
|
2020-12-02 23:00:13 -06:00
|
|
|
|
|
|
|
/// Returns the last save response time.
|
|
|
|
/// TODO: Remove: temporary for logging only.
|
|
|
|
std::chrono::steady_clock::time_point lastSaveResponseTime() const
|
|
|
|
{
|
2021-02-09 22:25:42 -06:00
|
|
|
return _request.lastResponseTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the last modified time of the document.
|
|
|
|
void setLastModifiedTime(std::chrono::system_clock::time_point time)
|
|
|
|
{
|
|
|
|
_request.setModifiedTime(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the last modified time of the document.
|
|
|
|
std::chrono::system_clock::time_point getLastModifiedTime() const
|
|
|
|
{
|
|
|
|
return _request.getModifiedTime();
|
2020-12-02 23:00:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// True iff a save is in progress (requested but not completed).
|
2021-02-09 22:25:42 -06:00
|
|
|
bool isSaving() const { return _request.isActive(); }
|
2020-12-02 23:00:13 -06:00
|
|
|
|
|
|
|
/// True iff the last save request has timed out.
|
2021-02-09 22:25:42 -06:00
|
|
|
bool hasSavingTimedOut(std::chrono::milliseconds timeoutMs
|
|
|
|
= std::chrono::milliseconds(COMMAND_TIMEOUT_MS)) const
|
|
|
|
{
|
2021-02-21 09:31:59 -06:00
|
|
|
return _request.hasLastRequestTimedOut(timeoutMs);
|
2021-02-09 22:25:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The duration elapsed since we sent the last save request to Core.
|
|
|
|
std::chrono::milliseconds timeSinceLastSaveRequest() const
|
2020-12-02 23:00:13 -06:00
|
|
|
{
|
2021-02-21 09:31:59 -06:00
|
|
|
return _request.timeSinceLastRequest();
|
2020-12-02 23:00:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-09 22:25:42 -06:00
|
|
|
/// Request tracking logic.
|
|
|
|
RequestManager _request;
|
|
|
|
|
2021-05-29 14:12:48 -05:00
|
|
|
/// The number of seconds between autosave checks for modification.
|
|
|
|
const std::chrono::seconds _autosaveInterval;
|
|
|
|
|
2021-01-24 10:46:24 -06:00
|
|
|
/// The last autosave check time.
|
2020-12-02 22:17:04 -06:00
|
|
|
std::chrono::steady_clock::time_point _lastAutosaveCheckTime;
|
|
|
|
|
|
|
|
/// Whether auto-saving is enabled at all or not.
|
|
|
|
const bool _isAutosaveEnabled;
|
|
|
|
};
|
|
|
|
|
2020-11-29 22:57:19 -06:00
|
|
|
/// Represents an upload request.
|
|
|
|
class UploadRequest final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UploadRequest(std::string uriAnonym,
|
|
|
|
std::chrono::system_clock::time_point newFileModifiedTime,
|
|
|
|
const std::shared_ptr<class ClientSession>& session, bool isSaveAs,
|
|
|
|
bool isRename)
|
|
|
|
: _startTime(std::chrono::steady_clock::now())
|
|
|
|
, _uriAnonym(std::move(uriAnonym))
|
|
|
|
, _newFileModifiedTime(newFileModifiedTime)
|
|
|
|
, _session(session)
|
|
|
|
, _isSaveAs(isSaveAs)
|
|
|
|
, _isRename(isRename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::chrono::milliseconds timeSinceRequest() const
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::steady_clock::now() - _startTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& uriAnonym() const { return _uriAnonym; }
|
|
|
|
const std::chrono::system_clock::time_point& newFileModifiedTime() const
|
|
|
|
{
|
|
|
|
return _newFileModifiedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<class ClientSession> session() const { return _session.lock(); }
|
|
|
|
bool isSaveAs() const { return _isSaveAs; }
|
|
|
|
bool isRename() const { return _isRename; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::chrono::steady_clock::time_point _startTime; //< The time we made the request.
|
|
|
|
const std::string _uriAnonym;
|
|
|
|
const std::chrono::system_clock::time_point _newFileModifiedTime;
|
|
|
|
const std::weak_ptr<class ClientSession> _session;
|
|
|
|
const bool _isSaveAs;
|
|
|
|
const bool _isRename;
|
|
|
|
};
|
|
|
|
|
2021-01-18 19:24:40 -06:00
|
|
|
/// Responsible for managing document uploading into storage.
|
2021-02-09 22:25:42 -06:00
|
|
|
class StorageManager final
|
2021-01-18 19:24:40 -06:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
StorageManager()
|
2021-02-14 08:31:38 -06:00
|
|
|
: _lastUploadTime(RequestManager::now())
|
2021-01-31 12:09:48 -06:00
|
|
|
, _lastUploadedFileModifiedTime(std::chrono::system_clock::now())
|
2021-01-18 19:24:40 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-14 08:31:38 -06:00
|
|
|
/// Marks the last time we attempted to upload, regardless of outcome, to now.
|
|
|
|
void markLastUploadTime() { _lastUploadTime = RequestManager::now(); }
|
|
|
|
|
|
|
|
// Gets the last time we attempted to upload.
|
|
|
|
std::chrono::steady_clock::time_point getLastUploadTime() const { return _lastUploadTime; }
|
2021-02-09 22:25:42 -06:00
|
|
|
|
|
|
|
/// Returns whether the last upload was successful or not.
|
|
|
|
bool lastUploadSuccessful() const { return _request.lastRequestSuccessful(); }
|
|
|
|
|
|
|
|
/// Sets whether the last upload was successful or not.
|
|
|
|
void setLastUploadResult(bool success) { _request.setLastRequestResult(success); }
|
2021-01-18 19:12:28 -06:00
|
|
|
|
2021-01-31 12:09:48 -06:00
|
|
|
/// Get the modified-timestamp of the local file on disk we last uploaded.
|
|
|
|
std::chrono::system_clock::time_point getLastUploadedFileModifiedTime() const
|
|
|
|
{
|
|
|
|
return _lastUploadedFileModifiedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the modified-timestamp of the local file on disk we last uploaded.
|
|
|
|
void setLastUploadedFileModifiedTime(std::chrono::system_clock::time_point modifiedTime)
|
|
|
|
{
|
|
|
|
_lastUploadedFileModifiedTime = modifiedTime;
|
|
|
|
}
|
|
|
|
|
2021-02-09 22:25:42 -06:00
|
|
|
/// Set the last modified time of the document.
|
|
|
|
void setLastModifiedTime(std::chrono::system_clock::time_point time)
|
|
|
|
{
|
|
|
|
_request.setModifiedTime(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the last modified time of the document.
|
|
|
|
std::chrono::system_clock::time_point getLastModifiedTime() const
|
|
|
|
{
|
|
|
|
return _request.getModifiedTime();
|
|
|
|
}
|
|
|
|
|
2021-01-18 19:24:40 -06:00
|
|
|
private:
|
2021-02-09 22:25:42 -06:00
|
|
|
/// Request tracking logic.
|
|
|
|
RequestManager _request;
|
|
|
|
|
2021-02-14 08:31:38 -06:00
|
|
|
/// The last time we tried uploading, regardless of whether the
|
|
|
|
/// document was modified and a newer version saved
|
2021-01-18 19:12:28 -06:00
|
|
|
/// and uploaded or not. In effect, this tracks the time we
|
|
|
|
/// synchronized with Storage (i.e. the last time we either uploaded
|
|
|
|
/// or had nothing new to upload). It is redundant as it is
|
|
|
|
/// equivalent to the larger of 'Last Save Response Time' and
|
|
|
|
/// 'Last Storage Response Time', and should be removed.
|
2021-02-14 08:31:38 -06:00
|
|
|
std::chrono::steady_clock::time_point _lastUploadTime;
|
2021-01-31 12:09:48 -06:00
|
|
|
|
|
|
|
/// The modified-timestamp of the local file on disk we uploaded last.
|
|
|
|
std::chrono::system_clock::time_point _lastUploadedFileModifiedTime;
|
2021-01-18 19:24:40 -06:00
|
|
|
};
|
|
|
|
|
2019-03-01 15:25:44 -06:00
|
|
|
protected:
|
2019-12-11 21:38:50 -06:00
|
|
|
/// Seconds to live for, or 0 forever
|
2020-12-06 13:02:46 -06:00
|
|
|
std::chrono::seconds _limitLifeSeconds;
|
2019-10-04 04:30:49 -05:00
|
|
|
std::string _uriOrig;
|
2021-01-19 21:04:07 -06:00
|
|
|
|
2020-12-03 20:14:30 -06:00
|
|
|
private:
|
2020-05-02 13:13:14 -05:00
|
|
|
/// What type are we: affects priority.
|
|
|
|
ChildType _type;
|
2016-03-10 20:42:33 -06:00
|
|
|
const Poco::URI _uriPublic;
|
2017-04-02 14:55:56 -05:00
|
|
|
/// URL-based key. May be repeated during the lifetime of WSD.
|
2016-03-12 18:29:17 -06:00
|
|
|
const std::string _docKey;
|
2017-04-02 14:55:56 -05:00
|
|
|
/// Short numerical ID. Unique during the lifetime of WSD.
|
|
|
|
const std::string _docId;
|
2016-04-24 10:08:08 -05:00
|
|
|
std::shared_ptr<ChildProcess> _childProcess;
|
2018-06-10 10:41:17 -05:00
|
|
|
std::string _uriJailed;
|
|
|
|
std::string _uriJailedAnonym;
|
2016-03-12 18:29:17 -06:00
|
|
|
std::string _jailId;
|
2016-03-21 18:12:00 -05:00
|
|
|
std::string _filename;
|
2017-01-01 18:42:19 -06:00
|
|
|
|
2021-01-18 05:41:08 -06:00
|
|
|
/// The state of the document.
|
|
|
|
/// This regulates all other primary operations.
|
|
|
|
class DocumentState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Strictly speaking, these are phases that are directional.
|
|
|
|
/// A document starts as New and progresses towards Unloaded.
|
|
|
|
/// Upon error, intermediary states may be skipped.
|
|
|
|
enum class Status
|
|
|
|
{
|
|
|
|
None, //< Doesn't exist, pending downloading.
|
|
|
|
Downloading, //< Download from Storage to disk. Synchronous.
|
|
|
|
Loading, //< Loading the document in Core.
|
|
|
|
Live, //< General availability for viewing/editing.
|
|
|
|
Destroying, //< End-of-life, marked to destroy.
|
|
|
|
Destroyed //< Unloading complete, destruction pending.
|
|
|
|
};
|
|
|
|
|
2021-05-24 21:05:47 -05:00
|
|
|
/// The current activity taking place.
|
|
|
|
/// Meaningful only when Status is Status::Live, but
|
|
|
|
/// we may Save and Upload during Status::Destroying.
|
|
|
|
enum class Activity
|
|
|
|
{
|
|
|
|
None, //< No particular activity.
|
|
|
|
Rename, //< The document is being renamed.
|
|
|
|
SaveAs, //< The document format is being converted.
|
|
|
|
Conflict, //< The document is conflicted in storaged.
|
|
|
|
Save, //< The document is being saved, manually or auto-save.
|
|
|
|
Upload, //< The document is being uploaded to storage.
|
|
|
|
};
|
|
|
|
|
2021-01-18 05:41:08 -06:00
|
|
|
static std::string toString(Status status)
|
|
|
|
{
|
|
|
|
#define CASE(X) \
|
|
|
|
case X: \
|
|
|
|
return #X;
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
CASE(Status::None);
|
|
|
|
CASE(Status::Downloading);
|
|
|
|
CASE(Status::Loading);
|
|
|
|
CASE(Status::Live);
|
|
|
|
CASE(Status::Destroying);
|
|
|
|
CASE(Status::Destroyed);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CASE
|
|
|
|
return "Unknown Document Status";
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:05:47 -05:00
|
|
|
static std::string toString(Activity activity)
|
|
|
|
{
|
|
|
|
#define CASE(X) \
|
|
|
|
case X: \
|
|
|
|
return #X;
|
|
|
|
switch (activity)
|
|
|
|
{
|
|
|
|
CASE(Activity::None);
|
|
|
|
CASE(Activity::Rename);
|
|
|
|
CASE(Activity::SaveAs);
|
|
|
|
CASE(Activity::Conflict);
|
|
|
|
CASE(Activity::Save);
|
|
|
|
CASE(Activity::Upload);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CASE
|
|
|
|
return "Unknown Document Activity";
|
|
|
|
}
|
|
|
|
|
2021-01-18 05:41:08 -06:00
|
|
|
DocumentState()
|
|
|
|
: _status(Status::None)
|
2021-05-24 21:05:47 -05:00
|
|
|
, _activity(Activity::None)
|
2021-01-24 14:01:35 -06:00
|
|
|
, _closeRequested(false)
|
2021-01-23 13:11:37 -06:00
|
|
|
, _loaded(false)
|
2021-02-26 09:01:39 -06:00
|
|
|
, _interactive(false)
|
2021-01-18 05:41:08 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentState::Status status() const { return _status; }
|
|
|
|
void setStatus(Status newStatus)
|
|
|
|
{
|
|
|
|
LOG_TRC("Setting DocumentState from " << toString(_status) << " to "
|
|
|
|
<< toString(newStatus));
|
|
|
|
assert(newStatus >= _status && "The document status cannot regress");
|
|
|
|
_status = newStatus;
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:05:47 -05:00
|
|
|
DocumentState::Activity activity() const { return _activity; }
|
|
|
|
void setActivity(Activity newActivity)
|
|
|
|
{
|
|
|
|
LOG_TRC("Setting Document Activity from " << toString(_activity) << " to "
|
|
|
|
<< toString(newActivity));
|
|
|
|
_activity = newActivity;
|
|
|
|
}
|
|
|
|
|
2021-01-23 13:11:37 -06:00
|
|
|
/// True iff the document had ever loaded completely, without implying it's still loaded.
|
|
|
|
bool hadLoaded() const { return _loaded; }
|
|
|
|
|
2021-01-18 06:10:56 -06:00
|
|
|
/// True iff the document is fully loaded and available for viewing/editing.
|
|
|
|
bool isLive() const { return _status == Status::Live; }
|
|
|
|
|
2021-01-23 13:11:37 -06:00
|
|
|
/// Transitions to Status::Live, implying the document has loaded.
|
|
|
|
void setLive()
|
|
|
|
{
|
|
|
|
LOG_TRC("Setting DocumentState to Status::Live from " << toString(_status));
|
|
|
|
// assert(_status == Status::Loading
|
|
|
|
// && "Document wasn't in Loading state to transition to Status::Live");
|
|
|
|
_loaded = true;
|
|
|
|
setStatus(Status::Live);
|
|
|
|
}
|
|
|
|
|
2021-01-18 06:10:56 -06:00
|
|
|
/// Flags the document for unloading and destruction.
|
|
|
|
void markToDestroy() { _status = Status::Destroying; }
|
|
|
|
bool isMarkedToDestroy() const { return _status >= Status::Destroying; }
|
|
|
|
|
|
|
|
/// Flag document termination. Cannot be reset.
|
2021-01-24 14:01:35 -06:00
|
|
|
void setCloseRequested() { _closeRequested = true; }
|
|
|
|
bool isCloseRequested() const { return _closeRequested; }
|
|
|
|
|
2021-02-26 09:01:39 -06:00
|
|
|
void setInteractive(bool value) { _interactive = value; }
|
|
|
|
bool isInteractive() const { return _interactive; }
|
|
|
|
|
2021-01-18 05:41:08 -06:00
|
|
|
private:
|
|
|
|
Status _status;
|
2021-05-24 21:05:47 -05:00
|
|
|
Activity _activity;
|
2021-01-24 14:01:35 -06:00
|
|
|
std::atomic<bool> _closeRequested; //< Owner-Termination flag.
|
2021-01-23 13:11:37 -06:00
|
|
|
std::atomic<bool> _loaded; //< If the document ever loaded (check isLive to see if it still is).
|
2021-02-26 09:01:39 -06:00
|
|
|
bool _interactive; //< If the document has interactive dialogs before load
|
2021-01-18 05:41:08 -06:00
|
|
|
};
|
|
|
|
|
2021-05-30 14:23:23 -05:00
|
|
|
/// Transition to a given activity. Returns false if an activity exists.
|
|
|
|
bool startActivity(DocumentState::Activity activity)
|
|
|
|
{
|
|
|
|
if (activity == DocumentState::Activity::None)
|
|
|
|
{
|
|
|
|
LOG_DBG("Error: Cannot start 'None' activity.");
|
|
|
|
assert(!"Cannot start 'None' activity.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_docState.activity() != DocumentState::Activity::None)
|
|
|
|
{
|
|
|
|
LOG_DBG("Error: Cannot start new activity ["
|
|
|
|
<< DocumentState::toString(activity) << "] while executing ["
|
|
|
|
<< DocumentState::toString(_docState.activity()) << ']');
|
|
|
|
assert(!"Cannot start new activity while executing another.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_docState.setActivity(activity);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ends the current activity.
|
|
|
|
void endActivity()
|
|
|
|
{
|
|
|
|
LOG_DBG("Ending [" << DocumentState::toString(_docState.activity()) << "] activity.");
|
|
|
|
_docState.setActivity(DocumentState::Activity::None);
|
|
|
|
}
|
|
|
|
|
2021-01-18 05:41:08 -06:00
|
|
|
/// The main state of the document.
|
|
|
|
DocumentState _docState;
|
|
|
|
|
2017-06-01 07:56:54 -05:00
|
|
|
/// Set to true when document changed in storage and we are waiting
|
|
|
|
/// for user's command to act.
|
|
|
|
bool _documentChangedInStorage;
|
|
|
|
|
2020-12-02 22:17:04 -06:00
|
|
|
/// Manage saving in Core.
|
|
|
|
SaveManager _saveManager;
|
|
|
|
|
2020-11-29 22:57:19 -06:00
|
|
|
/// The current upload request, if any.
|
|
|
|
/// For now we can only have one at a time.
|
|
|
|
std::unique_ptr<UploadRequest> _uploadRequest;
|
|
|
|
|
2021-01-18 19:24:40 -06:00
|
|
|
/// Manage uploading to Storage.
|
|
|
|
StorageManager _storageManager;
|
|
|
|
|
2018-01-14 17:59:11 -06:00
|
|
|
/// All session of this DocBroker by ID.
|
2020-01-02 15:11:54 -06:00
|
|
|
SessionMap<ClientSession> _sessions;
|
2017-03-06 12:05:49 -06:00
|
|
|
|
2020-04-26 15:55:16 -05:00
|
|
|
/// If we set the user-requested initial (on load) settings to be forced.
|
2018-04-24 11:09:37 -05:00
|
|
|
std::set<std::string> _isInitialStateSet;
|
|
|
|
|
2016-03-10 21:01:34 -06:00
|
|
|
std::unique_ptr<StorageBase> _storage;
|
2016-03-25 21:56:18 -05:00
|
|
|
std::unique_ptr<TileCache> _tileCache;
|
2016-10-08 09:31:35 -05:00
|
|
|
std::atomic<bool> _isModified;
|
2016-05-22 15:47:22 -05:00
|
|
|
int _cursorPosX;
|
|
|
|
int _cursorPosY;
|
2016-09-01 15:15:13 -05:00
|
|
|
int _cursorWidth;
|
|
|
|
int _cursorHeight;
|
2016-04-16 16:18:51 -05:00
|
|
|
mutable std::mutex _mutex;
|
2017-03-07 11:34:01 -06:00
|
|
|
std::unique_ptr<DocumentBrokerPoll> _poll;
|
2017-03-04 17:07:17 -06:00
|
|
|
std::atomic<bool> _stop;
|
2017-07-07 06:42:19 -05:00
|
|
|
std::string _closeReason;
|
2019-11-19 16:51:45 -06:00
|
|
|
std::unique_ptr<LockContext> _lockCtx;
|
2021-05-24 21:09:06 -05:00
|
|
|
std::string _renameFilename; //< The new filename to rename to.
|
|
|
|
std::string _renameSessionId; //< The sessionId used for renaming.
|
2016-04-09 22:20:20 -05:00
|
|
|
|
2016-05-22 13:31:18 -05:00
|
|
|
/// Versioning is used to prevent races between
|
|
|
|
/// painting and invalidation.
|
2020-11-15 11:03:45 -06:00
|
|
|
std::atomic<std::size_t> _tileVersion;
|
2016-05-22 13:31:18 -05:00
|
|
|
|
2016-10-11 07:39:56 -05:00
|
|
|
int _debugRenderedTileCount;
|
|
|
|
|
2017-01-01 18:42:19 -06:00
|
|
|
std::chrono::steady_clock::time_point _lastActivityTime;
|
2017-03-11 16:01:27 -06:00
|
|
|
std::chrono::steady_clock::time_point _threadStart;
|
|
|
|
std::chrono::milliseconds _loadDuration;
|
2021-02-15 08:29:51 -06:00
|
|
|
std::chrono::milliseconds _wopiDownloadDuration;
|
2016-12-14 10:12:57 -06:00
|
|
|
|
2017-04-02 14:55:56 -05:00
|
|
|
/// Unique DocBroker ID for tracing and debugging.
|
|
|
|
static std::atomic<unsigned> DocBrokerId;
|
2020-04-24 02:46:54 -05:00
|
|
|
|
|
|
|
// Relevant only in the mobile apps
|
|
|
|
const unsigned _mobileAppDocId;
|
2020-09-03 04:34:13 -05:00
|
|
|
|
|
|
|
// Maps download id -> URL
|
|
|
|
std::map<std::string, std::string> _registeredDownloadLinks;
|
2016-03-10 20:42:33 -06:00
|
|
|
};
|
|
|
|
|
2020-05-05 12:38:04 -05:00
|
|
|
#if !MOBILEAPP
|
2020-06-03 11:30:40 -05:00
|
|
|
class ConvertToBroker final : public DocumentBroker
|
2019-03-01 15:25:44 -06:00
|
|
|
{
|
2019-12-11 23:09:35 -06:00
|
|
|
const std::string _format;
|
|
|
|
const std::string _sOptions;
|
|
|
|
std::shared_ptr<ClientSession> _clientSession;
|
|
|
|
|
2019-03-01 15:25:44 -06:00
|
|
|
public:
|
|
|
|
/// Construct DocumentBroker with URI and docKey
|
|
|
|
ConvertToBroker(const std::string& uri,
|
|
|
|
const Poco::URI& uriPublic,
|
2019-12-11 23:09:35 -06:00
|
|
|
const std::string& docKey,
|
|
|
|
const std::string& format,
|
|
|
|
const std::string& sOptions);
|
2019-03-01 15:25:44 -06:00
|
|
|
virtual ~ConvertToBroker();
|
2019-03-12 09:41:54 -05:00
|
|
|
|
2019-12-11 23:09:35 -06:00
|
|
|
/// Move socket to this broker for response & do conversion
|
|
|
|
bool startConversion(SocketDisposition &disposition, const std::string &id);
|
|
|
|
|
2019-10-04 04:30:49 -05:00
|
|
|
/// Called when removed from the DocBrokers list
|
|
|
|
void dispose() override;
|
|
|
|
|
2019-12-11 23:09:35 -06:00
|
|
|
/// When the load completes - lets start saving
|
|
|
|
void setLoaded() override;
|
|
|
|
|
2019-03-12 09:41:54 -05:00
|
|
|
/// How many live conversions are running.
|
2020-11-15 11:03:45 -06:00
|
|
|
static std::size_t getInstanceCount();
|
2019-05-21 13:50:17 -05:00
|
|
|
|
|
|
|
/// Cleanup path and its parent
|
|
|
|
static void removeFile(const std::string &uri);
|
2020-11-22 16:36:44 -06:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool isConvertTo() const override { return true; }
|
2019-03-01 15:25:44 -06:00
|
|
|
};
|
2020-05-05 12:38:04 -05:00
|
|
|
#endif
|
2019-03-01 15:25:44 -06:00
|
|
|
|
2016-03-10 20:42:33 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|