1*8590a0fdSAndre Fischer /************************************************************** 2*8590a0fdSAndre Fischer * 3*8590a0fdSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*8590a0fdSAndre Fischer * or more contributor license agreements. See the NOTICE file 5*8590a0fdSAndre Fischer * distributed with this work for additional information 6*8590a0fdSAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*8590a0fdSAndre Fischer * to you under the Apache License, Version 2.0 (the 8*8590a0fdSAndre Fischer * "License"); you may not use this file except in compliance 9*8590a0fdSAndre Fischer * with the License. You may obtain a copy of the License at 10*8590a0fdSAndre Fischer * 11*8590a0fdSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*8590a0fdSAndre Fischer * 13*8590a0fdSAndre Fischer * Unless required by applicable law or agreed to in writing, 14*8590a0fdSAndre Fischer * software distributed under the License is distributed on an 15*8590a0fdSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*8590a0fdSAndre Fischer * KIND, either express or implied. See the License for the 17*8590a0fdSAndre Fischer * specific language governing permissions and limitations 18*8590a0fdSAndre Fischer * under the License. 19*8590a0fdSAndre Fischer * 20*8590a0fdSAndre Fischer *************************************************************/ 21*8590a0fdSAndre Fischer 22*8590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove 23*8590a0fdSAndre Fischer #include "precompiled_ucb.hxx" 24*8590a0fdSAndre Fischer 25*8590a0fdSAndre Fischer #include <hash_map> 26*8590a0fdSAndre Fischer #include <vector> 27*8590a0fdSAndre Fischer #include <string.h> 28*8590a0fdSAndre Fischer #include <rtl/string.h> 29*8590a0fdSAndre Fischer #include "comphelper/sequence.hxx" 30*8590a0fdSAndre Fischer #include "ucbhelper/simplecertificatevalidationrequest.hxx" 31*8590a0fdSAndre Fischer 32*8590a0fdSAndre Fischer #include <AprEnv.hxx> 33*8590a0fdSAndre Fischer #include <apr_strings.h> 34*8590a0fdSAndre Fischer 35*8590a0fdSAndre Fischer #include "DAVAuthListener.hxx" 36*8590a0fdSAndre Fischer #include <SerfTypes.hxx> 37*8590a0fdSAndre Fischer #include <SerfSession.hxx> 38*8590a0fdSAndre Fischer #include <SerfUri.hxx> 39*8590a0fdSAndre Fischer #include <SerfRequestProcessor.hxx> 40*8590a0fdSAndre Fischer #include <SerfCallbacks.hxx> 41*8590a0fdSAndre Fischer #include <SerfInputStream.hxx> 42*8590a0fdSAndre Fischer #include <UCBDeadPropertyValue.hxx> 43*8590a0fdSAndre Fischer 44*8590a0fdSAndre Fischer #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> 45*8590a0fdSAndre Fischer #include <com/sun/star/security/XCertificate.hpp> 46*8590a0fdSAndre Fischer #include <com/sun/star/security/CertificateValidity.hpp> 47*8590a0fdSAndre Fischer #include <com/sun/star/security/CertificateContainerStatus.hpp> 48*8590a0fdSAndre Fischer #include <com/sun/star/security/CertificateContainer.hpp> 49*8590a0fdSAndre Fischer #include <com/sun/star/security/XCertificateContainer.hpp> 50*8590a0fdSAndre Fischer #include <com/sun/star/ucb/Lock.hpp> 51*8590a0fdSAndre Fischer #include <com/sun/star/xml/crypto/XSEInitializer.hpp> 52*8590a0fdSAndre Fischer 53*8590a0fdSAndre Fischer using namespace com::sun::star; 54*8590a0fdSAndre Fischer using namespace http_dav_ucp; 55*8590a0fdSAndre Fischer 56*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 57*8590a0fdSAndre Fischer // static members! 58*8590a0fdSAndre Fischer bool SerfSession::m_bGlobalsInited = false; 59*8590a0fdSAndre Fischer osl::Mutex SerfSession::m_aGlobalMutex; 60*8590a0fdSAndre Fischer //SerfLockStore SerfSession::m_aSerfLockStore; 61*8590a0fdSAndre Fischer 62*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 63*8590a0fdSAndre Fischer // Constructor 64*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 65*8590a0fdSAndre Fischer SerfSession::SerfSession( 66*8590a0fdSAndre Fischer const rtl::Reference< DAVSessionFactory > & rSessionFactory, 67*8590a0fdSAndre Fischer const rtl::OUString& inUri, 68*8590a0fdSAndre Fischer const ucbhelper::InternetProxyDecider & rProxyDecider ) 69*8590a0fdSAndre Fischer throw ( DAVException ) 70*8590a0fdSAndre Fischer : DAVSession( rSessionFactory ) 71*8590a0fdSAndre Fischer , m_aMutex() 72*8590a0fdSAndre Fischer , m_aUri( inUri ) 73*8590a0fdSAndre Fischer , m_aProxyName() 74*8590a0fdSAndre Fischer , m_nProxyPort( 0 ) 75*8590a0fdSAndre Fischer , m_pSerfConnection( 0 ) 76*8590a0fdSAndre Fischer , m_pSerfContext( 0 ) 77*8590a0fdSAndre Fischer , m_bIsHeadRequestInProgress( false ) 78*8590a0fdSAndre Fischer , m_rProxyDecider( rProxyDecider ) 79*8590a0fdSAndre Fischer , m_aEnv() 80*8590a0fdSAndre Fischer { 81*8590a0fdSAndre Fischer m_pSerfContext = serf_context_create( getAprPool() ); 82*8590a0fdSAndre Fischer 83*8590a0fdSAndre Fischer m_pSerfBucket_Alloc = serf_bucket_allocator_create( getAprPool(), NULL, NULL ); 84*8590a0fdSAndre Fischer } 85*8590a0fdSAndre Fischer 86*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 87*8590a0fdSAndre Fischer // Destructor 88*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 89*8590a0fdSAndre Fischer SerfSession::~SerfSession( ) 90*8590a0fdSAndre Fischer { 91*8590a0fdSAndre Fischer if ( m_pSerfConnection ) 92*8590a0fdSAndre Fischer { 93*8590a0fdSAndre Fischer serf_connection_close( m_pSerfConnection ); 94*8590a0fdSAndre Fischer m_pSerfConnection = 0; 95*8590a0fdSAndre Fischer } 96*8590a0fdSAndre Fischer } 97*8590a0fdSAndre Fischer 98*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 99*8590a0fdSAndre Fischer void SerfSession::Init( const DAVRequestEnvironment & rEnv ) 100*8590a0fdSAndre Fischer throw ( DAVException ) 101*8590a0fdSAndre Fischer { 102*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 103*8590a0fdSAndre Fischer m_aEnv = rEnv; 104*8590a0fdSAndre Fischer Init(); 105*8590a0fdSAndre Fischer } 106*8590a0fdSAndre Fischer 107*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 108*8590a0fdSAndre Fischer void SerfSession::Init() 109*8590a0fdSAndre Fischer throw ( DAVException ) 110*8590a0fdSAndre Fischer { 111*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 112*8590a0fdSAndre Fischer 113*8590a0fdSAndre Fischer bool bCreateNewSession = false; 114*8590a0fdSAndre Fischer 115*8590a0fdSAndre Fischer if ( m_pSerfConnection == 0 ) 116*8590a0fdSAndre Fischer { 117*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGlobalGuard( m_aGlobalMutex ); 118*8590a0fdSAndre Fischer // <-- 119*8590a0fdSAndre Fischer if ( !m_bGlobalsInited ) 120*8590a0fdSAndre Fischer { 121*8590a0fdSAndre Fischer // TODO - figure out, if anything has to be done here 122*8590a0fdSAndre Fischer m_bGlobalsInited = true; 123*8590a0fdSAndre Fischer } 124*8590a0fdSAndre Fischer 125*8590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & rProxyCfg = getProxySettings(); 126*8590a0fdSAndre Fischer 127*8590a0fdSAndre Fischer m_aProxyName = rProxyCfg.aName; 128*8590a0fdSAndre Fischer m_nProxyPort = rProxyCfg.nPort; 129*8590a0fdSAndre Fischer 130*8590a0fdSAndre Fischer // Not yet initialized. Create new session. 131*8590a0fdSAndre Fischer bCreateNewSession = true; 132*8590a0fdSAndre Fischer } 133*8590a0fdSAndre Fischer else 134*8590a0fdSAndre Fischer { 135*8590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & rProxyCfg = getProxySettings(); 136*8590a0fdSAndre Fischer 137*8590a0fdSAndre Fischer if ( ( rProxyCfg.aName != m_aProxyName ) 138*8590a0fdSAndre Fischer || ( rProxyCfg.nPort != m_nProxyPort ) ) 139*8590a0fdSAndre Fischer { 140*8590a0fdSAndre Fischer m_aProxyName = rProxyCfg.aName; 141*8590a0fdSAndre Fischer m_nProxyPort = rProxyCfg.nPort; 142*8590a0fdSAndre Fischer 143*8590a0fdSAndre Fischer // new session needed, destroy old first 144*8590a0fdSAndre Fischer serf_connection_close( m_pSerfConnection ); 145*8590a0fdSAndre Fischer m_pSerfConnection = 0; 146*8590a0fdSAndre Fischer bCreateNewSession = true; 147*8590a0fdSAndre Fischer } 148*8590a0fdSAndre Fischer } 149*8590a0fdSAndre Fischer 150*8590a0fdSAndre Fischer if ( bCreateNewSession ) 151*8590a0fdSAndre Fischer { 152*8590a0fdSAndre Fischer // TODO - close_connection callback 153*8590a0fdSAndre Fischer apr_status_t status = serf_connection_create2( &m_pSerfConnection, 154*8590a0fdSAndre Fischer m_pSerfContext, 155*8590a0fdSAndre Fischer *(m_aUri.getAprUri()), 156*8590a0fdSAndre Fischer Serf_ConnectSetup, this, 157*8590a0fdSAndre Fischer 0 /* close connection callback */, 0 /* close connection baton */, 158*8590a0fdSAndre Fischer getAprPool() ); 159*8590a0fdSAndre Fischer 160*8590a0fdSAndre Fischer if ( m_pSerfConnection == 0 ||status != APR_SUCCESS ) 161*8590a0fdSAndre Fischer { 162*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_SESSION_CREATE, 163*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( m_aUri.GetHost(), m_aUri.GetPort() ) ); 164*8590a0fdSAndre Fischer } 165*8590a0fdSAndre Fischer 166*8590a0fdSAndre Fischer // Register the session with the lock store 167*8590a0fdSAndre Fischer // m_aSerfLockStore.registerSession( m_pSerfConnection ); 168*8590a0fdSAndre Fischer 169*8590a0fdSAndre Fischer if ( m_aProxyName.getLength() ) 170*8590a0fdSAndre Fischer { 171*8590a0fdSAndre Fischer apr_sockaddr_t *proxy_address = NULL; 172*8590a0fdSAndre Fischer const apr_status_t status = apr_sockaddr_info_get( &proxy_address, 173*8590a0fdSAndre Fischer rtl::OUStringToOString( m_aProxyName, RTL_TEXTENCODING_UTF8 ), 174*8590a0fdSAndre Fischer APR_UNSPEC, 175*8590a0fdSAndre Fischer static_cast<apr_port_t>(m_nProxyPort), 176*8590a0fdSAndre Fischer 0, getAprPool() ); 177*8590a0fdSAndre Fischer 178*8590a0fdSAndre Fischer if ( status != APR_SUCCESS ) 179*8590a0fdSAndre Fischer { 180*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_SESSION_CREATE, 181*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( m_aUri.GetHost(), m_aUri.GetPort() ) ); 182*8590a0fdSAndre Fischer } 183*8590a0fdSAndre Fischer 184*8590a0fdSAndre Fischer serf_config_proxy( m_pSerfContext, proxy_address ); 185*8590a0fdSAndre Fischer } 186*8590a0fdSAndre Fischer 187*8590a0fdSAndre Fischer 188*8590a0fdSAndre Fischer serf_config_credentials_callback( m_pSerfContext, Serf_Credentials ); 189*8590a0fdSAndre Fischer } 190*8590a0fdSAndre Fischer } 191*8590a0fdSAndre Fischer 192*8590a0fdSAndre Fischer apr_pool_t* SerfSession::getAprPool() 193*8590a0fdSAndre Fischer { 194*8590a0fdSAndre Fischer return apr_environment::AprEnv::getAprEnv()->getAprPool(); 195*8590a0fdSAndre Fischer } 196*8590a0fdSAndre Fischer 197*8590a0fdSAndre Fischer serf_bucket_alloc_t* SerfSession::getSerfBktAlloc() 198*8590a0fdSAndre Fischer { 199*8590a0fdSAndre Fischer return m_pSerfBucket_Alloc; 200*8590a0fdSAndre Fischer } 201*8590a0fdSAndre Fischer 202*8590a0fdSAndre Fischer serf_context_t* SerfSession::getSerfContext() 203*8590a0fdSAndre Fischer { 204*8590a0fdSAndre Fischer return m_pSerfContext; 205*8590a0fdSAndre Fischer } 206*8590a0fdSAndre Fischer 207*8590a0fdSAndre Fischer SerfConnection* SerfSession::getSerfConnection() 208*8590a0fdSAndre Fischer { 209*8590a0fdSAndre Fischer return m_pSerfConnection; 210*8590a0fdSAndre Fischer } 211*8590a0fdSAndre Fischer 212*8590a0fdSAndre Fischer bool SerfSession::isHeadRequestInProgress() 213*8590a0fdSAndre Fischer { 214*8590a0fdSAndre Fischer return m_bIsHeadRequestInProgress; 215*8590a0fdSAndre Fischer } 216*8590a0fdSAndre Fischer 217*8590a0fdSAndre Fischer bool SerfSession::isSSLNeeded() 218*8590a0fdSAndre Fischer { 219*8590a0fdSAndre Fischer return m_aUri.GetScheme().equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "https" ) ) ); 220*8590a0fdSAndre Fischer } 221*8590a0fdSAndre Fischer 222*8590a0fdSAndre Fischer char* SerfSession::getHostinfo() 223*8590a0fdSAndre Fischer { 224*8590a0fdSAndre Fischer return m_aUri.getAprUri()->hostinfo; 225*8590a0fdSAndre Fischer } 226*8590a0fdSAndre Fischer 227*8590a0fdSAndre Fischer 228*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 229*8590a0fdSAndre Fischer // virtual 230*8590a0fdSAndre Fischer sal_Bool SerfSession::CanUse( const rtl::OUString & inUri ) 231*8590a0fdSAndre Fischer { 232*8590a0fdSAndre Fischer try 233*8590a0fdSAndre Fischer { 234*8590a0fdSAndre Fischer SerfUri theUri( inUri ); 235*8590a0fdSAndre Fischer if ( ( theUri.GetPort() == m_aUri.GetPort() ) && 236*8590a0fdSAndre Fischer ( theUri.GetHost() == m_aUri.GetHost() ) && 237*8590a0fdSAndre Fischer ( theUri.GetScheme() == m_aUri.GetScheme() ) ) 238*8590a0fdSAndre Fischer { 239*8590a0fdSAndre Fischer return sal_True; 240*8590a0fdSAndre Fischer } 241*8590a0fdSAndre Fischer } 242*8590a0fdSAndre Fischer catch ( DAVException const & ) 243*8590a0fdSAndre Fischer { 244*8590a0fdSAndre Fischer return sal_False; 245*8590a0fdSAndre Fischer } 246*8590a0fdSAndre Fischer return sal_False; 247*8590a0fdSAndre Fischer } 248*8590a0fdSAndre Fischer 249*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 250*8590a0fdSAndre Fischer // virtual 251*8590a0fdSAndre Fischer sal_Bool SerfSession::UsesProxy() 252*8590a0fdSAndre Fischer { 253*8590a0fdSAndre Fischer Init(); 254*8590a0fdSAndre Fischer return ( m_aProxyName.getLength() > 0 ); 255*8590a0fdSAndre Fischer } 256*8590a0fdSAndre Fischer 257*8590a0fdSAndre Fischer apr_status_t SerfSession::setupSerfConnection( apr_socket_t * inAprSocket, 258*8590a0fdSAndre Fischer serf_bucket_t **outSerfInputBucket, 259*8590a0fdSAndre Fischer serf_bucket_t **outSerfOutputBucket, 260*8590a0fdSAndre Fischer apr_pool_t* /*inAprPool*/ ) 261*8590a0fdSAndre Fischer { 262*8590a0fdSAndre Fischer serf_bucket_t *tmpInputBkt; 263*8590a0fdSAndre Fischer tmpInputBkt = serf_context_bucket_socket_create( getSerfContext(), 264*8590a0fdSAndre Fischer inAprSocket, 265*8590a0fdSAndre Fischer getSerfBktAlloc() ); 266*8590a0fdSAndre Fischer 267*8590a0fdSAndre Fischer if ( isSSLNeeded() ) 268*8590a0fdSAndre Fischer { 269*8590a0fdSAndre Fischer tmpInputBkt = serf_bucket_ssl_decrypt_create( tmpInputBkt, 270*8590a0fdSAndre Fischer 0, 271*8590a0fdSAndre Fischer getSerfBktAlloc() ); 272*8590a0fdSAndre Fischer serf_ssl_server_cert_callback_set( serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), 273*8590a0fdSAndre Fischer Serf_CertificationValidation, 274*8590a0fdSAndre Fischer this ); 275*8590a0fdSAndre Fischer serf_ssl_set_hostname( serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), 276*8590a0fdSAndre Fischer getHostinfo() ); 277*8590a0fdSAndre Fischer 278*8590a0fdSAndre Fischer *outSerfOutputBucket = serf_bucket_ssl_encrypt_create( *outSerfOutputBucket, 279*8590a0fdSAndre Fischer serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), 280*8590a0fdSAndre Fischer getSerfBktAlloc() ); 281*8590a0fdSAndre Fischer } 282*8590a0fdSAndre Fischer 283*8590a0fdSAndre Fischer *outSerfInputBucket = tmpInputBkt; 284*8590a0fdSAndre Fischer 285*8590a0fdSAndre Fischer return APR_SUCCESS; 286*8590a0fdSAndre Fischer } 287*8590a0fdSAndre Fischer 288*8590a0fdSAndre Fischer apr_status_t SerfSession::provideSerfCredentials( char ** outUsername, 289*8590a0fdSAndre Fischer char ** outPassword, 290*8590a0fdSAndre Fischer serf_request_t * /*inRequest*/, 291*8590a0fdSAndre Fischer int /*inCode*/, 292*8590a0fdSAndre Fischer const char *inAuthProtocol, 293*8590a0fdSAndre Fischer const char *inRealm, 294*8590a0fdSAndre Fischer apr_pool_t *inAprPool ) 295*8590a0fdSAndre Fischer { 296*8590a0fdSAndre Fischer DAVAuthListener * pListener = getRequestEnvironment().m_xAuthListener.get(); 297*8590a0fdSAndre Fischer if ( !pListener ) 298*8590a0fdSAndre Fischer { 299*8590a0fdSAndre Fischer // abort 300*8590a0fdSAndre Fischer return SERF_ERROR_AUTHN_FAILED; 301*8590a0fdSAndre Fischer } 302*8590a0fdSAndre Fischer 303*8590a0fdSAndre Fischer rtl::OUString theUserName; 304*8590a0fdSAndre Fischer rtl::OUString thePassWord; 305*8590a0fdSAndre Fischer try 306*8590a0fdSAndre Fischer { 307*8590a0fdSAndre Fischer SerfUri uri( getRequestEnvironment().m_aRequestURI ); 308*8590a0fdSAndre Fischer rtl::OUString aUserInfo( uri.GetUserInfo() ); 309*8590a0fdSAndre Fischer if ( aUserInfo.getLength() ) 310*8590a0fdSAndre Fischer { 311*8590a0fdSAndre Fischer sal_Int32 nPos = aUserInfo.indexOf( '@' ); 312*8590a0fdSAndre Fischer if ( nPos == -1 ) 313*8590a0fdSAndre Fischer { 314*8590a0fdSAndre Fischer theUserName = aUserInfo; 315*8590a0fdSAndre Fischer } 316*8590a0fdSAndre Fischer else 317*8590a0fdSAndre Fischer { 318*8590a0fdSAndre Fischer theUserName = aUserInfo.copy( 0, nPos ); 319*8590a0fdSAndre Fischer thePassWord = aUserInfo.copy( nPos + 1 ); 320*8590a0fdSAndre Fischer } 321*8590a0fdSAndre Fischer } 322*8590a0fdSAndre Fischer } 323*8590a0fdSAndre Fischer catch ( DAVException const & ) 324*8590a0fdSAndre Fischer { 325*8590a0fdSAndre Fischer // abort 326*8590a0fdSAndre Fischer return SERF_ERROR_AUTHN_FAILED; 327*8590a0fdSAndre Fischer } 328*8590a0fdSAndre Fischer 329*8590a0fdSAndre Fischer const bool bCanUseSystemCreds = ( ( strcasecmp( inAuthProtocol, "NTLM" ) == 0 ) || 330*8590a0fdSAndre Fischer ( strcasecmp( inAuthProtocol, "Negotiate" ) == 0 ) ); 331*8590a0fdSAndre Fischer 332*8590a0fdSAndre Fischer int theRetVal = pListener->authenticate( rtl::OUString::createFromAscii( inRealm ), 333*8590a0fdSAndre Fischer getHostName(), 334*8590a0fdSAndre Fischer theUserName, 335*8590a0fdSAndre Fischer thePassWord, 336*8590a0fdSAndre Fischer bCanUseSystemCreds ); 337*8590a0fdSAndre Fischer 338*8590a0fdSAndre Fischer if ( theRetVal == 0 ) 339*8590a0fdSAndre Fischer { 340*8590a0fdSAndre Fischer *outUsername = apr_pstrdup( inAprPool, rtl::OUStringToOString( theUserName, RTL_TEXTENCODING_UTF8 ) ); 341*8590a0fdSAndre Fischer *outPassword = apr_pstrdup( inAprPool, rtl::OUStringToOString( thePassWord, RTL_TEXTENCODING_UTF8 ) ); 342*8590a0fdSAndre Fischer } 343*8590a0fdSAndre Fischer 344*8590a0fdSAndre Fischer return theRetVal != 0 ? SERF_ERROR_AUTHN_FAILED : APR_SUCCESS; 345*8590a0fdSAndre Fischer } 346*8590a0fdSAndre Fischer 347*8590a0fdSAndre Fischer namespace { 348*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 349*8590a0fdSAndre Fischer // Helper function 350*8590a0fdSAndre Fischer ::rtl::OUString GetHostnamePart( const ::rtl::OUString& _rRawString ) 351*8590a0fdSAndre Fischer { 352*8590a0fdSAndre Fischer ::rtl::OUString sPart; 353*8590a0fdSAndre Fischer ::rtl::OUString sPartId = ::rtl::OUString::createFromAscii( "CN=" ); 354*8590a0fdSAndre Fischer sal_Int32 nContStart = _rRawString.indexOf( sPartId ); 355*8590a0fdSAndre Fischer if ( nContStart != -1 ) 356*8590a0fdSAndre Fischer { 357*8590a0fdSAndre Fischer nContStart = nContStart + sPartId.getLength(); 358*8590a0fdSAndre Fischer sal_Int32 nContEnd 359*8590a0fdSAndre Fischer = _rRawString.indexOf( sal_Unicode( ',' ), nContStart ); 360*8590a0fdSAndre Fischer sPart = _rRawString.copy( nContStart, nContEnd - nContStart ); 361*8590a0fdSAndre Fischer } 362*8590a0fdSAndre Fischer return sPart; 363*8590a0fdSAndre Fischer } 364*8590a0fdSAndre Fischer } // namespace 365*8590a0fdSAndre Fischer 366*8590a0fdSAndre Fischer apr_status_t SerfSession::verifySerfCertificate( int inFailures, 367*8590a0fdSAndre Fischer const serf_ssl_certificate_t * inCert ) 368*8590a0fdSAndre Fischer { 369*8590a0fdSAndre Fischer OSL_ASSERT( inCert ); 370*8590a0fdSAndre Fischer 371*8590a0fdSAndre Fischer uno::Reference< security::XCertificateContainer > xCertificateContainer; 372*8590a0fdSAndre Fischer try 373*8590a0fdSAndre Fischer { 374*8590a0fdSAndre Fischer xCertificateContainer 375*8590a0fdSAndre Fischer = uno::Reference< security::XCertificateContainer >( 376*8590a0fdSAndre Fischer getMSF()->createInstance( 377*8590a0fdSAndre Fischer rtl::OUString::createFromAscii( 378*8590a0fdSAndre Fischer "com.sun.star.security.CertificateContainer" ) ), 379*8590a0fdSAndre Fischer uno::UNO_QUERY ); 380*8590a0fdSAndre Fischer } 381*8590a0fdSAndre Fischer catch ( uno::Exception const & ) 382*8590a0fdSAndre Fischer { 383*8590a0fdSAndre Fischer } 384*8590a0fdSAndre Fischer 385*8590a0fdSAndre Fischer if ( !xCertificateContainer.is() ) 386*8590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 387*8590a0fdSAndre Fischer 388*8590a0fdSAndre Fischer inFailures = 0; 389*8590a0fdSAndre Fischer 390*8590a0fdSAndre Fischer const char * subjectItem = static_cast<char*>(apr_hash_get( serf_ssl_cert_subject( inCert, getAprPool() ), 391*8590a0fdSAndre Fischer "CN", APR_HASH_KEY_STRING )); 392*8590a0fdSAndre Fischer if ( subjectItem == 0 ) 393*8590a0fdSAndre Fischer { 394*8590a0fdSAndre Fischer subjectItem = static_cast<char*>(apr_hash_get( serf_ssl_cert_subject( inCert, getAprPool() ), 395*8590a0fdSAndre Fischer "OU", APR_HASH_KEY_STRING )); 396*8590a0fdSAndre Fischer } 397*8590a0fdSAndre Fischer rtl::OUString cert_subject; 398*8590a0fdSAndre Fischer if ( subjectItem != 0 ) 399*8590a0fdSAndre Fischer { 400*8590a0fdSAndre Fischer cert_subject = rtl::OUString( subjectItem, strlen( subjectItem ), RTL_TEXTENCODING_UTF8, 0 ); 401*8590a0fdSAndre Fischer } 402*8590a0fdSAndre Fischer else 403*8590a0fdSAndre Fischer { 404*8590a0fdSAndre Fischer rtl::OUString::createFromAscii( "unknown subject" ); 405*8590a0fdSAndre Fischer } 406*8590a0fdSAndre Fischer 407*8590a0fdSAndre Fischer security::CertificateContainerStatus certificateContainer( 408*8590a0fdSAndre Fischer xCertificateContainer->hasCertificate( 409*8590a0fdSAndre Fischer getHostName(), cert_subject ) ); 410*8590a0fdSAndre Fischer 411*8590a0fdSAndre Fischer if ( certificateContainer != security::CertificateContainerStatus_NOCERT ) 412*8590a0fdSAndre Fischer { 413*8590a0fdSAndre Fischer return certificateContainer == security::CertificateContainerStatus_TRUSTED 414*8590a0fdSAndre Fischer ? APR_SUCCESS 415*8590a0fdSAndre Fischer : SERF_SSL_CERT_UNKNOWN_FAILURE; 416*8590a0fdSAndre Fischer } 417*8590a0fdSAndre Fischer 418*8590a0fdSAndre Fischer uno::Reference< xml::crypto::XSEInitializer > xSEInitializer; 419*8590a0fdSAndre Fischer try 420*8590a0fdSAndre Fischer { 421*8590a0fdSAndre Fischer xSEInitializer = uno::Reference< xml::crypto::XSEInitializer >( 422*8590a0fdSAndre Fischer getMSF()->createInstance( 423*8590a0fdSAndre Fischer rtl::OUString::createFromAscii( "com.sun.star.xml.crypto.SEInitializer" ) ), 424*8590a0fdSAndre Fischer uno::UNO_QUERY ); 425*8590a0fdSAndre Fischer } 426*8590a0fdSAndre Fischer catch ( uno::Exception const & ) 427*8590a0fdSAndre Fischer { 428*8590a0fdSAndre Fischer } 429*8590a0fdSAndre Fischer 430*8590a0fdSAndre Fischer if ( !xSEInitializer.is() ) 431*8590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 432*8590a0fdSAndre Fischer 433*8590a0fdSAndre Fischer uno::Reference< xml::crypto::XXMLSecurityContext > xSecurityContext( 434*8590a0fdSAndre Fischer xSEInitializer->createSecurityContext( rtl::OUString() ) ); 435*8590a0fdSAndre Fischer 436*8590a0fdSAndre Fischer uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnv( 437*8590a0fdSAndre Fischer xSecurityContext->getSecurityEnvironment() ); 438*8590a0fdSAndre Fischer 439*8590a0fdSAndre Fischer //The end entity certificate 440*8590a0fdSAndre Fischer const char * eeCertB64 = serf_ssl_cert_export( inCert, getAprPool() ); 441*8590a0fdSAndre Fischer 442*8590a0fdSAndre Fischer rtl::OString sEECertB64( eeCertB64 ); 443*8590a0fdSAndre Fischer 444*8590a0fdSAndre Fischer uno::Reference< security::XCertificate > xEECert( 445*8590a0fdSAndre Fischer xSecurityEnv->createCertificateFromAscii( 446*8590a0fdSAndre Fischer rtl::OStringToOUString( sEECertB64, RTL_TEXTENCODING_ASCII_US ) ) ); 447*8590a0fdSAndre Fischer 448*8590a0fdSAndre Fischer std::vector< uno::Reference< security::XCertificate > > vecCerts; 449*8590a0fdSAndre Fischer const serf_ssl_certificate_t * issuerCert = inCert; 450*8590a0fdSAndre Fischer do 451*8590a0fdSAndre Fischer { 452*8590a0fdSAndre Fischer //get the intermediate certificate 453*8590a0fdSAndre Fischer issuerCert = NULL; // TODO - figure out how to retrieve certificate chain - ssl_cert_signedby( issuerCert ); 454*8590a0fdSAndre Fischer if ( NULL == issuerCert ) 455*8590a0fdSAndre Fischer break; 456*8590a0fdSAndre Fischer 457*8590a0fdSAndre Fischer const char * imCertB64 = serf_ssl_cert_export( issuerCert, getAprPool() ); 458*8590a0fdSAndre Fischer rtl::OString sInterMediateCertB64( imCertB64 ); 459*8590a0fdSAndre Fischer 460*8590a0fdSAndre Fischer uno::Reference< security::XCertificate> xImCert( 461*8590a0fdSAndre Fischer xSecurityEnv->createCertificateFromAscii( 462*8590a0fdSAndre Fischer rtl::OStringToOUString( 463*8590a0fdSAndre Fischer sInterMediateCertB64, RTL_TEXTENCODING_ASCII_US ) ) ); 464*8590a0fdSAndre Fischer if ( xImCert.is() ) 465*8590a0fdSAndre Fischer vecCerts.push_back( xImCert ); 466*8590a0fdSAndre Fischer } 467*8590a0fdSAndre Fischer while ( 1 ); 468*8590a0fdSAndre Fischer 469*8590a0fdSAndre Fischer sal_Int64 certValidity = xSecurityEnv->verifyCertificate( xEECert, 470*8590a0fdSAndre Fischer ::comphelper::containerToSequence( vecCerts ) ); 471*8590a0fdSAndre Fischer 472*8590a0fdSAndre Fischer if ( isDomainMatch( GetHostnamePart( xEECert.get()->getSubjectName() ) ) ) 473*8590a0fdSAndre Fischer { 474*8590a0fdSAndre Fischer // if host name matched with certificate then look if the 475*8590a0fdSAndre Fischer // certificate was ok 476*8590a0fdSAndre Fischer if( certValidity == security::CertificateValidity::VALID ) 477*8590a0fdSAndre Fischer return APR_SUCCESS; 478*8590a0fdSAndre Fischer } 479*8590a0fdSAndre Fischer 480*8590a0fdSAndre Fischer const uno::Reference< ucb::XCommandEnvironment > xEnv( getRequestEnvironment().m_xEnv ); 481*8590a0fdSAndre Fischer if ( xEnv.is() ) 482*8590a0fdSAndre Fischer { 483*8590a0fdSAndre Fischer inFailures = static_cast< int >( certValidity ); 484*8590a0fdSAndre Fischer 485*8590a0fdSAndre Fischer uno::Reference< task::XInteractionHandler > xIH( xEnv->getInteractionHandler() ); 486*8590a0fdSAndre Fischer if ( xIH.is() ) 487*8590a0fdSAndre Fischer { 488*8590a0fdSAndre Fischer rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > 489*8590a0fdSAndre Fischer xRequest( new ucbhelper::SimpleCertificateValidationRequest( 490*8590a0fdSAndre Fischer (sal_Int32)inFailures, xEECert, getHostName() ) ); 491*8590a0fdSAndre Fischer xIH->handle( xRequest.get() ); 492*8590a0fdSAndre Fischer 493*8590a0fdSAndre Fischer rtl::Reference< ucbhelper::InteractionContinuation > xSelection 494*8590a0fdSAndre Fischer = xRequest->getSelection(); 495*8590a0fdSAndre Fischer 496*8590a0fdSAndre Fischer if ( xSelection.is() ) 497*8590a0fdSAndre Fischer { 498*8590a0fdSAndre Fischer uno::Reference< task::XInteractionApprove > xApprove( 499*8590a0fdSAndre Fischer xSelection.get(), uno::UNO_QUERY ); 500*8590a0fdSAndre Fischer if ( xApprove.is() ) 501*8590a0fdSAndre Fischer { 502*8590a0fdSAndre Fischer xCertificateContainer->addCertificate( getHostName(), cert_subject, sal_True ); 503*8590a0fdSAndre Fischer return APR_SUCCESS; 504*8590a0fdSAndre Fischer } 505*8590a0fdSAndre Fischer else 506*8590a0fdSAndre Fischer { 507*8590a0fdSAndre Fischer // Don't trust cert 508*8590a0fdSAndre Fischer xCertificateContainer->addCertificate( getHostName(), cert_subject, sal_False ); 509*8590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 510*8590a0fdSAndre Fischer } 511*8590a0fdSAndre Fischer } 512*8590a0fdSAndre Fischer } 513*8590a0fdSAndre Fischer else 514*8590a0fdSAndre Fischer { 515*8590a0fdSAndre Fischer // Don't trust cert 516*8590a0fdSAndre Fischer xCertificateContainer->addCertificate( getHostName(), cert_subject, sal_False ); 517*8590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 518*8590a0fdSAndre Fischer } 519*8590a0fdSAndre Fischer } 520*8590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 521*8590a0fdSAndre Fischer } 522*8590a0fdSAndre Fischer 523*8590a0fdSAndre Fischer serf_bucket_t* SerfSession::acceptSerfResponse( serf_request_t * inSerfRequest, 524*8590a0fdSAndre Fischer serf_bucket_t * inSerfStreamBucket, 525*8590a0fdSAndre Fischer apr_pool_t* /*inAprPool*/ ) 526*8590a0fdSAndre Fischer { 527*8590a0fdSAndre Fischer // get the per-request bucket allocator 528*8590a0fdSAndre Fischer serf_bucket_alloc_t* SerfBktAlloc = serf_request_get_alloc( inSerfRequest ); 529*8590a0fdSAndre Fischer 530*8590a0fdSAndre Fischer // create a barrier bucket so the response doesn't eat us! 531*8590a0fdSAndre Fischer serf_bucket_t *responseBkt = serf_bucket_barrier_create( inSerfStreamBucket, 532*8590a0fdSAndre Fischer SerfBktAlloc ); 533*8590a0fdSAndre Fischer 534*8590a0fdSAndre Fischer // create response bucket 535*8590a0fdSAndre Fischer responseBkt = serf_bucket_response_create( responseBkt, 536*8590a0fdSAndre Fischer SerfBktAlloc ); 537*8590a0fdSAndre Fischer 538*8590a0fdSAndre Fischer if ( isHeadRequestInProgress() ) 539*8590a0fdSAndre Fischer { 540*8590a0fdSAndre Fischer // advise the response bucket that this was from a HEAD request and that it should not expect to see a response body. 541*8590a0fdSAndre Fischer serf_bucket_response_set_head( responseBkt ); 542*8590a0fdSAndre Fischer } 543*8590a0fdSAndre Fischer 544*8590a0fdSAndre Fischer return responseBkt; 545*8590a0fdSAndre Fischer } 546*8590a0fdSAndre Fischer 547*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 548*8590a0fdSAndre Fischer // PROPFIND - allprop & named 549*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 550*8590a0fdSAndre Fischer void SerfSession::PROPFIND( const rtl::OUString & inPath, 551*8590a0fdSAndre Fischer const Depth inDepth, 552*8590a0fdSAndre Fischer const std::vector< rtl::OUString > & inPropNames, 553*8590a0fdSAndre Fischer std::vector< DAVResource > & ioResources, 554*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 555*8590a0fdSAndre Fischer throw ( DAVException ) 556*8590a0fdSAndre Fischer { 557*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 558*8590a0fdSAndre Fischer 559*8590a0fdSAndre Fischer Init( rEnv ); 560*8590a0fdSAndre Fischer 561*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 562*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 563*8590a0fdSAndre Fischer inPath ); 564*8590a0fdSAndre Fischer aReqProc.processPropFind( inDepth, 565*8590a0fdSAndre Fischer inPropNames, 566*8590a0fdSAndre Fischer ioResources, 567*8590a0fdSAndre Fischer status ); 568*8590a0fdSAndre Fischer 569*8590a0fdSAndre Fischer if ( status == APR_SUCCESS && 570*8590a0fdSAndre Fischer aReqProc.mpDAVException == 0 && 571*8590a0fdSAndre Fischer ioResources.empty() ) 572*8590a0fdSAndre Fischer { 573*8590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 574*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, inPath, (sal_uInt16)APR_EGENERAL ); 575*8590a0fdSAndre Fischer } 576*8590a0fdSAndre Fischer HandleError( aReqProc, 577*8590a0fdSAndre Fischer inPath, rEnv ); 578*8590a0fdSAndre Fischer } 579*8590a0fdSAndre Fischer 580*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 581*8590a0fdSAndre Fischer // PROPFIND - propnames 582*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 583*8590a0fdSAndre Fischer void SerfSession::PROPFIND( const rtl::OUString & inPath, 584*8590a0fdSAndre Fischer const Depth inDepth, 585*8590a0fdSAndre Fischer std::vector< DAVResourceInfo > & ioResInfo, 586*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 587*8590a0fdSAndre Fischer throw( DAVException ) 588*8590a0fdSAndre Fischer { 589*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 590*8590a0fdSAndre Fischer 591*8590a0fdSAndre Fischer Init( rEnv ); 592*8590a0fdSAndre Fischer 593*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 594*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 595*8590a0fdSAndre Fischer inPath ); 596*8590a0fdSAndre Fischer aReqProc.processPropFind( inDepth, 597*8590a0fdSAndre Fischer ioResInfo, 598*8590a0fdSAndre Fischer status ); 599*8590a0fdSAndre Fischer 600*8590a0fdSAndre Fischer if ( status == APR_SUCCESS && 601*8590a0fdSAndre Fischer aReqProc.mpDAVException == 0 && 602*8590a0fdSAndre Fischer ioResInfo.empty() ) 603*8590a0fdSAndre Fischer { 604*8590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 605*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, inPath, (sal_uInt16)APR_EGENERAL ); 606*8590a0fdSAndre Fischer } 607*8590a0fdSAndre Fischer HandleError( aReqProc, 608*8590a0fdSAndre Fischer inPath, rEnv ); 609*8590a0fdSAndre Fischer } 610*8590a0fdSAndre Fischer 611*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 612*8590a0fdSAndre Fischer // PROPPATCH 613*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 614*8590a0fdSAndre Fischer void SerfSession::PROPPATCH( const rtl::OUString & inPath, 615*8590a0fdSAndre Fischer const std::vector< ProppatchValue > & inValues, 616*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 617*8590a0fdSAndre Fischer throw( DAVException ) 618*8590a0fdSAndre Fischer { 619*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 620*8590a0fdSAndre Fischer 621*8590a0fdSAndre Fischer Init( rEnv ); 622*8590a0fdSAndre Fischer 623*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 624*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 625*8590a0fdSAndre Fischer inPath ); 626*8590a0fdSAndre Fischer aReqProc.processPropPatch( inValues, 627*8590a0fdSAndre Fischer status ); 628*8590a0fdSAndre Fischer 629*8590a0fdSAndre Fischer HandleError( aReqProc, 630*8590a0fdSAndre Fischer inPath, rEnv ); 631*8590a0fdSAndre Fischer } 632*8590a0fdSAndre Fischer 633*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 634*8590a0fdSAndre Fischer // HEAD 635*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 636*8590a0fdSAndre Fischer void SerfSession::HEAD( const ::rtl::OUString & inPath, 637*8590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 638*8590a0fdSAndre Fischer DAVResource & ioResource, 639*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 640*8590a0fdSAndre Fischer throw( DAVException ) 641*8590a0fdSAndre Fischer { 642*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 643*8590a0fdSAndre Fischer 644*8590a0fdSAndre Fischer Init( rEnv ); 645*8590a0fdSAndre Fischer 646*8590a0fdSAndre Fischer m_bIsHeadRequestInProgress = true; 647*8590a0fdSAndre Fischer 648*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 649*8590a0fdSAndre Fischer inPath ); 650*8590a0fdSAndre Fischer ioResource.uri = inPath; 651*8590a0fdSAndre Fischer ioResource.properties.clear(); 652*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 653*8590a0fdSAndre Fischer aReqProc.processHead( inHeaderNames, 654*8590a0fdSAndre Fischer ioResource, 655*8590a0fdSAndre Fischer status ); 656*8590a0fdSAndre Fischer 657*8590a0fdSAndre Fischer HandleError( aReqProc, 658*8590a0fdSAndre Fischer inPath, rEnv ); 659*8590a0fdSAndre Fischer m_bIsHeadRequestInProgress = false; 660*8590a0fdSAndre Fischer } 661*8590a0fdSAndre Fischer 662*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 663*8590a0fdSAndre Fischer // GET 664*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 665*8590a0fdSAndre Fischer uno::Reference< io::XInputStream > 666*8590a0fdSAndre Fischer SerfSession::GET( const rtl::OUString & inPath, 667*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 668*8590a0fdSAndre Fischer throw ( DAVException ) 669*8590a0fdSAndre Fischer { 670*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 671*8590a0fdSAndre Fischer 672*8590a0fdSAndre Fischer Init( rEnv ); 673*8590a0fdSAndre Fischer 674*8590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 675*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 676*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 677*8590a0fdSAndre Fischer inPath ); 678*8590a0fdSAndre Fischer aReqProc.processGet( xInputStream, 679*8590a0fdSAndre Fischer status ); 680*8590a0fdSAndre Fischer 681*8590a0fdSAndre Fischer HandleError( aReqProc, 682*8590a0fdSAndre Fischer inPath, rEnv ); 683*8590a0fdSAndre Fischer 684*8590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 685*8590a0fdSAndre Fischer } 686*8590a0fdSAndre Fischer 687*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 688*8590a0fdSAndre Fischer // GET 689*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 690*8590a0fdSAndre Fischer void SerfSession::GET( const rtl::OUString & inPath, 691*8590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & ioOutputStream, 692*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 693*8590a0fdSAndre Fischer throw ( DAVException ) 694*8590a0fdSAndre Fischer { 695*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 696*8590a0fdSAndre Fischer 697*8590a0fdSAndre Fischer Init( rEnv ); 698*8590a0fdSAndre Fischer 699*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 700*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 701*8590a0fdSAndre Fischer inPath ); 702*8590a0fdSAndre Fischer aReqProc.processGet( ioOutputStream, 703*8590a0fdSAndre Fischer status ); 704*8590a0fdSAndre Fischer 705*8590a0fdSAndre Fischer HandleError( aReqProc, 706*8590a0fdSAndre Fischer inPath, rEnv ); 707*8590a0fdSAndre Fischer } 708*8590a0fdSAndre Fischer 709*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 710*8590a0fdSAndre Fischer // GET 711*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 712*8590a0fdSAndre Fischer uno::Reference< io::XInputStream > 713*8590a0fdSAndre Fischer SerfSession::GET( const rtl::OUString & inPath, 714*8590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 715*8590a0fdSAndre Fischer DAVResource & ioResource, 716*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 717*8590a0fdSAndre Fischer throw ( DAVException ) 718*8590a0fdSAndre Fischer { 719*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 720*8590a0fdSAndre Fischer 721*8590a0fdSAndre Fischer Init( rEnv ); 722*8590a0fdSAndre Fischer 723*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 724*8590a0fdSAndre Fischer inPath ); 725*8590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 726*8590a0fdSAndre Fischer ioResource.uri = inPath; 727*8590a0fdSAndre Fischer ioResource.properties.clear(); 728*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 729*8590a0fdSAndre Fischer aReqProc.processGet( xInputStream, 730*8590a0fdSAndre Fischer inHeaderNames, 731*8590a0fdSAndre Fischer ioResource, 732*8590a0fdSAndre Fischer status ); 733*8590a0fdSAndre Fischer 734*8590a0fdSAndre Fischer HandleError( aReqProc, 735*8590a0fdSAndre Fischer inPath, rEnv ); 736*8590a0fdSAndre Fischer 737*8590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 738*8590a0fdSAndre Fischer } 739*8590a0fdSAndre Fischer 740*8590a0fdSAndre Fischer 741*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 742*8590a0fdSAndre Fischer // GET 743*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 744*8590a0fdSAndre Fischer void SerfSession::GET( const rtl::OUString & inPath, 745*8590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & ioOutputStream, 746*8590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 747*8590a0fdSAndre Fischer DAVResource & ioResource, 748*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 749*8590a0fdSAndre Fischer throw ( DAVException ) 750*8590a0fdSAndre Fischer { 751*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 752*8590a0fdSAndre Fischer 753*8590a0fdSAndre Fischer Init( rEnv ); 754*8590a0fdSAndre Fischer 755*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 756*8590a0fdSAndre Fischer inPath ); 757*8590a0fdSAndre Fischer ioResource.uri = inPath; 758*8590a0fdSAndre Fischer ioResource.properties.clear(); 759*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 760*8590a0fdSAndre Fischer aReqProc.processGet( ioOutputStream, 761*8590a0fdSAndre Fischer inHeaderNames, 762*8590a0fdSAndre Fischer ioResource, 763*8590a0fdSAndre Fischer status ); 764*8590a0fdSAndre Fischer 765*8590a0fdSAndre Fischer HandleError( aReqProc, 766*8590a0fdSAndre Fischer inPath, rEnv ); 767*8590a0fdSAndre Fischer } 768*8590a0fdSAndre Fischer 769*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 770*8590a0fdSAndre Fischer // PUT 771*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 772*8590a0fdSAndre Fischer void SerfSession::PUT( const rtl::OUString & inPath, 773*8590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 774*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 775*8590a0fdSAndre Fischer throw ( DAVException ) 776*8590a0fdSAndre Fischer { 777*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 778*8590a0fdSAndre Fischer 779*8590a0fdSAndre Fischer Init( rEnv ); 780*8590a0fdSAndre Fischer 781*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 782*8590a0fdSAndre Fischer inPath ); 783*8590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 784*8590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, false ) ) 785*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 786*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 787*8590a0fdSAndre Fischer aReqProc.processPut( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 788*8590a0fdSAndre Fischer aDataToSend.getLength(), 789*8590a0fdSAndre Fischer status ); 790*8590a0fdSAndre Fischer 791*8590a0fdSAndre Fischer HandleError( aReqProc, 792*8590a0fdSAndre Fischer inPath, rEnv ); 793*8590a0fdSAndre Fischer } 794*8590a0fdSAndre Fischer 795*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 796*8590a0fdSAndre Fischer // POST 797*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 798*8590a0fdSAndre Fischer uno::Reference< io::XInputStream > 799*8590a0fdSAndre Fischer SerfSession::POST( const rtl::OUString & inPath, 800*8590a0fdSAndre Fischer const rtl::OUString & rContentType, 801*8590a0fdSAndre Fischer const rtl::OUString & rReferer, 802*8590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 803*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 804*8590a0fdSAndre Fischer throw ( DAVException ) 805*8590a0fdSAndre Fischer { 806*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 807*8590a0fdSAndre Fischer 808*8590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 809*8590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, true ) ) 810*8590a0fdSAndre Fischer { 811*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 812*8590a0fdSAndre Fischer } 813*8590a0fdSAndre Fischer 814*8590a0fdSAndre Fischer Init( rEnv ); 815*8590a0fdSAndre Fischer 816*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 817*8590a0fdSAndre Fischer inPath ); 818*8590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 819*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 820*8590a0fdSAndre Fischer aReqProc.processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 821*8590a0fdSAndre Fischer aDataToSend.getLength(), 822*8590a0fdSAndre Fischer rContentType, 823*8590a0fdSAndre Fischer rReferer, 824*8590a0fdSAndre Fischer xInputStream, 825*8590a0fdSAndre Fischer status ); 826*8590a0fdSAndre Fischer 827*8590a0fdSAndre Fischer HandleError( aReqProc, 828*8590a0fdSAndre Fischer inPath, rEnv ); 829*8590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 830*8590a0fdSAndre Fischer } 831*8590a0fdSAndre Fischer 832*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 833*8590a0fdSAndre Fischer // POST 834*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 835*8590a0fdSAndre Fischer void SerfSession::POST( const rtl::OUString & inPath, 836*8590a0fdSAndre Fischer const rtl::OUString & rContentType, 837*8590a0fdSAndre Fischer const rtl::OUString & rReferer, 838*8590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 839*8590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & oOutputStream, 840*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 841*8590a0fdSAndre Fischer throw ( DAVException ) 842*8590a0fdSAndre Fischer { 843*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 844*8590a0fdSAndre Fischer 845*8590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 846*8590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, true ) ) 847*8590a0fdSAndre Fischer { 848*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 849*8590a0fdSAndre Fischer } 850*8590a0fdSAndre Fischer 851*8590a0fdSAndre Fischer Init( rEnv ); 852*8590a0fdSAndre Fischer 853*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 854*8590a0fdSAndre Fischer inPath ); 855*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 856*8590a0fdSAndre Fischer aReqProc.processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 857*8590a0fdSAndre Fischer aDataToSend.getLength(), 858*8590a0fdSAndre Fischer rContentType, 859*8590a0fdSAndre Fischer rReferer, 860*8590a0fdSAndre Fischer oOutputStream, 861*8590a0fdSAndre Fischer status ); 862*8590a0fdSAndre Fischer 863*8590a0fdSAndre Fischer HandleError( aReqProc, 864*8590a0fdSAndre Fischer inPath, rEnv ); 865*8590a0fdSAndre Fischer } 866*8590a0fdSAndre Fischer 867*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 868*8590a0fdSAndre Fischer // MKCOL 869*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 870*8590a0fdSAndre Fischer void SerfSession::MKCOL( const rtl::OUString & inPath, 871*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 872*8590a0fdSAndre Fischer throw ( DAVException ) 873*8590a0fdSAndre Fischer { 874*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 875*8590a0fdSAndre Fischer 876*8590a0fdSAndre Fischer Init( rEnv ); 877*8590a0fdSAndre Fischer 878*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 879*8590a0fdSAndre Fischer inPath ); 880*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 881*8590a0fdSAndre Fischer aReqProc.processMkCol( status ); 882*8590a0fdSAndre Fischer 883*8590a0fdSAndre Fischer HandleError( aReqProc, 884*8590a0fdSAndre Fischer inPath, rEnv ); 885*8590a0fdSAndre Fischer } 886*8590a0fdSAndre Fischer 887*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 888*8590a0fdSAndre Fischer // COPY 889*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 890*8590a0fdSAndre Fischer void SerfSession::COPY( const rtl::OUString & inSourceURL, 891*8590a0fdSAndre Fischer const rtl::OUString & inDestinationURL, 892*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv, 893*8590a0fdSAndre Fischer sal_Bool inOverWrite ) 894*8590a0fdSAndre Fischer throw ( DAVException ) 895*8590a0fdSAndre Fischer { 896*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 897*8590a0fdSAndre Fischer 898*8590a0fdSAndre Fischer Init( rEnv ); 899*8590a0fdSAndre Fischer 900*8590a0fdSAndre Fischer SerfUri theSourceUri( inSourceURL ); 901*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 902*8590a0fdSAndre Fischer theSourceUri.GetPath() ); 903*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 904*8590a0fdSAndre Fischer aReqProc.processCopy( inDestinationURL, 905*8590a0fdSAndre Fischer (inOverWrite ? true : false), 906*8590a0fdSAndre Fischer status ); 907*8590a0fdSAndre Fischer 908*8590a0fdSAndre Fischer HandleError( aReqProc, 909*8590a0fdSAndre Fischer inSourceURL, rEnv ); 910*8590a0fdSAndre Fischer } 911*8590a0fdSAndre Fischer 912*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 913*8590a0fdSAndre Fischer // MOVE 914*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 915*8590a0fdSAndre Fischer void SerfSession::MOVE( const rtl::OUString & inSourceURL, 916*8590a0fdSAndre Fischer const rtl::OUString & inDestinationURL, 917*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv, 918*8590a0fdSAndre Fischer sal_Bool inOverWrite ) 919*8590a0fdSAndre Fischer throw ( DAVException ) 920*8590a0fdSAndre Fischer { 921*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 922*8590a0fdSAndre Fischer 923*8590a0fdSAndre Fischer Init( rEnv ); 924*8590a0fdSAndre Fischer 925*8590a0fdSAndre Fischer SerfUri theSourceUri( inSourceURL ); 926*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 927*8590a0fdSAndre Fischer theSourceUri.GetPath() ); 928*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 929*8590a0fdSAndre Fischer aReqProc.processMove( inDestinationURL, 930*8590a0fdSAndre Fischer (inOverWrite ? true : false), 931*8590a0fdSAndre Fischer status ); 932*8590a0fdSAndre Fischer 933*8590a0fdSAndre Fischer HandleError( aReqProc, 934*8590a0fdSAndre Fischer inSourceURL, rEnv ); 935*8590a0fdSAndre Fischer } 936*8590a0fdSAndre Fischer 937*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 938*8590a0fdSAndre Fischer // DESTROY 939*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 940*8590a0fdSAndre Fischer void SerfSession::DESTROY( const rtl::OUString & inPath, 941*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 942*8590a0fdSAndre Fischer throw ( DAVException ) 943*8590a0fdSAndre Fischer { 944*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 945*8590a0fdSAndre Fischer 946*8590a0fdSAndre Fischer Init( rEnv ); 947*8590a0fdSAndre Fischer 948*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 949*8590a0fdSAndre Fischer inPath ); 950*8590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 951*8590a0fdSAndre Fischer aReqProc.processDelete( status ); 952*8590a0fdSAndre Fischer 953*8590a0fdSAndre Fischer HandleError( aReqProc, 954*8590a0fdSAndre Fischer inPath, rEnv ); 955*8590a0fdSAndre Fischer } 956*8590a0fdSAndre Fischer 957*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 958*8590a0fdSAndre Fischer /* 959*8590a0fdSAndre Fischer namespace 960*8590a0fdSAndre Fischer { 961*8590a0fdSAndre Fischer sal_Int32 lastChanceToSendRefreshRequest( TimeValue const & rStart, 962*8590a0fdSAndre Fischer int timeout ) 963*8590a0fdSAndre Fischer { 964*8590a0fdSAndre Fischer TimeValue aEnd; 965*8590a0fdSAndre Fischer osl_getSystemTime( &aEnd ); 966*8590a0fdSAndre Fischer 967*8590a0fdSAndre Fischer // Try to estimate a safe absolute time for sending the 968*8590a0fdSAndre Fischer // lock refresh request. 969*8590a0fdSAndre Fischer sal_Int32 lastChanceToSendRefreshRequest = -1; 970*8590a0fdSAndre Fischer if ( timeout != NE_TIMEOUT_INFINITE ) 971*8590a0fdSAndre Fischer { 972*8590a0fdSAndre Fischer sal_Int32 calltime = aEnd.Seconds - rStart.Seconds; 973*8590a0fdSAndre Fischer if ( calltime <= timeout ) 974*8590a0fdSAndre Fischer { 975*8590a0fdSAndre Fischer lastChanceToSendRefreshRequest 976*8590a0fdSAndre Fischer = aEnd.Seconds + timeout - calltime; 977*8590a0fdSAndre Fischer } 978*8590a0fdSAndre Fischer else 979*8590a0fdSAndre Fischer { 980*8590a0fdSAndre Fischer OSL_TRACE( "No chance to refresh lock before timeout!" ); 981*8590a0fdSAndre Fischer } 982*8590a0fdSAndre Fischer } 983*8590a0fdSAndre Fischer return lastChanceToSendRefreshRequest; 984*8590a0fdSAndre Fischer } 985*8590a0fdSAndre Fischer 986*8590a0fdSAndre Fischer } // namespace 987*8590a0fdSAndre Fischer */ 988*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 989*8590a0fdSAndre Fischer // LOCK (set new lock) 990*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 991*8590a0fdSAndre Fischer void SerfSession::LOCK( const ::rtl::OUString & inPath, 992*8590a0fdSAndre Fischer ucb::Lock & /*rLock*/, 993*8590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 994*8590a0fdSAndre Fischer throw ( DAVException ) 995*8590a0fdSAndre Fischer { 996*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 997*8590a0fdSAndre Fischer 998*8590a0fdSAndre Fischer Init( rEnv ); 999*8590a0fdSAndre Fischer 1000*8590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 1001*8590a0fdSAndre Fischer inPath ); 1002*8590a0fdSAndre Fischer HandleError( aReqProc, 1003*8590a0fdSAndre Fischer inPath, rEnv ); 1004*8590a0fdSAndre Fischer /* Create a depth zero, exclusive write lock, with default timeout 1005*8590a0fdSAndre Fischer * (allowing a server to pick a default). token, owner and uri are 1006*8590a0fdSAndre Fischer * unset. */ 1007*8590a0fdSAndre Fischer /* 1008*8590a0fdSAndre Fischer SerfLock * theLock = ne_lock_create(); 1009*8590a0fdSAndre Fischer 1010*8590a0fdSAndre Fischer // Set the lock uri 1011*8590a0fdSAndre Fischer ne_uri aUri; 1012*8590a0fdSAndre Fischer ne_uri_parse( rtl::OUStringToOString( makeAbsoluteURL( inPath ), 1013*8590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 1014*8590a0fdSAndre Fischer &aUri ); 1015*8590a0fdSAndre Fischer theLock->uri = aUri; 1016*8590a0fdSAndre Fischer 1017*8590a0fdSAndre Fischer // Set the lock depth 1018*8590a0fdSAndre Fischer switch( rLock.Depth ) 1019*8590a0fdSAndre Fischer { 1020*8590a0fdSAndre Fischer case ucb::LockDepth_ZERO: 1021*8590a0fdSAndre Fischer theLock->depth = NE_DEPTH_ZERO; 1022*8590a0fdSAndre Fischer break; 1023*8590a0fdSAndre Fischer case ucb::LockDepth_ONE: 1024*8590a0fdSAndre Fischer theLock->depth = NE_DEPTH_ONE; 1025*8590a0fdSAndre Fischer break; 1026*8590a0fdSAndre Fischer case ucb::LockDepth_INFINITY: 1027*8590a0fdSAndre Fischer theLock->depth = NE_DEPTH_INFINITE; 1028*8590a0fdSAndre Fischer break; 1029*8590a0fdSAndre Fischer default: 1030*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 1031*8590a0fdSAndre Fischer } 1032*8590a0fdSAndre Fischer 1033*8590a0fdSAndre Fischer // Set the lock scope 1034*8590a0fdSAndre Fischer switch ( rLock.Scope ) 1035*8590a0fdSAndre Fischer { 1036*8590a0fdSAndre Fischer case ucb::LockScope_EXCLUSIVE: 1037*8590a0fdSAndre Fischer theLock->scope = ne_lockscope_exclusive; 1038*8590a0fdSAndre Fischer break; 1039*8590a0fdSAndre Fischer case ucb::LockScope_SHARED: 1040*8590a0fdSAndre Fischer theLock->scope = ne_lockscope_shared; 1041*8590a0fdSAndre Fischer break; 1042*8590a0fdSAndre Fischer default: 1043*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 1044*8590a0fdSAndre Fischer } 1045*8590a0fdSAndre Fischer 1046*8590a0fdSAndre Fischer // Set the lock timeout 1047*8590a0fdSAndre Fischer theLock->timeout = (long)rLock.Timeout; 1048*8590a0fdSAndre Fischer 1049*8590a0fdSAndre Fischer // Set the lock owner 1050*8590a0fdSAndre Fischer rtl::OUString aValue; 1051*8590a0fdSAndre Fischer rLock.Owner >>= aValue; 1052*8590a0fdSAndre Fischer theLock->owner = 1053*8590a0fdSAndre Fischer ne_strdup( rtl::OUStringToOString( aValue, 1054*8590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 1055*8590a0fdSAndre Fischer TimeValue startCall; 1056*8590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 1057*8590a0fdSAndre Fischer 1058*8590a0fdSAndre Fischer int theRetVal = ne_lock( m_pHttpSession, theLock ); 1059*8590a0fdSAndre Fischer 1060*8590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 1061*8590a0fdSAndre Fischer { 1062*8590a0fdSAndre Fischer m_aSerfLockStore.addLock( theLock, 1063*8590a0fdSAndre Fischer this, 1064*8590a0fdSAndre Fischer lastChanceToSendRefreshRequest( 1065*8590a0fdSAndre Fischer startCall, theLock->timeout ) ); 1066*8590a0fdSAndre Fischer 1067*8590a0fdSAndre Fischer uno::Sequence< rtl::OUString > aTokens( 1 ); 1068*8590a0fdSAndre Fischer aTokens[ 0 ] = rtl::OUString::createFromAscii( theLock->token ); 1069*8590a0fdSAndre Fischer rLock.LockTokens = aTokens; 1070*8590a0fdSAndre Fischer 1071*8590a0fdSAndre Fischer OSL_TRACE( "SerfSession::LOCK: created lock for %s. token: %s", 1072*8590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 1073*8590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 1074*8590a0fdSAndre Fischer theLock->token ); 1075*8590a0fdSAndre Fischer } 1076*8590a0fdSAndre Fischer else 1077*8590a0fdSAndre Fischer { 1078*8590a0fdSAndre Fischer ne_lock_destroy( theLock ); 1079*8590a0fdSAndre Fischer 1080*8590a0fdSAndre Fischer OSL_TRACE( "SerfSession::LOCK: obtaining lock for %s failed!", 1081*8590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 1082*8590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 1083*8590a0fdSAndre Fischer } 1084*8590a0fdSAndre Fischer 1085*8590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 1086*8590a0fdSAndre Fischer */ 1087*8590a0fdSAndre Fischer } 1088*8590a0fdSAndre Fischer 1089*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1090*8590a0fdSAndre Fischer // LOCK (refresh existing lock) 1091*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1092*8590a0fdSAndre Fischer sal_Int64 SerfSession::LOCK( const ::rtl::OUString & /*inPath*/, 1093*8590a0fdSAndre Fischer sal_Int64 nTimeout, 1094*8590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 1095*8590a0fdSAndre Fischer throw ( DAVException ) 1096*8590a0fdSAndre Fischer { 1097*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1098*8590a0fdSAndre Fischer 1099*8590a0fdSAndre Fischer return nTimeout; 1100*8590a0fdSAndre Fischer /* 1101*8590a0fdSAndre Fischer // Try to get the neon lock from lock store 1102*8590a0fdSAndre Fischer SerfLock * theLock 1103*8590a0fdSAndre Fischer = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); 1104*8590a0fdSAndre Fischer if ( !theLock ) 1105*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_NOT_LOCKED ); 1106*8590a0fdSAndre Fischer 1107*8590a0fdSAndre Fischer Init( rEnv ); 1108*8590a0fdSAndre Fischer 1109*8590a0fdSAndre Fischer // refresh existing lock. 1110*8590a0fdSAndre Fischer theLock->timeout = static_cast< long >( nTimeout ); 1111*8590a0fdSAndre Fischer 1112*8590a0fdSAndre Fischer TimeValue startCall; 1113*8590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 1114*8590a0fdSAndre Fischer 1115*8590a0fdSAndre Fischer int theRetVal = ne_lock_refresh( m_pHttpSession, theLock ); 1116*8590a0fdSAndre Fischer 1117*8590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 1118*8590a0fdSAndre Fischer { 1119*8590a0fdSAndre Fischer m_aSerfLockStore.updateLock( theLock, 1120*8590a0fdSAndre Fischer lastChanceToSendRefreshRequest( 1121*8590a0fdSAndre Fischer startCall, theLock->timeout ) ); 1122*8590a0fdSAndre Fischer } 1123*8590a0fdSAndre Fischer 1124*8590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 1125*8590a0fdSAndre Fischer 1126*8590a0fdSAndre Fischer return theLock->timeout; 1127*8590a0fdSAndre Fischer */ 1128*8590a0fdSAndre Fischer } 1129*8590a0fdSAndre Fischer 1130*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1131*8590a0fdSAndre Fischer // LOCK (refresh existing lock) 1132*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1133*8590a0fdSAndre Fischer bool SerfSession::LOCK( SerfLock * /*pLock*/, 1134*8590a0fdSAndre Fischer sal_Int32 & /*rlastChanceToSendRefreshRequest*/ ) 1135*8590a0fdSAndre Fischer { 1136*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1137*8590a0fdSAndre Fischer 1138*8590a0fdSAndre Fischer return true; 1139*8590a0fdSAndre Fischer /* 1140*8590a0fdSAndre Fischer // refresh existing lock. 1141*8590a0fdSAndre Fischer 1142*8590a0fdSAndre Fischer TimeValue startCall; 1143*8590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 1144*8590a0fdSAndre Fischer 1145*8590a0fdSAndre Fischer if ( ne_lock_refresh( m_pHttpSession, pLock ) == NE_OK ) 1146*8590a0fdSAndre Fischer { 1147*8590a0fdSAndre Fischer rlastChanceToSendRefreshRequest 1148*8590a0fdSAndre Fischer = lastChanceToSendRefreshRequest( startCall, pLock->timeout ); 1149*8590a0fdSAndre Fischer 1150*8590a0fdSAndre Fischer OSL_TRACE( "Lock successfully refreshed." ); 1151*8590a0fdSAndre Fischer return true; 1152*8590a0fdSAndre Fischer } 1153*8590a0fdSAndre Fischer else 1154*8590a0fdSAndre Fischer { 1155*8590a0fdSAndre Fischer OSL_TRACE( "Lock not refreshed!" ); 1156*8590a0fdSAndre Fischer return false; 1157*8590a0fdSAndre Fischer } 1158*8590a0fdSAndre Fischer */ 1159*8590a0fdSAndre Fischer } 1160*8590a0fdSAndre Fischer 1161*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1162*8590a0fdSAndre Fischer // UNLOCK 1163*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1164*8590a0fdSAndre Fischer void SerfSession::UNLOCK( const ::rtl::OUString & /*inPath*/, 1165*8590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 1166*8590a0fdSAndre Fischer throw ( DAVException ) 1167*8590a0fdSAndre Fischer { 1168*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1169*8590a0fdSAndre Fischer 1170*8590a0fdSAndre Fischer /* 1171*8590a0fdSAndre Fischer // get the neon lock from lock store 1172*8590a0fdSAndre Fischer SerfLock * theLock 1173*8590a0fdSAndre Fischer = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); 1174*8590a0fdSAndre Fischer if ( !theLock ) 1175*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_NOT_LOCKED ); 1176*8590a0fdSAndre Fischer 1177*8590a0fdSAndre Fischer Init( rEnv ); 1178*8590a0fdSAndre Fischer 1179*8590a0fdSAndre Fischer int theRetVal = ne_unlock( m_pHttpSession, theLock ); 1180*8590a0fdSAndre Fischer 1181*8590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 1182*8590a0fdSAndre Fischer { 1183*8590a0fdSAndre Fischer m_aSerfLockStore.removeLock( theLock ); 1184*8590a0fdSAndre Fischer ne_lock_destroy( theLock ); 1185*8590a0fdSAndre Fischer } 1186*8590a0fdSAndre Fischer else 1187*8590a0fdSAndre Fischer { 1188*8590a0fdSAndre Fischer OSL_TRACE( "SerfSession::UNLOCK: unlocking of %s failed.", 1189*8590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 1190*8590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 1191*8590a0fdSAndre Fischer } 1192*8590a0fdSAndre Fischer 1193*8590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 1194*8590a0fdSAndre Fischer */ 1195*8590a0fdSAndre Fischer } 1196*8590a0fdSAndre Fischer 1197*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1198*8590a0fdSAndre Fischer // UNLOCK 1199*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1200*8590a0fdSAndre Fischer bool SerfSession::UNLOCK( SerfLock * /*pLock*/ ) 1201*8590a0fdSAndre Fischer { 1202*8590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1203*8590a0fdSAndre Fischer 1204*8590a0fdSAndre Fischer return true; 1205*8590a0fdSAndre Fischer /* 1206*8590a0fdSAndre Fischer if ( ne_unlock( m_pHttpSession, pLock ) == NE_OK ) 1207*8590a0fdSAndre Fischer { 1208*8590a0fdSAndre Fischer OSL_TRACE( "UNLOCK succeeded." ); 1209*8590a0fdSAndre Fischer return true; 1210*8590a0fdSAndre Fischer } 1211*8590a0fdSAndre Fischer else 1212*8590a0fdSAndre Fischer { 1213*8590a0fdSAndre Fischer OSL_TRACE( "UNLOCK failed!" ); 1214*8590a0fdSAndre Fischer return false; 1215*8590a0fdSAndre Fischer } 1216*8590a0fdSAndre Fischer */ 1217*8590a0fdSAndre Fischer } 1218*8590a0fdSAndre Fischer 1219*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1220*8590a0fdSAndre Fischer void SerfSession::abort() 1221*8590a0fdSAndre Fischer throw ( DAVException ) 1222*8590a0fdSAndre Fischer { 1223*8590a0fdSAndre Fischer // 11.11.09 (tkr): The following code lines causing crashes if 1224*8590a0fdSAndre Fischer // closing a ongoing connection. It turned out that this existing 1225*8590a0fdSAndre Fischer // solution doesn't work in multi-threading environments. 1226*8590a0fdSAndre Fischer // So I disabled them in 3.2. . Issue #73893# should fix it in OOo 3.3. 1227*8590a0fdSAndre Fischer //if ( m_pHttpSession ) 1228*8590a0fdSAndre Fischer // ne_close_connection( m_pHttpSession ); 1229*8590a0fdSAndre Fischer } 1230*8590a0fdSAndre Fischer 1231*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1232*8590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & SerfSession::getProxySettings() const 1233*8590a0fdSAndre Fischer { 1234*8590a0fdSAndre Fischer if ( m_aUri.GetScheme().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "http" ) ) || 1235*8590a0fdSAndre Fischer m_aUri.GetScheme().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "https" ) ) ) 1236*8590a0fdSAndre Fischer { 1237*8590a0fdSAndre Fischer return m_rProxyDecider.getProxy( m_aUri.GetScheme(), 1238*8590a0fdSAndre Fischer m_aUri.GetHost(), 1239*8590a0fdSAndre Fischer m_aUri.GetPort() ); 1240*8590a0fdSAndre Fischer } 1241*8590a0fdSAndre Fischer else 1242*8590a0fdSAndre Fischer { 1243*8590a0fdSAndre Fischer // TODO: figure out, if this case can occur 1244*8590a0fdSAndre Fischer return m_rProxyDecider.getProxy( m_aUri.GetScheme(), 1245*8590a0fdSAndre Fischer rtl::OUString() /* not used */, 1246*8590a0fdSAndre Fischer -1 /* not used */ ); 1247*8590a0fdSAndre Fischer } 1248*8590a0fdSAndre Fischer } 1249*8590a0fdSAndre Fischer 1250*8590a0fdSAndre Fischer /* 1251*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1252*8590a0fdSAndre Fischer namespace { 1253*8590a0fdSAndre Fischer 1254*8590a0fdSAndre Fischer bool containsLocktoken( const uno::Sequence< ucb::Lock > & rLocks, 1255*8590a0fdSAndre Fischer const char * token ) 1256*8590a0fdSAndre Fischer { 1257*8590a0fdSAndre Fischer for ( sal_Int32 n = 0; n < rLocks.getLength(); ++n ) 1258*8590a0fdSAndre Fischer { 1259*8590a0fdSAndre Fischer const uno::Sequence< rtl::OUString > & rTokens 1260*8590a0fdSAndre Fischer = rLocks[ n ].LockTokens; 1261*8590a0fdSAndre Fischer for ( sal_Int32 m = 0; m < rTokens.getLength(); ++m ) 1262*8590a0fdSAndre Fischer { 1263*8590a0fdSAndre Fischer if ( rTokens[ m ].equalsAscii( token ) ) 1264*8590a0fdSAndre Fischer return true; 1265*8590a0fdSAndre Fischer } 1266*8590a0fdSAndre Fischer } 1267*8590a0fdSAndre Fischer return false; 1268*8590a0fdSAndre Fischer } 1269*8590a0fdSAndre Fischer 1270*8590a0fdSAndre Fischer } // namespace 1271*8590a0fdSAndre Fischer */ 1272*8590a0fdSAndre Fischer 1273*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1274*8590a0fdSAndre Fischer bool SerfSession::removeExpiredLocktoken( const rtl::OUString & /*inURL*/, 1275*8590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 1276*8590a0fdSAndre Fischer { 1277*8590a0fdSAndre Fischer return true; 1278*8590a0fdSAndre Fischer /* 1279*8590a0fdSAndre Fischer SerfLock * theLock = m_aSerfLockStore.findByUri( inURL ); 1280*8590a0fdSAndre Fischer if ( !theLock ) 1281*8590a0fdSAndre Fischer return false; 1282*8590a0fdSAndre Fischer 1283*8590a0fdSAndre Fischer // do a lockdiscovery to check whether this lock is still valid. 1284*8590a0fdSAndre Fischer try 1285*8590a0fdSAndre Fischer { 1286*8590a0fdSAndre Fischer // @@@ Alternative: use ne_lock_discover() => less overhead 1287*8590a0fdSAndre Fischer 1288*8590a0fdSAndre Fischer std::vector< DAVResource > aResources; 1289*8590a0fdSAndre Fischer std::vector< rtl::OUString > aPropNames; 1290*8590a0fdSAndre Fischer aPropNames.push_back( DAVProperties::LOCKDISCOVERY ); 1291*8590a0fdSAndre Fischer 1292*8590a0fdSAndre Fischer PROPFIND( rEnv.m_aRequestURI, DAVZERO, aPropNames, aResources, rEnv ); 1293*8590a0fdSAndre Fischer 1294*8590a0fdSAndre Fischer if ( aResources.size() == 0 ) 1295*8590a0fdSAndre Fischer return false; 1296*8590a0fdSAndre Fischer 1297*8590a0fdSAndre Fischer std::vector< DAVPropertyValue >::const_iterator it 1298*8590a0fdSAndre Fischer = aResources[ 0 ].properties.begin(); 1299*8590a0fdSAndre Fischer std::vector< DAVPropertyValue >::const_iterator end 1300*8590a0fdSAndre Fischer = aResources[ 0 ].properties.end(); 1301*8590a0fdSAndre Fischer 1302*8590a0fdSAndre Fischer while ( it != end ) 1303*8590a0fdSAndre Fischer { 1304*8590a0fdSAndre Fischer if ( (*it).Name.equals( DAVProperties::LOCKDISCOVERY ) ) 1305*8590a0fdSAndre Fischer { 1306*8590a0fdSAndre Fischer uno::Sequence< ucb::Lock > aLocks; 1307*8590a0fdSAndre Fischer if ( !( (*it).Value >>= aLocks ) ) 1308*8590a0fdSAndre Fischer return false; 1309*8590a0fdSAndre Fischer 1310*8590a0fdSAndre Fischer if ( !containsLocktoken( aLocks, theLock->token ) ) 1311*8590a0fdSAndre Fischer { 1312*8590a0fdSAndre Fischer // expired! 1313*8590a0fdSAndre Fischer break; 1314*8590a0fdSAndre Fischer } 1315*8590a0fdSAndre Fischer 1316*8590a0fdSAndre Fischer // still valid. 1317*8590a0fdSAndre Fischer return false; 1318*8590a0fdSAndre Fischer } 1319*8590a0fdSAndre Fischer ++it; 1320*8590a0fdSAndre Fischer } 1321*8590a0fdSAndre Fischer 1322*8590a0fdSAndre Fischer // No lockdiscovery prop in propfind result / locktoken not found 1323*8590a0fdSAndre Fischer // in propfind result -> not locked 1324*8590a0fdSAndre Fischer OSL_TRACE( "SerfSession::removeExpiredLocktoken: Removing " 1325*8590a0fdSAndre Fischer " expired lock token for %s. token: %s", 1326*8590a0fdSAndre Fischer rtl::OUStringToOString( inURL, 1327*8590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 1328*8590a0fdSAndre Fischer theLock->token ); 1329*8590a0fdSAndre Fischer 1330*8590a0fdSAndre Fischer m_aSerfLockStore.removeLock( theLock ); 1331*8590a0fdSAndre Fischer ne_lock_destroy( theLock ); 1332*8590a0fdSAndre Fischer return true; 1333*8590a0fdSAndre Fischer } 1334*8590a0fdSAndre Fischer catch ( DAVException const & ) 1335*8590a0fdSAndre Fischer { 1336*8590a0fdSAndre Fischer } 1337*8590a0fdSAndre Fischer return false; 1338*8590a0fdSAndre Fischer */ 1339*8590a0fdSAndre Fischer } 1340*8590a0fdSAndre Fischer 1341*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1342*8590a0fdSAndre Fischer // HandleError 1343*8590a0fdSAndre Fischer // Common Error Handler 1344*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1345*8590a0fdSAndre Fischer void SerfSession::HandleError( SerfRequestProcessor& rReqProc, 1346*8590a0fdSAndre Fischer const rtl::OUString & /*inPath*/, 1347*8590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 1348*8590a0fdSAndre Fischer throw ( DAVException ) 1349*8590a0fdSAndre Fischer { 1350*8590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 1351*8590a0fdSAndre Fischer 1352*8590a0fdSAndre Fischer if ( rReqProc.mpDAVException ) 1353*8590a0fdSAndre Fischer { 1354*8590a0fdSAndre Fischer DAVException* mpDAVExp( rReqProc.mpDAVException ); 1355*8590a0fdSAndre Fischer 1356*8590a0fdSAndre Fischer serf_connection_reset( getSerfConnection() ); 1357*8590a0fdSAndre Fischer 1358*8590a0fdSAndre Fischer throw DAVException( mpDAVExp->getError(), 1359*8590a0fdSAndre Fischer mpDAVExp->getData(), 1360*8590a0fdSAndre Fischer mpDAVExp->getStatus() ); 1361*8590a0fdSAndre Fischer } 1362*8590a0fdSAndre Fischer 1363*8590a0fdSAndre Fischer /* 1364*8590a0fdSAndre Fischer // Map error code to DAVException. 1365*8590a0fdSAndre Fischer switch ( nError ) 1366*8590a0fdSAndre Fischer { 1367*8590a0fdSAndre Fischer case NE_OK: 1368*8590a0fdSAndre Fischer return; 1369*8590a0fdSAndre Fischer 1370*8590a0fdSAndre Fischer case NE_ERROR: // Generic error 1371*8590a0fdSAndre Fischer { 1372*8590a0fdSAndre Fischer rtl::OUString aText = rtl::OUString::createFromAscii( 1373*8590a0fdSAndre Fischer ne_get_error( m_pHttpSession ) ); 1374*8590a0fdSAndre Fischer 1375*8590a0fdSAndre Fischer sal_uInt16 code = makeStatusCode( aText ); 1376*8590a0fdSAndre Fischer 1377*8590a0fdSAndre Fischer if ( code == SC_LOCKED ) 1378*8590a0fdSAndre Fischer { 1379*8590a0fdSAndre Fischer if ( m_aSerfLockStore.findByUri( 1380*8590a0fdSAndre Fischer makeAbsoluteURL( inPath ) ) == 0 ) 1381*8590a0fdSAndre Fischer { 1382*8590a0fdSAndre Fischer // locked by 3rd party 1383*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCKED ); 1384*8590a0fdSAndre Fischer } 1385*8590a0fdSAndre Fischer else 1386*8590a0fdSAndre Fischer { 1387*8590a0fdSAndre Fischer // locked by ourself 1388*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCKED_SELF ); 1389*8590a0fdSAndre Fischer } 1390*8590a0fdSAndre Fischer } 1391*8590a0fdSAndre Fischer 1392*8590a0fdSAndre Fischer // Special handling for 400 and 412 status codes, which may indicate 1393*8590a0fdSAndre Fischer // that a lock previously obtained by us has been released meanwhile 1394*8590a0fdSAndre Fischer // by the server. Unfortunately, RFC is not clear at this point, 1395*8590a0fdSAndre Fischer // thus server implementations behave different... 1396*8590a0fdSAndre Fischer else if ( code == SC_BAD_REQUEST || code == SC_PRECONDITION_FAILED ) 1397*8590a0fdSAndre Fischer { 1398*8590a0fdSAndre Fischer if ( removeExpiredLocktoken( makeAbsoluteURL( inPath ), rEnv ) ) 1399*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCK_EXPIRED ); 1400*8590a0fdSAndre Fischer } 1401*8590a0fdSAndre Fischer 1402*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, aText, code ); 1403*8590a0fdSAndre Fischer } 1404*8590a0fdSAndre Fischer case NE_LOOKUP: // Name lookup failed. 1405*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_LOOKUP, 1406*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1407*8590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 1408*8590a0fdSAndre Fischer 1409*8590a0fdSAndre Fischer case NE_AUTH: // User authentication failed on server 1410*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_AUTH, 1411*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1412*8590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 1413*8590a0fdSAndre Fischer 1414*8590a0fdSAndre Fischer case NE_PROXYAUTH: // User authentication failed on proxy 1415*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_AUTHPROXY, 1416*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1417*8590a0fdSAndre Fischer m_aProxyName, m_nProxyPort ) ); 1418*8590a0fdSAndre Fischer 1419*8590a0fdSAndre Fischer case NE_CONNECT: // Could not connect to server 1420*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_CONNECT, 1421*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1422*8590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 1423*8590a0fdSAndre Fischer 1424*8590a0fdSAndre Fischer case NE_TIMEOUT: // Connection timed out 1425*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_TIMEOUT, 1426*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1427*8590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 1428*8590a0fdSAndre Fischer 1429*8590a0fdSAndre Fischer case NE_FAILED: // The precondition failed 1430*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_FAILED, 1431*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1432*8590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 1433*8590a0fdSAndre Fischer 1434*8590a0fdSAndre Fischer case NE_RETRY: // Retry request (ne_end_request ONLY) 1435*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_RETRY, 1436*8590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 1437*8590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 1438*8590a0fdSAndre Fischer 1439*8590a0fdSAndre Fischer case NE_REDIRECT: 1440*8590a0fdSAndre Fischer { 1441*8590a0fdSAndre Fischer SerfUri aUri( ne_redirect_location( m_pHttpSession ) ); 1442*8590a0fdSAndre Fischer throw DAVException( 1443*8590a0fdSAndre Fischer DAVException::DAV_HTTP_REDIRECT, aUri.GetURI() ); 1444*8590a0fdSAndre Fischer } 1445*8590a0fdSAndre Fischer default: 1446*8590a0fdSAndre Fischer { 1447*8590a0fdSAndre Fischer OSL_TRACE( "SerfSession::HandleError : Unknown Serf error code!" ); 1448*8590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, 1449*8590a0fdSAndre Fischer rtl::OUString::createFromAscii( 1450*8590a0fdSAndre Fischer ne_get_error( m_pHttpSession ) ) ); 1451*8590a0fdSAndre Fischer } 1452*8590a0fdSAndre Fischer } 1453*8590a0fdSAndre Fischer */ 1454*8590a0fdSAndre Fischer } 1455*8590a0fdSAndre Fischer 1456*8590a0fdSAndre Fischer // ------------------------------------------------------------------- 1457*8590a0fdSAndre Fischer // static 1458*8590a0fdSAndre Fischer bool 1459*8590a0fdSAndre Fischer SerfSession::getDataFromInputStream( 1460*8590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & xStream, 1461*8590a0fdSAndre Fischer uno::Sequence< sal_Int8 > & rData, 1462*8590a0fdSAndre Fischer bool bAppendTrailingZeroByte ) 1463*8590a0fdSAndre Fischer { 1464*8590a0fdSAndre Fischer if ( xStream.is() ) 1465*8590a0fdSAndre Fischer { 1466*8590a0fdSAndre Fischer uno::Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY ); 1467*8590a0fdSAndre Fischer if ( xSeekable.is() ) 1468*8590a0fdSAndre Fischer { 1469*8590a0fdSAndre Fischer try 1470*8590a0fdSAndre Fischer { 1471*8590a0fdSAndre Fischer sal_Int32 nSize 1472*8590a0fdSAndre Fischer = sal::static_int_cast<sal_Int32>(xSeekable->getLength()); 1473*8590a0fdSAndre Fischer sal_Int32 nRead 1474*8590a0fdSAndre Fischer = xStream->readBytes( rData, nSize ); 1475*8590a0fdSAndre Fischer 1476*8590a0fdSAndre Fischer if ( nRead == nSize ) 1477*8590a0fdSAndre Fischer { 1478*8590a0fdSAndre Fischer if ( bAppendTrailingZeroByte ) 1479*8590a0fdSAndre Fischer { 1480*8590a0fdSAndre Fischer rData.realloc( nSize + 1 ); 1481*8590a0fdSAndre Fischer rData[ nSize ] = sal_Int8( 0 ); 1482*8590a0fdSAndre Fischer } 1483*8590a0fdSAndre Fischer return true; 1484*8590a0fdSAndre Fischer } 1485*8590a0fdSAndre Fischer } 1486*8590a0fdSAndre Fischer catch ( io::NotConnectedException const & ) 1487*8590a0fdSAndre Fischer { 1488*8590a0fdSAndre Fischer // readBytes 1489*8590a0fdSAndre Fischer } 1490*8590a0fdSAndre Fischer catch ( io::BufferSizeExceededException const & ) 1491*8590a0fdSAndre Fischer { 1492*8590a0fdSAndre Fischer // readBytes 1493*8590a0fdSAndre Fischer } 1494*8590a0fdSAndre Fischer catch ( io::IOException const & ) 1495*8590a0fdSAndre Fischer { 1496*8590a0fdSAndre Fischer // getLength, readBytes 1497*8590a0fdSAndre Fischer } 1498*8590a0fdSAndre Fischer } 1499*8590a0fdSAndre Fischer else 1500*8590a0fdSAndre Fischer { 1501*8590a0fdSAndre Fischer try 1502*8590a0fdSAndre Fischer { 1503*8590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aBuffer; 1504*8590a0fdSAndre Fischer sal_Int32 nPos = 0; 1505*8590a0fdSAndre Fischer 1506*8590a0fdSAndre Fischer sal_Int32 nRead = xStream->readSomeBytes( aBuffer, 65536 ); 1507*8590a0fdSAndre Fischer while ( nRead > 0 ) 1508*8590a0fdSAndre Fischer { 1509*8590a0fdSAndre Fischer if ( rData.getLength() < ( nPos + nRead ) ) 1510*8590a0fdSAndre Fischer rData.realloc( nPos + nRead ); 1511*8590a0fdSAndre Fischer 1512*8590a0fdSAndre Fischer aBuffer.realloc( nRead ); 1513*8590a0fdSAndre Fischer rtl_copyMemory( (void*)( rData.getArray() + nPos ), 1514*8590a0fdSAndre Fischer (const void*)aBuffer.getConstArray(), 1515*8590a0fdSAndre Fischer nRead ); 1516*8590a0fdSAndre Fischer nPos += nRead; 1517*8590a0fdSAndre Fischer 1518*8590a0fdSAndre Fischer aBuffer.realloc( 0 ); 1519*8590a0fdSAndre Fischer nRead = xStream->readSomeBytes( aBuffer, 65536 ); 1520*8590a0fdSAndre Fischer } 1521*8590a0fdSAndre Fischer 1522*8590a0fdSAndre Fischer if ( bAppendTrailingZeroByte ) 1523*8590a0fdSAndre Fischer { 1524*8590a0fdSAndre Fischer rData.realloc( nPos + 1 ); 1525*8590a0fdSAndre Fischer rData[ nPos ] = sal_Int8( 0 ); 1526*8590a0fdSAndre Fischer } 1527*8590a0fdSAndre Fischer return true; 1528*8590a0fdSAndre Fischer } 1529*8590a0fdSAndre Fischer catch ( io::NotConnectedException const & ) 1530*8590a0fdSAndre Fischer { 1531*8590a0fdSAndre Fischer // readBytes 1532*8590a0fdSAndre Fischer } 1533*8590a0fdSAndre Fischer catch ( io::BufferSizeExceededException const & ) 1534*8590a0fdSAndre Fischer { 1535*8590a0fdSAndre Fischer // readBytes 1536*8590a0fdSAndre Fischer } 1537*8590a0fdSAndre Fischer catch ( io::IOException const & ) 1538*8590a0fdSAndre Fischer { 1539*8590a0fdSAndre Fischer // readBytes 1540*8590a0fdSAndre Fischer } 1541*8590a0fdSAndre Fischer } 1542*8590a0fdSAndre Fischer } 1543*8590a0fdSAndre Fischer return false; 1544*8590a0fdSAndre Fischer } 1545*8590a0fdSAndre Fischer 1546*8590a0fdSAndre Fischer // --------------------------------------------------------------------- 1547*8590a0fdSAndre Fischer sal_Bool 1548*8590a0fdSAndre Fischer SerfSession::isDomainMatch( rtl::OUString certHostName ) 1549*8590a0fdSAndre Fischer { 1550*8590a0fdSAndre Fischer rtl::OUString hostName = getHostName(); 1551*8590a0fdSAndre Fischer 1552*8590a0fdSAndre Fischer if (hostName.equalsIgnoreAsciiCase( certHostName ) ) 1553*8590a0fdSAndre Fischer return sal_True; 1554*8590a0fdSAndre Fischer 1555*8590a0fdSAndre Fischer if ( 0 == certHostName.indexOf( rtl::OUString::createFromAscii( "*" ) ) && 1556*8590a0fdSAndre Fischer hostName.getLength() >= certHostName.getLength() ) 1557*8590a0fdSAndre Fischer { 1558*8590a0fdSAndre Fischer rtl::OUString cmpStr = certHostName.copy( 1 ); 1559*8590a0fdSAndre Fischer 1560*8590a0fdSAndre Fischer if ( hostName.matchIgnoreAsciiCase( 1561*8590a0fdSAndre Fischer cmpStr, hostName.getLength() - cmpStr.getLength() ) ) 1562*8590a0fdSAndre Fischer return sal_True; 1563*8590a0fdSAndre Fischer } 1564*8590a0fdSAndre Fischer return sal_False; 1565*8590a0fdSAndre Fischer } 1566*8590a0fdSAndre Fischer 1567*8590a0fdSAndre Fischer /* 1568*8590a0fdSAndre Fischer // --------------------------------------------------------------------- 1569*8590a0fdSAndre Fischer rtl::OUString SerfSession::makeAbsoluteURL( rtl::OUString const & rURL ) const 1570*8590a0fdSAndre Fischer { 1571*8590a0fdSAndre Fischer try 1572*8590a0fdSAndre Fischer { 1573*8590a0fdSAndre Fischer // Is URL relative or already absolute? 1574*8590a0fdSAndre Fischer if ( rURL[ 0 ] != sal_Unicode( '/' ) ) 1575*8590a0fdSAndre Fischer { 1576*8590a0fdSAndre Fischer // absolute. 1577*8590a0fdSAndre Fischer return rtl::OUString( rURL ); 1578*8590a0fdSAndre Fischer } 1579*8590a0fdSAndre Fischer else 1580*8590a0fdSAndre Fischer { 1581*8590a0fdSAndre Fischer ne_uri aUri; 1582*8590a0fdSAndre Fischer memset( &aUri, 0, sizeof( aUri ) ); 1583*8590a0fdSAndre Fischer 1584*8590a0fdSAndre Fischer ne_fill_server_uri( m_pHttpSession, &aUri ); 1585*8590a0fdSAndre Fischer aUri.path 1586*8590a0fdSAndre Fischer = ne_strdup( rtl::OUStringToOString( 1587*8590a0fdSAndre Fischer rURL, RTL_TEXTENCODING_UTF8 ).getStr() ); 1588*8590a0fdSAndre Fischer SerfUri aSerfUri( &aUri ); 1589*8590a0fdSAndre Fischer ne_uri_free( &aUri ); 1590*8590a0fdSAndre Fischer return aSerfUri.GetURI(); 1591*8590a0fdSAndre Fischer } 1592*8590a0fdSAndre Fischer } 1593*8590a0fdSAndre Fischer catch ( DAVException const & ) 1594*8590a0fdSAndre Fischer { 1595*8590a0fdSAndre Fischer } 1596*8590a0fdSAndre Fischer // error. 1597*8590a0fdSAndre Fischer return rtl::OUString(); 1598*8590a0fdSAndre Fischer } 1599*8590a0fdSAndre Fischer */ 1600