ucb/source/ucp/webdav-curl/CurlSession.cxx |   35 ++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 13 deletions(-)

New commits:
commit 8edbf6b1c8e7359f26a41ce6c5524d19eda05e08
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Nov 25 18:24:06 2021 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Nov 26 18:02:51 2021 +0100

    ucb: webdav-curl: don't use chunked encoding for LOCK
    
    Sharepoint 16 produces exactly the same error HTML as for PROPFIND.
    
    Change-Id: Idd3862456c4efbb9eb0533298dcd93711b30faae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125847
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit f50d0ca0978d8c6b8dff5ce680bce9fe71c0a7dd)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125846

diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx 
b/ucb/source/ucp/webdav-curl/CurlSession.cxx
index 679083603d9b..5ea645f4d4ee 100644
--- a/ucb/source/ucp/webdav-curl/CurlSession.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx
@@ -1977,8 +1977,19 @@ auto CurlProcessor::Lock(
     uno::Reference<io::XInputStream> const* const pxRequestInStream)
     -> ::std::vector<::std::pair<ucb::Lock, sal_Int32>>
 {
-    ::std::vector<CurlOption> const options{ { CURLOPT_CUSTOMREQUEST, "LOCK",
-                                               "CURLOPT_CUSTOMREQUEST" } };
+    curl_off_t len(0);
+    if (pxRequestInStream)
+    {
+        uno::Reference<io::XSeekable> const xSeekable(*pxRequestInStream, 
uno::UNO_QUERY);
+        assert(xSeekable.is());
+        len = xSeekable->getLength();
+    }
+
+    ::std::vector<CurlOption> const options{
+        { CURLOPT_CUSTOMREQUEST, "LOCK", "CURLOPT_CUSTOMREQUEST" },
+        // note: Sharepoint cannot handle "Transfer-Encoding: chunked"
+        { CURLOPT_INFILESIZE_LARGE, len, nullptr, CurlOption::Type::CurlOffT }
+    };
 
     // stream for response
     uno::Reference<io::XInputStream> const 
xResponseInStream(io::Pipe::create(rSession.m_xContext));
@@ -2044,9 +2055,9 @@ auto CurlSession::LOCK(OUString const& rURIReference, 
ucb::Lock /*const*/& rLock
     // note: no m_Mutex lock needed here, only in CurlProcessor::Lock()
 
     // generate XML document for acquiring new LOCK
-    uno::Reference<io::XInputStream> const 
xRequestInStream(io::Pipe::create(m_xContext));
-    uno::Reference<io::XOutputStream> const 
xRequestOutStream(xRequestInStream, uno::UNO_QUERY);
-    assert(xRequestInStream.is());
+    uno::Reference<io::XSequenceOutputStream> const xSeqOutStream(
+        io::SequenceOutputStream::create(m_xContext));
+    uno::Reference<io::XOutputStream> const xRequestOutStream(xSeqOutStream);
     assert(xRequestOutStream.is());
     uno::Reference<xml::sax::XWriter> const 
xWriter(xml::sax::Writer::create(m_xContext));
     xWriter->setOutputStream(xRequestOutStream);
@@ -2082,15 +2093,13 @@ auto CurlSession::LOCK(OUString const& rURIReference, 
ucb::Lock /*const*/& rLock
     }
     xWriter->endElement("lockinfo");
     xWriter->endDocument();
-    xRequestOutStream->closeOutput();
 
-    // TODO: either set CURLOPT_INFILESIZE_LARGE or chunked?
-    ::std::unique_ptr<curl_slist, deleter_from_fn<curl_slist, 
curl_slist_free_all>> pList(
-        curl_slist_append(nullptr, "Transfer-Encoding: chunked"));
-    if (!pList)
-    {
-        throw uno::RuntimeException("curl_slist_append failed");
-    }
+    uno::Reference<io::XInputStream> const xRequestInStream(
+        io::SequenceInputStream::createStreamFromSequence(m_xContext,
+                                                          
xSeqOutStream->getWrittenBytes()));
+    assert(xRequestInStream.is());
+
+    ::std::unique_ptr<curl_slist, deleter_from_fn<curl_slist, 
curl_slist_free_all>> pList;
     pList.reset(curl_slist_append(pList.release(), "Content-Type: 
application/xml"));
     if (!pList)
     {

Reply via email to