Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions wsd/ClientRequestDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,19 @@ bool ClientRequestDispatcher::handleClipboardRequest(const Poco::Net::HTTPReques
docBroker = it->second;
}

DocumentBroker::ClipboardRequest type;
if (request.getMethod() != Poco::Net::HTTPRequest::HTTP_GET)
type = DocumentBroker::CLIP_REQUEST_SET;
else
{
if (mime == "text/html")
type = DocumentBroker::CLIP_REQUEST_GET_RICH_HTML_ONLY;
else if (mime == "text/html,text/plain;charset=utf-8")
type = DocumentBroker::CLIP_REQUEST_GET_HTML_PLAIN_ONLY;
else
type = DocumentBroker::CLIP_REQUEST_GET;
}

// If we have a valid docBroker, use it.
// Note: there is a race here as DocBroker may
// have already exited its SocketPoll, but we
Expand All @@ -1713,17 +1726,7 @@ bool ClientRequestDispatcher::handleClipboardRequest(const Poco::Net::HTTPReques
if (docBroker && docBroker->isAlive())
{
std::string jailClipFile, clipFile;
DocumentBroker::ClipboardRequest type;
if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
{
if (mime == "text/html")
type = DocumentBroker::CLIP_REQUEST_GET_RICH_HTML_ONLY;
else if (mime == "text/html,text/plain;charset=utf-8")
type = DocumentBroker::CLIP_REQUEST_GET_HTML_PLAIN_ONLY;
else
type = DocumentBroker::CLIP_REQUEST_GET;
}
else
if (type == DocumentBroker::CLIP_REQUEST_SET)
{
if (!docBroker->getSessionFromClipboardTag(viewId, tag))
{
Expand All @@ -1733,8 +1736,6 @@ bool ClientRequestDispatcher::handleClipboardRequest(const Poco::Net::HTTPReques
return true;
}

type = DocumentBroker::CLIP_REQUEST_SET;

std::string clipName = "setclipboard." + tag;

std::string jailId = docBroker->getJailId();
Expand Down Expand Up @@ -1774,7 +1775,7 @@ bool ClientRequestDispatcher::handleClipboardRequest(const Poco::Net::HTTPReques
LOG_TRC_S("queued clipboard command " << type << " on docBroker fetch");
}
// fallback to persistent clipboards if we can
else if (!DocumentBroker::lookupSendClipboardTag(socket, tag, false))
else if (!DocumentBroker::handlePersistentClipboardRequest(type, socket, tag, false))
{
LOG_ERR_S("Invalid clipboard request to server ["
<< serverId << "] with tag [" << tag << "] and broker [" << docKey
Expand Down
2 changes: 1 addition & 1 deletion wsd/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void ClientSession::handleClipboardRequest(DocumentBroker::ClipboardRequest
if (_state == SessionState::WAIT_DISCONNECT)
{
LOG_TRC("Clipboard request " << tag << " for disconnecting session");
if (docBroker->lookupSendClipboardTag(socket, tag, false))
if (DocumentBroker::handlePersistentClipboardRequest(type, socket, tag, false))
return; // the getclipboard already completed.
if (type == DocumentBroker::CLIP_REQUEST_SET)
{
Expand Down
14 changes: 9 additions & 5 deletions wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4584,13 +4584,15 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined, bool
}

/// lookup in global clipboard cache and send response, send error if missing if @sendError
bool DocumentBroker::lookupSendClipboardTag(const std::shared_ptr<StreamSocket> &socket,
const std::string &tag, bool sendError)
bool DocumentBroker::handlePersistentClipboardRequest(ClipboardRequest type,
const std::shared_ptr<StreamSocket> &socket,
const std::string &tag, bool sendError)
{
LOG_TRC("Clipboard request " << tag << " not for a live session - check cache.");
#if !MOBILEAPP
std::shared_ptr<FileUtil::OwnedFile> clipFile =
COOLWSD::SavedClipboards->getClipboard(tag);
std::shared_ptr<FileUtil::OwnedFile> clipFile;
if (type != ClipboardRequest::CLIP_REQUEST_SET)
clipFile = COOLWSD::SavedClipboards->getClipboard(tag);
if (clipFile)
{
auto session = std::make_shared<http::ServerSession>();
Expand All @@ -4614,6 +4616,8 @@ bool DocumentBroker::lookupSendClipboardTag(const std::shared_ptr<StreamSocket>
LOG_INF("Found and queued clipboard response for send of size " << FileUtil::Stat(clipFile->_file).size());
return true;
}
#else
(void)type;
#endif

if (!sendError)
Expand Down Expand Up @@ -4656,7 +4660,7 @@ void DocumentBroker::handleClipboardRequest(ClipboardRequest type, const std::sh
return;
}

if (!lookupSendClipboardTag(socket, tag, true))
if (!handlePersistentClipboardRequest(type, socket, tag, true))
LOG_ERR("Could not find matching session to handle clipboard request for " << viewId << " tag: " << tag);
}

Expand Down
5 changes: 3 additions & 2 deletions wsd/DocumentBroker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ class DocumentBroker : public std::enable_shared_from_this<DocumentBroker>
void handleClipboardRequest(ClipboardRequest type, const std::shared_ptr<StreamSocket> &socket,
const std::string &viewId, const std::string &tag,
const std::string &clipFile);
static bool lookupSendClipboardTag(const std::shared_ptr<StreamSocket> &socket,
const std::string &tag, bool sendError = false);
static bool handlePersistentClipboardRequest(ClipboardRequest type,
const std::shared_ptr<StreamSocket> &socket,
const std::string &tag, bool sendError = false);

void handleMediaRequest(std::string_view range, const std::shared_ptr<Socket>& socket,
const std::string& tag);
Expand Down