diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-03-25 12:19:35 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-03-26 16:39:54 +0100 |
commit | 166a934cdf6b3adc89bca8ce6b2489d225c75309 (patch) | |
tree | d80572ad9ef8eb05098015f5efa4d8abc648fe3a /ucb | |
parent | webdav: Implement unlocking of documents. (diff) | |
download | core-166a934cdf6b3adc89bca8ce6b2489d225c75309.tar.gz core-166a934cdf6b3adc89bca8ce6b2489d225c75309.zip |
webdav: Implement refreshing of locks.
Change-Id: Ia4a1c7b929dac473dfb5a5fa233c7f0c662a95c6
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/webdav/SerfLockReqProcImpl.cxx | 39 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfLockReqProcImpl.hxx | 5 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfLockStore.cxx | 3 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfRequestProcessor.cxx | 5 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfRequestProcessor.hxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfSession.cxx | 25 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfSession.hxx | 3 |
7 files changed, 51 insertions, 31 deletions
diff --git a/ucb/source/ucp/webdav/SerfLockReqProcImpl.cxx b/ucb/source/ucp/webdav/SerfLockReqProcImpl.cxx index 9e16212a2f8f..ff766effa108 100644 --- a/ucb/source/ucp/webdav/SerfLockReqProcImpl.cxx +++ b/ucb/source/ucp/webdav/SerfLockReqProcImpl.cxx @@ -32,10 +32,12 @@ namespace http_dav_ucp SerfLockReqProcImpl::SerfLockReqProcImpl( const char* inPath, const DAVRequestHeaders& inRequestHeaders, SerfSession& rSession, - const css::ucb::Lock & rLock ) + const css::ucb::Lock& rLock, + sal_Int32* plastChanceToSendRefreshRequest ) : SerfRequestProcessorImpl( inPath, inRequestHeaders ) , m_rSession( rSession ) , m_aLock( rLock ) + , m_plastChanceToSendRefreshRequest( plastChanceToSendRefreshRequest ) , m_xInputStream( new SerfInputStream() ) { } @@ -76,9 +78,12 @@ serf_bucket_t * SerfLockReqProcImpl::createSerfRequestBucket( serf_request_t * i aBody.append("</lockinfo>\n"); const OString aBodyText(aBody.makeStringAndClear()); - serf_bucket_t* body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(), - aBodyText.getLength(), - pSerfBucketAlloc ); + serf_bucket_t* body_bkt = 0; + + if (!m_plastChanceToSendRefreshRequest) + body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(), + aBodyText.getLength(), + pSerfBucketAlloc ); // create serf request serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, @@ -86,7 +91,8 @@ serf_bucket_t * SerfLockReqProcImpl::createSerfRequestBucket( serf_request_t * i getPathStr(), body_bkt, pSerfBucketAlloc ); - handleChunkedEncoding(req_bkt, aBodyText.getLength()); + if (!m_plastChanceToSendRefreshRequest) + handleChunkedEncoding(req_bkt, aBodyText.getLength()); // set request header fields serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); @@ -110,8 +116,18 @@ serf_bucket_t * SerfLockReqProcImpl::createSerfRequestBucket( serf_request_t * i default: throw DAVException( DAVException::DAV_INVALID_ARG ); } - serf_bucket_headers_set( hdrs_bkt, "Depth", depth ); - serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" ); + if (!m_plastChanceToSendRefreshRequest) + { + serf_bucket_headers_set( hdrs_bkt, "Depth", depth ); + serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" ); + } + else + { + const OString sToken( "(<" + OUStringToOString( apr_environment::AprEnv::getAprEnv()-> + getSerfLockStore()->getLockToken( OUString::createFromAscii(getPathStr())), + RTL_TEXTENCODING_UTF8 ) + ">)" ); + serf_bucket_headers_set( hdrs_bkt, "If", sToken.getStr() ); + } // Set the lock timeout if (m_aLock.Timeout == -1) @@ -121,6 +137,8 @@ serf_bucket_t * SerfLockReqProcImpl::createSerfRequestBucket( serf_request_t * i const OString aTimeValue("Second-" + OString::number(m_aLock.Timeout)); serf_bucket_headers_set( hdrs_bkt, "Timeout", aTimeValue.getStr() ); } + else + serf_bucket_headers_set( hdrs_bkt, "Timeout", "Second-180" ); osl_getSystemTime( &m_aStartCall ); @@ -158,6 +176,13 @@ void SerfLockReqProcImpl::handleEndOfResponseData( serf_bucket_t * ) else SAL_WARN("ucb.ucp.webdav", "No chance to refresh lock before timeout!" ); } + if (m_plastChanceToSendRefreshRequest) + { + *m_plastChanceToSendRefreshRequest = lastChanceToSendRefreshRequest; + assert(aLocks.size() == 1); + // We are just refreshing lock, do not add it into SerfLockStore + break; + } apr_environment::AprEnv::getAprEnv()->getSerfLockStore()->addLock( OUString::createFromAscii(getPathStr()), aLocks[i].LockTokens[0], diff --git a/ucb/source/ucp/webdav/SerfLockReqProcImpl.hxx b/ucb/source/ucp/webdav/SerfLockReqProcImpl.hxx index 766bc2ba6c5e..9341a401111e 100644 --- a/ucb/source/ucp/webdav/SerfLockReqProcImpl.hxx +++ b/ucb/source/ucp/webdav/SerfLockReqProcImpl.hxx @@ -37,7 +37,8 @@ public: SerfLockReqProcImpl( const char* inPath, const DAVRequestHeaders& inRequestHeaders, SerfSession& rSession, - const css::ucb::Lock & rLock ); + const css::ucb::Lock& rLock, + sal_Int32* plastChanceToSendRefreshRequest = 0 ); virtual ~SerfLockReqProcImpl() SAL_OVERRIDE; @@ -53,6 +54,8 @@ private: SerfSession& m_rSession; css::ucb::Lock m_aLock; + // if m_plastChanceToSendRefreshRequest is not 0 we are sending just refresh request + sal_Int32* m_plastChanceToSendRefreshRequest; TimeValue m_aStartCall; css::uno::Reference< SerfInputStream > m_xInputStream; }; diff --git a/ucb/source/ucp/webdav/SerfLockStore.cxx b/ucb/source/ucp/webdav/SerfLockStore.cxx index 6c0a29e9b1ed..a9696b331aec 100644 --- a/ucb/source/ucp/webdav/SerfLockStore.cxx +++ b/ucb/source/ucp/webdav/SerfLockStore.cxx @@ -197,8 +197,7 @@ void SerfLockStore::refreshLocks() // refresh the lock. sal_Int32 nlastChanceToSendRefreshRequest = -1; if ( rInfo.m_xSession->LOCK( - (*it).first, - /* out param */ nlastChanceToSendRefreshRequest ) ) + (*it).first, &nlastChanceToSendRefreshRequest ) ) { rInfo.m_nLastChanceToSendRefreshRequest = nlastChanceToSendRefreshRequest; diff --git a/ucb/source/ucp/webdav/SerfRequestProcessor.cxx b/ucb/source/ucp/webdav/SerfRequestProcessor.cxx index ced9d5b785c5..ddeecca45765 100644 --- a/ucb/source/ucp/webdav/SerfRequestProcessor.cxx +++ b/ucb/source/ucp/webdav/SerfRequestProcessor.cxx @@ -313,12 +313,13 @@ bool SerfRequestProcessor::processMove( const OUString & inDestinationPath, } -bool SerfRequestProcessor::processLock( const css::ucb::Lock & rLock ) +bool SerfRequestProcessor::processLock( const css::ucb::Lock & rLock, sal_Int32 *plastChanceToSendRefreshRequest ) { mpProcImpl = new SerfLockReqProcImpl( mPathStr, mrSerfSession.getRequestEnvironment().m_aRequestHeaders, mrSerfSession, - rLock ); + rLock, + plastChanceToSendRefreshRequest ); return runProcessor() == APR_SUCCESS; } diff --git a/ucb/source/ucp/webdav/SerfRequestProcessor.hxx b/ucb/source/ucp/webdav/SerfRequestProcessor.hxx index 7e4573fe64ed..ef0987f4d803 100644 --- a/ucb/source/ucp/webdav/SerfRequestProcessor.hxx +++ b/ucb/source/ucp/webdav/SerfRequestProcessor.hxx @@ -126,7 +126,7 @@ public: apr_status_t& outSerfStatus ); //LOCK - bool processLock( const css::ucb::Lock & rLock ); + bool processLock( const css::ucb::Lock & rLock, sal_Int32 *plastChanceToSendRefreshRequest = 0 ); //UNLOCK bool processUnlock(); diff --git a/ucb/source/ucp/webdav/SerfSession.cxx b/ucb/source/ucp/webdav/SerfSession.cxx index f8222b94cc92..65fd5dcea22f 100644 --- a/ucb/source/ucp/webdav/SerfSession.cxx +++ b/ucb/source/ucp/webdav/SerfSession.cxx @@ -1060,32 +1060,25 @@ sal_Int64 SerfSession::LOCK( const OUString & /*inPath*/, // LOCK (refresh existing lock) -bool SerfSession::LOCK( const OUString& /*rLock*/, - sal_Int32 & /*rlastChanceToSendRefreshRequest*/ ) +bool SerfSession::LOCK( const OUString& rLock, + sal_Int32 *plastChanceToSendRefreshRequest ) { osl::Guard< osl::Mutex > theGuard( m_aMutex ); - return true; - /* - // refresh existing lock. - - TimeValue startCall; - osl_getSystemTime( &startCall ); + boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( rLock ) ); + aReqProc->processLock( ucb::Lock(), plastChanceToSendRefreshRequest ); - if ( ne_lock_refresh( m_pHttpSession, pLock ) == NE_OK ) + try { - rlastChanceToSendRefreshRequest - = lastChanceToSendRefreshRequest( startCall, pLock->timeout ); - - SAL_INFO("ucb.ucp.webdav", "Lock successfully refreshed." ); + HandleError( aReqProc ); + SAL_INFO("ucb.ucp.webdav", "Refreshing LOCK of " << rLock << " succeeded." ); return true; } - else + catch(...) { - SAL_INFO("ucb.ucp.webdav", "Lock not refreshed!" ); + SAL_INFO("ucb.ucp.webdav", "Refreshing LOCK of " << rLock << " failed!" ); return false; } - */ } diff --git a/ucb/source/ucp/webdav/SerfSession.hxx b/ucb/source/ucp/webdav/SerfSession.hxx index 0c2288b8fe14..f580a4719e8f 100644 --- a/ucb/source/ucp/webdav/SerfSession.hxx +++ b/ucb/source/ucp/webdav/SerfSession.hxx @@ -267,8 +267,7 @@ private: const DAVRequestEnvironment & rEnv ); // refresh lock, called by SerfLockStore::refreshLocks - bool LOCK( const OUString& rLock, - sal_Int32 & rlastChanceToSendRefreshRequest ); + bool LOCK( const OUString& rLock, sal_Int32 *plastChanceToSendRefreshRequest ); // unlock, called by SerfLockStore::~SerfLockStore void UNLOCK( const OUString& rLock ); |