tdf#101094 (13) OPTIONS: Options cache removal: LOCK, UNLOCK

Change-Id: Ib5e52973252b3af7b0fbe440806eb1e669670299
Reviewed-on: https://gerrit.libreoffice.org/27686
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Giuseppe Castagno <giuseppe.castagno@acca-esse.eu>
This commit is contained in:
Giuseppe Castagno
2016-07-24 12:12:35 +02:00
parent 5cf5975cef
commit dfb714183f
5 changed files with 55 additions and 1 deletions

View File

@@ -58,6 +58,7 @@ namespace
CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass1() );
CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass2() );
CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass3() );
CPPUNIT_ASSERT_EQUAL( false, aDavType.isLocked() );
CPPUNIT_ASSERT_EQUAL( true, aDavType.getAllowedMethods().isEmpty() );
CPPUNIT_ASSERT_EQUAL( false, aDavType.isLockAllowed() );
CPPUNIT_ASSERT_EQUAL( true, aDavType.getURL().isEmpty() );
@@ -191,6 +192,7 @@ namespace
CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() );
CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() );
CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() );
CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLocked() );
CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() );
CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() );
CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() );
@@ -204,6 +206,7 @@ namespace
aDavOpt.setClass1();
aDavOpt.setClass2();
aDavOpt.setClass3();
aDavOpt.setLocked();
aDavOpt.setAllowedMethods( aAllowedMethods );
aDavOpt.setStaleTime( 1234567 );
aDavOpt.setURL( aURL );
@@ -230,6 +233,11 @@ namespace
aDavOpt.setClass3( false );
CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget );
aDavOpt.setLocked();
CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget );
aDavOpt.setLocked( false );
CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget );
aDavOpt.setResourceFound();
CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget );
aDavOpt.setResourceFound( false );

View File

@@ -24,6 +24,7 @@ DAVOptions::DAVOptions() :
m_isClass1( false ),
m_isClass2( false ),
m_isClass3( false ),
m_isLocked( false ),
m_aAllowedMethods(),
m_nStaleTime( 0 ),
m_sURL(),
@@ -37,6 +38,7 @@ DAVOptions::DAVOptions( const DAVOptions & rOther ) :
m_isClass1( rOther.m_isClass1 ),
m_isClass2( rOther.m_isClass2 ),
m_isClass3( rOther.m_isClass3 ),
m_isLocked( rOther.m_isLocked ),
m_aAllowedMethods( rOther.m_aAllowedMethods ),
m_nStaleTime( rOther.m_nStaleTime ),
m_sURL( rOther.m_sURL ),
@@ -57,6 +59,7 @@ bool DAVOptions::operator==( const DAVOptions& rOpts ) const
m_isClass1 == rOpts.m_isClass1 &&
m_isClass2 == rOpts.m_isClass2 &&
m_isClass3 == rOpts.m_isClass3 &&
m_isLocked == rOpts.m_isLocked &&
m_aAllowedMethods == rOpts.m_aAllowedMethods &&
m_nStaleTime == rOpts.m_nStaleTime &&
m_sURL == rOpts.m_sURL &&

View File

@@ -81,6 +81,9 @@ namespace webdav_ucp
bool m_isClass1;
bool m_isClass2;
bool m_isClass3;
// Internally used to maintain locked stated of the resource, only
// if it's a Class 2 resource
bool m_isLocked;
// contains the methods allowed on this resource
OUString m_aAllowedMethods;
@@ -122,11 +125,15 @@ namespace webdav_ucp
bool isLockAllowed() { return ( m_aAllowedMethods.indexOf( "LOCK" ) != -1 ); };
bool isUnlockAllowed() { return ( m_aAllowedMethods.indexOf( "UNLOCK" ) != -1 ); };
void setLocked( bool locked = true ) { m_isLocked = locked; } ;
bool isLocked() { return m_isLocked; };
void reset() {
m_isResourceFound = false;
m_isClass1 = false;
m_isClass2 = false;
m_isClass3 = false;
m_isLocked = false;
m_aAllowedMethods.clear();
m_nStaleTime = 0;
m_sURL.clear();

View File

@@ -939,6 +939,18 @@ void NeonSession::OPTIONS( const OUString & inPath,
}
}
rOptions.setResourceFound();
// if applicable, check for lock state:
if( rOptions.isClass2() || rOptions.isClass3() )
{
//dav with lock possible, check for locked state
if ( m_aNeonLockStore.findByUri(
makeAbsoluteURL( inPath ) ) != nullptr )
{
// we own a lock for this URL,
// set locked state
rOptions.setLocked();
}
}
}
ne_request_destroy(req);

View File

@@ -3035,6 +3035,8 @@ void Content::lock(
aURL = m_xIdentifier->getContentIdentifier();
}
OUString aTargetUrl = aURL;
try
{
std::unique_ptr< DAVResourceAccess > xResAccess;
@@ -3056,7 +3058,12 @@ void Content::lock(
//-1, // infinite lock
uno::Sequence< OUString >() );
// update the URL
aTargetUrl = xResAccess->getURL();
xResAccess->LOCK( aLock, Environment );
// OPTIONS may have changed as a consequence of the lock operation
aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
@@ -3065,6 +3072,7 @@ void Content::lock(
}
catch ( DAVException const & e )
{
aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
// check if the exception thrown is 'already locked'
// this exception is mapped directly to the ucb correct one, without
// going into the cancelCommandExecution() user interaction
@@ -3161,6 +3169,9 @@ void Content::unlock(
const uno::Reference< ucb::XCommandEnvironment >& Environment )
throw( uno::Exception, std::exception )
{
// save the URL to clean cache
OUString aTargetUrl = m_xIdentifier->getContentIdentifier();
try
{
std::unique_ptr< DAVResourceAccess > xResAccess;
@@ -3169,7 +3180,12 @@ void Content::unlock(
xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
}
// update the URL
aTargetUrl = xResAccess->getURL();
xResAccess->UNLOCK( Environment );
// remove options from cache, unlock may change it
// it will be refreshed when needed
aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
@@ -3208,6 +3224,9 @@ void Content::unlock(
}
break;
default:
// remove options from cache,
// it will be refreshed when needed
aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
//fallthrough
;
}
@@ -3714,7 +3733,12 @@ void Content::getResourceOptions(
rDAVOptions.isClass3() ) ?
m_nOptsCacheLifeDAV : // a WebDAV site
m_nOptsCacheLifeImplWeb; // a site implementing OPTIONS but
// it's not DAV
// it's not DAV
// if resource is locked, will use a
// different lifetime
if( rDAVOptions.isLocked() )
nLifeTime = m_nOptsCacheLifeDAVLocked;
// check if redirected
aRedirURL = rResAccess->getURL();
if( aRedirURL == aTargetURL)