[Libreoffice-commits] online.git: loolwsd/LOOLWSD.hpp loolwsd/Storage.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Fri Mar 4 03:06:46 UTC 2016
loolwsd/LOOLWSD.hpp | 4 ++-
loolwsd/Storage.hpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 63 insertions(+), 4 deletions(-)
New commits:
commit 743311af2137089e16bae3168a6e5413e3aee751
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Mar 3 21:05:30 2016 -0500
loolwsd: added wopi storage manager
Change-Id: Ia28fb3d42c43387432e0b183a1bcf6b0924da820
Reviewed-on: https://gerrit.libreoffice.org/22885
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index ba11e68..a41cceb 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -100,7 +100,9 @@ public:
else
{
Log::info("Public URI [" + uriPublic.toString() +
- "] is not a file.");
+ "] assuming cloud storage.");
+ //TODO: Configure the storage to use. For now, assume it's WOPI.
+ std::unique_ptr<StorageBase> storage(new WopiStorage(docPath.toString()));
}
auto document = std::shared_ptr<DocumentURI>(new DocumentURI(uriPublic, uriJailed, childId));
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index 1cf2991..f38c593 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -13,6 +13,8 @@
#include <string>
+#include <Poco/Net/HTTPResponse.h>
+
#include "Auth.hpp"
#include "Util.hpp"
@@ -21,13 +23,20 @@ class StorageBase
{
public:
- /// Returns a local file path given a URI.
+ StorageBase(const std::string& localStorePath) :
+ _localStorePath(localStorePath)
+ {
+ }
+
+ /// Returns a local file path given a URI or ID.
/// If necessary copies the file locally first.
virtual std::string getFilePathFromURI(const std::string& uri) = 0;
- /// Writes the contents of the file back to the URI.
+ /// Writes the contents of the file back to the source.
virtual bool restoreFileToURI(const std::string& path, const std::string& uri) = 0;
+protected:
+ const std::string _localStorePath;
};
/// Trivial implementation of local storage that does not need do anything.
@@ -51,11 +60,59 @@ public:
}
};
+class WopiStorage : public StorageBase
+{
+public:
+ WopiStorage(const std::string& localStorePath) :
+ StorageBase(localStorePath)
+ {
+ }
+
+ /// uri format: http://server/<...>/wopi*/files/<id>/content
+ std::string getFilePathFromURI(const std::string& uri) override
+ {
+ Poco::URI uriObject(uri);
+ Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort());
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uri, Poco::Net::HTTPMessage::HTTP_1_1);
+ Poco::Net::HTTPResponse response;
+ session.sendRequest(request);
+ std::istream& rs = session.receiveResponse(response);
+ Log::info() << "WOPI::GetFile Status: " << response.getStatus() << " " << response.getReason() << Log::end;
+
+ //TODO: Get proper filename.
+ const std::string local_filename = _localStorePath + "/filename";
+ std::ofstream ofs(local_filename);
+ std::copy(std::istreambuf_iterator<char>(rs),
+ std::istreambuf_iterator<char>(),
+ std::ostreambuf_iterator<char>(ofs));
+ return local_filename;
+ }
+
+ bool restoreFileToURI(const std::string& path, const std::string& uri) override
+ {
+ Poco::URI uriObject(uri);
+ Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort());
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, uri, Poco::Net::HTTPMessage::HTTP_1_1);
+
+ std::ifstream ifs(path);
+ request.read(ifs);
+
+ Poco::Net::HTTPResponse response;
+ session.sendRequest(request);
+ Log::info() << "WOPI::PutFile Status: " << response.getStatus() << " " << response.getReason() << Log::end;
+
+ return (response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK);
+ }
+};
+
class WebDAVStorage : public StorageBase
{
public:
- WebDAVStorage(const std::string& url, std::unique_ptr<AuthBase> authAgent) :
+ WebDAVStorage(const std::string& localStorePath,
+ const std::string& url,
+ std::unique_ptr<AuthBase> authAgent) :
+ StorageBase(localStorePath),
_url(url),
_authAgent(std::move(authAgent))
{
More information about the Libreoffice-commits
mailing list