2015-12-12 13:23:44 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
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 "ChildSession.hpp"
|
2016-04-15 09:13:04 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-08-30 00:19:49 -05:00
|
|
|
#include <sstream>
|
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
#include <Poco/JSON/Object.h>
|
|
|
|
#include <Poco/JSON/Parser.h>
|
|
|
|
#include <Poco/Net/WebSocket.h>
|
|
|
|
#include <Poco/StringTokenizer.h>
|
|
|
|
#include <Poco/URI.h>
|
|
|
|
|
2016-11-12 15:38:13 -06:00
|
|
|
#include "common/FileUtil.hpp"
|
2016-11-24 08:56:06 -06:00
|
|
|
#include "KitHelper.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-21 10:31:04 -05:00
|
|
|
#include "Png.hpp"
|
2016-03-08 01:31:29 -06:00
|
|
|
#include "Util.hpp"
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
using Poco::JSON::Object;
|
|
|
|
using Poco::JSON::Parser;
|
|
|
|
using Poco::StringTokenizer;
|
2016-04-04 05:29:02 -05:00
|
|
|
using Poco::Timestamp;
|
2015-12-12 13:23:44 -06:00
|
|
|
using Poco::URI;
|
|
|
|
|
2016-08-13 18:17:03 -05:00
|
|
|
using namespace LOOLProtocol;
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
std::recursive_mutex ChildSession::Mutex;
|
2015-12-19 14:55:19 -06:00
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
ChildSession::ChildSession(const std::string& id,
|
2016-05-17 17:28:59 -05:00
|
|
|
const std::string& jailId,
|
2016-08-14 17:02:51 -05:00
|
|
|
IDocumentManager& docManager) :
|
2016-10-12 22:04:07 -05:00
|
|
|
LOOLSession(id, Kind::ToMaster, nullptr),
|
2016-01-06 21:47:01 -06:00
|
|
|
_jailId(jailId),
|
2016-08-21 11:56:58 -05:00
|
|
|
_docManager(docManager),
|
2016-08-17 18:51:34 -05:00
|
|
|
_viewId(-1),
|
2016-08-21 11:56:58 -05:00
|
|
|
_isDocLoaded(false)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("ChildSession ctor [" << getName() << "].");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
ChildSession::~ChildSession()
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("~ChildSession dtor [" << getName() << "].");
|
2015-12-26 10:12:52 -06:00
|
|
|
|
2016-01-21 08:26:34 -06:00
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
void ChildSession::disconnect()
|
2016-01-21 08:26:34 -06:00
|
|
|
{
|
|
|
|
if (!isDisconnected())
|
|
|
|
{
|
2016-01-23 16:32:09 -06:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(Mutex);
|
2016-01-08 11:59:57 -06:00
|
|
|
|
2016-08-17 18:51:34 -05:00
|
|
|
if (_viewId >= 0)
|
|
|
|
{
|
2016-08-21 10:12:12 -05:00
|
|
|
_docManager.onUnload(*this);
|
2016-08-17 18:51:34 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_WRN("Skipping unload on incomplete view.");
|
2016-08-17 18:51:34 -05:00
|
|
|
}
|
2016-01-10 09:33:58 -06:00
|
|
|
|
2016-04-13 07:56:23 -05:00
|
|
|
LOOLSession::disconnect();
|
2016-01-21 08:26:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::_handleInput(const char *buffer, int length)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-04-23 13:05:21 -05:00
|
|
|
const std::string firstLine = getFirstLine(buffer, length);
|
|
|
|
StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
|
|
|
|
2016-08-15 18:06:42 -05:00
|
|
|
if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0]))
|
|
|
|
{
|
|
|
|
// Keep track of timestamps of incoming client messages that indicate user activity.
|
|
|
|
updateLastActivityTime();
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
if (tokens.count() > 0 && tokens[0] == "useractive" && getLOKitDocument() != nullptr)
|
2016-01-24 14:24:11 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_DBG("Handling message after inactivity of " << getInactivityMS() << "ms.");
|
2016-08-15 18:06:42 -05:00
|
|
|
setIsActive(true);
|
2016-01-24 14:24:11 -06:00
|
|
|
|
|
|
|
// Client is getting active again.
|
|
|
|
// Send invalidation and other sync-up messages.
|
2016-08-17 18:51:34 -05:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(Mutex); //TODO: Move to top of function?
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lockLokDoc(_docManager.getDocumentMutex());
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2016-10-05 21:06:02 -05:00
|
|
|
// Get the list of view ids from the core
|
2016-11-15 04:37:47 -06:00
|
|
|
const int viewCount = getLOKitDocument()->getViewsCount();
|
2016-10-05 21:06:02 -05:00
|
|
|
std::vector<int> viewIds(viewCount);
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->getViewIds(viewIds.data(), viewCount);
|
2016-08-14 21:20:35 -05:00
|
|
|
|
2016-11-15 05:50:58 -06:00
|
|
|
int curPart = 0;
|
|
|
|
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT)
|
|
|
|
curPart = getLOKitDocument()->getPart();
|
2016-10-05 21:06:02 -05:00
|
|
|
|
|
|
|
lockLokDoc.unlock();
|
|
|
|
|
|
|
|
// Notify all views about updated view info
|
|
|
|
_docManager.notifyViewInfo(viewIds);
|
|
|
|
|
2016-12-01 05:25:16 -06:00
|
|
|
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT)
|
|
|
|
{
|
|
|
|
sendTextFrame("curpart: part=" + std::to_string(curPart));
|
|
|
|
sendTextFrame("setpart: part=" + std::to_string(curPart));
|
|
|
|
}
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2016-04-22 16:45:44 -05:00
|
|
|
//TODO: Is the order of these important?
|
2016-11-01 08:24:14 -05:00
|
|
|
for (const auto& pair : _lastDocEvents)
|
2016-04-21 23:28:52 -05:00
|
|
|
{
|
2016-11-01 08:24:14 -05:00
|
|
|
const auto typeName = LOKitHelper::kitCallbackTypeToString(pair.first);
|
|
|
|
LOG_TRC("Replaying missed event: " << typeName << ": " << pair.second);
|
2016-08-15 18:06:42 -05:00
|
|
|
loKitCallback(pair.first, pair.second);
|
2016-04-21 23:28:52 -05:00
|
|
|
}
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2016-11-01 08:24:14 -05:00
|
|
|
for (const auto& pair : _lastDocStates)
|
|
|
|
{
|
2016-11-01 08:37:50 -05:00
|
|
|
LOG_TRC("Replaying missed state-change: STATE_CHANGED: " << pair.second);
|
2016-11-01 08:24:14 -05:00
|
|
|
loKitCallback(LOK_CALLBACK_STATE_CHANGED, pair.second);
|
|
|
|
}
|
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Finished replaying messages.");
|
2016-04-09 22:16:09 -05:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:55:28 -05:00
|
|
|
if (tokens[0] == "dummymsg")
|
|
|
|
{
|
2016-05-21 10:47:13 -05:00
|
|
|
// Just to update the activity of a view-only client.
|
2016-03-23 11:55:28 -05:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else if (tokens[0] == "commandvalues")
|
|
|
|
{
|
|
|
|
return getCommandValues(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "partpagerectangles")
|
|
|
|
{
|
|
|
|
return getPartPageRectangles(buffer, length);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "load")
|
|
|
|
{
|
2016-02-04 11:35:26 -06:00
|
|
|
if (_isDocLoaded)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=docalreadyloaded");
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-08 11:59:57 -06:00
|
|
|
|
2016-02-04 11:35:26 -06:00
|
|
|
_isDocLoaded = loadDocument(buffer, length, tokens);
|
2016-05-11 20:16:10 -05:00
|
|
|
if (!_isDocLoaded)
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=faileddocloading");
|
|
|
|
}
|
|
|
|
|
2016-02-04 11:35:26 -06:00
|
|
|
return _isDocLoaded;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
2016-02-04 11:35:26 -06:00
|
|
|
else if (!_isDocLoaded)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-04-21 00:14:27 -05:00
|
|
|
// Be forgiving to these messages while we load.
|
|
|
|
if (tokens[0] == "useractive" ||
|
|
|
|
tokens[0] == "userinactive")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "renderfont")
|
|
|
|
{
|
|
|
|
sendFontRendering(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "setclientpart")
|
|
|
|
{
|
|
|
|
return setClientPart(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "setpage")
|
|
|
|
{
|
|
|
|
return setPage(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "status")
|
|
|
|
{
|
|
|
|
return getStatus(buffer, length);
|
|
|
|
}
|
2016-05-03 06:47:58 -05:00
|
|
|
else if (tokens[0] == "tile" || tokens[0] == "tilecombine")
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-07-13 02:22:35 -05:00
|
|
|
assert(false && "Tile traffic should go through the DocumentBroker-LoKit WS.");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// All other commands are such that they always require a LibreOfficeKitDocument session,
|
|
|
|
// i.e. need to be handled in a child process.
|
|
|
|
|
|
|
|
assert(tokens[0] == "clientzoom" ||
|
2016-02-02 04:48:41 -06:00
|
|
|
tokens[0] == "clientvisiblearea" ||
|
2015-12-12 13:23:44 -06:00
|
|
|
tokens[0] == "downloadas" ||
|
|
|
|
tokens[0] == "getchildid" ||
|
|
|
|
tokens[0] == "gettextselection" ||
|
|
|
|
tokens[0] == "paste" ||
|
|
|
|
tokens[0] == "insertfile" ||
|
|
|
|
tokens[0] == "key" ||
|
|
|
|
tokens[0] == "mouse" ||
|
|
|
|
tokens[0] == "uno" ||
|
|
|
|
tokens[0] == "selecttext" ||
|
|
|
|
tokens[0] == "selectgraphic" ||
|
|
|
|
tokens[0] == "resetselection" ||
|
2016-04-21 00:14:27 -05:00
|
|
|
tokens[0] == "saveas" ||
|
|
|
|
tokens[0] == "useractive" ||
|
2016-09-20 02:46:39 -05:00
|
|
|
tokens[0] == "userinactive");
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
if (tokens[0] == "clientzoom")
|
|
|
|
{
|
|
|
|
return clientZoom(buffer, length, tokens);
|
|
|
|
}
|
2016-02-02 04:48:41 -06:00
|
|
|
else if (tokens[0] == "clientvisiblearea")
|
|
|
|
{
|
|
|
|
return clientVisibleArea(buffer, length, tokens);
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else if (tokens[0] == "downloadas")
|
|
|
|
{
|
|
|
|
return downloadAs(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "getchildid")
|
|
|
|
{
|
|
|
|
return getChildId();
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "gettextselection")
|
|
|
|
{
|
|
|
|
return getTextSelection(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "paste")
|
|
|
|
{
|
|
|
|
return paste(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "insertfile")
|
|
|
|
{
|
|
|
|
return insertFile(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "key")
|
|
|
|
{
|
|
|
|
return keyEvent(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "mouse")
|
|
|
|
{
|
|
|
|
return mouseEvent(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "uno")
|
|
|
|
{
|
|
|
|
return unoCommand(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "selecttext")
|
|
|
|
{
|
|
|
|
return selectText(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "selectgraphic")
|
|
|
|
{
|
|
|
|
return selectGraphic(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "resetselection")
|
|
|
|
{
|
|
|
|
return resetSelection(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "saveas")
|
|
|
|
{
|
|
|
|
return saveAs(buffer, length, tokens);
|
|
|
|
}
|
2016-04-21 00:14:27 -05:00
|
|
|
else if (tokens[0] == "useractive")
|
|
|
|
{
|
|
|
|
setIsActive(true);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "userinactive")
|
|
|
|
{
|
|
|
|
setIsActive(false);
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else
|
|
|
|
{
|
2016-07-13 02:22:35 -05:00
|
|
|
assert(false && "Unknown command token.");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
}
|
2016-05-21 10:47:13 -05:00
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int part = -1;
|
|
|
|
if (tokens.count() < 2)
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string timestamp;
|
|
|
|
parseDocOptions(tokens, part, timestamp);
|
|
|
|
|
2016-04-27 19:51:54 -05:00
|
|
|
std::string renderOpts;
|
2016-04-27 19:42:45 -05:00
|
|
|
if (!_docOptions.empty())
|
|
|
|
{
|
|
|
|
Parser parser;
|
|
|
|
Poco::Dynamic::Var var = parser.parse(_docOptions);
|
|
|
|
Object::Ptr object = var.extract<Object::Ptr>();
|
2016-08-29 09:21:47 -05:00
|
|
|
Poco::Dynamic::Var rendering = object->get("rendering");
|
|
|
|
if (!rendering.isEmpty())
|
|
|
|
renderOpts = rendering.toString();
|
2016-04-27 19:42:45 -05:00
|
|
|
}
|
|
|
|
|
2016-01-06 23:33:54 -06:00
|
|
|
assert(!_docURL.empty());
|
|
|
|
assert(!_jailedFilePath.empty());
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-04-30 09:27:49 -05:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(Mutex);
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName, _docPassword, renderOpts, _haveDocPassword);
|
|
|
|
if (!loaded || _viewId < 0)
|
2016-04-27 19:42:45 -05:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Failed to get LoKitDocument instance.");
|
2016-02-04 11:35:26 -06:00
|
|
|
return false;
|
2016-04-27 19:42:45 -05:00
|
|
|
}
|
2016-02-04 11:35:26 -06:00
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("Created new view with viewid: [" << _viewId << + "] for username: [" <<
|
|
|
|
_userName << "] in session: [" << getId() << "].");
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lockLokDoc(_docManager.getDocumentMutex());
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
_docType = LOKitHelper::getDocumentTypeAsString(getLOKitDocument()->get());
|
2015-12-25 18:37:44 -06:00
|
|
|
if (_docType != "text" && part != -1)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setPart(part);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-08-15 02:10:45 -05:00
|
|
|
// Respond by the document status
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_DBG("Sending status after loading view " << _viewId << ".");
|
2016-11-15 04:37:47 -06:00
|
|
|
const auto status = LOKitHelper::documentStatus(getLOKitDocument()->get());
|
2016-08-12 08:42:31 -05:00
|
|
|
if (status.empty() || !sendTextFrame("status: " + status))
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Failed to get/forward document status [" << status << "].");
|
2015-12-12 13:23:44 -06:00
|
|
|
return false;
|
2016-08-12 08:42:31 -05:00
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-10-05 21:06:02 -05:00
|
|
|
// Get the list of view ids from the core
|
2016-11-15 04:37:47 -06:00
|
|
|
const int viewCount = getLOKitDocument()->getViewsCount();
|
2016-10-05 21:06:02 -05:00
|
|
|
std::vector<int> viewIds(viewCount);
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->getViewIds(viewIds.data(), viewCount);
|
2016-10-05 21:06:02 -05:00
|
|
|
|
|
|
|
lockLokDoc.unlock();
|
|
|
|
|
2016-09-20 05:29:53 -05:00
|
|
|
// Inform everyone (including this one) about updated view info
|
2016-10-05 21:06:02 -05:00
|
|
|
_docManager.notifyViewInfo(viewIds);
|
2016-08-29 06:33:49 -05:00
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("Loaded session " << getId());
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-21 10:47:13 -05:00
|
|
|
bool ChildSession::sendFontRendering(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-27 17:49:17 -06:00
|
|
|
std::string font, text, decodedFont, decodedChar;
|
2016-11-29 18:22:23 -06:00
|
|
|
bool bSuccess;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-11-11 11:24:13 -06:00
|
|
|
if (tokens.count() < 3 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenString(tokens[1], "font", font))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=renderfont kind=syntax");
|
2016-05-21 10:47:13 -05:00
|
|
|
return false;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-11-11 11:24:13 -06:00
|
|
|
getTokenString(tokens[2], "char", text);
|
|
|
|
|
2016-11-27 17:49:17 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
URI::decode(font, decodedFont);
|
|
|
|
URI::decode(text, decodedChar);
|
|
|
|
}
|
|
|
|
catch (Poco::SyntaxException& exc)
|
|
|
|
{
|
|
|
|
LOG_DBG(exc.message());
|
|
|
|
sendTextFrame("error: cmd=renderfont kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
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-04-04 05:29:02 -05:00
|
|
|
Timestamp timestamp;
|
2016-01-08 18:58:50 -06:00
|
|
|
int width, height;
|
2016-09-27 21:05:02 -05:00
|
|
|
unsigned char* ptrFont = nullptr;
|
|
|
|
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-27 17:49:17 -06:00
|
|
|
ptrFont = getLOKitDocument()->renderFont(decodedFont.c_str(), decodedChar.c_str(), &width, &height);
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("renderFont [" << font << "] rendered in " << (timestamp.elapsed()/1000.) << "ms");
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-11-29 18:22:23 -06:00
|
|
|
if (!ptrFont)
|
2015-12-23 20:20:49 -06:00
|
|
|
{
|
2016-11-29 18:22:23 -06:00
|
|
|
return sendTextFrame(output.data(), output.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (png::encodeBufferToPNG(ptrFont, width, height, output, LOK_TILEMODE_RGBA))
|
|
|
|
{
|
|
|
|
bSuccess = sendTextFrame(output.data(), output.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bSuccess = sendTextFrame("error: cmd=renderfont kind=failure");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-31 09:12:03 -05:00
|
|
|
std::free(ptrFont);
|
2016-11-29 18:22:23 -06:00
|
|
|
return bSuccess;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getStatus(const char* /*buffer*/, int /*length*/)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-09-27 21:05:02 -05:00
|
|
|
std::string status;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
status = LOKitHelper::documentStatus(getLOKitDocument()->get());
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-05-07 22:27:15 -05:00
|
|
|
if (status.empty())
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Failed to get document status.");
|
2016-01-10 21:52:00 -06:00
|
|
|
return false;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-05-21 10:47:13 -05:00
|
|
|
return sendTextFrame("status: " + status);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-09-30 07:21:14 -05:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Given a view ID <-> user name map and a .uno:DocumentRepair result, annotate with user names.
|
2016-10-26 10:08:25 -05:00
|
|
|
void insertUserNames(const std::map<int, UserInfo>& viewInfo, std::string& json)
|
2016-09-30 07:21:14 -05:00
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
auto root = parser.parse(json).extract<Poco::JSON::Object::Ptr>();
|
|
|
|
std::vector<std::string> directions { "Undo", "Redo" };
|
|
|
|
for (auto& directionName : directions)
|
|
|
|
{
|
|
|
|
auto direction = root->get(directionName).extract<Poco::JSON::Object::Ptr>();
|
|
|
|
if (direction->get("actions").type() == typeid(Poco::JSON::Array::Ptr))
|
|
|
|
{
|
|
|
|
auto actions = direction->get("actions").extract<Poco::JSON::Array::Ptr>();
|
|
|
|
for (auto& actionVar : *actions)
|
|
|
|
{
|
|
|
|
auto action = actionVar.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
int viewId = action->getValue<int>("viewId");
|
|
|
|
auto it = viewInfo.find(viewId);
|
|
|
|
if (it != viewInfo.end())
|
2016-10-26 10:08:25 -05:00
|
|
|
action->set("userName", Poco::Dynamic::Var(it->second.username));
|
2016-09-30 07:21:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::stringstream ss;
|
|
|
|
root->stringify(ss);
|
|
|
|
json = ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getCommandValues(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-08-28 07:46:38 -05:00
|
|
|
bool success;
|
|
|
|
char* pValues;
|
2015-12-12 13:23:44 -06:00
|
|
|
std::string command;
|
|
|
|
if (tokens.count() != 2 || !getTokenString(tokens[1], "command", command))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=commandvalues kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-08-28 07:46:38 -05:00
|
|
|
if (command == ".uno:DocumentRepair")
|
|
|
|
{
|
|
|
|
char* pUndo;
|
2016-09-30 07:21:14 -05:00
|
|
|
const std::string jsonTemplate("{\"commandName\":\".uno:DocumentRepair\",\"Redo\":%s,\"Undo\":%s}");
|
2016-11-15 04:37:47 -06:00
|
|
|
pValues = getLOKitDocument()->getCommandValues(".uno:Redo");
|
|
|
|
pUndo = getLOKitDocument()->getCommandValues(".uno:Undo");
|
2016-09-30 07:21:14 -05:00
|
|
|
std::string json = Poco::format(jsonTemplate,
|
|
|
|
std::string(pValues == nullptr ? "" : pValues),
|
|
|
|
std::string(pUndo == nullptr ? "" : pUndo));
|
|
|
|
// json only contains view IDs, insert matching user names.
|
2016-10-26 10:08:25 -05:00
|
|
|
std::map<int, UserInfo> viewInfo = _docManager.getViewInfo();
|
2016-09-30 07:21:14 -05:00
|
|
|
insertUserNames(viewInfo, json);
|
|
|
|
success = sendTextFrame("commandvalues: " + json);
|
2016-08-28 07:46:38 -05:00
|
|
|
std::free(pValues);
|
|
|
|
std::free(pUndo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
pValues = getLOKitDocument()->getCommandValues(command.c_str());
|
2016-09-23 05:08:50 -05:00
|
|
|
success = sendTextFrame("commandvalues: " + std::string(pValues == nullptr ? "" : pValues));
|
2016-08-28 07:46:38 -05:00
|
|
|
std::free(pValues);
|
|
|
|
}
|
|
|
|
|
2016-05-24 23:32:00 -05:00
|
|
|
return success;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getPartPageRectangles(const char* /*buffer*/, int /*length*/)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-09-27 21:05:02 -05:00
|
|
|
char* partPage = nullptr;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
|
|
|
partPage = getLOKitDocument()->getPartPageRectangles();
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-05-29 19:34:24 -05:00
|
|
|
sendTextFrame("partpagerectangles: " + std::string(partPage));
|
|
|
|
std::free(partPage);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::clientZoom(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-02-19 01:37:29 -06:00
|
|
|
int tilePixelWidth, tilePixelHeight, tileTwipWidth, tileTwipHeight;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
if (tokens.count() != 5 ||
|
|
|
|
!getTokenInteger(tokens[1], "tilepixelwidth", tilePixelWidth) ||
|
|
|
|
!getTokenInteger(tokens[2], "tilepixelheight", tilePixelHeight) ||
|
|
|
|
!getTokenInteger(tokens[3], "tiletwipwidth", tileTwipWidth) ||
|
|
|
|
!getTokenInteger(tokens[4], "tiletwipheight", tileTwipHeight))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=clientzoom kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setClientZoom(tilePixelWidth, tilePixelHeight, tileTwipWidth, tileTwipHeight);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-19 14:55:19 -06:00
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::clientVisibleArea(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2016-02-02 04:48:41 -06:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
|
|
|
if (tokens.count() != 5 ||
|
|
|
|
!getTokenInteger(tokens[1], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[2], "y", y) ||
|
|
|
|
!getTokenInteger(tokens[3], "width", width) ||
|
|
|
|
!getTokenInteger(tokens[4], "height", height))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=clientvisiblearea kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-02-02 04:48:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-02-02 04:48:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setClientVisibleArea(x, y, width, height);
|
2016-02-02 04:48:41 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::downloadAs(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string name, id, format, filterOptions;
|
|
|
|
|
|
|
|
if (tokens.count() < 5 ||
|
|
|
|
!getTokenString(tokens[1], "name", name) ||
|
|
|
|
!getTokenString(tokens[2], "id", id))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=downloadas kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTokenString(tokens[3], "format", format);
|
|
|
|
|
|
|
|
if (getTokenString(tokens[4], "options", filterOptions))
|
|
|
|
{
|
|
|
|
if (tokens.count() > 5)
|
|
|
|
{
|
|
|
|
filterOptions += Poco::cat(std::string(" "), tokens.begin() + 5, tokens.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 19:42:44 -05:00
|
|
|
// The file is removed upon downloading.
|
2016-11-12 15:38:13 -06:00
|
|
|
const auto tmpDir = FileUtil::createRandomDir(JAILED_DOCUMENT_ROOT);
|
2016-07-21 05:31:35 -05:00
|
|
|
// Prevent user inputting anything funny here.
|
|
|
|
// A "name" should always be a name, not a path
|
|
|
|
const Poco::Path filenameParam(name);
|
|
|
|
const auto url = JAILED_DOCUMENT_ROOT + tmpDir + "/" + filenameParam.getFileName();
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-09-27 21:05:02 -05:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->saveAs(url.c_str(),
|
2016-09-27 21:05:02 -05:00
|
|
|
format.size() == 0 ? nullptr :format.c_str(),
|
|
|
|
filterOptions.size() == 0 ? nullptr : filterOptions.c_str());
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-01-06 21:47:01 -06:00
|
|
|
sendTextFrame("downloadas: jail=" + _jailId + " dir=" + tmpDir + " name=" + name +
|
2016-01-07 08:40:41 -06:00
|
|
|
" port=" + std::to_string(ClientPortNumber) + " id=" + id);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getChildId()
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-01-06 21:47:01 -06:00
|
|
|
sendTextFrame("getchildid: id=" + _jailId);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getTextSelection(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string mimeType;
|
|
|
|
|
|
|
|
if (tokens.count() != 2 ||
|
|
|
|
!getTokenString(tokens[1], "mimetype", mimeType))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=gettextselection kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-27 21:05:02 -05:00
|
|
|
char* textSelection = nullptr;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
textSelection = getLOKitDocument()->getTextSelection(mimeType.c_str(), nullptr);
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
sendTextFrame("textselectioncontent: " + std::string(textSelection));
|
2016-03-12 11:17:34 -06:00
|
|
|
free(textSelection);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::paste(const char* buffer, int length, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string mimeType;
|
|
|
|
|
2016-01-15 07:42:02 -06:00
|
|
|
if (tokens.count() < 2 || !getTokenString(tokens[1], "mimetype", mimeType))
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=paste kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-15 07:42:02 -06:00
|
|
|
const std::string firstLine = getFirstLine(buffer, length);
|
|
|
|
const char* data = buffer + firstLine.size() + 1;
|
2016-09-27 21:05:02 -05:00
|
|
|
const size_t size = length - firstLine.size() - 1;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->paste(mimeType.c_str(), data, size);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::insertFile(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string name, type;
|
|
|
|
if (tokens.count() != 3 ||
|
|
|
|
!getTokenString(tokens[1], "name", name) ||
|
|
|
|
!getTokenString(tokens[2], "type", type))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=insertfile kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "graphic")
|
|
|
|
{
|
2016-03-28 06:01:19 -05:00
|
|
|
std::string fileName = "file://" + std::string(JAILED_DOCUMENT_ROOT) + "insertfile/" + name;
|
2015-12-12 13:23:44 -06:00
|
|
|
std::string command = ".uno:InsertGraphic";
|
|
|
|
std::string arguments = "{"
|
|
|
|
"\"FileName\":{"
|
|
|
|
"\"type\":\"string\","
|
|
|
|
"\"value\":\"" + fileName + "\""
|
|
|
|
"}}";
|
2016-09-19 02:03:31 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postUnoCommand(command.c_str(), arguments.c_str(), false);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::keyEvent(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int type, charcode, keycode;
|
|
|
|
if (tokens.count() != 4 ||
|
|
|
|
!getTokenKeyword(tokens[1], "type",
|
|
|
|
{{"input", LOK_KEYEVENT_KEYINPUT}, {"up", LOK_KEYEVENT_KEYUP}},
|
|
|
|
type) ||
|
|
|
|
!getTokenInteger(tokens[2], "char", charcode) ||
|
|
|
|
!getTokenInteger(tokens[3], "key", keycode))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=key kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-10 21:04:55 -06:00
|
|
|
// Don't close LO window!
|
|
|
|
constexpr auto KEY_CTRL = 0x2000;
|
2016-03-01 09:28:42 -06:00
|
|
|
constexpr auto KEY_W = 0x0216;
|
2016-01-10 21:04:55 -06:00
|
|
|
if (keycode == (KEY_CTRL | KEY_W))
|
2016-04-09 23:14:20 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ctrl+Tab switching browser tabs,
|
|
|
|
// Doesn't insert tabs.
|
|
|
|
constexpr auto KEY_TAB = 0x0502;
|
|
|
|
if (keycode == (KEY_CTRL | KEY_TAB))
|
|
|
|
{
|
2016-01-10 21:04:55 -06:00
|
|
|
return true;
|
2016-04-09 23:14:20 -05:00
|
|
|
}
|
2016-01-10 21:04:55 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postKeyEvent(type, charcode, keycode);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::mouseEvent(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-02-08 08:44:13 -06:00
|
|
|
int type, x, y, count;
|
|
|
|
bool success = true;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-02-08 08:44:13 -06:00
|
|
|
// default values for compatibility reasons with older loleaflets
|
2016-02-09 02:14:16 -06:00
|
|
|
int buttons = 1; // left button
|
2016-02-08 08:44:13 -06:00
|
|
|
int modifier = 0;
|
|
|
|
|
|
|
|
if (tokens.count() < 5 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenKeyword(tokens[1], "type",
|
|
|
|
{{"buttondown", LOK_MOUSEEVENT_MOUSEBUTTONDOWN},
|
|
|
|
{"buttonup", LOK_MOUSEEVENT_MOUSEBUTTONUP},
|
|
|
|
{"move", LOK_MOUSEEVENT_MOUSEMOVE}},
|
|
|
|
type) ||
|
|
|
|
!getTokenInteger(tokens[2], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[3], "y", y) ||
|
2016-02-08 08:44:13 -06:00
|
|
|
!getTokenInteger(tokens[4], "count", count))
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compatibility with older loleaflets
|
|
|
|
if (success && tokens.count() > 5 && !getTokenInteger(tokens[5], "buttons", buttons))
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
// compatibility with older loleaflets
|
|
|
|
if (success && tokens.count() > 6 && !getTokenInteger(tokens[6], "modifier", modifier))
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
if (!success)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=mouse kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postMouseEvent(type, x, y, count, buttons, modifier);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::unoCommand(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-07-26 07:03:46 -05:00
|
|
|
if (tokens.count() <= 1)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=uno kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need to get LOK_CALLBACK_UNO_COMMAND_RESULT callback when saving
|
2016-11-27 18:53:11 -06:00
|
|
|
const bool bNotify = (tokens[1] == ".uno:Save" || tokens[1] == ".uno:Undo" || tokens[1] == ".uno:Redo");
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-09-28 14:07:07 -05:00
|
|
|
if (tokens.count() == 2 && tokens[1] == ".uno:fakeDiskFull")
|
|
|
|
{
|
|
|
|
Util::alertAllUsers("internal", "diskfull");
|
|
|
|
}
|
|
|
|
else if (tokens.count() == 2)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postUnoCommand(tokens[1].c_str(), nullptr, bNotify);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postUnoCommand(tokens[1].c_str(),
|
2016-08-24 17:22:32 -05:00
|
|
|
Poco::cat(std::string(" "), tokens.begin() + 2, tokens.end()).c_str(),
|
|
|
|
bNotify);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::selectText(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int type, x, y;
|
|
|
|
if (tokens.count() != 4 ||
|
|
|
|
!getTokenKeyword(tokens[1], "type",
|
|
|
|
{{"start", LOK_SETTEXTSELECTION_START},
|
|
|
|
{"end", LOK_SETTEXTSELECTION_END},
|
|
|
|
{"reset", LOK_SETTEXTSELECTION_RESET}},
|
|
|
|
type) ||
|
|
|
|
!getTokenInteger(tokens[2], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[3], "y", y))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=selecttext kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setTextSelection(type, x, y);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::selectGraphic(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int type, x, y;
|
|
|
|
if (tokens.count() != 4 ||
|
|
|
|
!getTokenKeyword(tokens[1], "type",
|
|
|
|
{{"start", LOK_SETGRAPHICSELECTION_START},
|
|
|
|
{"end", LOK_SETGRAPHICSELECTION_END}},
|
|
|
|
type) ||
|
|
|
|
!getTokenInteger(tokens[2], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[3], "y", y))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=selectgraphic kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setGraphicSelection(type, x, y);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::resetSelection(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
if (tokens.count() != 1)
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=resetselection kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->resetSelection();
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::saveAs(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string url, format, filterOptions;
|
|
|
|
|
|
|
|
if (tokens.count() < 4 ||
|
|
|
|
!getTokenString(tokens[1], "url", url))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=saveas kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTokenString(tokens[2], "format", format);
|
|
|
|
|
|
|
|
if (getTokenString(tokens[3], "options", filterOptions))
|
|
|
|
{
|
|
|
|
if (tokens.count() > 4)
|
|
|
|
{
|
|
|
|
filterOptions += Poco::cat(std::string(" "), tokens.begin() + 4, tokens.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 21:05:02 -05:00
|
|
|
bool success = false;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
success = getLOKitDocument()->saveAs(url.c_str(),
|
2016-09-27 21:05:02 -05:00
|
|
|
format.size() == 0 ? nullptr :format.c_str(),
|
|
|
|
filterOptions.size() == 0 ? nullptr : filterOptions.c_str());
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
sendTextFrame("saveas: url=" + url);
|
|
|
|
std::string successStr = success ? "true" : "false";
|
|
|
|
sendTextFrame("unocommandresult: {"
|
|
|
|
"\"commandName\":\"saveas\","
|
|
|
|
"\"success\":\"" + successStr + "\"}");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::setClientPart(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-04-27 12:47:58 -05:00
|
|
|
int part;
|
2015-12-12 13:23:44 -06:00
|
|
|
if (tokens.count() < 2 ||
|
2016-04-27 12:47:58 -05:00
|
|
|
!getTokenInteger(tokens[1], "part", part))
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-04-27 12:47:58 -05:00
|
|
|
sendTextFrame("error: cmd=setclientpart kind=invalid");
|
2015-12-12 13:23:44 -06:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-27 12:47:58 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-04-27 12:47:58 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-10-01 13:07:39 -05:00
|
|
|
|
2016-11-15 05:50:58 -06:00
|
|
|
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT && part != getLOKitDocument()->getPart())
|
2016-04-29 20:52:00 -05:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setPart(part);
|
2016-04-29 20:52:00 -05:00
|
|
|
}
|
2016-04-27 12:47:58 -05:00
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::setPage(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int page;
|
|
|
|
if (tokens.count() < 2 ||
|
|
|
|
!getTokenInteger(tokens[1], "page", page))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=setpage kind=invalid");
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setPart(page);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-13 17:25:06 -05:00
|
|
|
void ChildSession::loKitCallback(const int nType, const std::string& rPayload)
|
2016-01-24 17:25:02 -06:00
|
|
|
{
|
2016-08-13 17:25:06 -05:00
|
|
|
const auto typeName = LOKitHelper::kitCallbackTypeToString(nType);
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("CallbackWorker::callback [" << getName() << "]: " <<
|
|
|
|
typeName << " [" << rPayload << "].");
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-08-13 17:25:06 -05:00
|
|
|
if (isCloseFrame())
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Skipping callback [" << typeName << "] on closing session " << getName());
|
2016-08-13 17:25:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (isDisconnected())
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Skipping callback [" << typeName << "] on disconnected session " << getName());
|
2016-08-13 17:25:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!isActive())
|
|
|
|
{
|
2016-11-01 08:24:14 -05:00
|
|
|
// Cache important notifications to replay them when our client
|
|
|
|
// goes inactive and loses them.
|
|
|
|
if (nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR ||
|
|
|
|
nType == LOK_CALLBACK_CURSOR_VISIBLE ||
|
|
|
|
nType == LOK_CALLBACK_CELL_CURSOR ||
|
|
|
|
nType == LOK_CALLBACK_CELL_FORMULA ||
|
|
|
|
nType == LOK_CALLBACK_GRAPHIC_SELECTION ||
|
|
|
|
nType == LOK_CALLBACK_TEXT_SELECTION ||
|
|
|
|
nType == LOK_CALLBACK_TEXT_SELECTION_START ||
|
|
|
|
nType == LOK_CALLBACK_TEXT_SELECTION_END ||
|
|
|
|
nType == LOK_CALLBACK_DOCUMENT_SIZE_CHANGED ||
|
|
|
|
nType == LOK_CALLBACK_INVALIDATE_VIEW_CURSOR ||
|
|
|
|
nType == LOK_CALLBACK_TEXT_VIEW_SELECTION ||
|
|
|
|
nType == LOK_CALLBACK_CELL_VIEW_CURSOR ||
|
|
|
|
nType == LOK_CALLBACK_GRAPHIC_VIEW_SELECTION ||
|
|
|
|
nType == LOK_CALLBACK_VIEW_CURSOR_VISIBLE ||
|
|
|
|
nType == LOK_CALLBACK_VIEW_LOCK)
|
|
|
|
{
|
|
|
|
auto lock(getLock());
|
|
|
|
|
|
|
|
_lastDocEvents[nType] = rPayload;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nType == LOK_CALLBACK_STATE_CHANGED)
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string value;
|
|
|
|
if (LOOLProtocol::parseNameValuePair(rPayload, name, value, '='))
|
|
|
|
{
|
|
|
|
auto lock(getLock());
|
|
|
|
|
|
|
|
_lastDocStates[name] = rPayload;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 17:25:06 -05:00
|
|
|
// Pass save notifications through.
|
|
|
|
if (nType != LOK_CALLBACK_UNO_COMMAND_RESULT || rPayload.find(".uno:Save") == std::string::npos)
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Skipping callback [" << typeName << "] on inactive session " << getName());
|
2016-08-13 17:25:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nType)
|
|
|
|
{
|
|
|
|
case LOK_CALLBACK_INVALIDATE_TILES:
|
|
|
|
{
|
2016-10-02 15:44:11 -05:00
|
|
|
StringTokenizer tokens(rPayload, ",", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
|
|
|
if (tokens.count() == 5)
|
2016-08-13 17:25:06 -05:00
|
|
|
{
|
2016-10-02 15:44:11 -05:00
|
|
|
int part, x, y, width, height;
|
2016-08-13 17:25:06 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
x = std::stoi(tokens[0]);
|
|
|
|
y = std::stoi(tokens[1]);
|
|
|
|
width = std::stoi(tokens[2]);
|
|
|
|
height = std::stoi(tokens[3]);
|
2016-10-07 17:19:56 -05:00
|
|
|
part = (_docType != "text" ? std::stoi(tokens[4]) : 0); // Writer renders everything as part 0.
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
|
|
|
catch (const std::out_of_range&)
|
|
|
|
{
|
2016-10-21 21:00:10 -05:00
|
|
|
// We might get INT_MAX +/- some delta that
|
|
|
|
// can overflow signed int and we end up here.
|
2016-08-13 17:25:06 -05:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
width = INT_MAX;
|
|
|
|
height = INT_MAX;
|
2016-10-02 15:44:11 -05:00
|
|
|
part = 0;
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sendTextFrame("invalidatetiles:"
|
2016-10-02 15:44:11 -05:00
|
|
|
" part=" + std::to_string(part) +
|
2016-09-27 21:05:02 -05:00
|
|
|
" x=" + std::to_string(x) +
|
|
|
|
" y=" + std::to_string(y) +
|
|
|
|
" width=" + std::to_string(width) +
|
|
|
|
" height=" + std::to_string(height));
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
2016-11-29 21:59:47 -06:00
|
|
|
else if (tokens.count() == 2 && tokens[0] == "EMPTY")
|
|
|
|
{
|
|
|
|
const std::string part = (_docType != "text" ? tokens[1].c_str() : "0"); // Writer renders everything as part 0.
|
|
|
|
sendTextFrame("invalidatetiles: EMPTY, " + part);
|
|
|
|
}
|
2016-08-13 17:25:06 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sendTextFrame("invalidatetiles: " + rPayload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
|
|
|
|
sendTextFrame("invalidatecursor: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION:
|
|
|
|
sendTextFrame("textselection: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_START:
|
|
|
|
sendTextFrame("textselectionstart: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_END:
|
|
|
|
sendTextFrame("textselectionend: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CURSOR_VISIBLE:
|
|
|
|
sendTextFrame("cursorvisible: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_GRAPHIC_SELECTION:
|
|
|
|
sendTextFrame("graphicselection: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CELL_CURSOR:
|
|
|
|
sendTextFrame("cellcursor: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CELL_FORMULA:
|
|
|
|
sendTextFrame("cellformula: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_MOUSE_POINTER:
|
|
|
|
sendTextFrame("mousepointer: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_HYPERLINK_CLICKED:
|
|
|
|
sendTextFrame("hyperlinkclicked: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATE_CHANGED:
|
|
|
|
sendTextFrame("statechanged: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_SEARCH_NOT_FOUND:
|
|
|
|
sendTextFrame("searchnotfound: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
|
|
|
|
sendTextFrame("searchresultselection: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
|
|
|
|
getStatus("", 0);
|
|
|
|
getPartPageRectangles("", 0);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_SET_PART:
|
|
|
|
sendTextFrame("setpart: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_UNO_COMMAND_RESULT:
|
|
|
|
sendTextFrame("unocommandresult: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_ERROR:
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("CALLBACK_ERROR: " << rPayload);
|
2016-08-13 17:25:06 -05:00
|
|
|
Parser parser;
|
|
|
|
Poco::Dynamic::Var var = parser.parse(rPayload);
|
|
|
|
Object::Ptr object = var.extract<Object::Ptr>();
|
|
|
|
|
|
|
|
sendTextFrame("error: cmd=" + object->get("cmd").toString() +
|
|
|
|
" kind=" + object->get("kind").toString() + " code=" + object->get("code").toString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CONTEXT_MENU:
|
|
|
|
sendTextFrame("contextmenu: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_START:
|
|
|
|
sendTextFrame("statusindicatorstart:");
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
|
|
|
|
sendTextFrame("statusindicatorsetvalue: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
|
|
|
|
sendTextFrame("statusindicatorfinish:");
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
|
|
|
|
sendTextFrame("invalidateviewcursor: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
|
|
|
|
sendTextFrame("textviewselection: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CELL_VIEW_CURSOR:
|
|
|
|
sendTextFrame("cellviewcursor: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION:
|
|
|
|
sendTextFrame("graphicviewselection: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
|
|
|
|
sendTextFrame("viewcursorvisible: " + rPayload);
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_VIEW_LOCK:
|
|
|
|
sendTextFrame("viewlock: " + rPayload);
|
|
|
|
break;
|
2016-08-21 10:15:50 -05:00
|
|
|
case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
|
|
|
|
sendTextFrame("redlinetablechanged: " + rPayload);
|
|
|
|
break;
|
2016-09-19 04:15:15 -05:00
|
|
|
case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED:
|
|
|
|
sendTextFrame("redlinetablemodified: " + rPayload);
|
|
|
|
break;
|
2016-08-13 17:25:06 -05:00
|
|
|
default:
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Unknown callback event (" << nType << "): " << rPayload);
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
2016-01-24 17:25:02 -06:00
|
|
|
}
|
|
|
|
|
2015-12-13 11:47:14 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|