[Libreoffice-commits] online.git: loolwsd/LOOLWSD.hpp loolwsd/Storage.hpp
loolwsd/LOOLWSD.hpp |8 +-- loolwsd/Storage.hpp | 118 ++-- 2 files changed, 74 insertions(+), 52 deletions(-) New commits: commit e8214c1d2a51cfe50337ae1fd088528d1ea80984 Author: Ashod Nakashian Date: Wed Mar 9 18:36:25 2016 -0500 loolwsd: refactored Storage classes Change-Id: I3cc3aa2c1ddf70b8d2f3489aa4047f6470c93eb2 Reviewed-on: https://gerrit.libreoffice.org/23108 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 33f6913..c227587 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -64,8 +64,8 @@ public: { uriPublic.normalize(); Log::info("Public URI [" + uriPublic.toString() + "] is a file."); -std::unique_ptr storage(new LocalStorage(jailRoot, jailPath.toString())); -const auto localPath = storage->getFilePathFromURI(uriPublic.getPath()); +std::unique_ptr storage(new LocalStorage(jailRoot, jailPath.toString(), uriPublic.getPath())); +const auto localPath = storage->getLocalFilePathFromStorage(); uriJailed = Poco::URI(Poco::URI("file://"), localPath); } else @@ -73,8 +73,8 @@ public: Log::info("Public URI [" + uriPublic.toString() + "] assuming cloud storage."); //TODO: Configure the storage to use. For now, assume it's WOPI. -std::unique_ptr storage(new WopiStorage(jailRoot, jailPath.toString())); -const auto localPath = storage->getFilePathFromURI(uriPublic.toString()); +std::unique_ptr storage(new WopiStorage(jailRoot, jailPath.toString(), uriPublic.toString())); +const auto localPath = storage->getLocalFilePathFromStorage(); uriJailed = Poco::URI(Poco::URI("file://"), localPath); } diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index bb9a4d0..4e1133b 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -28,13 +28,15 @@ public: /// localStorePath the absolute root path of the chroot. /// jailPath the path within the jail that the child uses. StorageBase(const std::string& localStorePath, -const std::string& jailPath) : +const std::string& jailPath, +const std::string& uri) : _localStorePath(localStorePath), -_jailPath(jailPath) +_jailPath(jailPath), +_uri(uri) { } -std::string getRootPath() const +std::string getLocalRootPath() const { auto localPath = _jailPath; if (localPath[0] == '/') @@ -50,16 +52,20 @@ public: return rootPath.toString(); } +const std::string& getUri() const { return _uri; } + /// 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; +virtual std::string getLocalFilePathFromStorage() = 0; /// Writes the contents of the file back to the source. -virtual bool restoreFileToURI(const std::string& path, const std::string& uri) = 0; +virtual bool restoreLocalFileToStorage() = 0; protected: const std::string _localStorePath; const std::string _jailPath; +const std::string _uri; +std::string _jailedFilePath; }; /// Trivial implementation of local storage that does not need do anything. @@ -67,42 +73,45 @@ class LocalStorage : public StorageBase { public: LocalStorage(const std::string& localStorePath, - const std::string& jailPath) : -StorageBase(localStorePath, jailPath) + const std::string& jailPath, + const std::string& uri) : +StorageBase(localStorePath, jailPath, uri), +_isCopy(false) { } -std::string getFilePathFromURI(const std::string& uri) override +std::string getLocalFilePathFromStorage() override { -const auto rootPath = getRootPath(); +const auto rootPath = getLocalRootPath(); // /chroot/jailId/user/doc/childId/file.ext -const auto filename = Poco::Path(uri).getFileName(); -const auto jailedFilePath = Poco::Path(rootPath, filename).toString(); +const auto filename = Poco::Path(_uri).getFileName(); +_jailedFilePath = Poco::Path(rootPath, filename).toString(); -Log::info("Public URI [" + uri + - "] jailed to [" + jailedFilePath + "]."); +Log::info("Public URI [" + _uri + + "] jailed to [" + _jailedFilePath + "]."); -const auto publicFilePath = uri; -Log::info("Linking " + publicFilePath + " to " + jailedFilePath); -if (!Poco::File(jailedFilePath).exists() && link(publicFilePath.c_str(), jailedFilePath.c_str()) == -1) +const auto publicFilePath = _uri; +Log::info("Linking " + publicFilePath
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.hpp loolwsd/Storage.hpp
loolwsd/LOOLWSD.hpp | 14 -- loolwsd/Storage.hpp | 13 + 2 files changed, 17 insertions(+), 10 deletions(-) New commits: commit e5fcdb890e54568aa62fbc61c3454d6f2d106758 Author: Ashod Nakashian Date: Tue Mar 8 19:50:35 2016 -0500 loolwsd: corrections to file and wopi URI handling Change-Id: I7389a30931be01a40714167039055a758187bd82 Reviewed-on: https://gerrit.libreoffice.org/23053 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 77d0ea0..33f6913 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -39,12 +39,12 @@ public: Log::info("DocumentURI: url: " + url + ", jailRoot: " + jailRoot + ", childId: " + childId); // TODO: Sanitize the url and limit access! -auto uriPublic = Poco::URI(url); -uriPublic.normalize(); +std::string decodedUrl; +Poco::URI::decode(url, decodedUrl); +auto uriPublic = Poco::URI(decodedUrl); +Log::info("Public URI [" + uriPublic.toString() + "]."); -const auto publicFilePath = uriPublic.getPath(); - -if (publicFilePath.empty()) +if (uriPublic.getPath().empty()) throw std::runtime_error("Invalid URL."); // This lock could become a bottleneck. @@ -62,6 +62,8 @@ public: auto uriJailed = uriPublic; if (uriPublic.isRelative() || uriPublic.getScheme() == "file") { +uriPublic.normalize(); +Log::info("Public URI [" + uriPublic.toString() + "] is a file."); std::unique_ptr storage(new LocalStorage(jailRoot, jailPath.toString())); const auto localPath = storage->getFilePathFromURI(uriPublic.getPath()); uriJailed = Poco::URI(Poco::URI("file://"), localPath); @@ -78,7 +80,7 @@ public: auto document = std::shared_ptr(new DocumentURI(uriPublic, uriJailed, childId)); -Log::info("DocumentURI [" + publicFilePath + "] created."); +Log::info("DocumentURI [" + uriPublic.toString() + "] created."); return document; } diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index 8fcf773..5dadb9d 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -131,21 +131,26 @@ public: /// uri format: http://server/<...>/wopi*/files//content std::string getFilePathFromURI(const std::string& uri) override { +Log::info("Downloading URI [" + uri + "]."); + 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; +Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1); session.sendRequest(request); +Poco::Net::HTTPResponse response; 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"; +const auto filename = "filename"; +const std::string local_filename = Poco::Path(getRootPath(), filename).toString(); std::ofstream ofs(local_filename); std::copy(std::istreambuf_iterator(rs), std::istreambuf_iterator(), std::ostreambuf_iterator(ofs)); -return local_filename; + +// Now return the jailed path. +return Poco::Path(_jailPath, filename).toString(); } bool restoreFileToURI(const std::string& path, const std::string& uri) override ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.hpp loolwsd/Storage.hpp
loolwsd/LOOLWSD.hpp | 49 loolwsd/Storage.hpp | 70 +--- 2 files changed, 72 insertions(+), 47 deletions(-) New commits: commit 6c6951956269ceb232f682bac295a3204e4edeca Author: Ashod Nakashian Date: Sat Mar 5 10:27:30 2016 -0500 Storage is used to manage files locally Change-Id: Id50eca8fe1136777ca99c60d78c15e1a47397993 Reviewed-on: https://gerrit.libreoffice.org/23049 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 0997fb2..77d0ea0 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -36,6 +36,8 @@ public: const std::string& jailRoot, const std::string& childId) { +Log::info("DocumentURI: url: " + url + ", jailRoot: " + jailRoot + ", childId: " + childId); + // TODO: Sanitize the url and limit access! auto uriPublic = Poco::URI(url); uriPublic.normalize(); @@ -52,55 +54,26 @@ public: // The URL is the publicly visible one, not visible in the chroot jail. // We need to map it to a jailed path and copy the file there. -// chroot/jailId/user/doc -const auto jailedDocRoot = Poco::Path(jailRoot, JailedDocumentRoot); +// user/doc/childId +const auto jailPath = Poco::Path(JailedDocumentRoot, childId); -// chroot/jailId/user/doc/childId -const auto docPath = Poco::Path(jailedDocRoot, childId); -Poco::File(docPath).createDirectories(); +Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot); auto uriJailed = uriPublic; if (uriPublic.isRelative() || uriPublic.getScheme() == "file") { -const auto filename = Poco::Path(uriPublic.getPath()).getFileName(); - -// chroot/jailId/user/doc/childId/file.ext -const auto jailedFilePath = Poco::Path(docPath, filename).toString(); - -const auto localPath = Poco::Path(JailedDocumentRoot, childId); -uriJailed = Poco::URI(Poco::URI("file://"), Poco::Path(localPath, filename).toString()); - -Log::info("Public URI [" + uriPublic.toString() + - "] jailed to [" + uriJailed.toString() + "]."); - -Log::info("Linking " + publicFilePath + " to " + jailedFilePath); -if (!Poco::File(jailedFilePath).exists() && link(publicFilePath.c_str(), jailedFilePath.c_str()) == -1) -{ -// Failed -Log::error("link(\"" + publicFilePath + "\", \"" + jailedFilePath + "\") failed."); -} - -try -{ -// Fallback to copying. -if (!Poco::File(jailedFilePath).exists()) -{ -Log::info("Copying " + publicFilePath + " to " + jailedFilePath); -Poco::File(publicFilePath).copyTo(jailedFilePath); -} -} -catch (const Poco::Exception& exc) -{ -Log::error("copyTo(\"" + publicFilePath + "\", \"" + jailedFilePath + "\") failed: " + exc.displayText()); -throw; -} +std::unique_ptr storage(new LocalStorage(jailRoot, jailPath.toString())); +const auto localPath = storage->getFilePathFromURI(uriPublic.getPath()); +uriJailed = Poco::URI(Poco::URI("file://"), localPath); } else { Log::info("Public URI [" + uriPublic.toString() + "] assuming cloud storage."); //TODO: Configure the storage to use. For now, assume it's WOPI. -std::unique_ptr storage(new WopiStorage(docPath.toString())); +std::unique_ptr storage(new WopiStorage(jailRoot, jailPath.toString())); +const auto localPath = storage->getFilePathFromURI(uriPublic.toString()); +uriJailed = Poco::URI(Poco::URI("file://"), localPath); } auto document = std::shared_ptr(new DocumentURI(uriPublic, uriJailed, childId)); diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index a9db691..efda920 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -16,6 +16,7 @@ #include +#include "Common.hpp" #include "Auth.hpp" #include "Util.hpp" @@ -24,8 +25,12 @@ class StorageBase { public: -StorageBase(const std::string& localStorePath) : -_localStorePath(localStorePath) +/// localStorePath the absolute root path of the chroot. +/// jailPath the path within the jail that the child uses. +StorageBase(const std::string& localStorePath, +const std::string& jailPath) : +_localStorePath(localStorePath), +_jailPath(jailPath) { } @@ -38,18 +43,64 @@ public: protected: const std::string _localSt
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.hpp loolwsd/Storage.hpp
loolwsd/LOOLWSD.hpp |4 ++- loolwsd/Storage.hpp | 63 +--- 2 files changed, 63 insertions(+), 4 deletions(-) New commits: commit 743311af2137089e16bae3168a6e5413e3aee751 Author: Ashod Nakashian 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 Tested-by: Ashod Nakashian 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 storage(new WopiStorage(docPath.toString())); } auto document = std::shared_ptr(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 +#include + #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//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(rs), + std::istreambuf_iterator(), + std::ostreambuf_iterator(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 authAgent) : +WebDAVStorage(const std::string& localStorePath, + const std::string& url, + std::unique_ptr authAgent) : +StorageBase(localStorePath), _url(url), _authAgent(std::move(authAgent)) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits