diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-01-09 10:54:10 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-06-28 08:33:46 +0200 |
commit | 20b1e6440aacab043753e93be4499e939a80b05b (patch) | |
tree | 1ac64459d876a7b2bf24afc70f115ad40b685e90 /tools | |
parent | 80eb3fd393dd6d67f931c03b261b2558c7198da2 (diff) |
tdf#126121: WebDAV redirection detection
This rewrites URI of a document opened from a WebDAV mapped UNC path
on Windows (like "file://server/DavWWWRoot/Dir/Doc.odt") into HTTP URI
(like "http://server/Dir/Doc.odt"). This allows using WebDAV protocol
for these files, and e.g. get information about other user who locked
the document to show when asking if open read-only or a copy.
Change-Id: I643fa8df30d4b163783b279b1b973304fcafff37
Reviewed-on: https://gerrit.libreoffice.org/71746
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Library_tl.mk | 1 | ||||
-rw-r--r-- | tools/source/fsys/fileutil.cxx | 34 |
2 files changed, 27 insertions, 8 deletions
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index 9f3df2dc825f..54f200e5dbb5 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -110,6 +110,7 @@ ifeq ($(OS),WNT) $(eval $(call gb_Library_use_system_win32_libs,tl,\ mpr \ + netapi32 \ ole32 \ shell32 \ uuid \ diff --git a/tools/source/fsys/fileutil.cxx b/tools/source/fsys/fileutil.cxx index 731afa58e63e..9470fabd2fee 100644 --- a/tools/source/fsys/fileutil.cxx +++ b/tools/source/fsys/fileutil.cxx @@ -9,24 +9,40 @@ #include <tools/fileutil.hxx> #if defined _WIN32 -#include <tools/urlobj.hxx> #include <osl/file.hxx> -#include <string.h> #include <o3tl/char16_t2wchar_t.hxx> #define WIN32_LEAN_AND_MEAN #include <Windows.h> +#include <davclnt.h> #endif +namespace +{ +#if defined _WIN32 +OUString UNCToDavURL(LPCWSTR sUNC) +{ + DWORD nSize = 1024; + auto bufURL(std::make_unique<wchar_t[]>(nSize)); + DWORD nResult = DavGetHTTPFromUNCPath(sUNC, bufURL.get(), &nSize); + if (nResult == ERROR_INSUFFICIENT_BUFFER) + { + bufURL = std::make_unique<wchar_t[]>(nSize); + nResult = DavGetHTTPFromUNCPath(sUNC, bufURL.get(), &nSize); + } + return nResult == ERROR_SUCCESS ? o3tl::toU(bufURL.get()) : OUString(); +} +#endif +} + namespace tools { -bool IsMappedWebDAVPath(const INetURLObject& aURL) +bool IsMappedWebDAVPath([[maybe_unused]] const OUString& rURL, [[maybe_unused]] OUString* pRealURL) { #if defined _WIN32 - if (aURL.GetProtocol() == INetProtocol::File) + if (rURL.startsWithIgnoreAsciiCase("file:")) { - OUString sURL = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); OUString aSystemPath; - if (osl::FileBase::getSystemPathFromFileURL(sURL, aSystemPath) == osl::FileBase::E_None) + if (osl::FileBase::getSystemPathFromFileURL(rURL, aSystemPath) == osl::FileBase::E_None) { DWORD nSize = MAX_PATH; auto bufUNC(std::make_unique<char[]>(nSize)); @@ -61,13 +77,15 @@ bool IsMappedWebDAVPath(const INetURLObject& aURL) { LPNETRESOURCEW pInfo = reinterpret_cast<LPNETRESOURCEW>(bufInfo.get()); if (wcscmp(pInfo->lpProvider, L"Web Client Network") == 0) + { + if (pRealURL) + *pRealURL = UNCToDavURL(aReq.lpRemoteName); return true; + } } } } } -#else - (void)aURL; #endif return false; } |