[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Fri Mar 17 04:05:38 UTC 2017
wsd/ClientSession.cpp | 4 ++--
wsd/ClientSession.hpp | 30 +++++++++++++++---------------
wsd/DocumentBroker.cpp | 1 +
wsd/LOOLWSD.cpp | 46 ++--------------------------------------------
4 files changed, 20 insertions(+), 61 deletions(-)
New commits:
commit 5aedff24229bee65a5c0fd7154dce3f65e95567c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Mar 16 22:42:02 2017 -0400
wsd: convert-to functional again
Change-Id: Ibfdec5e898ccb7f851a09fb3fb5eae85ca20f482
Reviewed-on: https://gerrit.libreoffice.org/35307
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 1f179ed4..268dc05c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -414,7 +414,7 @@ bool ClientSession::filterMessage(const std::string& message) const
{
// By default, don't allow anything
allowed = false;
- if (tokens[0] == "userinactive" || tokens[0] == "useractive")
+ if (tokens[0] == "userinactive" || tokens[0] == "useractive" || tokens[0] == "saveas")
{
allowed = true;
}
@@ -503,7 +503,7 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
const auto& object = parsedJSON.extract<Poco::JSON::Object::Ptr>();
if (object->get("commandName").toString() == ".uno:Save")
{
- bool success = object->get("success").toString() == "true";
+ const bool success = object->get("success").toString() == "true";
std::string result;
if (object->has("result"))
{
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index c18e5cee..794ca06d 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -89,24 +89,24 @@ public:
_senderQueue.stop();
}
- /**
- * Return the URL of the saved-as document when it's ready. If called
- * before it's ready, the call blocks till then.
- */
- std::string getSaveAsUrl(const unsigned timeoutMs)
+ void setSaveAsSocket(const std::shared_ptr<StreamSocket>& socket)
{
- const auto payload = _saveAsQueue.get(timeoutMs);
- if (payload.empty())
- {
- throw std::runtime_error("Timed-out while getting save-as URL.");
- }
-
- return std::string(payload.data(), payload.size());
+ _saveAsSocket = socket;
}
void setSaveAsUrl(const std::string& url)
{
- _saveAsQueue.put(url);
+ Poco::URI resultURL(url);
+ LOG_TRC("Save-as URL: " << resultURL.toString());
+
+ if (!resultURL.getPath().empty())
+ {
+ const std::string mimeType = "application/octet-stream";
+ std::string encodedFilePath;
+ Poco::URI::encode(resultURL.getPath(), "", encodedFilePath);
+ LOG_TRC("Sending file: " << encodedFilePath);
+ HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType);
+ }
}
std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker.lock(); }
@@ -164,8 +164,8 @@ private:
/// Whether this session is the owner of currently opened document
bool _isDocumentOwner;
- /// Store URLs of completed 'save as' documents.
- MessageQueue _saveAsQueue;
+ /// The socket to which the converted (saveas) doc is sent.
+ std::shared_ptr<StreamSocket> _saveAsSocket;
bool _isLoaded;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a4153ffb..e6ddb30c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -478,6 +478,7 @@ bool DocumentBroker::load(std::shared_ptr<ClientSession>& session, const std::st
bool DocumentBroker::saveToStorage(const std::string& sessionId,
bool success, const std::string& result)
{
+ LOG_TRC("Saving to storage docKey [" << _docKey << "] for session [" << sessionId << "]: " << result);
const bool res = saveToStorageInternal(sessionId, success, result);
// If marked to destroy, then this was the last session.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index fac23b22..a4e34062 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1598,47 +1598,6 @@ private:
void performWrites() override
{
LOG_ERR("performWrites");
- auto socket = _socket.lock();
-
- // Send it back to the client.
- try
- {
- Poco::URI resultURL(_clientSession->getSaveAsUrl(COMMAND_TIMEOUT_MS));
- LOG_TRC("Save-as URL: " << resultURL.toString());
-
- if (!resultURL.getPath().empty())
- {
- const std::string mimeType = "application/octet-stream";
- std::string encodedFilePath;
- URI::encode(resultURL.getPath(), "", encodedFilePath);
- LOG_TRC("Sending file: " << encodedFilePath);
- HttpHelper::sendFile(socket, encodedFilePath, mimeType);
- }
- }
- catch (const std::exception& ex)
- {
- LOG_ERR("Failed to get save-as url: " << ex.what());
- }
-
- // auto docLock = docBroker->getLock();
- // sessionsCount = docBroker->removeSession(_id);
- // if (sessionsCount == 0)
- // {
- // // At this point we're done.
- // LOG_DBG("Removing DocumentBroker for docKey [" << docKey << "].");
- // DocBrokers.erase(docKey);
- // docBroker->terminateChild(docLock, "");
- // LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after removing [" << docKey << "].");
- // }
- // else
- // {
- // LOG_ERR("Multiple sessions during conversion. " << sessionsCount << " sessions remain.");
- // }
-
- // Clean up the temporary directory the HTMLForm ctor created.
- // Path tempDirectory(fromPath);
- // tempDirectory.setFileName("");
- // FileUtil::removeFile(tempDirectory, /*recursive=*/true);
}
private:
@@ -1980,12 +1939,11 @@ private:
WebServerPoll.releaseSocket(socket);
docBroker->addSocketToPoll(socket);
- auto convertToHandler = std::make_shared<ConvertToHandler>(clientSession);
+ clientSession->setSaveAsSocket(socket);
- // Set the ConvertToHandler to handle Socket events.
- socket->setHandler(convertToHandler);
docBroker->startThread();
+ // Load the document manually and request saving in the target format.
std::string encodedFrom;
URI::encode(docBroker->getPublicUri().getPath(), "", encodedFrom);
const std::string load = "load url=" + encodedFrom;
More information about the Libreoffice-commits
mailing list