[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - framework/source include/tools sfx2/source tools/Library_tl.mk tools/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 28 09:40:56 UTC 2019
framework/source/loadenv/loadenv.cxx | 11 ++++++++---
include/tools/fileutil.hxx | 5 ++---
sfx2/source/doc/docfile.cxx | 5 +++--
tools/Library_tl.mk | 1 +
tools/source/fsys/fileutil.cxx | 35 ++++++++++++++++++++++++++++-------
5 files changed, 42 insertions(+), 15 deletions(-)
New commits:
commit c614e1fb800e531afd52c89a133a98c6e075b8c9
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Jan 9 10:54:10 2019 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Jun 28 11:40:20 2019 +0200
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 at collabora.com>
Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/74833
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index 2963013872f9..830b1faa6f64 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -89,6 +89,7 @@
#include <cppuhelper/implbase.hxx>
#include <comphelper/profilezone.hxx>
#include <classes/taskcreator.hxx>
+#include <tools/fileutil.hxx>
const char PROP_TYPES[] = "Types";
const char PROP_NAME[] = "Name";
@@ -246,21 +247,25 @@ void LoadEnv::initializeLoading(const OUString& sURL, const uno::Sequence<beans:
m_bReactivateControllerOnError = false;
m_bLoaded = false;
+ OUString aRealURL;
+ if (!tools::IsMappedWebDAVPath(sURL, &aRealURL))
+ aRealURL = sURL;
+
// try to find out, if its really a content, which can be loaded or must be "handled"
// We use a default value for this in-parameter. Then we have to start a complex check method
// internally. But if this check was already done outside it can be suppressed to perform
// the load request. We take over the result then!
- m_eContentType = LoadEnv::classifyContent(sURL, lMediaDescriptor);
+ m_eContentType = LoadEnv::classifyContent(aRealURL, lMediaDescriptor);
if (m_eContentType == E_UNSUPPORTED_CONTENT)
throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT, "from LoadEnv::initializeLoading");
// make URL part of the MediaDescriptor
// It doesn't matter if it is already an item of it.
// It must be the same value... so we can overwrite it :-)
- m_lMediaDescriptor[utl::MediaDescriptor::PROP_URL()] <<= sURL;
+ m_lMediaDescriptor[utl::MediaDescriptor::PROP_URL()] <<= aRealURL;
// parse it - because some following code require that
- m_aURL.Complete = sURL;
+ m_aURL.Complete = aRealURL;
uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));
xParser->parseStrict(m_aURL);
diff --git a/include/tools/fileutil.hxx b/include/tools/fileutil.hxx
index 06e7bf820992..d2ed87a6dff6 100644
--- a/include/tools/fileutil.hxx
+++ b/include/tools/fileutil.hxx
@@ -11,15 +11,14 @@
#define INCLUDED_TOOLS_FILEUTIL_HXX
#include <tools/toolsdllapi.h>
-
-class INetURLObject;
+#include <rtl/ustring.hxx>
namespace tools
{
// Tests if the path is a UNC or local (drive-based) path that redirects to
// a WebDAV resource (e.g., using redirectors on Windows).
// Currently only implemented for Windows; on other platforms, returns false.
-TOOLS_DLLPUBLIC bool IsMappedWebDAVPath(const INetURLObject& aURL);
+TOOLS_DLLPUBLIC bool IsMappedWebDAVPath(const OUString& rURL, OUString* pRealURL = nullptr);
}
#endif // INCLUDED_TOOLS_FILEUTIL_HXX
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index a06ca65c65b9..bb153e5badb5 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -231,7 +231,7 @@ bool IsFileMovable(const INetURLObject& rURL)
if (buf.st_nlink > 1 || S_ISLNK(buf.st_mode))
return false;
#elif defined _WIN32
- if (tools::IsMappedWebDAVPath(rURL))
+ if (tools::IsMappedWebDAVPath(rURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)))
return false;
#endif
@@ -1365,7 +1365,8 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
}
catch (const uno::Exception&)
{
- if (tools::IsMappedWebDAVPath(GetURLObject()))
+ if (tools::IsMappedWebDAVPath(GetURLObject().GetMainURL(
+ INetURLObject::DecodeMechanism::NONE)))
{
// This is a path that redirects to a WebDAV resource;
// so failure creating lockfile is not an error here.
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;
}
More information about the Libreoffice-commits
mailing list