loolwsd/DocumentBroker.hpp | 9 ------- loolwsd/LOOLWSD.cpp | 57 ++++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 27 deletions(-)
New commits: commit 981e83ece6cc93d5d6c20fef45773b5dfb6b647d Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Mar 13 14:00:19 2016 -0400 loolwsd: fixed convert-to (POST) tests Change-Id: I6d48971b9daf0beaa16defa0b5f4dfb94575713c Reviewed-on: https://gerrit.libreoffice.org/23228 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index fd9efa3..ad068d1 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -31,14 +31,7 @@ public: { Log::info("Creating DocumentBroker for uri: " + uri + "."); - // The URI of the document is url-encoded - // and passed in our URL. - if (uri.size() > 0 && uri[0] == '/') - { - // Remove leading '/'. - uri.erase(0, 1); - } - + // The URI of the document should be url-encoded. std::string decodedUri; Poco::URI::decode(uri, decodedUri); auto uriPublic = Poco::URI(decodedUri); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 1dc41a2..5435669 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -329,55 +329,67 @@ private: void handlePostRequest(HTTPServerRequest& request, HTTPServerResponse& response, const std::string& id) { - Log::info("Post request."); + Log::info("Post request: " + request.getURI() + "]"); StringTokenizer tokens(request.getURI(), "/?"); if (tokens.count() >= 2 && tokens[1] == "convert-to") { - Log::info("Conversion request."); std::string fromPath; ConvertToPartHandler handler(fromPath); HTMLForm form(request, request.stream(), handler); - std::string format; - if (form.has("format")) - format = form.get("format"); + const std::string format = (form.has("format") ? form.get("format") : ""); bool sent = false; if (!fromPath.empty()) { if (!format.empty()) { + Log::info("Conversion request for URI [" + fromPath + "]."); + auto docBroker = DocumentBroker::create(fromPath, LOOLWSD::ChildRoot); + const auto docKey = docBroker->getDocKey(); + + // This lock could become a bottleneck. + // In that case, we can use a pool and index by publicPath. + std::unique_lock<std::mutex> lock(LOOLWSD::DocBrokersMutex); + + Log::debug("New DocumentBroker for docKey [" + docKey + "]."); + LOOLWSD::DocBrokers.emplace(docKey, docBroker); + // Load the document. std::shared_ptr<WebSocket> ws; const LOOLSession::Kind kind = LOOLSession::Kind::ToClient; - auto session = std::make_shared<MasterProcessSession>(id, kind, ws, nullptr); - const std::string filePrefix("file://"); + auto session = std::make_shared<MasterProcessSession>(id, kind, ws, docBroker); + docBroker->incSessions(); + lock.unlock(); + std::string encodedFrom; - URI::encode(filePrefix + fromPath, "", encodedFrom); + URI::encode(docBroker->getPublicUri().getPath(), "", encodedFrom); const std::string load = "load url=" + encodedFrom; session->handleInput(load.data(), load.size()); // Convert it to the requested format. - Path toPath(fromPath); + Path toPath(docBroker->getPublicUri().getPath()); toPath.setExtension(format); - std::string toJailURL = filePrefix + JailedDocumentRoot + toPath.getFileName(); + const std::string toJailURL = "file://" + JailedDocumentRoot + toPath.getFileName(); std::string encodedTo; URI::encode(toJailURL, "", encodedTo); std::string saveas = "saveas url=" + encodedTo + " format=" + format + " options="; session->handleInput(saveas.data(), saveas.size()); - std::string toURL = session->getSaveAs(); - std::string resultingURL; - URI::decode(toURL, resultingURL); - // Send it back to the client. - if (resultingURL.find(filePrefix) == 0) - resultingURL = resultingURL.substr(filePrefix.length()); - if (!resultingURL.empty()) + Poco::URI resultURL(session->getSaveAs()); + if (!resultURL.getPath().empty()) { const std::string mimeType = "application/octet-stream"; - response.sendFile(resultingURL, mimeType); + response.sendFile(resultURL.getPath(), mimeType); sent = true; } + + lock.lock(); + if (docBroker->decSessions() == 0) + { + Log::debug("Removing DocumentBroker for docKey [" + docKey + "]."); + LOOLWSD::DocBrokers.erase(docKey); + } } // Clean up the temporary directory the HTMLForm ctor created. @@ -505,7 +517,14 @@ private: // request.getCookies(cookies); // Log::info("Cookie: " + cookies.get("PHPSESSID", "")); - auto docBroker = DocumentBroker::create(request.getURI(), LOOLWSD::ChildRoot); + // Remove the leading '/' in the GET URL. + std::string uri = request.getURI(); + if (uri.size() > 0 && uri[0] == '/') + { + uri.erase(0, 1); + } + + auto docBroker = DocumentBroker::create(uri, LOOLWSD::ChildRoot); const auto docKey = docBroker->getDocKey(); // This lock could become a bottleneck. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits