Lines 26-31
Link Here
|
26 |
#include <vector> |
26 |
#include <vector> |
27 |
#include <string.h> |
27 |
#include <string.h> |
28 |
#include <rtl/string.h> |
28 |
#include <rtl/string.h> |
|
|
29 |
#include <rtl/ustrbuf.hxx> |
30 |
#include <osl/time.h> |
29 |
#include "comphelper/sequence.hxx" |
31 |
#include "comphelper/sequence.hxx" |
30 |
#include "ucbhelper/simplecertificatevalidationrequest.hxx" |
32 |
#include "ucbhelper/simplecertificatevalidationrequest.hxx" |
31 |
|
33 |
|
Lines 57-66
Link Here
|
57 |
using namespace com::sun::star; |
59 |
using namespace com::sun::star; |
58 |
using namespace http_dav_ucp; |
60 |
using namespace http_dav_ucp; |
59 |
|
61 |
|
60 |
|
|
|
61 |
// ------------------------------------------------------------------- |
62 |
// ------------------------------------------------------------------- |
62 |
// static members! |
63 |
// static members! |
63 |
//SerfLockStore SerfSession::m_aSerfLockStore; |
64 |
SerfLockStore SerfSession::m_aSerfLockStore; |
64 |
|
65 |
|
65 |
// ------------------------------------------------------------------- |
66 |
// ------------------------------------------------------------------- |
66 |
// Constructor |
67 |
// Constructor |
Lines 75-80
SerfSession::SerfSession(
Link Here
|
75 |
, m_aUri( inUri ) |
76 |
, m_aUri( inUri ) |
76 |
, m_aProxyName() |
77 |
, m_aProxyName() |
77 |
, m_nProxyPort( 0 ) |
78 |
, m_nProxyPort( 0 ) |
|
|
79 |
, m_aServerHeaderField() |
78 |
, m_pSerfConnection( 0 ) |
80 |
, m_pSerfConnection( 0 ) |
79 |
, m_pSerfContext( 0 ) |
81 |
, m_pSerfContext( 0 ) |
80 |
, m_bIsHeadRequestInProgress( false ) |
82 |
, m_bIsHeadRequestInProgress( false ) |
Lines 97-102
SerfSession::~SerfSession( )
Link Here
|
97 |
{ |
99 |
{ |
98 |
serf_connection_close( m_pSerfConnection ); |
100 |
serf_connection_close( m_pSerfConnection ); |
99 |
m_pSerfConnection = 0; |
101 |
m_pSerfConnection = 0; |
|
|
102 |
OSL_TRACE("SerfSession::~SerfSession: closed serf connection"); |
100 |
} |
103 |
} |
101 |
} |
104 |
} |
102 |
|
105 |
|
Lines 126-131
void SerfSession::Init()
Link Here
|
126 |
|
129 |
|
127 |
// Not yet initialized. Create new session. |
130 |
// Not yet initialized. Create new session. |
128 |
bCreateNewSession = true; |
131 |
bCreateNewSession = true; |
|
|
132 |
OSL_TRACE("SerfSession::Init: serf connection created"); |
129 |
} |
133 |
} |
130 |
else |
134 |
else |
131 |
{ |
135 |
{ |
Lines 166-172
void SerfSession::Init()
Link Here
|
166 |
if ( m_aProxyName.getLength() ) |
170 |
if ( m_aProxyName.getLength() ) |
167 |
{ |
171 |
{ |
168 |
apr_sockaddr_t *proxy_address = NULL; |
172 |
apr_sockaddr_t *proxy_address = NULL; |
169 |
status = apr_sockaddr_info_get( &proxy_address, |
173 |
status = apr_sockaddr_info_get( &proxy_address, |
170 |
rtl::OUStringToOString( m_aProxyName, RTL_TEXTENCODING_UTF8 ).getStr(), |
174 |
rtl::OUStringToOString( m_aProxyName, RTL_TEXTENCODING_UTF8 ).getStr(), |
171 |
APR_UNSPEC, |
175 |
APR_UNSPEC, |
172 |
static_cast<apr_port_t>(m_nProxyPort), |
176 |
static_cast<apr_port_t>(m_nProxyPort), |
Lines 223-228
char* SerfSession::getHostinfo()
Link Here
|
223 |
return m_aUri.getAprUri()->hostinfo; |
227 |
return m_aUri.getAprUri()->hostinfo; |
224 |
} |
228 |
} |
225 |
|
229 |
|
|
|
230 |
// ------------------------------------------------------------------- |
231 |
// helper function |
232 |
// it composes the uri for lockstore registration |
233 |
rtl::OUString SerfSession::composeCurrentUri(const rtl::OUString & inPath) |
234 |
{ |
235 |
rtl::OUString aScheme( m_aUri.GetScheme() ); |
236 |
rtl::OUStringBuffer aBuf( aScheme ); |
237 |
aBuf.appendAscii( "://" ); |
238 |
if ( m_aUri.GetUserInfo().getLength() > 0 ) |
239 |
{ |
240 |
aBuf.append( m_aUri.GetUserInfo() ); |
241 |
aBuf.appendAscii( "@" ); |
242 |
} |
243 |
// Is host a numeric IPv6 address? |
244 |
if ( ( m_aUri.GetHost().indexOf( ':' ) != -1 ) && |
245 |
( m_aUri.GetHost()[ 0 ] != sal_Unicode( '[' ) ) ) |
246 |
{ |
247 |
aBuf.appendAscii( "[" ); |
248 |
aBuf.append( m_aUri.GetHost() ); |
249 |
aBuf.appendAscii( "]" ); |
250 |
} |
251 |
else |
252 |
{ |
253 |
aBuf.append( m_aUri.GetHost() ); |
254 |
} |
255 |
|
256 |
// append port, but only, if not default port. |
257 |
bool bAppendPort = true; |
258 |
sal_Int32 aPort = m_aUri.GetPort(); |
259 |
switch ( aPort ) |
260 |
{ |
261 |
case DEFAULT_HTTP_PORT: |
262 |
bAppendPort = aScheme.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "http" ) ); |
263 |
break; |
264 |
|
265 |
case DEFAULT_HTTPS_PORT: |
266 |
bAppendPort = !aScheme.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "https" ) ); |
267 |
break; |
268 |
} |
269 |
if ( bAppendPort ) |
270 |
{ |
271 |
aBuf.appendAscii( ":" ); |
272 |
aBuf.append( rtl::OUString::valueOf( aPort ) ); |
273 |
} |
274 |
aBuf.append( inPath ); |
275 |
|
276 |
rtl::OUString aUri(aBuf.makeStringAndClear() ); |
277 |
return aUri; |
278 |
} |
226 |
|
279 |
|
227 |
// ------------------------------------------------------------------- |
280 |
// ------------------------------------------------------------------- |
228 |
// virtual |
281 |
// virtual |
Lines 259-269
apr_status_t SerfSession::setupSerfConnection( apr_socket_t * inAprSocket,
Link Here
|
259 |
apr_pool_t* /*inAprPool*/ ) |
312 |
apr_pool_t* /*inAprPool*/ ) |
260 |
{ |
313 |
{ |
261 |
serf_bucket_t *tmpInputBkt; |
314 |
serf_bucket_t *tmpInputBkt; |
262 |
tmpInputBkt = serf_context_bucket_socket_create( getSerfContext(), |
315 |
tmpInputBkt = serf_context_bucket_socket_create( getSerfContext(), |
263 |
inAprSocket, |
316 |
inAprSocket, |
264 |
getSerfBktAlloc() ); |
317 |
getSerfBktAlloc() ); |
265 |
|
318 |
|
266 |
if ( isSSLNeeded() ) |
319 |
if ( isSSLNeeded() ) |
267 |
{ |
320 |
{ |
268 |
tmpInputBkt = serf_bucket_ssl_decrypt_create( tmpInputBkt, |
321 |
tmpInputBkt = serf_bucket_ssl_decrypt_create( tmpInputBkt, |
269 |
0, |
322 |
0, |
Lines 276-282
apr_status_t SerfSession::setupSerfConnection( apr_socket_t * inAprSocket,
Link Here
|
276 |
NULL, |
329 |
NULL, |
277 |
Serf_CertificateChainValidation, |
330 |
Serf_CertificateChainValidation, |
278 |
this); |
331 |
this); |
279 |
serf_ssl_set_hostname( serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), |
332 |
serf_ssl_set_hostname( serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), |
280 |
getHostinfo() ); |
333 |
getHostinfo() ); |
281 |
|
334 |
|
282 |
*outSerfOutputBucket = serf_bucket_ssl_encrypt_create( *outSerfOutputBucket, |
335 |
*outSerfOutputBucket = serf_bucket_ssl_encrypt_create( *outSerfOutputBucket, |
Lines 290-299
apr_status_t SerfSession::setupSerfConnection( apr_socket_t * inAprSocket,
Link Here
|
290 |
} |
343 |
} |
291 |
|
344 |
|
292 |
apr_status_t SerfSession::provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry, |
345 |
apr_status_t SerfSession::provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry, |
293 |
char ** outUsername, |
346 |
char ** outUsername, |
294 |
char ** outPassword, |
347 |
char ** outPassword, |
295 |
serf_request_t * /*inRequest*/, |
348 |
serf_request_t * /*inRequest*/, |
296 |
int /*inCode*/, |
349 |
int /*inCode*/, |
297 |
const char *inAuthProtocol, |
350 |
const char *inAuthProtocol, |
298 |
const char *inRealm, |
351 |
const char *inRealm, |
299 |
apr_pool_t *inAprPool ) |
352 |
apr_pool_t *inAprPool ) |
Lines 600-606
serf_bucket_t* SerfSession::acceptSerfResponse( serf_request_t * inSerfRequest,
Link Here
|
600 |
SerfBktAlloc ); |
653 |
SerfBktAlloc ); |
601 |
|
654 |
|
602 |
// create response bucket |
655 |
// create response bucket |
603 |
responseBkt = serf_bucket_response_create( responseBkt, |
656 |
responseBkt = serf_bucket_response_create( responseBkt, |
604 |
SerfBktAlloc ); |
657 |
SerfBktAlloc ); |
605 |
|
658 |
|
606 |
if ( isHeadRequestInProgress() ) |
659 |
if ( isHeadRequestInProgress() ) |
Lines 693-699
void SerfSession::PROPPATCH( const rtl::OUString & inPath,
Link Here
|
693 |
|
746 |
|
694 |
apr_status_t status = APR_SUCCESS; |
747 |
apr_status_t status = APR_SUCCESS; |
695 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
748 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
|
|
749 |
//check whether a lock on this resource is already owned |
750 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
751 |
ucb::Lock inLock; |
752 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
753 |
if ( pLock ) |
754 |
{ |
755 |
inLock = pLock->getLock(); |
756 |
} |
696 |
aReqProc->processPropPatch( inValues, |
757 |
aReqProc->processPropPatch( inValues, |
|
|
758 |
inLock, |
697 |
status ); |
759 |
status ); |
698 |
|
760 |
|
699 |
HandleError( aReqProc ); |
761 |
HandleError( aReqProc ); |
Lines 843-850
void SerfSession::PUT( const rtl::OUString & inPath,
Link Here
|
843 |
if ( !getDataFromInputStream( inInputStream, aDataToSend, false ) ) |
905 |
if ( !getDataFromInputStream( inInputStream, aDataToSend, false ) ) |
844 |
throw DAVException( DAVException::DAV_INVALID_ARG ); |
906 |
throw DAVException( DAVException::DAV_INVALID_ARG ); |
845 |
apr_status_t status = APR_SUCCESS; |
907 |
apr_status_t status = APR_SUCCESS; |
|
|
908 |
|
909 |
//check whether a lock on this resource is already owned |
910 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
911 |
ucb::Lock inLock; |
912 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
913 |
if ( pLock ) |
914 |
{ |
915 |
inLock = pLock->getLock(); |
916 |
} |
846 |
aReqProc->processPut( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), |
917 |
aReqProc->processPut( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), |
847 |
aDataToSend.getLength(), |
918 |
aDataToSend.getLength(), |
|
|
919 |
inLock, |
848 |
status ); |
920 |
status ); |
849 |
|
921 |
|
850 |
HandleError( aReqProc ); |
922 |
HandleError( aReqProc ); |
Lines 874-883
SerfSession::POST( const rtl::OUString & inPath,
Link Here
|
874 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
946 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
875 |
uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); |
947 |
uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); |
876 |
apr_status_t status = APR_SUCCESS; |
948 |
apr_status_t status = APR_SUCCESS; |
|
|
949 |
//check whether a lock on this resource is already owned |
950 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
951 |
ucb::Lock inLock; |
952 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
953 |
if ( pLock ) |
954 |
{ |
955 |
inLock = pLock->getLock(); |
956 |
} |
877 |
aReqProc->processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), |
957 |
aReqProc->processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), |
878 |
aDataToSend.getLength(), |
958 |
aDataToSend.getLength(), |
879 |
rContentType, |
959 |
rContentType, |
880 |
rReferer, |
960 |
rReferer, |
|
|
961 |
inLock, |
881 |
xInputStream, |
962 |
xInputStream, |
882 |
status ); |
963 |
status ); |
883 |
|
964 |
|
Lines 908-917
void SerfSession::POST( const rtl::OUString & inPath,
Link Here
|
908 |
|
989 |
|
909 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
990 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
910 |
apr_status_t status = APR_SUCCESS; |
991 |
apr_status_t status = APR_SUCCESS; |
|
|
992 |
//check whether a lock on this resource is already owned |
993 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
994 |
ucb::Lock inLock; |
995 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
996 |
if ( pLock ) |
997 |
{ |
998 |
inLock = pLock->getLock(); |
999 |
} |
911 |
aReqProc->processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), |
1000 |
aReqProc->processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), |
912 |
aDataToSend.getLength(), |
1001 |
aDataToSend.getLength(), |
913 |
rContentType, |
1002 |
rContentType, |
914 |
rReferer, |
1003 |
rReferer, |
|
|
1004 |
inLock, |
915 |
oOutputStream, |
1005 |
oOutputStream, |
916 |
status ); |
1006 |
status ); |
917 |
|
1007 |
|
Lines 931-937
void SerfSession::MKCOL( const rtl::OUString & inPath,
Link Here
|
931 |
|
1021 |
|
932 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
1022 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
933 |
apr_status_t status = APR_SUCCESS; |
1023 |
apr_status_t status = APR_SUCCESS; |
934 |
aReqProc->processMkCol( status ); |
1024 |
//check whether a lock on the destination resource is already owned |
|
|
1025 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
1026 |
ucb::Lock inLock; |
1027 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
1028 |
if ( pLock ) |
1029 |
{ |
1030 |
inLock = pLock->getLock(); |
1031 |
} |
1032 |
aReqProc->processMkCol( inLock, status ); |
935 |
|
1033 |
|
936 |
HandleError( aReqProc ); |
1034 |
HandleError( aReqProc ); |
937 |
} |
1035 |
} |
Lines 952-959
void SerfSession::COPY( const rtl::OUString & inSourceURL,
Link Here
|
952 |
SerfUri theSourceUri( inSourceURL ); |
1050 |
SerfUri theSourceUri( inSourceURL ); |
953 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( theSourceUri.GetPath() ) ); |
1051 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( theSourceUri.GetPath() ) ); |
954 |
apr_status_t status = APR_SUCCESS; |
1052 |
apr_status_t status = APR_SUCCESS; |
|
|
1053 |
//check whether a lock on the destination resource is already owned |
1054 |
rtl::OUString aUri( composeCurrentUri( inDestinationURL ) ); |
1055 |
ucb::Lock inLock; |
1056 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
1057 |
if ( pLock ) |
1058 |
{ |
1059 |
inLock = pLock->getLock(); |
1060 |
} |
955 |
aReqProc->processCopy( inDestinationURL, |
1061 |
aReqProc->processCopy( inDestinationURL, |
956 |
(inOverWrite ? true : false), |
1062 |
(inOverWrite ? true : false), |
|
|
1063 |
inLock, |
957 |
status ); |
1064 |
status ); |
958 |
|
1065 |
|
959 |
HandleError( aReqProc ); |
1066 |
HandleError( aReqProc ); |
Lines 975-982
void SerfSession::MOVE( const rtl::OUString & inSourceURL,
Link Here
|
975 |
SerfUri theSourceUri( inSourceURL ); |
1082 |
SerfUri theSourceUri( inSourceURL ); |
976 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( theSourceUri.GetPath() ) ); |
1083 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( theSourceUri.GetPath() ) ); |
977 |
apr_status_t status = APR_SUCCESS; |
1084 |
apr_status_t status = APR_SUCCESS; |
|
|
1085 |
//check whether a lock on the destination resource is already owned |
1086 |
rtl::OUString aUri( composeCurrentUri( inDestinationURL ) ); |
1087 |
ucb::Lock inLock; |
1088 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
1089 |
if ( pLock ) |
1090 |
{ |
1091 |
inLock = pLock->getLock(); |
1092 |
} |
978 |
aReqProc->processMove( inDestinationURL, |
1093 |
aReqProc->processMove( inDestinationURL, |
979 |
(inOverWrite ? true : false), |
1094 |
(inOverWrite ? true : false), |
|
|
1095 |
inLock, |
980 |
status ); |
1096 |
status ); |
981 |
|
1097 |
|
982 |
HandleError( aReqProc ); |
1098 |
HandleError( aReqProc ); |
Lines 995-1019
void SerfSession::DESTROY( const rtl::OUString & inPath,
Link Here
|
995 |
|
1111 |
|
996 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
1112 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
997 |
apr_status_t status = APR_SUCCESS; |
1113 |
apr_status_t status = APR_SUCCESS; |
998 |
aReqProc->processDelete( status ); |
1114 |
//check whether a lock on this resource is already owned |
|
|
1115 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
1116 |
ucb::Lock inLock; |
1117 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
1118 |
if ( pLock ) |
1119 |
{ |
1120 |
inLock = pLock->getLock(); |
1121 |
} |
1122 |
aReqProc->processDelete( inLock, status ); |
999 |
|
1123 |
|
1000 |
HandleError( aReqProc ); |
1124 |
HandleError( aReqProc ); |
1001 |
} |
1125 |
} |
1002 |
|
1126 |
|
1003 |
// ------------------------------------------------------------------- |
1127 |
// ------------------------------------------------------------------- |
1004 |
/* |
1128 |
|
1005 |
namespace |
1129 |
namespace |
1006 |
{ |
1130 |
{ |
1007 |
sal_Int32 lastChanceToSendRefreshRequest( TimeValue const & rStart, |
1131 |
sal_Int32 lastChanceToSendRefreshRequest( TimeValue const & rStart, |
1008 |
int timeout ) |
1132 |
sal_Int32 timeout ) |
1009 |
{ |
1133 |
{ |
1010 |
TimeValue aEnd; |
1134 |
TimeValue aEnd; |
1011 |
osl_getSystemTime( &aEnd ); |
1135 |
osl_getSystemTime( &aEnd ); |
1012 |
|
1136 |
|
1013 |
// Try to estimate a safe absolute time for sending the |
1137 |
// Try to estimate a safe absolute time for sending the |
1014 |
// lock refresh request. |
1138 |
// lock refresh request. |
1015 |
sal_Int32 lastChanceToSendRefreshRequest = -1; |
1139 |
sal_Int32 lastChanceToSendRefreshRequest = DAVINFINITY; |
1016 |
if ( timeout != NE_TIMEOUT_INFINITE ) |
1140 |
if ( timeout != DAVINFINITY ) |
1017 |
{ |
1141 |
{ |
1018 |
sal_Int32 calltime = aEnd.Seconds - rStart.Seconds; |
1142 |
sal_Int32 calltime = aEnd.Seconds - rStart.Seconds; |
1019 |
if ( calltime <= timeout ) |
1143 |
if ( calltime <= timeout ) |
Lines 1030-1137
namespace
Link Here
|
1030 |
} |
1154 |
} |
1031 |
|
1155 |
|
1032 |
} // namespace |
1156 |
} // namespace |
1033 |
*/ |
1157 |
|
1034 |
// ------------------------------------------------------------------- |
1158 |
// ------------------------------------------------------------------- |
1035 |
// LOCK (set new lock) |
1159 |
// LOCK (set new lock) |
1036 |
// ------------------------------------------------------------------- |
1160 |
// ------------------------------------------------------------------- |
1037 |
void SerfSession::LOCK( const ::rtl::OUString & inPath, |
1161 |
void SerfSession::LOCK( const ::rtl::OUString & inPath, |
1038 |
ucb::Lock & /*rLock*/, |
1162 |
ucb::Lock & rLock, |
1039 |
const DAVRequestEnvironment & rEnv ) |
1163 |
const DAVRequestEnvironment & rEnv ) |
1040 |
throw ( DAVException ) |
1164 |
throw ( DAVException ) |
1041 |
{ |
1165 |
{ |
1042 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
1166 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
1043 |
|
1167 |
|
1044 |
Init( rEnv ); |
1168 |
//before locking, search in the lock store if we already own a lock for this resource |
1045 |
|
1169 |
//if present, return with exception DAV_LOCKED_SELF |
1046 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
1170 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
1047 |
HandleError( aReqProc ); |
1171 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
1048 |
/* Create a depth zero, exclusive write lock, with default timeout |
1172 |
if ( pLock ) |
1049 |
* (allowing a server to pick a default). token, owner and uri are |
|
|
1050 |
* unset. */ |
1051 |
/* |
1052 |
SerfLock * theLock = ne_lock_create(); |
1053 |
|
1054 |
// Set the lock uri |
1055 |
ne_uri aUri; |
1056 |
ne_uri_parse( rtl::OUStringToOString( makeAbsoluteURL( inPath ), |
1057 |
RTL_TEXTENCODING_UTF8 ).getStr(), |
1058 |
&aUri ); |
1059 |
theLock->uri = aUri; |
1060 |
|
1061 |
// Set the lock depth |
1062 |
switch( rLock.Depth ) |
1063 |
{ |
1173 |
{ |
1064 |
case ucb::LockDepth_ZERO: |
1174 |
//already present, meaning already locked by the same AOO session and already in the lockstore |
1065 |
theLock->depth = NE_DEPTH_ZERO; |
1175 |
//just return, nothing to do |
1066 |
break; |
1176 |
return; |
1067 |
case ucb::LockDepth_ONE: |
|
|
1068 |
theLock->depth = NE_DEPTH_ONE; |
1069 |
break; |
1070 |
case ucb::LockDepth_INFINITY: |
1071 |
theLock->depth = NE_DEPTH_INFINITE; |
1072 |
break; |
1073 |
default: |
1074 |
throw DAVException( DAVException::DAV_INVALID_ARG ); |
1075 |
} |
1177 |
} |
1076 |
|
1178 |
|
1077 |
// Set the lock scope |
1179 |
Init( rEnv ); |
1078 |
switch ( rLock.Scope ) |
1180 |
|
1079 |
{ |
1181 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
1080 |
case ucb::LockScope_EXCLUSIVE: |
1182 |
apr_status_t status = APR_SUCCESS; |
1081 |
theLock->scope = ne_lockscope_exclusive; |
|
|
1082 |
break; |
1083 |
case ucb::LockScope_SHARED: |
1084 |
theLock->scope = ne_lockscope_shared; |
1085 |
break; |
1086 |
default: |
1087 |
throw DAVException( DAVException::DAV_INVALID_ARG ); |
1088 |
} |
1089 |
|
1183 |
|
1090 |
// Set the lock timeout |
1184 |
//the returned property, a sequence of locks |
1091 |
theLock->timeout = (long)rLock.Timeout; |
1185 |
//only the first is used |
|
|
1186 |
DAVPropertyValue outLock; |
1092 |
|
1187 |
|
1093 |
// Set the lock owner |
|
|
1094 |
rtl::OUString aValue; |
1095 |
rLock.Owner >>= aValue; |
1096 |
theLock->owner = |
1097 |
ne_strdup( rtl::OUStringToOString( aValue, |
1098 |
RTL_TEXTENCODING_UTF8 ).getStr() ); |
1099 |
TimeValue startCall; |
1188 |
TimeValue startCall; |
1100 |
osl_getSystemTime( &startCall ); |
1189 |
osl_getSystemTime( &startCall ); |
|
|
1190 |
aReqProc->processLock(inPath, rLock, outLock, status); |
1101 |
|
1191 |
|
1102 |
int theRetVal = ne_lock( m_pHttpSession, theLock ); |
1192 |
//HandleError will handle the error and throw an exception, if needed |
1103 |
|
1193 |
HandleError( aReqProc ); |
1104 |
if ( theRetVal == NE_OK ) |
|
|
1105 |
{ |
1106 |
m_aSerfLockStore.addLock( theLock, |
1107 |
this, |
1108 |
lastChanceToSendRefreshRequest( |
1109 |
startCall, theLock->timeout ) ); |
1110 |
|
1111 |
uno::Sequence< rtl::OUString > aTokens( 1 ); |
1112 |
aTokens[ 0 ] = rtl::OUString::createFromAscii( theLock->token ); |
1113 |
rLock.LockTokens = aTokens; |
1114 |
|
1194 |
|
1115 |
OSL_TRACE( "SerfSession::LOCK: created lock for %s. token: %s", |
1195 |
if(outLock.Name.compareToAscii(RTL_CONSTASCII_STRINGPARAM( "DAV:lockdiscovery" )) == 0 ) |
1116 |
rtl::OUStringToOString( makeAbsoluteURL( inPath ), |
|
|
1117 |
RTL_TEXTENCODING_UTF8 ).getStr(), |
1118 |
theLock->token ); |
1119 |
} |
1120 |
else |
1121 |
{ |
1196 |
{ |
1122 |
ne_lock_destroy( theLock ); |
1197 |
//got a lock, use only the first returned |
1123 |
|
1198 |
uno::Sequence< ucb::Lock > aLocks; |
1124 |
OSL_TRACE( "SerfSession::LOCK: obtaining lock for %s failed!", |
1199 |
outLock.Value >>= aLocks; |
1125 |
rtl::OUStringToOString( makeAbsoluteURL( inPath ), |
1200 |
ucb::Lock aLock = aLocks[0]; |
1126 |
RTL_TEXTENCODING_UTF8 ).getStr() ); |
1201 |
|
|
|
1202 |
SerfLock* aNewLock = new SerfLock( aLock, aUri, inPath ); |
1203 |
// add the store the new lock |
1204 |
m_aSerfLockStore.addLock(aNewLock,this, |
1205 |
lastChanceToSendRefreshRequest( |
1206 |
startCall, static_cast< sal_Int32 >(aLock.Timeout) ) ); |
1127 |
} |
1207 |
} |
1128 |
|
1208 |
|
1129 |
HandleError( theRetVal, inPath, rEnv ); |
|
|
1130 |
*/ |
1131 |
} |
1209 |
} |
1132 |
|
1210 |
|
1133 |
// ------------------------------------------------------------------- |
1211 |
// ------------------------------------------------------------------- |
1134 |
// LOCK (refresh existing lock) |
1212 |
// LOCK (refresh existing lock from DAVResourceAccess) |
1135 |
// ------------------------------------------------------------------- |
1213 |
// ------------------------------------------------------------------- |
1136 |
sal_Int64 SerfSession::LOCK( const ::rtl::OUString & /*inPath*/, |
1214 |
sal_Int64 SerfSession::LOCK( const ::rtl::OUString & /*inPath*/, |
1137 |
sal_Int64 nTimeout, |
1215 |
sal_Int64 nTimeout, |
Lines 1172-1263
sal_Int64 SerfSession::LOCK( const ::rtl::OUString & /*inPath*/,
Link Here
|
1172 |
} |
1250 |
} |
1173 |
|
1251 |
|
1174 |
// ------------------------------------------------------------------- |
1252 |
// ------------------------------------------------------------------- |
1175 |
// LOCK (refresh existing lock) |
1253 |
// LOCK (refresh existing lock from SerfLockStore) |
1176 |
// ------------------------------------------------------------------- |
1254 |
// ------------------------------------------------------------------- |
1177 |
bool SerfSession::LOCK( SerfLock * /*pLock*/, |
1255 |
bool SerfSession::LOCK( SerfLock * pLock, |
1178 |
sal_Int32 & /*rlastChanceToSendRefreshRequest*/ ) |
1256 |
sal_Int32 & rlastChanceToSendRefreshRequest ) |
1179 |
{ |
1257 |
{ |
1180 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
1258 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
|
|
1259 |
rtl::OUString inPath = pLock->getResourcePath(); |
1181 |
|
1260 |
|
1182 |
return true; |
1261 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
1183 |
/* |
1262 |
apr_status_t status = APR_SUCCESS; |
1184 |
// refresh existing lock. |
1263 |
|
|
|
1264 |
//the returned property, a sequence of locks |
1265 |
//only the first is used |
1266 |
DAVPropertyValue outLock; |
1185 |
|
1267 |
|
1186 |
TimeValue startCall; |
1268 |
TimeValue startCall; |
1187 |
osl_getSystemTime( &startCall ); |
1269 |
osl_getSystemTime( &startCall ); |
1188 |
|
1270 |
|
1189 |
if ( ne_lock_refresh( m_pHttpSession, pLock ) == NE_OK ) |
1271 |
// refresh existing lock. |
1190 |
{ |
1272 |
aReqProc->processLockRefresh( inPath, pLock->getLock(), outLock, status); |
1191 |
rlastChanceToSendRefreshRequest |
|
|
1192 |
= lastChanceToSendRefreshRequest( startCall, pLock->timeout ); |
1193 |
|
1273 |
|
1194 |
OSL_TRACE( "Lock successfully refreshed." ); |
1274 |
// TODO: possible enhancement as the following: |
1195 |
return true; |
1275 |
// - use an interaction handler to alert the user if the lock was not refreshed, |
1196 |
} |
1276 |
// offering to try again with a new session, asking the user for credential, if necessary. |
1197 |
else |
1277 |
// This may happen if the WebDAV server goes off-line for whatever reason, or the connection is dropped for time-out |
1198 |
{ |
1278 |
// To implement this behavior, some redesigning of the current session implementation may be needed. |
1199 |
OSL_TRACE( "Lock not refreshed!" ); |
1279 |
// |
1200 |
return false; |
1280 |
|
1201 |
} |
1281 |
//HandleError will handle the error and throw an exception, if needed |
1202 |
*/ |
1282 |
HandleError( aReqProc ); |
|
|
1283 |
|
1284 |
uno::Sequence< ucb::Lock > aLocks; |
1285 |
outLock.Value >>= aLocks; |
1286 |
ucb::Lock aLock = aLocks[0]; |
1287 |
|
1288 |
//if ok, udate the lastchance refresh time in lock |
1289 |
rlastChanceToSendRefreshRequest |
1290 |
= lastChanceToSendRefreshRequest( startCall, static_cast< sal_Int32 >(aLock.Timeout) ); |
1291 |
|
1292 |
return true; |
1203 |
} |
1293 |
} |
1204 |
|
1294 |
|
1205 |
// ------------------------------------------------------------------- |
1295 |
// ------------------------------------------------------------------- |
1206 |
// UNLOCK |
1296 |
// UNLOCK called from external (DAVResourceAccess) |
1207 |
// ------------------------------------------------------------------- |
1297 |
// ------------------------------------------------------------------- |
1208 |
void SerfSession::UNLOCK( const ::rtl::OUString & /*inPath*/, |
1298 |
void SerfSession::UNLOCK( const ::rtl::OUString & inPath, |
1209 |
const DAVRequestEnvironment & /*rEnv*/ ) |
1299 |
const DAVRequestEnvironment & rEnv ) |
1210 |
throw ( DAVException ) |
1300 |
throw ( DAVException ) |
1211 |
{ |
1301 |
{ |
1212 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
1302 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
1213 |
|
1303 |
|
1214 |
/* |
1304 |
rtl::OUString aUri( composeCurrentUri( inPath ) ); |
1215 |
// get the neon lock from lock store |
1305 |
SerfLock * pLock = m_aSerfLockStore.findByUri( aUri ); |
1216 |
SerfLock * theLock |
1306 |
if ( !pLock ) |
1217 |
= m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); |
1307 |
{ |
1218 |
if ( !theLock ) |
|
|
1219 |
throw DAVException( DAVException::DAV_NOT_LOCKED ); |
1308 |
throw DAVException( DAVException::DAV_NOT_LOCKED ); |
|
|
1309 |
} |
1220 |
|
1310 |
|
1221 |
Init( rEnv ); |
1311 |
Init( rEnv ); |
1222 |
|
1312 |
|
1223 |
int theRetVal = ne_unlock( m_pHttpSession, theLock ); |
1313 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
|
|
1314 |
apr_status_t status = APR_SUCCESS; |
1224 |
|
1315 |
|
1225 |
if ( theRetVal == NE_OK ) |
1316 |
ucb::Lock inLock = pLock->getLock(); |
1226 |
{ |
1317 |
//remove lock from lockstore |
1227 |
m_aSerfLockStore.removeLock( theLock ); |
1318 |
// so, if something goes wrong, we don't refresh it anymore |
1228 |
ne_lock_destroy( theLock ); |
1319 |
m_aSerfLockStore.removeLock(pLock); |
1229 |
} |
1320 |
delete pLock; |
1230 |
else |
|
|
1231 |
{ |
1232 |
OSL_TRACE( "SerfSession::UNLOCK: unlocking of %s failed.", |
1233 |
rtl::OUStringToOString( makeAbsoluteURL( inPath ), |
1234 |
RTL_TEXTENCODING_UTF8 ).getStr() ); |
1235 |
} |
1236 |
|
1321 |
|
1237 |
HandleError( theRetVal, inPath, rEnv ); |
1322 |
// remove existing lock |
1238 |
*/ |
1323 |
aReqProc->processUnlock( inPath, inLock, status); |
|
|
1324 |
|
1325 |
//HandleError will handle the error and throw an exception, if needed |
1326 |
HandleError( aReqProc ); |
1239 |
} |
1327 |
} |
1240 |
|
1328 |
|
1241 |
// ------------------------------------------------------------------- |
1329 |
// ------------------------------------------------------------------- |
1242 |
// UNLOCK |
1330 |
// UNLOCK (called from SerfLockStore) |
1243 |
// ------------------------------------------------------------------- |
1331 |
// ------------------------------------------------------------------- |
1244 |
bool SerfSession::UNLOCK( SerfLock * /*pLock*/ ) |
1332 |
bool SerfSession::UNLOCK( SerfLock * pLock ) |
1245 |
{ |
1333 |
{ |
1246 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
1334 |
osl::Guard< osl::Mutex > theGuard( m_aMutex ); |
|
|
1335 |
rtl::OUString inPath = pLock->getResourcePath(); |
1336 |
|
1337 |
boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); |
1338 |
apr_status_t status = APR_SUCCESS; |
1339 |
|
1340 |
rtl::OUString aToken; |
1341 |
aToken = pLock->getLock().LockTokens[0]; |
1342 |
|
1343 |
aReqProc->processUnlock( inPath, pLock->getLock(), status); |
1344 |
|
1345 |
//HandleError will handle the error and throw an exception, if needed |
1346 |
HandleError( aReqProc ); |
1247 |
|
1347 |
|
1248 |
return true; |
1348 |
return true; |
1249 |
/* |
|
|
1250 |
if ( ne_unlock( m_pHttpSession, pLock ) == NE_OK ) |
1251 |
{ |
1252 |
OSL_TRACE( "UNLOCK succeeded." ); |
1253 |
return true; |
1254 |
} |
1255 |
else |
1256 |
{ |
1257 |
OSL_TRACE( "UNLOCK failed!" ); |
1258 |
return false; |
1259 |
} |
1260 |
*/ |
1261 |
} |
1349 |
} |
1262 |
|
1350 |
|
1263 |
// ------------------------------------------------------------------- |
1351 |
// ------------------------------------------------------------------- |
Lines 1315-1320
bool containsLocktoken( const uno::Sequence< ucb::Lock > & rLocks,
Link Here
|
1315 |
*/ |
1403 |
*/ |
1316 |
|
1404 |
|
1317 |
// ------------------------------------------------------------------- |
1405 |
// ------------------------------------------------------------------- |
|
|
1406 |
// This method doesn't seem to be used. |
1407 |
// In any case the default behavior is to ask a lock whith a life of 3 minutes |
1408 |
// it will then be refreshed automatically (see SerfLockStore class) |
1409 |
// In case of AOO crash the lock will expire by itself |
1318 |
bool SerfSession::removeExpiredLocktoken( const rtl::OUString & /*inURL*/, |
1410 |
bool SerfSession::removeExpiredLocktoken( const rtl::OUString & /*inURL*/, |
1319 |
const DAVRequestEnvironment & /*rEnv*/ ) |
1411 |
const DAVRequestEnvironment & /*rEnv*/ ) |
1320 |
{ |
1412 |
{ |
Lines 1612-1648
SerfSession::isDomainMatch( rtl::OUString certHostName )
Link Here
|
1612 |
} |
1704 |
} |
1613 |
return sal_False; |
1705 |
return sal_False; |
1614 |
} |
1706 |
} |
1615 |
|
|
|
1616 |
/* |
1617 |
// --------------------------------------------------------------------- |
1618 |
rtl::OUString SerfSession::makeAbsoluteURL( rtl::OUString const & rURL ) const |
1619 |
{ |
1620 |
try |
1621 |
{ |
1622 |
// Is URL relative or already absolute? |
1623 |
if ( rURL[ 0 ] != sal_Unicode( '/' ) ) |
1624 |
{ |
1625 |
// absolute. |
1626 |
return rtl::OUString( rURL ); |
1627 |
} |
1628 |
else |
1629 |
{ |
1630 |
ne_uri aUri; |
1631 |
memset( &aUri, 0, sizeof( aUri ) ); |
1632 |
|
1633 |
ne_fill_server_uri( m_pHttpSession, &aUri ); |
1634 |
aUri.path |
1635 |
= ne_strdup( rtl::OUStringToOString( |
1636 |
rURL, RTL_TEXTENCODING_UTF8 ).getStr() ); |
1637 |
SerfUri aSerfUri( &aUri ); |
1638 |
ne_uri_free( &aUri ); |
1639 |
return aSerfUri.GetURI(); |
1640 |
} |
1641 |
} |
1642 |
catch ( DAVException const & ) |
1643 |
{ |
1644 |
} |
1645 |
// error. |
1646 |
return rtl::OUString(); |
1647 |
} |
1648 |
*/ |