ucb/source/ucp/webdav-curl/webdavcontent.cxx |   47 ++++++++++++++++-----------
 1 file changed, 28 insertions(+), 19 deletions(-)

New commits:
commit 11a457538a300d8df0c5c03d3cb590e94e6d99fa
Author:     Giuseppe Castagno <[email protected]>
AuthorDate: Fri Dec 4 17:10:06 2015 +0100
Commit:     Michael Stahl <[email protected]>
CommitDate: Mon Nov 1 18:28:03 2021 +0100

    ucb: webdav-curl: tdf#95792: fix saving file the first time on some WebDAV 
servers.
    
    Some WebDAV servers don't implement section 7.3 of RFC4918:
    <http://tools.ietf.org/html/rfc4918#section-7.3>
    
    This lack of implementation breaks 'Save As...' functionality
    when the target is a WebDAV server, by not locking the URL
    ('reserve the name for use', in RFC4918 parlance).
    
    The server not implementing this usually answers with one of
    '405 Method Not Allowed', '501 Not Implemented' or
    '412 Precondition Failed' http error codes.
    
    The fix should manage this lack of implementation.
    
    [ port of commit 4c82edfb3a9286a0bfef3f006e468e5c331987eb ]
    
    Change-Id: I343368bb91bdffff143aa26d8449b48f3b5300d8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123275
    Tested-by: Michael Stahl <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.cxx 
b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
index e579a30c517c..e2ed80e3c5ed 100644
--- a/ucb/source/ucp/webdav-curl/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
@@ -2888,16 +2888,16 @@ Content::ResourceType Content::resourceTypeForLocks(
                                   << m_xIdentifier->getContentIdentifier() << 
"> was not found. ");
                         eResourceTypeForLocks = NOT_FOUND;
                         break;
-                        // some servers returns this, instead
+                        // some servers returns SC_FORBIDDEN, instead
                         // TODO: probably remove it, when OPTIONS implemented
-                        // the meaning of SC_FORBIDDEN is, according to 
http://tools.ietf.org/html/rfc7231#section-6.5.3
+                        // the meaning of SC_FORBIDDEN is, according to 
<http://tools.ietf.org/html/rfc7231#section-6.5.3>:
                         // The 403 (Forbidden) status code indicates that the 
server understood
                         // the request but refuses to authorize it
                     case SC_FORBIDDEN:
-                        // this returned errors are part of base http 1.1 RFCs
-                        // see:
-                    case SC_NOT_IMPLEMENTED:    // 
http://tools.ietf.org/html/rfc7231#section-6.6.2
-                    case SC_METHOD_NOT_ALLOWED: // 
http://tools.ietf.org/html/rfc7231#section-6.5.5
+                        // Errors SC_NOT_IMPLEMENTED and SC_METHOD_NOT_ALLOWED 
are
+                        // part of base http 1.1 RFCs
+                    case SC_NOT_IMPLEMENTED:        // 
<http://tools.ietf.org/html/rfc7231#section-6.6.2>
+                    case SC_METHOD_NOT_ALLOWED:     // 
<http://tools.ietf.org/html/rfc7231#section-6.5.5>
                         // they all mean the resource is NON_DAV
                         SAL_WARN( "ucb.ucp.webdav", "resourceTypeForLocks() 
DAVException (SC_FORBIDDEN, SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: 
<"
                                   << m_xIdentifier->getContentIdentifier() << 
">, DAV error: " << e.getError() << ", HTTP error: " << e.getStatus() );
@@ -3001,7 +3001,7 @@ void Content::lock(
             {
                 SAL_WARN( "ucb.ucp.webdav", "lock(): DAVException 
Authentication error - URL: <"
                           << m_xIdentifier->getContentIdentifier() << ">" );
-                // this could mean:
+                // DAVException::DAV_HTTP_AUTH exception can mean:
                 // - interaction handler for credential management not present 
(happens, depending
                 //   on the LO framework processing)
                 // - the remote site is a WebDAV with special configuration: 
read/only for read operations
@@ -3023,20 +3023,28 @@ void Content::lock(
                 //grab the error code
                 switch( e.getStatus() )
                 {
-                    // this returned error is part of base http 1.1 RFCs
-                    case SC_NOT_IMPLEMENTED:
-                    case SC_METHOD_NOT_ALLOWED:
-                        SAL_WARN( "ucb.ucp.webdav", "lock() DAVException 
(SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: <"
+                    // The 'case SC_PRECONDITION_FAILED' just below tries to 
solve a problem
+                    // in SharePoint when locking the resource on first 
creation fails due to this:
+                    // 
<https://msdn.microsoft.com/en-us/library/jj575265%28v=office.12%29.aspx#id15>
+                    // (retrieved on 2015-08-14)
+                    case SC_PRECONDITION_FAILED:    // 
<http://tools.ietf.org/html/rfc7232#section-4.2>
+                        // Errors SC_NOT_IMPLEMENTED and SC_METHOD_NOT_ALLOWED 
are
+                        // part of base http 1.1 RFCs
+                    case SC_NOT_IMPLEMENTED:        // 
<http://tools.ietf.org/html/rfc7231#section-6.6.2>
+                    case SC_METHOD_NOT_ALLOWED:     // 
<http://tools.ietf.org/html/rfc7231#section-6.5.5>
+                        SAL_WARN( "ucb.ucp.webdav", "lock() DAVException 
(SC_PRECONDITION_FAILED, SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: <"
                                   << m_xIdentifier->getContentIdentifier() << 
">, DAV error: " << e.getError() << ", HTTP error: " << e.getStatus() );
                         // act as nothing happened
                         // that's because when a resource is first created
                         // the lock is sent before the put, so the resource
                         // is actually created by LOCK, locking it before
-                        // doing the first PUT, but if LOCK is not supported
-                        // (simple web or DAV with lock disabled) we end with 
one of these two http
-                        // errors
-                        // details to LOCK on an unmapped (i.e. non existent) 
resource are in:
-                        // http://tools.ietf.org/html/rfc4918#section-7.3
+                        // the first PUT, but if LOCK is not supported
+                        // (simple web or DAV with lock disabled) we end with 
one of these http
+                        // errors.
+                        // These same errors may be reported when the LOCK on 
an unmapped
+                        // (i.e. non existent) resource is not implemented.
+                        // Detailed specification in:
+                        // <http://tools.ietf.org/html/rfc4918#section-7.3>
                         return;
                         break;
                     default:
@@ -3098,9 +3106,10 @@ void Content::unlock(
                 //grab the error code
                 switch( e.getStatus() )
                 {
-                    // this returned error is part of base http 1.1 RFCs
-                    case SC_NOT_IMPLEMENTED:
-                    case SC_METHOD_NOT_ALLOWED:
+                    // Errors SC_NOT_IMPLEMENTED and SC_METHOD_NOT_ALLOWED are
+                    // part of base http 1.1 RFCs
+                    case SC_NOT_IMPLEMENTED:        // 
<http://tools.ietf.org/html/rfc7231#section-6.6.2>
+                    case SC_METHOD_NOT_ALLOWED:     // 
<http://tools.ietf.org/html/rfc7231#section-6.5.5>
                         SAL_WARN( "ucb.ucp.webdav", "unlock() DAVException 
(SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: <"
                                   << m_xIdentifier->getContentIdentifier() << 
">, DAV error: " << e.getError() << ", HTTP error: " << e.getStatus() );
                         return;

Reply via email to