fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / ftp / ftpcontentprovider.cxx
bloba31a4b29b82afed5bfa9900898973316a4b82589
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 *************************************************************************/
27 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <osl/socket.hxx>
30 #include "ftpcontentprovider.hxx"
31 #include "ftpcontent.hxx"
32 #include "ftploaderthread.hxx"
34 using namespace ftp;
35 using namespace com::sun::star::lang;
36 using namespace com::sun::star::container;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::ucb;
39 using namespace com::sun::star::beans;
41 // ContentProvider Implementation.
43 FTPContentProvider::FTPContentProvider( const Reference< XComponentContext >& rxContext)
44 : ::ucbhelper::ContentProviderImplHelper(rxContext)
45 , m_ftpLoaderThread(0)
46 , m_pProxyDecider(0)
51 // virtual
52 FTPContentProvider::~FTPContentProvider()
54 delete m_ftpLoaderThread;
55 delete m_pProxyDecider;
58 // XInterface methods.
59 void SAL_CALL FTPContentProvider::acquire()
60 throw()
62 OWeakObject::acquire();
65 void SAL_CALL FTPContentProvider::release()
66 throw()
68 OWeakObject::release();
71 css::uno::Any SAL_CALL FTPContentProvider::queryInterface( const css::uno::Type & rType )
72 throw( css::uno::RuntimeException, std::exception )
74 css::uno::Any aRet = cppu::queryInterface( rType,
75 (static_cast< XTypeProvider* >(this)),
76 (static_cast< XServiceInfo* >(this)),
77 (static_cast< XContentProvider* >(this))
79 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
82 // XTypeProvider methods.
83 css::uno::Sequence< sal_Int8 > SAL_CALL FTPContentProvider::getImplementationId()
84 throw( css::uno::RuntimeException,
85 std::exception )
87 return css::uno::Sequence<sal_Int8>();
90 css::uno::Sequence< css::uno::Type > SAL_CALL FTPContentProvider::getTypes()
91 throw( css::uno::RuntimeException,
92 std::exception )
94 static cppu::OTypeCollection* pCollection = NULL;
95 if ( !pCollection )
97 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
98 if ( !pCollection )
100 static cppu::OTypeCollection collection(
101 cppu::UnoType<XTypeProvider>::get(),
102 cppu::UnoType<XServiceInfo>::get(),
103 cppu::UnoType<XContentProvider>::get()
105 pCollection = &collection;
108 return (*pCollection).getTypes();
113 // XServiceInfo methods.
115 OUString SAL_CALL FTPContentProvider::getImplementationName()
116 throw( css::uno::RuntimeException, std::exception )
118 return getImplementationName_Static();
121 OUString FTPContentProvider::getImplementationName_Static()
123 return OUString("com.sun.star.comp.FTPContentProvider");
126 sal_Bool SAL_CALL FTPContentProvider::supportsService( const OUString& ServiceName )
127 throw( css::uno::RuntimeException, std::exception )
129 return cppu::supportsService( this, ServiceName );
132 css::uno::Sequence< OUString > SAL_CALL FTPContentProvider::getSupportedServiceNames()
133 throw( css::uno::RuntimeException, std::exception )
135 return getSupportedServiceNames_Static();
138 static css::uno::Reference< css::uno::XInterface > SAL_CALL
139 FTPContentProvider_CreateInstance( const css::uno::Reference<
140 css::lang::XMultiServiceFactory> & rSMgr )
141 throw( css::uno::Exception )
143 css::lang::XServiceInfo* pX = (css::lang::XServiceInfo*)
144 new FTPContentProvider( ucbhelper::getComponentContext(rSMgr) );
145 return css::uno::Reference< css::uno::XInterface >::query( pX );
148 css::uno::Sequence< OUString > FTPContentProvider::getSupportedServiceNames_Static()
150 css::uno::Sequence< OUString > aSNS( 1 );
151 aSNS.getArray()[ 0 ] = FTP_CONTENT_PROVIDER_SERVICE_NAME;
152 return aSNS;
155 // Service factory implementation.
157 css::uno::Reference< css::lang::XSingleServiceFactory >
158 FTPContentProvider::createServiceFactory( const css::uno::Reference<
159 css::lang::XMultiServiceFactory >& rxServiceMgr )
161 return css::uno::Reference<
162 css::lang::XSingleServiceFactory >(
163 cppu::createOneInstanceFactory(
164 rxServiceMgr,
165 FTPContentProvider::getImplementationName_Static(),
166 FTPContentProvider_CreateInstance,
167 FTPContentProvider::getSupportedServiceNames_Static() ) );
170 // XContentProvider methods.
172 // virtual
173 Reference<XContent> SAL_CALL FTPContentProvider::queryContent(
174 const Reference< XContentIdentifier >& xCanonicId)
175 throw( IllegalIdentifierException,
176 RuntimeException,
177 std::exception)
179 // Check, if a content with given id already exists...
180 Reference<XContent> xContent = queryExistingContent(xCanonicId).get();
181 if(xContent.is())
182 return xContent;
184 // A new content has to be returned:
186 // Initialize
187 osl::MutexGuard aGuard( m_aMutex );
188 if(!m_ftpLoaderThread || !m_pProxyDecider)
190 try {
191 init();
192 } catch( ... ) {
193 throw RuntimeException();
196 if(!m_ftpLoaderThread || !m_pProxyDecider)
197 throw RuntimeException();
201 try {
202 FTPURL aURL(xCanonicId->getContentIdentifier(),
203 this);
205 if(!m_pProxyDecider->shouldUseProxy(
206 OUString("ftp"),
207 aURL.host(),
208 aURL.port().toInt32()))
210 xContent = new FTPContent( m_xContext, this,xCanonicId,aURL);
211 registerNewContent(xContent);
213 else {
214 Reference<XContentProvider>
215 xProvider(getHttpProvider());
216 if(xProvider.is())
217 return xProvider->queryContent(xCanonicId);
218 else
219 throw RuntimeException();
221 } catch(const malformed_exception&) {
222 throw IllegalIdentifierException();
225 // may throw IllegalIdentifierException
226 return xContent;
229 void FTPContentProvider::init()
231 m_ftpLoaderThread = new FTPLoaderThread();
232 m_pProxyDecider = new ucbhelper::InternetProxyDecider( m_xContext );
235 CURL* FTPContentProvider::handle()
237 // Cannot be zero if called from here;
238 return m_ftpLoaderThread->handle();
242 bool FTPContentProvider::forHost( const OUString& host,
243 const OUString& port,
244 const OUString& username,
245 OUString& password,
246 OUString& account)
248 osl::MutexGuard aGuard(m_aMutex);
249 for(unsigned int i = 0; i < m_ServerInfo.size(); ++i)
250 if(host == m_ServerInfo[i].host &&
251 port == m_ServerInfo[i].port &&
252 username == m_ServerInfo[i].username )
254 password = m_ServerInfo[i].password;
255 account = m_ServerInfo[i].account;
256 return true;
259 return false;
262 bool FTPContentProvider::setHost( const OUString& host,
263 const OUString& port,
264 const OUString& username,
265 const OUString& password,
266 const OUString& account)
268 ServerInfo inf;
269 inf.host = host;
270 inf.port = port;
271 inf.username = username;
272 inf.password = password;
273 inf.account = account;
275 bool present(false);
276 osl::MutexGuard aGuard(m_aMutex);
277 for(unsigned int i = 0; i < m_ServerInfo.size(); ++i)
278 if(host == m_ServerInfo[i].host &&
279 port == m_ServerInfo[i].port &&
280 username == m_ServerInfo[i].username)
282 present = true;
283 m_ServerInfo[i].password = password;
284 m_ServerInfo[i].account = account;
287 if(!present)
288 m_ServerInfo.push_back(inf);
290 return !present;
295 Reference<XContentProvider> FTPContentProvider::getHttpProvider()
296 throw(RuntimeException)
298 // used for access to ftp-proxy
299 return UniversalContentBroker::create( m_xContext )->queryContentProvider("http:");
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */