ucb: webdav-curl: tdf#101094 (29) Fix for IIS 10.0 disabled OPTIONS method

When OPTIONS methods (or verb) is disabled (or denied) on a IIS 10.0
web server, error 404 (e.g. 'Not Found') is emitted, so we need to deal
with it.

[ port of commit e0d0d87257d62ac61377a73909e17753f96e7aaa ]

Change-Id: I67309f1bce20bba1399a9a3c22568291d095ac69
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123484
Tested-by: Michael Stahl <michael.stahl@allotropia.de>
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.cxx b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
index 237c518..b96a58b 100644
--- a/ucb/source/ucp/webdav-curl/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
@@ -3965,8 +3965,17 @@ void Content::getResourceOptions(
                        break;
                        case SC_NOT_FOUND:
                        {
                            // Apparently on IIS 10.0, if you disabled OPTIONS method, this error is the one reported,
                            // instead of SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED.
                            // So check if this is an available resource, or a real 'Not Found' event.
                            sal_uInt32 nLifeTime = m_nOptsCacheLifeNotFound;
                            if( isResourceAvailable(xEnv, rResAccess ) )
                            {
                                nLifeTime = m_nOptsCacheLifeNotImpl;
                                rDAVOptions.setResourceFound(); // means it exists, but it's not DAV
                            }
                            aStaticDAVOptionsCache.addDAVOptions( rDAVOptions,
                                                                  m_nOptsCacheLifeNotFound );
                                                                  nLifeTime );
                            SAL_WARN( "ucb.ucp.webdav", "OPTIONS - Resource not found for URL <" << m_xIdentifier->getContentIdentifier() << ">" );
                        }
                        break;
@@ -4015,4 +4024,27 @@ void Content::getResourceOptions(
}


//static
bool Content::isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
                                  const std::unique_ptr< DAVResourceAccess > & rResAccess )
{
    try
    {
        // To check for the physical URL resource availability, using a simple HEAD command
        // if HEAD is successfull, set element found.
        std::vector< OUString > aHeaderNames;
        DAVResource resource;
        rResAccess->HEAD( aHeaderNames, resource, xEnv );
        return true;
    }
    catch ( ... )
    {
        // some error... so set as not found
        // retry errors are taken care of
        // in rResAccess function method.
        return false;
    }
}


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.hxx b/ucb/source/ucp/webdav-curl/webdavcontent.hxx
index f00b826..f854cc2 100644
--- a/ucb/source/ucp/webdav-curl/webdavcontent.hxx
+++ b/ucb/source/ucp/webdav-curl/webdavcontent.hxx
@@ -296,6 +296,9 @@ public:
    void getResourceOptions( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
                             DAVOptions& rDAVOptions );

    static bool isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
                             const std::unique_ptr< DAVResourceAccess > & rResAccess);

    static void removeCachedPropertyNames( const OUString & rURL );
};