1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "DAVSessionFactory.hxx"
21 #include "SerfSession.hxx"
22 #include "SerfUri.hxx"
23 #include <com/sun/star/uno/XComponentContext.hpp>
25 using namespace http_dav_ucp
;
26 using namespace com::sun::star
;
28 DAVSessionFactory::~DAVSessionFactory()
32 rtl::Reference
< DAVSession
> DAVSessionFactory::createDAVSession(
33 const OUString
& inUri
,
34 const uno::Reference
< uno::XComponentContext
> & rxContext
)
37 osl::MutexGuard
aGuard( m_aMutex
);
39 if ( !m_xProxyDecider
.get() )
40 m_xProxyDecider
.reset( new ucbhelper::InternetProxyDecider( rxContext
) );
42 Map::iterator
aIt( m_aMap
.begin() );
43 Map::iterator
aEnd( m_aMap
.end() );
47 if ( (*aIt
).second
->CanUse( inUri
) )
55 SerfUri
aURI( inUri
);
57 std::unique_ptr
< DAVSession
> xElement(
58 new SerfSession( this, inUri
, *m_xProxyDecider
.get() ) );
60 aIt
= m_aMap
.insert( Map::value_type( inUri
, xElement
.get() ) ).first
;
61 aIt
->second
->m_aContainerIt
= aIt
;
65 else if ( osl_incrementInterlockedCount( &aIt
->second
->m_nRefCount
) > 1 )
67 rtl::Reference
< DAVSession
> xElement( aIt
->second
);
68 osl_decrementInterlockedCount( &aIt
->second
->m_nRefCount
);
73 osl_decrementInterlockedCount( &aIt
->second
->m_nRefCount
);
74 aIt
->second
->m_aContainerIt
= m_aMap
.end();
76 // If URL scheme is different from http or https we definitely
77 // have to use a proxy and therefore can optimize the getProxy
79 SerfUri
aURI( inUri
);
81 aIt
->second
= new SerfSession( this, inUri
, *m_xProxyDecider
.get() );
82 aIt
->second
->m_aContainerIt
= aIt
;
87 void DAVSessionFactory::releaseElement( DAVSession
* pElement
)
90 osl::MutexGuard
aGuard( m_aMutex
);
91 if ( pElement
->m_aContainerIt
!= m_aMap
.end() )
92 m_aMap
.erase( pElement
->m_aContainerIt
);
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */