[Libreoffice-commits] online.git: 2 commits - loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp
Miklos Vajna
vmiklos at collabora.co.uk
Tue Oct 20 06:02:40 PDT 2015
loolwsd/LOOLSession.cpp | 10 ++++++++++
loolwsd/LOOLWSD.cpp | 37 ++++++++++++++++++++++++-------------
2 files changed, 34 insertions(+), 13 deletions(-)
New commits:
commit cdc0783c27a4b2b36c1f5ffc972f618be33f1ed7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Oct 20 15:00:05 2015 +0200
LOOLWSD: put file we get from convert-to to a temp. dir
Having a URL like file:///tmp/tmp13630baaaaa/test.txt allows retaining
the filename given by the user and still work with a URL.
We could try carrying around a memory buffer, but we would still have to
send it over the WS, so it's easier if we always work with URLs instead.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index b37c1b3..21256be 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -98,6 +98,8 @@ DEALINGS IN THE SOFTWARE.
#include <Poco/ThreadLocal.h>
#include <Poco/NamedMutex.h>
#include <Poco/FileStream.h>
+#include <Poco/TemporaryFile.h>
+#include <Poco/StreamCopier.h>
#include "LOOLProtocol.hpp"
@@ -183,16 +185,15 @@ private:
class ConvertToPartHandler : public Poco::Net::PartHandler
{
std::string& _filename;
- std::vector<char>& _buffer;
public:
- ConvertToPartHandler(std::string& filename, std::vector<char>& buffer)
- : _filename(filename),
- _buffer(buffer)
+ ConvertToPartHandler(std::string& filename)
+ : _filename(filename)
{
}
virtual void handlePart(const Poco::Net::MessageHeader& header, std::istream& stream) override
{
+ // Extract filename and put it to a temporary directory.
std::string disp;
Poco::Net::NameValueCollection params;
if (header.has("Content-Disposition"))
@@ -200,12 +201,19 @@ public:
std::string cd = header.get("Content-Disposition");
Poco::Net::MessageHeader::splitParameters(cd, disp, params);
}
- if (params.has("filename"))
- _filename = params.get("filename");
+ if (!params.has("filename"))
+ return;
+
+ Path tempPath = Path::forDirectory(Poco::TemporaryFile().tempName() + Path::separator());
+ File(tempPath).createDirectories();
+ tempPath.setFileName(params.get("filename"));
+ _filename = tempPath.toString();
- char c;
- while (stream.get(c))
- _buffer.push_back(c);
+ // Copy the stream to _filename.
+ std::ofstream fileStream;
+ fileStream.open(_filename);
+ Poco::StreamCopier::copyStream(stream, fileStream);
+ fileStream.close();
}
};
@@ -235,17 +243,20 @@ public:
StringTokenizer tokens(request.getURI(), "/?");
if (tokens.count() >= 2 && tokens[1] == "convert-to")
{
- std::string filename;
- std::vector<char> buffer;
- ConvertToPartHandler handler(filename, buffer);
+ std::string fromPath;
+ ConvertToPartHandler handler(fromPath);
Poco::Net::HTMLForm form(request, request.stream(), handler);
std::string format;
if (form.has("format"))
format = form.get("format");
- if (!format.empty() && !buffer.empty())
+ if (!fromPath.empty() && !format.empty())
{
// TODO implement actual conversion
+
+ Path tempDirectory(fromPath);
+ tempDirectory.setFileName("");
+ File(tempDirectory).remove(/*recursive=*/true);
}
response.setStatus(HTTPResponse::HTTP_OK);
commit 847c65cb1c4f80e6a0fbec56715ad857d6b78472
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Oct 20 14:44:47 2015 +0200
LOOLSession: handle file:// in the ToPrisoner saveas input handler
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 4bee505..15a2825 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -192,9 +192,19 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
return true;
if (peer)
+ {
// Save as completed, inform the other (Kind::ToClient)
// MasterProcessSession about it.
+
+ const std::string filePrefix("file:///");
+ if (url.find(filePrefix) == 0)
+ {
+ // Rewrite file:// URLs, as they are visible to the outside world.
+ Path path(MasterProcessSession::getJailPath(_childId), url.substr(filePrefix.length()));
+ url = filePrefix + path.toString().substr(1);
+ }
peer->_saveAsQueue.put(url);
+ }
return true;
}
More information about the Libreoffice-commits
mailing list