diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-03-21 12:42:51 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-03-26 16:39:53 +0100 |
commit | 53e9b3393aaeb00687eae096944531747976cef3 (patch) | |
tree | fa94110e475423b0ec37e3a58d423614dcbeef16 /ucb | |
parent | 3648ba0db379b3ca2cc6bb84a4b6c14f16217fa9 (diff) |
webdav: Implement unlocking of documents.
Change-Id: I12c092fa7034702273182ef07431ed00f38df8ef
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/Library_ucpdav1.mk | 1 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfLockStore.cxx | 11 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfLockStore.hxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfRequestProcessor.cxx | 19 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfRequestProcessor.hxx | 3 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfSession.cxx | 47 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfSession.hxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfUnlockReqProcImpl.cxx | 68 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/SerfUnlockReqProcImpl.hxx | 54 |
9 files changed, 177 insertions, 30 deletions
diff --git a/ucb/Library_ucpdav1.mk b/ucb/Library_ucpdav1.mk index 9ada038bb02d..51225d21901d 100644 --- a/ucb/Library_ucpdav1.mk +++ b/ucb/Library_ucpdav1.mk @@ -95,6 +95,7 @@ $(eval $(call gb_Library_add_exception_objects,ucpdav1,\ ucb/source/ucp/webdav/SerfRequestProcessor \ ucb/source/ucp/webdav/SerfRequestProcessorImpl \ ucb/source/ucp/webdav/SerfSession \ + ucb/source/ucp/webdav/SerfUnlockReqProcImpl \ ucb/source/ucp/webdav/SerfUri \ ucb/source/ucp/webdav/UCBDeadPropertyValue \ ucb/source/ucp/webdav/webdavcontent \ diff --git a/ucb/source/ucp/webdav/SerfLockStore.cxx b/ucb/source/ucp/webdav/SerfLockStore.cxx index 15aae7e50c07..6c0a29e9b1ed 100644 --- a/ucb/source/ucp/webdav/SerfLockStore.cxx +++ b/ucb/source/ucp/webdav/SerfLockStore.cxx @@ -123,6 +123,17 @@ void SerfLockStore::stopTicker() } } +OUString SerfLockStore::getLockToken( const OUString& rLock ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + LockInfoMap::const_iterator it( m_aLockInfoMap.find( rLock ) ); + if ( it != m_aLockInfoMap.end() ) + return (*it).second.m_sToken; + + SAL_WARN("ucb.ucp.webdav", "SerfLockStore::getLockToken: lock not found!" ); + return OUString(); +} void SerfLockStore::addLock( const OUString& rLock, const OUString& sToken, diff --git a/ucb/source/ucp/webdav/SerfLockStore.hxx b/ucb/source/ucp/webdav/SerfLockStore.hxx index 92ab19012c30..eefd7b838a74 100644 --- a/ucb/source/ucp/webdav/SerfLockStore.hxx +++ b/ucb/source/ucp/webdav/SerfLockStore.hxx @@ -62,6 +62,8 @@ public: SerfLockStore(); ~SerfLockStore(); + OUString getLockToken( const OUString& rLock ); + void addLock( const OUString& rLock, const OUString& sToken, rtl::Reference< SerfSession > const & xSession, diff --git a/ucb/source/ucp/webdav/SerfRequestProcessor.cxx b/ucb/source/ucp/webdav/SerfRequestProcessor.cxx index a557781fcce8..ced9d5b785c5 100644 --- a/ucb/source/ucp/webdav/SerfRequestProcessor.cxx +++ b/ucb/source/ucp/webdav/SerfRequestProcessor.cxx @@ -18,6 +18,8 @@ */ #include "SerfRequestProcessor.hxx" + +#include "AprEnv.hxx" #include "SerfCallbacks.hxx" #include "SerfSession.hxx" #include "SerfPropFindReqProcImpl.hxx" @@ -31,6 +33,7 @@ #include "SerfCopyReqProcImpl.hxx" #include "SerfMoveReqProcImpl.hxx" #include "SerfLockReqProcImpl.hxx" +#include "SerfUnlockReqProcImpl.hxx" #include <apr_strings.h> @@ -320,6 +323,22 @@ bool SerfRequestProcessor::processLock( const css::ucb::Lock & rLock ) return runProcessor() == APR_SUCCESS; } +bool SerfRequestProcessor::processUnlock() +{ + // get the lock from lock store + const OUString sToken( + apr_environment::AprEnv::getAprEnv()->getSerfLockStore()->getLockToken( + OUString::createFromAscii(mPathStr)) ); + if ( sToken.isEmpty() ) + throw DAVException( DAVException::DAV_NOT_LOCKED ); + + mpProcImpl = new SerfUnlockReqProcImpl( mPathStr, + mrSerfSession.getRequestEnvironment().m_aRequestHeaders, + sToken ); + + return runProcessor() == APR_SUCCESS; +} + apr_status_t SerfRequestProcessor::runProcessor() { prepareProcessor(); diff --git a/ucb/source/ucp/webdav/SerfRequestProcessor.hxx b/ucb/source/ucp/webdav/SerfRequestProcessor.hxx index f941a4956997..7e4573fe64ed 100644 --- a/ucb/source/ucp/webdav/SerfRequestProcessor.hxx +++ b/ucb/source/ucp/webdav/SerfRequestProcessor.hxx @@ -128,6 +128,9 @@ public: //LOCK bool processLock( const css::ucb::Lock & rLock ); + //UNLOCK + bool processUnlock(); + apr_status_t provideSerfCredentials( char ** outUsername, char ** outPassword, serf_request_t * inRequest, diff --git a/ucb/source/ucp/webdav/SerfSession.cxx b/ucb/source/ucp/webdav/SerfSession.cxx index 7b21f8fb11d9..f8222b94cc92 100644 --- a/ucb/source/ucp/webdav/SerfSession.cxx +++ b/ucb/source/ucp/webdav/SerfSession.cxx @@ -1091,58 +1091,47 @@ bool SerfSession::LOCK( const OUString& /*rLock*/, // UNLOCK -void SerfSession::UNLOCK( const OUString & /*inPath*/, - const DAVRequestEnvironment & /*rEnv*/ ) +void SerfSession::UNLOCK( const OUString & inPath, + const DAVRequestEnvironment & rEnv ) throw ( DAVException ) { osl::Guard< osl::Mutex > theGuard( m_aMutex ); - /* - // get the neon lock from lock store - SerfLock * theLock - = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); - if ( !theLock ) - throw DAVException( DAVException::DAV_NOT_LOCKED ); - Init( rEnv ); - int theRetVal = ne_unlock( m_pHttpSession, theLock ); + boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); + aReqProc->processUnlock(); - if ( theRetVal == NE_OK ) + try { - m_aSerfLockStore.removeLock( theLock ); - ne_lock_destroy( theLock ); + HandleError( aReqProc ); + SAL_INFO("ucb.ucp.webdav", "UNLOCK of " << inPath << " succeeded." ); } - else + catch(...) { - SAL_INFO("ucb.ucp.webdav", "SerfSession::UNLOCK: unlocking of " - << makeAbsoluteURL( inPath ) << " failed."); + SAL_INFO("ucb.ucp.webdav", "UNLOCK of " << inPath << " failed!" ); } - - HandleError( theRetVal, inPath, rEnv ); - */ } // UNLOCK -bool SerfSession::UNLOCK( const OUString& /*rLock*/ ) +void SerfSession::UNLOCK( const OUString& rLock ) { osl::Guard< osl::Mutex > theGuard( m_aMutex ); - return true; - /* - if ( ne_unlock( m_pHttpSession, pLock ) == NE_OK ) + boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( rLock ) ); + aReqProc->processUnlock(); + + try { - SAL_INFO("ucb.ucp.webdav", "UNLOCK succeeded." ); - return true; + HandleError( aReqProc ); + SAL_INFO("ucb.ucp.webdav", "UNLOCK of " << rLock << " succeeded." ); } - else + catch(...) { - SAL_INFO("ucb.ucp.webdav", "UNLOCK failed!" ); - return false; + SAL_INFO("ucb.ucp.webdav", "UNLOCK of " << rLock << " failed!" ); } - */ } diff --git a/ucb/source/ucp/webdav/SerfSession.hxx b/ucb/source/ucp/webdav/SerfSession.hxx index b3dfab7be719..0c2288b8fe14 100644 --- a/ucb/source/ucp/webdav/SerfSession.hxx +++ b/ucb/source/ucp/webdav/SerfSession.hxx @@ -271,7 +271,7 @@ private: sal_Int32 & rlastChanceToSendRefreshRequest ); // unlock, called by SerfLockStore::~SerfLockStore - bool UNLOCK( const OUString& rLock ); + void UNLOCK( const OUString& rLock ); /* // low level GET implementation, used by public GET implementations diff --git a/ucb/source/ucp/webdav/SerfUnlockReqProcImpl.cxx b/ucb/source/ucp/webdav/SerfUnlockReqProcImpl.cxx new file mode 100644 index 000000000000..59c8994f090f --- /dev/null +++ b/ucb/source/ucp/webdav/SerfUnlockReqProcImpl.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "SerfUnlockReqProcImpl.hxx" + +namespace http_dav_ucp +{ + +SerfUnlockReqProcImpl::SerfUnlockReqProcImpl( const char* inPath, + const DAVRequestHeaders& inRequestHeaders, + const OUString& sToken) + : SerfRequestProcessorImpl( inPath, inRequestHeaders ) + , m_sToken( sToken ) +{ +} + +SerfUnlockReqProcImpl::~SerfUnlockReqProcImpl() +{ +} + +serf_bucket_t * SerfUnlockReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) +{ + // create serf request + serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, + "UNLOCK", + getPathStr(), + 0, + serf_request_get_alloc( inSerfRequest ) ); + // set request header fields + serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); + + // general header fields provided by caller + setRequestHeaders( hdrs_bkt ); + + // token header field + serf_bucket_headers_set( hdrs_bkt, "Lock-Token", + OUStringToOString(m_sToken, RTL_TEXTENCODING_UTF8).getStr() ); + + return req_bkt; +} + +void SerfUnlockReqProcImpl::processChunkOfResponseData( const char* , apr_size_t ) +{ +} + +void SerfUnlockReqProcImpl::handleEndOfResponseData( serf_bucket_t * ) +{ +} + +} // namespace http_dav_ucp + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/webdav/SerfUnlockReqProcImpl.hxx b/ucb/source/ucp/webdav/SerfUnlockReqProcImpl.hxx new file mode 100644 index 000000000000..dc2e6d1e1b39 --- /dev/null +++ b/ucb/source/ucp/webdav/SerfUnlockReqProcImpl.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SERFUNLOCKREQPROCIMPL_HXX +#define INCLUDED_SERFUNLOCKREQPROCIMPL_HXX + +#include "SerfRequestProcessorImpl.hxx" + +namespace http_dav_ucp +{ + +class SerfUnlockReqProcImpl : public SerfRequestProcessorImpl +{ +public: + SerfUnlockReqProcImpl( const char* inPath, + const DAVRequestHeaders& inRequestHeaders, + const OUString& sToken); + + virtual ~SerfUnlockReqProcImpl() SAL_OVERRIDE; + + virtual serf_bucket_t *createSerfRequestBucket( + serf_request_t * inSerfRequest ) SAL_OVERRIDE; + +private: + virtual void processChunkOfResponseData( + const char* data, apr_size_t len ) SAL_OVERRIDE; + + virtual void handleEndOfResponseData( + serf_bucket_t * inSerfResponseBucket ) SAL_OVERRIDE; + + OUString m_sToken; +}; + +} // namespace http_dav_ucp + +#endif // INCLUDED_SERFUNLOCKREQPROCIMPL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |