xref: /AOO41X/main/ucb/source/ucp/webdav/DAVSessionFactory.cxx (revision 59ddfc10bd384e83978dcd8c83c4a7ba8f8fdec1)
12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52f86921cSAndrew Rist  * distributed with this work for additional information
62f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist  * software distributed under the License is distributed on an
152f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
172f86921cSAndrew Rist  * specific language governing permissions and limitations
182f86921cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202f86921cSAndrew Rist  *************************************************************/
212f86921cSAndrew Rist 
222f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir #include "DAVSessionFactory.hxx"
27*59ddfc10SAndre Fischer #include "SerfSession.hxx"
28*59ddfc10SAndre Fischer #include "SerfUri.hxx"
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir 
31*59ddfc10SAndre Fischer using namespace http_dav_ucp;
32cdf0e10cSrcweir using namespace com::sun::star;
33cdf0e10cSrcweir 
~DAVSessionFactory()34cdf0e10cSrcweir DAVSessionFactory::~DAVSessionFactory()
35cdf0e10cSrcweir {
36cdf0e10cSrcweir }
37cdf0e10cSrcweir 
createDAVSession(const::rtl::OUString & inUri,const uno::Reference<lang::XMultiServiceFactory> & rxSMgr)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     {
63*59ddfc10SAndre Fischer         SerfUri aURI( inUri );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         std::auto_ptr< DAVSession > xElement(
66*59ddfc10SAndre Fischer             new SerfSession( 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:
87*59ddfc10SAndre Fischer         SerfUri aURI( inUri );
88cdf0e10cSrcweir 
89*59ddfc10SAndre Fischer         aIt->second = new SerfSession( this, inUri, *m_xProxyDecider.get() );
90cdf0e10cSrcweir         aIt->second->m_aContainerIt = aIt;
91cdf0e10cSrcweir         return aIt->second;
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
releaseElement(DAVSession * pElement)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