1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ftpcontentprovider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
40 #include <ucbhelper/contentbroker.hxx>
41 #include <osl/socket.hxx>
42 #include "ftpcontentprovider.hxx"
43 #include "ftpcontent.hxx"
44 #include "ftploaderthread.hxx"
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::container
;
50 using namespace com::sun::star::uno
;
51 using namespace com::sun::star::ucb
;
52 using namespace com::sun::star::beans
;
56 //=========================================================================
57 //=========================================================================
59 // ContentProvider Implementation.
61 //=========================================================================
62 //=========================================================================
64 FTPContentProvider::FTPContentProvider(
65 const Reference
< XMultiServiceFactory
>& rSMgr
)
66 : ::ucbhelper::ContentProviderImplHelper(rSMgr
),
72 //=========================================================================
74 FTPContentProvider::~FTPContentProvider()
76 delete m_ftpLoaderThread
;
77 delete m_pProxyDecider
;
80 //=========================================================================
82 // XInterface methods.
84 //=========================================================================
86 XINTERFACE_IMPL_3(FTPContentProvider
,
91 //=========================================================================
93 // XTypeProvider methods.
95 //=========================================================================
97 XTYPEPROVIDER_IMPL_3(FTPContentProvider
,
102 //=========================================================================
104 // XServiceInfo methods.
106 //=========================================================================
110 rtl::OUString::createFromAscii("com.sun.star.comp.FTPContentProvider"),
111 rtl::OUString::createFromAscii(FTP_CONTENT_PROVIDER_SERVICE_NAME
));
113 //=========================================================================
115 // Service factory implementation.
117 //=========================================================================
119 ONE_INSTANCE_SERVICE_FACTORY_IMPL(FTPContentProvider
);
122 //=========================================================================
124 // XContentProvider methods.
126 //=========================================================================
129 Reference
<XContent
> SAL_CALL
130 FTPContentProvider::queryContent(
131 const Reference
< XContentIdentifier
>& xCanonicId
134 IllegalIdentifierException
,
138 // Check, if a content with given id already exists...
139 Reference
<XContent
> xContent
= queryExistingContent(xCanonicId
).get();
143 // A new content has to be returned:
146 osl::MutexGuard
aGuard( m_aMutex
);
147 if(!m_ftpLoaderThread
|| !m_pProxyDecider
)
152 throw RuntimeException();
155 if(!m_ftpLoaderThread
|| !m_pProxyDecider
)
156 throw RuntimeException();
161 FTPURL
aURL(xCanonicId
->getContentIdentifier(),
164 if(!m_pProxyDecider
->shouldUseProxy(
165 rtl::OUString::createFromAscii("ftp"),
167 aURL
.port().toInt32()))
169 xContent
= new FTPContent(m_xSMgr
,this,xCanonicId
,aURL
);
170 registerNewContent(xContent
);
173 Reference
<XContentProvider
>
174 xProvider(getHttpProvider());
176 return xProvider
->queryContent(xCanonicId
);
178 throw RuntimeException();
180 } catch(const malformed_exception
&) {
181 throw IllegalIdentifierException();
184 // may throw IllegalIdentifierException
191 void FTPContentProvider::init() {
192 m_ftpLoaderThread
= new FTPLoaderThread();
193 m_pProxyDecider
= new ucbhelper::InternetProxyDecider(m_xSMgr
);
198 CURL
* FTPContentProvider::handle() {
199 // Cannot be zero if called from here;
200 return m_ftpLoaderThread
->handle();
204 bool FTPContentProvider::forHost(
205 const rtl::OUString
& host
,
206 const rtl::OUString
& port
,
207 const rtl::OUString
& username
,
208 rtl::OUString
& password
,
209 rtl::OUString
& account
)
211 osl::MutexGuard
aGuard(m_aMutex
);
212 for(unsigned int i
= 0; i
< m_ServerInfo
.size(); ++i
)
213 if(host
== m_ServerInfo
[i
].host
&&
214 port
== m_ServerInfo
[i
].port
&&
215 username
== m_ServerInfo
[i
].username
)
217 password
= m_ServerInfo
[i
].password
;
218 account
= m_ServerInfo
[i
].account
;
226 bool FTPContentProvider::setHost(
227 const rtl::OUString
& host
,
228 const rtl::OUString
& port
,
229 const rtl::OUString
& username
,
230 const rtl::OUString
& password
,
231 const rtl::OUString
& account
)
236 inf
.username
= username
;
237 inf
.password
= password
;
238 inf
.account
= account
;
241 osl::MutexGuard
aGuard(m_aMutex
);
242 for(unsigned int i
= 0; i
< m_ServerInfo
.size(); ++i
)
243 if(host
== m_ServerInfo
[i
].host
&&
244 port
== m_ServerInfo
[i
].port
&&
245 username
== m_ServerInfo
[i
].username
)
248 m_ServerInfo
[i
].password
= password
;
249 m_ServerInfo
[i
].account
= account
;
253 m_ServerInfo
.push_back(inf
);
260 Reference
<XContentProvider
>
261 FTPContentProvider::getHttpProvider()
262 throw(RuntimeException
)
264 // used for access to ftp-proxy
265 ucbhelper::ContentBroker
*pBroker
= ucbhelper::ContentBroker::get();
268 Reference
<XContentProviderManager
> xManager(
269 pBroker
->getContentProviderManagerInterface());
273 xManager
->queryContentProvider(
274 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http:")));
276 throw RuntimeException(
277 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
278 "bad ucbhelper::ContentBroker")),