ucb/source/ucp/webdav-curl/CurlSession.cxx |   39 ++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

New commits:
commit 71963c56241cecc77a2bff5434f0a1cf759d744f
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Jan 17 19:07:52 2022 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue Jan 18 15:08:32 2022 +0100

    ucb: webdav-curl: add even more logging
    
    Some servers like to put error messages in the body if there's a
    problem, let's try to to dump that via SAL_INFO, unless it's too big.
    
    Change-Id: I9a29de59ab299f4bfda08ecc3be838972cf0c71d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128513
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit d32e7ddb6497c3b36b86589765790dbfc3de335e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128533
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx 
b/ucb/source/ucp/webdav-curl/CurlSession.cxx
index c30b0c775131..ee21e88fc44d 100644
--- a/ucb/source/ucp/webdav-curl/CurlSession.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx
@@ -1273,14 +1273,51 @@ auto CurlProcessor::ProcessRequest(
         }
 
         ResponseHeaders headers(rSession.m_pCurl.get());
+        uno::Reference<io::XSequenceOutputStream> xSeqOutStream;
+        uno::Reference<io::XOutputStream> xDebugOutStream;
+        if (!pxOutStream)
+        {
+            xSeqOutStream = 
io::SequenceOutputStream::create(rSession.m_xContext);
+            xDebugOutStream = xSeqOutStream;
+        }
 
         try
         {
-            ProcessRequestImpl(rSession, rURI, pRequestHeaderList.get(), 
pxOutStream,
+            ProcessRequestImpl(rSession, rURI, pRequestHeaderList.get(),
+                               pxOutStream ? pxOutStream : &xDebugOutStream,
                                pxInStream ? &data : nullptr, 
pRequestedHeaders, headers);
         }
         catch (DAVException const& rException)
         {
+            if (xDebugOutStream.is())
+            {
+                auto const bytes(xSeqOutStream->getWrittenBytes());
+                auto const len(::std::min<sal_Int32>(bytes.getLength(), 
10000));
+                SAL_INFO("ucb.ucp.webdav.curl",
+                         "DAVException; (first) " << len << " bytes of data 
received:");
+                if (0 < len)
+                {
+                    OStringBuffer buf(len);
+                    for (sal_Int32 i = 0; i < len; ++i)
+                    {
+                        if (bytes[i] < 0x20) // also if negative
+                        {
+                            static char const hexDigit[16]
+                                = { '0', '1', '2', '3', '4', '5', '6', '7',
+                                    '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+                            buf.append("\\x");
+                            
buf.append(hexDigit[static_cast<sal_uInt8>(bytes[i]) >> 4]);
+                            buf.append(hexDigit[bytes[i] & 0x0F]);
+                        }
+                        else
+                        {
+                            buf.append(static_cast<char>(bytes[i]));
+                        }
+                    }
+                    SAL_INFO("ucb.ucp.webdav.curl", buf.makeStringAndClear());
+                }
+            }
+
             // error handling part 3: special HTTP status codes
             // that require unlocking m_Mutex to handle
             if (rException.getError() == DAVException::DAV_HTTP_ERROR)

Reply via email to