Kaydet (Commit) 166a934c authored tarafından Matúš Kukan's avatar Matúš Kukan

webdav: Implement refreshing of locks.

Change-Id: Ia4a1c7b929dac473dfb5a5fa233c7f0c662a95c6
üst 53e9b339
......@@ -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],
......
......@@ -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;
};
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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();
......
......@@ -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;
}
*/
}
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment