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