LibreOffice Module ucb (master) 1
ftpcontentprovider.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 <sal/config.h>
21
22#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
23#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
24#include <com/sun/star/ucb/UniversalContentBroker.hpp>
29#include <cppuhelper/weak.hxx>
31#include "ftpcontent.hxx"
32#include "ftploaderthread.hxx"
33
34using namespace ftp;
35using namespace com::sun::star::lang;
36using namespace com::sun::star::container;
37using namespace com::sun::star::uno;
38using namespace com::sun::star::ucb;
39using namespace com::sun::star::beans;
40
41// ContentProvider Implementation.
42
43FTPContentProvider::FTPContentProvider( const Reference< XComponentContext >& rxContext)
44 : ::ucbhelper::ContentProviderImplHelper(rxContext)
45{
46}
47
48
49// virtual
51{
52 m_ftpLoaderThread.reset();
53 m_pProxyDecider.reset();
54}
55
56// XInterface methods.
58 noexcept
59{
60 OWeakObject::acquire();
61}
62
64 noexcept
65{
66 OWeakObject::release();
67}
68
69css::uno::Any SAL_CALL FTPContentProvider::queryInterface( const css::uno::Type & rType )
70{
71 css::uno::Any aRet = cppu::queryInterface( rType,
72 static_cast< XTypeProvider* >(this),
73 static_cast< XServiceInfo* >(this),
74 static_cast< XContentProvider* >(this)
75 );
76 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
77}
78
79// XTypeProvider methods.
80css::uno::Sequence< sal_Int8 > SAL_CALL FTPContentProvider::getImplementationId()
81{
82 return css::uno::Sequence<sal_Int8>();
83}
84
85css::uno::Sequence< css::uno::Type > SAL_CALL FTPContentProvider::getTypes()
86{
87 static cppu::OTypeCollection s_aCollection(
91 );
92
93 return s_aCollection.getTypes();
94}
95
96
97// XServiceInfo methods.
98
100{
101 return "com.sun.star.comp.FTPContentProvider";
102}
103
104sal_Bool SAL_CALL FTPContentProvider::supportsService( const OUString& ServiceName )
105{
106 return cppu::supportsService( this, ServiceName );
107}
108
109css::uno::Sequence< OUString > SAL_CALL FTPContentProvider::getSupportedServiceNames()
110{
112}
113
114
115
116// XContentProvider methods.
117
118// virtual
120 const Reference< XContentIdentifier >& xCanonicId)
121{
122 // Check, if a content with given id already exists...
124 if(xContent.is())
125 return xContent;
126
127 // A new content has to be returned:
128 {
129 // Initialize
130 osl::MutexGuard aGuard( m_aMutex );
132 {
133 try {
134 init();
135 } catch (css::uno::Exception const & ex) {
136 css::uno::Any anyEx = cppu::getCaughtException();
137 throw css::lang::WrappedTargetRuntimeException( ex.Message,
138 css::uno::Reference< css::uno::XInterface >(),
139 anyEx );
140 } catch( ... ) {
141 throw RuntimeException();
142 }
143
145 throw RuntimeException();
146 }
147 }
148
149 try {
150 FTPURL aURL(xCanonicId->getContentIdentifier(),
151 this);
152
153 if(!m_pProxyDecider->shouldUseProxy(
154 "ftp",
155 aURL.host(),
156 aURL.port().toInt32()))
157 {
158 xContent = new FTPContent( m_xContext, this,xCanonicId,aURL);
160 }
161 else {
162 Reference<XContentProvider> xProvider(UniversalContentBroker::create( m_xContext )->queryContentProvider("http:"));
163 if(!xProvider.is())
164 throw RuntimeException();
165 return xProvider->queryContent(xCanonicId);
166 }
167 } catch(const malformed_exception&) {
168 throw IllegalIdentifierException();
169 }
170
171 // may throw IllegalIdentifierException
172 return xContent;
173}
174
176{
177 m_ftpLoaderThread.reset( new FTPLoaderThread() );
179}
180
182{
183 // Cannot be zero if called from here;
184 return m_ftpLoaderThread->handle();
185}
186
187
188void FTPContentProvider::forHost( std::u16string_view host,
189 std::u16string_view port,
190 std::u16string_view username,
191 OUString& password,
192 OUString& account)
193{
194 osl::MutexGuard aGuard(m_aMutex);
195 for(const ServerInfo & i : m_ServerInfo)
196 if(host == i.host &&
197 port == i.port &&
198 username == i.username )
199 {
200 password = i.password;
201 account = i.account;
202 return;
203 }
204}
205
206bool FTPContentProvider::setHost( const OUString& host,
207 const OUString& port,
208 const OUString& username,
209 const OUString& password,
210 const OUString& account)
211{
212 ServerInfo inf;
213 inf.host = host;
214 inf.port = port;
215 inf.username = username;
216 inf.password = password;
217 inf.account = account;
218
219 bool present(false);
220 osl::MutexGuard aGuard(m_aMutex);
221 for(ServerInfo & i : m_ServerInfo)
222 if(host == i.host &&
223 port == i.port &&
224 username == i.username)
225 {
226 present = true;
227 i.password = password;
228 i.account = account;
229 }
230
231 if(!present)
232 m_ServerInfo.push_back(inf);
233
234 return !present;
235}
236
237extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
239 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
240{
241 return cppu::acquire(new FTPContentProvider(context));
242}
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
void forHost(std::u16string_view host, std::u16string_view port, std::u16string_view username, OUString &password, OUString &account)
host is in the form host:port.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual ~FTPContentProvider() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool setHost(const OUString &host, const OUString &port, const OUString &username, const OUString &password, const OUString &account)
std::unique_ptr< FTPLoaderThread > m_ftpLoaderThread
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
std::vector< ServerInfo > m_ServerInfo
virtual OUString SAL_CALL getImplementationName() override
std::unique_ptr< ucbhelper::InternetProxyDecider > m_pProxyDecider
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL release() noexcept override
A loaderthread acts as factory for CURL-handles, the key being ( implicit ) the threadid.
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
css::uno::Reference< css::uno::XComponentContext > m_xContext
URL aURL
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_ftp_FTPContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral FTP_CONTENT_PROVIDER_SERVICE_NAME
::rtl::Reference< OContentHelper > xContent
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
Definition of ftpcontentprovider.
int i
unsigned char sal_Bool