ucb/source/ucp/webdav-curl/DAVTypes.cxx      |   46 +++++++--------------------
 ucb/source/ucp/webdav-curl/DAVTypes.hxx      |    7 ++--
 ucb/source/ucp/webdav-curl/webdavcontent.cxx |    6 +--
 3 files changed, 21 insertions(+), 38 deletions(-)

New commits:
commit 805a4e9d3e03e1339e9149fa745ac14fe334ccdf
Author:     Giuseppe Castagno <giuseppe.casta...@acca-esse.eu>
AuthorDate: Tue Oct 11 15:21:23 2016 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Nov 1 18:51:55 2021 +0100

    ucb: webdav-curl: tdf#102499 (6): Cache OPTIONS if not present or if 
lifetime different
    
    Add the OPTIONS information and response status code into the cache:
    - if the OPTIONS information is already cached, update the cache only
      if the lifetime is different;
    - if the OPTIONS information is not cached, cache it.
    
    Add some new functions in DAVOptions to support the change and remove
    a function no longer used.
    
    [ port of commit 1ca68d386bc0345240bf288bec023faaba2e07af ]
    
    Change-Id: I9c06e06ba807eff393052dc706cb45b2dfcef105
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123498
    Tested-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/ucb/source/ucp/webdav-curl/DAVTypes.cxx 
b/ucb/source/ucp/webdav-curl/DAVTypes.cxx
index d16b7bacc3bd..82be1807ed41 100644
--- a/ucb/source/ucp/webdav-curl/DAVTypes.cxx
+++ b/ucb/source/ucp/webdav-curl/DAVTypes.cxx
@@ -29,6 +29,7 @@ DAVOptions::DAVOptions() :
     m_isLocked( false ),
     m_aAllowedMethods(),
     m_nStaleTime( 0 ),
+    m_nRequestedTimeLife( 0 ),
     m_sURL(),
     m_sRedirectedURL(),
     m_nHttpResponseStatusCode( 0 ),
@@ -44,6 +45,7 @@ DAVOptions::DAVOptions( const DAVOptions & rOther ) :
     m_isLocked( rOther.m_isLocked ),
     m_aAllowedMethods( rOther.m_aAllowedMethods ),
     m_nStaleTime( rOther.m_nStaleTime ),
+    m_nRequestedTimeLife( rOther.m_nRequestedTimeLife ),
     m_sURL( rOther.m_sURL ),
     m_sRedirectedURL( rOther.m_sRedirectedURL),
     m_nHttpResponseStatusCode( rOther.m_nHttpResponseStatusCode ),
@@ -64,6 +66,7 @@ DAVOptions & DAVOptions::operator=( const DAVOptions& rOpts )
     m_isHeadAllowed = rOpts.m_isHeadAllowed;
     m_aAllowedMethods = rOpts.m_aAllowedMethods;
     m_nStaleTime = rOpts.m_nStaleTime;
+    m_nRequestedTimeLife = rOpts.m_nRequestedTimeLife;
     m_sURL = rOpts.m_sURL;
     m_sRedirectedURL = rOpts.m_sRedirectedURL;
     m_nHttpResponseStatusCode = rOpts.m_nHttpResponseStatusCode;
@@ -81,6 +84,7 @@ bool DAVOptions::operator==( const DAVOptions& rOpts ) const
         m_isHeadAllowed == rOpts.m_isHeadAllowed &&
         m_aAllowedMethods == rOpts.m_aAllowedMethods &&
         m_nStaleTime == rOpts.m_nStaleTime &&
+        m_nRequestedTimeLife == rOpts.m_nRequestedTimeLife &&
         m_sURL == rOpts.m_sURL &&
         m_sRedirectedURL == rOpts.m_sRedirectedURL &&
         m_nHttpResponseStatusCode == rOpts.m_nHttpResponseStatusCode &&
@@ -149,26 +153,6 @@ void DAVOptionsCache::addDAVOptions( DAVOptions & 
rDAVOptions, const sal_uInt32
     normalizeURLLastChar( aEncodedUrl );
     rDAVOptions.setURL( aEncodedUrl );
 
-// unchanged, it may be used to access a server
-    OUString aRedirURL( rDAVOptions.getRedirectedURL() );
-    rDAVOptions.setRedirectedURL( aRedirURL );
-
-    TimeValue t1;
-    osl_getSystemTime( &t1 );
-    rDAVOptions.setStaleTime( t1.Seconds + nLifeTime );
-
-    m_aTheCache[ aEncodedUrl ] = rDAVOptions;
-}
-
-void DAVOptionsCache::updateCachedOption( DAVOptions & rDAVOptions, const 
sal_uInt32 nLifeTime )
-{
-    osl::MutexGuard aGuard( m_aMutex );
-    OUString aURL( rDAVOptions.getURL() );
-
-    OUString aEncodedUrl( ucb_impl::urihelper::encodeURI( DecodeURI(aURL) ) );
-    normalizeURLLastChar( aEncodedUrl );
-    rDAVOptions.setURL( aEncodedUrl );
-
 // unchanged, it may be used to access a server
     OUString aRedirURL( rDAVOptions.getRedirectedURL() );
     rDAVOptions.setRedirectedURL( aRedirURL );
@@ -177,20 +161,16 @@ void DAVOptionsCache::updateCachedOption( DAVOptions & 
rDAVOptions, const sal_uI
     DAVOptionsMap::iterator it;
     it = m_aTheCache.find( aEncodedUrl );
     if ( it != m_aTheCache.end() )
-    {
-        DAVOptions &opts = (*it).second;
-        // exists, set new staletime, only if remaining time is higher
-        TimeValue t1;
-        osl_getSystemTime( &t1 );
-
-        if ( ( opts.getStaleTime() - t1.Seconds ) > nLifeTime )
-        {
-            opts.setStaleTime( t1.Seconds + nLifeTime );
-        }
-        // update relevant fields
-        opts.setHttpResponseStatusCode( 
rDAVOptions.getHttpResponseStatusCode() );
-        opts.setHttpResponseStatusText( 
rDAVOptions.getHttpResponseStatusText() );
+    { // already in cache, check LifeTime
+        if ( (*it).second.getRequestedTimeLife() == nLifeTime )
+            return; // same lifetime, do nothing
     }
+    // not in cache, add it
+    TimeValue t1;
+    osl_getSystemTime( &t1 );
+    rDAVOptions.setStaleTime( t1.Seconds + nLifeTime );
+
+    m_aTheCache[ aEncodedUrl ] = rDAVOptions;
 }
 
 sal_uInt16 DAVOptionsCache::getHttpResponseStatusCode( const OUString & rURL, 
OUString & rHttpResponseStatusText )
diff --git a/ucb/source/ucp/webdav-curl/DAVTypes.hxx 
b/ucb/source/ucp/webdav-curl/DAVTypes.hxx
index e6062649663f..77e9d630bc0c 100644
--- a/ucb/source/ucp/webdav-curl/DAVTypes.hxx
+++ b/ucb/source/ucp/webdav-curl/DAVTypes.hxx
@@ -79,6 +79,7 @@ namespace http_dav_ucp
 
         /// target time when this capability becomes stale
         sal_uInt32 m_nStaleTime;
+        sal_uInt32 m_nRequestedTimeLife;
         OUString  m_sURL;
         OUString  m_sRedirectedURL;
 
@@ -109,6 +110,9 @@ namespace http_dav_ucp
         sal_uInt32 getStaleTime() { return m_nStaleTime ; };
         void setStaleTime( const sal_uInt32 nStaleTime ) { m_nStaleTime = 
nStaleTime; };
 
+        sal_uInt32 getRequestedTimeLife() { return m_nRequestedTimeLife; };
+        void setRequestedTimeLife( const sal_uInt32 nRequestedTimeLife ) { 
m_nRequestedTimeLife = nRequestedTimeLife; };
+
         const OUString & getURL() { return m_sURL; };
         void setURL( const OUString & sURL ) { m_sURL = sURL; };
 
@@ -136,6 +140,7 @@ namespace http_dav_ucp
             m_isLocked = false;
             m_aAllowedMethods.clear();
             m_nStaleTime = 0;
+            m_nRequestedTimeLife = 0;
             m_sURL.clear();
             m_sRedirectedURL.clear();
             m_nHttpResponseStatusCode = 0;
@@ -165,8 +170,6 @@ namespace http_dav_ucp
         void removeDAVOptions( const OUString & rURL );
         void addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32 
nLifeTime );
 
-        void updateCachedOption( DAVOptions & rDAVOptions, const sal_uInt32 
nLifeTime );
-
         /** return the cached value of HTTP response status code
             If the cached value is found stale, it is removed.
 
diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.cxx 
b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
index 55a2e8fe35fe..7866ce132632 100644
--- a/ucb/source/ucp/webdav-curl/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
@@ -1467,7 +1467,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValues(
                         if ( aDAVOptions.getHttpResponseStatusCode() != 
SC_GONE &&
                              !aDAVOptions.isHeadAllowed() )
                         {
-                            throw DAVException( DAVException::DAV_HTTP_ERROR, 
"405 Not Implemented", 405 );
+                            throw DAVException( DAVException::DAV_HTTP_ERROR, 
"405 Not Implemented", SC_METHOD_NOT_ALLOWED );
                         }
                         // if HEAD is enabled on this site
                         // check if there is a relevant HTTP response status 
code cached
@@ -1552,8 +1552,8 @@ uno::Reference< sdbc::XRow > Content::getPropertyValues(
                                 aLastException.getStatus();
                             aDAVOptionsException.setHttpResponseStatusCode( 
ResponseStatusCode );
                             aDAVOptionsException.setHttpResponseStatusText( 
aLastException.getData() );
-                            aStaticDAVOptionsCache.updateCachedOption( 
aDAVOptionsException,
-                                                                       
m_nOptsCacheLifeNotFound );
+                            aStaticDAVOptionsCache.addDAVOptions( 
aDAVOptionsException,
+                                                                  
m_nOptsCacheLifeNotFound );
 
                             if ( !shouldAccessNetworkAfterException( 
aLastException ) )
                             {

Reply via email to