1*2f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2f86921cSAndrew Rist * distributed with this work for additional information 6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance 9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2f86921cSAndrew Rist * software distributed under the License is distributed on an 15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the 17*2f86921cSAndrew Rist * specific language governing permissions and limitations 18*2f86921cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2f86921cSAndrew Rist *************************************************************/ 21*2f86921cSAndrew Rist 22*2f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_ucb.hxx" 26cdf0e10cSrcweir #include "DAVSessionFactory.hxx" 27cdf0e10cSrcweir #include "NeonSession.hxx" 28cdf0e10cSrcweir #include "NeonUri.hxx" 29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace webdav_ucp; 32cdf0e10cSrcweir using namespace com::sun::star; 33cdf0e10cSrcweir 34cdf0e10cSrcweir DAVSessionFactory::~DAVSessionFactory() 35cdf0e10cSrcweir { 36cdf0e10cSrcweir } 37cdf0e10cSrcweir 38cdf0e10cSrcweir rtl::Reference< DAVSession > DAVSessionFactory::createDAVSession( 39cdf0e10cSrcweir const ::rtl::OUString & inUri, 40cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & rxSMgr ) 41cdf0e10cSrcweir throw( DAVException ) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir m_xMSF = rxSMgr; 44cdf0e10cSrcweir 45cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 46cdf0e10cSrcweir 47cdf0e10cSrcweir if ( !m_xProxyDecider.get() ) 48cdf0e10cSrcweir m_xProxyDecider.reset( new ucbhelper::InternetProxyDecider( rxSMgr ) ); 49cdf0e10cSrcweir 50cdf0e10cSrcweir Map::iterator aIt( m_aMap.begin() ); 51cdf0e10cSrcweir Map::iterator aEnd( m_aMap.end() ); 52cdf0e10cSrcweir 53cdf0e10cSrcweir while ( aIt != aEnd ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir if ( (*aIt).second->CanUse( inUri ) ) 56cdf0e10cSrcweir break; 57cdf0e10cSrcweir 58cdf0e10cSrcweir ++aIt; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir if ( aIt == aEnd ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir NeonUri aURI( inUri ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir std::auto_ptr< DAVSession > xElement( 66cdf0e10cSrcweir new NeonSession( this, inUri, *m_xProxyDecider.get() ) ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir aIt = m_aMap.insert( Map::value_type( inUri, xElement.get() ) ).first; 69cdf0e10cSrcweir aIt->second->m_aContainerIt = aIt; 70cdf0e10cSrcweir xElement.release(); 71cdf0e10cSrcweir return aIt->second; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir else if ( osl_incrementInterlockedCount( &aIt->second->m_nRefCount ) > 1 ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir rtl::Reference< DAVSession > xElement( aIt->second ); 76cdf0e10cSrcweir osl_decrementInterlockedCount( &aIt->second->m_nRefCount ); 77cdf0e10cSrcweir return xElement; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir else 80cdf0e10cSrcweir { 81cdf0e10cSrcweir osl_decrementInterlockedCount( &aIt->second->m_nRefCount ); 82cdf0e10cSrcweir aIt->second->m_aContainerIt = m_aMap.end(); 83cdf0e10cSrcweir 84cdf0e10cSrcweir // If URL scheme is different from http or https we definitely 85cdf0e10cSrcweir // have to use a proxy and therefore can optimize the getProxy 86cdf0e10cSrcweir // call a little: 87cdf0e10cSrcweir NeonUri aURI( inUri ); 88cdf0e10cSrcweir 89cdf0e10cSrcweir aIt->second = new NeonSession( this, inUri, *m_xProxyDecider.get() ); 90cdf0e10cSrcweir aIt->second->m_aContainerIt = aIt; 91cdf0e10cSrcweir return aIt->second; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir void DAVSessionFactory::releaseElement( DAVSession * pElement ) SAL_THROW(()) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir OSL_ASSERT( pElement ); 98cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 99cdf0e10cSrcweir if ( pElement->m_aContainerIt != m_aMap.end() ) 100cdf0e10cSrcweir m_aMap.erase( pElement->m_aContainerIt ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103