[Libreoffice-commits] online.git: kit/ChildSession.cpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Nov 29 11:02:49 UTC 2018
kit/ChildSession.cpp | 46 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 38 insertions(+), 8 deletions(-)
New commits:
commit 9d8cc0b7663a79f2c8bf4ab5bbd92c1a7270c0d7
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Thu Nov 29 13:00:24 2018 +0200
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Thu Nov 29 13:00:35 2018 +0200
Initial attempt at C++ part of image insertion in the mobile app
Change-Id: I4b10f168f9283ba8a3f10dc272e24032af13b23b
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index cff93a276..056779a32 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -11,6 +11,7 @@
#include "ChildSession.hpp"
+#include <fstream>
#include <sstream>
#define LOK_USE_UNSTABLE_API
@@ -41,6 +42,18 @@ using namespace LOOLProtocol;
std::recursive_mutex ChildSession::Mutex;
+namespace {
+
+std::vector<unsigned char> decodeBase64(const std::string & inputBase64)
+{
+ std::istringstream stream(inputBase64);
+ Poco::Base64Decoder base64Decoder(stream);
+ std::istreambuf_iterator<char> eos;
+ return std::vector<unsigned char>(std::istreambuf_iterator<char>(base64Decoder), eos);
+}
+
+}
+
ChildSession::ChildSession(const std::string& id,
const std::string& jailId,
DocumentManagerInterface& docManager) :
@@ -773,6 +786,8 @@ bool ChildSession::paste(const char* buffer, int length, const std::vector<std::
bool ChildSession::insertFile(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
{
std::string name, type;
+
+#ifndef MOBILEAPP
if (tokens.size() != 3 ||
!getTokenString(tokens[1], "name", name) ||
!getTokenString(tokens[2], "type", type))
@@ -780,14 +795,37 @@ bool ChildSession::insertFile(const char* /*buffer*/, int /*length*/, const std:
sendTextFrame("error: cmd=insertfile kind=syntax");
return false;
}
+#else
+ std::string data;
+ if (tokens.size() != 4 ||
+ !getTokenString(tokens[1], "name", name) ||
+ !getTokenString(tokens[2], "type", type) ||
+ !getTokenString(tokens[3], "data", data))
+ {
+ sendTextFrame("error: cmd=insertfile kind=syntax");
+ return false;
+ }
+#endif
if (type == "graphic" || type == "graphicurl")
{
std::string url;
+
+#ifndef MOBILEAPP
if (type == "graphic")
url = "file://" + std::string(JAILED_DOCUMENT_ROOT) + "insertfile/" + name;
else if (type == "graphicurl")
URI::decode(name, url);
+#else
+ assert(type == "graphic");
+ auto binaryData = decodeBase64(data);
+ std::string tempFile = Util::createRandomTmpDir() + "/" + name;
+ std::ofstream fileStream;
+ fileStream.open(tempFile);
+ fileStream << binaryData.data();
+ fileStream.close();
+ url = "file://" + tempFile;
+#endif
std::string command = ".uno:InsertGraphic";
std::string arguments = "{"
@@ -1172,14 +1210,6 @@ std::string extractPrivateKey(const std::string & privateKey)
return privateKey.substr(pos1, pos2);
}
-std::vector<unsigned char> decodeBase64(const std::string & inputBase64)
-{
- std::istringstream stream(inputBase64);
- Poco::Base64Decoder base64Decoder(stream);
- std::istreambuf_iterator<char> eos;
- return std::vector<unsigned char>(std::istreambuf_iterator<char>(base64Decoder), eos);
-}
-
}
bool ChildSession::signDocumentContent(const char* buffer, int length, const std::vector<std::string>& /*tokens*/)
More information about the Libreoffice-commits
mailing list