1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <tools/fileutil.hxx>
12 #include <osl/file.hxx>
13 #include <rtl/uri.hxx>
14 #include <o3tl/char16_t2wchar_t.hxx>
15 #define WIN32_LEAN_AND_MEAN
23 OUString
UNCToDavURL(LPCWSTR sUNC
)
26 auto bufURL(std::make_unique
<wchar_t[]>(nSize
));
27 DWORD nResult
= DavGetHTTPFromUNCPath(sUNC
, bufURL
.get(), &nSize
);
28 if (nResult
== ERROR_INSUFFICIENT_BUFFER
)
30 bufURL
= std::make_unique
<wchar_t[]>(nSize
);
31 nResult
= DavGetHTTPFromUNCPath(sUNC
, bufURL
.get(), &nSize
);
33 // looks like on different Windowses this may or may not be URL encoded?
34 return nResult
== ERROR_SUCCESS
35 ? ::rtl::Uri::encode(OUString(o3tl::toU(bufURL
.get())), rtl_UriCharClassUric
,
36 rtl_UriEncodeKeepEscapes
, RTL_TEXTENCODING_UTF8
)
44 bool IsMappedWebDAVPath([[maybe_unused
]] const OUString
& rURL
, [[maybe_unused
]] OUString
* pRealURL
)
47 if (rURL
.startsWithIgnoreAsciiCase("file:"))
50 if (osl::FileBase::getSystemPathFromFileURL(rURL
, aSystemPath
) == osl::FileBase::E_None
)
52 DWORD nSize
= MAX_PATH
;
53 auto bufUNC(std::make_unique
<char[]>(nSize
));
54 DWORD nResult
= WNetGetUniversalNameW(o3tl::toW(aSystemPath
.getStr()),
55 UNIVERSAL_NAME_INFO_LEVEL
, bufUNC
.get(), &nSize
);
56 if (nResult
== ERROR_MORE_DATA
)
58 bufUNC
= std::make_unique
<char[]>(nSize
);
59 nResult
= WNetGetUniversalNameW(o3tl::toW(aSystemPath
.getStr()),
60 UNIVERSAL_NAME_INFO_LEVEL
, bufUNC
.get(), &nSize
);
62 if (nResult
== NO_ERROR
|| nResult
== ERROR_BAD_DEVICE
)
65 if (nResult
== ERROR_BAD_DEVICE
) // The path could already be an UNC
66 aReq
.lpRemoteName
= const_cast<LPWSTR
>(o3tl::toW(aSystemPath
.getStr()));
69 auto pInfo
= reinterpret_cast<LPUNIVERSAL_NAME_INFOW
>(bufUNC
.get());
70 aReq
.lpRemoteName
= pInfo
->lpUniversalName
;
73 auto bufInfo(std::make_unique
<char[]>(nSize
));
74 LPWSTR pSystem
= nullptr;
75 nResult
= WNetGetResourceInformationW(&aReq
, bufInfo
.get(), &nSize
, &pSystem
);
76 if (nResult
== ERROR_MORE_DATA
)
78 bufInfo
= std::make_unique
<char[]>(nSize
);
79 nResult
= WNetGetResourceInformationW(&aReq
, bufInfo
.get(), &nSize
, &pSystem
);
81 if (nResult
== NO_ERROR
)
83 LPNETRESOURCEW pInfo
= reinterpret_cast<LPNETRESOURCEW
>(bufInfo
.get());
84 if (wcscmp(pInfo
->lpProvider
, L
"Web Client Network") == 0)
87 *pRealURL
= UNCToDavURL(aReq
.lpRemoteName
);
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */