From 7110271f6a47dd19648864ad9e83e87a90f2d4fd Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 22 Oct 2021 19:34:55 +0200 Subject: ucb: webdav-curl: clean up CurlUri m_Path mess Fix the confused nonsense and add GetRelativeReference() for the cases where the path+query+fragment is needed. Change-Id: I663d20a686dcc787171ae7702d2a64451fa53807 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124078 Tested-by: Jenkins Reviewed-by: Michael Stahl --- ucb/source/ucp/webdav-curl/CurlUri.cxx | 21 ++++++--------------- ucb/source/ucp/webdav-curl/CurlUri.hxx | 3 ++- ucb/source/ucp/webdav-curl/DAVResourceAccess.cxx | 2 +- ucb/source/ucp/webdav-curl/webdavcontent.cxx | 6 +++--- ucb/source/ucp/webdav-curl/webdavdatasupplier.cxx | 2 +- 5 files changed, 13 insertions(+), 21 deletions(-) (limited to 'ucb') diff --git a/ucb/source/ucp/webdav-curl/CurlUri.cxx b/ucb/source/ucp/webdav-curl/CurlUri.cxx index 1c596dfcd299..44bbd806f267 100644 --- a/ucb/source/ucp/webdav-curl/CurlUri.cxx +++ b/ucb/source/ucp/webdav-curl/CurlUri.cxx @@ -89,16 +89,16 @@ void CurlUri::Init() assert(oPath); m_Path = *oPath; - // TODO: why put this in *path* ? because before 2007, ne_uri path contained query/fragment as well :-/ + // note: this used to be added to m_Path because before 2007, ne_uri path contained query/fragment as well :-/ auto const oQuery(GetURLComponent(*m_pUrl, CURLUPART_QUERY, CURLUE_NO_QUERY)); if (oQuery) { - m_Path += *oQuery; + m_QueryAndFragment += *oQuery; } auto const oFragment(GetURLComponent(*m_pUrl, CURLUPART_FRAGMENT, CURLUE_NO_FRAGMENT)); if (oFragment) { - m_Path += *oFragment; + m_QueryAndFragment += *oFragment; } } @@ -146,6 +146,7 @@ CurlUri::CurlUri(CurlUri const& rOther) , m_Host(rOther.m_Host) , m_nPort(rOther.m_nPort) , m_Path(rOther.m_Path) + , m_QueryAndFragment(rOther.m_QueryAndFragment) { assert(rOther.m_pUrl); if (!m_pUrl) @@ -169,6 +170,7 @@ void CurlUri::operator=(CurlUri const& rOther) m_Host = rOther.m_Host; m_nPort = rOther.m_nPort; m_Path = rOther.m_Path; + m_QueryAndFragment = rOther.m_QueryAndFragment; } bool CurlUri::operator==(CurlUri const& rOther) const { return m_URI == rOther.m_URI; } @@ -187,17 +189,7 @@ OUString CurlUri::GetPathBaseName() const { return "/"; } - OUString aTemp(m_Path.copy(nPos + 1, m_Path.getLength() - nPos - 1 - nTrail)); - - // query, fragment present? - nPos = aTemp.indexOf('?'); - if (nPos == -1) - nPos = aTemp.indexOf('#'); - - if (nPos != -1) - aTemp = aTemp.copy(0, nPos); - - return aTemp; + return m_Path.copy(nPos + 1, m_Path.getLength() - nPos - 1 - nTrail); } OUString CurlUri::GetPathBaseNameUnescaped() const { return DecodeURI(GetPathBaseName()); } @@ -224,7 +216,6 @@ void CurlUri::SetScheme(::std::u16string_view const rScheme) void CurlUri::AppendPath(::std::u16string_view const rPath) { OUStringBuffer path(m_Path); - // FIXME: it is utter nonsense that m_Path contains query/fragment if (path.lastIndexOf('/') != path.getLength() - 1) { path.append("/"); diff --git a/ucb/source/ucp/webdav-curl/CurlUri.hxx b/ucb/source/ucp/webdav-curl/CurlUri.hxx index 4071991c904e..2c7980176718 100644 --- a/ucb/source/ucp/webdav-curl/CurlUri.hxx +++ b/ucb/source/ucp/webdav-curl/CurlUri.hxx @@ -44,8 +44,8 @@ private: OUString m_Password; OUString m_Host; sal_uInt16 m_nPort = 0; - /// FIXME very misleading OUString m_Path; + OUString m_QueryAndFragment; void Init(); @@ -67,6 +67,7 @@ public: OUString const& GetHost() const { return m_Host; } sal_uInt16 GetPort() const { return m_nPort; } OUString const& GetPath() const { return m_Path; } + OUString GetRelativeReference() const { return m_Path + m_QueryAndFragment; } OUString GetPathBaseName() const; diff --git a/ucb/source/ucp/webdav-curl/DAVResourceAccess.cxx b/ucb/source/ucp/webdav-curl/DAVResourceAccess.cxx index 291f0d580b8d..a6bfd7d79642 100644 --- a/ucb/source/ucp/webdav-curl/DAVResourceAccess.cxx +++ b/ucb/source/ucp/webdav-curl/DAVResourceAccess.cxx @@ -1022,7 +1022,7 @@ void DAVResourceAccess::initialize() if ( m_aPath.isEmpty() ) { CurlUri const aURI( m_aURL ); - OUString aPath( aURI.GetPath() ); + OUString aPath( aURI.GetRelativeReference() ); /* #134089# - Check URI */ if ( aPath.isEmpty() ) diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.cxx b/ucb/source/ucp/webdav-curl/webdavcontent.cxx index 1fadd4560331..dc9b373ed5b1 100644 --- a/ucb/source/ucp/webdav-curl/webdavcontent.cxx +++ b/ucb/source/ucp/webdav-curl/webdavcontent.cxx @@ -2061,7 +2061,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues( aStaticDAVOptionsCache.removeDAVOptions( sourceURI.GetURI() ); aStaticDAVOptionsCache.removeDAVOptions( targetURI.GetURI() ); xResAccess->MOVE( - sourceURI.GetPath(), targetURI.GetURI(), false, xEnv ); + sourceURI.GetRelativeReference(), targetURI.GetURI(), false, xEnv ); // @@@ Should check for resources that could not be moved // (due to source access or target overwrite) and send @@ -2861,7 +2861,7 @@ void Content::transfer( aStaticDAVOptionsCache.removeDAVOptions( sourceURI.GetURI() ); aStaticDAVOptionsCache.removeDAVOptions( targetURI.GetURI() ); - aSourceAccess.MOVE( sourceURI.GetPath(), + aSourceAccess.MOVE( sourceURI.GetRelativeReference(), targetURI.GetURI(), rArgs.NameClash == ucb::NameClash::OVERWRITE, @@ -2890,7 +2890,7 @@ void Content::transfer( aStaticDAVOptionsCache.removeDAVOptions( sourceURI.GetURI() ); aStaticDAVOptionsCache.removeDAVOptions( targetURI.GetURI() ); - aSourceAccess.COPY( sourceURI.GetPath(), + aSourceAccess.COPY( sourceURI.GetRelativeReference(), targetURI.GetURI(), rArgs.NameClash == ucb::NameClash::OVERWRITE, diff --git a/ucb/source/ucp/webdav-curl/webdavdatasupplier.cxx b/ucb/source/ucp/webdav-curl/webdavdatasupplier.cxx index d7213a0d13ee..d97e6ce3e320 100644 --- a/ucb/source/ucp/webdav-curl/webdavdatasupplier.cxx +++ b/ucb/source/ucp/webdav-curl/webdavdatasupplier.cxx @@ -68,7 +68,7 @@ auto DumpResources(std::vector const& rResources) -> OUString try { CurlUri const uri(rResource.uri); buf.append("> parsed URL: <"); - buf.append(DecodeURI(uri.GetPath())); + buf.append(DecodeURI(uri.GetRelativeReference())); buf.append("> "); } catch (...) { // parsing uri could fail -- cgit