12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
32f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file
52f86921cSAndrew Rist * distributed with this work for additional information
62f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
72f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist * with the License. You may obtain a copy of the License at
102f86921cSAndrew Rist *
112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122f86921cSAndrew Rist *
132f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist * software distributed under the License is distributed on an
152f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist * KIND, either express or implied. See the License for the
172f86921cSAndrew Rist * specific language governing permissions and limitations
182f86921cSAndrew Rist * under the License.
192f86921cSAndrew Rist *
202f86921cSAndrew Rist *************************************************************/
212f86921cSAndrew Rist
222f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*421ed02eSdamjan #include "precompiled_ftp.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir TODO
29cdf0e10cSrcweir **************************************************************************
30cdf0e10cSrcweir
31cdf0e10cSrcweir *************************************************************************/
32cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "ftpdynresultset.hxx"
35cdf0e10cSrcweir #include "ftpresultsetfactory.hxx"
36cdf0e10cSrcweir #include "ftpresultsetI.hxx"
37cdf0e10cSrcweir #include "ftpcontent.hxx"
38cdf0e10cSrcweir #include "ftpcontentprovider.hxx"
39cdf0e10cSrcweir #include "ftpinpstr.hxx"
40cdf0e10cSrcweir #include "ftpdirp.hxx"
41cdf0e10cSrcweir #include "ftpcontentidentifier.hxx"
42cdf0e10cSrcweir #include "ftpcfunc.hxx"
43cdf0e10cSrcweir #include "ftpstrcont.hxx"
44cdf0e10cSrcweir #include "ftpintreq.hxx"
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <memory>
47cdf0e10cSrcweir #include <vector>
48cdf0e10cSrcweir #include <rtl/memory.h>
49cdf0e10cSrcweir #include "curl.hxx"
50cdf0e10cSrcweir #include <curl/easy.h>
51cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
52cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
53cdf0e10cSrcweir #include <ucbhelper/propertyvalueset.hxx>
54cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
55cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
56cdf0e10cSrcweir #include <ucbhelper/simpleauthenticationrequest.hxx>
57cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp>
58cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
59cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
61cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
62cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
63cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
64cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
65cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataStreamer.hpp>
66cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
67cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
68cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
69cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
70cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
71cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp>
72cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp>
73cdf0e10cSrcweir #include <com/sun/star/ucb/MissingInputStreamException.hpp>
74cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
75cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
76cdf0e10cSrcweir //#include <com/sun/star/ucb/NameClash.hpp>
77cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
78cdf0e10cSrcweir #include <com/sun/star/ucb/IOErrorCode.hpp>
79cdf0e10cSrcweir
80cdf0e10cSrcweir using namespace ftp;
81cdf0e10cSrcweir using namespace com::sun::star::task;
82cdf0e10cSrcweir using namespace com::sun::star::container;
83cdf0e10cSrcweir using namespace com::sun::star::lang;
84cdf0e10cSrcweir using namespace com::sun::star::uno;
85cdf0e10cSrcweir using namespace com::sun::star::ucb;
86cdf0e10cSrcweir using namespace com::sun::star::beans;
87cdf0e10cSrcweir using namespace com::sun::star::io;
88cdf0e10cSrcweir using namespace com::sun::star::sdbc;
89cdf0e10cSrcweir
90cdf0e10cSrcweir
91cdf0e10cSrcweir
92cdf0e10cSrcweir //=========================================================================
93cdf0e10cSrcweir //=========================================================================
94cdf0e10cSrcweir //
95cdf0e10cSrcweir // Content Implementation.
96cdf0e10cSrcweir //
97cdf0e10cSrcweir //=========================================================================
98cdf0e10cSrcweir //=========================================================================
99cdf0e10cSrcweir
FTPContent(const Reference<XMultiServiceFactory> & rxSMgr,FTPContentProvider * pProvider,const Reference<XContentIdentifier> & Identifier,const FTPURL & aFTPURL)100cdf0e10cSrcweir FTPContent::FTPContent( const Reference< XMultiServiceFactory >& rxSMgr,
101cdf0e10cSrcweir FTPContentProvider* pProvider,
102cdf0e10cSrcweir const Reference< XContentIdentifier >& Identifier,
103cdf0e10cSrcweir const FTPURL& aFTPURL)
104cdf0e10cSrcweir : ContentImplHelper(rxSMgr,pProvider,Identifier),
105cdf0e10cSrcweir m_pFCP(pProvider),
106cdf0e10cSrcweir m_aFTPURL(aFTPURL),
107cdf0e10cSrcweir m_bInserted(false),
108cdf0e10cSrcweir m_bTitleSet(false)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
112cdf0e10cSrcweir
113cdf0e10cSrcweir
FTPContent(const Reference<XMultiServiceFactory> & rxSMgr,FTPContentProvider * pProvider,const Reference<XContentIdentifier> & Identifier,const ContentInfo & Info)114cdf0e10cSrcweir FTPContent::FTPContent( const Reference< XMultiServiceFactory >& rxSMgr,
115cdf0e10cSrcweir FTPContentProvider* pProvider,
116cdf0e10cSrcweir const Reference< XContentIdentifier >& Identifier,
117cdf0e10cSrcweir const ContentInfo& Info)
118cdf0e10cSrcweir : ContentImplHelper(rxSMgr,pProvider,Identifier),
119cdf0e10cSrcweir m_pFCP(pProvider),
120cdf0e10cSrcweir m_aFTPURL(Identifier->getContentIdentifier(),
121cdf0e10cSrcweir pProvider),
122cdf0e10cSrcweir m_bInserted(true),
123cdf0e10cSrcweir m_bTitleSet(false),
124cdf0e10cSrcweir m_aInfo(Info)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir
129cdf0e10cSrcweir
130cdf0e10cSrcweir //=========================================================================
131cdf0e10cSrcweir
~FTPContent()132cdf0e10cSrcweir FTPContent::~FTPContent()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
136cdf0e10cSrcweir
137cdf0e10cSrcweir //=========================================================================
138cdf0e10cSrcweir //
139cdf0e10cSrcweir // XInterface methods.
140cdf0e10cSrcweir //
141cdf0e10cSrcweir //=========================================================================
142cdf0e10cSrcweir
143cdf0e10cSrcweir XINTERFACE_IMPL_6( FTPContent,
144cdf0e10cSrcweir XTypeProvider,
145cdf0e10cSrcweir XServiceInfo,
146cdf0e10cSrcweir XContent,
147cdf0e10cSrcweir XCommandProcessor,
148cdf0e10cSrcweir XContentCreator,
149cdf0e10cSrcweir XChild);
150cdf0e10cSrcweir
151cdf0e10cSrcweir //=========================================================================
152cdf0e10cSrcweir //
153cdf0e10cSrcweir // XTypeProvider methods.
154cdf0e10cSrcweir //
155cdf0e10cSrcweir //=========================================================================
156cdf0e10cSrcweir
157cdf0e10cSrcweir XTYPEPROVIDER_IMPL_6( FTPContent,
158cdf0e10cSrcweir XTypeProvider,
159cdf0e10cSrcweir XServiceInfo,
160cdf0e10cSrcweir XContent,
161cdf0e10cSrcweir XCommandProcessor,
162cdf0e10cSrcweir XContentCreator,
163cdf0e10cSrcweir XChild);
164cdf0e10cSrcweir
165cdf0e10cSrcweir //=========================================================================
166cdf0e10cSrcweir //
167cdf0e10cSrcweir // XServiceInfo methods.
168cdf0e10cSrcweir //
169cdf0e10cSrcweir //=========================================================================
170cdf0e10cSrcweir
171cdf0e10cSrcweir // needed, because the service shall not be creatable!!
172cdf0e10cSrcweir #undef XSERVICEINFO_CREATE_INSTANCE_IMPL
173cdf0e10cSrcweir #define XSERVICEINFO_CREATE_INSTANCE_IMPL( Class )
174cdf0e10cSrcweir
175cdf0e10cSrcweir XSERVICEINFO_IMPL_1( FTPContent,
176cdf0e10cSrcweir rtl::OUString::createFromAscii(
177cdf0e10cSrcweir "com.sun.star.comp.FTPContent"),
178cdf0e10cSrcweir rtl::OUString::createFromAscii(
179cdf0e10cSrcweir "com.sun.star.ucb.FTPContent"));
180cdf0e10cSrcweir
181cdf0e10cSrcweir
182cdf0e10cSrcweir
183cdf0e10cSrcweir //=========================================================================
184cdf0e10cSrcweir //
185cdf0e10cSrcweir // XContent methods.
186cdf0e10cSrcweir //
187cdf0e10cSrcweir //=========================================================================
188cdf0e10cSrcweir
189cdf0e10cSrcweir // virtual
getContentType()190cdf0e10cSrcweir rtl::OUString SAL_CALL FTPContent::getContentType()
191cdf0e10cSrcweir throw( RuntimeException )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir return rtl::OUString::createFromAscii(FTP_CONTENT_TYPE);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir
197cdf0e10cSrcweir //=========================================================================
198cdf0e10cSrcweir //
199cdf0e10cSrcweir // XCommandProcessor methods.
200cdf0e10cSrcweir //
201cdf0e10cSrcweir //=========================================================================
202cdf0e10cSrcweir
203cdf0e10cSrcweir
204cdf0e10cSrcweir //virtual
abort(sal_Int32)205cdf0e10cSrcweir void SAL_CALL FTPContent::abort( sal_Int32 /*CommandId*/ )
206cdf0e10cSrcweir throw( RuntimeException )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir
211cdf0e10cSrcweir
212cdf0e10cSrcweir /***************************************************************************/
213cdf0e10cSrcweir /* */
214cdf0e10cSrcweir /* Internal implementation class. */
215cdf0e10cSrcweir /* */
216cdf0e10cSrcweir /***************************************************************************/
217cdf0e10cSrcweir
218cdf0e10cSrcweir
219cdf0e10cSrcweir class ResultSetFactoryI
220cdf0e10cSrcweir : public ResultSetFactory
221cdf0e10cSrcweir {
222cdf0e10cSrcweir public:
223cdf0e10cSrcweir
ResultSetFactoryI(const Reference<XMultiServiceFactory> & xSMgr,const Reference<XContentProvider> & xProvider,sal_Int32 nOpenMode,const Sequence<Property> & seq,const Sequence<NumberedSortingInfo> & seqSort,const std::vector<FTPDirentry> & dirvec)224cdf0e10cSrcweir ResultSetFactoryI(const Reference<XMultiServiceFactory >& xSMgr,
225cdf0e10cSrcweir const Reference<XContentProvider >& xProvider,
226cdf0e10cSrcweir sal_Int32 nOpenMode,
227cdf0e10cSrcweir const Sequence<Property>& seq,
228cdf0e10cSrcweir const Sequence<NumberedSortingInfo>& seqSort,
229cdf0e10cSrcweir const std::vector<FTPDirentry>& dirvec)
230cdf0e10cSrcweir : m_xSMgr(xSMgr),
231cdf0e10cSrcweir m_xProvider(xProvider),
232cdf0e10cSrcweir m_nOpenMode(nOpenMode),
233cdf0e10cSrcweir m_seq(seq),
234cdf0e10cSrcweir m_seqSort(seqSort),
235cdf0e10cSrcweir m_dirvec(dirvec)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
createResultSet()239cdf0e10cSrcweir virtual ResultSetBase* createResultSet()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir return new ResultSetI(m_xSMgr,
242cdf0e10cSrcweir m_xProvider,
243cdf0e10cSrcweir m_nOpenMode,
244cdf0e10cSrcweir m_seq,
245cdf0e10cSrcweir m_seqSort,
246cdf0e10cSrcweir m_dirvec);
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir public:
250cdf0e10cSrcweir
251cdf0e10cSrcweir Reference< XMultiServiceFactory > m_xSMgr;
252cdf0e10cSrcweir Reference< XContentProvider > m_xProvider;
253cdf0e10cSrcweir sal_Int32 m_nOpenMode;
254cdf0e10cSrcweir Sequence< Property > m_seq;
255cdf0e10cSrcweir Sequence< NumberedSortingInfo > m_seqSort;
256cdf0e10cSrcweir std::vector<FTPDirentry> m_dirvec;
257cdf0e10cSrcweir };
258cdf0e10cSrcweir
259cdf0e10cSrcweir
260cdf0e10cSrcweir
261cdf0e10cSrcweir //=========================================================================
262cdf0e10cSrcweir //
263cdf0e10cSrcweir // XCommandProcessor methods.
264cdf0e10cSrcweir //
265cdf0e10cSrcweir //=========================================================================
266cdf0e10cSrcweir
267cdf0e10cSrcweir enum ACTION { NOACTION,
268cdf0e10cSrcweir THROWAUTHENTICATIONREQUEST,
269cdf0e10cSrcweir THROWACCESSDENIED,
270cdf0e10cSrcweir THROWINTERACTIVECONNECT,
271cdf0e10cSrcweir THROWRESOLVENAME,
272cdf0e10cSrcweir THROWQUOTE,
273cdf0e10cSrcweir THROWNOFILE,
274cdf0e10cSrcweir THROWGENERAL };
275cdf0e10cSrcweir
276cdf0e10cSrcweir
277cdf0e10cSrcweir // virtual
execute(const Command & aCommand,sal_Int32,const Reference<XCommandEnvironment> & Environment)278cdf0e10cSrcweir Any SAL_CALL FTPContent::execute(
279cdf0e10cSrcweir const Command& aCommand,
280cdf0e10cSrcweir sal_Int32 /*CommandId*/,
281cdf0e10cSrcweir const Reference<
282cdf0e10cSrcweir XCommandEnvironment >& Environment
283cdf0e10cSrcweir )
284cdf0e10cSrcweir throw(
285cdf0e10cSrcweir Exception,
286cdf0e10cSrcweir CommandAbortedException,
287cdf0e10cSrcweir RuntimeException
288cdf0e10cSrcweir )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir ACTION action(NOACTION);
291cdf0e10cSrcweir Any aRet;
292cdf0e10cSrcweir
293cdf0e10cSrcweir while(true)
294cdf0e10cSrcweir try {
295cdf0e10cSrcweir if(action == THROWAUTHENTICATIONREQUEST) {
296cdf0e10cSrcweir // try to get a continuation first
297cdf0e10cSrcweir rtl::OUString aRealm,aPassword,aAccount;
298cdf0e10cSrcweir m_pFCP->forHost(m_aFTPURL.host(),
299cdf0e10cSrcweir m_aFTPURL.port(),
300cdf0e10cSrcweir m_aFTPURL.username(),
301cdf0e10cSrcweir aPassword,
302cdf0e10cSrcweir aAccount);
303cdf0e10cSrcweir rtl::Reference<ucbhelper::SimpleAuthenticationRequest>
304cdf0e10cSrcweir p( new ucbhelper::SimpleAuthenticationRequest(
305cdf0e10cSrcweir m_aFTPURL.ident(false, false),
306cdf0e10cSrcweir m_aFTPURL.host(), // ServerName
307cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::ENTITY_NA,
308cdf0e10cSrcweir aRealm,
309cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest
310cdf0e10cSrcweir ::ENTITY_FIXED,
311cdf0e10cSrcweir m_aFTPURL.username(),
312cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest
313cdf0e10cSrcweir ::ENTITY_MODIFY,
314cdf0e10cSrcweir aPassword));
315cdf0e10cSrcweir
316cdf0e10cSrcweir Reference<XInteractionHandler> xInteractionHandler;
317cdf0e10cSrcweir if(Environment.is())
318cdf0e10cSrcweir xInteractionHandler =
319cdf0e10cSrcweir Environment->getInteractionHandler();
320cdf0e10cSrcweir
321cdf0e10cSrcweir if( xInteractionHandler.is()) {
322cdf0e10cSrcweir xInteractionHandler->handle(p.get());
323cdf0e10cSrcweir
324cdf0e10cSrcweir Reference<XInterface> xSelection(
325cdf0e10cSrcweir p->getSelection().get());
326cdf0e10cSrcweir
327cdf0e10cSrcweir if(Reference<XInteractionRetry>(
328cdf0e10cSrcweir xSelection,UNO_QUERY).is())
329cdf0e10cSrcweir action = NOACTION;
330cdf0e10cSrcweir else if(Reference<XInteractionSupplyAuthentication>(
331cdf0e10cSrcweir xSelection,UNO_QUERY).is()) {
332cdf0e10cSrcweir m_pFCP->setHost(
333cdf0e10cSrcweir m_aFTPURL.host(),
334cdf0e10cSrcweir m_aFTPURL.port(),
335cdf0e10cSrcweir m_aFTPURL.username(),
336cdf0e10cSrcweir p->getAuthenticationSupplier()->getPassword(),
337cdf0e10cSrcweir aAccount);
338cdf0e10cSrcweir action = NOACTION;
339cdf0e10cSrcweir }
340cdf0e10cSrcweir }
341cdf0e10cSrcweir aRet = p->getRequest();
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
344cdf0e10cSrcweir // if(aCommand.Name.compareToAscii(
345cdf0e10cSrcweir // "getPropertyValues") == 0 &&
346cdf0e10cSrcweir // action != NOACTION) {
347cdf0e10cSrcweir // // It is not allowed to throw if
348cdf0e10cSrcweir // // command is getPropertyValues
349cdf0e10cSrcweir // rtl::Reference<ucbhelper::PropertyValueSet> xRow =
350cdf0e10cSrcweir // new ucbhelper::PropertyValueSet(m_xSMgr);
351cdf0e10cSrcweir // Sequence<Property> Properties;
352cdf0e10cSrcweir // aCommand.Argument >>= Properties;
353cdf0e10cSrcweir // for(int i = 0; i < Properties.getLength(); ++i)
354cdf0e10cSrcweir // xRow->appendVoid(Properties[i]);
355cdf0e10cSrcweir // aRet <<= Reference<XRow>(xRow.get());
356cdf0e10cSrcweir // return aRet;
357cdf0e10cSrcweir // }
358cdf0e10cSrcweir
359cdf0e10cSrcweir switch (action)
360cdf0e10cSrcweir {
361cdf0e10cSrcweir case NOACTION:
362cdf0e10cSrcweir break;
363cdf0e10cSrcweir
364cdf0e10cSrcweir case THROWAUTHENTICATIONREQUEST:
365cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
366cdf0e10cSrcweir aRet,
367cdf0e10cSrcweir Reference<XCommandEnvironment>(0));
368cdf0e10cSrcweir break;
369cdf0e10cSrcweir
370cdf0e10cSrcweir case THROWACCESSDENIED:
371cdf0e10cSrcweir {
372cdf0e10cSrcweir Sequence<Any> seq(1);
373cdf0e10cSrcweir PropertyValue value;
374cdf0e10cSrcweir value.Name = rtl::OUString::createFromAscii("Uri");
375cdf0e10cSrcweir value.Handle = -1;
376cdf0e10cSrcweir value.Value <<= m_aFTPURL.ident(false,false);
377cdf0e10cSrcweir value.State = PropertyState_DIRECT_VALUE;
378cdf0e10cSrcweir seq[0] <<= value;
379cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
380cdf0e10cSrcweir IOErrorCode_ACCESS_DENIED,
381cdf0e10cSrcweir seq,
382cdf0e10cSrcweir Environment);
383cdf0e10cSrcweir break;
384cdf0e10cSrcweir }
385cdf0e10cSrcweir case THROWINTERACTIVECONNECT:
386cdf0e10cSrcweir {
387cdf0e10cSrcweir InteractiveNetworkConnectException excep;
388cdf0e10cSrcweir excep.Server = m_aFTPURL.host();
389cdf0e10cSrcweir aRet <<= excep;
390cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
391cdf0e10cSrcweir aRet,
392cdf0e10cSrcweir Environment);
393cdf0e10cSrcweir break;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir case THROWRESOLVENAME:
396cdf0e10cSrcweir {
397cdf0e10cSrcweir InteractiveNetworkResolveNameException excep;
398cdf0e10cSrcweir excep.Server = m_aFTPURL.host();
399cdf0e10cSrcweir aRet <<= excep;
400cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
401cdf0e10cSrcweir aRet,
402cdf0e10cSrcweir Environment);
403cdf0e10cSrcweir break;
404cdf0e10cSrcweir }
405cdf0e10cSrcweir case THROWNOFILE:
406cdf0e10cSrcweir {
407cdf0e10cSrcweir Sequence<Any> seq(1);
408cdf0e10cSrcweir PropertyValue value;
409cdf0e10cSrcweir value.Name = rtl::OUString::createFromAscii("Uri");
410cdf0e10cSrcweir value.Handle = -1;
411cdf0e10cSrcweir value.Value <<= m_aFTPURL.ident(false,false);
412cdf0e10cSrcweir value.State = PropertyState_DIRECT_VALUE;
413cdf0e10cSrcweir seq[0] <<= value;
414cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
415cdf0e10cSrcweir IOErrorCode_NO_FILE,
416cdf0e10cSrcweir seq,
417cdf0e10cSrcweir Environment);
418cdf0e10cSrcweir break;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir case THROWQUOTE:
421cdf0e10cSrcweir case THROWGENERAL:
422cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
423cdf0e10cSrcweir IOErrorCode_GENERAL,
424cdf0e10cSrcweir Sequence<Any>(0),
425cdf0e10cSrcweir Environment);
426cdf0e10cSrcweir break;
427cdf0e10cSrcweir }
428cdf0e10cSrcweir
429cdf0e10cSrcweir if(aCommand.Name.compareToAscii("getPropertyValues") == 0) {
430cdf0e10cSrcweir Sequence<Property> Properties;
431cdf0e10cSrcweir if(!(aCommand.Argument >>= Properties))
432cdf0e10cSrcweir {
433cdf0e10cSrcweir aRet <<= IllegalArgumentException(
434cdf0e10cSrcweir rtl::OUString::createFromAscii(
435cdf0e10cSrcweir "Wrong argument type!" ),
436cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
437cdf0e10cSrcweir -1);
438cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
441cdf0e10cSrcweir aRet <<= getPropertyValues(Properties,Environment);
442cdf0e10cSrcweir }
443cdf0e10cSrcweir else if(aCommand.Name.compareToAscii("setPropertyValues") == 0)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir Sequence<PropertyValue> propertyValues;
446cdf0e10cSrcweir
447cdf0e10cSrcweir if( ! ( aCommand.Argument >>= propertyValues ) ) {
448cdf0e10cSrcweir aRet <<= IllegalArgumentException(
449cdf0e10cSrcweir rtl::OUString::createFromAscii(
450cdf0e10cSrcweir "Wrong argument type!" ),
451cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
452cdf0e10cSrcweir -1);
453cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
454cdf0e10cSrcweir }
455cdf0e10cSrcweir
456cdf0e10cSrcweir aRet <<= setPropertyValues(propertyValues);
457cdf0e10cSrcweir }
458cdf0e10cSrcweir else if(aCommand.Name.compareToAscii("getCommandInfo") == 0) {
459cdf0e10cSrcweir // Note: Implemented by base class.
460cdf0e10cSrcweir aRet <<= getCommandInfo(Environment);
461cdf0e10cSrcweir }
462cdf0e10cSrcweir else if(aCommand.Name.compareToAscii("getPropertySetInfo") == 0) {
463cdf0e10cSrcweir // Note: Implemented by base class.
464cdf0e10cSrcweir aRet <<= getPropertySetInfo(Environment);
465cdf0e10cSrcweir }
466cdf0e10cSrcweir else if(aCommand.Name.compareToAscii( "insert" ) == 0)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir InsertCommandArgument aInsertArgument;
469cdf0e10cSrcweir if ( ! ( aCommand.Argument >>= aInsertArgument ) ) {
470cdf0e10cSrcweir aRet <<= IllegalArgumentException(
471cdf0e10cSrcweir rtl::OUString::createFromAscii(
472cdf0e10cSrcweir "Wrong argument type!" ),
473cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
474cdf0e10cSrcweir -1);
475cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
476cdf0e10cSrcweir }
477cdf0e10cSrcweir insert(aInsertArgument,Environment);
478cdf0e10cSrcweir }
479cdf0e10cSrcweir else if(aCommand.Name.compareToAscii("delete") == 0) {
480cdf0e10cSrcweir m_aFTPURL.del();
481cdf0e10cSrcweir deleted();
482cdf0e10cSrcweir }
483cdf0e10cSrcweir else if(aCommand.Name.compareToAscii( "open" ) == 0) {
484cdf0e10cSrcweir OpenCommandArgument2 aOpenCommand;
485cdf0e10cSrcweir if ( !( aCommand.Argument >>= aOpenCommand ) ) {
486cdf0e10cSrcweir aRet <<= IllegalArgumentException(
487cdf0e10cSrcweir rtl::OUString::createFromAscii(
488cdf0e10cSrcweir "Wrong argument type!" ),
489cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
490cdf0e10cSrcweir -1);
491cdf0e10cSrcweir
492cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
493cdf0e10cSrcweir }
494cdf0e10cSrcweir
495cdf0e10cSrcweir if(aOpenCommand.Mode == OpenMode::DOCUMENT) {
496cdf0e10cSrcweir // Open as a document
497cdf0e10cSrcweir Reference<XActiveDataSink>
498cdf0e10cSrcweir xActiveDataSink(aOpenCommand.Sink,UNO_QUERY);
499cdf0e10cSrcweir Reference< XOutputStream >
500cdf0e10cSrcweir xOutputStream(aOpenCommand.Sink,UNO_QUERY);
501cdf0e10cSrcweir
502cdf0e10cSrcweir if(xActiveDataSink.is()) {
503cdf0e10cSrcweir xActiveDataSink->setInputStream(
504cdf0e10cSrcweir new FTPInputStream(m_aFTPURL.open()));
505cdf0e10cSrcweir }
506cdf0e10cSrcweir else if(xOutputStream.is()) {
507cdf0e10cSrcweir Reference<XInputStream> xStream(
508cdf0e10cSrcweir new FTPInputStream(m_aFTPURL.open()));
509cdf0e10cSrcweir Sequence<sal_Int8> byte_seq(4096);
510cdf0e10cSrcweir sal_Int32 n = 1000; // value does not matter here
511cdf0e10cSrcweir for (;;) {
512cdf0e10cSrcweir n = xStream->readBytes(byte_seq,4096);
513cdf0e10cSrcweir if (n == 0) {
514cdf0e10cSrcweir break;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir try {
517cdf0e10cSrcweir if(byte_seq.getLength() != n)
518cdf0e10cSrcweir byte_seq.realloc(n);
519cdf0e10cSrcweir xOutputStream->writeBytes(byte_seq);
520cdf0e10cSrcweir } catch(const NotConnectedException&) {
521cdf0e10cSrcweir
522cdf0e10cSrcweir } catch(const BufferSizeExceededException&) {
523cdf0e10cSrcweir
524cdf0e10cSrcweir } catch(const IOException&) {
525cdf0e10cSrcweir
526cdf0e10cSrcweir }
527cdf0e10cSrcweir }
528cdf0e10cSrcweir if(n) {
529cdf0e10cSrcweir Sequence<Any> seq(1);
530cdf0e10cSrcweir PropertyValue value;
531cdf0e10cSrcweir value.Name =
532cdf0e10cSrcweir rtl::OUString::createFromAscii("Uri");
533cdf0e10cSrcweir value.Handle = -1;
534cdf0e10cSrcweir value.Value <<= m_aFTPURL.ident(false,false);
535cdf0e10cSrcweir value.State = PropertyState_DIRECT_VALUE;
536cdf0e10cSrcweir seq[0] <<= value;
537cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
538cdf0e10cSrcweir IOErrorCode_UNKNOWN,
539cdf0e10cSrcweir seq,
540cdf0e10cSrcweir Environment);
541cdf0e10cSrcweir }
542cdf0e10cSrcweir }
543cdf0e10cSrcweir else {
544cdf0e10cSrcweir aRet <<= UnsupportedDataSinkException(
545cdf0e10cSrcweir rtl::OUString(),
546cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
547cdf0e10cSrcweir aOpenCommand.Sink);
548cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
549cdf0e10cSrcweir }
550cdf0e10cSrcweir }
551cdf0e10cSrcweir else if(aOpenCommand.Mode == OpenMode::ALL ||
552cdf0e10cSrcweir aOpenCommand.Mode == OpenMode::DOCUMENTS ||
553cdf0e10cSrcweir aOpenCommand.Mode == OpenMode::FOLDERS ) {
554cdf0e10cSrcweir std::vector<FTPDirentry> resvec =
555cdf0e10cSrcweir m_aFTPURL.list(sal_Int16(aOpenCommand.Mode));
556cdf0e10cSrcweir Reference< XDynamicResultSet > xSet
557cdf0e10cSrcweir = new DynamicResultSet(
558cdf0e10cSrcweir m_xSMgr,
559cdf0e10cSrcweir this,
560cdf0e10cSrcweir aOpenCommand,
561cdf0e10cSrcweir Environment,
562cdf0e10cSrcweir new ResultSetFactoryI(m_xSMgr,
563cdf0e10cSrcweir m_xProvider.get(),
564cdf0e10cSrcweir aOpenCommand.Mode,
565cdf0e10cSrcweir aOpenCommand.Properties,
566cdf0e10cSrcweir aOpenCommand.SortingInfo,
567cdf0e10cSrcweir resvec));
568cdf0e10cSrcweir aRet <<= xSet;
569cdf0e10cSrcweir }
570cdf0e10cSrcweir else if(aOpenCommand.Mode ==
571cdf0e10cSrcweir OpenMode::DOCUMENT_SHARE_DENY_NONE ||
572cdf0e10cSrcweir aOpenCommand.Mode ==
573cdf0e10cSrcweir OpenMode::DOCUMENT_SHARE_DENY_WRITE) {
574cdf0e10cSrcweir // Unsupported OpenMode
575cdf0e10cSrcweir aRet <<= UnsupportedOpenModeException(
576cdf0e10cSrcweir rtl::OUString(),
577cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
578cdf0e10cSrcweir static_cast< sal_Int16 >(aOpenCommand.Mode));
579cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
580cdf0e10cSrcweir }
581cdf0e10cSrcweir else {
582cdf0e10cSrcweir aRet <<= IllegalArgumentException(
583cdf0e10cSrcweir rtl::OUString::createFromAscii(
584cdf0e10cSrcweir "Unexpected OpenMode!" ),
585cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
586cdf0e10cSrcweir -1);
587cdf0e10cSrcweir
588cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
589cdf0e10cSrcweir }
590cdf0e10cSrcweir } else if(aCommand.Name.compareToAscii("createNewContent") == 0) {
591cdf0e10cSrcweir ContentInfo aArg;
592cdf0e10cSrcweir if (!(aCommand.Argument >>= aArg)) {
593cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
594cdf0e10cSrcweir makeAny(
595cdf0e10cSrcweir IllegalArgumentException(
596cdf0e10cSrcweir rtl::OUString::createFromAscii(
597cdf0e10cSrcweir "Wrong argument type!" ),
598cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this),
599cdf0e10cSrcweir -1)),
600cdf0e10cSrcweir Environment);
601cdf0e10cSrcweir // Unreachable
602cdf0e10cSrcweir }
603cdf0e10cSrcweir aRet <<= createNewContent(aArg);
604cdf0e10cSrcweir } else {
605cdf0e10cSrcweir aRet <<= UnsupportedCommandException(
606cdf0e10cSrcweir aCommand.Name,
607cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this));
608cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aRet,Environment);
609cdf0e10cSrcweir }
610cdf0e10cSrcweir
611cdf0e10cSrcweir return aRet;
612cdf0e10cSrcweir } catch(const curl_exception& e) {
613cdf0e10cSrcweir if(e.code() == CURLE_COULDNT_CONNECT)
614cdf0e10cSrcweir action = THROWINTERACTIVECONNECT;
615cdf0e10cSrcweir else if(e.code() == CURLE_COULDNT_RESOLVE_HOST )
616cdf0e10cSrcweir action = THROWRESOLVENAME;
617cdf0e10cSrcweir else if(e.code() == CURLE_FTP_USER_PASSWORD_INCORRECT ||
618cdf0e10cSrcweir e.code() == CURLE_LOGIN_DENIED ||
619cdf0e10cSrcweir e.code() == CURLE_BAD_PASSWORD_ENTERED ||
620cdf0e10cSrcweir e.code() == CURLE_FTP_WEIRD_PASS_REPLY)
621cdf0e10cSrcweir action = THROWAUTHENTICATIONREQUEST;
622cdf0e10cSrcweir else if(e.code() == CURLE_FTP_ACCESS_DENIED)
623cdf0e10cSrcweir action = THROWACCESSDENIED;
624cdf0e10cSrcweir else if(e.code() == CURLE_FTP_QUOTE_ERROR)
625cdf0e10cSrcweir action = THROWQUOTE;
626cdf0e10cSrcweir else if(e.code() == CURLE_FTP_COULDNT_RETR_FILE)
627cdf0e10cSrcweir action = THROWNOFILE;
628cdf0e10cSrcweir else
629cdf0e10cSrcweir // nothing known about the cause of the error
630cdf0e10cSrcweir action = THROWGENERAL;
631cdf0e10cSrcweir }
632cdf0e10cSrcweir }
633cdf0e10cSrcweir
634cdf0e10cSrcweir #define FTP_FILE rtl::OUString::createFromAscii( \
635cdf0e10cSrcweir "application/" \
636cdf0e10cSrcweir "vnd.sun.staroffice.ftp-file")
637cdf0e10cSrcweir
638cdf0e10cSrcweir #define FTP_FOLDER rtl::OUString::createFromAscii( \
639cdf0e10cSrcweir "application/" \
640cdf0e10cSrcweir "vnd.sun.staroffice.ftp-folder")
641cdf0e10cSrcweir
642cdf0e10cSrcweir Sequence<ContentInfo > SAL_CALL
queryCreatableContentsInfo()643cdf0e10cSrcweir FTPContent::queryCreatableContentsInfo( )
644cdf0e10cSrcweir throw (RuntimeException)
645cdf0e10cSrcweir {
646cdf0e10cSrcweir return queryCreatableContentsInfo_Static();
647cdf0e10cSrcweir }
648cdf0e10cSrcweir
649cdf0e10cSrcweir // static
650cdf0e10cSrcweir Sequence<ContentInfo >
queryCreatableContentsInfo_Static()651cdf0e10cSrcweir FTPContent::queryCreatableContentsInfo_Static( )
652cdf0e10cSrcweir throw (RuntimeException)
653cdf0e10cSrcweir {
654cdf0e10cSrcweir Sequence< ContentInfo > seq(2);
655cdf0e10cSrcweir
656cdf0e10cSrcweir seq[0].Type = FTP_FILE;
657cdf0e10cSrcweir seq[0].Attributes = ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
658cdf0e10cSrcweir | ContentInfoAttribute::KIND_DOCUMENT;
659cdf0e10cSrcweir Sequence< Property > props( 1 );
660cdf0e10cSrcweir props[0] = Property(
661cdf0e10cSrcweir rtl::OUString::createFromAscii( "Title" ),
662cdf0e10cSrcweir -1,
663cdf0e10cSrcweir getCppuType( static_cast< rtl::OUString* >( 0 ) ),
664cdf0e10cSrcweir PropertyAttribute::MAYBEVOID
665cdf0e10cSrcweir | PropertyAttribute::BOUND );
666cdf0e10cSrcweir seq[0].Properties = props;
667cdf0e10cSrcweir
668cdf0e10cSrcweir // folder
669cdf0e10cSrcweir seq[1].Type = FTP_FOLDER;
670cdf0e10cSrcweir seq[1].Attributes = ContentInfoAttribute::KIND_FOLDER;
671cdf0e10cSrcweir seq[1].Properties = props;
672cdf0e10cSrcweir
673cdf0e10cSrcweir return seq;
674cdf0e10cSrcweir }
675cdf0e10cSrcweir
676cdf0e10cSrcweir Reference<XContent > SAL_CALL
createNewContent(const ContentInfo & Info)677cdf0e10cSrcweir FTPContent::createNewContent( const ContentInfo& Info )
678cdf0e10cSrcweir throw (RuntimeException)
679cdf0e10cSrcweir {
680cdf0e10cSrcweir if(Info.Type.equalsAscii("application/"
681cdf0e10cSrcweir "vnd.sun.staroffice.ftp-file") ||
682cdf0e10cSrcweir Info.Type.equalsAscii("application/"
683cdf0e10cSrcweir "vnd.sun.staroffice.ftp-folder"))
684cdf0e10cSrcweir return new FTPContent(m_xSMgr,
685cdf0e10cSrcweir m_pFCP,
686cdf0e10cSrcweir m_xIdentifier,Info);
687cdf0e10cSrcweir else
688cdf0e10cSrcweir return Reference<XContent>(0);
689cdf0e10cSrcweir }
690cdf0e10cSrcweir
691cdf0e10cSrcweir
692cdf0e10cSrcweir
693cdf0e10cSrcweir
694cdf0e10cSrcweir Reference<XInterface > SAL_CALL
getParent()695cdf0e10cSrcweir FTPContent::getParent( )
696cdf0e10cSrcweir throw (RuntimeException)
697cdf0e10cSrcweir {
698cdf0e10cSrcweir Reference<XContentIdentifier>
699cdf0e10cSrcweir xIdent(new FTPContentIdentifier(m_aFTPURL.parent(false)));
700cdf0e10cSrcweir Reference<XContent> xContent(m_xProvider->queryContent(xIdent));
701cdf0e10cSrcweir return Reference<XInterface>(xContent,UNO_QUERY);
702cdf0e10cSrcweir }
703cdf0e10cSrcweir
704cdf0e10cSrcweir
705cdf0e10cSrcweir void SAL_CALL
setParent(const Reference<XInterface> &)706cdf0e10cSrcweir FTPContent::setParent(const Reference<XInterface >& /*Parent*/ )
707cdf0e10cSrcweir throw (NoSupportException,
708cdf0e10cSrcweir RuntimeException)
709cdf0e10cSrcweir {
710cdf0e10cSrcweir throw NoSupportException();
711cdf0e10cSrcweir }
712cdf0e10cSrcweir
713cdf0e10cSrcweir
714cdf0e10cSrcweir
getParentURL()715cdf0e10cSrcweir rtl::OUString FTPContent::getParentURL()
716cdf0e10cSrcweir {
717cdf0e10cSrcweir return m_aFTPURL.parent();
718cdf0e10cSrcweir }
719cdf0e10cSrcweir
720cdf0e10cSrcweir
721cdf0e10cSrcweir class InsertData
722cdf0e10cSrcweir : public CurlInput {
723cdf0e10cSrcweir
724cdf0e10cSrcweir public:
725cdf0e10cSrcweir
InsertData(const Reference<XInputStream> & xInputStream)726cdf0e10cSrcweir InsertData(const Reference<XInputStream>& xInputStream)
727cdf0e10cSrcweir : m_xInputStream(xInputStream) { }
~InsertData()728cdf0e10cSrcweir virtual ~InsertData() {}
729cdf0e10cSrcweir
730cdf0e10cSrcweir // returns the number of bytes actually read
731cdf0e10cSrcweir virtual sal_Int32 read(sal_Int8 *dest,sal_Int32 nBytesRequested);
732cdf0e10cSrcweir
733cdf0e10cSrcweir private:
734cdf0e10cSrcweir
735cdf0e10cSrcweir Reference<XInputStream> m_xInputStream;
736cdf0e10cSrcweir };
737cdf0e10cSrcweir
738cdf0e10cSrcweir
739cdf0e10cSrcweir
read(sal_Int8 * dest,sal_Int32 nBytesRequested)740cdf0e10cSrcweir sal_Int32 InsertData::read(sal_Int8 *dest,sal_Int32 nBytesRequested)
741cdf0e10cSrcweir {
742cdf0e10cSrcweir sal_Int32 m = 0;
743cdf0e10cSrcweir
744cdf0e10cSrcweir if(m_xInputStream.is()) {
745cdf0e10cSrcweir Sequence<sal_Int8> seq(nBytesRequested);
746cdf0e10cSrcweir m = m_xInputStream->readBytes(seq,nBytesRequested);
747cdf0e10cSrcweir rtl_copyMemory(dest,seq.getConstArray(),m);
748cdf0e10cSrcweir }
749cdf0e10cSrcweir return m;
750cdf0e10cSrcweir }
751cdf0e10cSrcweir
752cdf0e10cSrcweir
insert(const InsertCommandArgument & aInsertCommand,const Reference<XCommandEnvironment> & Env)753cdf0e10cSrcweir void FTPContent::insert(const InsertCommandArgument& aInsertCommand,
754cdf0e10cSrcweir const Reference<XCommandEnvironment>& Env)
755cdf0e10cSrcweir {
756cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex);
757cdf0e10cSrcweir
758cdf0e10cSrcweir if(m_bInserted && !m_bTitleSet) {
759cdf0e10cSrcweir MissingPropertiesException excep;
760cdf0e10cSrcweir excep.Properties.realloc(1);
761cdf0e10cSrcweir excep.Properties[0] = rtl::OUString::createFromAscii("Title");
762cdf0e10cSrcweir Any aAny; aAny <<= excep;
763cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aAny,Env);
764cdf0e10cSrcweir }
765cdf0e10cSrcweir
766cdf0e10cSrcweir if(m_bInserted &&
767cdf0e10cSrcweir m_aInfo.Type == FTP_FILE &&
768cdf0e10cSrcweir !aInsertCommand.Data.is())
769cdf0e10cSrcweir {
770cdf0e10cSrcweir MissingInputStreamException excep;
771cdf0e10cSrcweir Any aAny; aAny <<= excep;
772cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aAny,Env);
773cdf0e10cSrcweir }
774cdf0e10cSrcweir
775cdf0e10cSrcweir bool bReplace(aInsertCommand.ReplaceExisting);
776cdf0e10cSrcweir
777cdf0e10cSrcweir retry:
778cdf0e10cSrcweir try {
779cdf0e10cSrcweir if(m_aInfo.Type == FTP_FILE) {
780cdf0e10cSrcweir InsertData data(aInsertCommand.Data);
781cdf0e10cSrcweir m_aFTPURL.insert(bReplace,&data);
782cdf0e10cSrcweir } else if(m_aInfo.Type == FTP_FOLDER)
783cdf0e10cSrcweir m_aFTPURL.mkdir(bReplace);
784cdf0e10cSrcweir } catch(const curl_exception& e) {
785cdf0e10cSrcweir if(e.code() == FILE_EXIST_DURING_INSERT ||
786cdf0e10cSrcweir e.code() == FOLDER_EXIST_DURING_INSERT) {
787cdf0e10cSrcweir // Deprecated, not used anymore:
788cdf0e10cSrcweir NameClashException excep;
789cdf0e10cSrcweir excep.Name = m_aFTPURL.child();
790cdf0e10cSrcweir Any aAny;
791cdf0e10cSrcweir aAny <<= excep;
792cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aAny,Env);
793cdf0e10cSrcweir } else if(e.code() == FOLDER_MIGHT_EXIST_DURING_INSERT ||
794cdf0e10cSrcweir e.code() == FILE_MIGHT_EXIST_DURING_INSERT) {
795cdf0e10cSrcweir // Interact
796cdf0e10cSrcweir Reference<XInteractionHandler> xInt;
797cdf0e10cSrcweir if(Env.is())
798cdf0e10cSrcweir xInt = Env->getInteractionHandler();
799cdf0e10cSrcweir
800cdf0e10cSrcweir UnsupportedNameClashException excep;
801cdf0e10cSrcweir excep.NameClash = 0; //NameClash::ERROR;
802cdf0e10cSrcweir
803cdf0e10cSrcweir if(!xInt.is()) {
804cdf0e10cSrcweir Any aAny;
805cdf0e10cSrcweir aAny <<= excep;
806cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aAny,Env);
807cdf0e10cSrcweir }
808cdf0e10cSrcweir
809cdf0e10cSrcweir XInteractionRequestImpl* p =
810cdf0e10cSrcweir new XInteractionRequestImpl(m_aFTPURL.child());
811cdf0e10cSrcweir Reference<XInteractionRequest> req(p);
812cdf0e10cSrcweir xInt->handle(req);
813cdf0e10cSrcweir if(p->approved()) {
814cdf0e10cSrcweir bReplace = true;
815cdf0e10cSrcweir goto retry;
816cdf0e10cSrcweir }
817cdf0e10cSrcweir else
818cdf0e10cSrcweir throw excep;
819cdf0e10cSrcweir }
820cdf0e10cSrcweir else
821cdf0e10cSrcweir throw;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir
824cdf0e10cSrcweir // May not be reached, because both mkdir and insert can throw curl-
825cdf0e10cSrcweir // exceptions
826cdf0e10cSrcweir m_bInserted = false;
827cdf0e10cSrcweir inserted();
828cdf0e10cSrcweir }
829cdf0e10cSrcweir
830cdf0e10cSrcweir
831cdf0e10cSrcweir
getPropertyValues(const Sequence<Property> & seqProp,const Reference<XCommandEnvironment> &)832cdf0e10cSrcweir Reference< XRow > FTPContent::getPropertyValues(
833cdf0e10cSrcweir const Sequence< Property >& seqProp,
834cdf0e10cSrcweir const Reference<XCommandEnvironment>& /*environment*/
835cdf0e10cSrcweir )
836cdf0e10cSrcweir {
837cdf0e10cSrcweir rtl::Reference<ucbhelper::PropertyValueSet> xRow =
838cdf0e10cSrcweir new ucbhelper::PropertyValueSet(m_xSMgr);
839cdf0e10cSrcweir
840cdf0e10cSrcweir FTPDirentry aDirEntry = m_aFTPURL.direntry();
841cdf0e10cSrcweir
842cdf0e10cSrcweir for(sal_Int32 i = 0; i < seqProp.getLength(); ++i) {
843cdf0e10cSrcweir const rtl::OUString& Name = seqProp[i].Name;
844cdf0e10cSrcweir if(Name.compareToAscii("Title") == 0)
845cdf0e10cSrcweir xRow->appendString(seqProp[i],aDirEntry.m_aName);
846cdf0e10cSrcweir else if(Name.compareToAscii("CreatableContentsInfo") == 0)
847cdf0e10cSrcweir xRow->appendObject(seqProp[i],
848cdf0e10cSrcweir makeAny(queryCreatableContentsInfo()));
849cdf0e10cSrcweir else if(aDirEntry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN) {
850cdf0e10cSrcweir if(Name.compareToAscii("ContentType") == 0)
851cdf0e10cSrcweir xRow->appendString(seqProp[i],
852cdf0e10cSrcweir aDirEntry.m_nMode&INETCOREFTP_FILEMODE_ISDIR
853cdf0e10cSrcweir ? FTP_FOLDER
854cdf0e10cSrcweir : FTP_FILE );
855cdf0e10cSrcweir else if(Name.compareToAscii("IsReadOnly") == 0)
856cdf0e10cSrcweir xRow->appendBoolean(seqProp[i],
857cdf0e10cSrcweir aDirEntry.m_nMode
858cdf0e10cSrcweir & INETCOREFTP_FILEMODE_WRITE
859cdf0e10cSrcweir ? 0
860cdf0e10cSrcweir : 1 );
861cdf0e10cSrcweir else if(Name.compareToAscii("IsDocument") == 0)
862cdf0e10cSrcweir xRow->appendBoolean(seqProp[i],
863cdf0e10cSrcweir ! sal_Bool(aDirEntry.m_nMode &
864cdf0e10cSrcweir INETCOREFTP_FILEMODE_ISDIR));
865cdf0e10cSrcweir else if(Name.compareToAscii("IsFolder") == 0)
866cdf0e10cSrcweir xRow->appendBoolean(seqProp[i],
867cdf0e10cSrcweir sal_Bool(aDirEntry.m_nMode &
868cdf0e10cSrcweir INETCOREFTP_FILEMODE_ISDIR));
869cdf0e10cSrcweir else if(Name.compareToAscii("Size") == 0)
870cdf0e10cSrcweir xRow->appendLong(seqProp[i],
871cdf0e10cSrcweir aDirEntry.m_nSize);
872cdf0e10cSrcweir else if(Name.compareToAscii("DateCreated") == 0)
873cdf0e10cSrcweir xRow->appendTimestamp(seqProp[i],
874cdf0e10cSrcweir aDirEntry.m_aDate);
875cdf0e10cSrcweir else
876cdf0e10cSrcweir xRow->appendVoid(seqProp[i]);
877cdf0e10cSrcweir } else
878cdf0e10cSrcweir xRow->appendVoid(seqProp[i]);
879cdf0e10cSrcweir }
880cdf0e10cSrcweir
881cdf0e10cSrcweir return Reference<XRow>(xRow.get());
882cdf0e10cSrcweir }
883cdf0e10cSrcweir
884cdf0e10cSrcweir
885cdf0e10cSrcweir
setPropertyValues(const Sequence<PropertyValue> & seqPropVal)886cdf0e10cSrcweir Sequence<Any> FTPContent::setPropertyValues(
887cdf0e10cSrcweir const Sequence<PropertyValue>& seqPropVal)
888cdf0e10cSrcweir {
889cdf0e10cSrcweir Sequence<Any> ret(seqPropVal.getLength());
890cdf0e10cSrcweir Sequence<PropertyChangeEvent > evt;
891cdf0e10cSrcweir
892cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex);
893cdf0e10cSrcweir for(sal_Int32 i = 0; i < ret.getLength(); ++i) {
894cdf0e10cSrcweir if(seqPropVal[i].Name.equalsAscii("Title")) {
895cdf0e10cSrcweir rtl::OUString Title;
896cdf0e10cSrcweir if(!(seqPropVal[i].Value >>= Title)) {
897cdf0e10cSrcweir ret[i] <<= IllegalTypeException();
898cdf0e10cSrcweir continue;
899cdf0e10cSrcweir } else if(!Title.getLength()) {
900cdf0e10cSrcweir ret[i] <<= IllegalArgumentException();
901cdf0e10cSrcweir continue;
902cdf0e10cSrcweir }
903cdf0e10cSrcweir
904cdf0e10cSrcweir if(m_bInserted) {
905cdf0e10cSrcweir m_aFTPURL.child(Title);
906cdf0e10cSrcweir m_xIdentifier =
907cdf0e10cSrcweir new FTPContentIdentifier(m_aFTPURL.ident(false,false));
908cdf0e10cSrcweir m_bTitleSet = true;
909cdf0e10cSrcweir } else
910cdf0e10cSrcweir try {
911cdf0e10cSrcweir rtl::OUString OldTitle = m_aFTPURL.ren(Title);
912cdf0e10cSrcweir evt.realloc(1);
913cdf0e10cSrcweir evt[0].PropertyName =
914cdf0e10cSrcweir rtl::OUString::createFromAscii("Title");
915cdf0e10cSrcweir evt[0].Further = false;
916cdf0e10cSrcweir evt[0].PropertyHandle = -1;
917cdf0e10cSrcweir evt[0].OldValue <<= OldTitle;
918cdf0e10cSrcweir evt[0].NewValue <<= Title;
919cdf0e10cSrcweir } catch(const curl_exception&) {
920cdf0e10cSrcweir InteractiveIOException excep;
921cdf0e10cSrcweir // any better possibility here?
922cdf0e10cSrcweir // ( the error code is always CURLE_FTP_QUOTE_ERROR )
923cdf0e10cSrcweir excep.Code = IOErrorCode_ACCESS_DENIED;
924cdf0e10cSrcweir ret[i] <<= excep;
925cdf0e10cSrcweir }
926cdf0e10cSrcweir } else {
927cdf0e10cSrcweir Sequence<Property> props =
928cdf0e10cSrcweir getProperties(Reference<XCommandEnvironment>(0));
929cdf0e10cSrcweir
930cdf0e10cSrcweir // either unknown or read-only
931cdf0e10cSrcweir ret[i] <<= UnknownPropertyException();
932cdf0e10cSrcweir for(sal_Int32 j = 0; j < props.getLength(); ++j)
933cdf0e10cSrcweir if(props[j].Name == seqPropVal[i].Name) {
934cdf0e10cSrcweir ret[i] <<= IllegalAccessException(
935cdf0e10cSrcweir rtl::OUString::createFromAscii(
936cdf0e10cSrcweir "Property is read-only!"),
937cdf0e10cSrcweir //props[j].Attributes & PropertyAttribute::READONLY
938cdf0e10cSrcweir // ? "Property is read-only!"
939cdf0e10cSrcweir // : "Access denied!"),
940cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ));
941cdf0e10cSrcweir break;
942cdf0e10cSrcweir }
943cdf0e10cSrcweir }
944cdf0e10cSrcweir }
945cdf0e10cSrcweir
946cdf0e10cSrcweir if(evt.getLength()) {
947cdf0e10cSrcweir // title has changed
948cdf0e10cSrcweir notifyPropertiesChange(evt);
949cdf0e10cSrcweir exchange(new FTPContentIdentifier(m_aFTPURL.ident(false,false)));
950cdf0e10cSrcweir }
951cdf0e10cSrcweir
952cdf0e10cSrcweir return ret;
953cdf0e10cSrcweir }
954