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 <o3tl/char16_t2wchar_t.hxx>
14 #define WIN32_LEAN_AND_MEAN
22 OUString
UNCToDavURL(LPCWSTR sUNC
)
25 auto bufURL(std::make_unique
<wchar_t[]>(nSize
));
26 DWORD nResult
= DavGetHTTPFromUNCPath(sUNC
, bufURL
.get(), &nSize
);
27 if (nResult
== ERROR_INSUFFICIENT_BUFFER
)
29 bufURL
= std::make_unique
<wchar_t[]>(nSize
);
30 nResult
= DavGetHTTPFromUNCPath(sUNC
, bufURL
.get(), &nSize
);
32 return nResult
== ERROR_SUCCESS
? o3tl::toU(bufURL
.get()) : OUString();
39 bool IsMappedWebDAVPath([[maybe_unused
]] const OUString
& rURL
, [[maybe_unused
]] OUString
* pRealURL
)
42 if (rURL
.startsWithIgnoreAsciiCase("file:"))
45 if (osl::FileBase::getSystemPathFromFileURL(rURL
, aSystemPath
) == osl::FileBase::E_None
)
47 DWORD nSize
= MAX_PATH
;
48 auto bufUNC(std::make_unique
<char[]>(nSize
));
49 DWORD nResult
= WNetGetUniversalNameW(o3tl::toW(aSystemPath
.getStr()),
50 UNIVERSAL_NAME_INFO_LEVEL
, bufUNC
.get(), &nSize
);
51 if (nResult
== ERROR_MORE_DATA
)
53 bufUNC
= std::make_unique
<char[]>(nSize
);
54 nResult
= WNetGetUniversalNameW(o3tl::toW(aSystemPath
.getStr()),
55 UNIVERSAL_NAME_INFO_LEVEL
, bufUNC
.get(), &nSize
);
57 if (nResult
== NO_ERROR
|| nResult
== ERROR_BAD_DEVICE
)
60 if (nResult
== ERROR_BAD_DEVICE
) // The path could already be an UNC
61 aReq
.lpRemoteName
= const_cast<LPWSTR
>(o3tl::toW(aSystemPath
.getStr()));
64 auto pInfo
= reinterpret_cast<LPUNIVERSAL_NAME_INFOW
>(bufUNC
.get());
65 aReq
.lpRemoteName
= pInfo
->lpUniversalName
;
68 auto bufInfo(std::make_unique
<char[]>(nSize
));
69 LPWSTR pSystem
= nullptr;
70 nResult
= WNetGetResourceInformationW(&aReq
, bufInfo
.get(), &nSize
, &pSystem
);
71 if (nResult
== ERROR_MORE_DATA
)
73 bufInfo
= std::make_unique
<char[]>(nSize
);
74 nResult
= WNetGetResourceInformationW(&aReq
, bufInfo
.get(), &nSize
, &pSystem
);
76 if (nResult
== NO_ERROR
)
78 LPNETRESOURCEW pInfo
= reinterpret_cast<LPNETRESOURCEW
>(bufInfo
.get());
79 if (wcscmp(pInfo
->lpProvider
, L
"Web Client Network") == 0)
82 *pRealURL
= UNCToDavURL(aReq
.lpRemoteName
);
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */