summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-01-09 10:54:10 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-06-28 11:40:20 +0200
commitc614e1fb800e531afd52c89a133a98c6e075b8c9 (patch)
tree8947bc7dc84440a1017c8046fe5a24662022e0b7 /tools
parent04146296b204da35c01420844930ae0c58fc8c89 (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> Reviewed-on: https://gerrit.libreoffice.org/74833
Diffstat (limited to 'tools')
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/fsys/fileutil.cxx35
2 files changed, 29 insertions, 7 deletions
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index acd007cc4761..b360919f570a 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -108,6 +108,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 a24f82316813..7b288ef378be 100644
--- a/tools/source/fsys/fileutil.cxx
+++ b/tools/source/fsys/fileutil.cxx
@@ -8,26 +8,42 @@
*/
#include <tools/fileutil.hxx>
-#include <tools/urlobj.hxx>
#if defined _WIN32
#include <osl/file.hxx>
-#include <string.h>
#include <o3tl/char16_t2wchar_t.hxx>
#include <o3tl/make_unique.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(o3tl::make_unique<wchar_t[]>(nSize));
+ DWORD nResult = DavGetHTTPFromUNCPath(sUNC, bufURL.get(), &nSize);
+ if (nResult == ERROR_INSUFFICIENT_BUFFER)
+ {
+ bufURL = o3tl::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(const OUString& rURL, 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(o3tl::make_unique<char[]>(nSize));
@@ -62,13 +78,18 @@ 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;
+ (void)rURL;
+ (void)pRealURL;
#endif
return false;
}