LibreOffice Module ucb (master)  1
DAVSessionFactory.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <memory>
21 #include "DAVSessionFactory.hxx"
22 #include "CurlSession.hxx"
23 #include "CurlUri.hxx"
24 
25 using namespace http_dav_ucp;
26 using namespace com::sun::star;
27 
29 {
30 }
31 
33  const OUString & inUri,
34  const uno::Sequence< beans::NamedValue >& rFlags,
35  const uno::Reference< uno::XComponentContext > & rxContext )
36 {
37  std::unique_lock aGuard( m_aMutex );
38 
39  if (!m_xProxyDecider)
40  m_xProxyDecider.reset( new ucbhelper::InternetProxyDecider( rxContext ) );
41 
42  Map::iterator aIt = std::find_if(m_aMap.begin(), m_aMap.end(),
43  [&inUri, &rFlags](const Map::value_type& rEntry) { return rEntry.second->CanUse( inUri, rFlags ); });
44 
45  if ( aIt == m_aMap.end() )
46  {
47  std::unique_ptr< DAVSession > xElement(
48  new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider) );
49 
50  aIt = m_aMap.emplace( inUri, xElement.get() ).first;
51  aIt->second->m_aContainerIt = aIt;
52  xElement.release();
53  return aIt->second;
54  }
55  else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )
56  {
57  rtl::Reference< DAVSession > xElement( aIt->second );
58  osl_atomic_decrement( &aIt->second->m_nRefCount );
59  return xElement;
60  }
61  else
62  {
63  osl_atomic_decrement( &aIt->second->m_nRefCount );
64  aIt->second->m_aContainerIt = m_aMap.end();
65 
66  aIt->second = new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider);
67  aIt->second->m_aContainerIt = aIt;
68  return aIt->second;
69  }
70 }
71 
73 {
74  assert( pElement );
75  std::unique_lock aGuard( m_aMutex );
76  if ( pElement->m_aContainerIt != m_aMap.end() )
77  m_aMap.erase( pElement->m_aContainerIt );
78 }
79 
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< DAVSession > createDAVSession(const OUString &inUri, const ::com::sun::star::uno::Sequence<::com::sun::star::beans::NamedValue > &rFlags, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
implementation of libcurl HTTP/DAV back-end
Definition: CurlSession.hxx:23
std::mutex m_aMutex
DAVSessionFactory::Map::iterator m_aContainerIt
Definition: DAVSession.hxx:187
void releaseElement(const DAVSession *pElement)
constexpr OUStringLiteral first