[Libreoffice-commits] online.git: wsd/Storage.cpp wsd/Storage.hpp
wsd/Storage.cpp | 71 wsd/Storage.hpp |6 2 files changed, 42 insertions(+), 35 deletions(-) New commits: commit 2c73b622d75ee6fa62b7d74e1548cda877201af8 Author: Ashod Nakashian AuthorDate: Sun Jun 14 12:44:10 2020 -0400 Commit: Ashod Nakashian CommitDate: Sat Jun 20 16:33:20 2020 +0200 wsd: extract WOPI HTTP request construction This hoists the common parts of the HTTPRequest for all WOPI requests to avoid errors when changing them. Change-Id: Ia02ef657a43b7a7d2fc13be3da012836fa0d7650 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96372 Tested-by: Jenkins CollaboraOffice Tested-by: Jenkins Reviewed-by: Ashod Nakashian diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 1da4eaf74..61823d67e 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -529,6 +529,23 @@ void LockContext::dumpState(std::ostream& os) const #if !MOBILEAPP +void WopiStorage::initHttpRequest(Poco::Net::HTTPRequest& request, const Poco::URI& uri, + const Authorization& auth, const std::string& cookies) const +{ +request.set("User-Agent", WOPI_AGENT_STRING); + +auth.authorizeRequest(request); + +addStorageDebugCookie(request); + +// TODO: Avoid repeated parsing. +std::map params = GetQueryParams(uri); +addWopiProof(request, uri, params["access_token"]); + +if (_reuseCookies) +addStorageReuseCookie(request, cookies); +} + std::unique_ptr WopiStorage::getWOPIFileInfo(const Authorization& auth, const std::string& cookies, LockContext& lockCtx) @@ -537,7 +554,6 @@ std::unique_ptr WopiStorage::getWOPIFileInfo(const Au Poco::URI uriObject(getUri()); auth.authorizeURI(uriObject); const std::string uriAnonym = LOOLWSD::anonymizeUrl(uriObject.toString()); -std::map params = GetQueryParams(uriObject); LOG_DBG("Getting info for wopi uri [" << uriAnonym << "]."); @@ -545,13 +561,11 @@ std::unique_ptr WopiStorage::getWOPIFileInfo(const Au std::chrono::duration callDuration(0); try { -Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1); -request.set("User-Agent", WOPI_AGENT_STRING); -auth.authorizeRequest(request); -addStorageDebugCookie(request); -if (_reuseCookies) -addStorageReuseCookie(request, cookies); -addWopiProof(request, uriObject, params["access_token"]); +Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, + uriObject.getPathAndQuery(), + Poco::Net::HTTPMessage::HTTP_1_1); +initHttpRequest(request, uriObject, auth, cookies); + const auto startTime = std::chrono::steady_clock::now(); std::unique_ptr psession(getHTTPClientSession(uriObject)); @@ -760,8 +774,6 @@ bool WopiStorage::updateLockState(const Authorization& auth, const std::string& Poco::URI uriObject(getUri()); auth.authorizeURI(uriObject); -std::map params = GetQueryParams(uriObject); - Poco::URI uriObjectAnonym(getUri()); uriObjectAnonym.setPath(LOOLWSD::anonymizeUrl(uriObjectAnonym.getPath())); const std::string uriAnonym = uriObjectAnonym.toString(); @@ -773,18 +785,15 @@ bool WopiStorage::updateLockState(const Authorization& auth, const std::string& { std::unique_ptr psession(getHTTPClientSession(uriObject)); -Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1); -request.set("User-Agent", WOPI_AGENT_STRING); -auth.authorizeRequest(request); +Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, + uriObject.getPathAndQuery(), + Poco::Net::HTTPMessage::HTTP_1_1); +initHttpRequest(request, uriObject, auth, cookies); request.set("X-WOPI-Override", lock ? "LOCK" : "UNLOCK"); request.set("X-WOPI-Lock", lockCtx._lockToken); if (!getExtendedData().empty()) request.set("X-LOOL-WOPI-ExtendedData", getExtendedData()); -addStorageDebugCookie(request); -if (_reuseCookies) -addStorageReuseCookie(request, cookies); -addWopiProof(request, uriObject, params["access_token"]); psession->sendRequest(request); Poco::Net::HTTPResponse response; @@ -833,8 +842,6 @@ std::string WopiStorage::loadStorageFileToLocal(const Authorization& auth, uriObject.setPath(uriObject.getPath() + "/contents"); auth.authorizeURI(uriObject); -std::map params = GetQueryParams(uriObject); - Poco::U
[Libreoffice-commits] online.git: wsd/Storage.cpp wsd/Storage.hpp
wsd/Storage.cpp | 239 ++-- wsd/Storage.hpp | 95 +- 2 files changed, 120 insertions(+), 214 deletions(-) New commits: commit 33a5813d84f24910c36adc3615b0d017f13f6e4d Author: Michael Meeks AuthorDate: Thu Jun 11 15:54:27 2020 +0100 Commit: Michael Meeks CommitDate: Thu Jun 11 17:38:32 2020 +0200 WOPI: pure re-factor, remove rampant duplication. Dung out lots of pointless intermediate variables, and overly verbose code. Vertical space is not a renewable resource. Most variables had a consistent pattern, except these: caller var c'tor parameter member name Change-Id: I7910b713b8c4f6950b1e7be9c3a8e4eb4f54e249 -- userId userid _userId userNameusername_username canWriteuserCanWrite_userCanWriter Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96129 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 95046acac..3960544c2 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -12,6 +12,7 @@ #include "Storage.hpp" #include +#include #include #include #include @@ -602,40 +603,6 @@ std::unique_ptr WopiStorage::getWOPIFileInfo(const Au LOG_ERR("Cannot get file info from WOPI storage uri [" << uriAnonym << "]. Error: Failed HTPP request authorization"); } -// Parse the response. -std::string filename; -size_t size = 0; -std::string ownerId; -std::string userId; -std::string userName; -std::string obfuscatedUserId; -std::string userExtraInfo; -std::string watermarkText; -std::string templateSaveAs; -std::string templateSource; -bool canWrite = false; -bool enableOwnerTermination = false; -std::string postMessageOrigin; -bool hidePrintOption = false; -bool hideSaveOption = false; -bool hideExportOption = false; -bool disablePrint = false; -bool disableExport = false; -bool disableCopy = false; -bool disableInactiveMessages = false; -bool downloadAsPostMessage = false; -std::string lastModifiedTime; -bool userCanNotWriteRelative = true; -bool enableInsertRemoteImage = false; -bool enableShare = false; -bool supportsLocks = false; -bool supportsRename = false; -bool userCanRename = false; -std::string hideUserList("false"); -WOPIFileInfo::TriState disableChangeTrackingRecord = WOPIFileInfo::TriState::Unset; -WOPIFileInfo::TriState disableChangeTrackingShow = WOPIFileInfo::TriState::Unset; -WOPIFileInfo::TriState hideChangeTrackingControls = WOPIFileInfo::TriState::Unset; - Poco::JSON::Object::Ptr object; if (JsonUtil::parseJSON(wopiResponse, object)) { @@ -644,88 +611,26 @@ std::unique_ptr WopiStorage::getWOPIFileInfo(const Au else LOG_DBG("WOPI::CheckFileInfo (" << callDuration.count() * 1000. << " ms): " << wopiResponse); -JsonUtil::findJSONValue(object, "BaseFileName", filename); +size_t size = 0; +std::string filename, ownerId, lastModifiedTime; + +JsonUtil::findJSONValue(object, "Size", size); JsonUtil::findJSONValue(object, "OwnerId", ownerId); -JsonUtil::findJSONValue(object, "UserId", userId); -JsonUtil::findJSONValue(object, "UserFriendlyName", userName); -JsonUtil::findJSONValue(object, "TemplateSaveAs", templateSaveAs); -JsonUtil::findJSONValue(object, "TemplateSource", templateSource); +JsonUtil::findJSONValue(object, "BaseFileName", filename); +JsonUtil::findJSONValue(object, "LastModifiedTime", lastModifiedTime); + +const std::chrono::system_clock::time_point modifiedTime = Util::iso8601ToTimestamp(lastModifiedTime, "LastModifiedTime"); +FileInfo fileInfo = FileInfo({filename, ownerId, modifiedTime, size}); +setFileInfo(fileInfo); -// Anonymize key values. if (LOOLWSD::AnonymizeUserData) -{ Util::mapAnonymized(Util::getFilenameFromURL(filename), Util::getFilenameFromURL(getUri().toString())); -JsonUtil::findJSONValue(object, "ObfuscatedUserId", obfuscatedUserId, false); -if (!obfuscatedUserId.empty()) -{ -Util::mapAnonymized(ownerId, obfuscatedUserId); -Util::mapAnonymized(userId, obfuscatedUserId); -Util::mapAnonymized(userName, obfuscatedUserId); -} - -// Set anonymized version of the above fields before logging. -// Note: anonymization caches the result, so we don't need to store here. -if (LOOLWSD::AnonymizeUserData) -object->set("BaseFileName", LOOLWSD::anonymizeUrl(filename)); - -// I
[Libreoffice-commits] online.git: wsd/Storage.cpp wsd/Storage.hpp
wsd/Storage.cpp |2 +- wsd/Storage.hpp |2 +- 2 files changed, 2 insertions(+), 2 deletions(-) New commits: commit 043e3c5238ded940a109f51bc170eaf83dde5670 Author: Samuel Mehrbrodt AuthorDate: Mon Jun 8 15:26:09 2020 +0200 Commit: Samuel Mehrbrodt CommitDate: Mon Jun 8 15:39:00 2020 +0200 Rename: getIsAutosave -> isAutosave Change-Id: I30b8d52ff33c2ae270b44a1670bacc4a48af4495 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95807 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 7e262b1cd..95046acac 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -970,7 +970,7 @@ WopiStorage::saveLocalFileToStorage(const Authorization& auth, const std::string if (lockCtx._supportsLocks) request.set("X-WOPI-Lock", lockCtx._lockToken); request.set("X-LOOL-WOPI-IsModifiedByUser", isUserModified()? "true": "false"); -request.set("X-LOOL-WOPI-IsAutosave", getIsAutosave()? "true": "false"); +request.set("X-LOOL-WOPI-IsAutosave", isAutosave()? "true": "false"); request.set("X-LOOL-WOPI-IsExitSave", isExitSave()? "true": "false"); if (!getExtendedData().empty()) request.set("X-LOOL-WOPI-ExtendedData", getExtendedData()); diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp index e5ea41101..e7fa612b9 100644 --- a/wsd/Storage.hpp +++ b/wsd/Storage.hpp @@ -203,7 +203,7 @@ public: /// To be able to set the WOPI 'is autosave/is exitsave?' headers appropriately. void setIsAutosave(bool isAutosave) { _isAutosave = isAutosave; } -bool getIsAutosave() const { return _isAutosave; } +bool isAutosave() const { return _isAutosave; } void setIsExitSave(bool exitSave) { _isExitSave = exitSave; } bool isExitSave() const { return _isExitSave; } void setExtendedData(const std::string& extendedData) { _extendedData = extendedData; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: wsd/Storage.cpp wsd/Storage.hpp
wsd/Storage.cpp | 54 ++ wsd/Storage.hpp | 17 + 2 files changed, 43 insertions(+), 28 deletions(-) New commits: commit aef5af8114b335dd3da840258c009729c73f2511 Author: Ashod Nakashian Date: Thu Dec 22 16:41:05 2016 -0500 wsd: Storage logs updated Change-Id: Ib3083e833fdc2891ab0c89231bf2ec3e81285803 Reviewed-on: https://gerrit.libreoffice.org/32560 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 9c0f0ef..d7a7119 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -108,14 +108,14 @@ bool isLocalhost(const std::string& targetHost) } catch (const Poco::Exception& exc) { -Log::warn("Poco::Net::DNS::resolveOne(\"" + targetHost + "\") failed: " + exc.displayText()); +LOG_WRN("Poco::Net::DNS::resolveOne(\"" << targetHost << "\") failed: " << exc.displayText()); try { targetAddress = Poco::Net::IPAddress(targetHost).toString(); } catch (const Poco::Exception& exc1) { -Log::warn("Poco::Net::IPAddress(\"" + targetHost + "\") failed: " + exc1.displayText()); +LOG_WRN("Poco::Net::IPAddress(\"" << targetHost << "\") failed: " << exc1.displayText()); } } @@ -192,7 +192,7 @@ std::atomic LocalStorage::LastLocalStorageId; std::unique_ptr LocalStorage::getLocalFileInfo(const Poco::URI& uriPublic) { const auto path = Poco::Path(uriPublic.getPath()); -Log::debug("Getting info for local uri [" + uriPublic.toString() + "], path [" + path.toString() + "]."); +LOG_DBG("Getting info for local uri [" << uriPublic.toString() << "], path [" << path.toString() << "]."); const auto& filename = path.getFileName(); const auto file = Poco::File(path); @@ -213,7 +213,7 @@ std::string LocalStorage::loadStorageFileToLocal() const auto filename = Poco::Path(_uri.getPath()).getFileName(); _jailedFilePath = Poco::Path(rootPath, filename).toString(); LOG_INF("Public URI [" << _uri.getPath() << -"] jailed to [" + _jailedFilePath + "]."); +"] jailed to [" << _jailedFilePath << "]."); // Despite the talk about URIs it seems that _uri is actually just a pathname here const auto publicFilePath = _uri.getPath(); @@ -227,7 +227,7 @@ std::string LocalStorage::loadStorageFileToLocal() if (!Poco::File(_jailedFilePath).exists() && link(publicFilePath.c_str(), _jailedFilePath.c_str()) == -1) { // Failed -Log::warn("link(\"" + publicFilePath + "\", \"" + _jailedFilePath + "\") failed. Will copy."); +LOG_WRN("link(\"" << publicFilePath << "\", \"" << _jailedFilePath << "\") failed. Will copy."); } try @@ -242,7 +242,7 @@ std::string LocalStorage::loadStorageFileToLocal() } catch (const Poco::Exception& exc) { -Log::error("copyTo(\"" + publicFilePath + "\", \"" + _jailedFilePath + "\") failed: " + exc.displayText()); +LOG_ERR("copyTo(\"" << publicFilePath << "\", \"" << _jailedFilePath << "\") failed: " << exc.displayText()); throw; } @@ -357,7 +357,7 @@ void getWOPIValue(const Poco::JSON::Object::Ptr &object, const std::string& key, std::unique_ptr WopiStorage::getWOPIFileInfo(const Poco::URI& uriPublic) { -LOG_DBG("Getting info for wopi uri [" + uriPublic.toString() + "]."); +LOG_DBG("Getting info for wopi uri [" << uriPublic.toString() << "]."); std::string resMsg; const auto startTime = std::chrono::steady_clock::now(); @@ -374,13 +374,17 @@ std::unique_ptr WopiStorage::getWOPIFileInfo(const Po std::istream& rs = psession->receiveResponse(response); callDuration = (std::chrono::steady_clock::now() - startTime); -auto logger = Log::trace(); -logger << "WOPI::CheckFileInfo header for URI [" << uriPublic.toString() << "]:\n"; -for (auto& pair : response) +if (Log::traceEnabled()) { -logger << '\t' + pair.first + ": " + pair.second << " / "; +auto logger = Log::trace(); +logger << "WOPI::CheckFileInfo header for URI [" << uriPublic.toString() << "]:\n"; +for (const auto& pair : response) +{ +logger << '\t' << pair.first << ": " << pair.second << " / "; +} + +logger << Log::end; } -logger << Log::end; Poco::StreamCopier::copyToString(rs, resMsg); } @@ -408,7 +412,7 @@ std::unique_ptr WopiStorage::getWOPIFileInfo(const Po bool disableCopy = false; std::string lastModifiedTime; -LOG_DBG("WOPI::CheckFileInfo returned: " + resMsg + ". Call duration: " + std::to_string(callDuration.count()) + "s"); +LOG_DBG("WOPI::CheckFileInfo returned: " << resMsg << ". Call duration: " << callDuration.count() << "s"); const auto index = resMsg.find_first_of('{