18590a0fdSAndre Fischer /************************************************************** 28590a0fdSAndre Fischer * 38590a0fdSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 48590a0fdSAndre Fischer * or more contributor license agreements. See the NOTICE file 58590a0fdSAndre Fischer * distributed with this work for additional information 68590a0fdSAndre Fischer * regarding copyright ownership. The ASF licenses this file 78590a0fdSAndre Fischer * to you under the Apache License, Version 2.0 (the 88590a0fdSAndre Fischer * "License"); you may not use this file except in compliance 98590a0fdSAndre Fischer * with the License. You may obtain a copy of the License at 108590a0fdSAndre Fischer * 118590a0fdSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 128590a0fdSAndre Fischer * 138590a0fdSAndre Fischer * Unless required by applicable law or agreed to in writing, 148590a0fdSAndre Fischer * software distributed under the License is distributed on an 158590a0fdSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 168590a0fdSAndre Fischer * KIND, either express or implied. See the License for the 178590a0fdSAndre Fischer * specific language governing permissions and limitations 188590a0fdSAndre Fischer * under the License. 198590a0fdSAndre Fischer * 208590a0fdSAndre Fischer *************************************************************/ 218590a0fdSAndre Fischer 228590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove 238590a0fdSAndre Fischer #include "precompiled_ucb.hxx" 248590a0fdSAndre Fischer 258590a0fdSAndre Fischer #include <hash_map> 268590a0fdSAndre Fischer #include <vector> 278590a0fdSAndre Fischer #include <string.h> 288590a0fdSAndre Fischer #include <rtl/string.h> 298590a0fdSAndre Fischer #include "comphelper/sequence.hxx" 308590a0fdSAndre Fischer #include "ucbhelper/simplecertificatevalidationrequest.hxx" 318590a0fdSAndre Fischer 328590a0fdSAndre Fischer #include <AprEnv.hxx> 338590a0fdSAndre Fischer #include <apr_strings.h> 348590a0fdSAndre Fischer 358590a0fdSAndre Fischer #include "DAVAuthListener.hxx" 368590a0fdSAndre Fischer #include <SerfTypes.hxx> 378590a0fdSAndre Fischer #include <SerfSession.hxx> 388590a0fdSAndre Fischer #include <SerfUri.hxx> 398590a0fdSAndre Fischer #include <SerfRequestProcessor.hxx> 408590a0fdSAndre Fischer #include <SerfCallbacks.hxx> 418590a0fdSAndre Fischer #include <SerfInputStream.hxx> 428590a0fdSAndre Fischer #include <UCBDeadPropertyValue.hxx> 438590a0fdSAndre Fischer 448590a0fdSAndre Fischer #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> 458590a0fdSAndre Fischer #include <com/sun/star/security/XCertificate.hpp> 468590a0fdSAndre Fischer #include <com/sun/star/security/CertificateValidity.hpp> 478590a0fdSAndre Fischer #include <com/sun/star/security/CertificateContainerStatus.hpp> 488590a0fdSAndre Fischer #include <com/sun/star/security/CertificateContainer.hpp> 498590a0fdSAndre Fischer #include <com/sun/star/security/XCertificateContainer.hpp> 508590a0fdSAndre Fischer #include <com/sun/star/ucb/Lock.hpp> 518590a0fdSAndre Fischer #include <com/sun/star/xml/crypto/XSEInitializer.hpp> 528590a0fdSAndre Fischer 538590a0fdSAndre Fischer using namespace com::sun::star; 548590a0fdSAndre Fischer using namespace http_dav_ucp; 558590a0fdSAndre Fischer 568590a0fdSAndre Fischer // ------------------------------------------------------------------- 578590a0fdSAndre Fischer // static members! 588590a0fdSAndre Fischer bool SerfSession::m_bGlobalsInited = false; 598590a0fdSAndre Fischer osl::Mutex SerfSession::m_aGlobalMutex; 608590a0fdSAndre Fischer //SerfLockStore SerfSession::m_aSerfLockStore; 618590a0fdSAndre Fischer 628590a0fdSAndre Fischer // ------------------------------------------------------------------- 638590a0fdSAndre Fischer // Constructor 648590a0fdSAndre Fischer // ------------------------------------------------------------------- 658590a0fdSAndre Fischer SerfSession::SerfSession( 668590a0fdSAndre Fischer const rtl::Reference< DAVSessionFactory > & rSessionFactory, 678590a0fdSAndre Fischer const rtl::OUString& inUri, 688590a0fdSAndre Fischer const ucbhelper::InternetProxyDecider & rProxyDecider ) 698590a0fdSAndre Fischer throw ( DAVException ) 708590a0fdSAndre Fischer : DAVSession( rSessionFactory ) 718590a0fdSAndre Fischer , m_aMutex() 728590a0fdSAndre Fischer , m_aUri( inUri ) 738590a0fdSAndre Fischer , m_aProxyName() 748590a0fdSAndre Fischer , m_nProxyPort( 0 ) 758590a0fdSAndre Fischer , m_pSerfConnection( 0 ) 768590a0fdSAndre Fischer , m_pSerfContext( 0 ) 778590a0fdSAndre Fischer , m_bIsHeadRequestInProgress( false ) 788590a0fdSAndre Fischer , m_rProxyDecider( rProxyDecider ) 798590a0fdSAndre Fischer , m_aEnv() 808590a0fdSAndre Fischer { 818590a0fdSAndre Fischer m_pSerfContext = serf_context_create( getAprPool() ); 828590a0fdSAndre Fischer 838590a0fdSAndre Fischer m_pSerfBucket_Alloc = serf_bucket_allocator_create( getAprPool(), NULL, NULL ); 848590a0fdSAndre Fischer } 858590a0fdSAndre Fischer 868590a0fdSAndre Fischer // ------------------------------------------------------------------- 878590a0fdSAndre Fischer // Destructor 888590a0fdSAndre Fischer // ------------------------------------------------------------------- 898590a0fdSAndre Fischer SerfSession::~SerfSession( ) 908590a0fdSAndre Fischer { 918590a0fdSAndre Fischer if ( m_pSerfConnection ) 928590a0fdSAndre Fischer { 938590a0fdSAndre Fischer serf_connection_close( m_pSerfConnection ); 948590a0fdSAndre Fischer m_pSerfConnection = 0; 958590a0fdSAndre Fischer } 968590a0fdSAndre Fischer } 978590a0fdSAndre Fischer 988590a0fdSAndre Fischer // ------------------------------------------------------------------- 998590a0fdSAndre Fischer void SerfSession::Init( const DAVRequestEnvironment & rEnv ) 1008590a0fdSAndre Fischer throw ( DAVException ) 1018590a0fdSAndre Fischer { 1028590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1038590a0fdSAndre Fischer m_aEnv = rEnv; 1048590a0fdSAndre Fischer Init(); 1058590a0fdSAndre Fischer } 1068590a0fdSAndre Fischer 1078590a0fdSAndre Fischer // ------------------------------------------------------------------- 1088590a0fdSAndre Fischer void SerfSession::Init() 1098590a0fdSAndre Fischer throw ( DAVException ) 1108590a0fdSAndre Fischer { 1118590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1128590a0fdSAndre Fischer 1138590a0fdSAndre Fischer bool bCreateNewSession = false; 1148590a0fdSAndre Fischer 1158590a0fdSAndre Fischer if ( m_pSerfConnection == 0 ) 1168590a0fdSAndre Fischer { 1178590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGlobalGuard( m_aGlobalMutex ); 1188590a0fdSAndre Fischer // <-- 1198590a0fdSAndre Fischer if ( !m_bGlobalsInited ) 1208590a0fdSAndre Fischer { 1218590a0fdSAndre Fischer // TODO - figure out, if anything has to be done here 1228590a0fdSAndre Fischer m_bGlobalsInited = true; 1238590a0fdSAndre Fischer } 1248590a0fdSAndre Fischer 1258590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & rProxyCfg = getProxySettings(); 1268590a0fdSAndre Fischer 1278590a0fdSAndre Fischer m_aProxyName = rProxyCfg.aName; 1288590a0fdSAndre Fischer m_nProxyPort = rProxyCfg.nPort; 1298590a0fdSAndre Fischer 1308590a0fdSAndre Fischer // Not yet initialized. Create new session. 1318590a0fdSAndre Fischer bCreateNewSession = true; 1328590a0fdSAndre Fischer } 1338590a0fdSAndre Fischer else 1348590a0fdSAndre Fischer { 1358590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & rProxyCfg = getProxySettings(); 1368590a0fdSAndre Fischer 1378590a0fdSAndre Fischer if ( ( rProxyCfg.aName != m_aProxyName ) 1388590a0fdSAndre Fischer || ( rProxyCfg.nPort != m_nProxyPort ) ) 1398590a0fdSAndre Fischer { 1408590a0fdSAndre Fischer m_aProxyName = rProxyCfg.aName; 1418590a0fdSAndre Fischer m_nProxyPort = rProxyCfg.nPort; 1428590a0fdSAndre Fischer 1438590a0fdSAndre Fischer // new session needed, destroy old first 1448590a0fdSAndre Fischer serf_connection_close( m_pSerfConnection ); 1458590a0fdSAndre Fischer m_pSerfConnection = 0; 1468590a0fdSAndre Fischer bCreateNewSession = true; 1478590a0fdSAndre Fischer } 1488590a0fdSAndre Fischer } 1498590a0fdSAndre Fischer 1508590a0fdSAndre Fischer if ( bCreateNewSession ) 1518590a0fdSAndre Fischer { 1528590a0fdSAndre Fischer // TODO - close_connection callback 1538590a0fdSAndre Fischer apr_status_t status = serf_connection_create2( &m_pSerfConnection, 1548590a0fdSAndre Fischer m_pSerfContext, 1558590a0fdSAndre Fischer *(m_aUri.getAprUri()), 1568590a0fdSAndre Fischer Serf_ConnectSetup, this, 1578590a0fdSAndre Fischer 0 /* close connection callback */, 0 /* close connection baton */, 1588590a0fdSAndre Fischer getAprPool() ); 1598590a0fdSAndre Fischer 1608590a0fdSAndre Fischer if ( m_pSerfConnection == 0 ||status != APR_SUCCESS ) 1618590a0fdSAndre Fischer { 1628590a0fdSAndre Fischer throw DAVException( DAVException::DAV_SESSION_CREATE, 1638590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( m_aUri.GetHost(), m_aUri.GetPort() ) ); 1648590a0fdSAndre Fischer } 1658590a0fdSAndre Fischer 1668590a0fdSAndre Fischer // Register the session with the lock store 1678590a0fdSAndre Fischer // m_aSerfLockStore.registerSession( m_pSerfConnection ); 1688590a0fdSAndre Fischer 1698590a0fdSAndre Fischer if ( m_aProxyName.getLength() ) 1708590a0fdSAndre Fischer { 1718590a0fdSAndre Fischer apr_sockaddr_t *proxy_address = NULL; 1728590a0fdSAndre Fischer const apr_status_t status = apr_sockaddr_info_get( &proxy_address, 1738590a0fdSAndre Fischer rtl::OUStringToOString( m_aProxyName, RTL_TEXTENCODING_UTF8 ), 1748590a0fdSAndre Fischer APR_UNSPEC, 1758590a0fdSAndre Fischer static_cast<apr_port_t>(m_nProxyPort), 1768590a0fdSAndre Fischer 0, getAprPool() ); 1778590a0fdSAndre Fischer 1788590a0fdSAndre Fischer if ( status != APR_SUCCESS ) 1798590a0fdSAndre Fischer { 1808590a0fdSAndre Fischer throw DAVException( DAVException::DAV_SESSION_CREATE, 1818590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( m_aUri.GetHost(), m_aUri.GetPort() ) ); 1828590a0fdSAndre Fischer } 1838590a0fdSAndre Fischer 1848590a0fdSAndre Fischer serf_config_proxy( m_pSerfContext, proxy_address ); 1858590a0fdSAndre Fischer } 1868590a0fdSAndre Fischer 1878590a0fdSAndre Fischer 1888590a0fdSAndre Fischer serf_config_credentials_callback( m_pSerfContext, Serf_Credentials ); 1898590a0fdSAndre Fischer } 1908590a0fdSAndre Fischer } 1918590a0fdSAndre Fischer 1928590a0fdSAndre Fischer apr_pool_t* SerfSession::getAprPool() 1938590a0fdSAndre Fischer { 1948590a0fdSAndre Fischer return apr_environment::AprEnv::getAprEnv()->getAprPool(); 1958590a0fdSAndre Fischer } 1968590a0fdSAndre Fischer 1978590a0fdSAndre Fischer serf_bucket_alloc_t* SerfSession::getSerfBktAlloc() 1988590a0fdSAndre Fischer { 1998590a0fdSAndre Fischer return m_pSerfBucket_Alloc; 2008590a0fdSAndre Fischer } 2018590a0fdSAndre Fischer 2028590a0fdSAndre Fischer serf_context_t* SerfSession::getSerfContext() 2038590a0fdSAndre Fischer { 2048590a0fdSAndre Fischer return m_pSerfContext; 2058590a0fdSAndre Fischer } 2068590a0fdSAndre Fischer 2078590a0fdSAndre Fischer SerfConnection* SerfSession::getSerfConnection() 2088590a0fdSAndre Fischer { 2098590a0fdSAndre Fischer return m_pSerfConnection; 2108590a0fdSAndre Fischer } 2118590a0fdSAndre Fischer 2128590a0fdSAndre Fischer bool SerfSession::isHeadRequestInProgress() 2138590a0fdSAndre Fischer { 2148590a0fdSAndre Fischer return m_bIsHeadRequestInProgress; 2158590a0fdSAndre Fischer } 2168590a0fdSAndre Fischer 2178590a0fdSAndre Fischer bool SerfSession::isSSLNeeded() 2188590a0fdSAndre Fischer { 2198590a0fdSAndre Fischer return m_aUri.GetScheme().equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "https" ) ) ); 2208590a0fdSAndre Fischer } 2218590a0fdSAndre Fischer 2228590a0fdSAndre Fischer char* SerfSession::getHostinfo() 2238590a0fdSAndre Fischer { 2248590a0fdSAndre Fischer return m_aUri.getAprUri()->hostinfo; 2258590a0fdSAndre Fischer } 2268590a0fdSAndre Fischer 2278590a0fdSAndre Fischer 2288590a0fdSAndre Fischer // ------------------------------------------------------------------- 2298590a0fdSAndre Fischer // virtual 2308590a0fdSAndre Fischer sal_Bool SerfSession::CanUse( const rtl::OUString & inUri ) 2318590a0fdSAndre Fischer { 2328590a0fdSAndre Fischer try 2338590a0fdSAndre Fischer { 2348590a0fdSAndre Fischer SerfUri theUri( inUri ); 2358590a0fdSAndre Fischer if ( ( theUri.GetPort() == m_aUri.GetPort() ) && 2368590a0fdSAndre Fischer ( theUri.GetHost() == m_aUri.GetHost() ) && 2378590a0fdSAndre Fischer ( theUri.GetScheme() == m_aUri.GetScheme() ) ) 2388590a0fdSAndre Fischer { 2398590a0fdSAndre Fischer return sal_True; 2408590a0fdSAndre Fischer } 2418590a0fdSAndre Fischer } 2428590a0fdSAndre Fischer catch ( DAVException const & ) 2438590a0fdSAndre Fischer { 2448590a0fdSAndre Fischer return sal_False; 2458590a0fdSAndre Fischer } 2468590a0fdSAndre Fischer return sal_False; 2478590a0fdSAndre Fischer } 2488590a0fdSAndre Fischer 2498590a0fdSAndre Fischer // ------------------------------------------------------------------- 2508590a0fdSAndre Fischer // virtual 2518590a0fdSAndre Fischer sal_Bool SerfSession::UsesProxy() 2528590a0fdSAndre Fischer { 2538590a0fdSAndre Fischer Init(); 2548590a0fdSAndre Fischer return ( m_aProxyName.getLength() > 0 ); 2558590a0fdSAndre Fischer } 2568590a0fdSAndre Fischer 2578590a0fdSAndre Fischer apr_status_t SerfSession::setupSerfConnection( apr_socket_t * inAprSocket, 2588590a0fdSAndre Fischer serf_bucket_t **outSerfInputBucket, 2598590a0fdSAndre Fischer serf_bucket_t **outSerfOutputBucket, 2608590a0fdSAndre Fischer apr_pool_t* /*inAprPool*/ ) 2618590a0fdSAndre Fischer { 2628590a0fdSAndre Fischer serf_bucket_t *tmpInputBkt; 2638590a0fdSAndre Fischer tmpInputBkt = serf_context_bucket_socket_create( getSerfContext(), 2648590a0fdSAndre Fischer inAprSocket, 2658590a0fdSAndre Fischer getSerfBktAlloc() ); 2668590a0fdSAndre Fischer 2678590a0fdSAndre Fischer if ( isSSLNeeded() ) 2688590a0fdSAndre Fischer { 2698590a0fdSAndre Fischer tmpInputBkt = serf_bucket_ssl_decrypt_create( tmpInputBkt, 2708590a0fdSAndre Fischer 0, 2718590a0fdSAndre Fischer getSerfBktAlloc() ); 2728590a0fdSAndre Fischer serf_ssl_server_cert_callback_set( serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), 2738590a0fdSAndre Fischer Serf_CertificationValidation, 2748590a0fdSAndre Fischer this ); 2758590a0fdSAndre Fischer serf_ssl_set_hostname( serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), 2768590a0fdSAndre Fischer getHostinfo() ); 2778590a0fdSAndre Fischer 2788590a0fdSAndre Fischer *outSerfOutputBucket = serf_bucket_ssl_encrypt_create( *outSerfOutputBucket, 2798590a0fdSAndre Fischer serf_bucket_ssl_decrypt_context_get( tmpInputBkt ), 2808590a0fdSAndre Fischer getSerfBktAlloc() ); 2818590a0fdSAndre Fischer } 2828590a0fdSAndre Fischer 2838590a0fdSAndre Fischer *outSerfInputBucket = tmpInputBkt; 2848590a0fdSAndre Fischer 2858590a0fdSAndre Fischer return APR_SUCCESS; 2868590a0fdSAndre Fischer } 2878590a0fdSAndre Fischer 288*fb7f54d2SOliver-Rainer Wittmann apr_status_t SerfSession::provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry, 289*fb7f54d2SOliver-Rainer Wittmann char ** outUsername, 2908590a0fdSAndre Fischer char ** outPassword, 2918590a0fdSAndre Fischer serf_request_t * /*inRequest*/, 2928590a0fdSAndre Fischer int /*inCode*/, 2938590a0fdSAndre Fischer const char *inAuthProtocol, 2948590a0fdSAndre Fischer const char *inRealm, 2958590a0fdSAndre Fischer apr_pool_t *inAprPool ) 2968590a0fdSAndre Fischer { 2978590a0fdSAndre Fischer DAVAuthListener * pListener = getRequestEnvironment().m_xAuthListener.get(); 2988590a0fdSAndre Fischer if ( !pListener ) 2998590a0fdSAndre Fischer { 3008590a0fdSAndre Fischer // abort 3018590a0fdSAndre Fischer return SERF_ERROR_AUTHN_FAILED; 3028590a0fdSAndre Fischer } 3038590a0fdSAndre Fischer 3048590a0fdSAndre Fischer rtl::OUString theUserName; 3058590a0fdSAndre Fischer rtl::OUString thePassWord; 3068590a0fdSAndre Fischer try 3078590a0fdSAndre Fischer { 3088590a0fdSAndre Fischer SerfUri uri( getRequestEnvironment().m_aRequestURI ); 3098590a0fdSAndre Fischer rtl::OUString aUserInfo( uri.GetUserInfo() ); 3108590a0fdSAndre Fischer if ( aUserInfo.getLength() ) 3118590a0fdSAndre Fischer { 3128590a0fdSAndre Fischer sal_Int32 nPos = aUserInfo.indexOf( '@' ); 3138590a0fdSAndre Fischer if ( nPos == -1 ) 3148590a0fdSAndre Fischer { 3158590a0fdSAndre Fischer theUserName = aUserInfo; 3168590a0fdSAndre Fischer } 3178590a0fdSAndre Fischer else 3188590a0fdSAndre Fischer { 3198590a0fdSAndre Fischer theUserName = aUserInfo.copy( 0, nPos ); 3208590a0fdSAndre Fischer thePassWord = aUserInfo.copy( nPos + 1 ); 3218590a0fdSAndre Fischer } 3228590a0fdSAndre Fischer } 3238590a0fdSAndre Fischer } 3248590a0fdSAndre Fischer catch ( DAVException const & ) 3258590a0fdSAndre Fischer { 3268590a0fdSAndre Fischer // abort 3278590a0fdSAndre Fischer return SERF_ERROR_AUTHN_FAILED; 3288590a0fdSAndre Fischer } 3298590a0fdSAndre Fischer 3308590a0fdSAndre Fischer const bool bCanUseSystemCreds = ( ( strcasecmp( inAuthProtocol, "NTLM" ) == 0 ) || 3318590a0fdSAndre Fischer ( strcasecmp( inAuthProtocol, "Negotiate" ) == 0 ) ); 3328590a0fdSAndre Fischer 3338590a0fdSAndre Fischer int theRetVal = pListener->authenticate( rtl::OUString::createFromAscii( inRealm ), 3348590a0fdSAndre Fischer getHostName(), 3358590a0fdSAndre Fischer theUserName, 3368590a0fdSAndre Fischer thePassWord, 337*fb7f54d2SOliver-Rainer Wittmann bCanUseSystemCreds, 338*fb7f54d2SOliver-Rainer Wittmann bGiveProvidedCredentialsASecondTry ? sal_False : sal_True ); 3398590a0fdSAndre Fischer 3408590a0fdSAndre Fischer if ( theRetVal == 0 ) 3418590a0fdSAndre Fischer { 3428590a0fdSAndre Fischer *outUsername = apr_pstrdup( inAprPool, rtl::OUStringToOString( theUserName, RTL_TEXTENCODING_UTF8 ) ); 3438590a0fdSAndre Fischer *outPassword = apr_pstrdup( inAprPool, rtl::OUStringToOString( thePassWord, RTL_TEXTENCODING_UTF8 ) ); 3448590a0fdSAndre Fischer } 3458590a0fdSAndre Fischer 3468590a0fdSAndre Fischer return theRetVal != 0 ? SERF_ERROR_AUTHN_FAILED : APR_SUCCESS; 3478590a0fdSAndre Fischer } 3488590a0fdSAndre Fischer 3498590a0fdSAndre Fischer namespace { 3508590a0fdSAndre Fischer // ------------------------------------------------------------------- 3518590a0fdSAndre Fischer // Helper function 3528590a0fdSAndre Fischer ::rtl::OUString GetHostnamePart( const ::rtl::OUString& _rRawString ) 3538590a0fdSAndre Fischer { 3548590a0fdSAndre Fischer ::rtl::OUString sPart; 3558590a0fdSAndre Fischer ::rtl::OUString sPartId = ::rtl::OUString::createFromAscii( "CN=" ); 3568590a0fdSAndre Fischer sal_Int32 nContStart = _rRawString.indexOf( sPartId ); 3578590a0fdSAndre Fischer if ( nContStart != -1 ) 3588590a0fdSAndre Fischer { 3598590a0fdSAndre Fischer nContStart = nContStart + sPartId.getLength(); 3608590a0fdSAndre Fischer sal_Int32 nContEnd 3618590a0fdSAndre Fischer = _rRawString.indexOf( sal_Unicode( ',' ), nContStart ); 3628590a0fdSAndre Fischer sPart = _rRawString.copy( nContStart, nContEnd - nContStart ); 3638590a0fdSAndre Fischer } 3648590a0fdSAndre Fischer return sPart; 3658590a0fdSAndre Fischer } 3668590a0fdSAndre Fischer } // namespace 3678590a0fdSAndre Fischer 3688590a0fdSAndre Fischer apr_status_t SerfSession::verifySerfCertificate( int inFailures, 3698590a0fdSAndre Fischer const serf_ssl_certificate_t * inCert ) 3708590a0fdSAndre Fischer { 3718590a0fdSAndre Fischer OSL_ASSERT( inCert ); 3728590a0fdSAndre Fischer 3738590a0fdSAndre Fischer uno::Reference< security::XCertificateContainer > xCertificateContainer; 3748590a0fdSAndre Fischer try 3758590a0fdSAndre Fischer { 3768590a0fdSAndre Fischer xCertificateContainer 3778590a0fdSAndre Fischer = uno::Reference< security::XCertificateContainer >( 3788590a0fdSAndre Fischer getMSF()->createInstance( 3798590a0fdSAndre Fischer rtl::OUString::createFromAscii( 3808590a0fdSAndre Fischer "com.sun.star.security.CertificateContainer" ) ), 3818590a0fdSAndre Fischer uno::UNO_QUERY ); 3828590a0fdSAndre Fischer } 3838590a0fdSAndre Fischer catch ( uno::Exception const & ) 3848590a0fdSAndre Fischer { 3858590a0fdSAndre Fischer } 3868590a0fdSAndre Fischer 3878590a0fdSAndre Fischer if ( !xCertificateContainer.is() ) 3888590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 3898590a0fdSAndre Fischer 3908590a0fdSAndre Fischer inFailures = 0; 3918590a0fdSAndre Fischer 3928590a0fdSAndre Fischer const char * subjectItem = static_cast<char*>(apr_hash_get( serf_ssl_cert_subject( inCert, getAprPool() ), 3938590a0fdSAndre Fischer "CN", APR_HASH_KEY_STRING )); 3948590a0fdSAndre Fischer if ( subjectItem == 0 ) 3958590a0fdSAndre Fischer { 3968590a0fdSAndre Fischer subjectItem = static_cast<char*>(apr_hash_get( serf_ssl_cert_subject( inCert, getAprPool() ), 3978590a0fdSAndre Fischer "OU", APR_HASH_KEY_STRING )); 3988590a0fdSAndre Fischer } 3998590a0fdSAndre Fischer rtl::OUString cert_subject; 4008590a0fdSAndre Fischer if ( subjectItem != 0 ) 4018590a0fdSAndre Fischer { 4028590a0fdSAndre Fischer cert_subject = rtl::OUString( subjectItem, strlen( subjectItem ), RTL_TEXTENCODING_UTF8, 0 ); 4038590a0fdSAndre Fischer } 4048590a0fdSAndre Fischer else 4058590a0fdSAndre Fischer { 4068590a0fdSAndre Fischer rtl::OUString::createFromAscii( "unknown subject" ); 4078590a0fdSAndre Fischer } 4088590a0fdSAndre Fischer 4098590a0fdSAndre Fischer security::CertificateContainerStatus certificateContainer( 4108590a0fdSAndre Fischer xCertificateContainer->hasCertificate( 4118590a0fdSAndre Fischer getHostName(), cert_subject ) ); 4128590a0fdSAndre Fischer 4138590a0fdSAndre Fischer if ( certificateContainer != security::CertificateContainerStatus_NOCERT ) 4148590a0fdSAndre Fischer { 4158590a0fdSAndre Fischer return certificateContainer == security::CertificateContainerStatus_TRUSTED 4168590a0fdSAndre Fischer ? APR_SUCCESS 4178590a0fdSAndre Fischer : SERF_SSL_CERT_UNKNOWN_FAILURE; 4188590a0fdSAndre Fischer } 4198590a0fdSAndre Fischer 4208590a0fdSAndre Fischer uno::Reference< xml::crypto::XSEInitializer > xSEInitializer; 4218590a0fdSAndre Fischer try 4228590a0fdSAndre Fischer { 4238590a0fdSAndre Fischer xSEInitializer = uno::Reference< xml::crypto::XSEInitializer >( 4248590a0fdSAndre Fischer getMSF()->createInstance( 4258590a0fdSAndre Fischer rtl::OUString::createFromAscii( "com.sun.star.xml.crypto.SEInitializer" ) ), 4268590a0fdSAndre Fischer uno::UNO_QUERY ); 4278590a0fdSAndre Fischer } 4288590a0fdSAndre Fischer catch ( uno::Exception const & ) 4298590a0fdSAndre Fischer { 4308590a0fdSAndre Fischer } 4318590a0fdSAndre Fischer 4328590a0fdSAndre Fischer if ( !xSEInitializer.is() ) 4338590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 4348590a0fdSAndre Fischer 4358590a0fdSAndre Fischer uno::Reference< xml::crypto::XXMLSecurityContext > xSecurityContext( 4368590a0fdSAndre Fischer xSEInitializer->createSecurityContext( rtl::OUString() ) ); 4378590a0fdSAndre Fischer 4388590a0fdSAndre Fischer uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnv( 4398590a0fdSAndre Fischer xSecurityContext->getSecurityEnvironment() ); 4408590a0fdSAndre Fischer 4418590a0fdSAndre Fischer //The end entity certificate 4428590a0fdSAndre Fischer const char * eeCertB64 = serf_ssl_cert_export( inCert, getAprPool() ); 4438590a0fdSAndre Fischer 4448590a0fdSAndre Fischer rtl::OString sEECertB64( eeCertB64 ); 4458590a0fdSAndre Fischer 4468590a0fdSAndre Fischer uno::Reference< security::XCertificate > xEECert( 4478590a0fdSAndre Fischer xSecurityEnv->createCertificateFromAscii( 4488590a0fdSAndre Fischer rtl::OStringToOUString( sEECertB64, RTL_TEXTENCODING_ASCII_US ) ) ); 4498590a0fdSAndre Fischer 4508590a0fdSAndre Fischer std::vector< uno::Reference< security::XCertificate > > vecCerts; 4518590a0fdSAndre Fischer const serf_ssl_certificate_t * issuerCert = inCert; 4528590a0fdSAndre Fischer do 4538590a0fdSAndre Fischer { 4548590a0fdSAndre Fischer //get the intermediate certificate 4558590a0fdSAndre Fischer issuerCert = NULL; // TODO - figure out how to retrieve certificate chain - ssl_cert_signedby( issuerCert ); 4568590a0fdSAndre Fischer if ( NULL == issuerCert ) 4578590a0fdSAndre Fischer break; 4588590a0fdSAndre Fischer 4598590a0fdSAndre Fischer const char * imCertB64 = serf_ssl_cert_export( issuerCert, getAprPool() ); 4608590a0fdSAndre Fischer rtl::OString sInterMediateCertB64( imCertB64 ); 4618590a0fdSAndre Fischer 4628590a0fdSAndre Fischer uno::Reference< security::XCertificate> xImCert( 4638590a0fdSAndre Fischer xSecurityEnv->createCertificateFromAscii( 4648590a0fdSAndre Fischer rtl::OStringToOUString( 4658590a0fdSAndre Fischer sInterMediateCertB64, RTL_TEXTENCODING_ASCII_US ) ) ); 4668590a0fdSAndre Fischer if ( xImCert.is() ) 4678590a0fdSAndre Fischer vecCerts.push_back( xImCert ); 4688590a0fdSAndre Fischer } 4698590a0fdSAndre Fischer while ( 1 ); 4708590a0fdSAndre Fischer 4718590a0fdSAndre Fischer sal_Int64 certValidity = xSecurityEnv->verifyCertificate( xEECert, 4728590a0fdSAndre Fischer ::comphelper::containerToSequence( vecCerts ) ); 4738590a0fdSAndre Fischer 4748590a0fdSAndre Fischer if ( isDomainMatch( GetHostnamePart( xEECert.get()->getSubjectName() ) ) ) 4758590a0fdSAndre Fischer { 4768590a0fdSAndre Fischer // if host name matched with certificate then look if the 4778590a0fdSAndre Fischer // certificate was ok 4788590a0fdSAndre Fischer if( certValidity == security::CertificateValidity::VALID ) 4798590a0fdSAndre Fischer return APR_SUCCESS; 4808590a0fdSAndre Fischer } 4818590a0fdSAndre Fischer 4828590a0fdSAndre Fischer const uno::Reference< ucb::XCommandEnvironment > xEnv( getRequestEnvironment().m_xEnv ); 4838590a0fdSAndre Fischer if ( xEnv.is() ) 4848590a0fdSAndre Fischer { 4858590a0fdSAndre Fischer inFailures = static_cast< int >( certValidity ); 4868590a0fdSAndre Fischer 4878590a0fdSAndre Fischer uno::Reference< task::XInteractionHandler > xIH( xEnv->getInteractionHandler() ); 4888590a0fdSAndre Fischer if ( xIH.is() ) 4898590a0fdSAndre Fischer { 4908590a0fdSAndre Fischer rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > 4918590a0fdSAndre Fischer xRequest( new ucbhelper::SimpleCertificateValidationRequest( 4928590a0fdSAndre Fischer (sal_Int32)inFailures, xEECert, getHostName() ) ); 4938590a0fdSAndre Fischer xIH->handle( xRequest.get() ); 4948590a0fdSAndre Fischer 4958590a0fdSAndre Fischer rtl::Reference< ucbhelper::InteractionContinuation > xSelection 4968590a0fdSAndre Fischer = xRequest->getSelection(); 4978590a0fdSAndre Fischer 4988590a0fdSAndre Fischer if ( xSelection.is() ) 4998590a0fdSAndre Fischer { 5008590a0fdSAndre Fischer uno::Reference< task::XInteractionApprove > xApprove( 5018590a0fdSAndre Fischer xSelection.get(), uno::UNO_QUERY ); 5028590a0fdSAndre Fischer if ( xApprove.is() ) 5038590a0fdSAndre Fischer { 5048590a0fdSAndre Fischer xCertificateContainer->addCertificate( getHostName(), cert_subject, sal_True ); 5058590a0fdSAndre Fischer return APR_SUCCESS; 5068590a0fdSAndre Fischer } 5078590a0fdSAndre Fischer else 5088590a0fdSAndre Fischer { 5098590a0fdSAndre Fischer // Don't trust cert 5108590a0fdSAndre Fischer xCertificateContainer->addCertificate( getHostName(), cert_subject, sal_False ); 5118590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 5128590a0fdSAndre Fischer } 5138590a0fdSAndre Fischer } 5148590a0fdSAndre Fischer } 5158590a0fdSAndre Fischer else 5168590a0fdSAndre Fischer { 5178590a0fdSAndre Fischer // Don't trust cert 5188590a0fdSAndre Fischer xCertificateContainer->addCertificate( getHostName(), cert_subject, sal_False ); 5198590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 5208590a0fdSAndre Fischer } 5218590a0fdSAndre Fischer } 5228590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 5238590a0fdSAndre Fischer } 5248590a0fdSAndre Fischer 5258590a0fdSAndre Fischer serf_bucket_t* SerfSession::acceptSerfResponse( serf_request_t * inSerfRequest, 5268590a0fdSAndre Fischer serf_bucket_t * inSerfStreamBucket, 5278590a0fdSAndre Fischer apr_pool_t* /*inAprPool*/ ) 5288590a0fdSAndre Fischer { 5298590a0fdSAndre Fischer // get the per-request bucket allocator 5308590a0fdSAndre Fischer serf_bucket_alloc_t* SerfBktAlloc = serf_request_get_alloc( inSerfRequest ); 5318590a0fdSAndre Fischer 5328590a0fdSAndre Fischer // create a barrier bucket so the response doesn't eat us! 5338590a0fdSAndre Fischer serf_bucket_t *responseBkt = serf_bucket_barrier_create( inSerfStreamBucket, 5348590a0fdSAndre Fischer SerfBktAlloc ); 5358590a0fdSAndre Fischer 5368590a0fdSAndre Fischer // create response bucket 5378590a0fdSAndre Fischer responseBkt = serf_bucket_response_create( responseBkt, 5388590a0fdSAndre Fischer SerfBktAlloc ); 5398590a0fdSAndre Fischer 5408590a0fdSAndre Fischer if ( isHeadRequestInProgress() ) 5418590a0fdSAndre Fischer { 5428590a0fdSAndre Fischer // advise the response bucket that this was from a HEAD request and that it should not expect to see a response body. 5438590a0fdSAndre Fischer serf_bucket_response_set_head( responseBkt ); 5448590a0fdSAndre Fischer } 5458590a0fdSAndre Fischer 5468590a0fdSAndre Fischer return responseBkt; 5478590a0fdSAndre Fischer } 5488590a0fdSAndre Fischer 5498590a0fdSAndre Fischer // ------------------------------------------------------------------- 5508590a0fdSAndre Fischer // PROPFIND - allprop & named 5518590a0fdSAndre Fischer // ------------------------------------------------------------------- 5528590a0fdSAndre Fischer void SerfSession::PROPFIND( const rtl::OUString & inPath, 5538590a0fdSAndre Fischer const Depth inDepth, 5548590a0fdSAndre Fischer const std::vector< rtl::OUString > & inPropNames, 5558590a0fdSAndre Fischer std::vector< DAVResource > & ioResources, 5568590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 5578590a0fdSAndre Fischer throw ( DAVException ) 5588590a0fdSAndre Fischer { 5598590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 5608590a0fdSAndre Fischer 5618590a0fdSAndre Fischer Init( rEnv ); 5628590a0fdSAndre Fischer 5638590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 5648590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 5658590a0fdSAndre Fischer inPath ); 5668590a0fdSAndre Fischer aReqProc.processPropFind( inDepth, 5678590a0fdSAndre Fischer inPropNames, 5688590a0fdSAndre Fischer ioResources, 5698590a0fdSAndre Fischer status ); 5708590a0fdSAndre Fischer 5718590a0fdSAndre Fischer if ( status == APR_SUCCESS && 5728590a0fdSAndre Fischer aReqProc.mpDAVException == 0 && 5738590a0fdSAndre Fischer ioResources.empty() ) 5748590a0fdSAndre Fischer { 5758590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 5768590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, inPath, (sal_uInt16)APR_EGENERAL ); 5778590a0fdSAndre Fischer } 5788590a0fdSAndre Fischer HandleError( aReqProc, 5798590a0fdSAndre Fischer inPath, rEnv ); 5808590a0fdSAndre Fischer } 5818590a0fdSAndre Fischer 5828590a0fdSAndre Fischer // ------------------------------------------------------------------- 5838590a0fdSAndre Fischer // PROPFIND - propnames 5848590a0fdSAndre Fischer // ------------------------------------------------------------------- 5858590a0fdSAndre Fischer void SerfSession::PROPFIND( const rtl::OUString & inPath, 5868590a0fdSAndre Fischer const Depth inDepth, 5878590a0fdSAndre Fischer std::vector< DAVResourceInfo > & ioResInfo, 5888590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 5898590a0fdSAndre Fischer throw( DAVException ) 5908590a0fdSAndre Fischer { 5918590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 5928590a0fdSAndre Fischer 5938590a0fdSAndre Fischer Init( rEnv ); 5948590a0fdSAndre Fischer 5958590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 5968590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 5978590a0fdSAndre Fischer inPath ); 5988590a0fdSAndre Fischer aReqProc.processPropFind( inDepth, 5998590a0fdSAndre Fischer ioResInfo, 6008590a0fdSAndre Fischer status ); 6018590a0fdSAndre Fischer 6028590a0fdSAndre Fischer if ( status == APR_SUCCESS && 6038590a0fdSAndre Fischer aReqProc.mpDAVException == 0 && 6048590a0fdSAndre Fischer ioResInfo.empty() ) 6058590a0fdSAndre Fischer { 6068590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 6078590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, inPath, (sal_uInt16)APR_EGENERAL ); 6088590a0fdSAndre Fischer } 6098590a0fdSAndre Fischer HandleError( aReqProc, 6108590a0fdSAndre Fischer inPath, rEnv ); 6118590a0fdSAndre Fischer } 6128590a0fdSAndre Fischer 6138590a0fdSAndre Fischer // ------------------------------------------------------------------- 6148590a0fdSAndre Fischer // PROPPATCH 6158590a0fdSAndre Fischer // ------------------------------------------------------------------- 6168590a0fdSAndre Fischer void SerfSession::PROPPATCH( const rtl::OUString & inPath, 6178590a0fdSAndre Fischer const std::vector< ProppatchValue > & inValues, 6188590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6198590a0fdSAndre Fischer throw( DAVException ) 6208590a0fdSAndre Fischer { 6218590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6228590a0fdSAndre Fischer 6238590a0fdSAndre Fischer Init( rEnv ); 6248590a0fdSAndre Fischer 6258590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 6268590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 6278590a0fdSAndre Fischer inPath ); 6288590a0fdSAndre Fischer aReqProc.processPropPatch( inValues, 6298590a0fdSAndre Fischer status ); 6308590a0fdSAndre Fischer 6318590a0fdSAndre Fischer HandleError( aReqProc, 6328590a0fdSAndre Fischer inPath, rEnv ); 6338590a0fdSAndre Fischer } 6348590a0fdSAndre Fischer 6358590a0fdSAndre Fischer // ------------------------------------------------------------------- 6368590a0fdSAndre Fischer // HEAD 6378590a0fdSAndre Fischer // ------------------------------------------------------------------- 6388590a0fdSAndre Fischer void SerfSession::HEAD( const ::rtl::OUString & inPath, 6398590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 6408590a0fdSAndre Fischer DAVResource & ioResource, 6418590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6428590a0fdSAndre Fischer throw( DAVException ) 6438590a0fdSAndre Fischer { 6448590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6458590a0fdSAndre Fischer 6468590a0fdSAndre Fischer Init( rEnv ); 6478590a0fdSAndre Fischer 6488590a0fdSAndre Fischer m_bIsHeadRequestInProgress = true; 6498590a0fdSAndre Fischer 6508590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 6518590a0fdSAndre Fischer inPath ); 6528590a0fdSAndre Fischer ioResource.uri = inPath; 6538590a0fdSAndre Fischer ioResource.properties.clear(); 6548590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 6558590a0fdSAndre Fischer aReqProc.processHead( inHeaderNames, 6568590a0fdSAndre Fischer ioResource, 6578590a0fdSAndre Fischer status ); 6588590a0fdSAndre Fischer 6598590a0fdSAndre Fischer HandleError( aReqProc, 6608590a0fdSAndre Fischer inPath, rEnv ); 6618590a0fdSAndre Fischer m_bIsHeadRequestInProgress = false; 6628590a0fdSAndre Fischer } 6638590a0fdSAndre Fischer 6648590a0fdSAndre Fischer // ------------------------------------------------------------------- 6658590a0fdSAndre Fischer // GET 6668590a0fdSAndre Fischer // ------------------------------------------------------------------- 6678590a0fdSAndre Fischer uno::Reference< io::XInputStream > 6688590a0fdSAndre Fischer SerfSession::GET( const rtl::OUString & inPath, 6698590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6708590a0fdSAndre Fischer throw ( DAVException ) 6718590a0fdSAndre Fischer { 6728590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6738590a0fdSAndre Fischer 6748590a0fdSAndre Fischer Init( rEnv ); 6758590a0fdSAndre Fischer 6768590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 6778590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 6788590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 6798590a0fdSAndre Fischer inPath ); 6808590a0fdSAndre Fischer aReqProc.processGet( xInputStream, 6818590a0fdSAndre Fischer status ); 6828590a0fdSAndre Fischer 6838590a0fdSAndre Fischer HandleError( aReqProc, 6848590a0fdSAndre Fischer inPath, rEnv ); 6858590a0fdSAndre Fischer 6868590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 6878590a0fdSAndre Fischer } 6888590a0fdSAndre Fischer 6898590a0fdSAndre Fischer // ------------------------------------------------------------------- 6908590a0fdSAndre Fischer // GET 6918590a0fdSAndre Fischer // ------------------------------------------------------------------- 6928590a0fdSAndre Fischer void SerfSession::GET( const rtl::OUString & inPath, 6938590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & ioOutputStream, 6948590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6958590a0fdSAndre Fischer throw ( DAVException ) 6968590a0fdSAndre Fischer { 6978590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6988590a0fdSAndre Fischer 6998590a0fdSAndre Fischer Init( rEnv ); 7008590a0fdSAndre Fischer 7018590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 7028590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 7038590a0fdSAndre Fischer inPath ); 7048590a0fdSAndre Fischer aReqProc.processGet( ioOutputStream, 7058590a0fdSAndre Fischer status ); 7068590a0fdSAndre Fischer 7078590a0fdSAndre Fischer HandleError( aReqProc, 7088590a0fdSAndre Fischer inPath, rEnv ); 7098590a0fdSAndre Fischer } 7108590a0fdSAndre Fischer 7118590a0fdSAndre Fischer // ------------------------------------------------------------------- 7128590a0fdSAndre Fischer // GET 7138590a0fdSAndre Fischer // ------------------------------------------------------------------- 7148590a0fdSAndre Fischer uno::Reference< io::XInputStream > 7158590a0fdSAndre Fischer SerfSession::GET( const rtl::OUString & inPath, 7168590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 7178590a0fdSAndre Fischer DAVResource & ioResource, 7188590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7198590a0fdSAndre Fischer throw ( DAVException ) 7208590a0fdSAndre Fischer { 7218590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7228590a0fdSAndre Fischer 7238590a0fdSAndre Fischer Init( rEnv ); 7248590a0fdSAndre Fischer 7258590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 7268590a0fdSAndre Fischer inPath ); 7278590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 7288590a0fdSAndre Fischer ioResource.uri = inPath; 7298590a0fdSAndre Fischer ioResource.properties.clear(); 7308590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 7318590a0fdSAndre Fischer aReqProc.processGet( xInputStream, 7328590a0fdSAndre Fischer inHeaderNames, 7338590a0fdSAndre Fischer ioResource, 7348590a0fdSAndre Fischer status ); 7358590a0fdSAndre Fischer 7368590a0fdSAndre Fischer HandleError( aReqProc, 7378590a0fdSAndre Fischer inPath, rEnv ); 7388590a0fdSAndre Fischer 7398590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 7408590a0fdSAndre Fischer } 7418590a0fdSAndre Fischer 7428590a0fdSAndre Fischer 7438590a0fdSAndre Fischer // ------------------------------------------------------------------- 7448590a0fdSAndre Fischer // GET 7458590a0fdSAndre Fischer // ------------------------------------------------------------------- 7468590a0fdSAndre Fischer void SerfSession::GET( const rtl::OUString & inPath, 7478590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & ioOutputStream, 7488590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 7498590a0fdSAndre Fischer DAVResource & ioResource, 7508590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7518590a0fdSAndre Fischer throw ( DAVException ) 7528590a0fdSAndre Fischer { 7538590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7548590a0fdSAndre Fischer 7558590a0fdSAndre Fischer Init( rEnv ); 7568590a0fdSAndre Fischer 7578590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 7588590a0fdSAndre Fischer inPath ); 7598590a0fdSAndre Fischer ioResource.uri = inPath; 7608590a0fdSAndre Fischer ioResource.properties.clear(); 7618590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 7628590a0fdSAndre Fischer aReqProc.processGet( ioOutputStream, 7638590a0fdSAndre Fischer inHeaderNames, 7648590a0fdSAndre Fischer ioResource, 7658590a0fdSAndre Fischer status ); 7668590a0fdSAndre Fischer 7678590a0fdSAndre Fischer HandleError( aReqProc, 7688590a0fdSAndre Fischer inPath, rEnv ); 7698590a0fdSAndre Fischer } 7708590a0fdSAndre Fischer 7718590a0fdSAndre Fischer // ------------------------------------------------------------------- 7728590a0fdSAndre Fischer // PUT 7738590a0fdSAndre Fischer // ------------------------------------------------------------------- 7748590a0fdSAndre Fischer void SerfSession::PUT( const rtl::OUString & inPath, 7758590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 7768590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7778590a0fdSAndre Fischer throw ( DAVException ) 7788590a0fdSAndre Fischer { 7798590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7808590a0fdSAndre Fischer 7818590a0fdSAndre Fischer Init( rEnv ); 7828590a0fdSAndre Fischer 7838590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 7848590a0fdSAndre Fischer inPath ); 7858590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 7868590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, false ) ) 7878590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 7888590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 7898590a0fdSAndre Fischer aReqProc.processPut( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 7908590a0fdSAndre Fischer aDataToSend.getLength(), 7918590a0fdSAndre Fischer status ); 7928590a0fdSAndre Fischer 7938590a0fdSAndre Fischer HandleError( aReqProc, 7948590a0fdSAndre Fischer inPath, rEnv ); 7958590a0fdSAndre Fischer } 7968590a0fdSAndre Fischer 7978590a0fdSAndre Fischer // ------------------------------------------------------------------- 7988590a0fdSAndre Fischer // POST 7998590a0fdSAndre Fischer // ------------------------------------------------------------------- 8008590a0fdSAndre Fischer uno::Reference< io::XInputStream > 8018590a0fdSAndre Fischer SerfSession::POST( const rtl::OUString & inPath, 8028590a0fdSAndre Fischer const rtl::OUString & rContentType, 8038590a0fdSAndre Fischer const rtl::OUString & rReferer, 8048590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 8058590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 8068590a0fdSAndre Fischer throw ( DAVException ) 8078590a0fdSAndre Fischer { 8088590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8098590a0fdSAndre Fischer 8108590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 8118590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, true ) ) 8128590a0fdSAndre Fischer { 8138590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 8148590a0fdSAndre Fischer } 8158590a0fdSAndre Fischer 8168590a0fdSAndre Fischer Init( rEnv ); 8178590a0fdSAndre Fischer 8188590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 8198590a0fdSAndre Fischer inPath ); 8208590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 8218590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 8228590a0fdSAndre Fischer aReqProc.processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 8238590a0fdSAndre Fischer aDataToSend.getLength(), 8248590a0fdSAndre Fischer rContentType, 8258590a0fdSAndre Fischer rReferer, 8268590a0fdSAndre Fischer xInputStream, 8278590a0fdSAndre Fischer status ); 8288590a0fdSAndre Fischer 8298590a0fdSAndre Fischer HandleError( aReqProc, 8308590a0fdSAndre Fischer inPath, rEnv ); 8318590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 8328590a0fdSAndre Fischer } 8338590a0fdSAndre Fischer 8348590a0fdSAndre Fischer // ------------------------------------------------------------------- 8358590a0fdSAndre Fischer // POST 8368590a0fdSAndre Fischer // ------------------------------------------------------------------- 8378590a0fdSAndre Fischer void SerfSession::POST( const rtl::OUString & inPath, 8388590a0fdSAndre Fischer const rtl::OUString & rContentType, 8398590a0fdSAndre Fischer const rtl::OUString & rReferer, 8408590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 8418590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & oOutputStream, 8428590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 8438590a0fdSAndre Fischer throw ( DAVException ) 8448590a0fdSAndre Fischer { 8458590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8468590a0fdSAndre Fischer 8478590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 8488590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, true ) ) 8498590a0fdSAndre Fischer { 8508590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 8518590a0fdSAndre Fischer } 8528590a0fdSAndre Fischer 8538590a0fdSAndre Fischer Init( rEnv ); 8548590a0fdSAndre Fischer 8558590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 8568590a0fdSAndre Fischer inPath ); 8578590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 8588590a0fdSAndre Fischer aReqProc.processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 8598590a0fdSAndre Fischer aDataToSend.getLength(), 8608590a0fdSAndre Fischer rContentType, 8618590a0fdSAndre Fischer rReferer, 8628590a0fdSAndre Fischer oOutputStream, 8638590a0fdSAndre Fischer status ); 8648590a0fdSAndre Fischer 8658590a0fdSAndre Fischer HandleError( aReqProc, 8668590a0fdSAndre Fischer inPath, rEnv ); 8678590a0fdSAndre Fischer } 8688590a0fdSAndre Fischer 8698590a0fdSAndre Fischer // ------------------------------------------------------------------- 8708590a0fdSAndre Fischer // MKCOL 8718590a0fdSAndre Fischer // ------------------------------------------------------------------- 8728590a0fdSAndre Fischer void SerfSession::MKCOL( const rtl::OUString & inPath, 8738590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 8748590a0fdSAndre Fischer throw ( DAVException ) 8758590a0fdSAndre Fischer { 8768590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8778590a0fdSAndre Fischer 8788590a0fdSAndre Fischer Init( rEnv ); 8798590a0fdSAndre Fischer 8808590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 8818590a0fdSAndre Fischer inPath ); 8828590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 8838590a0fdSAndre Fischer aReqProc.processMkCol( status ); 8848590a0fdSAndre Fischer 8858590a0fdSAndre Fischer HandleError( aReqProc, 8868590a0fdSAndre Fischer inPath, rEnv ); 8878590a0fdSAndre Fischer } 8888590a0fdSAndre Fischer 8898590a0fdSAndre Fischer // ------------------------------------------------------------------- 8908590a0fdSAndre Fischer // COPY 8918590a0fdSAndre Fischer // ------------------------------------------------------------------- 8928590a0fdSAndre Fischer void SerfSession::COPY( const rtl::OUString & inSourceURL, 8938590a0fdSAndre Fischer const rtl::OUString & inDestinationURL, 8948590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv, 8958590a0fdSAndre Fischer sal_Bool inOverWrite ) 8968590a0fdSAndre Fischer throw ( DAVException ) 8978590a0fdSAndre Fischer { 8988590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8998590a0fdSAndre Fischer 9008590a0fdSAndre Fischer Init( rEnv ); 9018590a0fdSAndre Fischer 9028590a0fdSAndre Fischer SerfUri theSourceUri( inSourceURL ); 9038590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 9048590a0fdSAndre Fischer theSourceUri.GetPath() ); 9058590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 9068590a0fdSAndre Fischer aReqProc.processCopy( inDestinationURL, 9078590a0fdSAndre Fischer (inOverWrite ? true : false), 9088590a0fdSAndre Fischer status ); 9098590a0fdSAndre Fischer 9108590a0fdSAndre Fischer HandleError( aReqProc, 9118590a0fdSAndre Fischer inSourceURL, rEnv ); 9128590a0fdSAndre Fischer } 9138590a0fdSAndre Fischer 9148590a0fdSAndre Fischer // ------------------------------------------------------------------- 9158590a0fdSAndre Fischer // MOVE 9168590a0fdSAndre Fischer // ------------------------------------------------------------------- 9178590a0fdSAndre Fischer void SerfSession::MOVE( const rtl::OUString & inSourceURL, 9188590a0fdSAndre Fischer const rtl::OUString & inDestinationURL, 9198590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv, 9208590a0fdSAndre Fischer sal_Bool inOverWrite ) 9218590a0fdSAndre Fischer throw ( DAVException ) 9228590a0fdSAndre Fischer { 9238590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 9248590a0fdSAndre Fischer 9258590a0fdSAndre Fischer Init( rEnv ); 9268590a0fdSAndre Fischer 9278590a0fdSAndre Fischer SerfUri theSourceUri( inSourceURL ); 9288590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 9298590a0fdSAndre Fischer theSourceUri.GetPath() ); 9308590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 9318590a0fdSAndre Fischer aReqProc.processMove( inDestinationURL, 9328590a0fdSAndre Fischer (inOverWrite ? true : false), 9338590a0fdSAndre Fischer status ); 9348590a0fdSAndre Fischer 9358590a0fdSAndre Fischer HandleError( aReqProc, 9368590a0fdSAndre Fischer inSourceURL, rEnv ); 9378590a0fdSAndre Fischer } 9388590a0fdSAndre Fischer 9398590a0fdSAndre Fischer // ------------------------------------------------------------------- 9408590a0fdSAndre Fischer // DESTROY 9418590a0fdSAndre Fischer // ------------------------------------------------------------------- 9428590a0fdSAndre Fischer void SerfSession::DESTROY( const rtl::OUString & inPath, 9438590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 9448590a0fdSAndre Fischer throw ( DAVException ) 9458590a0fdSAndre Fischer { 9468590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 9478590a0fdSAndre Fischer 9488590a0fdSAndre Fischer Init( rEnv ); 9498590a0fdSAndre Fischer 9508590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 9518590a0fdSAndre Fischer inPath ); 9528590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 9538590a0fdSAndre Fischer aReqProc.processDelete( status ); 9548590a0fdSAndre Fischer 9558590a0fdSAndre Fischer HandleError( aReqProc, 9568590a0fdSAndre Fischer inPath, rEnv ); 9578590a0fdSAndre Fischer } 9588590a0fdSAndre Fischer 9598590a0fdSAndre Fischer // ------------------------------------------------------------------- 9608590a0fdSAndre Fischer /* 9618590a0fdSAndre Fischer namespace 9628590a0fdSAndre Fischer { 9638590a0fdSAndre Fischer sal_Int32 lastChanceToSendRefreshRequest( TimeValue const & rStart, 9648590a0fdSAndre Fischer int timeout ) 9658590a0fdSAndre Fischer { 9668590a0fdSAndre Fischer TimeValue aEnd; 9678590a0fdSAndre Fischer osl_getSystemTime( &aEnd ); 9688590a0fdSAndre Fischer 9698590a0fdSAndre Fischer // Try to estimate a safe absolute time for sending the 9708590a0fdSAndre Fischer // lock refresh request. 9718590a0fdSAndre Fischer sal_Int32 lastChanceToSendRefreshRequest = -1; 9728590a0fdSAndre Fischer if ( timeout != NE_TIMEOUT_INFINITE ) 9738590a0fdSAndre Fischer { 9748590a0fdSAndre Fischer sal_Int32 calltime = aEnd.Seconds - rStart.Seconds; 9758590a0fdSAndre Fischer if ( calltime <= timeout ) 9768590a0fdSAndre Fischer { 9778590a0fdSAndre Fischer lastChanceToSendRefreshRequest 9788590a0fdSAndre Fischer = aEnd.Seconds + timeout - calltime; 9798590a0fdSAndre Fischer } 9808590a0fdSAndre Fischer else 9818590a0fdSAndre Fischer { 9828590a0fdSAndre Fischer OSL_TRACE( "No chance to refresh lock before timeout!" ); 9838590a0fdSAndre Fischer } 9848590a0fdSAndre Fischer } 9858590a0fdSAndre Fischer return lastChanceToSendRefreshRequest; 9868590a0fdSAndre Fischer } 9878590a0fdSAndre Fischer 9888590a0fdSAndre Fischer } // namespace 9898590a0fdSAndre Fischer */ 9908590a0fdSAndre Fischer // ------------------------------------------------------------------- 9918590a0fdSAndre Fischer // LOCK (set new lock) 9928590a0fdSAndre Fischer // ------------------------------------------------------------------- 9938590a0fdSAndre Fischer void SerfSession::LOCK( const ::rtl::OUString & inPath, 9948590a0fdSAndre Fischer ucb::Lock & /*rLock*/, 9958590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 9968590a0fdSAndre Fischer throw ( DAVException ) 9978590a0fdSAndre Fischer { 9988590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 9998590a0fdSAndre Fischer 10008590a0fdSAndre Fischer Init( rEnv ); 10018590a0fdSAndre Fischer 10028590a0fdSAndre Fischer SerfRequestProcessor aReqProc( *this, 10038590a0fdSAndre Fischer inPath ); 10048590a0fdSAndre Fischer HandleError( aReqProc, 10058590a0fdSAndre Fischer inPath, rEnv ); 10068590a0fdSAndre Fischer /* Create a depth zero, exclusive write lock, with default timeout 10078590a0fdSAndre Fischer * (allowing a server to pick a default). token, owner and uri are 10088590a0fdSAndre Fischer * unset. */ 10098590a0fdSAndre Fischer /* 10108590a0fdSAndre Fischer SerfLock * theLock = ne_lock_create(); 10118590a0fdSAndre Fischer 10128590a0fdSAndre Fischer // Set the lock uri 10138590a0fdSAndre Fischer ne_uri aUri; 10148590a0fdSAndre Fischer ne_uri_parse( rtl::OUStringToOString( makeAbsoluteURL( inPath ), 10158590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 10168590a0fdSAndre Fischer &aUri ); 10178590a0fdSAndre Fischer theLock->uri = aUri; 10188590a0fdSAndre Fischer 10198590a0fdSAndre Fischer // Set the lock depth 10208590a0fdSAndre Fischer switch( rLock.Depth ) 10218590a0fdSAndre Fischer { 10228590a0fdSAndre Fischer case ucb::LockDepth_ZERO: 10238590a0fdSAndre Fischer theLock->depth = NE_DEPTH_ZERO; 10248590a0fdSAndre Fischer break; 10258590a0fdSAndre Fischer case ucb::LockDepth_ONE: 10268590a0fdSAndre Fischer theLock->depth = NE_DEPTH_ONE; 10278590a0fdSAndre Fischer break; 10288590a0fdSAndre Fischer case ucb::LockDepth_INFINITY: 10298590a0fdSAndre Fischer theLock->depth = NE_DEPTH_INFINITE; 10308590a0fdSAndre Fischer break; 10318590a0fdSAndre Fischer default: 10328590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 10338590a0fdSAndre Fischer } 10348590a0fdSAndre Fischer 10358590a0fdSAndre Fischer // Set the lock scope 10368590a0fdSAndre Fischer switch ( rLock.Scope ) 10378590a0fdSAndre Fischer { 10388590a0fdSAndre Fischer case ucb::LockScope_EXCLUSIVE: 10398590a0fdSAndre Fischer theLock->scope = ne_lockscope_exclusive; 10408590a0fdSAndre Fischer break; 10418590a0fdSAndre Fischer case ucb::LockScope_SHARED: 10428590a0fdSAndre Fischer theLock->scope = ne_lockscope_shared; 10438590a0fdSAndre Fischer break; 10448590a0fdSAndre Fischer default: 10458590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 10468590a0fdSAndre Fischer } 10478590a0fdSAndre Fischer 10488590a0fdSAndre Fischer // Set the lock timeout 10498590a0fdSAndre Fischer theLock->timeout = (long)rLock.Timeout; 10508590a0fdSAndre Fischer 10518590a0fdSAndre Fischer // Set the lock owner 10528590a0fdSAndre Fischer rtl::OUString aValue; 10538590a0fdSAndre Fischer rLock.Owner >>= aValue; 10548590a0fdSAndre Fischer theLock->owner = 10558590a0fdSAndre Fischer ne_strdup( rtl::OUStringToOString( aValue, 10568590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 10578590a0fdSAndre Fischer TimeValue startCall; 10588590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 10598590a0fdSAndre Fischer 10608590a0fdSAndre Fischer int theRetVal = ne_lock( m_pHttpSession, theLock ); 10618590a0fdSAndre Fischer 10628590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 10638590a0fdSAndre Fischer { 10648590a0fdSAndre Fischer m_aSerfLockStore.addLock( theLock, 10658590a0fdSAndre Fischer this, 10668590a0fdSAndre Fischer lastChanceToSendRefreshRequest( 10678590a0fdSAndre Fischer startCall, theLock->timeout ) ); 10688590a0fdSAndre Fischer 10698590a0fdSAndre Fischer uno::Sequence< rtl::OUString > aTokens( 1 ); 10708590a0fdSAndre Fischer aTokens[ 0 ] = rtl::OUString::createFromAscii( theLock->token ); 10718590a0fdSAndre Fischer rLock.LockTokens = aTokens; 10728590a0fdSAndre Fischer 10738590a0fdSAndre Fischer OSL_TRACE( "SerfSession::LOCK: created lock for %s. token: %s", 10748590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 10758590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 10768590a0fdSAndre Fischer theLock->token ); 10778590a0fdSAndre Fischer } 10788590a0fdSAndre Fischer else 10798590a0fdSAndre Fischer { 10808590a0fdSAndre Fischer ne_lock_destroy( theLock ); 10818590a0fdSAndre Fischer 10828590a0fdSAndre Fischer OSL_TRACE( "SerfSession::LOCK: obtaining lock for %s failed!", 10838590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 10848590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 10858590a0fdSAndre Fischer } 10868590a0fdSAndre Fischer 10878590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 10888590a0fdSAndre Fischer */ 10898590a0fdSAndre Fischer } 10908590a0fdSAndre Fischer 10918590a0fdSAndre Fischer // ------------------------------------------------------------------- 10928590a0fdSAndre Fischer // LOCK (refresh existing lock) 10938590a0fdSAndre Fischer // ------------------------------------------------------------------- 10948590a0fdSAndre Fischer sal_Int64 SerfSession::LOCK( const ::rtl::OUString & /*inPath*/, 10958590a0fdSAndre Fischer sal_Int64 nTimeout, 10968590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 10978590a0fdSAndre Fischer throw ( DAVException ) 10988590a0fdSAndre Fischer { 10998590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 11008590a0fdSAndre Fischer 11018590a0fdSAndre Fischer return nTimeout; 11028590a0fdSAndre Fischer /* 11038590a0fdSAndre Fischer // Try to get the neon lock from lock store 11048590a0fdSAndre Fischer SerfLock * theLock 11058590a0fdSAndre Fischer = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); 11068590a0fdSAndre Fischer if ( !theLock ) 11078590a0fdSAndre Fischer throw DAVException( DAVException::DAV_NOT_LOCKED ); 11088590a0fdSAndre Fischer 11098590a0fdSAndre Fischer Init( rEnv ); 11108590a0fdSAndre Fischer 11118590a0fdSAndre Fischer // refresh existing lock. 11128590a0fdSAndre Fischer theLock->timeout = static_cast< long >( nTimeout ); 11138590a0fdSAndre Fischer 11148590a0fdSAndre Fischer TimeValue startCall; 11158590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 11168590a0fdSAndre Fischer 11178590a0fdSAndre Fischer int theRetVal = ne_lock_refresh( m_pHttpSession, theLock ); 11188590a0fdSAndre Fischer 11198590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 11208590a0fdSAndre Fischer { 11218590a0fdSAndre Fischer m_aSerfLockStore.updateLock( theLock, 11228590a0fdSAndre Fischer lastChanceToSendRefreshRequest( 11238590a0fdSAndre Fischer startCall, theLock->timeout ) ); 11248590a0fdSAndre Fischer } 11258590a0fdSAndre Fischer 11268590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 11278590a0fdSAndre Fischer 11288590a0fdSAndre Fischer return theLock->timeout; 11298590a0fdSAndre Fischer */ 11308590a0fdSAndre Fischer } 11318590a0fdSAndre Fischer 11328590a0fdSAndre Fischer // ------------------------------------------------------------------- 11338590a0fdSAndre Fischer // LOCK (refresh existing lock) 11348590a0fdSAndre Fischer // ------------------------------------------------------------------- 11358590a0fdSAndre Fischer bool SerfSession::LOCK( SerfLock * /*pLock*/, 11368590a0fdSAndre Fischer sal_Int32 & /*rlastChanceToSendRefreshRequest*/ ) 11378590a0fdSAndre Fischer { 11388590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 11398590a0fdSAndre Fischer 11408590a0fdSAndre Fischer return true; 11418590a0fdSAndre Fischer /* 11428590a0fdSAndre Fischer // refresh existing lock. 11438590a0fdSAndre Fischer 11448590a0fdSAndre Fischer TimeValue startCall; 11458590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 11468590a0fdSAndre Fischer 11478590a0fdSAndre Fischer if ( ne_lock_refresh( m_pHttpSession, pLock ) == NE_OK ) 11488590a0fdSAndre Fischer { 11498590a0fdSAndre Fischer rlastChanceToSendRefreshRequest 11508590a0fdSAndre Fischer = lastChanceToSendRefreshRequest( startCall, pLock->timeout ); 11518590a0fdSAndre Fischer 11528590a0fdSAndre Fischer OSL_TRACE( "Lock successfully refreshed." ); 11538590a0fdSAndre Fischer return true; 11548590a0fdSAndre Fischer } 11558590a0fdSAndre Fischer else 11568590a0fdSAndre Fischer { 11578590a0fdSAndre Fischer OSL_TRACE( "Lock not refreshed!" ); 11588590a0fdSAndre Fischer return false; 11598590a0fdSAndre Fischer } 11608590a0fdSAndre Fischer */ 11618590a0fdSAndre Fischer } 11628590a0fdSAndre Fischer 11638590a0fdSAndre Fischer // ------------------------------------------------------------------- 11648590a0fdSAndre Fischer // UNLOCK 11658590a0fdSAndre Fischer // ------------------------------------------------------------------- 11668590a0fdSAndre Fischer void SerfSession::UNLOCK( const ::rtl::OUString & /*inPath*/, 11678590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 11688590a0fdSAndre Fischer throw ( DAVException ) 11698590a0fdSAndre Fischer { 11708590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 11718590a0fdSAndre Fischer 11728590a0fdSAndre Fischer /* 11738590a0fdSAndre Fischer // get the neon lock from lock store 11748590a0fdSAndre Fischer SerfLock * theLock 11758590a0fdSAndre Fischer = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); 11768590a0fdSAndre Fischer if ( !theLock ) 11778590a0fdSAndre Fischer throw DAVException( DAVException::DAV_NOT_LOCKED ); 11788590a0fdSAndre Fischer 11798590a0fdSAndre Fischer Init( rEnv ); 11808590a0fdSAndre Fischer 11818590a0fdSAndre Fischer int theRetVal = ne_unlock( m_pHttpSession, theLock ); 11828590a0fdSAndre Fischer 11838590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 11848590a0fdSAndre Fischer { 11858590a0fdSAndre Fischer m_aSerfLockStore.removeLock( theLock ); 11868590a0fdSAndre Fischer ne_lock_destroy( theLock ); 11878590a0fdSAndre Fischer } 11888590a0fdSAndre Fischer else 11898590a0fdSAndre Fischer { 11908590a0fdSAndre Fischer OSL_TRACE( "SerfSession::UNLOCK: unlocking of %s failed.", 11918590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 11928590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 11938590a0fdSAndre Fischer } 11948590a0fdSAndre Fischer 11958590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 11968590a0fdSAndre Fischer */ 11978590a0fdSAndre Fischer } 11988590a0fdSAndre Fischer 11998590a0fdSAndre Fischer // ------------------------------------------------------------------- 12008590a0fdSAndre Fischer // UNLOCK 12018590a0fdSAndre Fischer // ------------------------------------------------------------------- 12028590a0fdSAndre Fischer bool SerfSession::UNLOCK( SerfLock * /*pLock*/ ) 12038590a0fdSAndre Fischer { 12048590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 12058590a0fdSAndre Fischer 12068590a0fdSAndre Fischer return true; 12078590a0fdSAndre Fischer /* 12088590a0fdSAndre Fischer if ( ne_unlock( m_pHttpSession, pLock ) == NE_OK ) 12098590a0fdSAndre Fischer { 12108590a0fdSAndre Fischer OSL_TRACE( "UNLOCK succeeded." ); 12118590a0fdSAndre Fischer return true; 12128590a0fdSAndre Fischer } 12138590a0fdSAndre Fischer else 12148590a0fdSAndre Fischer { 12158590a0fdSAndre Fischer OSL_TRACE( "UNLOCK failed!" ); 12168590a0fdSAndre Fischer return false; 12178590a0fdSAndre Fischer } 12188590a0fdSAndre Fischer */ 12198590a0fdSAndre Fischer } 12208590a0fdSAndre Fischer 12218590a0fdSAndre Fischer // ------------------------------------------------------------------- 12228590a0fdSAndre Fischer void SerfSession::abort() 12238590a0fdSAndre Fischer throw ( DAVException ) 12248590a0fdSAndre Fischer { 12258590a0fdSAndre Fischer // 11.11.09 (tkr): The following code lines causing crashes if 12268590a0fdSAndre Fischer // closing a ongoing connection. It turned out that this existing 12278590a0fdSAndre Fischer // solution doesn't work in multi-threading environments. 12288590a0fdSAndre Fischer // So I disabled them in 3.2. . Issue #73893# should fix it in OOo 3.3. 12298590a0fdSAndre Fischer //if ( m_pHttpSession ) 12308590a0fdSAndre Fischer // ne_close_connection( m_pHttpSession ); 12318590a0fdSAndre Fischer } 12328590a0fdSAndre Fischer 12338590a0fdSAndre Fischer // ------------------------------------------------------------------- 12348590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & SerfSession::getProxySettings() const 12358590a0fdSAndre Fischer { 12368590a0fdSAndre Fischer if ( m_aUri.GetScheme().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "http" ) ) || 12378590a0fdSAndre Fischer m_aUri.GetScheme().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "https" ) ) ) 12388590a0fdSAndre Fischer { 12398590a0fdSAndre Fischer return m_rProxyDecider.getProxy( m_aUri.GetScheme(), 12408590a0fdSAndre Fischer m_aUri.GetHost(), 12418590a0fdSAndre Fischer m_aUri.GetPort() ); 12428590a0fdSAndre Fischer } 12438590a0fdSAndre Fischer else 12448590a0fdSAndre Fischer { 12458590a0fdSAndre Fischer // TODO: figure out, if this case can occur 12468590a0fdSAndre Fischer return m_rProxyDecider.getProxy( m_aUri.GetScheme(), 12478590a0fdSAndre Fischer rtl::OUString() /* not used */, 12488590a0fdSAndre Fischer -1 /* not used */ ); 12498590a0fdSAndre Fischer } 12508590a0fdSAndre Fischer } 12518590a0fdSAndre Fischer 12528590a0fdSAndre Fischer /* 12538590a0fdSAndre Fischer // ------------------------------------------------------------------- 12548590a0fdSAndre Fischer namespace { 12558590a0fdSAndre Fischer 12568590a0fdSAndre Fischer bool containsLocktoken( const uno::Sequence< ucb::Lock > & rLocks, 12578590a0fdSAndre Fischer const char * token ) 12588590a0fdSAndre Fischer { 12598590a0fdSAndre Fischer for ( sal_Int32 n = 0; n < rLocks.getLength(); ++n ) 12608590a0fdSAndre Fischer { 12618590a0fdSAndre Fischer const uno::Sequence< rtl::OUString > & rTokens 12628590a0fdSAndre Fischer = rLocks[ n ].LockTokens; 12638590a0fdSAndre Fischer for ( sal_Int32 m = 0; m < rTokens.getLength(); ++m ) 12648590a0fdSAndre Fischer { 12658590a0fdSAndre Fischer if ( rTokens[ m ].equalsAscii( token ) ) 12668590a0fdSAndre Fischer return true; 12678590a0fdSAndre Fischer } 12688590a0fdSAndre Fischer } 12698590a0fdSAndre Fischer return false; 12708590a0fdSAndre Fischer } 12718590a0fdSAndre Fischer 12728590a0fdSAndre Fischer } // namespace 12738590a0fdSAndre Fischer */ 12748590a0fdSAndre Fischer 12758590a0fdSAndre Fischer // ------------------------------------------------------------------- 12768590a0fdSAndre Fischer bool SerfSession::removeExpiredLocktoken( const rtl::OUString & /*inURL*/, 12778590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 12788590a0fdSAndre Fischer { 12798590a0fdSAndre Fischer return true; 12808590a0fdSAndre Fischer /* 12818590a0fdSAndre Fischer SerfLock * theLock = m_aSerfLockStore.findByUri( inURL ); 12828590a0fdSAndre Fischer if ( !theLock ) 12838590a0fdSAndre Fischer return false; 12848590a0fdSAndre Fischer 12858590a0fdSAndre Fischer // do a lockdiscovery to check whether this lock is still valid. 12868590a0fdSAndre Fischer try 12878590a0fdSAndre Fischer { 12888590a0fdSAndre Fischer // @@@ Alternative: use ne_lock_discover() => less overhead 12898590a0fdSAndre Fischer 12908590a0fdSAndre Fischer std::vector< DAVResource > aResources; 12918590a0fdSAndre Fischer std::vector< rtl::OUString > aPropNames; 12928590a0fdSAndre Fischer aPropNames.push_back( DAVProperties::LOCKDISCOVERY ); 12938590a0fdSAndre Fischer 12948590a0fdSAndre Fischer PROPFIND( rEnv.m_aRequestURI, DAVZERO, aPropNames, aResources, rEnv ); 12958590a0fdSAndre Fischer 12968590a0fdSAndre Fischer if ( aResources.size() == 0 ) 12978590a0fdSAndre Fischer return false; 12988590a0fdSAndre Fischer 12998590a0fdSAndre Fischer std::vector< DAVPropertyValue >::const_iterator it 13008590a0fdSAndre Fischer = aResources[ 0 ].properties.begin(); 13018590a0fdSAndre Fischer std::vector< DAVPropertyValue >::const_iterator end 13028590a0fdSAndre Fischer = aResources[ 0 ].properties.end(); 13038590a0fdSAndre Fischer 13048590a0fdSAndre Fischer while ( it != end ) 13058590a0fdSAndre Fischer { 13068590a0fdSAndre Fischer if ( (*it).Name.equals( DAVProperties::LOCKDISCOVERY ) ) 13078590a0fdSAndre Fischer { 13088590a0fdSAndre Fischer uno::Sequence< ucb::Lock > aLocks; 13098590a0fdSAndre Fischer if ( !( (*it).Value >>= aLocks ) ) 13108590a0fdSAndre Fischer return false; 13118590a0fdSAndre Fischer 13128590a0fdSAndre Fischer if ( !containsLocktoken( aLocks, theLock->token ) ) 13138590a0fdSAndre Fischer { 13148590a0fdSAndre Fischer // expired! 13158590a0fdSAndre Fischer break; 13168590a0fdSAndre Fischer } 13178590a0fdSAndre Fischer 13188590a0fdSAndre Fischer // still valid. 13198590a0fdSAndre Fischer return false; 13208590a0fdSAndre Fischer } 13218590a0fdSAndre Fischer ++it; 13228590a0fdSAndre Fischer } 13238590a0fdSAndre Fischer 13248590a0fdSAndre Fischer // No lockdiscovery prop in propfind result / locktoken not found 13258590a0fdSAndre Fischer // in propfind result -> not locked 13268590a0fdSAndre Fischer OSL_TRACE( "SerfSession::removeExpiredLocktoken: Removing " 13278590a0fdSAndre Fischer " expired lock token for %s. token: %s", 13288590a0fdSAndre Fischer rtl::OUStringToOString( inURL, 13298590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 13308590a0fdSAndre Fischer theLock->token ); 13318590a0fdSAndre Fischer 13328590a0fdSAndre Fischer m_aSerfLockStore.removeLock( theLock ); 13338590a0fdSAndre Fischer ne_lock_destroy( theLock ); 13348590a0fdSAndre Fischer return true; 13358590a0fdSAndre Fischer } 13368590a0fdSAndre Fischer catch ( DAVException const & ) 13378590a0fdSAndre Fischer { 13388590a0fdSAndre Fischer } 13398590a0fdSAndre Fischer return false; 13408590a0fdSAndre Fischer */ 13418590a0fdSAndre Fischer } 13428590a0fdSAndre Fischer 13438590a0fdSAndre Fischer // ------------------------------------------------------------------- 13448590a0fdSAndre Fischer // HandleError 13458590a0fdSAndre Fischer // Common Error Handler 13468590a0fdSAndre Fischer // ------------------------------------------------------------------- 13478590a0fdSAndre Fischer void SerfSession::HandleError( SerfRequestProcessor& rReqProc, 13488590a0fdSAndre Fischer const rtl::OUString & /*inPath*/, 13498590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 13508590a0fdSAndre Fischer throw ( DAVException ) 13518590a0fdSAndre Fischer { 13528590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 13538590a0fdSAndre Fischer 13548590a0fdSAndre Fischer if ( rReqProc.mpDAVException ) 13558590a0fdSAndre Fischer { 13568590a0fdSAndre Fischer DAVException* mpDAVExp( rReqProc.mpDAVException ); 13578590a0fdSAndre Fischer 13588590a0fdSAndre Fischer serf_connection_reset( getSerfConnection() ); 13598590a0fdSAndre Fischer 13608590a0fdSAndre Fischer throw DAVException( mpDAVExp->getError(), 13618590a0fdSAndre Fischer mpDAVExp->getData(), 13628590a0fdSAndre Fischer mpDAVExp->getStatus() ); 13638590a0fdSAndre Fischer } 13648590a0fdSAndre Fischer 13658590a0fdSAndre Fischer /* 13668590a0fdSAndre Fischer // Map error code to DAVException. 13678590a0fdSAndre Fischer switch ( nError ) 13688590a0fdSAndre Fischer { 13698590a0fdSAndre Fischer case NE_OK: 13708590a0fdSAndre Fischer return; 13718590a0fdSAndre Fischer 13728590a0fdSAndre Fischer case NE_ERROR: // Generic error 13738590a0fdSAndre Fischer { 13748590a0fdSAndre Fischer rtl::OUString aText = rtl::OUString::createFromAscii( 13758590a0fdSAndre Fischer ne_get_error( m_pHttpSession ) ); 13768590a0fdSAndre Fischer 13778590a0fdSAndre Fischer sal_uInt16 code = makeStatusCode( aText ); 13788590a0fdSAndre Fischer 13798590a0fdSAndre Fischer if ( code == SC_LOCKED ) 13808590a0fdSAndre Fischer { 13818590a0fdSAndre Fischer if ( m_aSerfLockStore.findByUri( 13828590a0fdSAndre Fischer makeAbsoluteURL( inPath ) ) == 0 ) 13838590a0fdSAndre Fischer { 13848590a0fdSAndre Fischer // locked by 3rd party 13858590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCKED ); 13868590a0fdSAndre Fischer } 13878590a0fdSAndre Fischer else 13888590a0fdSAndre Fischer { 13898590a0fdSAndre Fischer // locked by ourself 13908590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCKED_SELF ); 13918590a0fdSAndre Fischer } 13928590a0fdSAndre Fischer } 13938590a0fdSAndre Fischer 13948590a0fdSAndre Fischer // Special handling for 400 and 412 status codes, which may indicate 13958590a0fdSAndre Fischer // that a lock previously obtained by us has been released meanwhile 13968590a0fdSAndre Fischer // by the server. Unfortunately, RFC is not clear at this point, 13978590a0fdSAndre Fischer // thus server implementations behave different... 13988590a0fdSAndre Fischer else if ( code == SC_BAD_REQUEST || code == SC_PRECONDITION_FAILED ) 13998590a0fdSAndre Fischer { 14008590a0fdSAndre Fischer if ( removeExpiredLocktoken( makeAbsoluteURL( inPath ), rEnv ) ) 14018590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCK_EXPIRED ); 14028590a0fdSAndre Fischer } 14038590a0fdSAndre Fischer 14048590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, aText, code ); 14058590a0fdSAndre Fischer } 14068590a0fdSAndre Fischer case NE_LOOKUP: // Name lookup failed. 14078590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_LOOKUP, 14088590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14098590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14108590a0fdSAndre Fischer 14118590a0fdSAndre Fischer case NE_AUTH: // User authentication failed on server 14128590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_AUTH, 14138590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14148590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14158590a0fdSAndre Fischer 14168590a0fdSAndre Fischer case NE_PROXYAUTH: // User authentication failed on proxy 14178590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_AUTHPROXY, 14188590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14198590a0fdSAndre Fischer m_aProxyName, m_nProxyPort ) ); 14208590a0fdSAndre Fischer 14218590a0fdSAndre Fischer case NE_CONNECT: // Could not connect to server 14228590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_CONNECT, 14238590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14248590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14258590a0fdSAndre Fischer 14268590a0fdSAndre Fischer case NE_TIMEOUT: // Connection timed out 14278590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_TIMEOUT, 14288590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14298590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14308590a0fdSAndre Fischer 14318590a0fdSAndre Fischer case NE_FAILED: // The precondition failed 14328590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_FAILED, 14338590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14348590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14358590a0fdSAndre Fischer 14368590a0fdSAndre Fischer case NE_RETRY: // Retry request (ne_end_request ONLY) 14378590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_RETRY, 14388590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14398590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14408590a0fdSAndre Fischer 14418590a0fdSAndre Fischer case NE_REDIRECT: 14428590a0fdSAndre Fischer { 14438590a0fdSAndre Fischer SerfUri aUri( ne_redirect_location( m_pHttpSession ) ); 14448590a0fdSAndre Fischer throw DAVException( 14458590a0fdSAndre Fischer DAVException::DAV_HTTP_REDIRECT, aUri.GetURI() ); 14468590a0fdSAndre Fischer } 14478590a0fdSAndre Fischer default: 14488590a0fdSAndre Fischer { 14498590a0fdSAndre Fischer OSL_TRACE( "SerfSession::HandleError : Unknown Serf error code!" ); 14508590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, 14518590a0fdSAndre Fischer rtl::OUString::createFromAscii( 14528590a0fdSAndre Fischer ne_get_error( m_pHttpSession ) ) ); 14538590a0fdSAndre Fischer } 14548590a0fdSAndre Fischer } 14558590a0fdSAndre Fischer */ 14568590a0fdSAndre Fischer } 14578590a0fdSAndre Fischer 14588590a0fdSAndre Fischer // ------------------------------------------------------------------- 14598590a0fdSAndre Fischer // static 14608590a0fdSAndre Fischer bool 14618590a0fdSAndre Fischer SerfSession::getDataFromInputStream( 14628590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & xStream, 14638590a0fdSAndre Fischer uno::Sequence< sal_Int8 > & rData, 14648590a0fdSAndre Fischer bool bAppendTrailingZeroByte ) 14658590a0fdSAndre Fischer { 14668590a0fdSAndre Fischer if ( xStream.is() ) 14678590a0fdSAndre Fischer { 14688590a0fdSAndre Fischer uno::Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY ); 14698590a0fdSAndre Fischer if ( xSeekable.is() ) 14708590a0fdSAndre Fischer { 14718590a0fdSAndre Fischer try 14728590a0fdSAndre Fischer { 14738590a0fdSAndre Fischer sal_Int32 nSize 14748590a0fdSAndre Fischer = sal::static_int_cast<sal_Int32>(xSeekable->getLength()); 14758590a0fdSAndre Fischer sal_Int32 nRead 14768590a0fdSAndre Fischer = xStream->readBytes( rData, nSize ); 14778590a0fdSAndre Fischer 14788590a0fdSAndre Fischer if ( nRead == nSize ) 14798590a0fdSAndre Fischer { 14808590a0fdSAndre Fischer if ( bAppendTrailingZeroByte ) 14818590a0fdSAndre Fischer { 14828590a0fdSAndre Fischer rData.realloc( nSize + 1 ); 14838590a0fdSAndre Fischer rData[ nSize ] = sal_Int8( 0 ); 14848590a0fdSAndre Fischer } 14858590a0fdSAndre Fischer return true; 14868590a0fdSAndre Fischer } 14878590a0fdSAndre Fischer } 14888590a0fdSAndre Fischer catch ( io::NotConnectedException const & ) 14898590a0fdSAndre Fischer { 14908590a0fdSAndre Fischer // readBytes 14918590a0fdSAndre Fischer } 14928590a0fdSAndre Fischer catch ( io::BufferSizeExceededException const & ) 14938590a0fdSAndre Fischer { 14948590a0fdSAndre Fischer // readBytes 14958590a0fdSAndre Fischer } 14968590a0fdSAndre Fischer catch ( io::IOException const & ) 14978590a0fdSAndre Fischer { 14988590a0fdSAndre Fischer // getLength, readBytes 14998590a0fdSAndre Fischer } 15008590a0fdSAndre Fischer } 15018590a0fdSAndre Fischer else 15028590a0fdSAndre Fischer { 15038590a0fdSAndre Fischer try 15048590a0fdSAndre Fischer { 15058590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aBuffer; 15068590a0fdSAndre Fischer sal_Int32 nPos = 0; 15078590a0fdSAndre Fischer 15088590a0fdSAndre Fischer sal_Int32 nRead = xStream->readSomeBytes( aBuffer, 65536 ); 15098590a0fdSAndre Fischer while ( nRead > 0 ) 15108590a0fdSAndre Fischer { 15118590a0fdSAndre Fischer if ( rData.getLength() < ( nPos + nRead ) ) 15128590a0fdSAndre Fischer rData.realloc( nPos + nRead ); 15138590a0fdSAndre Fischer 15148590a0fdSAndre Fischer aBuffer.realloc( nRead ); 15158590a0fdSAndre Fischer rtl_copyMemory( (void*)( rData.getArray() + nPos ), 15168590a0fdSAndre Fischer (const void*)aBuffer.getConstArray(), 15178590a0fdSAndre Fischer nRead ); 15188590a0fdSAndre Fischer nPos += nRead; 15198590a0fdSAndre Fischer 15208590a0fdSAndre Fischer aBuffer.realloc( 0 ); 15218590a0fdSAndre Fischer nRead = xStream->readSomeBytes( aBuffer, 65536 ); 15228590a0fdSAndre Fischer } 15238590a0fdSAndre Fischer 15248590a0fdSAndre Fischer if ( bAppendTrailingZeroByte ) 15258590a0fdSAndre Fischer { 15268590a0fdSAndre Fischer rData.realloc( nPos + 1 ); 15278590a0fdSAndre Fischer rData[ nPos ] = sal_Int8( 0 ); 15288590a0fdSAndre Fischer } 15298590a0fdSAndre Fischer return true; 15308590a0fdSAndre Fischer } 15318590a0fdSAndre Fischer catch ( io::NotConnectedException const & ) 15328590a0fdSAndre Fischer { 15338590a0fdSAndre Fischer // readBytes 15348590a0fdSAndre Fischer } 15358590a0fdSAndre Fischer catch ( io::BufferSizeExceededException const & ) 15368590a0fdSAndre Fischer { 15378590a0fdSAndre Fischer // readBytes 15388590a0fdSAndre Fischer } 15398590a0fdSAndre Fischer catch ( io::IOException const & ) 15408590a0fdSAndre Fischer { 15418590a0fdSAndre Fischer // readBytes 15428590a0fdSAndre Fischer } 15438590a0fdSAndre Fischer } 15448590a0fdSAndre Fischer } 15458590a0fdSAndre Fischer return false; 15468590a0fdSAndre Fischer } 15478590a0fdSAndre Fischer 15488590a0fdSAndre Fischer // --------------------------------------------------------------------- 15498590a0fdSAndre Fischer sal_Bool 15508590a0fdSAndre Fischer SerfSession::isDomainMatch( rtl::OUString certHostName ) 15518590a0fdSAndre Fischer { 15528590a0fdSAndre Fischer rtl::OUString hostName = getHostName(); 15538590a0fdSAndre Fischer 15548590a0fdSAndre Fischer if (hostName.equalsIgnoreAsciiCase( certHostName ) ) 15558590a0fdSAndre Fischer return sal_True; 15568590a0fdSAndre Fischer 15578590a0fdSAndre Fischer if ( 0 == certHostName.indexOf( rtl::OUString::createFromAscii( "*" ) ) && 15588590a0fdSAndre Fischer hostName.getLength() >= certHostName.getLength() ) 15598590a0fdSAndre Fischer { 15608590a0fdSAndre Fischer rtl::OUString cmpStr = certHostName.copy( 1 ); 15618590a0fdSAndre Fischer 15628590a0fdSAndre Fischer if ( hostName.matchIgnoreAsciiCase( 15638590a0fdSAndre Fischer cmpStr, hostName.getLength() - cmpStr.getLength() ) ) 15648590a0fdSAndre Fischer return sal_True; 15658590a0fdSAndre Fischer } 15668590a0fdSAndre Fischer return sal_False; 15678590a0fdSAndre Fischer } 15688590a0fdSAndre Fischer 15698590a0fdSAndre Fischer /* 15708590a0fdSAndre Fischer // --------------------------------------------------------------------- 15718590a0fdSAndre Fischer rtl::OUString SerfSession::makeAbsoluteURL( rtl::OUString const & rURL ) const 15728590a0fdSAndre Fischer { 15738590a0fdSAndre Fischer try 15748590a0fdSAndre Fischer { 15758590a0fdSAndre Fischer // Is URL relative or already absolute? 15768590a0fdSAndre Fischer if ( rURL[ 0 ] != sal_Unicode( '/' ) ) 15778590a0fdSAndre Fischer { 15788590a0fdSAndre Fischer // absolute. 15798590a0fdSAndre Fischer return rtl::OUString( rURL ); 15808590a0fdSAndre Fischer } 15818590a0fdSAndre Fischer else 15828590a0fdSAndre Fischer { 15838590a0fdSAndre Fischer ne_uri aUri; 15848590a0fdSAndre Fischer memset( &aUri, 0, sizeof( aUri ) ); 15858590a0fdSAndre Fischer 15868590a0fdSAndre Fischer ne_fill_server_uri( m_pHttpSession, &aUri ); 15878590a0fdSAndre Fischer aUri.path 15888590a0fdSAndre Fischer = ne_strdup( rtl::OUStringToOString( 15898590a0fdSAndre Fischer rURL, RTL_TEXTENCODING_UTF8 ).getStr() ); 15908590a0fdSAndre Fischer SerfUri aSerfUri( &aUri ); 15918590a0fdSAndre Fischer ne_uri_free( &aUri ); 15928590a0fdSAndre Fischer return aSerfUri.GetURI(); 15938590a0fdSAndre Fischer } 15948590a0fdSAndre Fischer } 15958590a0fdSAndre Fischer catch ( DAVException const & ) 15968590a0fdSAndre Fischer { 15978590a0fdSAndre Fischer } 15988590a0fdSAndre Fischer // error. 15998590a0fdSAndre Fischer return rtl::OUString(); 16008590a0fdSAndre Fischer } 16018590a0fdSAndre Fischer */ 1602