2015-04-13 04:09:02 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2015-03-04 17:14:04 -06:00
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2015-03-09 03:01:30 -05:00
|
|
|
#ifndef INCLUDED_LOOLSESSION_HPP
|
|
|
|
#define INCLUDED_LOOLSESSION_HPP
|
|
|
|
|
2015-04-08 09:22:42 -05:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.h>
|
|
|
|
|
|
|
|
#include <Poco/Net/WebSocket.h>
|
2015-03-17 18:56:15 -05:00
|
|
|
#include <Poco/Buffer.h>
|
2015-04-16 11:15:40 -05:00
|
|
|
#include <Poco/Path.h>
|
|
|
|
#include <Poco/Process.h>
|
2015-03-04 17:14:04 -06:00
|
|
|
#include <Poco/StringTokenizer.h>
|
2015-03-17 18:56:15 -05:00
|
|
|
#include <Poco/Types.h>
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
#include "TileCache.hpp"
|
|
|
|
|
2015-04-10 07:20:04 -05:00
|
|
|
// LOOLSession objects are used for three different purposes. This is probably not a good idea, I
|
|
|
|
// should introduce derived classes instead.
|
|
|
|
|
|
|
|
// 1) The Websocket session between the parent loolwsd process to the end-user LOOL client
|
|
|
|
// 2) The session between the parent loolwsd and a child loolwsd process, in the parent loolwsd
|
|
|
|
// 3) Ditto, in the child loolwsd
|
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
class LOOLSession
|
2015-03-04 17:14:04 -06:00
|
|
|
{
|
2015-03-12 18:34:42 -05:00
|
|
|
public:
|
2015-04-13 07:13:38 -05:00
|
|
|
LOOLSession(Poco::Net::WebSocket& ws, LibreOfficeKit *loKit = nullptr, Poco::UInt64 childId = 0);
|
2015-03-09 03:01:30 -05:00
|
|
|
~LOOLSession();
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-04-13 07:13:38 -05:00
|
|
|
static const std::string jailDocumentURL;
|
|
|
|
|
2015-03-07 05:23:46 -06:00
|
|
|
bool handleInput(char *buffer, int length);
|
2015-03-12 18:34:42 -05:00
|
|
|
bool haveSeparateProcess() const;
|
2015-03-17 18:56:15 -05:00
|
|
|
bool toChildProcess() const;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-26 04:25:22 -05:00
|
|
|
void sendTextFrame(const std::string& text);
|
2015-03-04 17:14:04 -06:00
|
|
|
void sendBinaryFrame(const char *buffer, int length);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-04-16 11:15:40 -05:00
|
|
|
static Poco::Path getJailPath(Poco::UInt64 childId);
|
|
|
|
|
2015-04-08 09:22:42 -05:00
|
|
|
// Set up the chroot environment for one child process and start
|
|
|
|
// it, in advance of it being actually needed
|
2015-04-15 07:17:15 -05:00
|
|
|
static void preSpawn();
|
2015-04-08 09:22:42 -05:00
|
|
|
|
2015-04-16 11:15:40 -05:00
|
|
|
static std::map<Poco::Process::PID, Poco::UInt64> _childProcesses;
|
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
private:
|
2015-03-17 18:56:15 -05:00
|
|
|
bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool getStatus(const char *buffer, int length);
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-19 07:38:04 -05:00
|
|
|
bool keyEvent(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool mouseEvent(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool unoCommand(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool selectText(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool selectGraphic(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
2015-03-20 07:56:37 -05:00
|
|
|
bool resetSelection(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
2015-03-23 15:13:57 -05:00
|
|
|
bool saveAs(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
2015-03-19 07:38:04 -05:00
|
|
|
|
2015-04-08 09:22:42 -05:00
|
|
|
void dispatchChild();
|
2015-04-14 09:50:38 -05:00
|
|
|
void forwardToPeer(const char *buffer, int length);
|
2015-03-09 10:33:53 -05:00
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
bool isChildProcess() const;
|
|
|
|
|
|
|
|
// Fields common to parent and child:
|
|
|
|
|
|
|
|
// In the parent process, the websocket to the LOOL client or the
|
|
|
|
// child process. In a child process, the websocket to the
|
|
|
|
// parent.
|
2015-04-08 09:22:42 -05:00
|
|
|
Poco::Net::WebSocket *_ws;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
// Whether this session is to a LOOL client or to a child process
|
|
|
|
bool _toChildProcess;
|
|
|
|
|
2015-04-08 09:22:42 -05:00
|
|
|
// In the parent, the actual URL. In the child, the copy inside the chroot jail.
|
|
|
|
std::string _docURL;
|
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
// Parent only:
|
|
|
|
|
2015-04-13 07:13:38 -05:00
|
|
|
// If haveSeparateProcess() is true and the child process has started and completed its
|
2015-04-14 09:50:38 -05:00
|
|
|
// handshake with the parent process: Points to the LOOLSession for the child process handling
|
|
|
|
// the document in question, if any.
|
2015-03-17 18:56:15 -05:00
|
|
|
|
2015-04-14 09:50:38 -05:00
|
|
|
// In the session to the child process, points to the LOOLSession for the LOOL client. This will
|
2015-04-13 07:13:38 -05:00
|
|
|
// obvious have to be rethought when we add collaboration and there can be several LOOL clients
|
|
|
|
// per document being edited (i.e., per child process).
|
2015-04-14 09:50:38 -05:00
|
|
|
LOOLSession *_peer;
|
2015-03-17 18:56:15 -05:00
|
|
|
|
|
|
|
// The id of the child process
|
|
|
|
Poco::UInt64 _childId;
|
|
|
|
|
2015-04-14 09:50:38 -05:00
|
|
|
std::unique_ptr<TileCache> _tileCache;
|
|
|
|
|
2015-04-08 09:22:42 -05:00
|
|
|
// Map from child ids to the corresponding session to the child
|
|
|
|
// process.
|
|
|
|
static std::map<Poco::UInt64, LOOLSession*> _childIdToChildSession;
|
|
|
|
|
2015-04-15 07:17:15 -05:00
|
|
|
// Pre-spawned child processes that haven't yet connected.
|
|
|
|
static std::set<Poco::UInt64> _pendingPreSpawnedChildren;
|
2015-03-17 18:56:15 -05:00
|
|
|
|
2015-04-08 09:22:42 -05:00
|
|
|
// Child processes that have connected but are not yet assigned a
|
|
|
|
// document to work on.
|
|
|
|
static std::set<LOOLSession*> _availableChildSessions;
|
2015-03-17 18:56:15 -05:00
|
|
|
|
|
|
|
// Child only:
|
2015-04-08 09:22:42 -05:00
|
|
|
std::string _jail;
|
|
|
|
std::string _loSubPath;
|
2015-03-17 18:56:15 -05:00
|
|
|
LibreOfficeKit *_loKit;
|
|
|
|
LibreOfficeKitDocument *_loKitDocument;
|
2015-03-04 17:14:04 -06:00
|
|
|
};
|
|
|
|
|
2015-03-09 03:01:30 -05:00
|
|
|
#endif
|
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|