24#include <rtl/ustrbuf.hxx>
33static ::std::optional<OUString>
GetURLComponent(CURLU& rURI, CURLUPart
const what,
34 CURLUcode
const expected,
35 unsigned int const flags = 0)
38 auto uc = curl_url_get(&rURI, what, &pPart, flags);
39 if (expected != CURLUE_OK && uc == expected)
41 return ::std::optional<OUString>();
45 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_get failed: " << what <<
" " << uc);
50 return ::rtl::OStringToOUString(pPart, RTL_TEXTENCODING_UTF8);
114 throw ::std::bad_alloc();
118 if (rURI.find(
u'\0') != std::u16string_view::npos)
123 auto uc = curl_url_set(
m_pUrl.get(), CURLUPART_URL, utf8URI.getStr(), 0);
126 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_set failed: " << uc);
134 : m_pUrl(curl_url_dup(&rUrl))
138 throw ::std::bad_alloc();
145 : m_pUrl(curl_url_dup(rOther.m_pUrl.
get()))
146 , m_URI(rOther.m_URI)
147 , m_Scheme(rOther.m_Scheme)
148 , m_User(rOther.m_User)
149 , m_Password(rOther.m_Password)
150 , m_Host(rOther.m_Host)
151 , m_nPort(rOther.m_nPort)
152 , m_Path(rOther.m_Path)
153 , m_QueryAndFragment(rOther.m_QueryAndFragment)
158 throw ::std::bad_alloc();
168 throw ::std::bad_alloc();
185 sal_Int32 nTrail = 0;
204 auto uc = curl_url_set(
m_pUrl.get(), CURLUPART_SCHEME, utf8URI.getStr(), 0);
207 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_set failed: " << uc);
222 OUStringBuffer path(
m_Path);
223 if (path.lastIndexOf(
'/') != path.getLength() - 1)
229 auto uc = curl_url_set(
m_pUrl.get(), CURLUPART_PATH, utf8Path.getStr(), 0);
232 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_set failed: " << uc);
245 ::std::unique_ptr<CURLU, deleter_from_fn<CURLU, curl_url_cleanup>> pUrl(
246 curl_url_dup(
m_pUrl.get()));
247 size_t indexEnd(rRelativeRef.size());
248 auto const indexQuery(rRelativeRef.find(
'?'));
249 auto const indexFragment(rRelativeRef.find(
'#'));
251 if (indexFragment != std::u16string_view::npos)
253 std::u16string_view
const fragment(rRelativeRef.substr(indexFragment + 1));
254 indexEnd = indexFragment;
256 uc = curl_url_set(pUrl.get(), CURLUPART_FRAGMENT, utf8Fragment.getStr(), 0);
260 uc = curl_url_set(pUrl.get(), CURLUPART_FRAGMENT,
nullptr, 0);
264 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_set failed: " << uc);
267 if (indexQuery != std::u16string_view::npos
268 && (indexFragment == std::u16string_view::npos || indexQuery < indexFragment))
270 std::u16string_view
const query(
271 rRelativeRef.substr(indexQuery + 1, indexEnd - indexQuery - 1));
272 indexEnd = indexQuery;
274 uc = curl_url_set(pUrl.get(), CURLUPART_QUERY, utf8Query.getStr(), 0);
278 uc = curl_url_set(pUrl.get(), CURLUPART_QUERY,
nullptr, 0);
282 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_set failed: " << uc);
285 std::u16string_view
const path(rRelativeRef.substr(0, indexEnd));
287 uc = curl_url_set(pUrl.get(), CURLUPART_PATH, utf8Path.getStr(), 0);
290 SAL_WARN(
"ucb.ucp.webdav.curl",
"curl_url_set failed: " << uc);
293 return CurlUri(*pUrl.release());
298 return rtl::Uri::encode(rSegment, rtl_UriCharClassPchar, rtl_UriEncodeIgnoreEscapes,
299 RTL_TEXTENCODING_UTF8);
304 return rtl::Uri::decode(rURI, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
312 if ((rHostName.find(
':') != std::u16string_view::npos) && (rHostName[0] !=
'['))
314 aBuf.append(OUString::Concat(
"[") + rHostName +
"]");
318 aBuf.append(rHostName);
323 aBuf.append(
":" + OUString::number(sal_Int32(nPort)));
325 return aBuf.makeStringAndClear();
CurlUri CloneWithRelativeRefPathAbsolute(std::u16string_view rRelativeRef) const
OUString GetPathBaseName() const
void SetScheme(::std::u16string_view rScheme)
CurlUri(CurlUri const &rUri)
::std::unique_ptr< CURLU, deleter_from_fn< CURLU, curl_url_cleanup > > m_pUrl
native curl representation of parsed URI
OUString m_QueryAndFragment
OUString m_URI
duplicate state for quick access to some components
bool operator==(CurlUri const &rOther) const
void operator=(CurlUri const &rOther)
OUString GetPathBaseNameUnescaped() const
void AppendPath(::std::u16string_view rPath)
#define SAL_WARN(area, stream)
OUString DecodeURI(OUString const &rURI)
const auto DEFAULT_HTTP_PORT
static ::std::optional< OUString > GetURLComponent(CURLU &rURI, CURLUPart const what, CURLUcode const expected, unsigned int const flags=0)
::std::unique_ptr< T, deleter_from_fn< T, curl_free > > CurlUniquePtr
OUString EncodeSegment(OUString const &rSegment)
OUString ConnectionEndPointString(std::u16string_view rHostName, sal_uInt16 const nPort)
const auto DEFAULT_HTTPS_PORT
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
store_handle_type *SAL_CALL query(OStoreObject *pHandle, store_handle_type *)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)