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
10cdf0e10cSrcweir *
112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
202f86921cSAndrew Rist *************************************************************/
212f86921cSAndrew Rist
222f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir #include <string.h>
27cdf0e10cSrcweir #include <unistd.h>
28cdf0e10cSrcweir #include <sys/types.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "osl/time.h"
31cdf0e10cSrcweir #include <osl/diagnose.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "osl/doublecheckedlocking.h"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChangeEvent.hpp>
39cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
40cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
41cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp>
42cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
43cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
44cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
45cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
46cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
47cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp>
48cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkReadException.hpp>
49cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
50cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp>
51cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
52cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
54cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
55cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp>
56cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
57cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
58cdf0e10cSrcweir #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
59cdf0e10cSrcweir #include <com/sun/star/ucb/MissingInputStreamException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp>
61cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
62cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
63cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
64cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
65cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
66cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
67cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
68cdf0e10cSrcweir #include <ucbhelper/propertyvalueset.hxx>
69cdf0e10cSrcweir #include <ucbhelper/interactionrequest.hxx>
70cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
71cdf0e10cSrcweir #include <ucbhelper/simpleauthenticationrequest.hxx>
72cdf0e10cSrcweir
73cdf0e10cSrcweir const int TRANSFER_BUFFER_SIZE = 65536;
74cdf0e10cSrcweir
75cdf0e10cSrcweir /*
76cdf0e10cSrcweir * NB. Name escaping is done only for URIs
77cdf0e10cSrcweir * the 'Title' property is unescaped on set/get
78cdf0e10cSrcweir */
79cdf0e10cSrcweir #include <libgnomevfs/gnome-vfs-utils.h>
80cdf0e10cSrcweir #include <libgnomevfs/gnome-vfs-result.h>
81cdf0e10cSrcweir #include <libgnomevfs/gnome-vfs-standard-callbacks.h>
82cdf0e10cSrcweir extern "C" { // missing in the header: doh.
83cdf0e10cSrcweir # include <libgnomevfs/gnome-vfs-module-callback.h>
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir #include "gvfs_content.hxx"
87cdf0e10cSrcweir #include "gvfs_provider.hxx"
88cdf0e10cSrcweir #include "gvfs_directory.hxx"
89cdf0e10cSrcweir #include "gvfs_stream.hxx"
90cdf0e10cSrcweir
91cdf0e10cSrcweir using namespace gvfs;
92cdf0e10cSrcweir using namespace com::sun::star;
93cdf0e10cSrcweir
94cdf0e10cSrcweir #define CLEAR_INFO(info) memset((info), 0, sizeof ((info)[0]))
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweir static char *
OUStringToGnome(const rtl::OUString & str)98cdf0e10cSrcweir OUStringToGnome( const rtl::OUString &str )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir rtl::OString aTempStr = rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 );
101*24c56ab9SHerbert Dürr return g_strdup( aTempStr.getStr() );
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir static rtl::OUString
GnomeToOUString(const char * utf8_str)105cdf0e10cSrcweir GnomeToOUString( const char *utf8_str)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if (!utf8_str)
108cdf0e10cSrcweir return rtl::OUString();
109cdf0e10cSrcweir else
110cdf0e10cSrcweir return rtl::OUString( utf8_str, strlen( utf8_str ), RTL_TEXTENCODING_UTF8 );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir
Content(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,ContentProvider * pProvider,const uno::Reference<ucb::XContentIdentifier> & Identifier)114cdf0e10cSrcweir Content::Content(
115cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
116cdf0e10cSrcweir ContentProvider* pProvider,
117cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier)
118cdf0e10cSrcweir throw ( ucb::ContentCreationException )
119cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
120cdf0e10cSrcweir m_pProvider( pProvider ),
121cdf0e10cSrcweir m_bTransient( sal_False )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir CLEAR_INFO (&m_info);
124cdf0e10cSrcweir #ifdef DEBUG
125cdf0e10cSrcweir g_warning ("New Content ('%s')", getURI());
126cdf0e10cSrcweir #endif
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
Content(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,ContentProvider * pProvider,const uno::Reference<ucb::XContentIdentifier> & Identifier,sal_Bool IsFolder)129cdf0e10cSrcweir Content::Content(
130cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
131cdf0e10cSrcweir ContentProvider * pProvider,
132cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier,
133cdf0e10cSrcweir sal_Bool IsFolder)
134cdf0e10cSrcweir throw ( ucb::ContentCreationException )
135cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
136cdf0e10cSrcweir m_pProvider( pProvider ),
137cdf0e10cSrcweir m_bTransient( sal_True )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir CLEAR_INFO (&m_info);
140cdf0e10cSrcweir
141cdf0e10cSrcweir #ifdef DEBUG
142cdf0e10cSrcweir g_warning ("New Transient content ('%s') (%d)", getURI(), IsFolder);
143cdf0e10cSrcweir #endif
144cdf0e10cSrcweir // m_info.name = FIXME: set name ?
145cdf0e10cSrcweir m_info.valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE;
146cdf0e10cSrcweir m_info.type = IsFolder ? GNOME_VFS_FILE_TYPE_DIRECTORY :
147cdf0e10cSrcweir GNOME_VFS_FILE_TYPE_REGULAR;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir // virtual
~Content()151cdf0e10cSrcweir Content::~Content()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir gnome_vfs_file_info_clear( &m_info );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir //
157cdf0e10cSrcweir // XInterface methods.
158cdf0e10cSrcweir //
159cdf0e10cSrcweir
acquire()160cdf0e10cSrcweir void SAL_CALL Content::acquire()
161cdf0e10cSrcweir throw( )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir ContentImplHelper::acquire();
164cdf0e10cSrcweir }
release()165cdf0e10cSrcweir void SAL_CALL Content::release()
166cdf0e10cSrcweir throw( )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir ContentImplHelper::release();
169cdf0e10cSrcweir }
queryInterface(const uno::Type & rType)170cdf0e10cSrcweir uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
171cdf0e10cSrcweir throw ( uno::RuntimeException )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir // Note: isFolder may require network activities! So call it only
174cdf0e10cSrcweir // if it is really necessary!!!
175cdf0e10cSrcweir uno::Any aRet = cppu::queryInterface( rType,
176cdf0e10cSrcweir static_cast< ucb::XContentCreator * >( this ) );
177cdf0e10cSrcweir if ( aRet.hasValue() )
178cdf0e10cSrcweir return isFolder( uno::Reference< ucb::XCommandEnvironment >() )
179cdf0e10cSrcweir ? aRet : uno::Any();
180cdf0e10cSrcweir else
181cdf0e10cSrcweir return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir //
185cdf0e10cSrcweir // XTypeProvider methods.
186cdf0e10cSrcweir //
187cdf0e10cSrcweir
188cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( Content );
189cdf0e10cSrcweir
getTypes()190cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
191cdf0e10cSrcweir throw( uno::RuntimeException )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir static cppu::OTypeCollection *pFolderCollection = NULL;
194cdf0e10cSrcweir static cppu::OTypeCollection *pFileCollection = NULL;
195cdf0e10cSrcweir
196cdf0e10cSrcweir if (!pFolderCollection) {
197cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
198cdf0e10cSrcweir
199cdf0e10cSrcweir if (!pFolderCollection) {
200cdf0e10cSrcweir static cppu::OTypeCollection aFolderCollection
201cdf0e10cSrcweir (CPPU_TYPE_REF( lang::XTypeProvider ),
202cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ),
203cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ),
204cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ),
205cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ),
206cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
207cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
208cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ),
209cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
210cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ),
211cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContentCreator ) ); // !!
212cdf0e10cSrcweir static cppu::OTypeCollection aFileCollection
213cdf0e10cSrcweir (CPPU_TYPE_REF( lang::XTypeProvider ),
214cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ),
215cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ),
216cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ),
217cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ),
218cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
219cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
220cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ),
221cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
222cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ) );
223cdf0e10cSrcweir
224cdf0e10cSrcweir pFolderCollection = &aFolderCollection;
225cdf0e10cSrcweir pFileCollection = &aFileCollection;
226cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir else {
230cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
233cdf0e10cSrcweir if ( isFolder( uno::Reference< ucb::XCommandEnvironment >() ) )
234cdf0e10cSrcweir return pFolderCollection->getTypes();
235cdf0e10cSrcweir else
236cdf0e10cSrcweir return pFileCollection->getTypes();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir //
240cdf0e10cSrcweir // XServiceInfo methods.
241cdf0e10cSrcweir //
242cdf0e10cSrcweir
getImplementationName()243cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getImplementationName()
244cdf0e10cSrcweir throw( uno::RuntimeException )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir return rtl::OUString::createFromAscii("com.sun.star.comp.GnomeVFSContent" );
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
getSupportedServiceNames()249cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
250cdf0e10cSrcweir throw( uno::RuntimeException )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSNS( 1 );
253cdf0e10cSrcweir aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii(
254cdf0e10cSrcweir "com.sun.star.ucb.GnomeVFSContent" );
255cdf0e10cSrcweir return aSNS;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir
258cdf0e10cSrcweir //
259cdf0e10cSrcweir // XContent methods.
260cdf0e10cSrcweir //
261cdf0e10cSrcweir
getContentType()262cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getContentType()
263cdf0e10cSrcweir throw( uno::RuntimeException )
264cdf0e10cSrcweir {
265cdf0e10cSrcweir if ( isFolder( uno::Reference< ucb::XCommandEnvironment >() ) )
266cdf0e10cSrcweir return rtl::OUString::createFromAscii( GVFS_FOLDER_TYPE );
267cdf0e10cSrcweir else
268cdf0e10cSrcweir return rtl::OUString::createFromAscii( GVFS_FILE_TYPE );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir //
272cdf0e10cSrcweir // XCommandProcessor methods.
273cdf0e10cSrcweir //
274cdf0e10cSrcweir
getBadArgExcept()275cdf0e10cSrcweir uno::Any Content::getBadArgExcept()
276cdf0e10cSrcweir {
277cdf0e10cSrcweir return uno::makeAny( lang::IllegalArgumentException
278cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Wrong argument type!" ),
279cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
280cdf0e10cSrcweir -1 ) );
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
283cdf0e10cSrcweir #include <stdio.h>
284cdf0e10cSrcweir
execute(const ucb::Command & aCommand,sal_Int32,const uno::Reference<ucb::XCommandEnvironment> & xEnv)285cdf0e10cSrcweir uno::Any SAL_CALL Content::execute(
286cdf0e10cSrcweir const ucb::Command& aCommand,
287cdf0e10cSrcweir sal_Int32 /*CommandId*/,
288cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
289cdf0e10cSrcweir throw( uno::Exception,
290cdf0e10cSrcweir ucb::CommandAbortedException,
291cdf0e10cSrcweir uno::RuntimeException )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir uno::Any aRet;
294cdf0e10cSrcweir
295cdf0e10cSrcweir #ifdef DEBUG
296cdf0e10cSrcweir {
297cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH;
298cdf0e10cSrcweir
299cdf0e10cSrcweir if ( xEnv.is() )
300cdf0e10cSrcweir xIH = xEnv->getInteractionHandler();
301cdf0e10cSrcweir g_warning( "Execute command: '%s' with %s interaction env",
302cdf0e10cSrcweir OUStringToGnome( aCommand.Name ),
303cdf0e10cSrcweir xIH.is() ? "" : "NO" );
304cdf0e10cSrcweir }
305cdf0e10cSrcweir #endif
306cdf0e10cSrcweir
307cdf0e10cSrcweir #define COMMAND_IS(cmd,name) ( (cmd).Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( name ) ) )
308cdf0e10cSrcweir
309cdf0e10cSrcweir if ( COMMAND_IS( aCommand, "getPropertyValues" ) ) {
310cdf0e10cSrcweir uno::Sequence< beans::Property > Properties;
311cdf0e10cSrcweir
312cdf0e10cSrcweir if ( !( aCommand.Argument >>= Properties ) )
313cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv );
314cdf0e10cSrcweir
315cdf0e10cSrcweir aRet <<= getPropertyValues( Properties, xEnv );
316cdf0e10cSrcweir
317cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "setPropertyValues" ) ) {
318cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProperties;
319cdf0e10cSrcweir
320cdf0e10cSrcweir if ( !( aCommand.Argument >>= aProperties ) ||
321cdf0e10cSrcweir !aProperties.getLength() )
322cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv );
323cdf0e10cSrcweir
324cdf0e10cSrcweir aRet <<= setPropertyValues( aProperties, xEnv );
325cdf0e10cSrcweir
326cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "getPropertySetInfo" ) ) {
327cdf0e10cSrcweir aRet <<= getPropertySetInfo( xEnv, sal_False );
328cdf0e10cSrcweir
329cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "getCommandInfo" ) ) {
330cdf0e10cSrcweir aRet <<= getCommandInfo( xEnv, sal_False );
331cdf0e10cSrcweir
332cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "open" ) ) {
333cdf0e10cSrcweir rtl::OUString str = m_xIdentifier->getContentIdentifier();
334cdf0e10cSrcweir rtl::OString stra(
335cdf0e10cSrcweir str.getStr(),
336cdf0e10cSrcweir str.getLength(),
337cdf0e10cSrcweir RTL_TEXTENCODING_UTF8);
338cdf0e10cSrcweir
339cdf0e10cSrcweir ucb::OpenCommandArgument2 aOpenCommand;
340cdf0e10cSrcweir if ( !( aCommand.Argument >>= aOpenCommand ) )
341cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv );
342cdf0e10cSrcweir
343cdf0e10cSrcweir sal_Bool bOpenFolder =
344cdf0e10cSrcweir ( ( aOpenCommand.Mode == ucb::OpenMode::ALL ) ||
345cdf0e10cSrcweir ( aOpenCommand.Mode == ucb::OpenMode::FOLDERS ) ||
346cdf0e10cSrcweir ( aOpenCommand.Mode == ucb::OpenMode::DOCUMENTS ) );
347cdf0e10cSrcweir
348cdf0e10cSrcweir if ( bOpenFolder && isFolder( xEnv ) ) {
349cdf0e10cSrcweir uno::Reference< ucb::XDynamicResultSet > xSet
350cdf0e10cSrcweir = new DynamicResultSet(m_xSMgr, this, aOpenCommand, xEnv );
351cdf0e10cSrcweir aRet <<= xSet;
352cdf0e10cSrcweir
353cdf0e10cSrcweir } else if ( aOpenCommand.Sink.is() ) {
354cdf0e10cSrcweir
355cdf0e10cSrcweir if ( ( aOpenCommand.Mode
356cdf0e10cSrcweir == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
357cdf0e10cSrcweir ( aOpenCommand.Mode
358cdf0e10cSrcweir == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) ) {
359cdf0e10cSrcweir ucbhelper::cancelCommandExecution
360cdf0e10cSrcweir ( uno::makeAny ( ucb::UnsupportedOpenModeException
361cdf0e10cSrcweir ( rtl::OUString(),
362cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
363cdf0e10cSrcweir sal_Int16( aOpenCommand.Mode ) ) ),
364cdf0e10cSrcweir xEnv );
365cdf0e10cSrcweir }
366cdf0e10cSrcweir if ( !feedSink( aOpenCommand.Sink, xEnv ) ) {
367cdf0e10cSrcweir // Note: aOpenCommand.Sink may contain an XStream
368cdf0e10cSrcweir // implementation. Support for this type of
369cdf0e10cSrcweir // sink is optional...
370cdf0e10cSrcweir #ifdef DEBUG
371cdf0e10cSrcweir g_warning ("Failed to load data from '%s'", getURI());
372cdf0e10cSrcweir #endif
373cdf0e10cSrcweir ucbhelper::cancelCommandExecution
374cdf0e10cSrcweir ( uno::makeAny (ucb::UnsupportedDataSinkException
375cdf0e10cSrcweir ( rtl::OUString(),
376cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
377cdf0e10cSrcweir aOpenCommand.Sink ) ),
378cdf0e10cSrcweir xEnv );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir }
381cdf0e10cSrcweir #ifdef DEBUG
382cdf0e10cSrcweir else
383cdf0e10cSrcweir g_warning ("Open falling through ...");
384cdf0e10cSrcweir #endif
385cdf0e10cSrcweir
386cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "createNewContent" ) && isFolder( xEnv ) ) {
387cdf0e10cSrcweir ucb::ContentInfo arg;
388cdf0e10cSrcweir if ( !( aCommand.Argument >>= arg ) )
389cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv );
390cdf0e10cSrcweir
391cdf0e10cSrcweir aRet <<= createNewContent( arg );
392cdf0e10cSrcweir
393cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "insert" ) ) {
394cdf0e10cSrcweir ucb::InsertCommandArgument arg;
395cdf0e10cSrcweir if ( !( aCommand.Argument >>= arg ) )
396cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv );
397cdf0e10cSrcweir
398cdf0e10cSrcweir insert( arg.Data, arg.ReplaceExisting, xEnv );
399cdf0e10cSrcweir
400cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "delete" ) ) {
401cdf0e10cSrcweir
402cdf0e10cSrcweir sal_Bool bDeletePhysical = sal_False;
403cdf0e10cSrcweir aCommand.Argument >>= bDeletePhysical;
404cdf0e10cSrcweir
405cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
406*24c56ab9SHerbert Dürr GnomeVFSResult result = gnome_vfs_unlink( aURI.getStr());
407cdf0e10cSrcweir
408cdf0e10cSrcweir if (result != GNOME_VFS_OK)
409cdf0e10cSrcweir cancelCommandExecution( result, xEnv, sal_True );
410cdf0e10cSrcweir
411cdf0e10cSrcweir destroy( bDeletePhysical );
412cdf0e10cSrcweir
413cdf0e10cSrcweir } else if ( COMMAND_IS( aCommand, "transfer" ) && isFolder( xEnv ) ) {
414cdf0e10cSrcweir ucb::TransferInfo transferArgs;
415cdf0e10cSrcweir
416cdf0e10cSrcweir if ( !( aCommand.Argument >>= transferArgs ) )
417cdf0e10cSrcweir ucbhelper::cancelCommandExecution( getBadArgExcept(), xEnv );
418cdf0e10cSrcweir
419cdf0e10cSrcweir transfer( transferArgs, xEnv );
420cdf0e10cSrcweir
421cdf0e10cSrcweir } else { // Unsuported
422cdf0e10cSrcweir #ifdef DEBUG
423cdf0e10cSrcweir g_warning( "Unsupported command: '%s'",
424cdf0e10cSrcweir OUStringToGnome( aCommand.Name ) );
425cdf0e10cSrcweir #endif
426cdf0e10cSrcweir ucbhelper::cancelCommandExecution
427cdf0e10cSrcweir ( uno::makeAny( ucb::UnsupportedCommandException
428cdf0e10cSrcweir ( rtl::OUString(),
429cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
430cdf0e10cSrcweir xEnv );
431cdf0e10cSrcweir }
432cdf0e10cSrcweir #undef COMMAND_IS
433cdf0e10cSrcweir
434cdf0e10cSrcweir return aRet;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir
abort(sal_Int32)437cdf0e10cSrcweir void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
438cdf0e10cSrcweir throw( uno::RuntimeException )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir // FIXME: we should use the GnomeVFSCancellation APIs here ...
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
443cdf0e10cSrcweir //
444cdf0e10cSrcweir // XContentCreator methods.
445cdf0e10cSrcweir //
446cdf0e10cSrcweir
queryCreatableContentsInfo(const uno::Reference<ucb::XCommandEnvironment> & xEnv)447cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > Content::queryCreatableContentsInfo(
448cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv)
449cdf0e10cSrcweir throw( uno::RuntimeException )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir if ( isFolder( xEnv ) )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > seq(2);
454cdf0e10cSrcweir
455cdf0e10cSrcweir // Minimum set of props we really need
456cdf0e10cSrcweir uno::Sequence< beans::Property > props( 1 );
457cdf0e10cSrcweir props[0] = beans::Property(
458cdf0e10cSrcweir rtl::OUString::createFromAscii( "Title" ),
459cdf0e10cSrcweir -1,
460cdf0e10cSrcweir getCppuType( static_cast< rtl::OUString* >( 0 ) ),
461cdf0e10cSrcweir beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::BOUND );
462cdf0e10cSrcweir
463cdf0e10cSrcweir // file
464cdf0e10cSrcweir seq[0].Type = rtl::OUString::createFromAscii( GVFS_FILE_TYPE );
465cdf0e10cSrcweir seq[0].Attributes = ( ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM |
466cdf0e10cSrcweir ucb::ContentInfoAttribute::KIND_DOCUMENT );
467cdf0e10cSrcweir seq[0].Properties = props;
468cdf0e10cSrcweir
469cdf0e10cSrcweir // folder
470cdf0e10cSrcweir seq[1].Type = rtl::OUString::createFromAscii( GVFS_FOLDER_TYPE );
471cdf0e10cSrcweir seq[1].Attributes = ucb::ContentInfoAttribute::KIND_FOLDER;
472cdf0e10cSrcweir seq[1].Properties = props;
473cdf0e10cSrcweir
474cdf0e10cSrcweir return seq;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir else
477cdf0e10cSrcweir {
478cdf0e10cSrcweir return uno::Sequence< ucb::ContentInfo >();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
queryCreatableContentsInfo()482cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL Content::queryCreatableContentsInfo()
483cdf0e10cSrcweir throw( uno::RuntimeException )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir return queryCreatableContentsInfo( uno::Reference< ucb::XCommandEnvironment >() );
486cdf0e10cSrcweir }
487cdf0e10cSrcweir
488cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL
createNewContent(const ucb::ContentInfo & Info)489cdf0e10cSrcweir Content::createNewContent( const ucb::ContentInfo& Info )
490cdf0e10cSrcweir throw( uno::RuntimeException )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir bool create_document;
493cdf0e10cSrcweir const char *name;
494cdf0e10cSrcweir
495cdf0e10cSrcweir if ( Info.Type.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( GVFS_FILE_TYPE ) ) )
496cdf0e10cSrcweir create_document = true;
497cdf0e10cSrcweir else if ( Info.Type.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( GVFS_FOLDER_TYPE ) ) )
498cdf0e10cSrcweir create_document = false;
499cdf0e10cSrcweir else {
500cdf0e10cSrcweir #ifdef DEBUG
501cdf0e10cSrcweir g_warning( "Failed to create new content '%s'",
502cdf0e10cSrcweir OUStringToGnome( Info.Type ) );
503cdf0e10cSrcweir #endif
504cdf0e10cSrcweir return uno::Reference< ucb::XContent >();
505cdf0e10cSrcweir }
506cdf0e10cSrcweir
507cdf0e10cSrcweir #ifdef DEBUG
508cdf0e10cSrcweir g_warning( "createNewContent (%d)", (int) create_document );
509cdf0e10cSrcweir #endif
510cdf0e10cSrcweir
511cdf0e10cSrcweir rtl::OUString aURL = getOUURI();
512cdf0e10cSrcweir
513cdf0e10cSrcweir if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() )
514cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" );
515cdf0e10cSrcweir
516cdf0e10cSrcweir name = create_document ? "[New_Content]" : "[New_Collection]";
517cdf0e10cSrcweir // This looks problematic to me cf. webdav
518cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( name );
519cdf0e10cSrcweir
520cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId
521cdf0e10cSrcweir ( new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ) );
522cdf0e10cSrcweir
523cdf0e10cSrcweir try {
524cdf0e10cSrcweir return new ::gvfs::Content( m_xSMgr, m_pProvider, xId, !create_document );
525cdf0e10cSrcweir } catch ( ucb::ContentCreationException & ) {
526cdf0e10cSrcweir return uno::Reference< ucb::XContent >();
527cdf0e10cSrcweir }
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
getParentURL()530cdf0e10cSrcweir rtl::OUString Content::getParentURL()
531cdf0e10cSrcweir {
532cdf0e10cSrcweir rtl::OUString aParentURL;
533cdf0e10cSrcweir // <scheme>:// -> ""
534cdf0e10cSrcweir // <scheme>://foo -> ""
535cdf0e10cSrcweir // <scheme>://foo/ -> ""
536cdf0e10cSrcweir // <scheme>://foo/bar -> <scheme>://foo/
537cdf0e10cSrcweir // <scheme>://foo/bar/ -> <scheme>://foo/
538cdf0e10cSrcweir // <scheme>://foo/bar/abc -> <scheme>://foo/bar/
539cdf0e10cSrcweir
540cdf0e10cSrcweir rtl::OUString aURL = getOUURI();
541cdf0e10cSrcweir
542cdf0e10cSrcweir sal_Int32 nPos = aURL.lastIndexOf( '/' );
543cdf0e10cSrcweir if ( nPos == ( aURL.getLength() - 1 ) ) {
544cdf0e10cSrcweir // Trailing slash found. Skip.
545cdf0e10cSrcweir nPos = aURL.lastIndexOf( '/', nPos );
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
548cdf0e10cSrcweir sal_Int32 nPos1 = aURL.lastIndexOf( '/', nPos );
549cdf0e10cSrcweir if ( nPos1 != -1 )
550cdf0e10cSrcweir nPos1 = aURL.lastIndexOf( '/', nPos1 );
551cdf0e10cSrcweir
552cdf0e10cSrcweir if ( nPos1 != -1 )
553cdf0e10cSrcweir aParentURL = rtl::OUString( aURL.copy( 0, nPos + 1 ) );
554cdf0e10cSrcweir
555cdf0e10cSrcweir #ifdef DEBUG
556cdf0e10cSrcweir g_warning ("getParentURL '%s' -> '%s'",
557*24c56ab9SHerbert Dürr getURI(), rtl::OUStringToOString( aParentURL, RTL_TEXTENCODING_UTF8).getStr() );
558cdf0e10cSrcweir #endif
559cdf0e10cSrcweir
560cdf0e10cSrcweir return aParentURL;
561cdf0e10cSrcweir }
562cdf0e10cSrcweir
563cdf0e10cSrcweir static util::DateTime
getDateFromUnix(time_t t)564cdf0e10cSrcweir getDateFromUnix (time_t t)
565cdf0e10cSrcweir {
566cdf0e10cSrcweir TimeValue tv;
567cdf0e10cSrcweir tv.Nanosec = 0;
568cdf0e10cSrcweir tv.Seconds = t;
569cdf0e10cSrcweir oslDateTime dt;
570cdf0e10cSrcweir
571cdf0e10cSrcweir if ( osl_getDateTimeFromTimeValue( &tv, &dt ) )
572cdf0e10cSrcweir return util::DateTime( 0, dt.Seconds, dt.Minutes, dt.Hours,
573cdf0e10cSrcweir dt.Day, dt.Month, dt.Year);
574cdf0e10cSrcweir else
575cdf0e10cSrcweir return util::DateTime();
576cdf0e10cSrcweir }
577cdf0e10cSrcweir
getPropertyValues(const uno::Sequence<beans::Property> & rProperties,const uno::Reference<ucb::XCommandEnvironment> & xEnv)578cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues(
579cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties,
580cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
581cdf0e10cSrcweir {
582cdf0e10cSrcweir int nProps;
583cdf0e10cSrcweir GnomeVFSResult result;
584cdf0e10cSrcweir uno::Sequence< beans::Property > allProperties;
585cdf0e10cSrcweir
586cdf0e10cSrcweir if( ( result = getInfo( xEnv ) ) != GNOME_VFS_OK )
587cdf0e10cSrcweir cancelCommandExecution( result, xEnv, sal_False );
588cdf0e10cSrcweir
589cdf0e10cSrcweir const beans::Property* pProps;
590cdf0e10cSrcweir
591cdf0e10cSrcweir if( rProperties.getLength() ) {
592cdf0e10cSrcweir nProps = rProperties.getLength();
593cdf0e10cSrcweir pProps = rProperties.getConstArray();
594cdf0e10cSrcweir } else {
595cdf0e10cSrcweir allProperties = getPropertySetInfo( xEnv )->getProperties();
596cdf0e10cSrcweir nProps = allProperties.getLength();
597cdf0e10cSrcweir pProps = allProperties.getConstArray();
598cdf0e10cSrcweir }
599cdf0e10cSrcweir
600cdf0e10cSrcweir rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
601cdf0e10cSrcweir = new ::ucbhelper::PropertyValueSet( m_xSMgr );
602cdf0e10cSrcweir
603cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
604cdf0e10cSrcweir for( sal_Int32 n = 0; n < nProps; ++n ) {
605cdf0e10cSrcweir const beans::Property& rProp = pProps[ n ];
606cdf0e10cSrcweir
607cdf0e10cSrcweir if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) {
608cdf0e10cSrcweir if (m_info.name && m_info.name[0] == '/')
609cdf0e10cSrcweir g_warning ("Odd NFS title on item '%s' == '%s'",
610cdf0e10cSrcweir getURI(), m_info.name);
611cdf0e10cSrcweir xRow->appendString( rProp, GnomeToOUString( m_info.name ) );
612cdf0e10cSrcweir }
613cdf0e10cSrcweir
614cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
615cdf0e10cSrcweir xRow->appendString( rProp, getContentType () );
616cdf0e10cSrcweir
617cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ) {
618cdf0e10cSrcweir if (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE)
619cdf0e10cSrcweir xRow->appendBoolean( rProp, ( m_info.type == GNOME_VFS_FILE_TYPE_REGULAR ||
620cdf0e10cSrcweir m_info.type == GNOME_VFS_FILE_TYPE_UNKNOWN ) );
621cdf0e10cSrcweir else
622cdf0e10cSrcweir xRow->appendVoid( rProp );
623cdf0e10cSrcweir }
624cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ) {
625cdf0e10cSrcweir if (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE)
626cdf0e10cSrcweir xRow->appendBoolean( rProp, ( m_info.type == GNOME_VFS_FILE_TYPE_DIRECTORY ) );
627cdf0e10cSrcweir else
628cdf0e10cSrcweir xRow->appendVoid( rProp );
629cdf0e10cSrcweir }
630cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsReadOnly" ) ) ) {
631cdf0e10cSrcweir
632cdf0e10cSrcweir GnomeVFSFileInfo* fileInfo = gnome_vfs_file_info_new ();
633cdf0e10cSrcweir
634cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
635*24c56ab9SHerbert Dürr gnome_vfs_get_file_info( aURI.getStr(), fileInfo,
636cdf0e10cSrcweir GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS );
637cdf0e10cSrcweir
638cdf0e10cSrcweir if (fileInfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
639cdf0e10cSrcweir bool read_only = true;
640cdf0e10cSrcweir
641cdf0e10cSrcweir if (fileInfo->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE)
642cdf0e10cSrcweir read_only = false;
643cdf0e10cSrcweir
644cdf0e10cSrcweir xRow->appendBoolean( rProp, read_only );
645cdf0e10cSrcweir } else
646cdf0e10cSrcweir xRow->appendVoid( rProp );
647cdf0e10cSrcweir gnome_vfs_file_info_unref (fileInfo);
648cdf0e10cSrcweir }
649cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) {
650cdf0e10cSrcweir if (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)
651cdf0e10cSrcweir xRow->appendLong( rProp, m_info.size );
652cdf0e10cSrcweir else
653cdf0e10cSrcweir xRow->appendVoid( rProp );
654cdf0e10cSrcweir }
655cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsHidden" ) ) )
656cdf0e10cSrcweir xRow->appendBoolean( rProp, ( m_info.name && m_info.name[0] == '.' ) );
657cdf0e10cSrcweir
658cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsVolume" ) ) ||
659cdf0e10cSrcweir rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsCompactDisk" ) ) )
660cdf0e10cSrcweir xRow->appendBoolean( rProp, sal_False );
661cdf0e10cSrcweir
662cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) ) {
663cdf0e10cSrcweir if (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_CTIME)
664cdf0e10cSrcweir xRow->appendTimestamp( rProp, getDateFromUnix( m_info.ctime ) );
665cdf0e10cSrcweir else
666cdf0e10cSrcweir xRow->appendVoid( rProp );
667cdf0e10cSrcweir }
668cdf0e10cSrcweir
669cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) ) {
670cdf0e10cSrcweir if (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
671cdf0e10cSrcweir xRow->appendTimestamp( rProp, getDateFromUnix( m_info.mtime ) );
672cdf0e10cSrcweir else
673cdf0e10cSrcweir xRow->appendVoid( rProp );
674cdf0e10cSrcweir }
675cdf0e10cSrcweir
676cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) {
677cdf0e10cSrcweir // We do this by sniffing in gnome-vfs; rather expensively.
678cdf0e10cSrcweir #ifdef DEBUG
679cdf0e10cSrcweir g_warning ("FIXME: Requested mime-type - an expensive op. indeed!");
680cdf0e10cSrcweir #endif
681cdf0e10cSrcweir xRow->appendVoid( rProp );
682cdf0e10cSrcweir } else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
683cdf0e10cSrcweir xRow->appendObject( rProp, uno::makeAny( queryCreatableContentsInfo( xEnv ) ) );
684cdf0e10cSrcweir
685cdf0e10cSrcweir else {
686cdf0e10cSrcweir xRow->appendVoid( rProp );
687cdf0e10cSrcweir }
688cdf0e10cSrcweir }
689cdf0e10cSrcweir #ifdef DEBUG
690cdf0e10cSrcweir g_warning ("getPropertyValues on '%s' %d properties returned (of %d)",
691cdf0e10cSrcweir getURI(), (int)xRow->getLength(), (int)nProps);
692cdf0e10cSrcweir #endif
693cdf0e10cSrcweir
694cdf0e10cSrcweir return uno::Reference< sdbc::XRow >( xRow.get() );
695cdf0e10cSrcweir }
696cdf0e10cSrcweir
697cdf0e10cSrcweir static lang::IllegalAccessException
getReadOnlyException(Content * ctnt)698cdf0e10cSrcweir getReadOnlyException( Content *ctnt )
699cdf0e10cSrcweir {
700cdf0e10cSrcweir return lang::IllegalAccessException
701cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Property is read-only!" ),
702cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( ctnt ) );
703cdf0e10cSrcweir }
704cdf0e10cSrcweir
705cdf0e10cSrcweir rtl::OUString
makeNewURL(const char *)706cdf0e10cSrcweir Content::makeNewURL( const char */*newName*/ )
707cdf0e10cSrcweir {
708cdf0e10cSrcweir rtl::OUString aNewURL = getParentURL();
709cdf0e10cSrcweir if ( aNewURL.lastIndexOf( '/' ) != ( aNewURL.getLength() - 1 ) )
710cdf0e10cSrcweir aNewURL += rtl::OUString::createFromAscii( "/" );
711cdf0e10cSrcweir
712cdf0e10cSrcweir char *name = gnome_vfs_escape_string( m_info.name );
713cdf0e10cSrcweir aNewURL += GnomeToOUString( name );
714cdf0e10cSrcweir g_free( name );
715cdf0e10cSrcweir
716cdf0e10cSrcweir return aNewURL;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir
719cdf0e10cSrcweir // This is slightly complicated by needing to support either 'move' or 'setname'
720cdf0e10cSrcweir GnomeVFSResult
doSetFileInfo(const GnomeVFSFileInfo * newInfo,GnomeVFSSetFileInfoMask setMask,const uno::Reference<ucb::XCommandEnvironment> &)721cdf0e10cSrcweir Content::doSetFileInfo( const GnomeVFSFileInfo *newInfo,
722cdf0e10cSrcweir GnomeVFSSetFileInfoMask setMask,
723cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& /*xEnv*/ )
724cdf0e10cSrcweir {
725cdf0e10cSrcweir GnomeVFSResult result = GNOME_VFS_OK;
726cdf0e10cSrcweir
727cdf0e10cSrcweir g_assert (!m_bTransient);
728cdf0e10cSrcweir
729cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
730cdf0e10cSrcweir
731cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
732cdf0e10cSrcweir
733cdf0e10cSrcweir // The simple approach:
734cdf0e10cSrcweir if( setMask != GNOME_VFS_SET_FILE_INFO_NONE )
735cdf0e10cSrcweir result = gnome_vfs_set_file_info // missed a const in the API there
736*24c56ab9SHerbert Dürr ( aURI.getStr(), (GnomeVFSFileInfo *)newInfo, setMask );
737cdf0e10cSrcweir
738cdf0e10cSrcweir if ( result == GNOME_VFS_ERROR_NOT_SUPPORTED &&
739cdf0e10cSrcweir ( setMask & GNOME_VFS_SET_FILE_INFO_NAME ) ) {
740cdf0e10cSrcweir // Try a move instead
741cdf0e10cSrcweir #ifdef DEBUG
742cdf0e10cSrcweir g_warning( "SetFileInfo not supported on '%s'", getURI() );
743cdf0e10cSrcweir #endif
744cdf0e10cSrcweir
745cdf0e10cSrcweir char *newURI = OUStringToGnome( makeNewURL( newInfo->name ) );
746cdf0e10cSrcweir
747*24c56ab9SHerbert Dürr result = gnome_vfs_move( aURI.getStr(), newURI, FALSE);
748cdf0e10cSrcweir
749cdf0e10cSrcweir g_free (newURI);
750cdf0e10cSrcweir }
751cdf0e10cSrcweir
752cdf0e10cSrcweir return result;
753cdf0e10cSrcweir }
754cdf0e10cSrcweir
755cdf0e10cSrcweir
setPropertyValues(const uno::Sequence<beans::PropertyValue> & rValues,const uno::Reference<ucb::XCommandEnvironment> & xEnv)756cdf0e10cSrcweir uno::Sequence< uno::Any > Content::setPropertyValues(
757cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rValues,
758cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
759cdf0e10cSrcweir {
760cdf0e10cSrcweir rtl::OUString aNewTitle;
761cdf0e10cSrcweir GnomeVFSFileInfo newInfo;
762cdf0e10cSrcweir int setMask = GNOME_VFS_SET_FILE_INFO_NONE;
763cdf0e10cSrcweir
764cdf0e10cSrcweir getInfo( xEnv );
765cdf0e10cSrcweir
766cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
767cdf0e10cSrcweir
768cdf0e10cSrcweir gnome_vfs_file_info_copy( &newInfo, &m_info );
769cdf0e10cSrcweir
770cdf0e10cSrcweir Authentication aAuth( xEnv );
771cdf0e10cSrcweir
772cdf0e10cSrcweir int nChanged = 0, nTitlePos = 0;
773cdf0e10cSrcweir uno::Sequence< uno::Any > aRet( rValues.getLength() );
774cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
775cdf0e10cSrcweir
776cdf0e10cSrcweir beans::PropertyChangeEvent aEvent;
777cdf0e10cSrcweir aEvent.Source = static_cast< cppu::OWeakObject * >( this );
778cdf0e10cSrcweir aEvent.Further = sal_False;
779cdf0e10cSrcweir aEvent.PropertyHandle = -1;
780cdf0e10cSrcweir // aEvent.PropertyName = fill in later ...
781cdf0e10cSrcweir // aEvent.OldValue =
782cdf0e10cSrcweir // aEvent.NewValue =
783cdf0e10cSrcweir
784cdf0e10cSrcweir int nCount = rValues.getLength();
785cdf0e10cSrcweir const beans::PropertyValue* pValues = rValues.getConstArray();
786cdf0e10cSrcweir
787cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) {
788cdf0e10cSrcweir const beans::PropertyValue& rValue = pValues[ n ];
789cdf0e10cSrcweir
790cdf0e10cSrcweir #ifdef DEBUG
791cdf0e10cSrcweir g_warning( "Set prop '%s'", OUStringToGnome( rValue.Name ) );
792cdf0e10cSrcweir #endif
793cdf0e10cSrcweir if ( rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) ||
794cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ||
795cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ||
796cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ||
797cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ||
798cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
799cdf0e10cSrcweir aRet[ n ] <<= getReadOnlyException( this );
800cdf0e10cSrcweir
801cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) {
802cdf0e10cSrcweir if ( rValue.Value >>= aNewTitle ) {
803cdf0e10cSrcweir if ( aNewTitle.getLength() <= 0 )
804cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException
805cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Empty title not allowed!" ),
806cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), -1 );
807cdf0e10cSrcweir else {
808cdf0e10cSrcweir char *newName = OUStringToGnome( aNewTitle );
809cdf0e10cSrcweir
810cdf0e10cSrcweir if( !newName || !m_info.name || strcmp( newName, m_info.name ) ) {
811cdf0e10cSrcweir #ifdef DEBUG
812cdf0e10cSrcweir g_warning ("Set new name to '%s'", newName);
813cdf0e10cSrcweir #endif
814cdf0e10cSrcweir
815cdf0e10cSrcweir aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" );
816cdf0e10cSrcweir aEvent.OldValue = uno::makeAny( GnomeToOUString( newInfo.name ) );
817cdf0e10cSrcweir aEvent.NewValue = uno::makeAny( aNewTitle );
818cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent;
819cdf0e10cSrcweir nTitlePos = nChanged++;
820cdf0e10cSrcweir
821cdf0e10cSrcweir newInfo.name = newName;
822cdf0e10cSrcweir setMask |= GNOME_VFS_SET_FILE_INFO_NAME;
823cdf0e10cSrcweir } else // same name
824cdf0e10cSrcweir g_free (newName);
825cdf0e10cSrcweir }
826cdf0e10cSrcweir } else
827cdf0e10cSrcweir aRet[ n ] <<= beans::IllegalTypeException
828cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Property value has wrong type!" ),
829cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
830cdf0e10cSrcweir
831cdf0e10cSrcweir } else if ( rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) ||
832cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) ) {
833cdf0e10cSrcweir // FIXME: should be able to set the timestamps
834cdf0e10cSrcweir aRet[ n ] <<= getReadOnlyException( this );
835cdf0e10cSrcweir } else {
836cdf0e10cSrcweir #ifdef DEBUG
837cdf0e10cSrcweir g_warning( "Unhandled property '%s'", OUStringToGnome( rValue.Name ) );
838cdf0e10cSrcweir #endif
839cdf0e10cSrcweir aRet[ n ] <<= getReadOnlyException( this );
840cdf0e10cSrcweir }
841cdf0e10cSrcweir }
842cdf0e10cSrcweir
843cdf0e10cSrcweir GnomeVFSResult result = GNOME_VFS_OK;
844cdf0e10cSrcweir
845cdf0e10cSrcweir if ( !m_bTransient &&
846cdf0e10cSrcweir ( result = doSetFileInfo( &newInfo,
847cdf0e10cSrcweir (GnomeVFSSetFileInfoMask) setMask,
848cdf0e10cSrcweir xEnv ) ) != GNOME_VFS_OK ) {
849cdf0e10cSrcweir for (int i = 0; i < nChanged; i++)
850cdf0e10cSrcweir aRet[ i ] <<= mapVFSException( result, sal_True );
851cdf0e10cSrcweir
852cdf0e10cSrcweir }
853cdf0e10cSrcweir
854cdf0e10cSrcweir if ( result == GNOME_VFS_OK) {
855cdf0e10cSrcweir gnome_vfs_file_info_copy( &m_info, &newInfo );
856cdf0e10cSrcweir
857cdf0e10cSrcweir if ( setMask & GNOME_VFS_SET_FILE_INFO_NAME ) {
858cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewId
859cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier(
860cdf0e10cSrcweir m_xSMgr, makeNewURL( newInfo.name ) );
861cdf0e10cSrcweir
862cdf0e10cSrcweir aGuard.clear();
863cdf0e10cSrcweir if (!exchangeIdentity( xNewId ) )
864cdf0e10cSrcweir aRet[ nTitlePos ] <<= uno::Exception
865cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Exchange failed!" ),
866cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
867cdf0e10cSrcweir }
868cdf0e10cSrcweir }
869cdf0e10cSrcweir
870cdf0e10cSrcweir gnome_vfs_file_info_clear( &newInfo );
871cdf0e10cSrcweir
872cdf0e10cSrcweir if ( nChanged > 0 ) {
873cdf0e10cSrcweir aGuard.clear();
874cdf0e10cSrcweir aChanges.realloc( nChanged );
875cdf0e10cSrcweir notifyPropertiesChange( aChanges );
876cdf0e10cSrcweir }
877cdf0e10cSrcweir
878cdf0e10cSrcweir return aRet;
879cdf0e10cSrcweir }
880cdf0e10cSrcweir
queryChildren(ContentRefList & rChildren)881cdf0e10cSrcweir void Content::queryChildren( ContentRefList& rChildren )
882cdf0e10cSrcweir {
883cdf0e10cSrcweir // Obtain a list with a snapshot of all currently instanciated contents
884cdf0e10cSrcweir // from provider and extract the contents which are direct children
885cdf0e10cSrcweir // of this content.
886cdf0e10cSrcweir
887cdf0e10cSrcweir ::ucbhelper::ContentRefList aAllContents;
888cdf0e10cSrcweir m_xProvider->queryExistingContents( aAllContents );
889cdf0e10cSrcweir
890cdf0e10cSrcweir rtl::OUString aURL = getOUURI();
891cdf0e10cSrcweir sal_Int32 nURLPos = aURL.lastIndexOf( '/' );
892cdf0e10cSrcweir
893cdf0e10cSrcweir if ( nURLPos != ( aURL.getLength() - 1 ) )
894cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" );
895cdf0e10cSrcweir
896cdf0e10cSrcweir sal_Int32 nLen = aURL.getLength();
897cdf0e10cSrcweir
898cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
899cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
900cdf0e10cSrcweir
901cdf0e10cSrcweir while ( it != end ) {
902cdf0e10cSrcweir ::ucbhelper::ContentImplHelperRef xChild = (*it);
903cdf0e10cSrcweir rtl::OUString aChildURL
904cdf0e10cSrcweir = xChild->getIdentifier()->getContentIdentifier();
905cdf0e10cSrcweir
906cdf0e10cSrcweir // Is aURL a prefix of aChildURL?
907cdf0e10cSrcweir if ( ( aChildURL.getLength() > nLen ) &&
908cdf0e10cSrcweir ( aChildURL.compareTo( aURL, nLen ) == 0 ) ) {
909cdf0e10cSrcweir sal_Int32 nPos = nLen;
910cdf0e10cSrcweir nPos = aChildURL.indexOf( '/', nPos );
911cdf0e10cSrcweir
912cdf0e10cSrcweir if ( ( nPos == -1 ) ||
913cdf0e10cSrcweir ( nPos == ( aChildURL.getLength() - 1 ) ) ) {
914cdf0e10cSrcweir // No further slashes / only a final slash. It's a child!
915cdf0e10cSrcweir rChildren.push_back( ::gvfs::Content::ContentRef
916cdf0e10cSrcweir (static_cast< ::gvfs::Content * >(xChild.get() ) ) );
917cdf0e10cSrcweir }
918cdf0e10cSrcweir }
919cdf0e10cSrcweir ++it;
920cdf0e10cSrcweir }
921cdf0e10cSrcweir }
922cdf0e10cSrcweir
insert(const uno::Reference<io::XInputStream> & xInputStream,sal_Bool bReplaceExisting,const uno::Reference<ucb::XCommandEnvironment> & xEnv)923cdf0e10cSrcweir void Content::insert(
924cdf0e10cSrcweir const uno::Reference< io::XInputStream > &xInputStream,
925cdf0e10cSrcweir sal_Bool bReplaceExisting,
926cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > &xEnv )
927cdf0e10cSrcweir throw( uno::Exception )
928cdf0e10cSrcweir {
929cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
930cdf0e10cSrcweir
931cdf0e10cSrcweir #ifdef DEBUG
932cdf0e10cSrcweir g_warning( "Insert '%s' (%d) (0x%x:%d)", getURI(), bReplaceExisting,
933cdf0e10cSrcweir m_info.valid_fields, m_info.type );
934cdf0e10cSrcweir #endif
935cdf0e10cSrcweir
936cdf0e10cSrcweir GnomeVFSResult result = getInfo( xEnv );
937cdf0e10cSrcweir // a racy design indeed.
938cdf0e10cSrcweir if( !bReplaceExisting && !m_bTransient &&
939cdf0e10cSrcweir result != GNOME_VFS_ERROR_NOT_FOUND) {
940cdf0e10cSrcweir #ifdef DEBUG
941cdf0e10cSrcweir g_warning ("Nasty error inserting to '%s' ('%s')",
942cdf0e10cSrcweir getURI(), gnome_vfs_result_to_string( result ));
943cdf0e10cSrcweir #endif
944cdf0e10cSrcweir cancelCommandExecution( GNOME_VFS_ERROR_FILE_EXISTS, xEnv, sal_True );
945cdf0e10cSrcweir }
946cdf0e10cSrcweir
947cdf0e10cSrcweir if ( m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
948cdf0e10cSrcweir m_info.type == GNOME_VFS_FILE_TYPE_DIRECTORY ) {
949cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
950cdf0e10cSrcweir int perm;
951cdf0e10cSrcweir
952cdf0e10cSrcweir perm = ( GNOME_VFS_PERM_USER_ALL |
953cdf0e10cSrcweir GNOME_VFS_PERM_GROUP_READ |
954cdf0e10cSrcweir GNOME_VFS_PERM_OTHER_READ );
955cdf0e10cSrcweir
956cdf0e10cSrcweir #ifdef DEBUG
957cdf0e10cSrcweir g_warning ("Make directory");
958cdf0e10cSrcweir #endif
959*24c56ab9SHerbert Dürr result = gnome_vfs_make_directory( aURI.getStr(), perm );
960cdf0e10cSrcweir
961cdf0e10cSrcweir if( result != GNOME_VFS_OK )
962cdf0e10cSrcweir cancelCommandExecution( result, xEnv, sal_True );
963cdf0e10cSrcweir
964cdf0e10cSrcweir return;
965cdf0e10cSrcweir }
966cdf0e10cSrcweir
967cdf0e10cSrcweir if ( !xInputStream.is() ) {
968cdf0e10cSrcweir // FIXME: slightly unclear whether to accept this and create an empty file
969cdf0e10cSrcweir ucbhelper::cancelCommandExecution
970cdf0e10cSrcweir ( uno::makeAny
971cdf0e10cSrcweir ( ucb::MissingInputStreamException
972cdf0e10cSrcweir ( rtl::OUString(),
973cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
974cdf0e10cSrcweir xEnv );
975cdf0e10cSrcweir }
976cdf0e10cSrcweir
977cdf0e10cSrcweir GnomeVFSHandle *handle = NULL;
978cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
979cdf0e10cSrcweir
980cdf0e10cSrcweir result = GNOME_VFS_OK;
981cdf0e10cSrcweir if ( bReplaceExisting ) {
982cdf0e10cSrcweir Authentication aAuth( xEnv );
983*24c56ab9SHerbert Dürr result = gnome_vfs_open( &handle, aURI.getStr(),
984cdf0e10cSrcweir GNOME_VFS_OPEN_WRITE );
985cdf0e10cSrcweir }
986cdf0e10cSrcweir
987cdf0e10cSrcweir if ( result != GNOME_VFS_OK ) {
988cdf0e10cSrcweir int perm;
989cdf0e10cSrcweir Authentication aAuth( xEnv );
990cdf0e10cSrcweir
991cdf0e10cSrcweir perm = ( ( GNOME_VFS_PERM_USER_WRITE | GNOME_VFS_PERM_USER_READ ) |
992cdf0e10cSrcweir ( GNOME_VFS_PERM_GROUP_WRITE | GNOME_VFS_PERM_GROUP_READ ) );
993cdf0e10cSrcweir
994cdf0e10cSrcweir result = gnome_vfs_create
995*24c56ab9SHerbert Dürr ( &handle, aURI.getStr(), GNOME_VFS_OPEN_WRITE, TRUE, perm );
996cdf0e10cSrcweir }
997cdf0e10cSrcweir
998cdf0e10cSrcweir if( result != GNOME_VFS_OK )
999cdf0e10cSrcweir cancelCommandExecution( result, xEnv, sal_True );
1000cdf0e10cSrcweir
1001cdf0e10cSrcweir if ( !xInputStream.is() ) {
1002cdf0e10cSrcweir result = gnome_vfs_close( handle );
1003cdf0e10cSrcweir if (result != GNOME_VFS_OK)
1004cdf0e10cSrcweir cancelCommandExecution( result, xEnv, sal_True );
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir } else { // copy it over
1007cdf0e10cSrcweir uno::Reference < io::XOutputStream > xOutput =
1008cdf0e10cSrcweir new gvfs::Stream( handle, &m_info );
1009cdf0e10cSrcweir
1010cdf0e10cSrcweir copyData( xInputStream, xOutput );
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir if (m_bTransient) {
1014cdf0e10cSrcweir m_bTransient = sal_False;
1015cdf0e10cSrcweir aGuard.clear();
1016cdf0e10cSrcweir inserted();
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir
transfer(const ucb::TransferInfo &,const uno::Reference<ucb::XCommandEnvironment> & xEnv)1020cdf0e10cSrcweir void Content::transfer(const ucb::TransferInfo & /*rArgs*/,
1021cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1022cdf0e10cSrcweir throw( uno::Exception )
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir // FIXME: see gnome-vfs-xfer.h - but we need to be able to easily
1025cdf0e10cSrcweir // detect which are gnome-vfs owned URI types ...
1026cdf0e10cSrcweir ucbhelper::cancelCommandExecution
1027cdf0e10cSrcweir ( uno::makeAny
1028cdf0e10cSrcweir ( ucb::InteractiveBadTransferURLException
1029cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Unsupported URL scheme!" ),
1030cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
1031cdf0e10cSrcweir xEnv );
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir
destroy(sal_Bool bDeletePhysical)1034cdf0e10cSrcweir void Content::destroy( sal_Bool bDeletePhysical )
1035cdf0e10cSrcweir throw( uno::Exception )
1036cdf0e10cSrcweir {
1037cdf0e10cSrcweir // @@@ take care about bDeletePhysical -> trashcan support
1038cdf0e10cSrcweir rtl::OUString aURL = getOUURI();
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this;
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir deleted();
1043cdf0e10cSrcweir
1044cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1045cdf0e10cSrcweir
1046cdf0e10cSrcweir // Process instanciated children...
1047cdf0e10cSrcweir ::gvfs::Content::ContentRefList aChildren;
1048cdf0e10cSrcweir queryChildren( aChildren );
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin();
1051cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end();
1052cdf0e10cSrcweir
1053cdf0e10cSrcweir while ( it != end ) {
1054cdf0e10cSrcweir (*it)->destroy( bDeletePhysical );
1055cdf0e10cSrcweir ++it;
1056cdf0e10cSrcweir }
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir // Used by the 'setPropertyValues' method for
1060cdf0e10cSrcweir // propagating the renaming of a Content.
exchangeIdentity(const uno::Reference<ucb::XContentIdentifier> & xNewId)1061cdf0e10cSrcweir sal_Bool Content::exchangeIdentity(
1062cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& xNewId )
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir if ( !xNewId.is() )
1065cdf0e10cSrcweir return sal_False;
1066cdf0e10cSrcweir
1067cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this;
1068cdf0e10cSrcweir
1069cdf0e10cSrcweir #ifdef DEBUG
1070cdf0e10cSrcweir g_warning( "exchangeIdentity from '%s' to '%s'",
1071cdf0e10cSrcweir getURI(), OUStringToGnome( xNewId->getContentIdentifier() ) );
1072cdf0e10cSrcweir #endif
1073cdf0e10cSrcweir
1074cdf0e10cSrcweir if ( m_bTransient ) {
1075cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1076cdf0e10cSrcweir /* FIXME: can we not screw up an identically named
1077cdf0e10cSrcweir * Content pointing to ourself here ? */
1078cdf0e10cSrcweir m_xIdentifier = xNewId;
1079cdf0e10cSrcweir return sal_False;
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir rtl::OUString aOldURL = getOUURI();
1083cdf0e10cSrcweir
1084cdf0e10cSrcweir // Exchange own identitity.
1085cdf0e10cSrcweir if ( exchange( xNewId ) ) {
1086cdf0e10cSrcweir
1087cdf0e10cSrcweir // Process instanciated children...
1088cdf0e10cSrcweir ContentRefList aChildren;
1089cdf0e10cSrcweir queryChildren( aChildren );
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin();
1092cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end();
1093cdf0e10cSrcweir
1094cdf0e10cSrcweir while ( it != end ) {
1095cdf0e10cSrcweir ContentRef xChild = (*it);
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir // Create new content identifier for the child...
1098cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier >
1099cdf0e10cSrcweir xOldChildId = xChild->getIdentifier();
1100cdf0e10cSrcweir rtl::OUString aOldChildURL
1101cdf0e10cSrcweir = xOldChildId->getContentIdentifier();
1102cdf0e10cSrcweir rtl::OUString aNewChildURL
1103cdf0e10cSrcweir = aOldChildURL.replaceAt(
1104cdf0e10cSrcweir 0,
1105cdf0e10cSrcweir aOldURL.getLength(),
1106cdf0e10cSrcweir xNewId->getContentIdentifier() );
1107cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier >
1108cdf0e10cSrcweir xNewChildId
1109cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewChildURL );
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir if ( !xChild->exchangeIdentity( xNewChildId ) )
1112cdf0e10cSrcweir return sal_False;
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir ++it;
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir return sal_True;
1117cdf0e10cSrcweir }
1118cdf0e10cSrcweir
1119cdf0e10cSrcweir return sal_False;
1120cdf0e10cSrcweir }
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir GnomeVFSResult
getInfo(const uno::Reference<ucb::XCommandEnvironment> & xEnv)1123cdf0e10cSrcweir Content::getInfo( const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir GnomeVFSResult result;
1126cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1127cdf0e10cSrcweir
1128cdf0e10cSrcweir if (m_bTransient)
1129cdf0e10cSrcweir result = GNOME_VFS_OK;
1130cdf0e10cSrcweir
1131cdf0e10cSrcweir else if ( !m_info.valid_fields ) {
1132cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
1133cdf0e10cSrcweir Authentication aAuth( xEnv );
1134cdf0e10cSrcweir result = gnome_vfs_get_file_info
1135*24c56ab9SHerbert Dürr ( aURI.getStr(), &m_info, GNOME_VFS_FILE_INFO_DEFAULT );
1136cdf0e10cSrcweir if (result != GNOME_VFS_OK)
1137cdf0e10cSrcweir gnome_vfs_file_info_clear( &m_info );
1138cdf0e10cSrcweir } else
1139cdf0e10cSrcweir result = GNOME_VFS_OK;
1140cdf0e10cSrcweir #ifdef DEBUG
1141cdf0e10cSrcweir g_warning( "getInfo on '%s' returns '%s' (%d) (0x%x)",
1142cdf0e10cSrcweir getURI(), gnome_vfs_result_to_string( result ),
1143cdf0e10cSrcweir result, m_info.valid_fields );
1144cdf0e10cSrcweir #endif
1145cdf0e10cSrcweir return result;
1146cdf0e10cSrcweir }
1147cdf0e10cSrcweir
1148cdf0e10cSrcweir sal_Bool
isFolder(const uno::Reference<ucb::XCommandEnvironment> & xEnv)1149cdf0e10cSrcweir Content::isFolder(const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1152cdf0e10cSrcweir getInfo( xEnv );
1153cdf0e10cSrcweir return (m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
1154cdf0e10cSrcweir m_info.type == GNOME_VFS_FILE_TYPE_DIRECTORY);
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir
mapVFSException(const GnomeVFSResult result,sal_Bool bWrite)1157cdf0e10cSrcweir uno::Any Content::mapVFSException( const GnomeVFSResult result, sal_Bool bWrite )
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir uno::Any aException;
1160cdf0e10cSrcweir const char *gvfs_message;
1161cdf0e10cSrcweir rtl::OUString message;
1162cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 );
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir #ifdef DEBUG
1165cdf0e10cSrcweir g_warning ("Map VFS exception '%s' (%d)",
1166cdf0e10cSrcweir gnome_vfs_result_to_string( result ), result );
1167cdf0e10cSrcweir #endif
1168cdf0e10cSrcweir
1169cdf0e10cSrcweir if ((gvfs_message = gnome_vfs_result_to_string (result)))
1170cdf0e10cSrcweir message = GnomeToOUString( gvfs_message );
1171cdf0e10cSrcweir
1172cdf0e10cSrcweir switch (result) {
1173cdf0e10cSrcweir case GNOME_VFS_OK:
1174cdf0e10cSrcweir g_warning("VFS_OK mapped to exception.");
1175cdf0e10cSrcweir break;
1176cdf0e10cSrcweir case GNOME_VFS_ERROR_EOF:
1177cdf0e10cSrcweir g_warning ("VFS_EOF not handled somewhere.");
1178cdf0e10cSrcweir break;
1179cdf0e10cSrcweir case GNOME_VFS_ERROR_NOT_FOUND:
1180cdf0e10cSrcweir aArgs[ 0 ] <<= m_xIdentifier->getContentIdentifier();
1181cdf0e10cSrcweir aException <<=
1182cdf0e10cSrcweir ucb::InteractiveAugmentedIOException
1183cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Not found!" ),
1184cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1185cdf0e10cSrcweir task::InteractionClassification_ERROR,
1186cdf0e10cSrcweir ucb::IOErrorCode_NOT_EXISTING,
1187cdf0e10cSrcweir aArgs );
1188cdf0e10cSrcweir break;
1189cdf0e10cSrcweir case GNOME_VFS_ERROR_BAD_PARAMETERS:
1190cdf0e10cSrcweir aException <<=
1191cdf0e10cSrcweir lang::IllegalArgumentException
1192cdf0e10cSrcweir ( rtl::OUString(),
1193cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1194cdf0e10cSrcweir -1 );
1195cdf0e10cSrcweir break;
1196cdf0e10cSrcweir case GNOME_VFS_ERROR_GENERIC:
1197cdf0e10cSrcweir case GNOME_VFS_ERROR_INTERNAL:
1198cdf0e10cSrcweir case GNOME_VFS_ERROR_NOT_SUPPORTED:
1199cdf0e10cSrcweir #ifdef DEBUG
1200cdf0e10cSrcweir g_warning ("Internal - un-mapped error");
1201cdf0e10cSrcweir #endif
1202cdf0e10cSrcweir aException <<= io::IOException();
1203cdf0e10cSrcweir break;
1204cdf0e10cSrcweir case GNOME_VFS_ERROR_IO:
1205cdf0e10cSrcweir if ( bWrite )
1206cdf0e10cSrcweir aException <<=
1207cdf0e10cSrcweir ucb::InteractiveNetworkWriteException
1208cdf0e10cSrcweir ( rtl::OUString(),
1209cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1210cdf0e10cSrcweir task::InteractionClassification_ERROR,
1211cdf0e10cSrcweir message );
1212cdf0e10cSrcweir else
1213cdf0e10cSrcweir aException <<=
1214cdf0e10cSrcweir ucb::InteractiveNetworkReadException
1215cdf0e10cSrcweir ( rtl::OUString(),
1216cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1217cdf0e10cSrcweir task::InteractionClassification_ERROR,
1218cdf0e10cSrcweir message );
1219cdf0e10cSrcweir break;
1220cdf0e10cSrcweir case GNOME_VFS_ERROR_HOST_NOT_FOUND:
1221cdf0e10cSrcweir case GNOME_VFS_ERROR_INVALID_HOST_NAME:
1222cdf0e10cSrcweir aException <<=
1223cdf0e10cSrcweir ucb::InteractiveNetworkResolveNameException
1224cdf0e10cSrcweir ( rtl::OUString(),
1225cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1226cdf0e10cSrcweir task::InteractionClassification_ERROR,
1227cdf0e10cSrcweir message );
1228cdf0e10cSrcweir break;
1229cdf0e10cSrcweir case GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE:
1230cdf0e10cSrcweir case GNOME_VFS_ERROR_SERVICE_OBSOLETE:
1231cdf0e10cSrcweir case GNOME_VFS_ERROR_PROTOCOL_ERROR:
1232cdf0e10cSrcweir case GNOME_VFS_ERROR_NO_MASTER_BROWSER:
1233cdf0e10cSrcweir aException <<=
1234cdf0e10cSrcweir ucb::InteractiveNetworkConnectException
1235cdf0e10cSrcweir ( rtl::OUString(),
1236cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1237cdf0e10cSrcweir task::InteractionClassification_ERROR,
1238cdf0e10cSrcweir message );
1239cdf0e10cSrcweir break;
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir case GNOME_VFS_ERROR_FILE_EXISTS:
1242cdf0e10cSrcweir aException <<= ucb::NameClashException
1243cdf0e10cSrcweir ( rtl::OUString(),
1244cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1245cdf0e10cSrcweir task::InteractionClassification_ERROR,
1246cdf0e10cSrcweir message );
1247cdf0e10cSrcweir break;
1248cdf0e10cSrcweir
1249cdf0e10cSrcweir case GNOME_VFS_ERROR_INVALID_OPEN_MODE:
1250cdf0e10cSrcweir aException <<= ucb::UnsupportedOpenModeException();
1251cdf0e10cSrcweir break;
1252cdf0e10cSrcweir
1253cdf0e10cSrcweir case GNOME_VFS_ERROR_CORRUPTED_DATA:
1254cdf0e10cSrcweir case GNOME_VFS_ERROR_WRONG_FORMAT:
1255cdf0e10cSrcweir case GNOME_VFS_ERROR_BAD_FILE:
1256cdf0e10cSrcweir case GNOME_VFS_ERROR_TOO_BIG:
1257cdf0e10cSrcweir case GNOME_VFS_ERROR_NO_SPACE:
1258cdf0e10cSrcweir case GNOME_VFS_ERROR_READ_ONLY:
1259cdf0e10cSrcweir case GNOME_VFS_ERROR_INVALID_URI:
1260cdf0e10cSrcweir case GNOME_VFS_ERROR_NOT_OPEN:
1261cdf0e10cSrcweir case GNOME_VFS_ERROR_ACCESS_DENIED:
1262cdf0e10cSrcweir case GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES:
1263cdf0e10cSrcweir case GNOME_VFS_ERROR_NOT_A_DIRECTORY:
1264cdf0e10cSrcweir case GNOME_VFS_ERROR_IN_PROGRESS:
1265cdf0e10cSrcweir case GNOME_VFS_ERROR_INTERRUPTED:
1266cdf0e10cSrcweir case GNOME_VFS_ERROR_LOOP:
1267cdf0e10cSrcweir case GNOME_VFS_ERROR_NOT_PERMITTED:
1268cdf0e10cSrcweir case GNOME_VFS_ERROR_IS_DIRECTORY:
1269cdf0e10cSrcweir case GNOME_VFS_ERROR_NO_MEMORY:
1270cdf0e10cSrcweir case GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS:
1271cdf0e10cSrcweir case GNOME_VFS_ERROR_LOGIN_FAILED:
1272cdf0e10cSrcweir case GNOME_VFS_ERROR_CANCELLED:
1273cdf0e10cSrcweir case GNOME_VFS_ERROR_DIRECTORY_BUSY:
1274cdf0e10cSrcweir case GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY:
1275cdf0e10cSrcweir case GNOME_VFS_ERROR_TOO_MANY_LINKS:
1276cdf0e10cSrcweir case GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM:
1277cdf0e10cSrcweir case GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM:
1278cdf0e10cSrcweir case GNOME_VFS_ERROR_NAME_TOO_LONG:
1279cdf0e10cSrcweir #ifdef DEBUG
1280cdf0e10cSrcweir g_warning( "FIXME: Un-mapped VFS exception '%s' (%d)",
1281cdf0e10cSrcweir gnome_vfs_result_to_string( result ), result );
1282cdf0e10cSrcweir #endif
1283cdf0e10cSrcweir default:
1284cdf0e10cSrcweir aException <<= ucb::InteractiveNetworkGeneralException
1285cdf0e10cSrcweir ( rtl::OUString(),
1286cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1287cdf0e10cSrcweir task::InteractionClassification_ERROR );
1288cdf0e10cSrcweir break;
1289cdf0e10cSrcweir }
1290cdf0e10cSrcweir
1291cdf0e10cSrcweir return aException;
1292cdf0e10cSrcweir }
1293cdf0e10cSrcweir
cancelCommandExecution(GnomeVFSResult result,const uno::Reference<ucb::XCommandEnvironment> & xEnv,sal_Bool bWrite)1294cdf0e10cSrcweir void Content::cancelCommandExecution(
1295cdf0e10cSrcweir GnomeVFSResult result,
1296cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv,
1297cdf0e10cSrcweir sal_Bool bWrite /* = sal_False */ )
1298cdf0e10cSrcweir throw ( uno::Exception )
1299cdf0e10cSrcweir {
1300cdf0e10cSrcweir ucbhelper::cancelCommandExecution( mapVFSException( result, bWrite ), xEnv );
1301cdf0e10cSrcweir // Unreachable
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir
getProperties(const uno::Reference<ucb::XCommandEnvironment> &)1304cdf0e10cSrcweir uno::Sequence< beans::Property > Content::getProperties(
1305cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
1306cdf0e10cSrcweir {
1307cdf0e10cSrcweir static const beans::Property aGenericProperties[] = {
1308cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
1309cdf0e10cSrcweir -1, getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1310cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1311cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
1312cdf0e10cSrcweir -1, getCppuBooleanType(),
1313cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1314cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
1315cdf0e10cSrcweir -1, getCppuBooleanType(),
1316cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1317cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
1318cdf0e10cSrcweir -1, getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1319cdf0e10cSrcweir beans::PropertyAttribute::BOUND ),
1320cdf0e10cSrcweir // Optional ...
1321cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ),
1322cdf0e10cSrcweir -1, getCppuType( static_cast< const util::DateTime * >( 0 ) ),
1323cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1324cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ),
1325cdf0e10cSrcweir -1, getCppuType( static_cast< const util::DateTime * >( 0 ) ),
1326cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1327cdf0e10cSrcweir // FIXME: Too expensive for now (?)
1328cdf0e10cSrcweir // beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1329cdf0e10cSrcweir // -1, getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1330cdf0e10cSrcweir // beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1331cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
1332cdf0e10cSrcweir -1, getCppuType( static_cast< const sal_Int64 * >( 0 ) ),
1333cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1334cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ),
1335cdf0e10cSrcweir -1, getCppuBooleanType(),
1336cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1337cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVolume" ) ),
1338cdf0e10cSrcweir -1, getCppuBooleanType(),
1339cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1340cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsCompactDisk" ) ),
1341cdf0e10cSrcweir -1, getCppuBooleanType(),
1342cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1343cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ),
1344cdf0e10cSrcweir -1, getCppuBooleanType(),
1345cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1346cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CreatableContentsInfo" ) ),
1347cdf0e10cSrcweir -1, getCppuType( static_cast< const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
1348cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY )
1349cdf0e10cSrcweir };
1350cdf0e10cSrcweir
1351cdf0e10cSrcweir const int nProps = sizeof (aGenericProperties) / sizeof (aGenericProperties[0]);
1352cdf0e10cSrcweir
1353cdf0e10cSrcweir return uno::Sequence< beans::Property > ( aGenericProperties, nProps );
1354cdf0e10cSrcweir
1355cdf0e10cSrcweir }
1356cdf0e10cSrcweir
getCommands(const uno::Reference<ucb::XCommandEnvironment> & xEnv)1357cdf0e10cSrcweir uno::Sequence< ucb::CommandInfo > Content::getCommands(
1358cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir static ucb::CommandInfo aCommandInfoTable[] = {
1361cdf0e10cSrcweir // Required commands
1362cdf0e10cSrcweir ucb::CommandInfo
1363cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
1364cdf0e10cSrcweir -1, getCppuVoidType() ),
1365cdf0e10cSrcweir ucb::CommandInfo
1366cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
1367cdf0e10cSrcweir -1, getCppuVoidType() ),
1368cdf0e10cSrcweir ucb::CommandInfo
1369cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
1370cdf0e10cSrcweir -1, getCppuType( static_cast<uno::Sequence< beans::Property > * >( 0 ) ) ),
1371cdf0e10cSrcweir ucb::CommandInfo
1372cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
1373cdf0e10cSrcweir -1, getCppuType( static_cast<uno::Sequence< beans::PropertyValue > * >( 0 ) ) ),
1374cdf0e10cSrcweir
1375cdf0e10cSrcweir // Optional standard commands
1376cdf0e10cSrcweir ucb::CommandInfo
1377cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
1378cdf0e10cSrcweir -1, getCppuBooleanType() ),
1379cdf0e10cSrcweir ucb::CommandInfo
1380cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
1381cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::InsertCommandArgument * >( 0 ) ) ),
1382cdf0e10cSrcweir ucb::CommandInfo
1383cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
1384cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::OpenCommandArgument2 * >( 0 ) ) ),
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir // Folder Only, omitted if not a folder
1387cdf0e10cSrcweir ucb::CommandInfo
1388cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
1389cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::TransferInfo * >( 0 ) ) ),
1390cdf0e10cSrcweir ucb::CommandInfo
1391cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
1392cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::ContentInfo * >( 0 ) ) )
1393cdf0e10cSrcweir };
1394cdf0e10cSrcweir
1395cdf0e10cSrcweir const int nProps
1396cdf0e10cSrcweir = sizeof( aCommandInfoTable ) / sizeof( aCommandInfoTable[ 0 ] );
1397cdf0e10cSrcweir return uno::Sequence< ucb::CommandInfo >(
1398cdf0e10cSrcweir aCommandInfoTable, isFolder( xEnv ) ? nProps : nProps - 2 );
1399cdf0e10cSrcweir }
1400cdf0e10cSrcweir
1401cdf0e10cSrcweir rtl::OUString
getOUURI()1402cdf0e10cSrcweir Content::getOUURI ()
1403cdf0e10cSrcweir {
1404cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1405cdf0e10cSrcweir return m_xIdentifier->getContentIdentifier();
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir
1408cdf0e10cSrcweir rtl::OString
getOURI()1409cdf0e10cSrcweir Content::getOURI ()
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir return rtl::OUStringToOString( getOUURI(), RTL_TEXTENCODING_UTF8 );
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir
1414cdf0e10cSrcweir char *
getURI()1415cdf0e10cSrcweir Content::getURI ()
1416cdf0e10cSrcweir {
1417cdf0e10cSrcweir return OUStringToGnome( getOUURI() );
1418cdf0e10cSrcweir }
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir void
copyData(uno::Reference<io::XInputStream> xIn,uno::Reference<io::XOutputStream> xOut)1421cdf0e10cSrcweir Content::copyData( uno::Reference< io::XInputStream > xIn,
1422cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut )
1423cdf0e10cSrcweir {
1424cdf0e10cSrcweir uno::Sequence< sal_Int8 > theData( TRANSFER_BUFFER_SIZE );
1425cdf0e10cSrcweir
1426cdf0e10cSrcweir g_return_if_fail( xIn.is() && xOut.is() );
1427cdf0e10cSrcweir
1428cdf0e10cSrcweir while ( xIn->readBytes( theData, TRANSFER_BUFFER_SIZE ) > 0 )
1429cdf0e10cSrcweir xOut->writeBytes( theData );
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir xOut->closeOutput();
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir
1434cdf0e10cSrcweir // Inherits an authentication context
1435cdf0e10cSrcweir uno::Reference< io::XInputStream >
createTempStream(const uno::Reference<ucb::XCommandEnvironment> & xEnv)1436cdf0e10cSrcweir Content::createTempStream(
1437cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1438cdf0e10cSrcweir throw( uno::Exception )
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir GnomeVFSResult result;
1441cdf0e10cSrcweir GnomeVFSHandle *handle = NULL;
1442cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
1443cdf0e10cSrcweir
1444cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1445cdf0e10cSrcweir // Something badly wrong happened - can't seek => stream to a temporary file
1446cdf0e10cSrcweir const rtl::OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
1447cdf0e10cSrcweir uno::Reference < io::XOutputStream > xTempOut =
1448cdf0e10cSrcweir uno::Reference < io::XOutputStream >
1449cdf0e10cSrcweir ( m_xSMgr->createInstance( sServiceName ), uno::UNO_QUERY );
1450cdf0e10cSrcweir
1451cdf0e10cSrcweir if ( !xTempOut.is() )
1452cdf0e10cSrcweir cancelCommandExecution( GNOME_VFS_ERROR_IO, xEnv );
1453cdf0e10cSrcweir
1454*24c56ab9SHerbert Dürr result = gnome_vfs_open( &handle, aURI.getStr(), GNOME_VFS_OPEN_READ );
1455cdf0e10cSrcweir if (result != GNOME_VFS_OK)
1456cdf0e10cSrcweir cancelCommandExecution( result, xEnv );
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir uno::Reference < io::XInputStream > pStream = new ::gvfs::Stream( handle, &m_info );
1459cdf0e10cSrcweir copyData( pStream, xTempOut );
1460cdf0e10cSrcweir
1461cdf0e10cSrcweir return uno::Reference < io::XInputStream > ( xTempOut, uno::UNO_QUERY );
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir
1464cdf0e10cSrcweir uno::Reference< io::XInputStream >
createInputStream(const uno::Reference<ucb::XCommandEnvironment> & xEnv)1465cdf0e10cSrcweir Content::createInputStream(
1466cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1467cdf0e10cSrcweir throw( uno::Exception )
1468cdf0e10cSrcweir {
1469cdf0e10cSrcweir GnomeVFSHandle *handle = NULL;
1470cdf0e10cSrcweir GnomeVFSResult result;
1471cdf0e10cSrcweir uno::Reference<io::XInputStream > xIn;
1472cdf0e10cSrcweir
1473cdf0e10cSrcweir Authentication aAuth( xEnv );
1474cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1475cdf0e10cSrcweir
1476cdf0e10cSrcweir getInfo( xEnv );
1477cdf0e10cSrcweir ::rtl::OString aURI = getOURI();
1478cdf0e10cSrcweir
1479cdf0e10cSrcweir if ( !(m_info.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) )
1480cdf0e10cSrcweir return createTempStream( xEnv );
1481cdf0e10cSrcweir
1482*24c56ab9SHerbert Dürr result = gnome_vfs_open( &handle, aURI.getStr(),
1483cdf0e10cSrcweir (GnomeVFSOpenMode) (GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_RANDOM ) );
1484cdf0e10cSrcweir
1485cdf0e10cSrcweir if (result == GNOME_VFS_ERROR_INVALID_OPEN_MODE ||
1486cdf0e10cSrcweir result == GNOME_VFS_ERROR_NOT_SUPPORTED)
1487cdf0e10cSrcweir return createTempStream( xEnv );
1488cdf0e10cSrcweir
1489cdf0e10cSrcweir if (result != GNOME_VFS_OK)
1490cdf0e10cSrcweir cancelCommandExecution( result, xEnv );
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir // Try a seek just to make sure it's Random access: some lie.
1493cdf0e10cSrcweir result = gnome_vfs_seek( handle, GNOME_VFS_SEEK_START, 0);
1494cdf0e10cSrcweir if (result == GNOME_VFS_ERROR_NOT_SUPPORTED) {
1495cdf0e10cSrcweir gnome_vfs_close( handle );
1496cdf0e10cSrcweir return createTempStream( xEnv );
1497cdf0e10cSrcweir }
1498cdf0e10cSrcweir
1499cdf0e10cSrcweir if (result != GNOME_VFS_OK)
1500cdf0e10cSrcweir cancelCommandExecution( result, xEnv );
1501cdf0e10cSrcweir
1502cdf0e10cSrcweir if (handle != NULL)
1503cdf0e10cSrcweir xIn = new ::gvfs::Stream( handle, &m_info );
1504cdf0e10cSrcweir
1505cdf0e10cSrcweir return xIn;
1506cdf0e10cSrcweir }
1507cdf0e10cSrcweir
1508cdf0e10cSrcweir sal_Bool
feedSink(uno::Reference<uno::XInterface> aSink,const uno::Reference<ucb::XCommandEnvironment> & xEnv)1509cdf0e10cSrcweir Content::feedSink( uno::Reference< uno::XInterface > aSink,
1510cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1511cdf0e10cSrcweir {
1512cdf0e10cSrcweir if ( !aSink.is() )
1513cdf0e10cSrcweir return sal_False;
1514cdf0e10cSrcweir
1515cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut
1516cdf0e10cSrcweir = uno::Reference< io::XOutputStream >(aSink, uno::UNO_QUERY );
1517cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xDataSink
1518cdf0e10cSrcweir = uno::Reference< io::XActiveDataSink >(aSink, uno::UNO_QUERY );
1519cdf0e10cSrcweir
1520cdf0e10cSrcweir if ( !xOut.is() && !xDataSink.is() )
1521cdf0e10cSrcweir return sal_False;
1522cdf0e10cSrcweir
1523cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn = createInputStream( xEnv );
1524cdf0e10cSrcweir if ( !xIn.is() )
1525cdf0e10cSrcweir return sal_False;
1526cdf0e10cSrcweir
1527cdf0e10cSrcweir if ( xOut.is() )
1528cdf0e10cSrcweir copyData( xIn, xOut );
1529cdf0e10cSrcweir
1530cdf0e10cSrcweir if ( xDataSink.is() )
1531cdf0e10cSrcweir xDataSink->setInputStream( xIn );
1532cdf0e10cSrcweir
1533cdf0e10cSrcweir return sal_True;
1534cdf0e10cSrcweir }
1535cdf0e10cSrcweir
1536cdf0e10cSrcweir extern "C" {
1537cdf0e10cSrcweir
1538cdf0e10cSrcweir #ifndef GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION
1539cdf0e10cSrcweir # error "We require Gnome VFS 2.6.x to compile (will run fine with < 2.6)"
1540cdf0e10cSrcweir #endif
1541cdf0e10cSrcweir
1542cdf0e10cSrcweir static void
vfs_authentication_callback(gconstpointer in_void,gsize in_size,gpointer out_void,gsize out_size,gpointer callback_data)1543cdf0e10cSrcweir vfs_authentication_callback (gconstpointer in_void,
1544cdf0e10cSrcweir gsize in_size,
1545cdf0e10cSrcweir gpointer out_void,
1546cdf0e10cSrcweir gsize out_size,
1547cdf0e10cSrcweir gpointer callback_data)
1548cdf0e10cSrcweir {
1549cdf0e10cSrcweir task::XInteractionHandler *xIH;
1550cdf0e10cSrcweir
1551cdf0e10cSrcweir #ifdef DEBUG
1552cdf0e10cSrcweir g_warning ("Full authentication callback (%p) ...", callback_data);
1553cdf0e10cSrcweir #endif
1554cdf0e10cSrcweir
1555cdf0e10cSrcweir if( !( xIH = (task::XInteractionHandler *) callback_data ) )
1556cdf0e10cSrcweir return;
1557cdf0e10cSrcweir
1558cdf0e10cSrcweir const GnomeVFSModuleCallbackFullAuthenticationIn *in =
1559cdf0e10cSrcweir (const GnomeVFSModuleCallbackFullAuthenticationIn *) in_void;
1560cdf0e10cSrcweir GnomeVFSModuleCallbackFullAuthenticationOut *out =
1561cdf0e10cSrcweir (GnomeVFSModuleCallbackFullAuthenticationOut *) out_void;
1562cdf0e10cSrcweir
1563cdf0e10cSrcweir g_return_if_fail (in != NULL && out != NULL);
1564cdf0e10cSrcweir g_return_if_fail (sizeof (GnomeVFSModuleCallbackFullAuthenticationIn) == in_size &&
1565cdf0e10cSrcweir sizeof (GnomeVFSModuleCallbackFullAuthenticationOut) == out_size);
1566cdf0e10cSrcweir
1567cdf0e10cSrcweir #ifdef DEBUG
1568cdf0e10cSrcweir # define NNIL(x) (x?x:"<Null>")
1569cdf0e10cSrcweir g_warning (" InComing data 0x%x uri '%s' prot '%s' server '%s' object '%s' "
1570cdf0e10cSrcweir "port %d auth_t '%s' user '%s' domain '%s' "
1571cdf0e10cSrcweir "def user '%s', def domain '%s'",
1572cdf0e10cSrcweir (int) in->flags, NNIL(in->uri), NNIL(in->protocol),
1573cdf0e10cSrcweir NNIL(in->server), NNIL(in->object),
1574cdf0e10cSrcweir (int) in->port, NNIL(in->authtype), NNIL(in->username), NNIL(in->domain),
1575cdf0e10cSrcweir NNIL(in->default_user), NNIL(in->default_domain));
1576cdf0e10cSrcweir # undef NNIL
1577cdf0e10cSrcweir #endif
1578cdf0e10cSrcweir
1579cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::EntityType
1580cdf0e10cSrcweir eDomain, eUserName, ePassword;
1581cdf0e10cSrcweir ::rtl::OUString aHostName, aDomain, aUserName, aPassword;
1582cdf0e10cSrcweir
1583cdf0e10cSrcweir aHostName = GnomeToOUString( in->server );
1584cdf0e10cSrcweir
1585cdf0e10cSrcweir if (in->flags & GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_DOMAIN)
1586cdf0e10cSrcweir {
1587cdf0e10cSrcweir aDomain = GnomeToOUString( in->domain );
1588cdf0e10cSrcweir eDomain = ucbhelper::SimpleAuthenticationRequest::ENTITY_MODIFY;
1589cdf0e10cSrcweir if (!aDomain.getLength())
1590cdf0e10cSrcweir aDomain = GnomeToOUString( in->default_domain );
1591cdf0e10cSrcweir }
1592cdf0e10cSrcweir else // no underlying capability to display realm otherwise
1593cdf0e10cSrcweir eDomain = ucbhelper::SimpleAuthenticationRequest::ENTITY_NA;
1594cdf0e10cSrcweir
1595cdf0e10cSrcweir aUserName = GnomeToOUString( in->username );
1596cdf0e10cSrcweir if (!aUserName.getLength())
1597cdf0e10cSrcweir aUserName = GnomeToOUString( in->default_user );
1598cdf0e10cSrcweir eUserName = (in->flags & GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_USERNAME) ?
1599cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::ENTITY_MODIFY :
1600cdf0e10cSrcweir (aUserName.getLength() ?
1601cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::ENTITY_FIXED :
1602cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::ENTITY_NA);
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir // No suggested password.
1605cdf0e10cSrcweir ePassword = (in->flags & GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_PASSWORD) ?
1606cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::ENTITY_MODIFY :
1607cdf0e10cSrcweir ucbhelper::SimpleAuthenticationRequest::ENTITY_FIXED;
1608cdf0e10cSrcweir
1609cdf0e10cSrcweir // Really, really bad things happen if we don't provide
1610cdf0e10cSrcweir // the same user/password as was entered last time if
1611cdf0e10cSrcweir // we failed to authenticate - infinite looping / flickering
1612cdf0e10cSrcweir // madness etc. [ nice infrastructure ! ]
1613cdf0e10cSrcweir static rtl::OUString aLastUserName, aLastPassword;
1614cdf0e10cSrcweir if (in->flags & GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_PREVIOUS_ATTEMPT_FAILED)
1615cdf0e10cSrcweir {
1616cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1617cdf0e10cSrcweir aUserName = aLastUserName;
1618cdf0e10cSrcweir aPassword = aLastPassword;
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir
1621cdf0e10cSrcweir rtl::Reference< ucbhelper::SimpleAuthenticationRequest > xRequest
1622cdf0e10cSrcweir = new ucbhelper::SimpleAuthenticationRequest (GnomeToOUString(in->uri),
1623cdf0e10cSrcweir aHostName, eDomain, aDomain,
1624cdf0e10cSrcweir eUserName, aUserName,
1625cdf0e10cSrcweir ePassword, aPassword);
1626cdf0e10cSrcweir
1627cdf0e10cSrcweir xIH->handle( xRequest.get() );
1628cdf0e10cSrcweir
1629cdf0e10cSrcweir rtl::Reference< ucbhelper::InteractionContinuation > xSelection
1630cdf0e10cSrcweir = xRequest->getSelection();
1631cdf0e10cSrcweir
1632cdf0e10cSrcweir if ( xSelection.is() ) {
1633cdf0e10cSrcweir // Handler handled the request.
1634cdf0e10cSrcweir uno::Reference< task::XInteractionAbort > xAbort(xSelection.get(), uno::UNO_QUERY );
1635cdf0e10cSrcweir if ( !xAbort.is() ) {
1636cdf0e10cSrcweir const rtl::Reference<
1637cdf0e10cSrcweir ucbhelper::InteractionSupplyAuthentication > & xSupp
1638cdf0e10cSrcweir = xRequest->getAuthenticationSupplier();
1639cdf0e10cSrcweir
1640cdf0e10cSrcweir aUserName = xSupp->getUserName();
1641cdf0e10cSrcweir aDomain = xSupp->getRealm();
1642cdf0e10cSrcweir aPassword = xSupp->getPassword();
1643cdf0e10cSrcweir
1644cdf0e10cSrcweir {
1645cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1646cdf0e10cSrcweir aLastUserName = aUserName;
1647cdf0e10cSrcweir aLastPassword = aPassword;
1648cdf0e10cSrcweir }
1649cdf0e10cSrcweir
1650cdf0e10cSrcweir out->username = OUStringToGnome( aUserName );
1651cdf0e10cSrcweir out->domain = OUStringToGnome( aDomain );
1652cdf0e10cSrcweir out->password = OUStringToGnome( aPassword );
1653cdf0e10cSrcweir out->save_password = xSupp->getRememberPasswordMode();
1654cdf0e10cSrcweir
1655cdf0e10cSrcweir #ifdef DEBUG
1656cdf0e10cSrcweir g_warning ("Got valid user/domain/password '%s' '%s' '%s', %s password",
1657cdf0e10cSrcweir out->username, out->domain, out->password,
1658cdf0e10cSrcweir out->save_password ? "save" : "don't save");
1659cdf0e10cSrcweir #endif
1660cdf0e10cSrcweir }
1661cdf0e10cSrcweir else
1662cdf0e10cSrcweir out->abort_auth = TRUE;
1663cdf0e10cSrcweir }
1664cdf0e10cSrcweir else
1665cdf0e10cSrcweir out->abort_auth = TRUE;
1666cdf0e10cSrcweir }
1667cdf0e10cSrcweir
1668cdf0e10cSrcweir static void
vfs_authentication_old_callback(gconstpointer in_void,gsize in_size,gpointer out_void,gsize out_size,gpointer callback_data)1669cdf0e10cSrcweir vfs_authentication_old_callback (gconstpointer in_void,
1670cdf0e10cSrcweir gsize in_size,
1671cdf0e10cSrcweir gpointer out_void,
1672cdf0e10cSrcweir gsize out_size,
1673cdf0e10cSrcweir gpointer callback_data)
1674cdf0e10cSrcweir {
1675cdf0e10cSrcweir #ifdef DEBUG
1676cdf0e10cSrcweir g_warning ("Old authentication callback (%p) [ UNTESTED ] ...", callback_data);
1677cdf0e10cSrcweir #endif
1678cdf0e10cSrcweir const GnomeVFSModuleCallbackAuthenticationIn *in =
1679cdf0e10cSrcweir (const GnomeVFSModuleCallbackAuthenticationIn *) in_void;
1680cdf0e10cSrcweir GnomeVFSModuleCallbackAuthenticationOut *out =
1681cdf0e10cSrcweir (GnomeVFSModuleCallbackAuthenticationOut *) out_void;
1682cdf0e10cSrcweir
1683cdf0e10cSrcweir g_return_if_fail (in != NULL && out != NULL);
1684cdf0e10cSrcweir g_return_if_fail (sizeof (GnomeVFSModuleCallbackAuthenticationIn) == in_size &&
1685cdf0e10cSrcweir sizeof (GnomeVFSModuleCallbackAuthenticationOut) == out_size);
1686cdf0e10cSrcweir
1687cdf0e10cSrcweir GnomeVFSModuleCallbackFullAuthenticationIn mapped_in = {
1688cdf0e10cSrcweir (GnomeVFSModuleCallbackFullAuthenticationFlags)
1689cdf0e10cSrcweir (GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_PASSWORD |
1690cdf0e10cSrcweir GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_USERNAME |
1691cdf0e10cSrcweir GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_DOMAIN),
1692cdf0e10cSrcweir 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1693cdf0e10cSrcweir GnomeVFSModuleCallbackFullAuthenticationOut mapped_out = { 0, 0, 0, 0, 0, 0, 0, 0 };
1694cdf0e10cSrcweir
1695cdf0e10cSrcweir // Map the old style input auth. data to the new style structure.
1696cdf0e10cSrcweir if (in->previous_attempt_failed)
1697cdf0e10cSrcweir mapped_in.flags = (GnomeVFSModuleCallbackFullAuthenticationFlags)
1698cdf0e10cSrcweir (mapped_in.flags |
1699cdf0e10cSrcweir GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_PREVIOUS_ATTEMPT_FAILED);
1700cdf0e10cSrcweir
1701cdf0e10cSrcweir GnomeVFSURI *pURI = NULL;
1702cdf0e10cSrcweir // Urk - parse all this from the URL ...
1703cdf0e10cSrcweir mapped_in.uri = in->uri;
1704cdf0e10cSrcweir if (in->uri)
1705cdf0e10cSrcweir {
1706cdf0e10cSrcweir pURI = gnome_vfs_uri_new( in->uri );
1707cdf0e10cSrcweir mapped_in.protocol = (char *) gnome_vfs_uri_get_scheme (pURI);
1708cdf0e10cSrcweir mapped_in.server = (char *) gnome_vfs_uri_get_host_name (pURI);
1709cdf0e10cSrcweir mapped_in.port = gnome_vfs_uri_get_host_port (pURI);
1710cdf0e10cSrcweir mapped_in.username = (char *) gnome_vfs_uri_get_user_name (pURI);
1711cdf0e10cSrcweir }
1712cdf0e10cSrcweir mapped_in.domain = in->realm;
1713cdf0e10cSrcweir mapped_in.default_user = mapped_in.username;
1714cdf0e10cSrcweir mapped_in.default_domain = mapped_in.domain;
1715cdf0e10cSrcweir
1716cdf0e10cSrcweir vfs_authentication_callback ((gconstpointer) &mapped_in,
1717cdf0e10cSrcweir sizeof (mapped_in),
1718cdf0e10cSrcweir (gpointer) &mapped_out,
1719cdf0e10cSrcweir sizeof (mapped_out),
1720cdf0e10cSrcweir callback_data);
1721cdf0e10cSrcweir
1722cdf0e10cSrcweir if (pURI)
1723cdf0e10cSrcweir gnome_vfs_uri_unref (pURI);
1724cdf0e10cSrcweir
1725cdf0e10cSrcweir // Map the new style auth. out data to the old style out structure.
1726cdf0e10cSrcweir out->username = mapped_out.username;
1727cdf0e10cSrcweir out->password = mapped_out.password;
1728cdf0e10cSrcweir g_free (mapped_out.domain);
1729cdf0e10cSrcweir g_free (mapped_out.keyring);
1730cdf0e10cSrcweir }
1731cdf0e10cSrcweir
1732cdf0e10cSrcweir
1733cdf0e10cSrcweir static void
auth_destroy(gpointer data)1734cdf0e10cSrcweir auth_destroy (gpointer data)
1735cdf0e10cSrcweir {
1736cdf0e10cSrcweir task::XInteractionHandler *xIH;
1737cdf0e10cSrcweir if( ( xIH = ( task::XInteractionHandler * )data ) )
1738cdf0e10cSrcweir xIH->release();
1739cdf0e10cSrcweir }
1740cdf0e10cSrcweir
1741cdf0e10cSrcweir // This sucks, but gnome-vfs doesn't much like
1742cdf0e10cSrcweir // repeated set / unsets - so we have to compensate.
1743cdf0e10cSrcweir GPrivate *auth_queue = NULL;
1744cdf0e10cSrcweir
auth_queue_destroy(gpointer data)1745cdf0e10cSrcweir void auth_queue_destroy( gpointer data )
1746cdf0e10cSrcweir {
1747cdf0e10cSrcweir GList *l;
1748cdf0e10cSrcweir GQueue *vq = (GQueue *) data;
1749cdf0e10cSrcweir
1750cdf0e10cSrcweir for (l = vq->head; l; l = l->next)
1751cdf0e10cSrcweir auth_destroy (l->data);
1752cdf0e10cSrcweir g_queue_free (vq);
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir }
1755cdf0e10cSrcweir
1756cdf0e10cSrcweir static void
refresh_auth(GQueue * vq)1757cdf0e10cSrcweir refresh_auth( GQueue *vq )
1758cdf0e10cSrcweir {
1759cdf0e10cSrcweir GList *l;
1760cdf0e10cSrcweir
1761cdf0e10cSrcweir gnome_vfs_module_callback_pop( GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION );
1762cdf0e10cSrcweir gnome_vfs_module_callback_pop( GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION );
1763cdf0e10cSrcweir
1764cdf0e10cSrcweir for (l = vq->head; l; l = l->next) {
1765cdf0e10cSrcweir if (l->data) {
1766cdf0e10cSrcweir gnome_vfs_module_callback_push
1767cdf0e10cSrcweir ( GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION,
1768cdf0e10cSrcweir vfs_authentication_old_callback, l->data, NULL );
1769cdf0e10cSrcweir gnome_vfs_module_callback_push
1770cdf0e10cSrcweir ( GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION,
1771cdf0e10cSrcweir vfs_authentication_callback, l->data, NULL );
1772cdf0e10cSrcweir break;
1773cdf0e10cSrcweir }
1774cdf0e10cSrcweir }
1775cdf0e10cSrcweir }
1776cdf0e10cSrcweir
Authentication(const uno::Reference<ucb::XCommandEnvironment> & xEnv)1777cdf0e10cSrcweir gvfs::Authentication::Authentication(
1778cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1779cdf0e10cSrcweir {
1780cdf0e10cSrcweir GQueue *vq;
1781cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH;
1782cdf0e10cSrcweir
1783cdf0e10cSrcweir if ( xEnv.is() )
1784cdf0e10cSrcweir xIH = xEnv->getInteractionHandler();
1785cdf0e10cSrcweir
1786cdf0e10cSrcweir if ( xIH.is() )
1787cdf0e10cSrcweir xIH->acquire();
1788cdf0e10cSrcweir
1789cdf0e10cSrcweir if( !(vq = (GQueue *)g_private_get( auth_queue ) ) ) {
1790cdf0e10cSrcweir vq = g_queue_new();
1791cdf0e10cSrcweir g_private_set( auth_queue, vq );
1792cdf0e10cSrcweir }
1793cdf0e10cSrcweir
1794cdf0e10cSrcweir g_queue_push_head( vq, (gpointer) xIH.get() );
1795cdf0e10cSrcweir refresh_auth( vq );
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir
~Authentication()1798cdf0e10cSrcweir gvfs::Authentication::~Authentication()
1799cdf0e10cSrcweir {
1800cdf0e10cSrcweir GQueue *vq;
1801cdf0e10cSrcweir gpointer data;
1802cdf0e10cSrcweir
1803cdf0e10cSrcweir vq = (GQueue *)g_private_get( auth_queue );
1804cdf0e10cSrcweir
1805cdf0e10cSrcweir data = g_queue_pop_head( vq );
1806cdf0e10cSrcweir auth_destroy (data);
1807cdf0e10cSrcweir
1808cdf0e10cSrcweir refresh_auth( vq );
1809cdf0e10cSrcweir }
1810