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-20 09:43:31 -05:00
|
|
|
#include <cassert>
|
2015-05-07 08:29:36 -05:00
|
|
|
#include <condition_variable>
|
2015-04-08 09:22:42 -05:00
|
|
|
#include <map>
|
2015-04-22 13:35:52 -05:00
|
|
|
#include <memory>
|
2015-05-07 08:29:36 -05:00
|
|
|
#include <mutex>
|
2015-04-20 09:43:31 -05:00
|
|
|
#include <ostream>
|
2015-04-08 09:22:42 -05:00
|
|
|
#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-05-07 12:01:40 -05:00
|
|
|
#include <Poco/Random.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-11-09 04:36:37 -06:00
|
|
|
#include "MessageQueue.hpp"
|
2015-03-12 18:34:42 -05:00
|
|
|
#include "TileCache.hpp"
|
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
// We have three kinds of Websocket sessions
|
|
|
|
// 1) Between the master loolwsd server to the end-user LOOL client
|
|
|
|
// 2) Between the master loolwsd server and a jailed loolwsd child process, in the master process
|
|
|
|
// 3) Ditto, in the jailed loolwsd process
|
2015-04-10 07:20:04 -05:00
|
|
|
|
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-20 09:43:31 -05:00
|
|
|
enum class Kind { ToClient, ToPrisoner, ToMaster };
|
|
|
|
|
|
|
|
void sendTextFrame(const std::string& text);
|
|
|
|
|
2015-05-28 06:51:08 -05:00
|
|
|
virtual bool getStatus(const char *buffer, int length) = 0;
|
|
|
|
|
2015-09-09 12:23:49 -05:00
|
|
|
virtual bool getCommandValues(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0;
|
2015-08-18 13:01:05 -05:00
|
|
|
|
2015-09-29 05:27:45 -05:00
|
|
|
virtual bool getPartPageRectangles(const char *buffer, int length) = 0;
|
|
|
|
|
2015-12-25 12:51:32 -06:00
|
|
|
bool handleInput(const char *buffer, int length);
|
2015-06-09 10:04:46 -05:00
|
|
|
|
2015-10-09 07:55:49 -05:00
|
|
|
static const std::string jailDocumentURL;
|
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
protected:
|
2015-05-28 08:42:38 -05:00
|
|
|
LOOLSession(std::shared_ptr<Poco::Net::WebSocket> ws, Kind kind);
|
2015-04-20 09:43:31 -05:00
|
|
|
virtual ~LOOLSession();
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
const Kind _kind;
|
|
|
|
|
2015-07-20 04:54:08 -05:00
|
|
|
std::string _kindString;
|
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
void sendBinaryFrame(const char *buffer, int length);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-11-19 03:30:00 -06:00
|
|
|
/// Parses the options of the "load" command, shared between MasterProcessSession::loadDocument() and ChildProcessSession::loadDocument().
|
|
|
|
void parseDocOptions(const Poco::StringTokenizer& tokens, int& part, std::string& timestamp);
|
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0;
|
2015-04-16 11:15:40 -05:00
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0;
|
2015-04-08 09:22:42 -05:00
|
|
|
|
2015-11-27 08:13:25 -06:00
|
|
|
virtual void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0;
|
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
// Fields common to sessions in master and jailed processes:
|
2015-04-16 11:15:40 -05:00
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
// In the master process, the websocket to the LOOL client or the jailed child process. In a
|
|
|
|
// jailed process, the websocket to the parent.
|
2015-05-28 08:42:38 -05:00
|
|
|
std::shared_ptr<Poco::Net::WebSocket> _ws;
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-06-05 05:05:51 -05:00
|
|
|
// The actual URL, also in the child, even if the child never accesses that.
|
2015-04-20 09:43:31 -05:00
|
|
|
std::string _docURL;
|
2015-06-05 08:12:06 -05:00
|
|
|
|
2015-11-18 11:09:13 -06:00
|
|
|
/// Document options: a JSON string, containing options (rendering, also possibly load in the future).
|
|
|
|
std::string _docOptions;
|
|
|
|
|
2015-12-25 12:51:32 -06:00
|
|
|
private:
|
|
|
|
|
|
|
|
virtual bool _handleInput(const char *buffer, int length) = 0;
|
|
|
|
|
2015-06-05 08:12:06 -05:00
|
|
|
private:
|
|
|
|
std::mutex _mutex;
|
2015-04-20 09:43:31 -05:00
|
|
|
};
|
2015-03-09 10:33:53 -05:00
|
|
|
|
2015-04-20 09:43:31 -05:00
|
|
|
template<typename charT, typename traits>
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(std::basic_ostream<charT, traits> & stream, LOOLSession::Kind kind)
|
|
|
|
{
|
|
|
|
switch (kind)
|
|
|
|
{
|
|
|
|
case LOOLSession::Kind::ToClient:
|
|
|
|
return stream << "TO_CLIENT";
|
|
|
|
case LOOLSession::Kind::ToPrisoner:
|
|
|
|
return stream << "TO_PRISONER";
|
|
|
|
case LOOLSession::Kind::ToMaster:
|
|
|
|
return stream << "TO_MASTER";
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
return stream << "UNK_" + std::to_string(static_cast<int>(kind));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 03:01:30 -05:00
|
|
|
#endif
|
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|