framework/source/loadenv/loadenv.cxx | 11 ++++++++--- include/tools/fileutil.hxx | 5 ++--- sfx2/source/doc/docfile.cxx | 3 ++- tools/Library_tl.mk | 1 + tools/source/fsys/fileutil.cxx | 35 ++++++++++++++++++++++++++++------- 5 files changed, 41 insertions(+), 14 deletions(-)
New commits: commit 295557e083871ffe187b5e9c8dabf676c57311de Author: Mike Kaganski <[email protected]> AuthorDate: Wed Jan 9 10:54:10 2019 +0300 Commit: Mike Kaganski <[email protected]> CommitDate: Fri Jun 28 10:06:15 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 <[email protected]> Tested-by: Mike Kaganski <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/74831 diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index 178fd0ffe6c0..9fd29cd11a4a 100644 --- a/framework/source/loadenv/loadenv.cxx +++ b/framework/source/loadenv/loadenv.cxx @@ -88,6 +88,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"; @@ -238,21 +239,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 f198cb6b085a..ed96ed98395b 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -1311,7 +1311,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 252692c86863..8a77e03b4fc7 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -109,6 +109,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; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
