[Libreoffice-commits] core.git: sfx2/source ucb/source

Giuseppe Castagno giuseppe.castagno at acca-esse.eu
Tue Dec 15 06:26:41 PST 2015


 sfx2/source/doc/docfile.cxx                  |   30 ++++++++++++++++-
 ucb/source/ucp/webdav-neon/NeonSession.cxx   |    2 -
 ucb/source/ucp/webdav-neon/webdavcontent.cxx |   47 ++++++++++++++++-----------
 3 files changed, 57 insertions(+), 22 deletions(-)

New commits:
commit 4c82edfb3a9286a0bfef3f006e468e5c331987eb
Author: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>
Date:   Fri Dec 4 17:10:06 2015 +0100

    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.
    
    Change-Id: Ie4689a076aafa365106d02b3ea16459a28fcde65
    Reviewed-on: https://gerrit.libreoffice.org/20600
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 94633e6..a9a5df0 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -2083,11 +2083,37 @@ void SfxMedium::Transfer_Impl()
                             sComment = pComments->GetValue( );
                     }
                     OUString sResultURL;
-                    if (!aTransferContent.transferContent( aSourceContent, eOperation,
-                                aFileName, nNameClash, aMimeType, bMajor, sComment, &sResultURL, sObjectId))
+                    bool isTransferOK = aTransferContent.transferContent(
+                        aSourceContent, eOperation,
+                        aFileName, nNameClash, aMimeType, bMajor, sComment,
+                        &sResultURL, sObjectId );
+
+                    if ( !isTransferOK )
                         pImp->m_eError = ERRCODE_IO_GENERAL;
                     else if ( !sResultURL.isEmpty( ) )  // Likely to happen only for checkin
                         SwitchDocumentToFile( sResultURL );
+                    try
+                    {
+                        if ( GetURLObject().isAnyKnownWebDAVScheme() &&
+                             isTransferOK &&
+                             eOperation == ::ucbhelper::InsertOperation_COPY )
+                        {
+                            // tdf#95272 try to re-issue a lock command when a new file is created.
+                            // This may be needed because some WebDAV servers fail to implement the
+                            // 'LOCK on unallocated reference', see issue comment:
+                            // <https://bugs.documentfoundation.org/show_bug.cgi?id=95792#c8>
+                            // and specification at:
+                            // <http://tools.ietf.org/html/rfc4918#section-7.3>
+                            // If the WebDAV resource is already locked by this LO instance, nothing will
+                            // happen, e.g. the LOCK method will not be sent to the server.
+                            ::ucbhelper::Content aLockContent = ::ucbhelper::Content( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xComEnv, comphelper::getProcessComponentContext() );
+                            aLockContent.lock();
+                        }
+                    }
+                    catch ( css::uno::Exception & e )
+                    {
+                        SAL_WARN( "sfx.doc", "LOCK not working while re-issuing it. Exception message: " << e.Message );
+                    }
                 }
                 catch ( const css::ucb::CommandAbortedException& )
                 {
diff --git a/ucb/source/ucp/webdav-neon/NeonSession.cxx b/ucb/source/ucp/webdav-neon/NeonSession.cxx
index 56a2837..61b3ce9 100644
--- a/ucb/source/ucp/webdav-neon/NeonSession.cxx
+++ b/ucb/source/ucp/webdav-neon/NeonSession.cxx
@@ -596,7 +596,7 @@ NeonSession::NeonSession( const rtl::Reference< DAVSessionFactory > & rSessionFa
     m_aScheme    = theUri.GetScheme();
     m_aHostName  = theUri.GetHost();
     m_nPort      = theUri.GetPort();
-    SAL_INFO( "ucb.ucp.webdav", "NeonSession ctor - URL < " << inUri << ">" );
+    SAL_INFO( "ucb.ucp.webdav", "NeonSession ctor - URL <" << inUri << ">" );
 }
 
 NeonSession::~NeonSession( )
diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
index dfcf7eb..98d56e13 100644
--- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
@@ -2872,16 +2872,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() );
@@ -2986,7 +2986,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
@@ -3008,20 +3008,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:
@@ -3084,9 +3092,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;


More information about the Libreoffice-commits mailing list