1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /**************************************************************************
32 **************************************************************************
34 *************************************************************************/
36 #include <ucbhelper/contentbroker.hxx>
37 #include <osl/socket.hxx>
38 #include "ftpcontentprovider.hxx"
39 #include "ftpcontent.hxx"
40 #include "ftploaderthread.hxx"
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::container
;
46 using namespace com::sun::star::uno
;
47 using namespace com::sun::star::ucb
;
48 using namespace com::sun::star::beans
;
52 //=========================================================================
53 //=========================================================================
55 // ContentProvider Implementation.
57 //=========================================================================
58 //=========================================================================
60 FTPContentProvider::FTPContentProvider(
61 const Reference
< XMultiServiceFactory
>& rSMgr
)
62 : ::ucbhelper::ContentProviderImplHelper(rSMgr
),
68 //=========================================================================
70 FTPContentProvider::~FTPContentProvider()
72 delete m_ftpLoaderThread
;
73 delete m_pProxyDecider
;
76 //=========================================================================
78 // XInterface methods.
80 //=========================================================================
82 XINTERFACE_IMPL_3(FTPContentProvider
,
87 //=========================================================================
89 // XTypeProvider methods.
91 //=========================================================================
93 XTYPEPROVIDER_IMPL_3(FTPContentProvider
,
98 //=========================================================================
100 // XServiceInfo methods.
102 //=========================================================================
106 rtl::OUString("com.sun.star.comp.FTPContentProvider"),
107 rtl::OUString(FTP_CONTENT_PROVIDER_SERVICE_NAME
));
109 //=========================================================================
111 // Service factory implementation.
113 //=========================================================================
115 ONE_INSTANCE_SERVICE_FACTORY_IMPL(FTPContentProvider
);
118 //=========================================================================
120 // XContentProvider methods.
122 //=========================================================================
125 Reference
<XContent
> SAL_CALL
126 FTPContentProvider::queryContent(
127 const Reference
< XContentIdentifier
>& xCanonicId
130 IllegalIdentifierException
,
134 // Check, if a content with given id already exists...
135 Reference
<XContent
> xContent
= queryExistingContent(xCanonicId
).get();
139 // A new content has to be returned:
142 osl::MutexGuard
aGuard( m_aMutex
);
143 if(!m_ftpLoaderThread
|| !m_pProxyDecider
)
148 throw RuntimeException();
151 if(!m_ftpLoaderThread
|| !m_pProxyDecider
)
152 throw RuntimeException();
157 FTPURL
aURL(xCanonicId
->getContentIdentifier(),
160 if(!m_pProxyDecider
->shouldUseProxy(
161 rtl::OUString("ftp"),
163 aURL
.port().toInt32()))
165 xContent
= new FTPContent(m_xSMgr
,this,xCanonicId
,aURL
);
166 registerNewContent(xContent
);
169 Reference
<XContentProvider
>
170 xProvider(getHttpProvider());
172 return xProvider
->queryContent(xCanonicId
);
174 throw RuntimeException();
176 } catch(const malformed_exception
&) {
177 throw IllegalIdentifierException();
180 // may throw IllegalIdentifierException
187 void FTPContentProvider::init() {
188 m_ftpLoaderThread
= new FTPLoaderThread();
189 m_pProxyDecider
= new ucbhelper::InternetProxyDecider(m_xSMgr
);
194 CURL
* FTPContentProvider::handle() {
195 // Cannot be zero if called from here;
196 return m_ftpLoaderThread
->handle();
200 bool FTPContentProvider::forHost(
201 const rtl::OUString
& host
,
202 const rtl::OUString
& port
,
203 const rtl::OUString
& username
,
204 rtl::OUString
& password
,
205 rtl::OUString
& account
)
207 osl::MutexGuard
aGuard(m_aMutex
);
208 for(unsigned int i
= 0; i
< m_ServerInfo
.size(); ++i
)
209 if(host
== m_ServerInfo
[i
].host
&&
210 port
== m_ServerInfo
[i
].port
&&
211 username
== m_ServerInfo
[i
].username
)
213 password
= m_ServerInfo
[i
].password
;
214 account
= m_ServerInfo
[i
].account
;
222 bool FTPContentProvider::setHost(
223 const rtl::OUString
& host
,
224 const rtl::OUString
& port
,
225 const rtl::OUString
& username
,
226 const rtl::OUString
& password
,
227 const rtl::OUString
& account
)
232 inf
.username
= username
;
233 inf
.password
= password
;
234 inf
.account
= account
;
237 osl::MutexGuard
aGuard(m_aMutex
);
238 for(unsigned int i
= 0; i
< m_ServerInfo
.size(); ++i
)
239 if(host
== m_ServerInfo
[i
].host
&&
240 port
== m_ServerInfo
[i
].port
&&
241 username
== m_ServerInfo
[i
].username
)
244 m_ServerInfo
[i
].password
= password
;
245 m_ServerInfo
[i
].account
= account
;
249 m_ServerInfo
.push_back(inf
);
256 Reference
<XContentProvider
>
257 FTPContentProvider::getHttpProvider()
258 throw(RuntimeException
)
260 // used for access to ftp-proxy
261 ucbhelper::ContentBroker
*pBroker
= ucbhelper::ContentBroker::get();
264 Reference
<XContentProviderManager
> xManager(
265 pBroker
->getContentProviderManagerInterface());
269 xManager
->queryContentProvider(
270 rtl::OUString("http:"));
272 throw RuntimeException(
273 rtl::OUString( "bad ucbhelper::ContentBroker"),
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */