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 .
21 /**************************************************************************
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"
36 using namespace com::sun::star::lang
;
37 using namespace com::sun::star::container
;
38 using namespace com::sun::star::uno
;
39 using namespace com::sun::star::ucb
;
40 using namespace com::sun::star::beans
;
44 //=========================================================================
45 //=========================================================================
47 // ContentProvider Implementation.
49 //=========================================================================
50 //=========================================================================
52 FTPContentProvider::FTPContentProvider(
53 const Reference
< XComponentContext
>& rxContext
)
54 : ::ucbhelper::ContentProviderImplHelper(rxContext
),
60 //=========================================================================
62 FTPContentProvider::~FTPContentProvider()
64 delete m_ftpLoaderThread
;
65 delete m_pProxyDecider
;
68 //=========================================================================
70 // XInterface methods.
72 //=========================================================================
74 XINTERFACE_IMPL_3(FTPContentProvider
,
79 //=========================================================================
81 // XTypeProvider methods.
83 //=========================================================================
85 XTYPEPROVIDER_IMPL_3(FTPContentProvider
,
90 //=========================================================================
92 // XServiceInfo methods.
94 //=========================================================================
96 XSERVICEINFO_IMPL_1_CTX(
98 rtl::OUString("com.sun.star.comp.FTPContentProvider"),
99 rtl::OUString(FTP_CONTENT_PROVIDER_SERVICE_NAME
));
101 //=========================================================================
103 // Service factory implementation.
105 //=========================================================================
107 ONE_INSTANCE_SERVICE_FACTORY_IMPL(FTPContentProvider
);
110 //=========================================================================
112 // XContentProvider methods.
114 //=========================================================================
117 Reference
<XContent
> SAL_CALL
118 FTPContentProvider::queryContent(
119 const Reference
< XContentIdentifier
>& xCanonicId
122 IllegalIdentifierException
,
126 // Check, if a content with given id already exists...
127 Reference
<XContent
> xContent
= queryExistingContent(xCanonicId
).get();
131 // A new content has to be returned:
134 osl::MutexGuard
aGuard( m_aMutex
);
135 if(!m_ftpLoaderThread
|| !m_pProxyDecider
)
140 throw RuntimeException();
143 if(!m_ftpLoaderThread
|| !m_pProxyDecider
)
144 throw RuntimeException();
149 FTPURL
aURL(xCanonicId
->getContentIdentifier(),
152 if(!m_pProxyDecider
->shouldUseProxy(
153 rtl::OUString("ftp"),
155 aURL
.port().toInt32()))
157 xContent
= new FTPContent( m_xContext
, this,xCanonicId
,aURL
);
158 registerNewContent(xContent
);
161 Reference
<XContentProvider
>
162 xProvider(getHttpProvider());
164 return xProvider
->queryContent(xCanonicId
);
166 throw RuntimeException();
168 } catch(const malformed_exception
&) {
169 throw IllegalIdentifierException();
172 // may throw IllegalIdentifierException
179 void FTPContentProvider::init() {
180 m_ftpLoaderThread
= new FTPLoaderThread();
181 m_pProxyDecider
= new ucbhelper::InternetProxyDecider( m_xContext
);
186 CURL
* FTPContentProvider::handle() {
187 // Cannot be zero if called from here;
188 return m_ftpLoaderThread
->handle();
192 bool FTPContentProvider::forHost(
193 const rtl::OUString
& host
,
194 const rtl::OUString
& port
,
195 const rtl::OUString
& username
,
196 rtl::OUString
& password
,
197 rtl::OUString
& account
)
199 osl::MutexGuard
aGuard(m_aMutex
);
200 for(unsigned int i
= 0; i
< m_ServerInfo
.size(); ++i
)
201 if(host
== m_ServerInfo
[i
].host
&&
202 port
== m_ServerInfo
[i
].port
&&
203 username
== m_ServerInfo
[i
].username
)
205 password
= m_ServerInfo
[i
].password
;
206 account
= m_ServerInfo
[i
].account
;
214 bool FTPContentProvider::setHost(
215 const rtl::OUString
& host
,
216 const rtl::OUString
& port
,
217 const rtl::OUString
& username
,
218 const rtl::OUString
& password
,
219 const rtl::OUString
& account
)
224 inf
.username
= username
;
225 inf
.password
= password
;
226 inf
.account
= account
;
229 osl::MutexGuard
aGuard(m_aMutex
);
230 for(unsigned int i
= 0; i
< m_ServerInfo
.size(); ++i
)
231 if(host
== m_ServerInfo
[i
].host
&&
232 port
== m_ServerInfo
[i
].port
&&
233 username
== m_ServerInfo
[i
].username
)
236 m_ServerInfo
[i
].password
= password
;
237 m_ServerInfo
[i
].account
= account
;
241 m_ServerInfo
.push_back(inf
);
248 Reference
<XContentProvider
>
249 FTPContentProvider::getHttpProvider()
250 throw(RuntimeException
)
252 // used for access to ftp-proxy
253 return UniversalContentBroker::create( m_xContext
)->queryContentProvider("http:");
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */