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 56c58749d7SAndre Fischer 578590a0fdSAndre Fischer // ------------------------------------------------------------------- 588590a0fdSAndre Fischer // static members! 598590a0fdSAndre Fischer //SerfLockStore SerfSession::m_aSerfLockStore; 608590a0fdSAndre Fischer 618590a0fdSAndre Fischer // ------------------------------------------------------------------- 628590a0fdSAndre Fischer // Constructor 638590a0fdSAndre Fischer // ------------------------------------------------------------------- 648590a0fdSAndre Fischer SerfSession::SerfSession( 658590a0fdSAndre Fischer const rtl::Reference< DAVSessionFactory > & rSessionFactory, 668590a0fdSAndre Fischer const rtl::OUString& inUri, 678590a0fdSAndre Fischer const ucbhelper::InternetProxyDecider & rProxyDecider ) 688590a0fdSAndre Fischer throw ( DAVException ) 698590a0fdSAndre Fischer : DAVSession( rSessionFactory ) 708590a0fdSAndre Fischer , m_aMutex() 718590a0fdSAndre Fischer , m_aUri( inUri ) 728590a0fdSAndre Fischer , m_aProxyName() 738590a0fdSAndre Fischer , m_nProxyPort( 0 ) 748590a0fdSAndre Fischer , m_pSerfConnection( 0 ) 758590a0fdSAndre Fischer , m_pSerfContext( 0 ) 768590a0fdSAndre Fischer , m_bIsHeadRequestInProgress( false ) 7749989859SOliver-Rainer Wittmann , m_bUseChunkedEncoding( false ) 7849989859SOliver-Rainer Wittmann , m_bNoOfTransferEncodingSwitches( 0 ) 798590a0fdSAndre Fischer , m_rProxyDecider( rProxyDecider ) 808590a0fdSAndre Fischer , m_aEnv() 818590a0fdSAndre Fischer { 828590a0fdSAndre Fischer m_pSerfContext = serf_context_create( getAprPool() ); 838590a0fdSAndre Fischer 848590a0fdSAndre Fischer m_pSerfBucket_Alloc = serf_bucket_allocator_create( getAprPool(), NULL, NULL ); 858590a0fdSAndre Fischer } 868590a0fdSAndre Fischer 878590a0fdSAndre Fischer // ------------------------------------------------------------------- 888590a0fdSAndre Fischer // Destructor 898590a0fdSAndre Fischer // ------------------------------------------------------------------- 908590a0fdSAndre Fischer SerfSession::~SerfSession( ) 918590a0fdSAndre Fischer { 928590a0fdSAndre Fischer if ( m_pSerfConnection ) 938590a0fdSAndre Fischer { 948590a0fdSAndre Fischer serf_connection_close( m_pSerfConnection ); 958590a0fdSAndre Fischer m_pSerfConnection = 0; 968590a0fdSAndre Fischer } 978590a0fdSAndre Fischer } 988590a0fdSAndre Fischer 998590a0fdSAndre Fischer // ------------------------------------------------------------------- 1008590a0fdSAndre Fischer void SerfSession::Init( const DAVRequestEnvironment & rEnv ) 1018590a0fdSAndre Fischer throw ( DAVException ) 1028590a0fdSAndre Fischer { 1038590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1048590a0fdSAndre Fischer m_aEnv = rEnv; 1058590a0fdSAndre Fischer Init(); 1068590a0fdSAndre Fischer } 1078590a0fdSAndre Fischer 1088590a0fdSAndre Fischer // ------------------------------------------------------------------- 1098590a0fdSAndre Fischer void SerfSession::Init() 1108590a0fdSAndre Fischer throw ( DAVException ) 1118590a0fdSAndre Fischer { 1128590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 1138590a0fdSAndre Fischer 1148590a0fdSAndre Fischer bool bCreateNewSession = false; 1158590a0fdSAndre Fischer 1168590a0fdSAndre Fischer if ( m_pSerfConnection == 0 ) 1178590a0fdSAndre Fischer { 1188590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & rProxyCfg = getProxySettings(); 1198590a0fdSAndre Fischer 1208590a0fdSAndre Fischer m_aProxyName = rProxyCfg.aName; 1218590a0fdSAndre Fischer m_nProxyPort = rProxyCfg.nPort; 1228590a0fdSAndre Fischer 1238590a0fdSAndre Fischer // Not yet initialized. Create new session. 1248590a0fdSAndre Fischer bCreateNewSession = true; 1258590a0fdSAndre Fischer } 1268590a0fdSAndre Fischer else 1278590a0fdSAndre Fischer { 1288590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & rProxyCfg = getProxySettings(); 1298590a0fdSAndre Fischer 1308590a0fdSAndre Fischer if ( ( rProxyCfg.aName != m_aProxyName ) 1318590a0fdSAndre Fischer || ( rProxyCfg.nPort != m_nProxyPort ) ) 1328590a0fdSAndre Fischer { 1338590a0fdSAndre Fischer m_aProxyName = rProxyCfg.aName; 1348590a0fdSAndre Fischer m_nProxyPort = rProxyCfg.nPort; 1358590a0fdSAndre Fischer 1368590a0fdSAndre Fischer // new session needed, destroy old first 1378590a0fdSAndre Fischer serf_connection_close( m_pSerfConnection ); 1388590a0fdSAndre Fischer m_pSerfConnection = 0; 1398590a0fdSAndre Fischer bCreateNewSession = true; 1408590a0fdSAndre Fischer } 1418590a0fdSAndre Fischer } 1428590a0fdSAndre Fischer 1438590a0fdSAndre Fischer if ( bCreateNewSession ) 1448590a0fdSAndre Fischer { 1458590a0fdSAndre Fischer // TODO - close_connection callback 1468590a0fdSAndre Fischer apr_status_t status = serf_connection_create2( &m_pSerfConnection, 1478590a0fdSAndre Fischer m_pSerfContext, 1488590a0fdSAndre Fischer *(m_aUri.getAprUri()), 1498590a0fdSAndre Fischer Serf_ConnectSetup, this, 1508590a0fdSAndre Fischer 0 /* close connection callback */, 0 /* close connection baton */, 1518590a0fdSAndre Fischer getAprPool() ); 1528590a0fdSAndre Fischer 1538590a0fdSAndre Fischer if ( m_pSerfConnection == 0 ||status != APR_SUCCESS ) 1548590a0fdSAndre Fischer { 1558590a0fdSAndre Fischer throw DAVException( DAVException::DAV_SESSION_CREATE, 1568590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( m_aUri.GetHost(), m_aUri.GetPort() ) ); 1578590a0fdSAndre Fischer } 1588590a0fdSAndre Fischer 1598590a0fdSAndre Fischer // Register the session with the lock store 1608590a0fdSAndre Fischer // m_aSerfLockStore.registerSession( m_pSerfConnection ); 1618590a0fdSAndre Fischer 1628590a0fdSAndre Fischer if ( m_aProxyName.getLength() ) 1638590a0fdSAndre Fischer { 1648590a0fdSAndre Fischer apr_sockaddr_t *proxy_address = NULL; 165*fdf35928SAndre Fischer status = apr_sockaddr_info_get( &proxy_address, 1668590a0fdSAndre Fischer rtl::OUStringToOString( m_aProxyName, RTL_TEXTENCODING_UTF8 ), 1678590a0fdSAndre Fischer APR_UNSPEC, 1688590a0fdSAndre Fischer static_cast<apr_port_t>(m_nProxyPort), 1698590a0fdSAndre Fischer 0, getAprPool() ); 1708590a0fdSAndre Fischer 1718590a0fdSAndre Fischer if ( status != APR_SUCCESS ) 1728590a0fdSAndre Fischer { 1738590a0fdSAndre Fischer throw DAVException( DAVException::DAV_SESSION_CREATE, 1748590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( m_aUri.GetHost(), m_aUri.GetPort() ) ); 1758590a0fdSAndre Fischer } 1768590a0fdSAndre Fischer 1778590a0fdSAndre Fischer serf_config_proxy( m_pSerfContext, proxy_address ); 1788590a0fdSAndre Fischer } 1798590a0fdSAndre Fischer 1808590a0fdSAndre Fischer 1818590a0fdSAndre Fischer serf_config_credentials_callback( m_pSerfContext, Serf_Credentials ); 18249989859SOliver-Rainer Wittmann 18349989859SOliver-Rainer Wittmann m_bUseChunkedEncoding = isSSLNeeded(); 1848590a0fdSAndre Fischer } 1858590a0fdSAndre Fischer } 1868590a0fdSAndre Fischer 1878590a0fdSAndre Fischer apr_pool_t* SerfSession::getAprPool() 1888590a0fdSAndre Fischer { 1898590a0fdSAndre Fischer return apr_environment::AprEnv::getAprEnv()->getAprPool(); 1908590a0fdSAndre Fischer } 1918590a0fdSAndre Fischer 1928590a0fdSAndre Fischer serf_bucket_alloc_t* SerfSession::getSerfBktAlloc() 1938590a0fdSAndre Fischer { 1948590a0fdSAndre Fischer return m_pSerfBucket_Alloc; 1958590a0fdSAndre Fischer } 1968590a0fdSAndre Fischer 1978590a0fdSAndre Fischer serf_context_t* SerfSession::getSerfContext() 1988590a0fdSAndre Fischer { 1998590a0fdSAndre Fischer return m_pSerfContext; 2008590a0fdSAndre Fischer } 2018590a0fdSAndre Fischer 2028590a0fdSAndre Fischer SerfConnection* SerfSession::getSerfConnection() 2038590a0fdSAndre Fischer { 2048590a0fdSAndre Fischer return m_pSerfConnection; 2058590a0fdSAndre Fischer } 2068590a0fdSAndre Fischer 2078590a0fdSAndre Fischer bool SerfSession::isHeadRequestInProgress() 2088590a0fdSAndre Fischer { 2098590a0fdSAndre Fischer return m_bIsHeadRequestInProgress; 2108590a0fdSAndre Fischer } 2118590a0fdSAndre Fischer 2128590a0fdSAndre Fischer bool SerfSession::isSSLNeeded() 2138590a0fdSAndre Fischer { 2148590a0fdSAndre Fischer return m_aUri.GetScheme().equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "https" ) ) ); 2158590a0fdSAndre Fischer } 2168590a0fdSAndre Fischer 2178590a0fdSAndre Fischer char* SerfSession::getHostinfo() 2188590a0fdSAndre Fischer { 2198590a0fdSAndre Fischer return m_aUri.getAprUri()->hostinfo; 2208590a0fdSAndre Fischer } 2218590a0fdSAndre Fischer 2228590a0fdSAndre Fischer 2238590a0fdSAndre Fischer // ------------------------------------------------------------------- 2248590a0fdSAndre Fischer // virtual 2258590a0fdSAndre Fischer sal_Bool SerfSession::CanUse( const rtl::OUString & inUri ) 2268590a0fdSAndre Fischer { 2278590a0fdSAndre Fischer try 2288590a0fdSAndre Fischer { 2298590a0fdSAndre Fischer SerfUri theUri( inUri ); 2308590a0fdSAndre Fischer if ( ( theUri.GetPort() == m_aUri.GetPort() ) && 2318590a0fdSAndre Fischer ( theUri.GetHost() == m_aUri.GetHost() ) && 2328590a0fdSAndre Fischer ( theUri.GetScheme() == m_aUri.GetScheme() ) ) 2338590a0fdSAndre Fischer { 2348590a0fdSAndre Fischer return sal_True; 2358590a0fdSAndre Fischer } 2368590a0fdSAndre Fischer } 2378590a0fdSAndre Fischer catch ( DAVException const & ) 2388590a0fdSAndre Fischer { 2398590a0fdSAndre Fischer return sal_False; 2408590a0fdSAndre Fischer } 2418590a0fdSAndre Fischer return sal_False; 2428590a0fdSAndre Fischer } 2438590a0fdSAndre Fischer 2448590a0fdSAndre Fischer // ------------------------------------------------------------------- 2458590a0fdSAndre Fischer // virtual 2468590a0fdSAndre Fischer sal_Bool SerfSession::UsesProxy() 2478590a0fdSAndre Fischer { 2488590a0fdSAndre Fischer Init(); 2498590a0fdSAndre Fischer return ( m_aProxyName.getLength() > 0 ); 2508590a0fdSAndre Fischer } 2518590a0fdSAndre Fischer 2528590a0fdSAndre Fischer apr_status_t SerfSession::setupSerfConnection( apr_socket_t * inAprSocket, 2538590a0fdSAndre Fischer serf_bucket_t **outSerfInputBucket, 2548590a0fdSAndre Fischer serf_bucket_t **outSerfOutputBucket, 2558590a0fdSAndre Fischer apr_pool_t* /*inAprPool*/ ) 2568590a0fdSAndre Fischer { 2578590a0fdSAndre Fischer serf_bucket_t *tmpInputBkt; 2588590a0fdSAndre Fischer tmpInputBkt = serf_context_bucket_socket_create( getSerfContext(), 2598590a0fdSAndre Fischer inAprSocket, 2608590a0fdSAndre Fischer getSerfBktAlloc() ); 2618590a0fdSAndre Fischer 2628590a0fdSAndre Fischer if ( isSSLNeeded() ) 2638590a0fdSAndre Fischer { 2648590a0fdSAndre Fischer tmpInputBkt = serf_bucket_ssl_decrypt_create( tmpInputBkt, 2658590a0fdSAndre Fischer 0, 2668590a0fdSAndre Fischer getSerfBktAlloc() ); 267c58749d7SAndre Fischer /** Set the callback that is called to authenticate the 268c58749d7SAndre Fischer certifcate (chain). 269c58749d7SAndre Fischer */ 270c58749d7SAndre Fischer serf_ssl_server_cert_chain_callback_set( 271c58749d7SAndre Fischer serf_bucket_ssl_decrypt_context_get(tmpInputBkt), 27210e20387SAndre Fischer NULL, 273c58749d7SAndre Fischer Serf_CertificateChainValidation, 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 288fb7f54d2SOliver-Rainer Wittmann apr_status_t SerfSession::provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry, 289fb7f54d2SOliver-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, 337fb7f54d2SOliver-Rainer Wittmann bCanUseSystemCreds, 338fb7f54d2SOliver-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 369c58749d7SAndre Fischer apr_status_t SerfSession::verifySerfCertificateChain ( 370c58749d7SAndre Fischer int, 37110e20387SAndre Fischer const serf_ssl_certificate_t * const * pCertificateChainBase64Encoded, 372de38cc67SOliver-Rainer Wittmann int nCertificateChainLength) 373c58749d7SAndre Fischer { 374c58749d7SAndre Fischer // Check arguments. 375c58749d7SAndre Fischer if (pCertificateChainBase64Encoded == NULL || nCertificateChainLength<=0) 376c58749d7SAndre Fischer { 377c58749d7SAndre Fischer OSL_ASSERT(pCertificateChainBase64Encoded != NULL); 378c58749d7SAndre Fischer OSL_ASSERT(nCertificateChainLength>0); 379c58749d7SAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 380c58749d7SAndre Fischer } 381c58749d7SAndre Fischer 382c58749d7SAndre Fischer // Create some crypto objects to decode and handle the base64 383c58749d7SAndre Fischer // encoded certificate chain. 384c58749d7SAndre Fischer uno::Reference< xml::crypto::XSEInitializer > xSEInitializer; 3858590a0fdSAndre Fischer uno::Reference< security::XCertificateContainer > xCertificateContainer; 386c58749d7SAndre Fischer uno::Reference< xml::crypto::XXMLSecurityContext > xSecurityContext; 387c58749d7SAndre Fischer uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnv; 3888590a0fdSAndre Fischer try 3898590a0fdSAndre Fischer { 390c58749d7SAndre Fischer // Create a certificate container. 391c58749d7SAndre Fischer xCertificateContainer = uno::Reference< security::XCertificateContainer >( 3928590a0fdSAndre Fischer getMSF()->createInstance( 3938590a0fdSAndre Fischer rtl::OUString::createFromAscii( 3948590a0fdSAndre Fischer "com.sun.star.security.CertificateContainer" ) ), 395c58749d7SAndre Fischer uno::UNO_QUERY_THROW); 396c58749d7SAndre Fischer 397c58749d7SAndre Fischer xSEInitializer = uno::Reference< xml::crypto::XSEInitializer >( 398c58749d7SAndre Fischer getMSF()->createInstance( 399c58749d7SAndre Fischer rtl::OUString::createFromAscii( "com.sun.star.xml.crypto.SEInitializer" ) ), 400c58749d7SAndre Fischer uno::UNO_QUERY_THROW); 401c58749d7SAndre Fischer 402c58749d7SAndre Fischer xSecurityContext = xSEInitializer->createSecurityContext( rtl::OUString() ); 403c58749d7SAndre Fischer if (xSecurityContext.is()) 404c58749d7SAndre Fischer xSecurityEnv = xSecurityContext->getSecurityEnvironment(); 405c58749d7SAndre Fischer 406c58749d7SAndre Fischer if ( ! xSecurityContext.is() || ! xSecurityEnv.is()) 407c58749d7SAndre Fischer { 408c58749d7SAndre Fischer // Do we have to dispose xSEInitializer or xCertificateContainer? 409c58749d7SAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 410c58749d7SAndre Fischer } 4118590a0fdSAndre Fischer } 4128590a0fdSAndre Fischer catch ( uno::Exception const &) 4138590a0fdSAndre Fischer { 414c58749d7SAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 4158590a0fdSAndre Fischer } 4168590a0fdSAndre Fischer 417c58749d7SAndre Fischer // Decode the server certificate. 41810e20387SAndre Fischer const char* sBase64EncodedServerCertificate ( 41910e20387SAndre Fischer serf_ssl_cert_export( 42010e20387SAndre Fischer pCertificateChainBase64Encoded[0], 42110e20387SAndre Fischer getAprPool())); 422c58749d7SAndre Fischer uno::Reference< security::XCertificate > xServerCertificate( 423c58749d7SAndre Fischer xSecurityEnv->createCertificateFromAscii( 42410e20387SAndre Fischer rtl::OUString::createFromAscii(sBase64EncodedServerCertificate))); 425c58749d7SAndre Fischer if ( ! xServerCertificate.is()) 4268590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 4278590a0fdSAndre Fischer 428c58749d7SAndre Fischer // Get the subject from the server certificate. 429c58749d7SAndre Fischer ::rtl::OUString sServerCertificateSubject (xServerCertificate->getSubjectName()); 430c58749d7SAndre Fischer sal_Int32 nIndex = 0; 431c58749d7SAndre Fischer while (nIndex >= 0) 4328590a0fdSAndre Fischer { 433c58749d7SAndre Fischer const ::rtl::OUString sToken (sServerCertificateSubject.getToken(0, ',', nIndex)); 434c58749d7SAndre Fischer if (sToken.compareToAscii("CN=", 3) == 0) 435c58749d7SAndre Fischer { 436c58749d7SAndre Fischer sServerCertificateSubject = sToken.copy(3); 437c58749d7SAndre Fischer break; 4388590a0fdSAndre Fischer } 439c58749d7SAndre Fischer else if (sToken.compareToAscii(" CN=", 4) == 0) 4408590a0fdSAndre Fischer { 441c58749d7SAndre Fischer sServerCertificateSubject = sToken.copy(4); 442c58749d7SAndre Fischer break; 4438590a0fdSAndre Fischer } 4448590a0fdSAndre Fischer } 4458590a0fdSAndre Fischer 446c58749d7SAndre Fischer // When the certificate container already contains a (trusted) 447c58749d7SAndre Fischer // entry for the server then we do not have to authenticate any 448c58749d7SAndre Fischer // certificate. 449c58749d7SAndre Fischer const security::CertificateContainerStatus eStatus ( 4508590a0fdSAndre Fischer xCertificateContainer->hasCertificate( 451c58749d7SAndre Fischer getHostName(), sServerCertificateSubject ) ); 452c58749d7SAndre Fischer if (eStatus != security::CertificateContainerStatus_NOCERT) 4538590a0fdSAndre Fischer { 454c58749d7SAndre Fischer return eStatus == security::CertificateContainerStatus_TRUSTED 4558590a0fdSAndre Fischer ? APR_SUCCESS 4568590a0fdSAndre Fischer : SERF_SSL_CERT_UNKNOWN_FAILURE; 4578590a0fdSAndre Fischer } 4588590a0fdSAndre Fischer 459c58749d7SAndre Fischer // The shortcut failed, so try to verify the whole chain. This is 460c58749d7SAndre Fischer // done outside the isDomainMatch() block because the result is 461c58749d7SAndre Fischer // used by the interaction handler. 462c58749d7SAndre Fischer std::vector< uno::Reference< security::XCertificate > > aChain; 463*fdf35928SAndre Fischer for (nIndex=1; nIndex<nCertificateChainLength; ++nIndex) 4648590a0fdSAndre Fischer { 46510e20387SAndre Fischer const char* sBase64EncodedCertificate ( 46610e20387SAndre Fischer serf_ssl_cert_export( 46710e20387SAndre Fischer pCertificateChainBase64Encoded[nIndex], 46810e20387SAndre Fischer getAprPool())); 469c58749d7SAndre Fischer uno::Reference< security::XCertificate > xCertificate( 470c58749d7SAndre Fischer xSecurityEnv->createCertificateFromAscii( 47110e20387SAndre Fischer rtl::OUString::createFromAscii(sBase64EncodedCertificate))); 472c58749d7SAndre Fischer if ( ! xCertificate.is()) 4738590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 474c58749d7SAndre Fischer aChain.push_back(xCertificate); 4758590a0fdSAndre Fischer } 476c58749d7SAndre Fischer const sal_Int64 nVerificationResult (xSecurityEnv->verifyCertificate( 477c58749d7SAndre Fischer xServerCertificate, 478c58749d7SAndre Fischer ::comphelper::containerToSequence(aChain))); 4798590a0fdSAndre Fischer 480c58749d7SAndre Fischer // When the certificate matches the host name then we can use the 481c58749d7SAndre Fischer // result of the verification. 482c58749d7SAndre Fischer if (isDomainMatch(sServerCertificateSubject)) 4838590a0fdSAndre Fischer { 484c58749d7SAndre Fischer 485c58749d7SAndre Fischer if (nVerificationResult == 0) 486c58749d7SAndre Fischer { 487c58749d7SAndre Fischer // Certificate (chain) is valid. 488c58749d7SAndre Fischer xCertificateContainer->addCertificate(getHostName(), sServerCertificateSubject, sal_True); 4898590a0fdSAndre Fischer return APR_SUCCESS; 4908590a0fdSAndre Fischer } 491c58749d7SAndre Fischer else if ((nVerificationResult & security::CertificateValidity::CHAIN_INCOMPLETE) != 0) 492c58749d7SAndre Fischer { 493c58749d7SAndre Fischer // We do not have enough information for verification, 494c58749d7SAndre Fischer // neither automatically (as we just discovered) nor 495c58749d7SAndre Fischer // manually (so there is no point in showing any dialog.) 496c58749d7SAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 497c58749d7SAndre Fischer } 498c58749d7SAndre Fischer else if ((nVerificationResult & 499c58749d7SAndre Fischer (security::CertificateValidity::INVALID | security::CertificateValidity::REVOKED)) != 0) 500c58749d7SAndre Fischer { 501c58749d7SAndre Fischer // Certificate (chain) is invalid. 502c58749d7SAndre Fischer xCertificateContainer->addCertificate(getHostName(), sServerCertificateSubject, sal_False); 503c58749d7SAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 504c58749d7SAndre Fischer } 505c58749d7SAndre Fischer else 506c58749d7SAndre Fischer { 507c58749d7SAndre Fischer // For all other we have to ask the user. 508c58749d7SAndre Fischer } 509c58749d7SAndre Fischer } 5108590a0fdSAndre Fischer 511c58749d7SAndre Fischer // We have not been able to automatically verify (or falsify) the 512c58749d7SAndre Fischer // certificate chain. To resolve this we have to ask the user. 5138590a0fdSAndre Fischer const uno::Reference< ucb::XCommandEnvironment > xEnv( getRequestEnvironment().m_xEnv ); 5148590a0fdSAndre Fischer if ( xEnv.is() ) 5158590a0fdSAndre Fischer { 5168590a0fdSAndre Fischer uno::Reference< task::XInteractionHandler > xIH( xEnv->getInteractionHandler() ); 5178590a0fdSAndre Fischer if ( xIH.is() ) 5188590a0fdSAndre Fischer { 5198590a0fdSAndre Fischer rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > 5208590a0fdSAndre Fischer xRequest( new ucbhelper::SimpleCertificateValidationRequest( 521c58749d7SAndre Fischer static_cast<sal_Int32>(nVerificationResult), xServerCertificate, getHostName() ) ); 5228590a0fdSAndre Fischer xIH->handle( xRequest.get() ); 5238590a0fdSAndre Fischer 5248590a0fdSAndre Fischer rtl::Reference< ucbhelper::InteractionContinuation > xSelection 5258590a0fdSAndre Fischer = xRequest->getSelection(); 5268590a0fdSAndre Fischer 5278590a0fdSAndre Fischer if ( xSelection.is() ) 5288590a0fdSAndre Fischer { 5298590a0fdSAndre Fischer uno::Reference< task::XInteractionApprove > xApprove( 5308590a0fdSAndre Fischer xSelection.get(), uno::UNO_QUERY ); 5318590a0fdSAndre Fischer if ( xApprove.is() ) 5328590a0fdSAndre Fischer { 533c58749d7SAndre Fischer xCertificateContainer->addCertificate( getHostName(), sServerCertificateSubject, sal_True ); 5348590a0fdSAndre Fischer return APR_SUCCESS; 5358590a0fdSAndre Fischer } 5368590a0fdSAndre Fischer else 5378590a0fdSAndre Fischer { 5388590a0fdSAndre Fischer // Don't trust cert 539c58749d7SAndre Fischer xCertificateContainer->addCertificate( getHostName(), sServerCertificateSubject, sal_False ); 5408590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 5418590a0fdSAndre Fischer } 5428590a0fdSAndre Fischer } 5438590a0fdSAndre Fischer } 5448590a0fdSAndre Fischer else 5458590a0fdSAndre Fischer { 5468590a0fdSAndre Fischer // Don't trust cert 547c58749d7SAndre Fischer xCertificateContainer->addCertificate( getHostName(), sServerCertificateSubject, sal_False ); 5488590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 5498590a0fdSAndre Fischer } 5508590a0fdSAndre Fischer } 551c58749d7SAndre Fischer 5528590a0fdSAndre Fischer return SERF_SSL_CERT_UNKNOWN_FAILURE; 5538590a0fdSAndre Fischer } 5548590a0fdSAndre Fischer 5558590a0fdSAndre Fischer serf_bucket_t* SerfSession::acceptSerfResponse( serf_request_t * inSerfRequest, 5568590a0fdSAndre Fischer serf_bucket_t * inSerfStreamBucket, 5578590a0fdSAndre Fischer apr_pool_t* /*inAprPool*/ ) 5588590a0fdSAndre Fischer { 5598590a0fdSAndre Fischer // get the per-request bucket allocator 5608590a0fdSAndre Fischer serf_bucket_alloc_t* SerfBktAlloc = serf_request_get_alloc( inSerfRequest ); 5618590a0fdSAndre Fischer 5628590a0fdSAndre Fischer // create a barrier bucket so the response doesn't eat us! 5638590a0fdSAndre Fischer serf_bucket_t *responseBkt = serf_bucket_barrier_create( inSerfStreamBucket, 5648590a0fdSAndre Fischer SerfBktAlloc ); 5658590a0fdSAndre Fischer 5668590a0fdSAndre Fischer // create response bucket 5678590a0fdSAndre Fischer responseBkt = serf_bucket_response_create( responseBkt, 5688590a0fdSAndre Fischer SerfBktAlloc ); 5698590a0fdSAndre Fischer 5708590a0fdSAndre Fischer if ( isHeadRequestInProgress() ) 5718590a0fdSAndre Fischer { 5728590a0fdSAndre Fischer // advise the response bucket that this was from a HEAD request and that it should not expect to see a response body. 5738590a0fdSAndre Fischer serf_bucket_response_set_head( responseBkt ); 5748590a0fdSAndre Fischer } 5758590a0fdSAndre Fischer 5768590a0fdSAndre Fischer return responseBkt; 5778590a0fdSAndre Fischer } 5788590a0fdSAndre Fischer 57949989859SOliver-Rainer Wittmann SerfRequestProcessor* SerfSession::createReqProc( const rtl::OUString & inPath ) 58049989859SOliver-Rainer Wittmann { 58149989859SOliver-Rainer Wittmann return new SerfRequestProcessor( *this, 58249989859SOliver-Rainer Wittmann inPath, 58349989859SOliver-Rainer Wittmann m_bUseChunkedEncoding ); 58449989859SOliver-Rainer Wittmann } 58549989859SOliver-Rainer Wittmann 5868590a0fdSAndre Fischer // ------------------------------------------------------------------- 5878590a0fdSAndre Fischer // PROPFIND - allprop & named 5888590a0fdSAndre Fischer // ------------------------------------------------------------------- 5898590a0fdSAndre Fischer void SerfSession::PROPFIND( const rtl::OUString & inPath, 5908590a0fdSAndre Fischer const Depth inDepth, 5918590a0fdSAndre Fischer const std::vector< rtl::OUString > & inPropNames, 5928590a0fdSAndre Fischer std::vector< DAVResource > & ioResources, 5938590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 5948590a0fdSAndre Fischer throw ( DAVException ) 5958590a0fdSAndre Fischer { 5968590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 5978590a0fdSAndre Fischer 5988590a0fdSAndre Fischer Init( rEnv ); 5998590a0fdSAndre Fischer 6008590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 60149989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 60249989859SOliver-Rainer Wittmann aReqProc->processPropFind( inDepth, 6038590a0fdSAndre Fischer inPropNames, 6048590a0fdSAndre Fischer ioResources, 6058590a0fdSAndre Fischer status ); 6068590a0fdSAndre Fischer 6078590a0fdSAndre Fischer if ( status == APR_SUCCESS && 60849989859SOliver-Rainer Wittmann aReqProc->mpDAVException == 0 && 6098590a0fdSAndre Fischer ioResources.empty() ) 6108590a0fdSAndre Fischer { 6118590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 6128590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, inPath, (sal_uInt16)APR_EGENERAL ); 6138590a0fdSAndre Fischer } 61449989859SOliver-Rainer Wittmann HandleError( aReqProc ); 6158590a0fdSAndre Fischer } 6168590a0fdSAndre Fischer 6178590a0fdSAndre Fischer // ------------------------------------------------------------------- 6188590a0fdSAndre Fischer // PROPFIND - propnames 6198590a0fdSAndre Fischer // ------------------------------------------------------------------- 6208590a0fdSAndre Fischer void SerfSession::PROPFIND( const rtl::OUString & inPath, 6218590a0fdSAndre Fischer const Depth inDepth, 6228590a0fdSAndre Fischer std::vector< DAVResourceInfo > & ioResInfo, 6238590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6248590a0fdSAndre Fischer throw( DAVException ) 6258590a0fdSAndre Fischer { 6268590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6278590a0fdSAndre Fischer 6288590a0fdSAndre Fischer Init( rEnv ); 6298590a0fdSAndre Fischer 6308590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 63149989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 63249989859SOliver-Rainer Wittmann aReqProc->processPropFind( inDepth, 6338590a0fdSAndre Fischer ioResInfo, 6348590a0fdSAndre Fischer status ); 6358590a0fdSAndre Fischer 6368590a0fdSAndre Fischer if ( status == APR_SUCCESS && 63749989859SOliver-Rainer Wittmann aReqProc->mpDAVException == 0 && 6388590a0fdSAndre Fischer ioResInfo.empty() ) 6398590a0fdSAndre Fischer { 6408590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 6418590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, inPath, (sal_uInt16)APR_EGENERAL ); 6428590a0fdSAndre Fischer } 64349989859SOliver-Rainer Wittmann HandleError( aReqProc ); 6448590a0fdSAndre Fischer } 6458590a0fdSAndre Fischer 6468590a0fdSAndre Fischer // ------------------------------------------------------------------- 6478590a0fdSAndre Fischer // PROPPATCH 6488590a0fdSAndre Fischer // ------------------------------------------------------------------- 6498590a0fdSAndre Fischer void SerfSession::PROPPATCH( const rtl::OUString & inPath, 6508590a0fdSAndre Fischer const std::vector< ProppatchValue > & inValues, 6518590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6528590a0fdSAndre Fischer throw( DAVException ) 6538590a0fdSAndre Fischer { 6548590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6558590a0fdSAndre Fischer 6568590a0fdSAndre Fischer Init( rEnv ); 6578590a0fdSAndre Fischer 6588590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 65949989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 66049989859SOliver-Rainer Wittmann aReqProc->processPropPatch( inValues, 6618590a0fdSAndre Fischer status ); 6628590a0fdSAndre Fischer 66349989859SOliver-Rainer Wittmann HandleError( aReqProc ); 6648590a0fdSAndre Fischer } 6658590a0fdSAndre Fischer 6668590a0fdSAndre Fischer // ------------------------------------------------------------------- 6678590a0fdSAndre Fischer // HEAD 6688590a0fdSAndre Fischer // ------------------------------------------------------------------- 6698590a0fdSAndre Fischer void SerfSession::HEAD( const ::rtl::OUString & inPath, 6708590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 6718590a0fdSAndre Fischer DAVResource & ioResource, 6728590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 6738590a0fdSAndre Fischer throw( DAVException ) 6748590a0fdSAndre Fischer { 6758590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 6768590a0fdSAndre Fischer 6778590a0fdSAndre Fischer Init( rEnv ); 6788590a0fdSAndre Fischer 6798590a0fdSAndre Fischer m_bIsHeadRequestInProgress = true; 6808590a0fdSAndre Fischer 68149989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 6828590a0fdSAndre Fischer ioResource.uri = inPath; 6838590a0fdSAndre Fischer ioResource.properties.clear(); 6848590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 68549989859SOliver-Rainer Wittmann aReqProc->processHead( inHeaderNames, 6868590a0fdSAndre Fischer ioResource, 6878590a0fdSAndre Fischer status ); 6888590a0fdSAndre Fischer 6898590a0fdSAndre Fischer m_bIsHeadRequestInProgress = false; 69049989859SOliver-Rainer Wittmann 69149989859SOliver-Rainer Wittmann HandleError( aReqProc ); 6928590a0fdSAndre Fischer } 6938590a0fdSAndre Fischer 6948590a0fdSAndre Fischer // ------------------------------------------------------------------- 6958590a0fdSAndre Fischer // GET 6968590a0fdSAndre Fischer // ------------------------------------------------------------------- 6978590a0fdSAndre Fischer uno::Reference< io::XInputStream > 6988590a0fdSAndre Fischer SerfSession::GET( const rtl::OUString & inPath, 6998590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7008590a0fdSAndre Fischer throw ( DAVException ) 7018590a0fdSAndre Fischer { 7028590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7038590a0fdSAndre Fischer 7048590a0fdSAndre Fischer Init( rEnv ); 7058590a0fdSAndre Fischer 7068590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 7078590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 70849989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 70949989859SOliver-Rainer Wittmann aReqProc->processGet( xInputStream, 7108590a0fdSAndre Fischer status ); 7118590a0fdSAndre Fischer 71249989859SOliver-Rainer Wittmann HandleError( aReqProc ); 7138590a0fdSAndre Fischer 7148590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 7158590a0fdSAndre Fischer } 7168590a0fdSAndre Fischer 7178590a0fdSAndre Fischer // ------------------------------------------------------------------- 7188590a0fdSAndre Fischer // GET 7198590a0fdSAndre Fischer // ------------------------------------------------------------------- 7208590a0fdSAndre Fischer void SerfSession::GET( const rtl::OUString & inPath, 7218590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & ioOutputStream, 7228590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7238590a0fdSAndre Fischer throw ( DAVException ) 7248590a0fdSAndre Fischer { 7258590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7268590a0fdSAndre Fischer 7278590a0fdSAndre Fischer Init( rEnv ); 7288590a0fdSAndre Fischer 7298590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 73049989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 73149989859SOliver-Rainer Wittmann aReqProc->processGet( ioOutputStream, 7328590a0fdSAndre Fischer status ); 7338590a0fdSAndre Fischer 73449989859SOliver-Rainer Wittmann HandleError( aReqProc ); 7358590a0fdSAndre Fischer } 7368590a0fdSAndre Fischer 7378590a0fdSAndre Fischer // ------------------------------------------------------------------- 7388590a0fdSAndre Fischer // GET 7398590a0fdSAndre Fischer // ------------------------------------------------------------------- 7408590a0fdSAndre Fischer uno::Reference< io::XInputStream > 7418590a0fdSAndre Fischer SerfSession::GET( const rtl::OUString & inPath, 7428590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 7438590a0fdSAndre Fischer DAVResource & ioResource, 7448590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7458590a0fdSAndre Fischer throw ( DAVException ) 7468590a0fdSAndre Fischer { 7478590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7488590a0fdSAndre Fischer 7498590a0fdSAndre Fischer Init( rEnv ); 7508590a0fdSAndre Fischer 75149989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 7528590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 7538590a0fdSAndre Fischer ioResource.uri = inPath; 7548590a0fdSAndre Fischer ioResource.properties.clear(); 7558590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 75649989859SOliver-Rainer Wittmann aReqProc->processGet( xInputStream, 7578590a0fdSAndre Fischer inHeaderNames, 7588590a0fdSAndre Fischer ioResource, 7598590a0fdSAndre Fischer status ); 7608590a0fdSAndre Fischer 76149989859SOliver-Rainer Wittmann HandleError( aReqProc ); 7628590a0fdSAndre Fischer 7638590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 7648590a0fdSAndre Fischer } 7658590a0fdSAndre Fischer 7668590a0fdSAndre Fischer 7678590a0fdSAndre Fischer // ------------------------------------------------------------------- 7688590a0fdSAndre Fischer // GET 7698590a0fdSAndre Fischer // ------------------------------------------------------------------- 7708590a0fdSAndre Fischer void SerfSession::GET( const rtl::OUString & inPath, 7718590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & ioOutputStream, 7728590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames, 7738590a0fdSAndre Fischer DAVResource & ioResource, 7748590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7758590a0fdSAndre Fischer throw ( DAVException ) 7768590a0fdSAndre Fischer { 7778590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 7788590a0fdSAndre Fischer 7798590a0fdSAndre Fischer Init( rEnv ); 7808590a0fdSAndre Fischer 78149989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 7828590a0fdSAndre Fischer ioResource.uri = inPath; 7838590a0fdSAndre Fischer ioResource.properties.clear(); 7848590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 78549989859SOliver-Rainer Wittmann aReqProc->processGet( ioOutputStream, 7868590a0fdSAndre Fischer inHeaderNames, 7878590a0fdSAndre Fischer ioResource, 7888590a0fdSAndre Fischer status ); 7898590a0fdSAndre Fischer 79049989859SOliver-Rainer Wittmann HandleError( aReqProc ); 7918590a0fdSAndre Fischer } 7928590a0fdSAndre Fischer 7938590a0fdSAndre Fischer // ------------------------------------------------------------------- 7948590a0fdSAndre Fischer // PUT 7958590a0fdSAndre Fischer // ------------------------------------------------------------------- 7968590a0fdSAndre Fischer void SerfSession::PUT( const rtl::OUString & inPath, 7978590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 7988590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 7998590a0fdSAndre Fischer throw ( DAVException ) 8008590a0fdSAndre Fischer { 8018590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8028590a0fdSAndre Fischer 8038590a0fdSAndre Fischer Init( rEnv ); 8048590a0fdSAndre Fischer 80549989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 8068590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 8078590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, false ) ) 8088590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 8098590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 81049989859SOliver-Rainer Wittmann aReqProc->processPut( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 8118590a0fdSAndre Fischer aDataToSend.getLength(), 8128590a0fdSAndre Fischer status ); 8138590a0fdSAndre Fischer 81449989859SOliver-Rainer Wittmann HandleError( aReqProc ); 8158590a0fdSAndre Fischer } 8168590a0fdSAndre Fischer 8178590a0fdSAndre Fischer // ------------------------------------------------------------------- 8188590a0fdSAndre Fischer // POST 8198590a0fdSAndre Fischer // ------------------------------------------------------------------- 8208590a0fdSAndre Fischer uno::Reference< io::XInputStream > 8218590a0fdSAndre Fischer SerfSession::POST( const rtl::OUString & inPath, 8228590a0fdSAndre Fischer const rtl::OUString & rContentType, 8238590a0fdSAndre Fischer const rtl::OUString & rReferer, 8248590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 8258590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 8268590a0fdSAndre Fischer throw ( DAVException ) 8278590a0fdSAndre Fischer { 8288590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8298590a0fdSAndre Fischer 8308590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 8318590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, true ) ) 8328590a0fdSAndre Fischer { 8338590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 8348590a0fdSAndre Fischer } 8358590a0fdSAndre Fischer 8368590a0fdSAndre Fischer Init( rEnv ); 8378590a0fdSAndre Fischer 83849989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 8398590a0fdSAndre Fischer uno::Reference< SerfInputStream > xInputStream( new SerfInputStream ); 8408590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 84149989859SOliver-Rainer Wittmann aReqProc->processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 8428590a0fdSAndre Fischer aDataToSend.getLength(), 8438590a0fdSAndre Fischer rContentType, 8448590a0fdSAndre Fischer rReferer, 8458590a0fdSAndre Fischer xInputStream, 8468590a0fdSAndre Fischer status ); 8478590a0fdSAndre Fischer 84849989859SOliver-Rainer Wittmann HandleError( aReqProc ); 8498590a0fdSAndre Fischer return uno::Reference< io::XInputStream >( xInputStream.get() ); 8508590a0fdSAndre Fischer } 8518590a0fdSAndre Fischer 8528590a0fdSAndre Fischer // ------------------------------------------------------------------- 8538590a0fdSAndre Fischer // POST 8548590a0fdSAndre Fischer // ------------------------------------------------------------------- 8558590a0fdSAndre Fischer void SerfSession::POST( const rtl::OUString & inPath, 8568590a0fdSAndre Fischer const rtl::OUString & rContentType, 8578590a0fdSAndre Fischer const rtl::OUString & rReferer, 8588590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & inInputStream, 8598590a0fdSAndre Fischer uno::Reference< io::XOutputStream > & oOutputStream, 8608590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 8618590a0fdSAndre Fischer throw ( DAVException ) 8628590a0fdSAndre Fischer { 8638590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8648590a0fdSAndre Fischer 8658590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aDataToSend; 8668590a0fdSAndre Fischer if ( !getDataFromInputStream( inInputStream, aDataToSend, true ) ) 8678590a0fdSAndre Fischer { 8688590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 8698590a0fdSAndre Fischer } 8708590a0fdSAndre Fischer 8718590a0fdSAndre Fischer Init( rEnv ); 8728590a0fdSAndre Fischer 87349989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 8748590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 87549989859SOliver-Rainer Wittmann aReqProc->processPost( reinterpret_cast< const char * >( aDataToSend.getConstArray() ), 8768590a0fdSAndre Fischer aDataToSend.getLength(), 8778590a0fdSAndre Fischer rContentType, 8788590a0fdSAndre Fischer rReferer, 8798590a0fdSAndre Fischer oOutputStream, 8808590a0fdSAndre Fischer status ); 8818590a0fdSAndre Fischer 88249989859SOliver-Rainer Wittmann HandleError( aReqProc ); 8838590a0fdSAndre Fischer } 8848590a0fdSAndre Fischer 8858590a0fdSAndre Fischer // ------------------------------------------------------------------- 8868590a0fdSAndre Fischer // MKCOL 8878590a0fdSAndre Fischer // ------------------------------------------------------------------- 8888590a0fdSAndre Fischer void SerfSession::MKCOL( const rtl::OUString & inPath, 8898590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 8908590a0fdSAndre Fischer throw ( DAVException ) 8918590a0fdSAndre Fischer { 8928590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 8938590a0fdSAndre Fischer 8948590a0fdSAndre Fischer Init( rEnv ); 8958590a0fdSAndre Fischer 89649989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 8978590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 89849989859SOliver-Rainer Wittmann aReqProc->processMkCol( status ); 8998590a0fdSAndre Fischer 90049989859SOliver-Rainer Wittmann HandleError( aReqProc ); 9018590a0fdSAndre Fischer } 9028590a0fdSAndre Fischer 9038590a0fdSAndre Fischer // ------------------------------------------------------------------- 9048590a0fdSAndre Fischer // COPY 9058590a0fdSAndre Fischer // ------------------------------------------------------------------- 9068590a0fdSAndre Fischer void SerfSession::COPY( const rtl::OUString & inSourceURL, 9078590a0fdSAndre Fischer const rtl::OUString & inDestinationURL, 9088590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv, 9098590a0fdSAndre Fischer sal_Bool inOverWrite ) 9108590a0fdSAndre Fischer throw ( DAVException ) 9118590a0fdSAndre Fischer { 9128590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 9138590a0fdSAndre Fischer 9148590a0fdSAndre Fischer Init( rEnv ); 9158590a0fdSAndre Fischer 9168590a0fdSAndre Fischer SerfUri theSourceUri( inSourceURL ); 91749989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( theSourceUri.GetPath() ) ); 9188590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 91949989859SOliver-Rainer Wittmann aReqProc->processCopy( inDestinationURL, 9208590a0fdSAndre Fischer (inOverWrite ? true : false), 9218590a0fdSAndre Fischer status ); 9228590a0fdSAndre Fischer 92349989859SOliver-Rainer Wittmann HandleError( aReqProc ); 9248590a0fdSAndre Fischer } 9258590a0fdSAndre Fischer 9268590a0fdSAndre Fischer // ------------------------------------------------------------------- 9278590a0fdSAndre Fischer // MOVE 9288590a0fdSAndre Fischer // ------------------------------------------------------------------- 9298590a0fdSAndre Fischer void SerfSession::MOVE( const rtl::OUString & inSourceURL, 9308590a0fdSAndre Fischer const rtl::OUString & inDestinationURL, 9318590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv, 9328590a0fdSAndre Fischer sal_Bool inOverWrite ) 9338590a0fdSAndre Fischer throw ( DAVException ) 9348590a0fdSAndre Fischer { 9358590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 9368590a0fdSAndre Fischer 9378590a0fdSAndre Fischer Init( rEnv ); 9388590a0fdSAndre Fischer 9398590a0fdSAndre Fischer SerfUri theSourceUri( inSourceURL ); 94049989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( theSourceUri.GetPath() ) ); 9418590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 94249989859SOliver-Rainer Wittmann aReqProc->processMove( inDestinationURL, 9438590a0fdSAndre Fischer (inOverWrite ? true : false), 9448590a0fdSAndre Fischer status ); 9458590a0fdSAndre Fischer 94649989859SOliver-Rainer Wittmann HandleError( aReqProc ); 9478590a0fdSAndre Fischer } 9488590a0fdSAndre Fischer 9498590a0fdSAndre Fischer // ------------------------------------------------------------------- 9508590a0fdSAndre Fischer // DESTROY 9518590a0fdSAndre Fischer // ------------------------------------------------------------------- 9528590a0fdSAndre Fischer void SerfSession::DESTROY( const rtl::OUString & inPath, 9538590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 9548590a0fdSAndre Fischer throw ( DAVException ) 9558590a0fdSAndre Fischer { 9568590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 9578590a0fdSAndre Fischer 9588590a0fdSAndre Fischer Init( rEnv ); 9598590a0fdSAndre Fischer 96049989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 9618590a0fdSAndre Fischer apr_status_t status = APR_SUCCESS; 96249989859SOliver-Rainer Wittmann aReqProc->processDelete( status ); 9638590a0fdSAndre Fischer 96449989859SOliver-Rainer Wittmann HandleError( aReqProc ); 9658590a0fdSAndre Fischer } 9668590a0fdSAndre Fischer 9678590a0fdSAndre Fischer // ------------------------------------------------------------------- 9688590a0fdSAndre Fischer /* 9698590a0fdSAndre Fischer namespace 9708590a0fdSAndre Fischer { 9718590a0fdSAndre Fischer sal_Int32 lastChanceToSendRefreshRequest( TimeValue const & rStart, 9728590a0fdSAndre Fischer int timeout ) 9738590a0fdSAndre Fischer { 9748590a0fdSAndre Fischer TimeValue aEnd; 9758590a0fdSAndre Fischer osl_getSystemTime( &aEnd ); 9768590a0fdSAndre Fischer 9778590a0fdSAndre Fischer // Try to estimate a safe absolute time for sending the 9788590a0fdSAndre Fischer // lock refresh request. 9798590a0fdSAndre Fischer sal_Int32 lastChanceToSendRefreshRequest = -1; 9808590a0fdSAndre Fischer if ( timeout != NE_TIMEOUT_INFINITE ) 9818590a0fdSAndre Fischer { 9828590a0fdSAndre Fischer sal_Int32 calltime = aEnd.Seconds - rStart.Seconds; 9838590a0fdSAndre Fischer if ( calltime <= timeout ) 9848590a0fdSAndre Fischer { 9858590a0fdSAndre Fischer lastChanceToSendRefreshRequest 9868590a0fdSAndre Fischer = aEnd.Seconds + timeout - calltime; 9878590a0fdSAndre Fischer } 9888590a0fdSAndre Fischer else 9898590a0fdSAndre Fischer { 9908590a0fdSAndre Fischer OSL_TRACE( "No chance to refresh lock before timeout!" ); 9918590a0fdSAndre Fischer } 9928590a0fdSAndre Fischer } 9938590a0fdSAndre Fischer return lastChanceToSendRefreshRequest; 9948590a0fdSAndre Fischer } 9958590a0fdSAndre Fischer 9968590a0fdSAndre Fischer } // namespace 9978590a0fdSAndre Fischer */ 9988590a0fdSAndre Fischer // ------------------------------------------------------------------- 9998590a0fdSAndre Fischer // LOCK (set new lock) 10008590a0fdSAndre Fischer // ------------------------------------------------------------------- 10018590a0fdSAndre Fischer void SerfSession::LOCK( const ::rtl::OUString & inPath, 10028590a0fdSAndre Fischer ucb::Lock & /*rLock*/, 10038590a0fdSAndre Fischer const DAVRequestEnvironment & rEnv ) 10048590a0fdSAndre Fischer throw ( DAVException ) 10058590a0fdSAndre Fischer { 10068590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 10078590a0fdSAndre Fischer 10088590a0fdSAndre Fischer Init( rEnv ); 10098590a0fdSAndre Fischer 101049989859SOliver-Rainer Wittmann boost::shared_ptr<SerfRequestProcessor> aReqProc( createReqProc( inPath ) ); 101149989859SOliver-Rainer Wittmann HandleError( aReqProc ); 10128590a0fdSAndre Fischer /* Create a depth zero, exclusive write lock, with default timeout 10138590a0fdSAndre Fischer * (allowing a server to pick a default). token, owner and uri are 10148590a0fdSAndre Fischer * unset. */ 10158590a0fdSAndre Fischer /* 10168590a0fdSAndre Fischer SerfLock * theLock = ne_lock_create(); 10178590a0fdSAndre Fischer 10188590a0fdSAndre Fischer // Set the lock uri 10198590a0fdSAndre Fischer ne_uri aUri; 10208590a0fdSAndre Fischer ne_uri_parse( rtl::OUStringToOString( makeAbsoluteURL( inPath ), 10218590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 10228590a0fdSAndre Fischer &aUri ); 10238590a0fdSAndre Fischer theLock->uri = aUri; 10248590a0fdSAndre Fischer 10258590a0fdSAndre Fischer // Set the lock depth 10268590a0fdSAndre Fischer switch( rLock.Depth ) 10278590a0fdSAndre Fischer { 10288590a0fdSAndre Fischer case ucb::LockDepth_ZERO: 10298590a0fdSAndre Fischer theLock->depth = NE_DEPTH_ZERO; 10308590a0fdSAndre Fischer break; 10318590a0fdSAndre Fischer case ucb::LockDepth_ONE: 10328590a0fdSAndre Fischer theLock->depth = NE_DEPTH_ONE; 10338590a0fdSAndre Fischer break; 10348590a0fdSAndre Fischer case ucb::LockDepth_INFINITY: 10358590a0fdSAndre Fischer theLock->depth = NE_DEPTH_INFINITE; 10368590a0fdSAndre Fischer break; 10378590a0fdSAndre Fischer default: 10388590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 10398590a0fdSAndre Fischer } 10408590a0fdSAndre Fischer 10418590a0fdSAndre Fischer // Set the lock scope 10428590a0fdSAndre Fischer switch ( rLock.Scope ) 10438590a0fdSAndre Fischer { 10448590a0fdSAndre Fischer case ucb::LockScope_EXCLUSIVE: 10458590a0fdSAndre Fischer theLock->scope = ne_lockscope_exclusive; 10468590a0fdSAndre Fischer break; 10478590a0fdSAndre Fischer case ucb::LockScope_SHARED: 10488590a0fdSAndre Fischer theLock->scope = ne_lockscope_shared; 10498590a0fdSAndre Fischer break; 10508590a0fdSAndre Fischer default: 10518590a0fdSAndre Fischer throw DAVException( DAVException::DAV_INVALID_ARG ); 10528590a0fdSAndre Fischer } 10538590a0fdSAndre Fischer 10548590a0fdSAndre Fischer // Set the lock timeout 10558590a0fdSAndre Fischer theLock->timeout = (long)rLock.Timeout; 10568590a0fdSAndre Fischer 10578590a0fdSAndre Fischer // Set the lock owner 10588590a0fdSAndre Fischer rtl::OUString aValue; 10598590a0fdSAndre Fischer rLock.Owner >>= aValue; 10608590a0fdSAndre Fischer theLock->owner = 10618590a0fdSAndre Fischer ne_strdup( rtl::OUStringToOString( aValue, 10628590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 10638590a0fdSAndre Fischer TimeValue startCall; 10648590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 10658590a0fdSAndre Fischer 10668590a0fdSAndre Fischer int theRetVal = ne_lock( m_pHttpSession, theLock ); 10678590a0fdSAndre Fischer 10688590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 10698590a0fdSAndre Fischer { 10708590a0fdSAndre Fischer m_aSerfLockStore.addLock( theLock, 10718590a0fdSAndre Fischer this, 10728590a0fdSAndre Fischer lastChanceToSendRefreshRequest( 10738590a0fdSAndre Fischer startCall, theLock->timeout ) ); 10748590a0fdSAndre Fischer 10758590a0fdSAndre Fischer uno::Sequence< rtl::OUString > aTokens( 1 ); 10768590a0fdSAndre Fischer aTokens[ 0 ] = rtl::OUString::createFromAscii( theLock->token ); 10778590a0fdSAndre Fischer rLock.LockTokens = aTokens; 10788590a0fdSAndre Fischer 10798590a0fdSAndre Fischer OSL_TRACE( "SerfSession::LOCK: created lock for %s. token: %s", 10808590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 10818590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 10828590a0fdSAndre Fischer theLock->token ); 10838590a0fdSAndre Fischer } 10848590a0fdSAndre Fischer else 10858590a0fdSAndre Fischer { 10868590a0fdSAndre Fischer ne_lock_destroy( theLock ); 10878590a0fdSAndre Fischer 10888590a0fdSAndre Fischer OSL_TRACE( "SerfSession::LOCK: obtaining lock for %s failed!", 10898590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 10908590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 10918590a0fdSAndre Fischer } 10928590a0fdSAndre Fischer 10938590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 10948590a0fdSAndre Fischer */ 10958590a0fdSAndre Fischer } 10968590a0fdSAndre Fischer 10978590a0fdSAndre Fischer // ------------------------------------------------------------------- 10988590a0fdSAndre Fischer // LOCK (refresh existing lock) 10998590a0fdSAndre Fischer // ------------------------------------------------------------------- 11008590a0fdSAndre Fischer sal_Int64 SerfSession::LOCK( const ::rtl::OUString & /*inPath*/, 11018590a0fdSAndre Fischer sal_Int64 nTimeout, 11028590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 11038590a0fdSAndre Fischer throw ( DAVException ) 11048590a0fdSAndre Fischer { 11058590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 11068590a0fdSAndre Fischer 11078590a0fdSAndre Fischer return nTimeout; 11088590a0fdSAndre Fischer /* 11098590a0fdSAndre Fischer // Try to get the neon lock from lock store 11108590a0fdSAndre Fischer SerfLock * theLock 11118590a0fdSAndre Fischer = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); 11128590a0fdSAndre Fischer if ( !theLock ) 11138590a0fdSAndre Fischer throw DAVException( DAVException::DAV_NOT_LOCKED ); 11148590a0fdSAndre Fischer 11158590a0fdSAndre Fischer Init( rEnv ); 11168590a0fdSAndre Fischer 11178590a0fdSAndre Fischer // refresh existing lock. 11188590a0fdSAndre Fischer theLock->timeout = static_cast< long >( nTimeout ); 11198590a0fdSAndre Fischer 11208590a0fdSAndre Fischer TimeValue startCall; 11218590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 11228590a0fdSAndre Fischer 11238590a0fdSAndre Fischer int theRetVal = ne_lock_refresh( m_pHttpSession, theLock ); 11248590a0fdSAndre Fischer 11258590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 11268590a0fdSAndre Fischer { 11278590a0fdSAndre Fischer m_aSerfLockStore.updateLock( theLock, 11288590a0fdSAndre Fischer lastChanceToSendRefreshRequest( 11298590a0fdSAndre Fischer startCall, theLock->timeout ) ); 11308590a0fdSAndre Fischer } 11318590a0fdSAndre Fischer 11328590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 11338590a0fdSAndre Fischer 11348590a0fdSAndre Fischer return theLock->timeout; 11358590a0fdSAndre Fischer */ 11368590a0fdSAndre Fischer } 11378590a0fdSAndre Fischer 11388590a0fdSAndre Fischer // ------------------------------------------------------------------- 11398590a0fdSAndre Fischer // LOCK (refresh existing lock) 11408590a0fdSAndre Fischer // ------------------------------------------------------------------- 11418590a0fdSAndre Fischer bool SerfSession::LOCK( SerfLock * /*pLock*/, 11428590a0fdSAndre Fischer sal_Int32 & /*rlastChanceToSendRefreshRequest*/ ) 11438590a0fdSAndre Fischer { 11448590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 11458590a0fdSAndre Fischer 11468590a0fdSAndre Fischer return true; 11478590a0fdSAndre Fischer /* 11488590a0fdSAndre Fischer // refresh existing lock. 11498590a0fdSAndre Fischer 11508590a0fdSAndre Fischer TimeValue startCall; 11518590a0fdSAndre Fischer osl_getSystemTime( &startCall ); 11528590a0fdSAndre Fischer 11538590a0fdSAndre Fischer if ( ne_lock_refresh( m_pHttpSession, pLock ) == NE_OK ) 11548590a0fdSAndre Fischer { 11558590a0fdSAndre Fischer rlastChanceToSendRefreshRequest 11568590a0fdSAndre Fischer = lastChanceToSendRefreshRequest( startCall, pLock->timeout ); 11578590a0fdSAndre Fischer 11588590a0fdSAndre Fischer OSL_TRACE( "Lock successfully refreshed." ); 11598590a0fdSAndre Fischer return true; 11608590a0fdSAndre Fischer } 11618590a0fdSAndre Fischer else 11628590a0fdSAndre Fischer { 11638590a0fdSAndre Fischer OSL_TRACE( "Lock not refreshed!" ); 11648590a0fdSAndre Fischer return false; 11658590a0fdSAndre Fischer } 11668590a0fdSAndre Fischer */ 11678590a0fdSAndre Fischer } 11688590a0fdSAndre Fischer 11698590a0fdSAndre Fischer // ------------------------------------------------------------------- 11708590a0fdSAndre Fischer // UNLOCK 11718590a0fdSAndre Fischer // ------------------------------------------------------------------- 11728590a0fdSAndre Fischer void SerfSession::UNLOCK( const ::rtl::OUString & /*inPath*/, 11738590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 11748590a0fdSAndre Fischer throw ( DAVException ) 11758590a0fdSAndre Fischer { 11768590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 11778590a0fdSAndre Fischer 11788590a0fdSAndre Fischer /* 11798590a0fdSAndre Fischer // get the neon lock from lock store 11808590a0fdSAndre Fischer SerfLock * theLock 11818590a0fdSAndre Fischer = m_aSerfLockStore.findByUri( makeAbsoluteURL( inPath ) ); 11828590a0fdSAndre Fischer if ( !theLock ) 11838590a0fdSAndre Fischer throw DAVException( DAVException::DAV_NOT_LOCKED ); 11848590a0fdSAndre Fischer 11858590a0fdSAndre Fischer Init( rEnv ); 11868590a0fdSAndre Fischer 11878590a0fdSAndre Fischer int theRetVal = ne_unlock( m_pHttpSession, theLock ); 11888590a0fdSAndre Fischer 11898590a0fdSAndre Fischer if ( theRetVal == NE_OK ) 11908590a0fdSAndre Fischer { 11918590a0fdSAndre Fischer m_aSerfLockStore.removeLock( theLock ); 11928590a0fdSAndre Fischer ne_lock_destroy( theLock ); 11938590a0fdSAndre Fischer } 11948590a0fdSAndre Fischer else 11958590a0fdSAndre Fischer { 11968590a0fdSAndre Fischer OSL_TRACE( "SerfSession::UNLOCK: unlocking of %s failed.", 11978590a0fdSAndre Fischer rtl::OUStringToOString( makeAbsoluteURL( inPath ), 11988590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr() ); 11998590a0fdSAndre Fischer } 12008590a0fdSAndre Fischer 12018590a0fdSAndre Fischer HandleError( theRetVal, inPath, rEnv ); 12028590a0fdSAndre Fischer */ 12038590a0fdSAndre Fischer } 12048590a0fdSAndre Fischer 12058590a0fdSAndre Fischer // ------------------------------------------------------------------- 12068590a0fdSAndre Fischer // UNLOCK 12078590a0fdSAndre Fischer // ------------------------------------------------------------------- 12088590a0fdSAndre Fischer bool SerfSession::UNLOCK( SerfLock * /*pLock*/ ) 12098590a0fdSAndre Fischer { 12108590a0fdSAndre Fischer osl::Guard< osl::Mutex > theGuard( m_aMutex ); 12118590a0fdSAndre Fischer 12128590a0fdSAndre Fischer return true; 12138590a0fdSAndre Fischer /* 12148590a0fdSAndre Fischer if ( ne_unlock( m_pHttpSession, pLock ) == NE_OK ) 12158590a0fdSAndre Fischer { 12168590a0fdSAndre Fischer OSL_TRACE( "UNLOCK succeeded." ); 12178590a0fdSAndre Fischer return true; 12188590a0fdSAndre Fischer } 12198590a0fdSAndre Fischer else 12208590a0fdSAndre Fischer { 12218590a0fdSAndre Fischer OSL_TRACE( "UNLOCK failed!" ); 12228590a0fdSAndre Fischer return false; 12238590a0fdSAndre Fischer } 12248590a0fdSAndre Fischer */ 12258590a0fdSAndre Fischer } 12268590a0fdSAndre Fischer 12278590a0fdSAndre Fischer // ------------------------------------------------------------------- 12288590a0fdSAndre Fischer void SerfSession::abort() 12298590a0fdSAndre Fischer throw ( DAVException ) 12308590a0fdSAndre Fischer { 12318590a0fdSAndre Fischer // 11.11.09 (tkr): The following code lines causing crashes if 12328590a0fdSAndre Fischer // closing a ongoing connection. It turned out that this existing 12338590a0fdSAndre Fischer // solution doesn't work in multi-threading environments. 12348590a0fdSAndre Fischer // So I disabled them in 3.2. . Issue #73893# should fix it in OOo 3.3. 12358590a0fdSAndre Fischer //if ( m_pHttpSession ) 12368590a0fdSAndre Fischer // ne_close_connection( m_pHttpSession ); 12378590a0fdSAndre Fischer } 12388590a0fdSAndre Fischer 12398590a0fdSAndre Fischer // ------------------------------------------------------------------- 12408590a0fdSAndre Fischer const ucbhelper::InternetProxyServer & SerfSession::getProxySettings() const 12418590a0fdSAndre Fischer { 12428590a0fdSAndre Fischer if ( m_aUri.GetScheme().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "http" ) ) || 12438590a0fdSAndre Fischer m_aUri.GetScheme().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "https" ) ) ) 12448590a0fdSAndre Fischer { 12458590a0fdSAndre Fischer return m_rProxyDecider.getProxy( m_aUri.GetScheme(), 12468590a0fdSAndre Fischer m_aUri.GetHost(), 12478590a0fdSAndre Fischer m_aUri.GetPort() ); 12488590a0fdSAndre Fischer } 12498590a0fdSAndre Fischer else 12508590a0fdSAndre Fischer { 12518590a0fdSAndre Fischer // TODO: figure out, if this case can occur 12528590a0fdSAndre Fischer return m_rProxyDecider.getProxy( m_aUri.GetScheme(), 12538590a0fdSAndre Fischer rtl::OUString() /* not used */, 12548590a0fdSAndre Fischer -1 /* not used */ ); 12558590a0fdSAndre Fischer } 12568590a0fdSAndre Fischer } 12578590a0fdSAndre Fischer 12588590a0fdSAndre Fischer /* 12598590a0fdSAndre Fischer // ------------------------------------------------------------------- 12608590a0fdSAndre Fischer namespace { 12618590a0fdSAndre Fischer 12628590a0fdSAndre Fischer bool containsLocktoken( const uno::Sequence< ucb::Lock > & rLocks, 12638590a0fdSAndre Fischer const char * token ) 12648590a0fdSAndre Fischer { 12658590a0fdSAndre Fischer for ( sal_Int32 n = 0; n < rLocks.getLength(); ++n ) 12668590a0fdSAndre Fischer { 12678590a0fdSAndre Fischer const uno::Sequence< rtl::OUString > & rTokens 12688590a0fdSAndre Fischer = rLocks[ n ].LockTokens; 12698590a0fdSAndre Fischer for ( sal_Int32 m = 0; m < rTokens.getLength(); ++m ) 12708590a0fdSAndre Fischer { 12718590a0fdSAndre Fischer if ( rTokens[ m ].equalsAscii( token ) ) 12728590a0fdSAndre Fischer return true; 12738590a0fdSAndre Fischer } 12748590a0fdSAndre Fischer } 12758590a0fdSAndre Fischer return false; 12768590a0fdSAndre Fischer } 12778590a0fdSAndre Fischer 12788590a0fdSAndre Fischer } // namespace 12798590a0fdSAndre Fischer */ 12808590a0fdSAndre Fischer 12818590a0fdSAndre Fischer // ------------------------------------------------------------------- 12828590a0fdSAndre Fischer bool SerfSession::removeExpiredLocktoken( const rtl::OUString & /*inURL*/, 12838590a0fdSAndre Fischer const DAVRequestEnvironment & /*rEnv*/ ) 12848590a0fdSAndre Fischer { 12858590a0fdSAndre Fischer return true; 12868590a0fdSAndre Fischer /* 12878590a0fdSAndre Fischer SerfLock * theLock = m_aSerfLockStore.findByUri( inURL ); 12888590a0fdSAndre Fischer if ( !theLock ) 12898590a0fdSAndre Fischer return false; 12908590a0fdSAndre Fischer 12918590a0fdSAndre Fischer // do a lockdiscovery to check whether this lock is still valid. 12928590a0fdSAndre Fischer try 12938590a0fdSAndre Fischer { 12948590a0fdSAndre Fischer // @@@ Alternative: use ne_lock_discover() => less overhead 12958590a0fdSAndre Fischer 12968590a0fdSAndre Fischer std::vector< DAVResource > aResources; 12978590a0fdSAndre Fischer std::vector< rtl::OUString > aPropNames; 12988590a0fdSAndre Fischer aPropNames.push_back( DAVProperties::LOCKDISCOVERY ); 12998590a0fdSAndre Fischer 13008590a0fdSAndre Fischer PROPFIND( rEnv.m_aRequestURI, DAVZERO, aPropNames, aResources, rEnv ); 13018590a0fdSAndre Fischer 13028590a0fdSAndre Fischer if ( aResources.size() == 0 ) 13038590a0fdSAndre Fischer return false; 13048590a0fdSAndre Fischer 13058590a0fdSAndre Fischer std::vector< DAVPropertyValue >::const_iterator it 13068590a0fdSAndre Fischer = aResources[ 0 ].properties.begin(); 13078590a0fdSAndre Fischer std::vector< DAVPropertyValue >::const_iterator end 13088590a0fdSAndre Fischer = aResources[ 0 ].properties.end(); 13098590a0fdSAndre Fischer 13108590a0fdSAndre Fischer while ( it != end ) 13118590a0fdSAndre Fischer { 13128590a0fdSAndre Fischer if ( (*it).Name.equals( DAVProperties::LOCKDISCOVERY ) ) 13138590a0fdSAndre Fischer { 13148590a0fdSAndre Fischer uno::Sequence< ucb::Lock > aLocks; 13158590a0fdSAndre Fischer if ( !( (*it).Value >>= aLocks ) ) 13168590a0fdSAndre Fischer return false; 13178590a0fdSAndre Fischer 13188590a0fdSAndre Fischer if ( !containsLocktoken( aLocks, theLock->token ) ) 13198590a0fdSAndre Fischer { 13208590a0fdSAndre Fischer // expired! 13218590a0fdSAndre Fischer break; 13228590a0fdSAndre Fischer } 13238590a0fdSAndre Fischer 13248590a0fdSAndre Fischer // still valid. 13258590a0fdSAndre Fischer return false; 13268590a0fdSAndre Fischer } 13278590a0fdSAndre Fischer ++it; 13288590a0fdSAndre Fischer } 13298590a0fdSAndre Fischer 13308590a0fdSAndre Fischer // No lockdiscovery prop in propfind result / locktoken not found 13318590a0fdSAndre Fischer // in propfind result -> not locked 13328590a0fdSAndre Fischer OSL_TRACE( "SerfSession::removeExpiredLocktoken: Removing " 13338590a0fdSAndre Fischer " expired lock token for %s. token: %s", 13348590a0fdSAndre Fischer rtl::OUStringToOString( inURL, 13358590a0fdSAndre Fischer RTL_TEXTENCODING_UTF8 ).getStr(), 13368590a0fdSAndre Fischer theLock->token ); 13378590a0fdSAndre Fischer 13388590a0fdSAndre Fischer m_aSerfLockStore.removeLock( theLock ); 13398590a0fdSAndre Fischer ne_lock_destroy( theLock ); 13408590a0fdSAndre Fischer return true; 13418590a0fdSAndre Fischer } 13428590a0fdSAndre Fischer catch ( DAVException const & ) 13438590a0fdSAndre Fischer { 13448590a0fdSAndre Fischer } 13458590a0fdSAndre Fischer return false; 13468590a0fdSAndre Fischer */ 13478590a0fdSAndre Fischer } 13488590a0fdSAndre Fischer 13498590a0fdSAndre Fischer // ------------------------------------------------------------------- 13508590a0fdSAndre Fischer // HandleError 13518590a0fdSAndre Fischer // Common Error Handler 13528590a0fdSAndre Fischer // ------------------------------------------------------------------- 135349989859SOliver-Rainer Wittmann void SerfSession::HandleError( boost::shared_ptr<SerfRequestProcessor> rReqProc ) 13548590a0fdSAndre Fischer throw ( DAVException ) 13558590a0fdSAndre Fischer { 13568590a0fdSAndre Fischer m_aEnv = DAVRequestEnvironment(); 13578590a0fdSAndre Fischer 135849989859SOliver-Rainer Wittmann if ( rReqProc->mpDAVException ) 13598590a0fdSAndre Fischer { 136049989859SOliver-Rainer Wittmann DAVException* mpDAVExp( rReqProc->mpDAVException ); 13618590a0fdSAndre Fischer 13628590a0fdSAndre Fischer serf_connection_reset( getSerfConnection() ); 13638590a0fdSAndre Fischer 136449989859SOliver-Rainer Wittmann if ( mpDAVExp->getStatus() == 413 && 136549989859SOliver-Rainer Wittmann m_bNoOfTransferEncodingSwitches < 2 ) 136649989859SOliver-Rainer Wittmann { 136749989859SOliver-Rainer Wittmann m_bUseChunkedEncoding = !m_bUseChunkedEncoding; 136849989859SOliver-Rainer Wittmann ++m_bNoOfTransferEncodingSwitches; 136949989859SOliver-Rainer Wittmann } 137049989859SOliver-Rainer Wittmann 13718590a0fdSAndre Fischer throw DAVException( mpDAVExp->getError(), 13728590a0fdSAndre Fischer mpDAVExp->getData(), 13738590a0fdSAndre Fischer mpDAVExp->getStatus() ); 13748590a0fdSAndre Fischer } 13758590a0fdSAndre Fischer 13768590a0fdSAndre Fischer /* 13778590a0fdSAndre Fischer // Map error code to DAVException. 13788590a0fdSAndre Fischer switch ( nError ) 13798590a0fdSAndre Fischer { 13808590a0fdSAndre Fischer case NE_OK: 13818590a0fdSAndre Fischer return; 13828590a0fdSAndre Fischer 13838590a0fdSAndre Fischer case NE_ERROR: // Generic error 13848590a0fdSAndre Fischer { 13858590a0fdSAndre Fischer rtl::OUString aText = rtl::OUString::createFromAscii( 13868590a0fdSAndre Fischer ne_get_error( m_pHttpSession ) ); 13878590a0fdSAndre Fischer 13888590a0fdSAndre Fischer sal_uInt16 code = makeStatusCode( aText ); 13898590a0fdSAndre Fischer 13908590a0fdSAndre Fischer if ( code == SC_LOCKED ) 13918590a0fdSAndre Fischer { 13928590a0fdSAndre Fischer if ( m_aSerfLockStore.findByUri( 13938590a0fdSAndre Fischer makeAbsoluteURL( inPath ) ) == 0 ) 13948590a0fdSAndre Fischer { 13958590a0fdSAndre Fischer // locked by 3rd party 13968590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCKED ); 13978590a0fdSAndre Fischer } 13988590a0fdSAndre Fischer else 13998590a0fdSAndre Fischer { 14008590a0fdSAndre Fischer // locked by ourself 14018590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCKED_SELF ); 14028590a0fdSAndre Fischer } 14038590a0fdSAndre Fischer } 14048590a0fdSAndre Fischer 14058590a0fdSAndre Fischer // Special handling for 400 and 412 status codes, which may indicate 14068590a0fdSAndre Fischer // that a lock previously obtained by us has been released meanwhile 14078590a0fdSAndre Fischer // by the server. Unfortunately, RFC is not clear at this point, 14088590a0fdSAndre Fischer // thus server implementations behave different... 14098590a0fdSAndre Fischer else if ( code == SC_BAD_REQUEST || code == SC_PRECONDITION_FAILED ) 14108590a0fdSAndre Fischer { 14118590a0fdSAndre Fischer if ( removeExpiredLocktoken( makeAbsoluteURL( inPath ), rEnv ) ) 14128590a0fdSAndre Fischer throw DAVException( DAVException::DAV_LOCK_EXPIRED ); 14138590a0fdSAndre Fischer } 14148590a0fdSAndre Fischer 14158590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, aText, code ); 14168590a0fdSAndre Fischer } 14178590a0fdSAndre Fischer case NE_LOOKUP: // Name lookup failed. 14188590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_LOOKUP, 14198590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14208590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14218590a0fdSAndre Fischer 14228590a0fdSAndre Fischer case NE_AUTH: // User authentication failed on server 14238590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_AUTH, 14248590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14258590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14268590a0fdSAndre Fischer 14278590a0fdSAndre Fischer case NE_PROXYAUTH: // User authentication failed on proxy 14288590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_AUTHPROXY, 14298590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14308590a0fdSAndre Fischer m_aProxyName, m_nProxyPort ) ); 14318590a0fdSAndre Fischer 14328590a0fdSAndre Fischer case NE_CONNECT: // Could not connect to server 14338590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_CONNECT, 14348590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14358590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14368590a0fdSAndre Fischer 14378590a0fdSAndre Fischer case NE_TIMEOUT: // Connection timed out 14388590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_TIMEOUT, 14398590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14408590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14418590a0fdSAndre Fischer 14428590a0fdSAndre Fischer case NE_FAILED: // The precondition failed 14438590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_FAILED, 14448590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14458590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14468590a0fdSAndre Fischer 14478590a0fdSAndre Fischer case NE_RETRY: // Retry request (ne_end_request ONLY) 14488590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_RETRY, 14498590a0fdSAndre Fischer SerfUri::makeConnectionEndPointString( 14508590a0fdSAndre Fischer m_aHostName, m_nPort ) ); 14518590a0fdSAndre Fischer 14528590a0fdSAndre Fischer case NE_REDIRECT: 14538590a0fdSAndre Fischer { 14548590a0fdSAndre Fischer SerfUri aUri( ne_redirect_location( m_pHttpSession ) ); 14558590a0fdSAndre Fischer throw DAVException( 14568590a0fdSAndre Fischer DAVException::DAV_HTTP_REDIRECT, aUri.GetURI() ); 14578590a0fdSAndre Fischer } 14588590a0fdSAndre Fischer default: 14598590a0fdSAndre Fischer { 14608590a0fdSAndre Fischer OSL_TRACE( "SerfSession::HandleError : Unknown Serf error code!" ); 14618590a0fdSAndre Fischer throw DAVException( DAVException::DAV_HTTP_ERROR, 14628590a0fdSAndre Fischer rtl::OUString::createFromAscii( 14638590a0fdSAndre Fischer ne_get_error( m_pHttpSession ) ) ); 14648590a0fdSAndre Fischer } 14658590a0fdSAndre Fischer } 14668590a0fdSAndre Fischer */ 14678590a0fdSAndre Fischer } 14688590a0fdSAndre Fischer 14698590a0fdSAndre Fischer // ------------------------------------------------------------------- 14708590a0fdSAndre Fischer // static 14718590a0fdSAndre Fischer bool 14728590a0fdSAndre Fischer SerfSession::getDataFromInputStream( 14738590a0fdSAndre Fischer const uno::Reference< io::XInputStream > & xStream, 14748590a0fdSAndre Fischer uno::Sequence< sal_Int8 > & rData, 14758590a0fdSAndre Fischer bool bAppendTrailingZeroByte ) 14768590a0fdSAndre Fischer { 14778590a0fdSAndre Fischer if ( xStream.is() ) 14788590a0fdSAndre Fischer { 14798590a0fdSAndre Fischer uno::Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY ); 14808590a0fdSAndre Fischer if ( xSeekable.is() ) 14818590a0fdSAndre Fischer { 14828590a0fdSAndre Fischer try 14838590a0fdSAndre Fischer { 14848590a0fdSAndre Fischer sal_Int32 nSize 14858590a0fdSAndre Fischer = sal::static_int_cast<sal_Int32>(xSeekable->getLength()); 14868590a0fdSAndre Fischer sal_Int32 nRead 14878590a0fdSAndre Fischer = xStream->readBytes( rData, nSize ); 14888590a0fdSAndre Fischer 14898590a0fdSAndre Fischer if ( nRead == nSize ) 14908590a0fdSAndre Fischer { 14918590a0fdSAndre Fischer if ( bAppendTrailingZeroByte ) 14928590a0fdSAndre Fischer { 14938590a0fdSAndre Fischer rData.realloc( nSize + 1 ); 14948590a0fdSAndre Fischer rData[ nSize ] = sal_Int8( 0 ); 14958590a0fdSAndre Fischer } 14968590a0fdSAndre Fischer return true; 14978590a0fdSAndre Fischer } 14988590a0fdSAndre Fischer } 14998590a0fdSAndre Fischer catch ( io::NotConnectedException const & ) 15008590a0fdSAndre Fischer { 15018590a0fdSAndre Fischer // readBytes 15028590a0fdSAndre Fischer } 15038590a0fdSAndre Fischer catch ( io::BufferSizeExceededException const & ) 15048590a0fdSAndre Fischer { 15058590a0fdSAndre Fischer // readBytes 15068590a0fdSAndre Fischer } 15078590a0fdSAndre Fischer catch ( io::IOException const & ) 15088590a0fdSAndre Fischer { 15098590a0fdSAndre Fischer // getLength, readBytes 15108590a0fdSAndre Fischer } 15118590a0fdSAndre Fischer } 15128590a0fdSAndre Fischer else 15138590a0fdSAndre Fischer { 15148590a0fdSAndre Fischer try 15158590a0fdSAndre Fischer { 15168590a0fdSAndre Fischer uno::Sequence< sal_Int8 > aBuffer; 15178590a0fdSAndre Fischer sal_Int32 nPos = 0; 15188590a0fdSAndre Fischer 15198590a0fdSAndre Fischer sal_Int32 nRead = xStream->readSomeBytes( aBuffer, 65536 ); 15208590a0fdSAndre Fischer while ( nRead > 0 ) 15218590a0fdSAndre Fischer { 15228590a0fdSAndre Fischer if ( rData.getLength() < ( nPos + nRead ) ) 15238590a0fdSAndre Fischer rData.realloc( nPos + nRead ); 15248590a0fdSAndre Fischer 15258590a0fdSAndre Fischer aBuffer.realloc( nRead ); 15268590a0fdSAndre Fischer rtl_copyMemory( (void*)( rData.getArray() + nPos ), 15278590a0fdSAndre Fischer (const void*)aBuffer.getConstArray(), 15288590a0fdSAndre Fischer nRead ); 15298590a0fdSAndre Fischer nPos += nRead; 15308590a0fdSAndre Fischer 15318590a0fdSAndre Fischer aBuffer.realloc( 0 ); 15328590a0fdSAndre Fischer nRead = xStream->readSomeBytes( aBuffer, 65536 ); 15338590a0fdSAndre Fischer } 15348590a0fdSAndre Fischer 15358590a0fdSAndre Fischer if ( bAppendTrailingZeroByte ) 15368590a0fdSAndre Fischer { 15378590a0fdSAndre Fischer rData.realloc( nPos + 1 ); 15388590a0fdSAndre Fischer rData[ nPos ] = sal_Int8( 0 ); 15398590a0fdSAndre Fischer } 15408590a0fdSAndre Fischer return true; 15418590a0fdSAndre Fischer } 15428590a0fdSAndre Fischer catch ( io::NotConnectedException const & ) 15438590a0fdSAndre Fischer { 15448590a0fdSAndre Fischer // readBytes 15458590a0fdSAndre Fischer } 15468590a0fdSAndre Fischer catch ( io::BufferSizeExceededException const & ) 15478590a0fdSAndre Fischer { 15488590a0fdSAndre Fischer // readBytes 15498590a0fdSAndre Fischer } 15508590a0fdSAndre Fischer catch ( io::IOException const & ) 15518590a0fdSAndre Fischer { 15528590a0fdSAndre Fischer // readBytes 15538590a0fdSAndre Fischer } 15548590a0fdSAndre Fischer } 15558590a0fdSAndre Fischer } 15568590a0fdSAndre Fischer return false; 15578590a0fdSAndre Fischer } 15588590a0fdSAndre Fischer 15598590a0fdSAndre Fischer // --------------------------------------------------------------------- 15608590a0fdSAndre Fischer sal_Bool 15618590a0fdSAndre Fischer SerfSession::isDomainMatch( rtl::OUString certHostName ) 15628590a0fdSAndre Fischer { 15638590a0fdSAndre Fischer rtl::OUString hostName = getHostName(); 15648590a0fdSAndre Fischer 15658590a0fdSAndre Fischer if (hostName.equalsIgnoreAsciiCase( certHostName ) ) 15668590a0fdSAndre Fischer return sal_True; 15678590a0fdSAndre Fischer 15688590a0fdSAndre Fischer if ( 0 == certHostName.indexOf( rtl::OUString::createFromAscii( "*" ) ) && 15698590a0fdSAndre Fischer hostName.getLength() >= certHostName.getLength() ) 15708590a0fdSAndre Fischer { 15718590a0fdSAndre Fischer rtl::OUString cmpStr = certHostName.copy( 1 ); 15728590a0fdSAndre Fischer 15738590a0fdSAndre Fischer if ( hostName.matchIgnoreAsciiCase( 15748590a0fdSAndre Fischer cmpStr, hostName.getLength() - cmpStr.getLength() ) ) 15758590a0fdSAndre Fischer return sal_True; 15768590a0fdSAndre Fischer } 15778590a0fdSAndre Fischer return sal_False; 15788590a0fdSAndre Fischer } 15798590a0fdSAndre Fischer 15808590a0fdSAndre Fischer /* 15818590a0fdSAndre Fischer // --------------------------------------------------------------------- 15828590a0fdSAndre Fischer rtl::OUString SerfSession::makeAbsoluteURL( rtl::OUString const & rURL ) const 15838590a0fdSAndre Fischer { 15848590a0fdSAndre Fischer try 15858590a0fdSAndre Fischer { 15868590a0fdSAndre Fischer // Is URL relative or already absolute? 15878590a0fdSAndre Fischer if ( rURL[ 0 ] != sal_Unicode( '/' ) ) 15888590a0fdSAndre Fischer { 15898590a0fdSAndre Fischer // absolute. 15908590a0fdSAndre Fischer return rtl::OUString( rURL ); 15918590a0fdSAndre Fischer } 15928590a0fdSAndre Fischer else 15938590a0fdSAndre Fischer { 15948590a0fdSAndre Fischer ne_uri aUri; 15958590a0fdSAndre Fischer memset( &aUri, 0, sizeof( aUri ) ); 15968590a0fdSAndre Fischer 15978590a0fdSAndre Fischer ne_fill_server_uri( m_pHttpSession, &aUri ); 15988590a0fdSAndre Fischer aUri.path 15998590a0fdSAndre Fischer = ne_strdup( rtl::OUStringToOString( 16008590a0fdSAndre Fischer rURL, RTL_TEXTENCODING_UTF8 ).getStr() ); 16018590a0fdSAndre Fischer SerfUri aSerfUri( &aUri ); 16028590a0fdSAndre Fischer ne_uri_free( &aUri ); 16038590a0fdSAndre Fischer return aSerfUri.GetURI(); 16048590a0fdSAndre Fischer } 16058590a0fdSAndre Fischer } 16068590a0fdSAndre Fischer catch ( DAVException const & ) 16078590a0fdSAndre Fischer { 16088590a0fdSAndre Fischer } 16098590a0fdSAndre Fischer // error. 16108590a0fdSAndre Fischer return rtl::OUString(); 16118590a0fdSAndre Fischer } 16128590a0fdSAndre Fischer */ 1613