diff options
author | Andreas Bille <abi@openoffice.org> | 2002-08-28 06:23:17 +0000 |
---|---|---|
committer | Andreas Bille <abi@openoffice.org> | 2002-08-28 06:23:17 +0000 |
commit | 596dca1ba20842c3820d4c6fd91dcd596614232a (patch) | |
tree | b401044597f03ed3a28de2a5976b1a4086affb04 /ucb/source | |
parent | 66588fcf6a5a9fd90fa192eaaee2139426f3b894 (diff) |
Simply saving
Diffstat (limited to 'ucb/source')
24 files changed, 1240 insertions, 494 deletions
diff --git a/ucb/source/ucp/ftp/ftpcfunc.cxx b/ucb/source/ucp/ftp/ftpcfunc.cxx new file mode 100644 index 000000000000..32ebeb667abc --- /dev/null +++ b/ucb/source/ucp/ftp/ftpcfunc.cxx @@ -0,0 +1,83 @@ +#include <string.h> + +#include "ftpcontentidentifier.hxx" +#include "ftpinpstr.hxx" + +using namespace ftp; +using namespace com::sun::star::uno; + +extern "C" { + + int ftp_write(void *buffer,size_t size,size_t nmemb,void *stream) + { + FTPStreamContainer *_stream = + reinterpret_cast<FTPStreamContainer*>(stream); + + if(!_stream) + return 0; + + return _stream->write(buffer,size,nmemb); + } + + +// int write2InputStream(void *buffer,size_t size,size_t nmemb,void *stream) +// { +// size_t ret = size*nmemb; +// if(!(stream && ret)) // OK, no error if nothing can be written. +// return ret; + +// FTPBufferContainer *p = +// reinterpret_cast<FTPBufferContainer*>(stream); +// if(p && p->m_out) +// p->m_out->append(buffer,size,nmemb); +// return ret; +// } + + +// /** Callback for curl_easy_perform(), +// * forwarding the written content to the outputstream. +// */ + +// int write2OutputStream(void *buffer,size_t size,size_t nmemb,void *stream) +// { +// size_t ret = size*nmemb; + +// if(!(stream && ret)) // OK, no error if nothing can be written. +// return ret; + +// try{ +// FTPStreamContainer *p = +// reinterpret_cast<FTPStreamContainer*>(stream); +// if(p && p->m_out.is()) +// p->m_out->writeBytes( +// Sequence<sal_Int8>(static_cast<sal_Int8*>(buffer), +// size*nmemb) +// ); +// return ret; +// } catch(const Exception&) { +// return 0; +// } +// } + + + int ftp_passwd(void *client,char*prompt,char*buffer,int bufferlength) + { +// FTPClient *p = +// reinterpret_cast<FTPClient>(client); + +// // 'passwd' returns actually "username:password" +// rtl::OUString passwd = p->passwd(); +// rtl::OString opasswd(passwd.getStr(), +// passwd.getLength(), +// RTL_TEXTENCODING_UTF8); +// if(strlen(opasswd.getStr()) <= bufferlength) +// strncpy(buffer,opasswd.getStr(),opasswd.getLength()); +// else +// strcpy(buffer,opasswd.getStr()); + strcpy(buffer,"psswd"); + + return 0; + } + + +} diff --git a/ucb/source/ucp/ftp/ftpcfunc.hxx b/ucb/source/ucp/ftp/ftpcfunc.hxx new file mode 100644 index 000000000000..61cf81a4ef46 --- /dev/null +++ b/ucb/source/ucp/ftp/ftpcfunc.hxx @@ -0,0 +1,54 @@ +#ifndef _FTP_FTPCFUNC_HXX_ +#define _FTP_FTPCFUNC_HXX_ + +#include <rtl/ustring.hxx> + + +namespace ftp { + + class FTPStreamContainer + { + public: + + virtual write(void *buffer,size_t size,size_t nmemb) = 0; + }; + +} + + +extern "C" { + + /** callback for curl_easy_perform(), + * forwarding the written content to the stream. + * stream has to be of type 'FTPStreamContainer'. + */ + + + int ftp_write(void *buffer,size_t size,size_t nmemb,void *stream); +} + + + + +namespace ftp { + + /** Is the first argument to 'passwd' below. + */ + + class FTPClient + { + public: + + virtual rtl::OUString passwd() const = 0; + }; + +} + + +extern "C" { + + int ftp_passwd(void *client,char*prompt,char*buffer,int bufferlength); + +} + +#endif diff --git a/ucb/source/ucp/ftp/ftpcontent.cxx b/ucb/source/ucp/ftp/ftpcontent.cxx index 31e9c5c58f2e..6c2e63ebda02 100644 --- a/ucb/source/ucp/ftp/ftpcontent.cxx +++ b/ucb/source/ucp/ftp/ftpcontent.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpcontent.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:12:53 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,6 +75,9 @@ #include "ftploaderthread.hxx" #include "ftpinpstr.hxx" #include "ftpdirp.hxx" +#include "ftpcontentidentifier.hxx" +#include "ftpcfunc.hxx" +#include "ftpstrcont.hxx" #include <curl/curl.h> #include <curl/easy.h> @@ -90,6 +93,7 @@ #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> #include <com/sun/star/ucb/OpenCommandArgument2.hpp> #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp> +#include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp> #include <com/sun/star/ucb/OpenMode.hpp> @@ -110,8 +114,8 @@ using namespace com::sun::star::sdbc; //========================================================================= //========================================================================= -FtpContent::FtpContent( const Reference< XMultiServiceFactory >& rxSMgr, - FtpContentProvider* pProvider, +FTPContent::FTPContent( const Reference< XMultiServiceFactory >& rxSMgr, + FTPContentProvider* pProvider, const Reference< XContentIdentifier >& Identifier) : ContentImplHelper(rxSMgr,pProvider,Identifier), m_pFCP(pProvider) @@ -120,7 +124,7 @@ FtpContent::FtpContent( const Reference< XMultiServiceFactory >& rxSMgr, //========================================================================= -FtpContent::~FtpContent() +FTPContent::~FTPContent() { } @@ -131,7 +135,7 @@ FtpContent::~FtpContent() // //========================================================================= -XINTERFACE_IMPL_4( FtpContent, +XINTERFACE_IMPL_4( FTPContent, XTypeProvider, XServiceInfo, XContent, @@ -143,7 +147,7 @@ XINTERFACE_IMPL_4( FtpContent, // //========================================================================= -XTYPEPROVIDER_IMPL_4( FtpContent, +XTYPEPROVIDER_IMPL_4( FTPContent, XTypeProvider, XServiceInfo, XContent, @@ -159,11 +163,11 @@ XTYPEPROVIDER_IMPL_4( FtpContent, #undef XSERVICEINFO_CREATE_INSTANCE_IMPL #define XSERVICEINFO_CREATE_INSTANCE_IMPL( Class ) -XSERVICEINFO_IMPL_1( FtpContent, +XSERVICEINFO_IMPL_1( FTPContent, rtl::OUString::createFromAscii( - "com.sun.star.comp.FtpContent"), + "com.sun.star.comp.FTPContent"), rtl::OUString::createFromAscii( - "com.sun.star.ucb.FtpContent")); + "com.sun.star.ucb.FTPContent")); @@ -174,7 +178,7 @@ XSERVICEINFO_IMPL_1( FtpContent, //========================================================================= // virtual -rtl::OUString SAL_CALL FtpContent::getContentType() +rtl::OUString SAL_CALL FTPContent::getContentType() throw( RuntimeException ) { return rtl::OUString::createFromAscii(MYUCP_CONTENT_TYPE); @@ -188,75 +192,18 @@ rtl::OUString SAL_CALL FtpContent::getContentType() //virtual -void SAL_CALL FtpContent::abort( sal_Int32 CommandId ) +void SAL_CALL FTPContent::abort( sal_Int32 CommandId ) throw( RuntimeException ) { } -struct StreamContainer -{ - Reference<XOutputStream> m_out; - - StreamContainer(const Reference<XOutputStream>& out) - : m_out(out) { } -}; - - -struct FtpBufferContainer -{ - FtpInputStream *m_out; - - FtpBufferContainer(FtpInputStream* out) - : m_out(out) { } -}; - - -#ifdef __cplusplus -extern "C" { -#endif - - int write2InputStream(void *buffer,size_t size,size_t nmemb,void *stream) - { - size_t ret = size*nmemb; - if(!stream || !ret) // OK, no error if nothing can be written. - return ret; - - FtpBufferContainer *p = reinterpret_cast<FtpBufferContainer*>(stream); - if(p && p->m_out) - p->m_out->append(buffer,size,nmemb); - return ret; - } - - - /** Callback for curl_easy_perform(), - * forwarding the written content to the outputstream. - */ - - int write2OutputStream(void *buffer,size_t size,size_t nmemb,void *stream) - { - size_t ret = size*nmemb; - - if(!stream || !ret) // OK, no error if nothing can be written. - return ret; - - try{ - StreamContainer *p = reinterpret_cast<StreamContainer*>(stream); - if(p && p->m_out.is()) - p->m_out->writeBytes( - Sequence<sal_Int8>(static_cast<sal_Int8*>(buffer), - size*nmemb) - ); - return ret; - } catch(const Exception&) { - return 0; - } - } - -#ifdef __cplusplus -} -#endif +/***************************************************************************/ +/* */ +/* Interne Implklasse */ +/* */ +/***************************************************************************/ class ResultSetFactoryI @@ -301,10 +248,15 @@ public: +//========================================================================= +// +// XCommandProcessor methods. +// +//========================================================================= // virtual -Any SAL_CALL FtpContent::execute( +Any SAL_CALL FTPContent::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< @@ -319,14 +271,14 @@ Any SAL_CALL FtpContent::execute( Any aRet; if(aCommand.Name.compareToAscii("getPropertyValues") == 0) { - Sequence< Property > Properties; - if(!( aCommand.Argument >>= Properties)) + Sequence<Property> Properties; + if(!(aCommand.Argument >>= Properties)) { aRet <<= IllegalArgumentException(); ucbhelper::cancelCommandExecution(aRet,Environment); } - aRet <<= getPropertyValues(Properties); + aRet <<= getPropertyValues(Properties,Environment); } else if(aCommand.Name.compareToAscii("setPropertyValues") == 0) { } @@ -345,48 +297,54 @@ Any SAL_CALL FtpContent::execute( ucbhelper::cancelCommandExecution(aRet,Environment); } + if(aOpenCommand.Mode == OpenMode::DOCUMENT) { + // Open as a document + CURL *curl = m_pFCP->handle(); - CURL *curl = m_pFCP->handle(); - - // Setting the header write function, - // which receives the output of the control connection. + // Setting the header write function, + // which receives the output of the control connection. - std::auto_ptr<FtpInputStream> header(new FtpInputStream()); - FtpBufferContainer headerContainer(header.get()); + std::auto_ptr<FTPInputStream> control(new FTPInputStream()); + FTPInputStreamContainer controlContainer(control.get()); - curl_easy_setopt(curl,CURLOPT_HEADERFUNCTION,write2InputStream); - curl_easy_setopt(curl,CURLOPT_WRITEHEADER,&headerContainer); + curl_easy_setopt(curl,CURLOPT_NOBODY,false); + curl_easy_setopt(curl, + CURLOPT_HEADERFUNCTION, + ftp_write); + curl_easy_setopt(curl, + CURLOPT_WRITEHEADER, + &controlContainer); + // Now setting the URL - // Now setting the URL + rtl::OUString url(m_xIdentifier->getContentIdentifier()); - rtl::OUString aOUStr(m_xIdentifier->getContentIdentifier()); - rtl::OString aOStr(aOUStr.getStr(), - aOUStr.getLength(), - RTL_TEXTENCODING_UTF8); // Only ASCII in URLs - // // => UTF8 ok + curl_easy_setopt(curl, + CURLOPT_URL, + rtl::OString(url.getStr(), + url.getLength(), + // Only ASCII in URLs => UTF8 ok + RTL_TEXTENCODING_UTF8).getStr()); - curl_easy_setopt(curl,CURLOPT_URL,aOStr.getStr()); + curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0); - if(aOpenCommand.Mode == OpenMode::DOCUMENT) { - // Open as a document Reference<XActiveDataSink> xActiveDataSink(aOpenCommand.Sink,UNO_QUERY); Reference< XOutputStream > xOutputStream(aOpenCommand.Sink,UNO_QUERY); if(xActiveDataSink.is()) { - FtpBufferContainer cont(new FtpInputStream()); - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write2InputStream); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,&cont); + FTPInputStreamContainer dataContainer(new FTPInputStream()); + curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,ftp_write); + curl_easy_setopt(curl,CURLOPT_WRITEDATA,&dataContainer); curl_easy_perform(curl); - xActiveDataSink->setInputStream(cont.m_out); + xActiveDataSink->setInputStream(dataContainer()); } else if(xOutputStream.is()) { - StreamContainer cont(xOutputStream); + FTPOutputStreamContainer dataContainer(xOutputStream); curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, - write2OutputStream); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,&cont); + ftp_write); + curl_easy_setopt(curl,CURLOPT_WRITEDATA,&dataContainer); curl_easy_perform(curl); } else { @@ -397,78 +355,11 @@ Any SAL_CALL FtpContent::execute( else if(aOpenCommand.Mode == OpenMode::ALL || aOpenCommand.Mode == OpenMode::DOCUMENTS || aOpenCommand.Mode == OpenMode::FOLDERS ) { - std::auto_ptr<FtpInputStream> ap(new FtpInputStream()); - FtpBufferContainer cont(ap.get()); - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write2InputStream); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,&cont); - curl_easy_perform(curl); - - rtl::OUString aStr((char*)header.get()->getBuffer(), - sal_Int32(header.get()->getLength()), - RTL_TEXTENCODING_UTF8); - - // Now parse the content. - // Parsing is here somewhat ugly, because - // the regular expression does not forward - // the pointer to end of parsed expression. - - sal_uInt32 len = (sal_uInt32) ap.get()->getLength(); - char* fwd = (char*) ap.get()->getBuffer(); - char *p1, *p2; - p1 = p2 = fwd; - - enum OS { DOS,UNIX,VMS,UNKNOWN }; - OS osKind(UNKNOWN); - std::vector<FTPDirentry> resvec; - FTPDirentry aDirEntry; - - while(true) { - while(p2-fwd < int(len) && *p2 != '\n') ++p2; - if(p2-fwd == int(len)) break; - - *p2 = 0; - switch(osKind) { - case DOS: - FTPDirectoryParser::parseDOS(aDirEntry,p1); - break; - case UNIX: - FTPDirectoryParser::parseUNIX(aDirEntry,p1); - break; - case VMS: - FTPDirectoryParser::parseUNIX(aDirEntry,p1); - break; - default: - if(FTPDirectoryParser::parseUNIX(aDirEntry,p1)) - osKind = UNIX; - else if(FTPDirectoryParser::parseDOS(aDirEntry,p1)) - osKind = DOS; - else if(FTPDirectoryParser::parseVMS(aDirEntry,p1)) - osKind = VMS; - } - if(osKind != int(UNKNOWN)) { - if(1 + aOUStr.lastIndexOf(sal_Unicode('/')) == - aOUStr.getLength()) - aDirEntry.m_aURL = - aOUStr + - aDirEntry.m_aName; - else - aDirEntry.m_aURL = - aOUStr + - sal_Unicode('/') + - aDirEntry.m_aName; - - resvec.push_back(aDirEntry); - aDirEntry.clear(); - } - - p1 = p2 + 1; - } - - if(osKind == int(UNKNOWN)) { - // Ok, this was not a directory, but a file - //todo: Check here wether our parent lists our name - } - else { + FTPURL aFTPURL(m_xIdentifier->getContentIdentifier(), + m_pFCP); + try{ + std::vector<FTPDirentry> resvec = + aFTPURL.list(aOpenCommand.Mode); Reference< XDynamicResultSet > xSet = new DynamicResultSet( m_xSMgr, @@ -482,6 +373,14 @@ Any SAL_CALL FtpContent::execute( aOpenCommand.SortingInfo, resvec)); aRet <<= xSet; + } catch(const no_such_directory_exception& e) { + if(e.code() == CURLE_COULDNT_CONNECT) { + InteractiveNetworkConnectException + excep; + excep.Server == aFTPURL.host(); + aRet <<= excep; + ucbhelper::cancelCommandExecution(aRet,Environment); + } } } else if(aOpenCommand.Mode == OpenMode::DOCUMENT_SHARE_DENY_NONE || @@ -503,54 +402,159 @@ Any SAL_CALL FtpContent::execute( } -// curl_slist_free_all(list); - - -rtl::OUString FtpContent::getParentURL() +rtl::OUString FTPContent::getParentURL() { return rtl::OUString(); } +extern void err_msg( const char* p, + const rtl::OUString& aOUString ); -Reference< XRow > FtpContent::getPropertyValues( - const Sequence< Property >& seqProp + +class FTPClientI + : public FTPClient +{ +public: + + FTPClientI(const Reference<XCommandEnvironment>& env); + + virtual rtl::OUString passwd() const; + +private: + + Reference<XCommandEnvironment> m_env; +}; + + + +Reference< XRow > FTPContent::getPropertyValues( + const Sequence< Property >& seqProp, + const Reference<XCommandEnvironment>& environment ) { - FTPDirentry aDirEntry; vos::ORef<::ucb::PropertyValueSet> xRow = new ::ucb::PropertyValueSet(m_xSMgr); - for(sal_Int32 i = 0; i < seqProp.getLength(); ++i) { - const rtl::OUString& Name = seqProp[i].Name; - if(Name.compareToAscii("ContentType") == 0) - xRow->appendString(seqProp[i], - rtl::OUString::createFromAscii( - "application/ftp")); - else if(Name.compareToAscii("Title") == 0) - xRow->appendString(seqProp[i],aDirEntry.m_aName); - else if(Name.compareToAscii("IsReadOnly") == 0) - xRow->appendBoolean(seqProp[i], - sal_Bool(aDirEntry.m_nMode & - INETCOREFTP_FILEMODE_WRITE)); - else if(Name.compareToAscii("IsDocument") == 0) - xRow->appendBoolean(seqProp[i], - ! sal_Bool(aDirEntry.m_nMode & - INETCOREFTP_FILEMODE_ISDIR)); - else if(Name.compareToAscii("IsFolder") == 0) - xRow->appendBoolean(seqProp[i], - sal_Bool(aDirEntry.m_nMode & - INETCOREFTP_FILEMODE_ISDIR)); - else if(Name.compareToAscii("Size") == 0) - xRow->appendLong(seqProp[i], - aDirEntry.m_nSize); - else if(Name.compareToAscii("DateCreated") == 0) - xRow->appendTimestamp(seqProp[i], - aDirEntry.m_aDate); - else - xRow->appendVoid(seqProp[i]); + FTPURL aFTPURL(m_xIdentifier->getContentIdentifier(), + m_pFCP); + + rtl::OUString passwd; + bool retried(false); + FTPDirentry aDirEntry; + + tryconnect: + try { + aDirEntry = aFTPURL.direntry(passwd); + for(sal_Int32 i = 0; i < seqProp.getLength(); ++i) { + const rtl::OUString& Name = seqProp[i].Name; + if(Name.compareToAscii("ContentType") == 0) + xRow->appendString(seqProp[i], + rtl::OUString::createFromAscii( + "application/ftp")); + else if(Name.compareToAscii("Title") == 0) + xRow->appendString(seqProp[i],aDirEntry.m_aName); + else if(Name.compareToAscii("IsReadOnly") == 0) + xRow->appendBoolean(seqProp[i], + ! sal_Bool(aDirEntry.m_nMode & + INETCOREFTP_FILEMODE_WRITE)); + else if(Name.compareToAscii("IsDocument") == 0) + xRow->appendBoolean(seqProp[i], + ! sal_Bool(aDirEntry.m_nMode & + INETCOREFTP_FILEMODE_ISDIR)); + else if(Name.compareToAscii("IsFolder") == 0) + xRow->appendBoolean(seqProp[i], + sal_Bool(aDirEntry.m_nMode & + INETCOREFTP_FILEMODE_ISDIR)); + else if(Name.compareToAscii("Size") == 0) + xRow->appendLong(seqProp[i], + aDirEntry.m_nSize); + else if(Name.compareToAscii("DateCreated") == 0) + xRow->appendTimestamp(seqProp[i], + aDirEntry.m_aDate); + else + xRow->appendVoid(seqProp[i]); + } + } catch(const no_such_directory_exception& e) { + if(e.code() == CURLE_FTP_ACCESS_DENIED && !retried) { + retried = true; + FTPClientI aClient(environment); + passwd = aClient.passwd(); + goto tryconnect; + } + else if(e.code() == CURLE_COULDNT_CONNECT) { + InteractiveNetworkConnectException excep; + excep.Server == aFTPURL.host(); + for(sal_Int32 i = 0; i < seqProp.getLength(); ++i) { + xRow->appendVoid(seqProp[i]); + } + } } return Reference<XRow>(xRow.getBodyPtr()); } + + + +// Some minor defs for 'ftpstrcont.hxx' + + +FTPOutputStreamContainer::FTPOutputStreamContainer( + const Reference<XOutputStream>& out) + : m_out(out) { } + + +int FTPOutputStreamContainer::write( + void *buffer,size_t size,size_t nmemb) +{ + size_t ret = size*nmemb; + if(ret && m_out.is()) { + try { + m_out->writeBytes( + Sequence<sal_Int8>(static_cast<sal_Int8*>(buffer), + ret) + ); + return ret; + } catch(const Exception&) { + } + } + return 0; +} + + + +FTPInputStreamContainer::FTPInputStreamContainer( + FTPInputStream* out) + : m_out(out) +{ +} + +int FTPInputStreamContainer::write( + void *buffer,size_t size,size_t nmemb) +{ + size_t ret = size*nmemb; + if(ret && m_out) { + m_out->append(buffer,size,nmemb); + return ret; + } + return 0; +} + +Reference<XInputStream> FTPInputStreamContainer::operator()() +{ + return Reference<XInputStream>(m_out); +} + + + + +FTPClientI::FTPClientI(const Reference<XCommandEnvironment>& env) + : m_env(env) +{ +} + +rtl::OUString FTPClientI::passwd() const +{ + return rtl::OUString::createFromAscii("abi:psswd"); +} diff --git a/ucb/source/ucp/ftp/ftpcontent.hxx b/ucb/source/ucp/ftp/ftpcontent.hxx index b9f140ec8325..872a90c1936a 100644 --- a/ucb/source/ucp/ftp/ftpcontent.hxx +++ b/ucb/source/ucp/ftp/ftpcontent.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpcontent.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:12:55 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -86,7 +86,7 @@ namespace ftp //========================================================================= // UNO service name for the content. -#define MYUCP_CONTENT_SERVICE_NAME "com.sun.star.ucb.FtpContent" +#define MYUCP_CONTENT_SERVICE_NAME "com.sun.star.ucb.FTPContent" //========================================================================= @@ -103,23 +103,23 @@ namespace ftp //========================================================================= - class FtpContentProvider; + class FTPContentProvider; //========================================================================= - class FtpContent + class FTPContent : public ::ucb::ContentImplHelper { public: - FtpContent( const ::com::sun::star::uno::Reference< + FTPContent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, - FtpContentProvider* pProvider, + FTPContentProvider* pProvider, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier >& Identifier); - virtual ~FtpContent(); + virtual ~FTPContent(); // XInterface XINTERFACE_DECL() @@ -152,7 +152,7 @@ namespace ftp private: - FtpContentProvider *m_pFCP; + FTPContentProvider *m_pFCP; virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > getProperties( const com::sun::star::uno::Reference< @@ -170,7 +170,9 @@ namespace ftp com::sun::star::uno::Reference<com::sun::star::sdbc::XRow> getPropertyValues( const com::sun::star::uno::Sequence< - com::sun::star::beans::Property>& seqProp + com::sun::star::beans::Property>& seqProp, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ); }; diff --git a/ucb/source/ucp/ftp/ftpcontentcaps.cxx b/ucb/source/ucp/ftp/ftpcontentcaps.cxx index b0e498ca1678..68f7c6b3eecc 100644 --- a/ucb/source/ucp/ftp/ftpcontentcaps.cxx +++ b/ucb/source/ucp/ftp/ftpcontentcaps.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpcontentcaps.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:12:57 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -78,7 +78,7 @@ using namespace rtl; using namespace ftp; // virtual -Sequence< Property > FtpContent::getProperties( +Sequence< Property > FTPContent::getProperties( const Reference< XCommandEnvironment > & xEnv ) { @@ -133,7 +133,7 @@ Sequence< Property > FtpContent::getProperties( //========================================================================= // virtual -Sequence< CommandInfo > FtpContent::getCommands( +Sequence< CommandInfo > FTPContent::getCommands( const Reference< XCommandEnvironment > & xEnv ) { // osl::MutexGuard aGuard( m_aMutex ); diff --git a/ucb/source/ucp/ftp/ftpcontentidentifier.cxx b/ucb/source/ucp/ftp/ftpcontentidentifier.cxx index 05188fd4e19e..144b9d2fc100 100644 --- a/ucb/source/ucp/ftp/ftpcontentidentifier.cxx +++ b/ucb/source/ucp/ftp/ftpcontentidentifier.cxx @@ -1,58 +1,72 @@ #include "ftpcontentidentifier.hxx" - using namespace ftp; using namespace com::sun::star::uno; using namespace com::sun::star::ucb; -FtpContentIdentifier::FtpContentIdentifier(const rtl::OUString& aIdent) - : m_aIdent(aIdent) +FTPContentIdentifier::FTPContentIdentifier( + const rtl::OUString& aIdent, + FTPContentProvider* pFCP +) + : m_pURL(new FTPURL(aIdent,pFCP)) +{ +} + +FTPContentIdentifier::FTPContentIdentifier(FTPURL* pURL) + : m_pURL(pURL) +{ +} + + +FTPContentIdentifier::~FTPContentIdentifier() { + delete m_pURL; } Any SAL_CALL -FtpContentIdentifier::queryInterface( +FTPContentIdentifier::queryInterface( const Type& rType ) throw( RuntimeException ) { - Any aRet = ::cppu::queryInterface(rType, - SAL_STATIC_CAST(XContentIdentifier*,this)); + Any aRet = + ::cppu::queryInterface(rType, + SAL_STATIC_CAST(XContentIdentifier*,this)); return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); } -void SAL_CALL FtpContentIdentifier::acquire( void ) throw() { +void SAL_CALL FTPContentIdentifier::acquire( void ) throw() { OWeakObject::acquire(); } -void SAL_CALL FtpContentIdentifier::release( void ) throw() { +void SAL_CALL FTPContentIdentifier::release( void ) throw() { OWeakObject::release(); } ::rtl::OUString SAL_CALL -FtpContentIdentifier::getContentIdentifier( +FTPContentIdentifier::getContentIdentifier( ) throw ( ::com::sun::star::uno::RuntimeException ) { - return m_aIdent; + return m_pURL->ident(); } ::rtl::OUString SAL_CALL -FtpContentIdentifier::getContentProviderScheme( +FTPContentIdentifier::getContentProviderScheme( ) throw ( ::com::sun::star::uno::RuntimeException diff --git a/ucb/source/ucp/ftp/ftpcontentidentifier.hxx b/ucb/source/ucp/ftp/ftpcontentidentifier.hxx index d9859ccb5455..8a62142f8c08 100644 --- a/ucb/source/ucp/ftp/ftpcontentidentifier.hxx +++ b/ucb/source/ucp/ftp/ftpcontentidentifier.hxx @@ -1,26 +1,36 @@ #ifndef _FTP_FTPCONTENTIDENTIFIER_HXX_ #define _FTP_FTPCONTENTIDENTIFIER_HXX_ -#ifndef _CPPUHELPER_WEAK_HXX_ +#include <vector> +#include <curl/curl.h> +#include <curl/easy.h> #include <cppuhelper/weak.hxx> -#endif -#ifndef _CPPUHELPER_QUERYINTERFACE_HXX_ #include <cppuhelper/queryinterface.hxx> -#endif -#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ #include <com/sun/star/ucb/XContentIdentifier.hpp> -#endif +#include <com/sun/star/io/XOutputStream.hpp> +#include "ftpdirp.hxx" +#include "ftpurl.hxx" + namespace ftp { - class FtpContentIdentifier + + class FTPContentProvider; + + + class FTPContentIdentifier : public cppu::OWeakObject, public com::sun::star::ucb::XContentIdentifier { public: - FtpContentIdentifier(const rtl::OUString& ident); + FTPContentIdentifier(const rtl::OUString& ident, + FTPContentProvider* pFCP = 0); + + FTPContentIdentifier(FTPURL *pURL); + + ~FTPContentIdentifier(); // XInterface @@ -49,9 +59,10 @@ namespace ftp { ::com::sun::star::uno::RuntimeException ); + private: - rtl::OUString m_aIdent; + FTPURL *m_pURL; }; } diff --git a/ucb/source/ucp/ftp/ftpcontentprovider.cxx b/ucb/source/ucp/ftp/ftpcontentprovider.cxx index 78d780600f69..fdc46525c1c1 100644 --- a/ucb/source/ucp/ftp/ftpcontentprovider.cxx +++ b/ucb/source/ucp/ftp/ftpcontentprovider.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpcontentprovider.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:06 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -91,7 +91,7 @@ using namespace com::sun::star::ucb; //========================================================================= //========================================================================= -FtpContentProvider::FtpContentProvider(const Reference< XMultiServiceFactory >& rSMgr) +FTPContentProvider::FTPContentProvider(const Reference< XMultiServiceFactory >& rSMgr) : ::ucb::ContentProviderImplHelper(rSMgr), m_ftpLoaderThread(NULL) { @@ -99,7 +99,7 @@ FtpContentProvider::FtpContentProvider(const Reference< XMultiServiceFactory >& //========================================================================= // virtual -FtpContentProvider::~FtpContentProvider() +FTPContentProvider::~FTPContentProvider() { delete m_ftpLoaderThread; } @@ -110,7 +110,7 @@ FtpContentProvider::~FtpContentProvider() // //========================================================================= -XINTERFACE_IMPL_3( FtpContentProvider, +XINTERFACE_IMPL_3( FTPContentProvider, XTypeProvider, XServiceInfo, XContentProvider); @@ -121,7 +121,7 @@ XINTERFACE_IMPL_3( FtpContentProvider, // //========================================================================= -XTYPEPROVIDER_IMPL_3( FtpContentProvider, +XTYPEPROVIDER_IMPL_3( FTPContentProvider, XTypeProvider, XServiceInfo, XContentProvider); @@ -132,8 +132,8 @@ XTYPEPROVIDER_IMPL_3( FtpContentProvider, // //========================================================================= -XSERVICEINFO_IMPL_1(FtpContentProvider, - rtl::OUString::createFromAscii("com.sun.star.comp.FtpContentProvider"), +XSERVICEINFO_IMPL_1(FTPContentProvider, + rtl::OUString::createFromAscii("com.sun.star.comp.FTPContentProvider"), rtl::OUString::createFromAscii(MYUCP_CONTENT_PROVIDER_SERVICE_NAME)); //========================================================================= @@ -142,7 +142,7 @@ XSERVICEINFO_IMPL_1(FtpContentProvider, // //========================================================================= -ONE_INSTANCE_SERVICE_FACTORY_IMPL(FtpContentProvider); +ONE_INSTANCE_SERVICE_FACTORY_IMPL(FTPContentProvider); //========================================================================= @@ -153,7 +153,7 @@ ONE_INSTANCE_SERVICE_FACTORY_IMPL(FtpContentProvider); // virtual Reference<XContent> SAL_CALL -FtpContentProvider::queryContent( +FTPContentProvider::queryContent( const Reference< XContentIdentifier >& xCanonicId ) throw( @@ -179,18 +179,18 @@ FtpContentProvider::queryContent( } } - xContent = new FtpContent(m_xSMgr,this,xCanonicId); + xContent = new FTPContent(m_xSMgr,this,xCanonicId); // may throw IllegalIdentifierException return xContent; } -void FtpContentProvider::init() { - m_ftpLoaderThread = new FtpLoaderThread(); +void FTPContentProvider::init() { + m_ftpLoaderThread = new FTPLoaderThread(); } -CURL* FtpContentProvider::handle() { +CURL* FTPContentProvider::handle() { // Cannot be zero if called from here; return m_ftpLoaderThread->handle(); } diff --git a/ucb/source/ucp/ftp/ftpcontentprovider.hxx b/ucb/source/ucp/ftp/ftpcontentprovider.hxx index 06302e7dfdbd..d74dd7ed3315 100644 --- a/ucb/source/ucp/ftp/ftpcontentprovider.hxx +++ b/ucb/source/ucp/ftp/ftpcontentprovider.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpcontentprovider.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2002-06-20 14:49:21 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -82,7 +82,7 @@ // UNO service name for the provider. This name will be used by the UCB to // create instances of the provider. -#define MYUCP_CONTENT_PROVIDER_SERVICE_NAME "com.sun.star.ucb.FtpContentProvider" +#define MYUCP_CONTENT_PROVIDER_SERVICE_NAME "com.sun.star.ucb.FTPContentProvider" #define MYUCP_CONTENT_PROVIDER_SERVICE_NAME_LENGTH 35 #define MYUCP_URL_SCHEME "ftp" #define MYUCP_URL_SCHEME_LENGTH 3 @@ -98,16 +98,16 @@ namespace ftp { - class FtpLoaderThread; + class FTPLoaderThread; - class FtpContentProvider: + class FTPContentProvider: public ::ucb::ContentProviderImplHelper { public: - FtpContentProvider(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>& xMSF ); - ~FtpContentProvider(); + FTPContentProvider(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>& xMSF ); + ~FTPContentProvider(); // XInterface XINTERFACE_DECL() @@ -148,12 +148,12 @@ namespace ftp { private: osl::Mutex m_aMutex; - FtpLoaderThread *m_ftpLoaderThread; + FTPLoaderThread *m_ftpLoaderThread; void init(); - }; // end class FtpContentProvider + }; // end class FTPContentProvider } // end namespace ftp diff --git a/ucb/source/ucp/ftp/ftpdirp.hxx b/ucb/source/ucp/ftp/ftpdirp.hxx index c312accce25b..c08940c3befe 100644 --- a/ucb/source/ucp/ftp/ftpdirp.hxx +++ b/ucb/source/ucp/ftp/ftpdirp.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpdirp.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:11 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -125,7 +125,7 @@ namespace ftp { * *======================================================================*/ - enum FtpDirentryMode { INETCOREFTP_FILEMODE_UNKNOWN = 0x00, + enum FTPDirentryMode { INETCOREFTP_FILEMODE_UNKNOWN = 0x00, INETCOREFTP_FILEMODE_READ = 0x01, INETCOREFTP_FILEMODE_WRITE = 0x02, INETCOREFTP_FILEMODE_ISDIR = 0x04, diff --git a/ucb/source/ucp/ftp/ftpdynresultset.cxx b/ucb/source/ucp/ftp/ftpdynresultset.cxx index ff8a06aea751..6fe9412ebeaa 100644 --- a/ucb/source/ucp/ftp/ftpdynresultset.cxx +++ b/ucb/source/ucp/ftp/ftpdynresultset.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpdynresultset.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:15 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,7 +87,7 @@ using namespace ftp; DynamicResultSet::DynamicResultSet( const Reference< XMultiServiceFactory >& rxSMgr, - const vos::ORef< FtpContent >& rxContent, + const vos::ORef< FTPContent >& rxContent, const OpenCommandArgument2& rCommand, const Reference< XCommandEnvironment >& rxEnv, ResultSetFactory* pFactory ) diff --git a/ucb/source/ucp/ftp/ftpdynresultset.hxx b/ucb/source/ucp/ftp/ftpdynresultset.hxx index aef86c145b20..7e98e6d74fae 100644 --- a/ucb/source/ucp/ftp/ftpdynresultset.hxx +++ b/ucb/source/ucp/ftp/ftpdynresultset.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpdynresultset.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:19 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -78,7 +78,7 @@ namespace ftp { class DynamicResultSet : public ::ucb::ResultSetImplHelper { - vos::ORef< FtpContent > m_xContent; + vos::ORef< FTPContent > m_xContent; com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xEnv; ResultSetFactory* m_pFactory; @@ -91,7 +91,7 @@ namespace ftp { DynamicResultSet( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr, - const vos::ORef< FtpContent >& rxContent, + const vos::ORef< FTPContent >& rxContent, const com::sun::star::ucb::OpenCommandArgument2& rCommand, const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv, diff --git a/ucb/source/ucp/ftp/ftpinpstr.cxx b/ucb/source/ucp/ftp/ftpinpstr.cxx index eb7f97806884..31f2c62cce98 100644 --- a/ucb/source/ucp/ftp/ftpinpstr.cxx +++ b/ucb/source/ucp/ftp/ftpinpstr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpinpstr.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:23 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -83,7 +83,7 @@ using namespace com::sun::star::lang; using namespace com::sun::star::io; -FtpInputStream::FtpInputStream() +FTPInputStream::FTPInputStream() : m_nMaxLen(1024*1024), m_nLen(0), m_nWritePos(0), @@ -92,12 +92,19 @@ FtpInputStream::FtpInputStream() m_pFile(0) { } -FtpInputStream::~FtpInputStream() { + +FTPInputStream::~FTPInputStream() { rtl_freeMemory(m_pBuffer); } -Any SAL_CALL FtpInputStream::queryInterface( const Type& rType ) throw( RuntimeException ) { +Any SAL_CALL FTPInputStream::queryInterface( + const Type& rType +) + throw( + RuntimeException + ) +{ Any aRet = ::cppu::queryInterface(rType, SAL_STATIC_CAST( XInputStream*,this ), SAL_STATIC_CAST( XSeekable*,this ) ); @@ -107,13 +114,13 @@ Any SAL_CALL FtpInputStream::queryInterface( const Type& rType ) throw( RuntimeE -void SAL_CALL FtpInputStream::acquire( void ) throw() { +void SAL_CALL FTPInputStream::acquire( void ) throw() { OWeakObject::acquire(); } -void SAL_CALL FtpInputStream::release( void ) throw() { +void SAL_CALL FTPInputStream::release( void ) throw() { OWeakObject::release(); } @@ -122,7 +129,7 @@ void SAL_CALL FtpInputStream::release( void ) throw() { returns zero written bytes. */ -sal_Int32 SAL_CALL FtpInputStream::readBytes(Sequence< sal_Int8 >& aData, +sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(NotConnectedException, BufferSizeExceededException, @@ -130,7 +137,8 @@ sal_Int32 SAL_CALL FtpInputStream::readBytes(Sequence< sal_Int8 >& aData, RuntimeException) { osl::MutexGuard aGuard( m_aMutex ); - sal_Int32 curr(std::min(nBytesToRead,sal_Int32(m_nWritePos)-sal_Int32(m_nReadPos))); + sal_Int32 curr = + std::min(nBytesToRead,sal_Int32(m_nWritePos)-sal_Int32(m_nReadPos)); if(0 <= curr && aData.getLength() < curr) aData.realloc(curr); @@ -142,7 +150,7 @@ sal_Int32 SAL_CALL FtpInputStream::readBytes(Sequence< sal_Int8 >& aData, } -sal_Int32 SAL_CALL FtpInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,sal_Int32 nMaxBytesToRead ) +sal_Int32 SAL_CALL FTPInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,sal_Int32 nMaxBytesToRead ) throw( NotConnectedException, BufferSizeExceededException, IOException, @@ -153,12 +161,12 @@ sal_Int32 SAL_CALL FtpInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,sa -void SAL_CALL FtpInputStream::skipBytes(sal_Int32 nBytesToSkip) +void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) { - osl::MutexGuard aGuard( m_aMutex ); + osl::MutexGuard aGuard(m_aMutex); if(nBytesToSkip < 0) throw IOException(); m_nReadPos += nBytesToSkip; @@ -168,100 +176,125 @@ void SAL_CALL FtpInputStream::skipBytes(sal_Int32 nBytesToSkip) -sal_Int32 SAL_CALL FtpInputStream::available(void) +sal_Int32 SAL_CALL FTPInputStream::available(void) throw(NotConnectedException, IOException, RuntimeException) { - osl::MutexGuard aGuard( m_aMutex ); - return std::max(sal_Int32(m_nWritePos)-sal_Int32(m_nReadPos),sal_Int32(0)); + osl::MutexGuard aGuard(m_aMutex); + return std::max(sal_Int32(m_nWritePos)-sal_Int32(m_nReadPos),sal_Int32(0)); } -void SAL_CALL FtpInputStream::closeInput(void) +void SAL_CALL FTPInputStream::closeInput(void) throw(NotConnectedException, IOException, RuntimeException) { + // fclose(m_pFile); } -void SAL_CALL FtpInputStream::seek(sal_Int64 location) +void SAL_CALL FTPInputStream::seek(sal_Int64 location) throw( IllegalArgumentException, IOException, RuntimeException ) { - osl::MutexGuard aGuard( m_aMutex ); + osl::MutexGuard aGuard(m_aMutex); if(location < 0) throw IllegalArgumentException(); m_nReadPos = sal_uInt32(location); - if(m_nReadPos > m_nWritePos) // Can't seek behind the end of the current write-position. + if(m_nReadPos > m_nWritePos) // Can't seek behind the end + // // of the current write-position. m_nReadPos = m_nWritePos; } sal_Int64 SAL_CALL -FtpInputStream::getPosition( +FTPInputStream::getPosition( void ) throw( IOException, RuntimeException ) { - osl::MutexGuard aGuard( m_aMutex ); + osl::MutexGuard aGuard(m_aMutex); return sal_Int64(m_nReadPos); } -sal_Int64 SAL_CALL FtpInputStream::getLength( void ) throw( - IOException,RuntimeException) { - osl::MutexGuard aGuard( m_aMutex ); +sal_Int64 SAL_CALL FTPInputStream::getLength( + void +) throw( + IOException,RuntimeException +) +{ + osl::MutexGuard aGuard(m_aMutex); return sal_Int64(m_nWritePos); } -const void* FtpInputStream::getBuffer(void) const throw() +const void* FTPInputStream::getBuffer( + void +) const + throw( + ) { + osl::MutexGuard aGuard(m_aMutex); return m_pBuffer; } +// void +// FTPInputStream::append( +// const void* pBuffer, +// size_t size, +// size_t nmemb +// ) throw() +// { +// if(!m_pFile) +// m_pFile = tmpfile(); + +// fwrite(pBuffer,size,nmemb,m_pFile); +// } void -FtpInputStream::append( +FTPInputStream::append( const void* pBuffer, size_t size, size_t nmemb ) throw() { - if(m_pFile) - append2File(pBuffer,size,nmemb); - - osl::MutexGuard aGuard( m_aMutex ); + osl::MutexGuard aGuard(m_aMutex); sal_uInt32 nLen = size*nmemb; sal_uInt32 tmp(nLen + m_nWritePos); - if(tmp > 1024*1024) { - // if download is larger than 1MB store in file - m_pFile = tmpfile(); - fwrite(m_pBuffer,m_nWritePos,1,m_pFile); - rtl_freeMemory(m_pBuffer),m_nLen = 0,m_nWritePos = 0,m_nReadPos = 0; - } - else + if(m_nLen < tmp) { // enlarge in steps of multiples of 1K do { m_nLen+=1024; - } while(m_nLen < tmp); + } while(m_nLen < tmp); m_pBuffer = rtl_reallocateMemory(m_pBuffer,m_nLen); } + rtl_copyMemory(static_cast<sal_Int8*>(m_pBuffer)+m_nWritePos, pBuffer,nLen); m_nWritePos = tmp; } +void FTPInputStream::reset() throw() +{ + osl::MutexGuard aGuard(m_aMutex); + m_nLen = 0; + m_nWritePos = 0; + m_nReadPos = 0; + rtl_freeMemory(m_pBuffer),m_pBuffer = 0; +} + + void -FtpInputStream::append2File( +FTPInputStream::append2File( const void* pBuffer, size_t size, size_t nmemb diff --git a/ucb/source/ucp/ftp/ftpinpstr.hxx b/ucb/source/ucp/ftp/ftpinpstr.hxx index 49be6ded94b9..cc8f76fab14a 100644 --- a/ucb/source/ucp/ftp/ftpinpstr.hxx +++ b/ucb/source/ucp/ftp/ftpinpstr.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpinpstr.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:24 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -96,7 +96,7 @@ namespace ftp { namespace css = com::sun::star; - class FtpInputStream + class FTPInputStream : public cppu::OWeakObject, public com::sun::star::io::XInputStream, public com::sun::star::io::XSeekable @@ -107,9 +107,9 @@ namespace ftp { * on which the inputstream acts. */ - FtpInputStream(); + FTPInputStream(); - ~FtpInputStream(); + ~FTPInputStream(); virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& rType) throw(css::uno::RuntimeException); @@ -183,6 +183,8 @@ namespace ftp { const void* getBuffer() const throw(); + void reset() throw(); + private: /** Don't hold more than 1MB in memory. @@ -190,7 +192,7 @@ namespace ftp { const sal_uInt32 m_nMaxLen; - osl::Mutex m_aMutex; + mutable osl::Mutex m_aMutex; sal_uInt32 m_nLen,m_nWritePos,m_nReadPos; void* m_pBuffer; diff --git a/ucb/source/ucp/ftp/ftploaderthread.cxx b/ucb/source/ucp/ftp/ftploaderthread.cxx index 764ed1233875..90d023dc9533 100644 --- a/ucb/source/ucp/ftp/ftploaderthread.cxx +++ b/ucb/source/ucp/ftp/ftploaderthread.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftploaderthread.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: abi $ $Date: 2002-06-24 15:17:55 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -99,24 +99,24 @@ extern "C" { /********************************************************************************/ /* */ -/* Member part of FtpLoaderThread */ +/* Member part of FTPLoaderThread */ /* */ /********************************************************************************/ -FtpLoaderThread::FtpLoaderThread() +FTPLoaderThread::FTPLoaderThread() : m_threadKey(osl_createThreadKey(delete_CURL)) { } -FtpLoaderThread::~FtpLoaderThread() { +FTPLoaderThread::~FTPLoaderThread() { osl_destroyThreadKey(m_threadKey); } -CURL* FtpLoaderThread::handle() { +CURL* FTPLoaderThread::handle() { CURL* ret; if(!(ret = osl_getThreadKeyData(m_threadKey))) { ret = curl_easy_init(); diff --git a/ucb/source/ucp/ftp/ftploaderthread.hxx b/ucb/source/ucp/ftp/ftploaderthread.hxx index 7f210abf2efa..73c9b232a569 100644 --- a/ucb/source/ucp/ftp/ftploaderthread.hxx +++ b/ucb/source/ucp/ftp/ftploaderthread.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftploaderthread.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:25 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -80,15 +80,15 @@ namespace ftp { /** A loaderthread acts as factory for CURL-handles, * the key being ( implicit ) the threadid. - * Owner is a FtpContentProvider-instance + * Owner is a FTPContentProvider-instance */ - class FtpLoaderThread + class FTPLoaderThread { public: - FtpLoaderThread(); - ~FtpLoaderThread(); + FTPLoaderThread(); + ~FTPLoaderThread(); CURL* handle(); @@ -99,12 +99,12 @@ namespace ftp { * Not defined: */ - FtpLoaderThread(const FtpLoaderThread&); - FtpLoaderThread& operator=(const FtpLoaderThread&); + FTPLoaderThread(const FTPLoaderThread&); + FTPLoaderThread& operator=(const FTPLoaderThread&); oslThreadKey m_threadKey; - }; // end class FtpLoaderThread + }; // end class FTPLoaderThread } diff --git a/ucb/source/ucp/ftp/ftpresultsetI.cxx b/ucb/source/ucp/ftp/ftpresultsetI.cxx index 5c34f48a00e7..8f5718711106 100644 --- a/ucb/source/ucp/ftp/ftpresultsetI.cxx +++ b/ucb/source/ucp/ftp/ftpresultsetI.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpresultsetI.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:29 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,18 +59,12 @@ * ************************************************************************/ -#ifndef _COM_SUN_STAR_UCB_COMMAND_HPP_ +#include <ucbhelper/propertyvalueset.hxx> +#include <vos/ref.hxx> #include <com/sun/star/ucb/Command.hpp> -#endif -#ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_ #include <com/sun/star/ucb/XCommandEnvironment.hpp> -#endif -#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ #include <com/sun/star/ucb/XCommandProcessor.hpp> -#endif #include <com/sun/star/sdbc/XRow.hpp> -#include <ucbhelper/propertyvalueset.hxx> -#include <vos/ref.hxx> #include "ftpresultsetI.hxx" @@ -120,7 +114,7 @@ ResultSetI::ResultSetI(const Reference< lang::XMultiServiceFactory >& xMSF, else if(Name.compareToAscii("IsDocument") == 0) xRow->appendBoolean(seqProp[i], ! sal_Bool(dirvec[n].m_nMode & - INETCOREFTP_FILEMODE_ISDIR)); + INETCOREFTP_FILEMODE_ISDIR)); else if(Name.compareToAscii("IsFolder") == 0) xRow->appendBoolean(seqProp[i], sal_Bool(dirvec[n].m_nMode & @@ -136,124 +130,4 @@ ResultSetI::ResultSetI(const Reference< lang::XMultiServiceFactory >& xMSF, } m_aItems[n] = Reference<XRow>(xRow.getBodyPtr()); } - -// unsigned int i; -// vector< vector< rtl::OUString > > queryList; - -// { -// sal_Int32 idx; -// rtl::OUString query = m_aURLParameter.get_query(); -// while( query.getLength() ) -// { -// idx = query.indexOf( sal_Unicode( ' ' ) ); -// if( idx == -1 ) -// idx = query.getLength(); - -// vector< rtl::OUString > currentQuery; -// currentQuery.push_back( query.copy( 0,idx ) ); -// queryList.push_back( currentQuery ); -// query = query.copy( 1 + idx ); -// } -// } - -// rtl::OUString scope = m_aURLParameter.get_scope(); -// StaticModuleInformation* inf = -// m_pDatabases->getStaticInformationForModule( m_aURLParameter.get_module(), -// m_aURLParameter.get_language() ); - -// if( inf ) -// { -// if( scope.compareToAscii( "Heading" ) == 0 ) -// scope = inf->get_heading(); -// else -// scope = inf->get_fulltext(); -// } - -// sal_Int32 hitCount = m_aURLParameter.get_hitCount(); - -// QueryResults* queryResults = 0; -// QueryHitIterator* it = 0; -// set< rtl::OUString > aSet,aCurrent,aResultSet; - -// try -// { -// rtl::OUString idxDir = -// m_pDatabases->getInstallPathAsURL() + -// m_pDatabases->lang( m_aURLParameter.get_language() ) + -// rtl::OUString::createFromAscii( "/" ) + -// m_aURLParameter.get_module() + -// rtl::OUString::createFromAscii( ".idx/" ); - -// for( i = 0; i < queryList.size(); ++i ) -// { -// QueryProcessor queryProcessor(idxDir); -// QueryStatement queryStatement(hitCount,queryList[i],scope); -// queryResults = queryProcessor.processQuery( queryStatement ); - -// it = 0; -// if( queryResults ) -// it = queryResults->makeQueryHitIterator(); - -// aSet.clear(); -// while( it && it->next() ) -// { -// QueryHitData* qhd = it->getHit( 0 /*PrefixTranslator*/ ); -// if(qhd) -// aSet.insert(qhd->getDocument()); -// } - -// delete it; // deletes also queryResults[i] - -// // intersect -// if( i == 0 ) -// aResultSet = aSet; -// else -// { -// aCurrent = aResultSet; -// aResultSet.clear(); -// set_intersection( aSet.begin(),aSet.end(), -// aCurrent.begin(),aCurrent.end(), -// inserter(aResultSet,aResultSet.begin())); -// } -// } -// } -// catch( IOException ) -// { -// } - -// sal_Int32 replIdx = rtl::OUString::createFromAscii( "#HLP#" ).getLength(); -// rtl::OUString replWith = rtl::OUString::createFromAscii( "vnd.sun.star.help://" ); - -// set< rtl::OUString >::const_iterator set_it = aResultSet.begin(); -// while( set_it != aResultSet.end() ) -// { -// m_aPath.push_back(replWith + set_it->copy(replIdx)); -// ++set_it; -// } - -// m_aItems.resize( m_aPath.size() ); -// m_aIdents.resize( m_aPath.size() ); - -// Command aCommand; -// aCommand.Name = rtl::OUString::createFromAscii( "getPropertyValues" ); -// aCommand.Argument <<= m_sProperty; - -// for( m_nRow = 0; m_nRow < m_aPath.size(); ++m_nRow ) -// { -// m_aPath[m_nRow] = -// m_aPath[m_nRow] + -// rtl::OUString::createFromAscii( "?Language=" ) + -// m_aURLParameter.get_language() + -// rtl::OUString::createFromAscii( "&System=" ) + -// m_aURLParameter.get_system(); - -// Reference< XContent > content = queryContent(); -// if( content.is() ) -// { -// Reference< XCommandProcessor > cmd( content,UNO_QUERY ); -// if( ! ( cmd->execute( aCommand,0,Reference< XCommandEnvironment >( 0 ) ) >>= m_aItems[m_nRow] ) ) -// ; -// } -// } -// m_nRow = -1; } diff --git a/ucb/source/ucp/ftp/ftpresultsetbase.hxx b/ucb/source/ucp/ftp/ftpresultsetbase.hxx index 3fba3da8ca69..74aa984875c1 100644 --- a/ucb/source/ucp/ftp/ftpresultsetbase.hxx +++ b/ucb/source/ucp/ftp/ftpresultsetbase.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpresultsetbase.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:35 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:15 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -186,10 +186,11 @@ namespace ftp { throw( com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException) { + rtl::OUString ret; if( 0 <= m_nRow && m_nRow < m_aItems.size() ) - return m_aItems[m_nRow]->getString( columnIndex ); - else - return rtl::OUString(); + ret = m_aItems[m_nRow]->getString( columnIndex ); + + return ret; } virtual sal_Bool SAL_CALL diff --git a/ucb/source/ucp/ftp/ftpservices.cxx b/ucb/source/ucp/ftp/ftpservices.cxx index 461bf64c116d..38cbdcf2bffa 100644 --- a/ucb/source/ucp/ftp/ftpservices.cxx +++ b/ucb/source/ucp/ftp/ftpservices.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ftpservices.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2002-06-07 15:31:00 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:16 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -128,12 +128,12 @@ extern "C" sal_Bool SAL_CALL component_writeInfo( return pRegistryKey && ////////////////////////////////////////////////////////////////////// - // Ftp Content Provider. + // FTP Content Provider. ////////////////////////////////////////////////////////////////////// writeInfo( pRegistryKey, - FtpContentProvider::getImplementationName_Static(), - FtpContentProvider::getSupportedServiceNames_Static() ); + FTPContentProvider::getImplementationName_Static(), + FTPContentProvider::getSupportedServiceNames_Static() ); } //========================================================================= @@ -148,13 +148,13 @@ extern "C" void * SAL_CALL component_getFactory( uno::Reference< lang::XSingleServiceFactory > xFactory; ////////////////////////////////////////////////////////////////////// - // Ftp Content Provider. + // FTP Content Provider. ////////////////////////////////////////////////////////////////////// - if ( FtpContentProvider::getImplementationName_Static(). + if ( FTPContentProvider::getImplementationName_Static(). compareToAscii( pImplName ) == 0 ) { - xFactory = FtpContentProvider::createServiceFactory( xSMgr ); + xFactory = FTPContentProvider::createServiceFactory( xSMgr ); } if ( xFactory.is() ) diff --git a/ucb/source/ucp/ftp/ftpstrcont.hxx b/ucb/source/ucp/ftp/ftpstrcont.hxx new file mode 100644 index 000000000000..a71374a59d10 --- /dev/null +++ b/ucb/source/ucp/ftp/ftpstrcont.hxx @@ -0,0 +1,54 @@ +#ifndef _FTP_STRCONT_HXX_ +#define _FTP_STRCONT_HXX_ + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include "ftpcfunc.hxx" + + +namespace ftp { + + + class FTPInputStream; + + + class FTPOutputStreamContainer + : public FTPStreamContainer + { + public: + + FTPOutputStreamContainer(const com::sun::star::uno::Reference< + com::sun::star::io::XOutputStream>& out); + + virtual write(void *buffer,size_t size,size_t nmemb); + + + private: + + com::sun::star::uno::Reference< + com::sun::star::io::XOutputStream> m_out; + }; + + + class FTPInputStreamContainer + : public FTPStreamContainer + { + public: + + FTPInputStreamContainer(FTPInputStream* out); + + virtual write(void *buffer,size_t size,size_t nmemb); + + com::sun::star::uno::Reference< + com::sun::star::io::XInputStream> operator()(); + + private: + + FTPInputStream* m_out; + }; + + +} + + +#endif diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx new file mode 100644 index 000000000000..b9e48c0072c7 --- /dev/null +++ b/ucb/source/ucp/ftp/ftpurl.cxx @@ -0,0 +1,421 @@ +/************************************************************************* + * + * $RCSfile: ftpurl.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2002-08-28 07:23:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#include <memory> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/ucb/OpenMode.hpp> + +#include "ftpstrcont.hxx" +#include "ftpurl.hxx" +#include "ftpcontentprovider.hxx" +#include "ftpinpstr.hxx" +#include "ftpcfunc.hxx" + +using namespace ftp; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; + + + +FTPURL::FTPURL(const rtl::OUString& url, + FTPContentProvider* pFCP) + throw( + malformed_exception + ) + : m_aIdent(url), + m_nPort(21), + m_pFCP(pFCP) +{ + parse(); +} + + +FTPURL::~FTPURL() +{ +} + + +void FTPURL::parse() + throw( + malformed_exception + ) +{ + rtl::OString aIdent(m_aIdent.getStr(), + m_aIdent.getLength(), + RTL_TEXTENCODING_UTF8); + char *buffer = new char[1+aIdent.getLength()]; + + const char* p2 = aIdent.getStr(); + + if(strncmp("ftp://",p2,6)) + throw malformed_exception(); + + p2 += 6; + + char ch; + char *p1 = buffer; // determine "username:password@host:port" + while((ch = *p2++) != '/' && ch) + *p1++ = ch; + *p1 = 0; + + m_aUsername = rtl::OUString(buffer,strlen(buffer), + RTL_TEXTENCODING_UTF8); + + while(ch) { // now determine the pathsegments + p1 = buffer; + while((ch = *p2++) != '/' && ch) + *p1++ = ch; + *p1 = 0; + + if(buffer[0]) { + if(strcmp(buffer,"..") == 0 && + m_aPathSegmentVec.size() && + m_aPathSegmentVec.back().equalsAscii("..")) + m_aPathSegmentVec.pop_back(); + else if(strcmp(buffer,".") == 0) + ; // Ignore + else + // This is a legal name. + m_aPathSegmentVec.push_back( + rtl::OUString(buffer, + strlen(buffer), + RTL_TEXTENCODING_UTF8)); + } + } + + delete[] buffer; + + // No rebuild the url as one without ellipses. + rtl::OUStringBuffer bff(m_aIdent.getLength()); + bff.appendAscii("ftp://"); + if(m_aUsername.getLength()) + bff.append(m_aUsername); + for(unsigned i = 0; i < m_aPathSegmentVec.size(); ++i) + bff.append(sal_Unicode('/')).append(m_aPathSegmentVec[i]); + + m_aIdent = bff.makeStringAndClear(); +} + + +rtl::OUString FTPURL::ident() const +{ + return m_aIdent; +} + + +/** Listing of a directory. + */ + + +std::vector<FTPDirentry> FTPURL::list( + sal_Int16 nMode +) const + throw( + no_such_directory_exception + ) +{ + CURL *curl = m_pFCP->handle(); + + std::auto_ptr<FTPInputStream> control(new FTPInputStream()); // control + FTPInputStreamContainer controlContainer(control.get()); + curl_easy_setopt(curl, + CURLOPT_HEADERFUNCTION, + ftp_write); + curl_easy_setopt(curl, + CURLOPT_WRITEHEADER, + &controlContainer); + + + curl_easy_setopt(curl,CURLOPT_NOBODY,false); // data + std::auto_ptr<FTPInputStream> data(new FTPInputStream()); + FTPInputStreamContainer dataContainer(data.get()); + curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,ftp_write); + curl_easy_setopt(curl,CURLOPT_WRITEDATA,&dataContainer); + + rtl::OUString url(ident()); // setting the URL + if(1+url.lastIndexOf(sal_Unicode('/')) != url.getLength()) + url += rtl::OUString::createFromAscii("/"); + + curl_easy_setopt(curl, + CURLOPT_URL, + rtl::OString(url.getStr(), + url.getLength(), + // Only ASCII in URLs => UTF8 ok + RTL_TEXTENCODING_UTF8).getStr()); + + curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0); + + CURLcode err = curl_easy_perform(curl); + if(err != CURLE_OK) + throw no_such_directory_exception(err); + + // now evaluate the error messages + + sal_uInt32 len = (sal_uInt32) data->getLength(); + char* fwd = (char*) data->getBuffer(); + char *p1, *p2; + p1 = p2 = fwd; + + enum OS { + DOS,UNIX,VMS,UNKNOWN + }; + + OS osKind(UNKNOWN); + std::vector<FTPDirentry> resvec; + FTPDirentry aDirEntry; + + while(true) { + while(p2-fwd < int(len) && *p2 != '\n') ++p2; + if(p2-fwd == int(len)) break; + + *p2 = 0; + switch(osKind) { + // While FTP knows the 'system'-command, + // which returns the operating system type, + // this is not usable here: There are Windows-server + // formatting the output like UNIX-ls command. + case DOS: + FTPDirectoryParser::parseDOS(aDirEntry,p1); + break; + case UNIX: + FTPDirectoryParser::parseUNIX(aDirEntry,p1); + break; + case VMS: + FTPDirectoryParser::parseVMS(aDirEntry,p1); + break; + default: + if(FTPDirectoryParser::parseUNIX(aDirEntry,p1)) + osKind = UNIX; + else if(FTPDirectoryParser::parseDOS(aDirEntry,p1)) + osKind = DOS; + else if(FTPDirectoryParser::parseVMS(aDirEntry,p1)) + osKind = VMS; + } + aDirEntry.m_aName = aDirEntry.m_aName.trim(); + if(osKind != int(UNKNOWN) && + !aDirEntry.m_aName.equalsAscii("..") && + !aDirEntry.m_aName.equalsAscii(".")) { + if(1 + url.lastIndexOf(sal_Unicode('/')) == + url.getLength()) + aDirEntry.m_aURL = + url + + aDirEntry.m_aName; + else + aDirEntry.m_aURL = + url + + sal_Unicode('/') + + aDirEntry.m_aName; + sal_Bool isDir = + sal_Bool(aDirEntry.m_nMode&INETCOREFTP_FILEMODE_ISDIR); + switch(nMode) { + case OpenMode::DOCUMENTS: + if(!isDir) { + resvec.push_back(aDirEntry); + aDirEntry.clear(); + } + break; + case OpenMode::FOLDERS: + if(isDir) { + resvec.push_back(aDirEntry); + aDirEntry.clear(); + } + break; + default: + resvec.push_back(aDirEntry); + aDirEntry.clear(); + }; + } + + p1 = p2 + 1; + } + + if(osKind == int(UNKNOWN)) + throw no_such_directory_exception(FTPCouldNotDetermineSystem); + + return resvec; +} + + + +FTPDirentry FTPURL::direntry( + const rtl::OUString& passwd +) const + throw( + no_such_directory_exception + ) +{ + CURL *curl = m_pFCP->handle(); + + std::auto_ptr<FTPInputStream> control(new FTPInputStream()); // control + FTPInputStreamContainer controlContainer(control.get()); + curl_easy_setopt(curl, + CURLOPT_HEADERFUNCTION, + ftp_write); + curl_easy_setopt(curl, + CURLOPT_WRITEHEADER, + &controlContainer); + + curl_easy_setopt(curl,CURLOPT_NOBODY,TRUE); // no data => no transfer + + rtl::OUString url(ident()); // url + if(1+url.lastIndexOf(sal_Unicode('/')) != url.getLength()) + // Try to a pwd on the directory, which makes libcurl + // cd'ing to that directory. + url += rtl::OUString::createFromAscii("/"); + curl_easy_setopt(curl, + CURLOPT_URL, + rtl::OString(url.getStr(), + url.getLength(), + // Only ASCII in URLs => UTF8 ok + RTL_TEXTENCODING_UTF8).getStr()); + + // post request + struct curl_slist *slist = 0; + slist = curl_slist_append(slist,"PWD"); + curl_easy_setopt(curl,CURLOPT_POSTQUOTE,slist); + + char* buffer = 0; + if(passwd.getLength()) { + rtl::OString psswd(passwd.getStr(), + passwd.getLength(), + RTL_TEXTENCODING_UTF8); + buffer = new char[1+psswd.getLength()]; + strcpy(buffer,psswd.getStr()); + buffer[psswd.getLength()] = 0; + curl_easy_setopt(curl,CURLOPT_USERPWD, + buffer); + } + + CURLcode err = curl_easy_perform(curl); + // clean up + delete[] buffer; + curl_slist_free_all(slist); + + /* now decide on the error codes:*/ + if(err == CURLE_FTP_ACCESS_DENIED) + throw no_such_directory_exception(err); + + + rtl::OUString title; + if(err == CURLE_OK) { + // get the title + sal_uInt32 len = (sal_uInt32) control->getLength(); + char* fwd = (char*) control->getBuffer(); + title = rtl::OUString(fwd,len,RTL_TEXTENCODING_UTF8); + + // the buffer now contains the name of the file; + // analyze the output: + // Format of current working directory: + // 257 "/bla" is current directory + sal_Int32 index1 = title.lastIndexOf( + rtl::OUString::createFromAscii("257")); + index1 = 1+title.indexOf(sal_Unicode('"'),index1); + sal_Int32 index2 = title.indexOf(sal_Unicode('"'),index1); + title = title.copy(index1,index2-index1); + if(!title.equalsAscii("/")) { + index1 = title.lastIndexOf(sal_Unicode('/')); + title = title.copy(1+index1); + } + } + /** The ideas is to have always a title, + * either determined by 'pwd' or else from the URL. + */ + else if(m_aPathSegmentVec.size()) + // Determine title form url + title = m_aPathSegmentVec.back(); + else + // title is root. + title = rtl::OUString::createFromAscii("/"); + + FTPDirentry aDirentry; + // init aDirentry + aDirentry.m_aName = title; + aDirentry.m_nMode = INETCOREFTP_FILEMODE_ISDIR; + aDirentry.m_nSize = 0; + + try { + if(!title.equalsAscii("/")) { + // try to open it the parent directory + FTPURL aURL(url + rtl::OUString::createFromAscii("../"), + m_pFCP); + + std::vector<FTPDirentry> list = aURL.list(OpenMode::ALL); + + for(unsigned i = 0; i < list.size(); ++i) { + if(list[i].m_aName == title) { + aDirentry = list[i]; + break; + } + } + } + } catch(const no_such_directory_exception&) { + // no hope, we cannot get any propertyvalues + } + + return aDirentry; +} diff --git a/ucb/source/ucp/ftp/ftpurl.hxx b/ucb/source/ucp/ftp/ftpurl.hxx new file mode 100644 index 000000000000..d0780c19bb66 --- /dev/null +++ b/ucb/source/ucp/ftp/ftpurl.hxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * $RCSfile: ftpurl.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2002-08-28 07:23:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _FTP_FTPURL_HXX_ +#define _FTP_FTPURL_HXX_ + +#include <curl/curl.h> +#include <curl/easy.h> +#include <com/sun/star/io/XOutputStream.hpp> + +#include <rtl/ustring.hxx> +#include <osl/mutex.hxx> +#include <vector> + +#include "ftpdirp.hxx" +#include "ftpcfunc.hxx" + +namespace ftp { + + /** Forward declarations. + */ + + class FTPContentProvider; + + + + enum FTPErrorCode { + FTPCouldNotDetermineSystem = CURL_LAST + 1 + }; + + + class malformed_exception { }; + + + class no_such_directory_exception + { + public: + + no_such_directory_exception(sal_Int32 err) + : n_err(err) { } + + sal_Int32 code() const { return n_err; } + + + private: + + sal_Int32 n_err; + }; + + + class FTPURL + { + public: + + FTPURL( + const rtl::OUString& aIdent, + FTPContentProvider* pFCP = 0 + ) + throw( + malformed_exception + ); + + + ~FTPURL(); + + rtl::OUString username() const { return m_aUsername; } + + rtl::OUString password() const { return m_aPassword; } + + rtl::OUString host() const { return m_aHost; } + + sal_Int32 port() const { return m_nPort; } + + /** This returns the URL, but cleaned from + * unnessary ellipses. + */ + + rtl::OUString ident() const; + + + std::vector<FTPDirentry> list( + sal_Int16 nMode + ) const + throw( + no_such_directory_exception + ); + + FTPDirentry direntry( + const rtl::OUString& passwd = rtl::OUString() + ) const + throw( + no_such_directory_exception + ); + + + private: + + osl::Mutex m_mutex; + + FTPContentProvider *m_pFCP; + + rtl::OUString m_aIdent; + + + rtl::OUString m_aUsername; + rtl::OUString m_aPassword; + rtl::OUString m_aHost; + sal_Int32 m_nPort; + + /** Contains the decoded pathsegments of the url. + */ + std::vector<rtl::OUString> m_aPathSegmentVec; + + void parse() + throw( + malformed_exception + ); + + }; + +} + + +#endif diff --git a/ucb/source/ucp/ftp/makefile.mk b/ucb/source/ucp/ftp/makefile.mk index b39bb9139129..4009059a5dd3 100644 --- a/ucb/source/ucp/ftp/makefile.mk +++ b/ucb/source/ucp/ftp/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.3 $ +# $Revision: 1.4 $ # -# last change: $Author: abi $ $Date: 2002-07-31 15:13:37 $ +# last change: $Author: abi $ $Date: 2002-08-28 07:23:17 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -79,7 +79,6 @@ UCPFTP_MAJOR=1 SLOFILES=\ $(SLO)$/ftpservices.obj \ $(SLO)$/ftpcontentprovider.obj \ - $(SLO)$/ftpurl.obj \ $(SLO)$/ftpcontent.obj \ $(SLO)$/ftpcontentidentifier.obj \ $(SLO)$/ftpcontentcaps.obj \ @@ -88,7 +87,10 @@ SLOFILES=\ $(SLO)$/ftpresultsetI.obj \ $(SLO)$/ftploaderthread.obj \ $(SLO)$/ftpinpstr.obj \ - $(SLO)$/ftpdirp.obj + $(SLO)$/ftpdirp.obj \ + $(SLO)$/ftpcfunc.obj \ + $(SLO)$/ftpurl.obj \ + $(SLO)$/debughelper.obj LIB1TARGET=$(SLB)$/_$(TARGET).lib LIB1OBJFILES=$(SLOFILES) @@ -130,7 +132,10 @@ APP1OBJS=\ $(SLO)$/ftpcontentidentifier.obj \ $(SLO)$/ftploaderthread.obj \ $(SLO)$/ftpinpstr.obj \ - $(SLO)$/ftpdirp.obj + $(SLO)$/ftpurl.obj \ + $(SLO)$/ftpdirp.obj \ + $(SLO)$/ftpcfunc.obj \ + $(SLO)$/debughelper.obj .IF "$(COMPHELPERLIB)"=="" .IF "$(GUI)" == "UNX" diff --git a/ucb/source/ucp/ftp/test.cxx b/ucb/source/ucp/ftp/test.cxx index 6baf6d990a5c..503d7aa30c62 100644 --- a/ucb/source/ucp/ftp/test.cxx +++ b/ucb/source/ucp/ftp/test.cxx @@ -2,9 +2,9 @@ * * $RCSfile: test.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2002-07-31 15:13:38 $ + * last change: $Author: abi $ $Date: 2002-08-28 07:23:17 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -146,12 +146,12 @@ using namespace com::sun::star::io; -class FtpThread +class FTPThread : public osl::Thread { public: - FtpThread(const Reference<XContentProvider>& xProvider); + FTPThread(const Reference<XContentProvider>& xProvider); protected: @@ -167,18 +167,18 @@ private: -FtpThread::FtpThread(const Reference<XContentProvider>& xProvider) +FTPThread::FTPThread(const Reference<XContentProvider>& xProvider) : m_xProvider(xProvider) { } -void FtpThread::run() { +void FTPThread::run() { // Reference<XContentIdentifierFactory> xFactory(m_xProvider, // UNO_QUERY); // xFactory->createContentIdentifier( // rtl::OUString::createFromAscii("ftp://chagall/")); Reference<XContentIdentifier> xIdent( - new ftp::FtpContentIdentifier( + new ftp::FTPContentIdentifier( rtl::OUString::createFromAscii("ftp://chagall/"))); @@ -235,8 +235,8 @@ int main(int argc,char* argv[]) comphelper::setProcessServiceFactory(xFac); Reference< XMultiServiceFactory > xFac(new Test_MultiServiceFactory()); - Reference< XContentProvider> xProvider(new ftp::FtpContentProvider(xFac)); - FtpThread aThread(xProvider); + Reference< XContentProvider> xProvider(new ftp::FTPContentProvider(xFac)); + FTPThread aThread(xProvider); aThread.create(); aThread.join(); |