2016-05-16 06:37:02 -05: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/.
|
|
|
|
*/
|
|
|
|
|
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 "ClientSession.hpp"
|
2016-05-16 06:37:02 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
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 <fstream>
|
|
|
|
|
2016-05-16 06:37:02 -05:00
|
|
|
#include <Poco/FileStream.h>
|
|
|
|
#include <Poco/JSON/Object.h>
|
|
|
|
#include <Poco/JSON/Parser.h>
|
|
|
|
#include <Poco/URI.h>
|
|
|
|
#include <Poco/URIStreamOpener.h>
|
|
|
|
|
|
|
|
#include "Common.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 "IoUtil.hpp"
|
2016-11-24 08:56:06 -06:00
|
|
|
#include "Protocol.hpp"
|
|
|
|
#include "Session.hpp"
|
2016-05-16 06:37:02 -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-05-16 18:05:22 -05:00
|
|
|
#include "PrisonerSession.hpp"
|
2016-05-16 06:37:02 -05:00
|
|
|
#include "Rectangle.hpp"
|
|
|
|
#include "Storage.hpp"
|
|
|
|
#include "TileCache.hpp"
|
|
|
|
#include "Util.hpp"
|
2016-05-16 17:22:41 -05:00
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
using namespace LOOLProtocol;
|
|
|
|
|
|
|
|
using Poco::StringTokenizer;
|
|
|
|
|
2016-05-16 19:49:36 -05:00
|
|
|
ClientSession::ClientSession(const std::string& id,
|
2016-11-10 02:47:25 -06:00
|
|
|
const std::shared_ptr<LOOLWebSocket>& ws,
|
2016-10-16 12:20:49 -05:00
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker,
|
2016-10-16 11:40:52 -05:00
|
|
|
const Poco::URI& uriPublic,
|
|
|
|
const bool readOnly) :
|
2016-12-12 19:18:25 -06:00
|
|
|
Session("ToClient-" + id, id, ws),
|
2016-10-16 12:20:49 -05:00
|
|
|
_docBroker(docBroker),
|
2016-10-16 11:40:52 -05:00
|
|
|
_uriPublic(uriPublic),
|
2016-07-11 02:45:10 -05:00
|
|
|
_isReadOnly(readOnly),
|
2016-11-08 07:37:28 -06:00
|
|
|
_isDocumentOwner(false),
|
2016-05-16 20:03:45 -05:00
|
|
|
_loadPart(-1)
|
2016-05-16 19:49:36 -05:00
|
|
|
{
|
|
|
|
Log::info("ClientSession ctor [" + getName() + "].");
|
|
|
|
}
|
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
ClientSession::~ClientSession()
|
|
|
|
{
|
2016-05-17 17:33:37 -05:00
|
|
|
Log::info("~ClientSession dtor [" + getName() + "].");
|
2016-05-16 18:05:22 -05:00
|
|
|
|
|
|
|
// Release the save-as queue.
|
|
|
|
_saveAsQueue.put("");
|
|
|
|
}
|
|
|
|
|
2016-11-13 11:26:00 -06:00
|
|
|
void ClientSession::bridgePrisonerSession()
|
|
|
|
{
|
|
|
|
auto docBroker = getDocumentBroker();
|
|
|
|
if (docBroker)
|
|
|
|
{
|
|
|
|
_peer = std::make_shared<PrisonerSession>(shared_from_this(), docBroker);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const std::string msg = "No valid DocBroker while bridging Prisoner Session for " + getName();
|
|
|
|
LOG_ERR(msg);
|
|
|
|
throw std::runtime_error(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
bool ClientSession::_handleInput(const char *buffer, int length)
|
|
|
|
{
|
|
|
|
const std::string firstLine = getFirstLine(buffer, length);
|
|
|
|
StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
|
|
|
Log::trace(getName() + ": handling [" + firstLine + "].");
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
auto docBroker = getDocumentBroker();
|
|
|
|
if (!docBroker)
|
|
|
|
{
|
|
|
|
Log::error("No DocBroker found. Terminating session " + getName());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOLWSD::dumpIncomingTrace(docBroker->getJailId(), getId(), firstLine);
|
2016-07-30 22:06:12 -05:00
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0]))
|
|
|
|
{
|
|
|
|
// Keep track of timestamps of incoming client messages that indicate user activity.
|
|
|
|
updateLastActivityTime();
|
2016-12-05 14:11:07 -06:00
|
|
|
docBroker->updateLastActivityTime();
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tokens[0] == "loolclient")
|
|
|
|
{
|
|
|
|
const auto versionTuple = ParseVersion(tokens[1]);
|
|
|
|
if (std::get<0>(versionTuple) != ProtocolMajorVersionNumber ||
|
|
|
|
std::get<1>(versionTuple) != ProtocolMinorVersionNumber)
|
|
|
|
{
|
2016-06-20 13:58:00 -05:00
|
|
|
sendTextFrame("error: cmd=loolclient kind=badprotocolversion");
|
2016-05-16 18:05:22 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:58:00 -05:00
|
|
|
// Send LOOL version information
|
|
|
|
std::string version, hash;
|
|
|
|
Util::getVersionInfo(version, hash);
|
2016-06-21 11:41:33 -05:00
|
|
|
std::string versionStr =
|
|
|
|
"{ \"Version\": \"" + version + "\", " +
|
|
|
|
"\"Hash\": \"" + hash + "\", " +
|
|
|
|
"\"Protocol\": \"" + GetProtocolVersion() + "\" }";
|
|
|
|
sendTextFrame("loolserver " + versionStr);
|
2016-06-20 13:58:00 -05:00
|
|
|
// Send LOKit version information
|
|
|
|
sendTextFrame("lokitversion " + LOOLWSD::LOKitVersion);
|
|
|
|
|
|
|
|
return true;
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
|
2016-09-20 02:46:39 -05:00
|
|
|
if (tokens[0] == "load")
|
2016-05-16 18:05:22 -05:00
|
|
|
{
|
|
|
|
if (_docURL != "")
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=docalreadyloaded");
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-16 12:20:49 -05:00
|
|
|
|
|
|
|
return loadDocument(buffer, length, tokens, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else if (tokens[0] != "canceltiles" &&
|
|
|
|
tokens[0] != "clientzoom" &&
|
|
|
|
tokens[0] != "clientvisiblearea" &&
|
|
|
|
tokens[0] != "commandvalues" &&
|
2016-11-08 07:37:28 -06:00
|
|
|
tokens[0] != "closedocument" &&
|
2016-05-16 18:05:22 -05:00
|
|
|
tokens[0] != "downloadas" &&
|
|
|
|
tokens[0] != "getchildid" &&
|
|
|
|
tokens[0] != "gettextselection" &&
|
|
|
|
tokens[0] != "paste" &&
|
|
|
|
tokens[0] != "insertfile" &&
|
|
|
|
tokens[0] != "key" &&
|
|
|
|
tokens[0] != "mouse" &&
|
|
|
|
tokens[0] != "partpagerectangles" &&
|
2016-09-27 13:22:09 -05:00
|
|
|
tokens[0] != "ping" &&
|
2016-05-16 18:05:22 -05:00
|
|
|
tokens[0] != "renderfont" &&
|
|
|
|
tokens[0] != "requestloksession" &&
|
|
|
|
tokens[0] != "resetselection" &&
|
|
|
|
tokens[0] != "saveas" &&
|
|
|
|
tokens[0] != "selectgraphic" &&
|
|
|
|
tokens[0] != "selecttext" &&
|
|
|
|
tokens[0] != "setclientpart" &&
|
|
|
|
tokens[0] != "setpage" &&
|
|
|
|
tokens[0] != "status" &&
|
|
|
|
tokens[0] != "tile" &&
|
|
|
|
tokens[0] != "tilecombine" &&
|
|
|
|
tokens[0] != "uno" &&
|
|
|
|
tokens[0] != "useractive" &&
|
|
|
|
tokens[0] != "userinactive")
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=" + tokens[0] + " kind=unknown");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (_docURL == "")
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "canceltiles")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
docBroker->cancelTileRequests(shared_from_this());
|
2016-08-30 22:15:44 -05:00
|
|
|
return true;
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else if (tokens[0] == "commandvalues")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
return getCommandValues(buffer, length, tokens, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
2016-11-08 07:37:28 -06:00
|
|
|
else if (tokens[0] == "closedocument")
|
|
|
|
{
|
2016-12-13 03:16:34 -06:00
|
|
|
// If this session is the owner of the file & 'EnableOwnerTermination' feature
|
|
|
|
// is turned on by WOPI, let it close all sessions
|
|
|
|
if (_isDocumentOwner && _wopiFileInfo && _wopiFileInfo->_enableOwnerTermination)
|
2016-11-08 07:37:28 -06:00
|
|
|
{
|
|
|
|
LOG_DBG("Session [" + getId() + "] requested owner termination");
|
|
|
|
docBroker->closeDocument("ownertermination");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 18:05:22 -05:00
|
|
|
else if (tokens[0] == "partpagerectangles")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
return getPartPageRectangles(buffer, length, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
2016-09-27 13:22:09 -05:00
|
|
|
else if (tokens[0] == "ping")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
std::string count = std::to_string(docBroker->getRenderedTileCount());
|
2016-10-11 07:39:56 -05:00
|
|
|
sendTextFrame("pong rendercount=" + count);
|
2016-09-27 13:22:09 -05:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 18:05:22 -05:00
|
|
|
else if (tokens[0] == "renderfont")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
return sendFontRendering(buffer, length, tokens, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else if (tokens[0] == "status")
|
|
|
|
{
|
2016-10-16 12:43:44 -05:00
|
|
|
assert(firstLine.size() == static_cast<size_t>(length));
|
|
|
|
return forwardToChild(firstLine, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else if (tokens[0] == "tile")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
return sendTile(buffer, length, tokens, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else if (tokens[0] == "tilecombine")
|
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
return sendCombinedTiles(buffer, length, tokens, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-05 06:18:33 -06:00
|
|
|
if (!filterMessage(firstLine))
|
2016-05-16 18:05:22 -05:00
|
|
|
{
|
2016-10-16 12:43:44 -05:00
|
|
|
const std::string dummyFrame = "dummymsg";
|
|
|
|
return forwardToChild(dummyFrame, docBroker);
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
else if (tokens[0] != "requestloksession")
|
|
|
|
{
|
2016-10-16 12:43:44 -05:00
|
|
|
return forwardToChild(std::string(buffer, length), docBroker);
|
2016-05-20 18:25:38 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(tokens[0] == "requestloksession");
|
|
|
|
return true;
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
}
|
2016-05-20 18:25:38 -05:00
|
|
|
|
|
|
|
return false;
|
2016-05-16 18:05:22 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens,
|
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-05-16 18:11:34 -05:00
|
|
|
{
|
|
|
|
if (tokens.count() < 2)
|
|
|
|
{
|
2016-05-20 18:25:38 -05:00
|
|
|
// Failed loading ends connection.
|
2016-05-16 18:11:34 -05:00
|
|
|
sendTextFrame("error: cmd=load kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-20 14:25:42 -05:00
|
|
|
Log::info("Requesting document load from child.");
|
2016-05-16 18:11:34 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
std::string timestamp;
|
|
|
|
parseDocOptions(tokens, _loadPart, timestamp);
|
|
|
|
|
2016-05-20 14:25:42 -05:00
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "load";
|
2016-10-16 12:20:49 -05:00
|
|
|
oss << " url=" << docBroker->getPublicUri().toString();
|
|
|
|
oss << " jail=" << docBroker->getJailedUri().toString();
|
2016-05-16 18:11:34 -05:00
|
|
|
|
2016-10-26 09:35:40 -05:00
|
|
|
if (!_userId.empty() && !_userName.empty())
|
2016-08-30 01:08:07 -05:00
|
|
|
{
|
2016-10-26 09:35:40 -05:00
|
|
|
std::string encodedUserId;
|
|
|
|
Poco::URI::encode(_userId, "", encodedUserId);
|
|
|
|
oss << " authorid=" + encodedUserId;
|
|
|
|
|
2016-08-30 01:08:07 -05:00
|
|
|
std::string encodedUserName;
|
|
|
|
Poco::URI::encode(_userName, "", encodedUserName);
|
|
|
|
oss << " author=" + encodedUserName;
|
|
|
|
}
|
2016-08-29 13:08:01 -05:00
|
|
|
|
2016-05-20 14:25:42 -05:00
|
|
|
if (_loadPart >= 0)
|
|
|
|
oss << " part=" + std::to_string(_loadPart);
|
|
|
|
|
|
|
|
if (_haveDocPassword)
|
|
|
|
oss << " password=" << _docPassword;
|
|
|
|
|
|
|
|
if (!_docOptions.empty())
|
|
|
|
oss << " options=" << _docOptions;
|
|
|
|
|
|
|
|
const auto loadRequest = oss.str();
|
2016-10-16 12:43:44 -05:00
|
|
|
return forwardToChild(loadRequest, docBroker);
|
2016-05-16 18:11:34 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::SyntaxException&)
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=uriinvalid");
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
bool ClientSession::getCommandValues(const char *buffer, int length, StringTokenizer& tokens,
|
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
|
|
|
std::string command;
|
|
|
|
if (tokens.count() != 2 || !getTokenString(tokens[1], "command", command))
|
|
|
|
{
|
2016-05-20 18:25:38 -05:00
|
|
|
return sendTextFrame("error: cmd=commandvalues kind=syntax");
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
const std::string cmdValues = docBroker->tileCache().getTextFile("cmdValues" + command + ".txt");
|
2016-05-16 06:37:02 -05:00
|
|
|
if (cmdValues.size() > 0)
|
|
|
|
{
|
2016-05-20 18:25:38 -05:00
|
|
|
return sendTextFrame(cmdValues);
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:43:44 -05:00
|
|
|
return forwardToChild(std::string(buffer, length), docBroker);
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
bool ClientSession::getPartPageRectangles(const char *buffer, int length,
|
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
2016-10-16 12:20:49 -05:00
|
|
|
const std::string partPageRectangles = docBroker->tileCache().getTextFile("partpagerectangles.txt");
|
2016-05-16 06:37:02 -05:00
|
|
|
if (partPageRectangles.size() > 0)
|
|
|
|
{
|
2016-05-20 18:25:38 -05:00
|
|
|
return sendTextFrame(partPageRectangles);
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:43:44 -05:00
|
|
|
return forwardToChild(std::string(buffer, length), docBroker);
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
bool ClientSession::sendFontRendering(const char *buffer, int length, StringTokenizer& tokens,
|
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
2016-11-27 17:49:17 -06:00
|
|
|
std::string font, text;
|
2016-05-16 06:37:02 -05:00
|
|
|
if (tokens.count() < 2 ||
|
|
|
|
!getTokenString(tokens[1], "font", font))
|
|
|
|
{
|
2016-05-20 18:25:38 -05:00
|
|
|
return sendTextFrame("error: cmd=renderfont kind=syntax");
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-11-11 11:24:13 -06:00
|
|
|
getTokenString(tokens[2], "char", text);
|
2016-05-16 06:37:02 -05:00
|
|
|
const std::string response = "renderfont: " + Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end()) + "\n";
|
|
|
|
|
|
|
|
std::vector<char> output;
|
|
|
|
output.resize(response.size());
|
|
|
|
std::memcpy(output.data(), response.data(), response.size());
|
|
|
|
|
2016-11-27 17:49:17 -06:00
|
|
|
std::unique_ptr<std::fstream> cachedRendering = docBroker->tileCache().lookupCachedFile(font+text, "font");
|
2016-05-16 06:37:02 -05:00
|
|
|
if (cachedRendering && cachedRendering->is_open())
|
|
|
|
{
|
|
|
|
cachedRendering->seekg(0, std::ios_base::end);
|
|
|
|
size_t pos = output.size();
|
|
|
|
std::streamsize size = cachedRendering->tellg();
|
|
|
|
output.resize(pos + size);
|
|
|
|
cachedRendering->seekg(0, std::ios_base::beg);
|
|
|
|
cachedRendering->read(output.data() + pos, size);
|
|
|
|
cachedRendering->close();
|
|
|
|
|
2016-05-20 18:25:38 -05:00
|
|
|
return sendBinaryFrame(output.data(), output.size());
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:43:44 -05:00
|
|
|
return forwardToChild(std::string(buffer, length), docBroker);
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
bool ClientSession::sendTile(const char * /*buffer*/, int /*length*/, StringTokenizer& tokens,
|
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto tileDesc = TileDesc::parse(tokens);
|
2016-10-16 12:20:49 -05:00
|
|
|
docBroker->handleTileRequest(tileDesc, shared_from_this());
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
catch (const std::exception& exc)
|
|
|
|
{
|
|
|
|
Log::error(std::string("Failed to process tile command: ") + exc.what() + ".");
|
2016-05-20 18:25:38 -05:00
|
|
|
return sendTextFrame("error: cmd=tile kind=invalid");
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
2016-05-20 18:25:38 -05:00
|
|
|
|
|
|
|
return true;
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:20:49 -05:00
|
|
|
bool ClientSession::sendCombinedTiles(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens,
|
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
2016-05-22 10:45:28 -05:00
|
|
|
try
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
2016-05-22 10:45:28 -05:00
|
|
|
auto tileCombined = TileCombined::parse(tokens);
|
2016-10-16 12:20:49 -05:00
|
|
|
docBroker->handleTileCombinedRequest(tileCombined, shared_from_this());
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
2016-05-22 10:45:28 -05:00
|
|
|
catch (const std::exception& exc)
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
2016-05-22 10:45:28 -05:00
|
|
|
Log::error(std::string("Failed to process tilecombine command: ") + exc.what() + ".");
|
|
|
|
return sendTextFrame("error: cmd=tile kind=invalid");
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
2016-05-20 18:25:38 -05:00
|
|
|
|
|
|
|
return true;
|
2016-05-16 06:37:02 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 12:43:44 -05:00
|
|
|
bool ClientSession::forwardToChild(const std::string& message,
|
2016-10-16 12:20:49 -05:00
|
|
|
const std::shared_ptr<DocumentBroker>& docBroker)
|
2016-10-08 13:25:27 -05:00
|
|
|
{
|
2016-10-16 12:43:44 -05:00
|
|
|
return docBroker->forwardToChild(getId(), message);
|
2016-10-08 13:25:27 -05:00
|
|
|
}
|
|
|
|
|
2016-12-05 06:18:33 -06:00
|
|
|
bool ClientSession::filterMessage(const std::string& message) const
|
|
|
|
{
|
|
|
|
bool allowed = true;
|
|
|
|
StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
|
|
|
if (isReadOnly())
|
|
|
|
{
|
|
|
|
allowed = false;
|
|
|
|
if (tokens[0] == "downloadas" || tokens[0] == "userinactive" || tokens[0] == "useractive")
|
|
|
|
{
|
|
|
|
allowed = true;
|
|
|
|
}
|
2016-12-05 06:20:22 -06:00
|
|
|
else if (tokens[0] == "uno")
|
|
|
|
{
|
|
|
|
if (tokens[1] == ".uno:ExecuteSearch")
|
|
|
|
{
|
|
|
|
allowed = true;
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 06:18:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return allowed;
|
|
|
|
}
|
|
|
|
|
2016-10-19 09:52:53 -05:00
|
|
|
void ClientSession::setReadOnly()
|
|
|
|
{
|
|
|
|
_isReadOnly = true;
|
|
|
|
// Also inform the client
|
|
|
|
sendTextFrame("perm: readonly");
|
|
|
|
}
|
|
|
|
|
2016-05-16 06:37:02 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|