summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorAndreas Bille <abi@openoffice.org>2002-10-15 08:21:19 +0000
committerAndreas Bille <abi@openoffice.org>2002-10-15 08:21:19 +0000
commitc4baeafbbf7f40dc17c04f6e9522d812da54da71 (patch)
tree41affdeafe66d354e594be3c3e4e23753630ec79 /ucb
parent40b51f98c4b2717d8369002b4c8719840727a5ee (diff)
#100904# mostly complete now
Diffstat (limited to 'ucb')
-rw-r--r--ucb/source/ucp/ftp/ftpcfunc.cxx65
-rw-r--r--ucb/source/ucp/ftp/ftpcfunc.hxx7
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.cxx502
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.hxx30
-rw-r--r--ucb/source/ucp/ftp/ftpcontentcaps.cxx12
-rw-r--r--ucb/source/ucp/ftp/ftpcontentidentifier.cxx19
-rw-r--r--ucb/source/ucp/ftp/ftpcontentidentifier.hxx8
-rw-r--r--ucb/source/ucp/ftp/ftpcontentprovider.cxx65
-rw-r--r--ucb/source/ucp/ftp/ftpcontentprovider.hxx33
-rw-r--r--ucb/source/ucp/ftp/ftpdirp.hxx12
-rwxr-xr-xucb/source/ucp/ftp/ftphandleprovider.hxx16
-rw-r--r--ucb/source/ucp/ftp/ftpinpstr.cxx163
-rw-r--r--ucb/source/ucp/ftp/ftpinpstr.hxx45
-rw-r--r--ucb/source/ucp/ftp/ftpurl.cxx578
-rw-r--r--ucb/source/ucp/ftp/ftpurl.hxx55
-rw-r--r--ucb/source/ucp/ftp/makefile.mk77
-rw-r--r--ucb/source/ucp/ftp/test.cxx379
-rw-r--r--ucb/source/ucp/ftp/test.py27
-rwxr-xr-xucb/source/ucp/ftp/test_ftpurl.cxx232
-rwxr-xr-xucb/source/ucp/ftp/test_ftpurl.hxx3
-rw-r--r--ucb/source/ucp/ftp/test_interactionhandler.hxx109
-rw-r--r--ucb/source/ucp/ftp/test_multiservicefac.hxx5
22 files changed, 1511 insertions, 931 deletions
diff --git a/ucb/source/ucp/ftp/ftpcfunc.cxx b/ucb/source/ucp/ftp/ftpcfunc.cxx
index 135e56c1b2d1..b0afeecc83ac 100644
--- a/ucb/source/ucp/ftp/ftpcfunc.cxx
+++ b/ucb/source/ucp/ftp/ftpcfunc.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcfunc.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:29:49 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:15 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -68,6 +68,7 @@
#include "ftpcontentidentifier.hxx"
#include "ftpinpstr.hxx"
+#include <stdio.h>
using namespace ftp;
using namespace com::sun::star::uno;
@@ -86,62 +87,18 @@ extern "C" {
}
-// 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 file_write(void *buffer,size_t size,size_t nmemb,void *stream)
+ {
+ FILE* file =
+ reinterpret_cast<FILE*>(stream);
+ if(!file)
+ return 0;
+ return fwrite(buffer,size,nmemb,file);
+ }
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
index a15c4abbb71c..d1652e7317f6 100644
--- a/ucb/source/ucp/ftp/ftpcfunc.hxx
+++ b/ucb/source/ucp/ftp/ftpcfunc.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcfunc.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:29:50 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:15 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -91,6 +91,9 @@ extern "C" {
int ftp_write(void *buffer,size_t size,size_t nmemb,void *stream);
+
+ int file_write(void *buffer,size_t size,size_t nmemb,void *stream);
+
}
diff --git a/ucb/source/ucp/ftp/ftpcontent.cxx b/ucb/source/ucp/ftp/ftpcontent.cxx
index 6714b702f8c9..58dd8a1c4e49 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.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: abi $ $Date: 2002-08-29 09:45:03 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:15 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -85,6 +85,7 @@
#include <ucbhelper/contentidentifier.hxx>
#include <ucbhelper/propertyvalueset.hxx>
#include <ucbhelper/cancelcommandexecution.hxx>
+#include <ucbhelper/simpleauthenticationrequest.hxx>
#include <com/sun/star/beans/Property.hpp>
#include <com/sun/star/ucb/XCommandInfo.hpp>
#include <com/sun/star/io/XActiveDataSink.hpp>
@@ -95,9 +96,11 @@
#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
#include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
#include <com/sun/star/ucb/OpenMode.hpp>
-
+#include <com/sun/star/ucb/IOErrorCode.hpp>
using namespace ftp;
+using namespace com::sun::star::task;
+using namespace com::sun::star::container;
using namespace com::sun::star::lang;
using namespace com::sun::star::uno;
using namespace com::sun::star::ucb;
@@ -106,6 +109,7 @@ using namespace com::sun::star::io;
using namespace com::sun::star::sdbc;
+
//=========================================================================
//=========================================================================
//
@@ -118,7 +122,9 @@ FTPContent::FTPContent( const Reference< XMultiServiceFactory >& rxSMgr,
FTPContentProvider* pProvider,
const Reference< XContentIdentifier >& Identifier)
: ContentImplHelper(rxSMgr,pProvider,Identifier),
- m_pFCP(pProvider)
+ m_pFCP(pProvider),
+ m_aFTPURL(Identifier->getContentIdentifier(),
+ pProvider)
{
}
@@ -135,11 +141,12 @@ FTPContent::~FTPContent()
//
//=========================================================================
-XINTERFACE_IMPL_4( FTPContent,
+XINTERFACE_IMPL_5( FTPContent,
XTypeProvider,
XServiceInfo,
XContent,
- XCommandProcessor);
+ XCommandProcessor,
+ XChild);
//=========================================================================
//
@@ -147,11 +154,12 @@ XINTERFACE_IMPL_4( FTPContent,
//
//=========================================================================
-XTYPEPROVIDER_IMPL_4( FTPContent,
+XTYPEPROVIDER_IMPL_5( FTPContent,
XTypeProvider,
XServiceInfo,
XContent,
- XCommandProcessor);
+ XCommandProcessor,
+ XChild);
//=========================================================================
//
@@ -254,6 +262,13 @@ public:
//
//=========================================================================
+#include "debughelper.hxx"
+
+enum ACTION { NOACTION,
+ THROWAUTHENTICATIONREQUEST,
+ THROWACCESSDENIED,
+ THROWINTERACTIVECONNECT };
+
// virtual
Any SAL_CALL FTPContent::execute(
@@ -268,164 +283,232 @@ Any SAL_CALL FTPContent::execute(
RuntimeException
)
{
+ ACTION action(NOACTION);
Any aRet;
- if(aCommand.Name.compareToAscii("getPropertyValues") == 0) {
- Sequence<Property> Properties;
- if(!(aCommand.Argument >>= Properties))
- {
- aRet <<= IllegalArgumentException();
- ucbhelper::cancelCommandExecution(aRet,Environment);
- }
-
- aRet <<= getPropertyValues(Properties,Environment);
- }
- else if(aCommand.Name.compareToAscii("setPropertyValues") == 0) {
- }
- else if(aCommand.Name.compareToAscii("getCommandInfo") == 0) {
- // Note: Implemented by base class.
- aRet <<= getCommandInfo(Environment);
- }
- else if(aCommand.Name.compareToAscii("getPropertySetInfo") == 0) {
- // Note: Implemented by base class.
- aRet <<= getPropertySetInfo(Environment);
- }
- else if ( aCommand.Name.compareToAscii( "open" ) == 0 ) {
- OpenCommandArgument2 aOpenCommand;
- if ( !( aCommand.Argument >>= aOpenCommand ) ) {
- aRet <<= IllegalArgumentException();
- ucbhelper::cancelCommandExecution(aRet,Environment);
- }
-
- if(aOpenCommand.Mode == OpenMode::DOCUMENT) {
- // Open as a document
- CURL *curl = m_pFCP->handle();
-
- // Setting the header write function,
- // which receives the output of the control connection.
-
- std::auto_ptr<FTPInputStream> control(new FTPInputStream());
- FTPInputStreamContainer controlContainer(control.get());
-
- 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
+ while(true)
+ try {
+ if(action == THROWAUTHENTICATIONREQUEST) {
+ // try to get a continuation first
+ rtl::OUString aRealm,aPassword,aAccount;
+ rtl::Reference<ucbhelper::SimpleAuthenticationRequest>
+ p( new ucbhelper::SimpleAuthenticationRequest(
+ m_aFTPURL.host(), // ServerName
+ ucbhelper::SimpleAuthenticationRequest::ENTITY_NA,
+ aRealm,
+ ucbhelper::SimpleAuthenticationRequest
+ ::ENTITY_FIXED,
+ m_aFTPURL.username(),
+ ucbhelper::SimpleAuthenticationRequest
+ ::ENTITY_MODIFY,
+ aPassword));
+
+ Reference<XInteractionHandler> xInteractionHandler;
+ if(Environment.is())
+ xInteractionHandler =
+ Environment->getInteractionHandler();
+
+ if( xInteractionHandler.is()) {
+ xInteractionHandler->handle(p.get());
+
+ Reference<XInterface> xSelection(
+ p->getSelection().get());
+
+ if(Reference<XInteractionRetry>(
+ xSelection,UNO_QUERY).is())
+ action = NOACTION;
+ else if(Reference<XInteractionSupplyAuthentication>(
+ xSelection,UNO_QUERY).is()) {
+ m_pFCP->setHost(
+ m_aFTPURL.host(),
+ m_aFTPURL.port(),
+ m_aFTPURL.username(),
+ p->getAuthenticationSupplier()->getPassword(),
+ aAccount);
+ action = NOACTION;
+ }
+ }
+ aRet = p->getRequest();
+ }
- rtl::OUString url(m_xIdentifier->getContentIdentifier());
- curl_easy_setopt(curl,
- CURLOPT_URL,
- rtl::OString(url.getStr(),
- url.getLength(),
- // Only ASCII in URLs => UTF8 ok
- RTL_TEXTENCODING_UTF8).getStr());
+ if(aCommand.Name.compareToAscii(
+ "getPropertyValues") == 0 &&
+ action != NOACTION) {
+ // It is not allowed to throw if
+ // command is getPropertyValues
+ vos::ORef<ucb::PropertyValueSet> xRow =
+ new ucb::PropertyValueSet(m_xSMgr);
+ Sequence<Property> Properties;
+ aCommand.Argument >>= Properties;
+ for(int i = 0; i < Properties.getLength(); ++i)
+ xRow->appendVoid(Properties[i]);
+ aRet <<= Reference<XRow>(xRow.getBodyPtr());
+ return aRet;
+ }
- curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0);
+ if(action == THROWAUTHENTICATIONREQUEST) {
+ ucbhelper::cancelCommandExecution(
+ aRet,
+ Reference<XCommandEnvironment>(0));
+ } else if(action == THROWACCESSDENIED) {
+ Sequence<Any> seq(1);
+ seq[0] <<= m_aFTPURL.ident(false,false);
+ ucbhelper::cancelCommandExecution(
+ IOErrorCode_ACCESS_DENIED,
+ seq,
+ Environment);
+ } else if(action == THROWINTERACTIVECONNECT) {
+ InteractiveNetworkConnectException
+ excep;
+ excep.Server = m_aFTPURL.host();
+ aRet <<= excep;
+ ucbhelper::cancelCommandExecution(
+ aRet,
+ Environment);
+ }
- Reference<XActiveDataSink>
- xActiveDataSink(aOpenCommand.Sink,UNO_QUERY);
- Reference< XOutputStream >
- xOutputStream(aOpenCommand.Sink,UNO_QUERY);
+ if(aCommand.Name.compareToAscii("getPropertyValues") == 0) {
+ Sequence<Property> Properties;
+ if(!(aCommand.Argument >>= Properties))
+ {
+ aRet <<= IllegalArgumentException();
+ ucbhelper::cancelCommandExecution(aRet,Environment);
+ }
- if(xActiveDataSink.is()) {
- 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(dataContainer());
+ aRet <<= getPropertyValues(Properties,Environment);
}
- else if(xOutputStream.is()) {
- FTPOutputStreamContainer dataContainer(xOutputStream);
- curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,
- ftp_write);
- curl_easy_setopt(curl,CURLOPT_WRITEDATA,&dataContainer);
- curl_easy_perform(curl);
+ else if(aCommand.Name.compareToAscii("setPropertyValues") == 0) {
}
- else {
- aRet <<= UnsupportedDataSinkException();
- ucbhelper::cancelCommandExecution(aRet,Environment);
+ else if(aCommand.Name.compareToAscii("getCommandInfo") == 0) {
+ // Note: Implemented by base class.
+ aRet <<= getCommandInfo(Environment);
}
- }
- else if(aOpenCommand.Mode == OpenMode::ALL ||
- aOpenCommand.Mode == OpenMode::DOCUMENTS ||
- aOpenCommand.Mode == OpenMode::FOLDERS ) {
- FTPURL aFTPURL(m_xIdentifier->getContentIdentifier(),
- m_pFCP);
- try{
- std::vector<FTPDirentry> resvec =
- aFTPURL.list(aOpenCommand.Mode);
- Reference< XDynamicResultSet > xSet
- = new DynamicResultSet(
- m_xSMgr,
- this,
- aOpenCommand,
- Environment,
- new ResultSetFactoryI(m_xSMgr,
- m_xProvider.getBodyPtr(),
- aOpenCommand.Mode,
- aOpenCommand.Properties,
- 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;
+ else if(aCommand.Name.compareToAscii("getPropertySetInfo") == 0) {
+ // Note: Implemented by base class.
+ aRet <<= getPropertySetInfo(Environment);
+ }
+ else if(aCommand.Name.compareToAscii( "insert" ) == 0)
+ {
+ InsertCommandArgument aInsertArgument;
+ if ( ! ( aCommand.Argument >>= aInsertArgument ) ) {
+ aRet <<= IllegalArgumentException();
ucbhelper::cancelCommandExecution(aRet,Environment);
}
+ insert(aInsertArgument);
}
+ else if(aCommand.Name.compareToAscii( "open" ) == 0) {
+ OpenCommandArgument2 aOpenCommand;
+ if ( !( aCommand.Argument >>= aOpenCommand ) ) {
+ aRet <<= IllegalArgumentException();
+ ucbhelper::cancelCommandExecution(aRet,Environment);
+ }
+
+ 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()) {
+ xActiveDataSink->setInputStream(
+ new FTPInputStream(m_aFTPURL.open()));
+ }
+ else if(xOutputStream.is()) {
+ }
+ else {
+ aRet <<= UnsupportedDataSinkException();
+ ucbhelper::cancelCommandExecution(aRet,Environment);
+ }
+ }
+ else if(aOpenCommand.Mode == OpenMode::ALL ||
+ aOpenCommand.Mode == OpenMode::DOCUMENTS ||
+ aOpenCommand.Mode == OpenMode::FOLDERS ) {
+ std::vector<FTPDirentry> resvec =
+ m_aFTPURL.list(sal_Int16(aOpenCommand.Mode));
+ Reference< XDynamicResultSet > xSet
+ = new DynamicResultSet(
+ m_xSMgr,
+ this,
+ aOpenCommand,
+ Environment,
+ new ResultSetFactoryI(m_xSMgr,
+ m_xProvider.getBodyPtr(),
+ aOpenCommand.Mode,
+ aOpenCommand.Properties,
+ aOpenCommand.SortingInfo,
+ resvec));
+ aRet <<= xSet;
+ }
+ else if(aOpenCommand.Mode ==
+ OpenMode::DOCUMENT_SHARE_DENY_NONE ||
+ aOpenCommand.Mode ==
+ OpenMode::DOCUMENT_SHARE_DENY_WRITE) {
+ // Unsupported OpenMode
+ aRet <<= UnsupportedOpenModeException();
+ ucbhelper::cancelCommandExecution(aRet,Environment);
+ }
+ else {
+ // IllegalArgumentException:: No OpenMode
+ aRet <<= IllegalArgumentException();
+ ucbhelper::cancelCommandExecution(aRet,Environment);
+ }
+ }
+ else
+ throw CommandAbortedException();
+
+ return aRet;
+ } catch(const curl_exception& e) {
+ if(e.code() == CURLE_COULDNT_CONNECT)
+ action = THROWINTERACTIVECONNECT;
+ else if(e.code() == CURLE_FTP_USER_PASSWORD_INCORRECT ||
+ e.code() == CURLE_BAD_PASSWORD_ENTERED ||
+ e.code() == CURLE_FTP_WEIRD_PASS_REPLY )
+ action = THROWAUTHENTICATIONREQUEST;
+ else if(e.code() == CURLE_FTP_ACCESS_DENIED)
+ action = THROWACCESSDENIED;
+ else
+ break;
}
- else if(aOpenCommand.Mode == OpenMode::DOCUMENT_SHARE_DENY_NONE ||
- aOpenCommand.Mode == OpenMode::DOCUMENT_SHARE_DENY_WRITE) {
- // Unsupported OpenMode
- aRet <<= UnsupportedOpenModeException();
- ucbhelper::cancelCommandExecution(aRet,Environment);
- }
- else {
- // IllegalArgumentException:: No OpenMode
- aRet <<= IllegalArgumentException();
- ucbhelper::cancelCommandExecution(aRet,Environment);
- }
- }
- else
- throw CommandAbortedException();
return aRet;
}
-
-rtl::OUString FTPContent::getParentURL()
+Reference<XInterface > SAL_CALL
+FTPContent::getParent( )
+ throw (RuntimeException)
{
- return rtl::OUString();
+ Reference<XContentIdentifier>
+ xIdent(new FTPContentIdentifier(m_aFTPURL.parent(),m_pFCP));
+ Reference<XContent> xContent(m_xProvider->queryContent(xIdent));
+ return Reference<XInterface>(xContent,UNO_QUERY);
}
-extern void err_msg( const char* p,
- const rtl::OUString& aOUString );
+void SAL_CALL
+FTPContent::setParent(const Reference<XInterface >& Parent )
+ throw (NoSupportException,
+ RuntimeException)
+{
+ throw NoSupportException();
+}
+
-class FTPClientI
- : public FTPClient
+rtl::OUString FTPContent::getParentURL()
{
-public:
+ return m_aFTPURL.parent();
+}
- FTPClientI(const Reference<XCommandEnvironment>& env);
- virtual rtl::OUString passwd() const;
-private:
+void FTPContent::insert(const InsertCommandArgument& aInsertCommand)
+{
+// m_aFTPURL.insert(bool(aInsertCommand.ReplaceExisting),
- Reference<XCommandEnvironment> m_env;
-};
+}
@@ -437,124 +520,37 @@ Reference< XRow > FTPContent::getPropertyValues(
vos::ORef<ucb::PropertyValueSet> xRow =
new ucb::PropertyValueSet(m_xSMgr);
- 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]);
- }
- }
+ FTPDirentry aDirEntry = m_aFTPURL.direntry();
+
+ 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]);
}
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 872a90c1936a..cc51377bdb74 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.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -62,12 +62,10 @@
#ifndef _FTP_FTPCONTENT_HXX
#define _FTP_FTPCONTENT_HXX
-#ifndef _VOS_REF_HXX_
#include <vos/ref.hxx>
-#endif
-#ifndef _UCBHELPER_CONTENTHELPER_HXX
#include <ucbhelper/contenthelper.hxx>
-#endif
+#include <com/sun/star/ucb/InsertCommandArgument.hpp>
+#include "ftpurl.hxx"
namespace com { namespace sun { namespace star { namespace beans {
@@ -146,13 +144,28 @@ namespace ftp
com::sun::star::uno::RuntimeException );
virtual void SAL_CALL
- abort( sal_Int32 CommandId )
- throw( com::sun::star::uno::RuntimeException );
+ abort(sal_Int32 CommandId)
+ throw( com::sun::star::uno::RuntimeException);
+
+
+ // XChild
+
+ virtual ::com::sun::star::uno::Reference<
+ ::com::sun::star::uno::XInterface > SAL_CALL
+ getParent( )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL
+ setParent( const ::com::sun::star::uno::Reference<
+ ::com::sun::star::uno::XInterface >& Parent )
+ throw (::com::sun::star::lang::NoSupportException,
+ ::com::sun::star::uno::RuntimeException);
private:
FTPContentProvider *m_pFCP;
+ FTPURL m_aFTPURL;
virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
getProperties( const com::sun::star::uno::Reference<
@@ -175,6 +188,7 @@ namespace ftp
com::sun::star::ucb::XCommandEnvironment >& Environment
);
+ void insert(const com::sun::star::ucb::InsertCommandArgument&);
};
}
diff --git a/ucb/source/ucp/ftp/ftpcontentcaps.cxx b/ucb/source/ucp/ftp/ftpcontentcaps.cxx
index 68f7c6b3eecc..6ba2371ab0f7 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.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -64,6 +64,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/ucb/CommandInfo.hpp>
#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
+#include <com/sun/star/ucb/InsertCommandArgument.hpp>
#include <com/sun/star/util/DateTime.hpp>
#include <com/sun/star/uno/Sequence.hxx>
@@ -144,7 +145,7 @@ Sequence< CommandInfo > FTPContent::getCommands(
//
//=================================================================
-#define COMMAND_COUNT 5
+#define COMMAND_COUNT 6
static CommandInfo aCommandInfoTable[] =
{
@@ -175,6 +176,11 @@ Sequence< CommandInfo > FTPContent::getCommands(
OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
-1,
getCppuType( static_cast< OpenCommandArgument2 * >( 0 ) )
+ ),
+ CommandInfo(
+ OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
+ -1,
+ getCppuType( static_cast< InsertCommandArgument * >( 0 ) )
)
};
diff --git a/ucb/source/ucp/ftp/ftpcontentidentifier.cxx b/ucb/source/ucp/ftp/ftpcontentidentifier.cxx
index 404f545c4379..ed6bf95147d7 100644
--- a/ucb/source/ucp/ftp/ftpcontentidentifier.cxx
+++ b/ucb/source/ucp/ftp/ftpcontentidentifier.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentidentifier.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: abi $ $Date: 2002-09-09 12:28:15 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -76,19 +76,13 @@ FTPContentIdentifier::FTPContentIdentifier(
const rtl::OUString& aIdent,
FTPContentProvider* pFCP
)
- : m_pURL(new FTPURL(aIdent,pFCP))
-{
-}
-
-FTPContentIdentifier::FTPContentIdentifier(FTPURL* pURL)
- : m_pURL(pURL)
+ : m_pURL(aIdent,pFCP)
{
}
FTPContentIdentifier::~FTPContentIdentifier()
{
- delete m_pURL;
}
@@ -127,7 +121,7 @@ FTPContentIdentifier::getContentIdentifier(
::com::sun::star::uno::RuntimeException
)
{
- return m_pURL->ident();
+ return m_pURL.ident(false,false);
}
@@ -141,3 +135,8 @@ FTPContentIdentifier::getContentProviderScheme(
return rtl::OUString::createFromAscii("ftp");
}
+
+
+
+
+
diff --git a/ucb/source/ucp/ftp/ftpcontentidentifier.hxx b/ucb/source/ucp/ftp/ftpcontentidentifier.hxx
index a67db24652e1..125352f96f12 100644
--- a/ucb/source/ucp/ftp/ftpcontentidentifier.hxx
+++ b/ucb/source/ucp/ftp/ftpcontentidentifier.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentidentifier.hxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:29:50 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -94,8 +94,6 @@ namespace ftp {
FTPContentIdentifier(const rtl::OUString& ident,
FTPContentProvider* pFCP = 0);
- FTPContentIdentifier(FTPURL *pURL);
-
~FTPContentIdentifier();
// XInterface
@@ -128,7 +126,7 @@ namespace ftp {
private:
- FTPURL *m_pURL;
+ FTPURL m_pURL;
};
}
diff --git a/ucb/source/ucp/ftp/ftpcontentprovider.cxx b/ucb/source/ucp/ftp/ftpcontentprovider.cxx
index fdc46525c1c1..6a93faf178e3 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.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:23:11 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -194,3 +194,64 @@ CURL* FTPContentProvider::handle() {
// Cannot be zero if called from here;
return m_ftpLoaderThread->handle();
}
+
+
+bool FTPContentProvider::forHost(
+ const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ rtl::OUString& password,
+ rtl::OUString& account)
+{
+ osl::MutexGuard aGuard(m_aMutex);
+ for(unsigned int i = 0; i < m_ServerInfo.size(); ++i)
+ if(host == m_ServerInfo[i].host &&
+ port == m_ServerInfo[i].port &&
+ username == m_ServerInfo[i].username )
+ {
+ password = m_ServerInfo[i].password;
+ account = m_ServerInfo[i].account;
+ return true;
+ }
+
+ return false;
+}
+
+
+bool FTPContentProvider::setHost(
+ const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ const rtl::OUString& password,
+ const rtl::OUString& account)
+{
+ ServerInfo inf;
+ inf.host = host;
+ inf.port = port;
+ inf.username = username;
+ inf.password = password;
+ inf.account = account;
+
+ bool present(false);
+ osl::MutexGuard aGuard(m_aMutex);
+ for(unsigned int i = 0; i < m_ServerInfo.size(); ++i)
+ if(host == m_ServerInfo[i].host &&
+ port == m_ServerInfo[i].port &&
+ username == m_ServerInfo[i].username)
+ {
+ present = true;
+ m_ServerInfo[i].password = password;
+ m_ServerInfo[i].account = account;
+ }
+
+ if(!present)
+ m_ServerInfo.push_back(inf);
+
+ return !present;
+}
+
+
+
+
+
+
diff --git a/ucb/source/ucp/ftp/ftpcontentprovider.hxx b/ucb/source/ucp/ftp/ftpcontentprovider.hxx
index 5ee9efe24601..cdaa5ff7e9ae 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.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: abi $ $Date: 2002-09-09 12:28:15 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -62,15 +62,10 @@
#ifndef _FTP_FTPCONTENTPROVIDER_HXX_
#define _FTP_FTPCONTENTPROVIDER_HXX_
-#ifndef _OSL_MUTEX_HXX_
+#include <vector>
#include <osl/mutex.hxx>
-#endif
-#ifndef _UCBHELPER_MACROS_HXX
#include <ucbhelper/macros.hxx>
-#endif
-#ifndef _UCBHELPER_PROVIDERHELPER_HXX
#include <ucbhelper/providerhelper.hxx>
-#endif
#include "ftphandleprovider.hxx"
@@ -127,12 +122,34 @@ namespace ftp {
virtual CURL* handle();
+ virtual bool forHost(const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ rtl::OUString& password,
+ rtl::OUString& account);
+
+ virtual bool setHost(const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ const rtl::OUString& password,
+ const rtl::OUString& account);
+
+
+ struct ServerInfo {
+ rtl::OUString host;
+ rtl::OUString port;
+ rtl::OUString username;
+ rtl::OUString password;
+ rtl::OUString account;
+ };
+
private:
osl::Mutex m_aMutex;
FTPLoaderThread *m_ftpLoaderThread;
void init();
+ std::vector<ServerInfo> m_ServerInfo;
}; // end class FTPContentProvider
} // end namespace ftp
diff --git a/ucb/source/ucp/ftp/ftpdirp.hxx b/ucb/source/ucp/ftp/ftpdirp.hxx
index a0165bf4cb12..667ef795e8bc 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.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: abi $ $Date: 2002-08-29 09:45:03 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -150,6 +150,14 @@ namespace ftp {
m_nMode = INETCOREFTP_FILEMODE_UNKNOWN;
m_nSize = sal_uInt32(-1);
}
+
+ bool isDir() const {
+ return bool(m_nMode && INETCOREFTP_FILEMODE_ISDIR);
+ }
+
+ bool isFile() const {
+ return ! bool(m_nMode && INETCOREFTP_FILEMODE_ISDIR);
+ }
};
diff --git a/ucb/source/ucp/ftp/ftphandleprovider.hxx b/ucb/source/ucp/ftp/ftphandleprovider.hxx
index 07f652ba1ddb..9982d8ebe1cf 100755
--- a/ucb/source/ucp/ftp/ftphandleprovider.hxx
+++ b/ucb/source/ucp/ftp/ftphandleprovider.hxx
@@ -1,3 +1,4 @@
+#include <rtl/ustring.hxx>
#include <curl/types.h>
namespace ftp {
@@ -7,6 +8,21 @@ namespace ftp {
virtual CURL* handle() = 0;
+
+ /** host is in the form host:port.
+ */
+
+ virtual bool forHost(const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ rtl::OUString& password,
+ rtl::OUString& account) = 0;
+
+ virtual bool setHost(const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ const rtl::OUString& password,
+ const rtl::OUString& account) = 0;
};
diff --git a/ucb/source/ucp/ftp/ftpinpstr.cxx b/ucb/source/ucp/ftp/ftpinpstr.cxx
index 31f2c62cce98..aced7118496d 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.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -83,18 +83,21 @@ using namespace com::sun::star::lang;
using namespace com::sun::star::io;
-FTPInputStream::FTPInputStream()
- : m_nMaxLen(1024*1024),
- m_nLen(0),
- m_nWritePos(0),
- m_nReadPos(0),
- m_pBuffer(0),
- m_pFile(0) { }
+FTPInputStream::FTPInputStream(FILE* tmpfl)
+ : m_tmpfl(tmpfl ? tmpfl : tmpfile())
+{
+ fseek(m_tmpfl,0,SEEK_END);
+ fpos_t pos;
+ fgetpos(m_tmpfl,&pos);
+ rewind(m_tmpfl);
+ m_nLength = sal_Int64(pos);
+}
-FTPInputStream::~FTPInputStream() {
- rtl_freeMemory(m_pBuffer);
+FTPInputStream::~FTPInputStream()
+{
+ fclose(m_tmpfl);
}
@@ -125,28 +128,25 @@ void SAL_CALL FTPInputStream::release( void ) throw() {
}
-/** nBytesToRead < 0
- returns zero written bytes.
-*/
-
sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData,
sal_Int32 nBytesToRead)
throw(NotConnectedException,
BufferSizeExceededException,
IOException,
- RuntimeException) {
- osl::MutexGuard aGuard( m_aMutex );
+ RuntimeException)
+{
+ osl::MutexGuard aGuard(m_aMutex);
- sal_Int32 curr =
- std::min(nBytesToRead,sal_Int32(m_nWritePos)-sal_Int32(m_nReadPos));
+ if(0 <= nBytesToRead && aData.getLength() < nBytesToRead)
+ aData.realloc(nBytesToRead);
- if(0 <= curr && aData.getLength() < curr)
- aData.realloc(curr);
+ fpos_t bpos,epos;
- for(sal_Int32 k = 0; k < curr; )
- aData[k++] = static_cast<sal_Int8*>(m_pBuffer)[m_nReadPos++];
+ fgetpos(m_tmpfl,&bpos);
+ fread(aData.getArray(),nBytesToRead,1,m_tmpfl);
+ fgetpos(m_tmpfl,&epos);
- return curr > 0 ? curr : 0;
+ return sal_Int32(epos-bpos);
}
@@ -165,13 +165,13 @@ void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip)
throw(NotConnectedException,
BufferSizeExceededException,
IOException,
- RuntimeException) {
+ RuntimeException)
+{
osl::MutexGuard aGuard(m_aMutex);
- if(nBytesToSkip < 0)
+ if(!m_tmpfl)
throw IOException();
- m_nReadPos += nBytesToSkip;
- if(m_nReadPos > m_nWritePos) // Can't skip behind the end of the current write-position.
- m_nReadPos = m_nWritePos;
+
+ fseek(m_tmpfl,long(nBytesToSkip),SEEK_CUR);
}
@@ -179,9 +179,9 @@ void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip)
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));
+ RuntimeException)
+{
+ return m_nLength - getPosition();
}
@@ -189,8 +189,11 @@ sal_Int32 SAL_CALL FTPInputStream::available(void)
void SAL_CALL FTPInputStream::closeInput(void)
throw(NotConnectedException,
IOException,
- RuntimeException) {
- // fclose(m_pFile);
+ RuntimeException)
+{
+ osl::MutexGuard aGuard(m_aMutex);
+ if(m_tmpfl)
+ fclose(m_tmpfl),m_tmpfl = 0;
}
@@ -198,15 +201,13 @@ void SAL_CALL FTPInputStream::closeInput(void)
void SAL_CALL FTPInputStream::seek(sal_Int64 location)
throw( IllegalArgumentException,
IOException,
- RuntimeException ) {
+ RuntimeException )
+{
osl::MutexGuard aGuard(m_aMutex);
- if(location < 0)
- throw IllegalArgumentException();
+ if(!m_tmpfl)
+ throw IOException();
- m_nReadPos = sal_uInt32(location);
- if(m_nReadPos > m_nWritePos) // Can't seek behind the end
- // // of the current write-position.
- m_nReadPos = m_nWritePos;
+ fseek(m_tmpfl,long(location),SEEK_SET);
}
@@ -218,7 +219,12 @@ FTPInputStream::getPosition(
RuntimeException )
{
osl::MutexGuard aGuard(m_aMutex);
- return sal_Int64(m_nReadPos);
+ if(!m_tmpfl)
+ throw IOException();
+
+ fpos_t pos;
+ fgetpos(m_tmpfl,&pos);
+ return sal_Int64(pos);
}
@@ -229,76 +235,5 @@ sal_Int64 SAL_CALL FTPInputStream::getLength(
IOException,RuntimeException
)
{
- osl::MutexGuard aGuard(m_aMutex);
- return sal_Int64(m_nWritePos);
-}
-
-
-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(
- const void* pBuffer,
- size_t size,
- size_t nmemb
-) throw()
-{
- osl::MutexGuard aGuard(m_aMutex);
- sal_uInt32 nLen = size*nmemb;
- sal_uInt32 tmp(nLen + m_nWritePos);
-
- if(m_nLen < tmp) { // enlarge in steps of multiples of 1K
- do {
- m_nLen+=1024;
- } 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(
- const void* pBuffer,
- size_t size,
- size_t nmemb
-) throw()
-{
- fwrite(pBuffer,size,nmemb,m_pFile);
+ return m_nLength;
}
diff --git a/ucb/source/ucp/ftp/ftpinpstr.hxx b/ucb/source/ucp/ftp/ftpinpstr.hxx
index cc8f76fab14a..1397b3cf1117 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.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:23:12 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -68,21 +68,13 @@
#ifndef _FTP_FTPINPSTR_HXX_
#define _FTP_FTPINPSTR_HXX_
-#ifndef _RTL_USTRING_HXX_
+
#include <rtl/ustring.hxx>
-#endif
-#ifndef _CPPUHELPER_WEAK_HXX_
+#include <osl/mutex.hxx>
#include <cppuhelper/weak.hxx>
-#endif
-#ifndef _CPPUHELPER_QUERYINTERFACE_HXX_
#include <cppuhelper/queryinterface.hxx>
-#endif
-#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
#include <com/sun/star/io/XInputStream.hpp>
-#endif
-#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
#include <com/sun/star/io/XSeekable.hpp>
-#endif
#include <stdio.h>
@@ -93,6 +85,7 @@ namespace ftp {
* working on a buffer.
*/
+
namespace css = com::sun::star;
@@ -107,7 +100,7 @@ namespace ftp {
* on which the inputstream acts.
*/
- FTPInputStream();
+ FTPInputStream(FILE* tmpfl = 0);
~FTPInputStream();
@@ -175,31 +168,15 @@ namespace ftp {
throw(css::io::IOException,
css::uno::RuntimeException);
+ // additional
- /** appends the content of *pBuffer.
- */
-
- void append(const void* pBuffer,size_t size,size_t nmemb) throw();
-
- const void* getBuffer() const throw();
-
- void reset() throw();
+// void append(const void* pBuffer,size_t size,size_t nmemb);
private:
- /** Don't hold more than 1MB in memory.
- */
-
- const sal_uInt32 m_nMaxLen;
-
- mutable osl::Mutex m_aMutex;
-
- sal_uInt32 m_nLen,m_nWritePos,m_nReadPos;
- void* m_pBuffer;
- rtl::OUString m_aTmpFileURL;
-
- FILE* m_pFile;
- void append2File(const void* pBuffer,size_t size,size_t nmemb) throw();
+ osl::Mutex m_aMutex;
+ FILE* m_tmpfl;
+ sal_Int64 m_nLength;
};
diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx
index 551a107ac329..32ab5943ec7d 100644
--- a/ucb/source/ucp/ftp/ftpurl.cxx
+++ b/ucb/source/ucp/ftp/ftpurl.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpurl.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: obo $ $Date: 2002-09-18 15:22:01 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -75,6 +75,7 @@
#include "ftphandleprovider.hxx"
#include "ftpinpstr.hxx"
#include "ftpcfunc.hxx"
+#include "debughelper.hxx"
using namespace ftp;
using namespace com::sun::star::ucb;
@@ -82,18 +83,91 @@ using namespace com::sun::star::uno;
using namespace com::sun::star::io;
+class MemoryContainer {
+
+public:
+
+ MemoryContainer();
+
+ ~MemoryContainer();
+
+ int append(
+ const void* pBuffer,
+ size_t size,
+ size_t nmemb
+ ) throw();
+
+
+ sal_uInt32 m_nLen,m_nWritePos;
+ void *m_pBuffer;
+};
+
+
+MemoryContainer::MemoryContainer()
+ : m_nLen(0),
+ m_nWritePos(0),
+ m_pBuffer(0)
+{
+}
+
+MemoryContainer::~MemoryContainer()
+{
+ rtl_freeMemory(m_pBuffer);
+}
+
+
+int MemoryContainer::append(
+ const void* pBuffer,
+ size_t size,
+ size_t nmemb
+) throw()
+{
+ sal_uInt32 nLen = size*nmemb;
+ sal_uInt32 tmp(nLen + m_nWritePos);
+
+ if(m_nLen < tmp) { // enlarge in steps of multiples of 1K
+ do {
+ m_nLen+=1024;
+ } 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;
+ return nLen;
+}
+
+
+extern "C" {
+
+ int memory_write(void *buffer,size_t size,size_t nmemb,void *stream)
+ {
+ MemoryContainer *_stream =
+ reinterpret_cast<MemoryContainer*>(stream);
+
+ if(!_stream)
+ return 0;
+
+ return _stream->append(buffer,size,nmemb);
+ }
+
+}
+
+
FTPURL::FTPURL(const rtl::OUString& url,
FTPHandleProvider* pFCP)
throw(
malformed_exception
)
- : m_aIdent(url),
- m_aUsername(rtl::OUString::createFromAscii("anonymous")),
+ : m_aUsername(rtl::OUString::createFromAscii("anonymous")),
m_aPort(rtl::OUString::createFromAscii("21")),
- m_pFCP(pFCP)
+ m_pFCP(pFCP),
+ m_bShowPassword(false)
{
- parse();
+ parse(url); // can reset m_bShowPassword
}
@@ -102,13 +176,14 @@ FTPURL::~FTPURL()
}
-void FTPURL::parse()
+void FTPURL::parse(const rtl::OUString& url)
throw(
malformed_exception
)
{
- rtl::OString aIdent(m_aIdent.getStr(),
- m_aIdent.getLength(),
+ rtl::OUString aPassword,aAccount;
+ rtl::OString aIdent(url.getStr(),
+ url.getLength(),
RTL_TEXTENCODING_UTF8);
char *buffer = new char[1+aIdent.getLength()];
@@ -135,11 +210,16 @@ void FTPURL::parse()
// Now username and password.
aExpr = aExpr.copy(0,l);
l = aExpr.indexOf(sal_Unicode(':'));
- if(l != -1)
- m_aPassword = aExpr.copy(1+l);
+ if(l != -1) {
+ aPassword = aExpr.copy(1+l);
+ if(aPassword.getLength())
+ m_bShowPassword = true;
+ }
if(l > 0)
// Overwritte only if the username is not empty.
m_aUsername = aExpr.copy(0,l);
+ else if(aExpr.getLength())
+ m_aUsername = aExpr;
}
l = m_aHost.indexOf(sal_Unicode(':'));
@@ -173,22 +253,113 @@ void FTPURL::parse()
delete[] buffer;
- // ... and rebuild the url as one without ellipses,
+ if(m_bShowPassword)
+ m_pFCP->setHost(m_aHost,
+ m_aPort,
+ m_aUsername,
+ aPassword,
+ aAccount);
+}
+
+
+rtl::OUString FTPURL::ident(bool withslash,bool internal) const
+{
+ // rebuild the url as one without ellipses,
// and more important, as one without username and
// password. ( These are set together with the command. )
- rtl::OUStringBuffer bff(m_aIdent.getLength());
- bff.appendAscii("ftp://")
- .append(m_aHost)
- .append(sal_Unicode(':'))
- .append(m_aPort);
- for(unsigned i = 0; i < m_aPathSegmentVec.size(); ++i)
- bff.append(sal_Unicode('/')).append(m_aPathSegmentVec[i]);
+ rtl::OUStringBuffer bff;
+ bff.appendAscii("ftp://");
+
+ if(!m_aUsername.equalsAscii("anonymous")) {
+ bff.append(m_aUsername);
+
+ rtl::OUString aPassword,aAccount;
+ m_pFCP->forHost(m_aHost,
+ m_aPort,
+ m_aUsername,
+ aPassword,
+ aAccount);
- m_aIdent = bff.makeStringAndClear();
+ if((m_bShowPassword || internal) &&
+ aPassword.getLength() )
+ bff.append(sal_Unicode(':'))
+ .append(aPassword);
+
+ bff.append(sal_Unicode('@'));
+ }
+ bff.append(m_aHost);
+
+ if(!m_aPort.equalsAscii("21"))
+ bff.append(sal_Unicode(':'))
+ .append(m_aPort)
+ .append(sal_Unicode('/'));
+ else
+ bff.append(sal_Unicode('/'));
+
+ for(unsigned i = 0; i < m_aPathSegmentVec.size(); ++i)
+ if(i == 0)
+ bff.append(m_aPathSegmentVec[i]);
+ else
+ bff.append(sal_Unicode('/')).append(m_aPathSegmentVec[i]);
+ if(withslash)
+ if(bff.getLength() && bff[bff.getLength()-1] != sal_Unicode('/'))
+ bff.append(sal_Unicode('/'));
+
+ return bff.makeStringAndClear();
}
+rtl::OUString FTPURL::parent() const
+{
+ rtl::OUStringBuffer bff;
+
+ bff.appendAscii("ftp://");
+
+ if(!m_aUsername.equalsAscii("anonymous")) {
+ bff.append(m_aUsername);
+
+ rtl::OUString aPassword,aAccount;
+ m_pFCP->forHost(m_aHost,
+ m_aPort,
+ m_aUsername,
+ aPassword,
+ aAccount);
+
+ if(m_bShowPassword && aPassword.getLength())
+ bff.append(sal_Unicode(':'))
+ .append(aPassword);
+
+ bff.append(sal_Unicode('@'));
+ }
+
+ bff.append(m_aHost);
+
+ if(!m_aPort.equalsAscii("21"))
+ bff.append(sal_Unicode(':'))
+ .append(m_aPort)
+ .append(sal_Unicode('/'));
+ else
+ bff.append(sal_Unicode('/'));
+
+ rtl::OUString last;
+
+ for(unsigned int i = 0; i < m_aPathSegmentVec.size(); ++i)
+ if(1+i == m_aPathSegmentVec.size())
+ last = m_aPathSegmentVec[i];
+ else if(i == 0)
+ bff.append(m_aPathSegmentVec[i]);
+ else
+ bff.append(sal_Unicode('/')).append(m_aPathSegmentVec[i]);
+
+ if(!last.getLength())
+ bff.appendAscii("..");
+ else if(last.equalsAscii(".."))
+ bff.append(last).appendAscii("/..");
+
+ return bff.makeStringAndClear();
+}
+
/** Listing of a directory.
*/
@@ -201,69 +372,112 @@ namespace ftp {
}
+
+extern "C" int no_func(void *client, char *prompt, char*
+ buffer, int buflen ) { return 1; }
+
+
+#define SET_CONTROL_CONTAINER \
+ MemoryContainer control; \
+ curl_easy_setopt(curl, \
+ CURLOPT_HEADERFUNCTION, \
+ memory_write); \
+ curl_easy_setopt(curl, \
+ CURLOPT_WRITEHEADER, \
+ &control)
+
+
+#define SET_DATA_CONTAINER \
+ curl_easy_setopt(curl,CURLOPT_NOBODY,false); \
+ MemoryContainer data; \
+ curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,memory_write); \
+ curl_easy_setopt(curl,CURLOPT_WRITEDATA,&data)
+
+
+#define SET_URL(url) \
+ rtl::OString urlParAscii(url.getStr(), \
+ url.getLength(), \
+ RTL_TEXTENCODING_UTF8); \
+ curl_easy_setopt(curl, \
+ CURLOPT_URL, \
+ urlParAscii.getStr()); \
+ curl_easy_setopt(curl, \
+ CURLOPT_PASSWDFUNCTION, \
+ no_func)
+
+
+ // Setting username:password
+#define SET_USER_PASSWORD(username,password) \
+ rtl::OUString combi(username + \
+ rtl::OUString::createFromAscii(":") + \
+ password); \
+ rtl::OString aUserPsswd(combi.getStr(), \
+ combi.getLength(), \
+ RTL_TEXTENCODING_UTF8); \
+ curl_easy_setopt(curl, \
+ CURLOPT_USERPWD, \
+ aUserPsswd.getStr())
+
+
+
+FILE* FTPURL::open()
+ throw(curl_exception)
+{
+ CURL *curl = m_pFCP->handle();
+
+ SET_CONTROL_CONTAINER;
+ rtl::OUString url(ident(false,true));
+ SET_URL(url);
+ FILE *res = tmpfile();
+ curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,file_write);
+ curl_easy_setopt(curl,CURLOPT_WRITEDATA,res);
+
+ curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0);
+ CURLcode err = curl_easy_perform(curl);
+
+ if(err == CURLE_OK)
+ rewind(res);
+ else {
+ fclose(res),res = 0;
+ throw curl_exception(err);
+ }
+
+ return res;
+}
+
+
std::vector<FTPDirentry> FTPURL::list(
sal_Int16 nMode
) const
throw(
- no_such_directory_exception
+ curl_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
- 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());
-
- // Setting username:password
- // Setting username:password
- rtl::OUString combi(username() +
- rtl::OUString::createFromAscii(":") +
- password());
- rtl::OString aUserPsswd(combi.getStr(),
- combi.getLength(),
- RTL_TEXTENCODING_UTF8);
- curl_easy_setopt(curl,
- CURLOPT_USERPWD,
- aUserPsswd.getStr());
-
+ SET_CONTROL_CONTAINER;
+ SET_DATA_CONTAINER;
+ rtl::OUString url(ident(true,true));
+ SET_URL(url);
curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0);
CURLcode err = curl_easy_perform(curl);
if(err != CURLE_OK)
- throw no_such_directory_exception(err);
+ throw curl_exception(err);
// now evaluate the error messages
- sal_uInt32 len = (sal_uInt32) data->getLength();
- char* fwd = (char*) data->getBuffer();
+ sal_uInt32 len = data.m_nWritePos;
+ char* fwd = (char*) data.m_pBuffer;
+ rtl::OString str(fwd,len);
char *p1, *p2;
p1 = p2 = fwd;
OS osKind(FTP_UNKNOWN);
std::vector<FTPDirentry> resvec;
FTPDirentry aDirEntry;
+ // ensure slash at the end
+ rtl::OUString viewurl(ident(true,false));
while(true) {
while(p2-fwd < int(len) && *p2 != '\n') ++p2;
@@ -275,55 +489,47 @@ std::vector<FTPDirentry> FTPURL::list(
// which returns the operating system type,
// this is not usable here: There are Windows-server
// formatting the output like UNIX-ls command.
- case FTP_DOS:
- FTPDirectoryParser::parseDOS(aDirEntry,p1);
- break;
- case FTP_UNIX:
- FTPDirectoryParser::parseUNIX(aDirEntry,p1);
- break;
- case FTP_VMS:
- FTPDirectoryParser::parseVMS(aDirEntry,p1);
- break;
- default:
- if(FTPDirectoryParser::parseUNIX(aDirEntry,p1))
- osKind = FTP_UNIX;
- else if(FTPDirectoryParser::parseDOS(aDirEntry,p1))
- osKind = FTP_DOS;
- else if(FTPDirectoryParser::parseVMS(aDirEntry,p1))
- osKind = FTP_VMS;
+ case FTP_DOS:
+ FTPDirectoryParser::parseDOS(aDirEntry,p1);
+ break;
+ case FTP_UNIX:
+ FTPDirectoryParser::parseUNIX(aDirEntry,p1);
+ break;
+ case FTP_VMS:
+ FTPDirectoryParser::parseVMS(aDirEntry,p1);
+ break;
+ default:
+ if(FTPDirectoryParser::parseUNIX(aDirEntry,p1))
+ osKind = FTP_UNIX;
+ else if(FTPDirectoryParser::parseDOS(aDirEntry,p1))
+ osKind = FTP_DOS;
+ else if(FTPDirectoryParser::parseVMS(aDirEntry,p1))
+ osKind = FTP_VMS;
}
aDirEntry.m_aName = aDirEntry.m_aName.trim();
if(osKind != int(FTP_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;
+ aDirEntry.m_aURL = viewurl + 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:
+ 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();
};
}
@@ -331,122 +537,110 @@ std::vector<FTPDirentry> FTPURL::list(
}
if(osKind == int(FTP_UNKNOWN))
- throw no_such_directory_exception(FTPCouldNotDetermineSystem);
+ throw curl_exception(FTPCouldNotDetermineSystem);
return resvec;
}
-
-FTPDirentry FTPURL::direntry(
- const rtl::OUString& passwd
-) const
- throw(
- no_such_directory_exception
- )
+rtl::OUString FTPURL::net_title() const
+ throw(curl_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
- 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());
- // Setting username:password
- rtl::OUString combi(username() +
- rtl::OUString::createFromAscii(":") +
- password());
- rtl::OString aUserPsswd(combi.getStr(),
- combi.getLength(),
- RTL_TEXTENCODING_UTF8);
- curl_easy_setopt(curl,
- CURLOPT_USERPWD,
- aUserPsswd.getStr());
-
- // post request
+ SET_CONTROL_CONTAINER;
+ curl_easy_setopt(curl,CURLOPT_NOBODY,TRUE); // no data => no transfer
struct curl_slist *slist = 0;
+ // post request
slist = curl_slist_append(slist,"PWD");
curl_easy_setopt(curl,CURLOPT_POSTQUOTE,slist);
- CURLcode err = curl_easy_perform(curl);
- // clean up
- curl_slist_free_all(slist);
+ bool try_more(true);
+ CURLcode err;
+ rtl::OUString net_title;
- /* 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);
+ while(true) {
+ rtl::OUString url(ident(false,true));
+
+ if(try_more &&
+ 1+url.lastIndexOf(sal_Unicode('/')) != url.getLength())
+ url += rtl::OUString::createFromAscii("/"); // add end-slash
+ else if(!try_more &&
+ 1+url.lastIndexOf(sal_Unicode('/')) == url.getLength())
+ url = url.copy(0,url.getLength()-1); // remove end-slash
+
+ SET_URL(url);
+ err = curl_easy_perform(curl);
+
+ if(err == CURLE_OK) { // get the title from the server
+ char* fwd = (char*) control.m_pBuffer;
+ sal_uInt32 len = (sal_uInt32) control.m_nWritePos;
+
+ net_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/bla" is current directory
+ sal_Int32 index1 = net_title.lastIndexOf(
+ rtl::OUString::createFromAscii("257"));
+ index1 = 1+net_title.indexOf(sal_Unicode('"'),index1);
+ sal_Int32 index2 = net_title.indexOf(sal_Unicode('"'),index1);
+ net_title = net_title.copy(index1,index2-index1);
+ if(!net_title.equalsAscii("/")) {
+ index1 = net_title.lastIndexOf(sal_Unicode('/'));
+ net_title = net_title.copy(1+index1);
+ }
+ try_more = false;
+ } else if(err == CURLE_BAD_PASSWORD_ENTERED)
+ // the client should retry after getting the correct
+ // username + password
+ throw curl_exception(err);
+ else if(try_more && err == CURLE_FTP_ACCESS_DENIED) {
+ // We were either denied access when trying to login to
+ // an FTP server or when trying to change working directory
+ // to the one given in the URL.
+ if(m_aPathSegmentVec.size())
+ // determine title form url
+ net_title = m_aPathSegmentVec.back();
+ else
+ // must be root
+ net_title = rtl::OUString::createFromAscii("/");
+ try_more = false;
}
+
+ if(try_more)
+ try_more = false;
+ else
+ break;
}
- /** 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("/");
+ curl_slist_free_all(slist);
+ return net_title;
+}
+
+
+FTPDirentry FTPURL::direntry() const
+ throw(curl_exception)
+{
+ rtl::OUString nettitle = net_title();
FTPDirentry aDirentry;
- // init aDirentry
- aDirentry.m_aName = title;
+
+ aDirentry.m_aName = nettitle; // init aDirentry
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);
+ if(!nettitle.equalsAscii("/")) {
+ // try to open the parent directory
+ FTPURL aURL(parent(),m_pFCP);
- std::vector<FTPDirentry> list = aURL.list(OpenMode::ALL);
+ 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;
- }
+ for(unsigned i = 0; i < list.size(); ++i) {
+ if(list[i].m_aName == nettitle) { // the relevant file is found
+ 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
index 1bdf6af41812..432848f76b81 100644
--- a/ucb/source/ucp/ftp/ftpurl.hxx
+++ b/ucb/source/ucp/ftp/ftpurl.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpurl.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: abi $ $Date: 2002-09-09 12:28:17 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -72,6 +72,7 @@
#include <curl/easy.h>
#include <com/sun/star/io/XOutputStream.hpp>
+#include <stdio.h>
#include <rtl/ustring.hxx>
#include <osl/mutex.hxx>
#include <vector>
@@ -96,11 +97,11 @@ namespace ftp {
class malformed_exception { };
- class no_such_directory_exception
+ class curl_exception
{
public:
- no_such_directory_exception(sal_Int32 err)
+ curl_exception(sal_Int32 err)
: n_err(err) { }
sal_Int32 code() const { return n_err; }
@@ -127,34 +128,32 @@ namespace ftp {
~FTPURL();
- rtl::OUString username() const { return m_aUsername; }
-
- rtl::OUString password() const { return m_aPassword; }
-
rtl::OUString host() const { return m_aHost; }
rtl::OUString port() const { return m_aPort; }
+ rtl::OUString username() const { return m_aUsername; }
+
/** This returns the URL, but cleaned from
* unnessary ellipses.
*/
- rtl::OUString ident() const { return m_aIdent; }
+ rtl::OUString ident(bool withslash,bool internal) const;
+ /** returns the parent url.
+ */
- std::vector<FTPDirentry> list(
- sal_Int16 nMode
- ) const
- throw(
- no_such_directory_exception
- );
+ rtl::OUString parent() const;
- FTPDirentry direntry(
- const rtl::OUString& passwd = rtl::OUString()
- ) const
- throw(
- no_such_directory_exception
- );
+
+ std::vector<FTPDirentry> list(sal_Int16 nMode) const
+ throw(curl_exception);
+
+ // returns a pointer to an open tempfile,
+ // seeked to the beginning of.
+ FILE* open() throw(curl_exception);
+
+ FTPDirentry direntry() const throw(curl_exception);
private:
@@ -163,23 +162,21 @@ namespace ftp {
FTPHandleProvider *m_pFCP;
- rtl::OUString m_aIdent;
-
-
- rtl::OUString m_aUsername;
- rtl::OUString m_aPassword;
- rtl::OUString m_aHost;
- rtl::OUString m_aPort;
+ mutable rtl::OUString m_aUsername;
+ bool m_bShowPassword;
+ mutable rtl::OUString m_aHost;
+ mutable rtl::OUString m_aPort;
/** Contains the decoded pathsegments of the url.
*/
std::vector<rtl::OUString> m_aPathSegmentVec;
- void parse()
+ void parse(const rtl::OUString& url)
throw(
malformed_exception
);
+ rtl::OUString net_title() const throw(curl_exception);
};
}
diff --git a/ucb/source/ucp/ftp/makefile.mk b/ucb/source/ucp/ftp/makefile.mk
index dc5eac4a77c5..01f9f0ab9a4c 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.7 $
+# $Revision: 1.8 $
#
-# last change: $Author: abi $ $Date: 2002-09-09 12:28:17 $
+# last change: $Author: abi $ $Date: 2002-10-15 09:21:18 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -76,7 +76,9 @@ UCPFTP_MAJOR=1
# --- General -----------------------------------------------------
-SLOFILES=\
+# first target ( shared library )
+
+SLOFILES1=\
$(SLO)$/ftpservices.obj \
$(SLO)$/ftpcontentprovider.obj \
$(SLO)$/ftpcontent.obj \
@@ -93,9 +95,9 @@ SLOFILES=\
$(SLO)$/debughelper.obj
LIB1TARGET=$(SLB)$/_$(TARGET).lib
-LIB1OBJFILES=$(SLOFILES)
+LIB1OBJFILES=$(SLOFILES1)
-# --- Shared-Library ---------------------------------------------------
+# --- Shared-Library 1 ---------------------------------------------------
SHL1TARGET=$(TARGET)$(UCPFTP_MAJOR)
SHL1IMPLIB=i$(TARGET)
@@ -116,26 +118,40 @@ SHL1DEF=$(MISC)$/$(SHL1TARGET).def
SHL1LIBS= \
$(LIB1TARGET)
+# Make symbol renaming match library name for Mac OS X
+.IF "$(OS)"=="MACOSX"
+SYMBOLPREFIX=$(TARGET)$(UCPFTP_MAJOR)
+.ENDIF
+
+# --- Def-File ---------------------------------------------------------
+
+DEF1NAME=$(SHL1TARGET)
+DEF1EXPORTFILE= $(TARGET).dxp
+DEF1DES=UCB Ftp Content Provider
+
+# --- Targets ----------------------------------------------------------
+
APP1TARGET=ftptest
APP1OBJS=\
$(OBJ)$/test.obj \
+ $(OBJ)$/test_activedatasink.obj \
$(OBJ)$/test_ftpurl.obj \
- $(OBJ)$/test_activedatasink.obj \
- $(OBJ)$/test_multiservicefac.obj \
- $(SLO)$/ftpcontentcaps.obj \
- $(SLO)$/ftpservices.obj \
- $(SLO)$/ftpcontentprovider.obj \
- $(SLO)$/ftpcontent.obj \
- $(SLO)$/ftpdynresultset.obj \
- $(SLO)$/ftpresultsetbase.obj \
- $(SLO)$/ftpresultsetI.obj \
- $(SLO)$/ftpcontentidentifier.obj \
- $(SLO)$/ftploaderthread.obj \
- $(SLO)$/ftpinpstr.obj \
- $(SLO)$/ftpurl.obj \
- $(SLO)$/ftpdirp.obj \
- $(SLO)$/ftpcfunc.obj \
- $(SLO)$/debughelper.obj
+ $(OBJ)$/test_multiservicefac.obj \
+ $(OBJ)$/ftpservices.obj \
+ $(OBJ)$/ftpcontentprovider.obj \
+ $(OBJ)$/ftpcontent.obj \
+ $(OBJ)$/ftpcontentidentifier.obj \
+ $(OBJ)$/ftpcontentcaps.obj \
+ $(OBJ)$/ftpdynresultset.obj \
+ $(OBJ)$/ftpresultsetbase.obj \
+ $(OBJ)$/ftpresultsetI.obj \
+ $(OBJ)$/ftploaderthread.obj \
+ $(OBJ)$/ftpinpstr.obj \
+ $(OBJ)$/ftpdirp.obj \
+ $(OBJ)$/ftpcfunc.obj \
+ $(OBJ)$/ftpurl.obj \
+ $(OBJ)$/debughelper.obj
+
.IF "$(COMPHELPERLIB)"==""
.IF "$(GUI)" == "UNX"
@@ -155,20 +171,17 @@ APP1STDLIBS=\
$(UCBHELPERLIB) \
$(CURLLIB)
-APP1DEF= $(MISC)\$(APP1TARGET).def
+.INCLUDE: target.mk
+
+
+
+
+
+
+
-# Make symbol renaming match library name for Mac OS X
-.IF "$(OS)"=="MACOSX"
-SYMBOLPREFIX=$(TARGET)$(UCPFTP_MAJOR)
-.ENDIF
-# --- Def-File ---------------------------------------------------------
-DEF1NAME=$(SHL1TARGET)
-DEF1EXPORTFILE= $(TARGET).dxp
-DEF1DES=UCB Ftp Content Provider
-# --- Targets ----------------------------------------------------------
-.INCLUDE: target.mk
diff --git a/ucb/source/ucp/ftp/test.cxx b/ucb/source/ucp/ftp/test.cxx
index da93d7d26231..3961e1dfc701 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.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: abi $ $Date: 2002-09-09 12:28:17 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -65,189 +65,268 @@
*************************************************************************/
-
-#ifndef _OSL_PROCESS_H_
-#include <osl/process.h>
-#endif
-#ifndef _OSL_FILE_HXX_
-#include <osl/file.hxx>
-#endif
-#ifndef _THREAD_HXX_
-#include <osl/thread.hxx>
-#endif
-#ifndef _RTL_USTRING_HXX_
-#include <rtl/ustring.hxx>
-#endif
-#ifndef _CPPUHELPER_SERVICEFACTORY_HXX_
-#include <cppuhelper/servicefactory.hxx>
-#endif
-#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
-#include <comphelper/processfactory.hxx>
-#endif
-#ifndef _COMPHELPER_REGPATHHELPER_HXX_
-#include <comphelper/regpathhelper.hxx>
-#endif
-#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
-#include <com/sun/star/lang/XComponent.hpp>
-#endif
-#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_
-#include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
-#include <com/sun/star/ucb/XContent.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_
-#include <com/sun/star/ucb/XContentProvider.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
-#include <com/sun/star/ucb/XCommandProcessor.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
-#include <com/sun/star/ucb/OpenMode.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_COMMAND_HPP_
-#include <com/sun/star/ucb/Command.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_
-#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
-#endif
-#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_
-#include <com/sun/star/io/XActiveDataSink.hpp>
-#endif
-#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_
-#include <com/sun/star/beans/Property.hpp>
-#endif
-
-
-#include "test_activedatasink.hxx"
#include "test_ftpurl.hxx"
-#include "test_multiservicefac.hxx"
-#include "ftpcontentprovider.hxx"
-#include "ftpcontentidentifier.hxx"
+#include <stdio.h>
+#include <unistd.h>
+// #include <vos/process.hxx>
+// #include <osl/process.h>
-using namespace test_ftp;
-using namespace rtl;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::ucb;
-using namespace com::sun::star::beans;
-using namespace com::sun::star::io;
+// #include <osl/thread.hxx>
-class FTPThread
- : public osl::Thread
-{
-public:
+// #include <ucbhelper/configurationkeys.hxx>
+// #include <cppuhelper/bootstrap.hxx>
+// #include <cppuhelper/servicefactory.hxx>
+// #include <comphelper/processfactory.hxx>
+// #include <comphelper/regpathhelper.hxx>
+// #include <com/sun/star/lang/XComponent.hpp>
+// #include <com/sun/star/lang/XMultiServiceFactory.hpp>
+// #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
+// #include <com/sun/star/ucb/XContent.hpp>
+// #include <com/sun/star/ucb/XContentProvider.hpp>
+// #include <com/sun/star/ucb/XCommandProcessor.hpp>
+// #include <com/sun/star/ucb/OpenMode.hpp>
+// #include <com/sun/star/ucb/Command.hpp>
+// #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
+// #include <com/sun/star/io/XActiveDataSink.hpp>
+// #include <com/sun/star/beans/Property.hpp>
+
+
+// #include "debughelper.hxx"
+// #include "test_activedatasink.hxx"
+// #include "test_ftpurl.hxx"
+// #include "test_multiservicefac.hxx"
+// #include "ftpcontentprovider.hxx"
+// #include "ftpcontentidentifier.hxx"
- FTPThread(const Reference<XContentProvider>& xProvider);
+// using namespace test_ftp;
+// using namespace rtl;
+// using namespace com::sun::star::uno;
+// using namespace com::sun::star::lang;
+// using namespace com::sun::star::ucb;
+// using namespace com::sun::star::beans;
+// using namespace com::sun::star::io;
-protected:
- void SAL_CALL run();
+// class FTPThread
+// : public osl::Thread
+// {
+// public:
-private:
+// FTPThread();
- Reference<XContentProvider> m_xProvider;
-};
+// int number_of_errors() { return _number_of_errors; }
+// protected:
+// void SAL_CALL run();
-FTPThread::FTPThread(const Reference<XContentProvider>& xProvider)
- : m_xProvider(xProvider) { }
+// private:
+// ftp::FTPContentProvider *pProvider;
+// Reference<XContentProvider> xProvider;
+// Reference<XMultiServiceFactory> xFac;
-void FTPThread::run() {
-// Reference<XContentIdentifierFactory> xFactory(m_xProvider,
-// UNO_QUERY);
-// xFactory->createContentIdentifier(
-// rtl::OUString::createFromAscii("ftp://chagall/"));
+// int _number_of_errors;
+// };
- Reference<XContentIdentifier> xIdent(
- new ftp::FTPContentIdentifier(
- rtl::OUString::createFromAscii("ftp://chagall/")));
+// Reference< XMultiServiceFactory > createApplicationServiceManager()
+// {
+// try
+// {
+// Reference<XComponentContext> xComponentContext =
+// ::cppu::defaultBootstrap_InitialComponentContext();
+// Reference<XMultiServiceFactory> xMS(
+// xComponentContext->getServiceManager(),
+// UNO_QUERY);
- Reference<XContent> xContent = m_xProvider->queryContent(xIdent);
+// return xMS;
+// }
+// catch( ::com::sun::star::uno::Exception& )
+// {
+// return Reference< XMultiServiceFactory >();
+// }
+// }
- Reference<XActiveDataSink> xActDS(new Test_ActiveDataSink());
- OpenCommandArgument2 aOpenCommand(OpenMode::DOCUMENTS,
- 0,
- Reference<XInterface>(xActDS,UNO_QUERY),
- Sequence<Property>(0),
- Sequence<NumberedSortingInfo>(0));
- Any aAny; aAny <<= aOpenCommand;
- Command aCommand(OUString::createFromAscii("open"),
- -1,
- aAny);
+// FTPThread::FTPThread()
+// : _number_of_errors(0),
+// xFac(createApplicationServiceManager())
+// {
+// pProvider = new ftp::FTPContentProvider(xFac);
+// xProvider = Reference<XContentProvider>(pProvider);
- Reference<XCommandProcessor> xCommandProcessor(xContent,UNO_QUERY);
- xCommandProcessor->execute(aCommand,0,Reference<XCommandEnvironment>(0));
+// if(!xProvider.is())
+// ++_number_of_errors;
+// }
- int n;
- Reference<XInputStream> xInputStream = xActDS->getInputStream();
- if(xInputStream.is())
- do {
- Sequence<sal_Int8> seq(0);
- n = xInputStream->readBytes(seq,2048);
- fprintf(stdout,OString(reinterpret_cast<const sal_Char*>(seq.getConstArray()),
- seq.getLength()).getStr());
- } while(n == 2048);
-}
+// void FTPThread::run() {
+// if(!xFac.is()) {
+// ++_number_of_errors;
+// exit(1);
+// }
+
+// Reference<XContentIdentifier> xIdent(
+// new ftp::FTPContentIdentifier(
+// rtl::OUString::createFromAscii("ftp://abi:psswd@abi-1/file"),
+// pProvider));
+
+// Reference<XContent> xContent = xProvider->queryContent(xIdent);
+// if(!xContent.is())
+// {
+// err_msg("no content",OUString());
+// exit(1);
+// }
+
+
+// Reference<XActiveDataSink> xActDS(new Test_ActiveDataSink());
+// OpenCommandArgument2 aOpenCommand(OpenMode::DOCUMENT,
+// 0,
+// Reference<XInterface>(xActDS,UNO_QUERY),
+// Sequence<Property>(0),
+// Sequence<NumberedSortingInfo>(0));
+// Any aAny; aAny <<= aOpenCommand;
+
+// Command aCommand(OUString::createFromAscii("open"),
+// -1,
+// aAny);
+
+// Reference<XCommandProcessor> xCommandProcessor(xContent,UNO_QUERY);
+// if(!xCommandProcessor.is())
+// {
+// err_msg("no command_processor",OUString());
+// exit(1);
+// }
+// xCommandProcessor->execute(aCommand,
+// 0,Reference<XCommandEnvironment>(0));
+// Reference<XInputStream> xInputStream = xActDS->getInputStream();
+// if(!xInputStream.is())
+// ;
+// }
int main(int argc,char* argv[])
{
+// FTPThread aThread;
+// aThread.create();
+// aThread.join();
+
+ typedef int (*INT_FUNC)(void);
+ INT_FUNC tests[] = { test_ftpurl,
+ test_ftpparent,
+ test_ftpproperties,
+ test_ftpopen,
+ test_ftplist,
+ 0 }; // don't remove ending zero
+
int err_level = 0;
- err_level += test_ftpurl();
- err_level += test_ftpproperties();
- if(err_level)
- fprintf(stderr,"number of errors occured: %d",err_level);
+ fprintf(stderr,"------- Testing ----------\n");
+
+ int i = -1;
+ do {
+ INT_FUNC f = tests[++i];
+ if(f) {
+ err_level += (*f)();
+ fprintf(stderr,".");
+ } else
+ break;
+ } while(true);
+
+ if(err_level) {
+ fprintf(stderr,"number of failed tests: %d\n",err_level);
+ fprintf(stderr,"----------------------------------\n");
+ } else
+ fprintf(stderr,"no errors\n");
return err_level;
+}
-// Reference< XMultiServiceFactory > xFac;
-
-// try {
-// OUString systemRegistryPath = comphelper::getPathToSystemRegistry();
-// OString path(systemRegistryPath.getStr(),
-// systemRegistryPath.getLength(),
-// RTL_TEXTENCODING_UTF8);
-// fprintf(stdout,"\nsystem registry path: %s\n",path.getStr());
-
-// xFac = cppu::createRegistryServiceFactory(systemRegistryPath,
-// OUString(),
-// true);
-// if(!xFac.is()) {
-// fprintf(stderr,"\ncould not create ServiceFactory");
-// return 1;
-// }
-
-// comphelper::setProcessServiceFactory(xFac);
-
-// Reference< XMultiServiceFactory > xFac(new Test_MultiServiceFactory());
-// Reference< XContentProvider> xProvider(new ftp::FTPContentProvider(xFac));
-// FTPThread aThread(xProvider);
-// aThread.create();
-// aThread.join();
-
-// Reference< XComponent > xComponent(xFac,UNO_QUERY);
-// if(xComponent.is())
-// xComponent->dispose();
-// return 0;
-// } catch(const Exception& e) {
-// fprintf(stderr,"\nERROR: any other error");
-// fprintf(stderr,"\nERROR: P0-bug to ABI\n");
+
+
+// char *scefile = 0;
+// if(strcmp(argv[1],"-sce") == 0)
+// scefile = argv[2];
+
+// if(!scefile) {
+// fprintf(stderr,"usage: ftptest -sce filename\n");
// return 1;
// }
-}
+
+// rtl::OUString sceurl;
+// osl::FileBase::RC err =
+// osl::FileBase::getFileURLFromSystemPath(
+// rtl::OUString(scefile,
+// strlen(scefile),
+// RTL_TEXTENCODING_UTF8),
+// sceurl);
+
+// osl::File aFile(sceurl);
+// err = aFile.open(OpenFlag_Read);
+// if(err != osl::FileBase::E_None) {
+// fprintf(stderr,"could not open sce-file %s\n",scefile);
+// return 1;
+// }
+
+// sal_uInt64 n;
+// char buffer[256];
+// rtl::OUStringBuffer bff;
+// do {
+// err = aFile.read((void*)buffer,256,n);
+// bff.appendAscii(buffer,sal_Int32(n));
+// } while(err == osl::FileBase::E_None && n == 256);
+
+// aFile.close();
+
+// rtl::OUString sce = bff.makeStringAndClear();
+
+// fprintf(stderr,rtl::OString(sce.getStr(),
+// sce.getLength(),
+// RTL_TEXTENCODING_UTF8).getStr());
+
+// rtl::OUString lib,tmp,testlib;
+// std::vector<rtl::OUString> tests;
+// sal_Int32 TEST = sce.indexOf(rtl::OUString::createFromAscii("TEST"));
+// sal_Int32 WITH = sce.indexOf(rtl::OUString::createFromAscii("WITH"));
+// sal_Int32 FROM = sce.indexOf(rtl::OUString::createFromAscii("FROM"));
+// lib = sce.copy(TEST+4,WITH-TEST-4).trim();
+
+// tmp = sce.copy(WITH+4,FROM-WITH-4).trim();
+// sal_Int32 nIndex = 0;
+// do
+// {
+// rtl::OUString token = tmp.getToken(0,';',nIndex).trim();
+// if(token.getLength())
+// tests.push_back(token);
+// } while(nIndex >= 0);
+
+// testlib = sce.copy(FROM+4).trim();
+
+// // fprintf(stderr,"%s\n",
+// // rtl::OString(token.getStr(),
+// // token.getLength(),
+// // RTL_TEXTENCODING_UTF8).getStr());
+
+// osl::Module testLib;
+// if(!testLib.load(testlib)) {
+// fprintf(stderr,"library not found: %s\n",
+// rtl::OString(testlib.getStr(),
+// testlib.getLength(),
+// RTL_TEXTENCODING_UTF8).getStr());
+// return 1;
+// }
+
+// osl::Module mathLib;
+// mathLib.load(rtl::OUString::createFromAscii("libm.so"));
+// typedef double (*DF)(double);
+// DF func = (DF)mathLib.getSymbol(rtl::OUString::createFromAscii("cos"));
+// fprintf(stderr,"-------double %f ----------\n",(*func)(2.0));
+
+// fprintf(stderr,"-------testing %s ----------\n",scefile);
diff --git a/ucb/source/ucp/ftp/test.py b/ucb/source/ucp/ftp/test.py
new file mode 100644
index 000000000000..531ca605e498
--- /dev/null
+++ b/ucb/source/ucp/ftp/test.py
@@ -0,0 +1,27 @@
+#/usr/bin/env python
+
+import re,os
+
+def grep(pattern,dirname,names):
+ for name in names:
+ filename = os.path.join(dirname,name)
+ if os.path.isfile(filename):
+ lines = open(filename,"r").readlines()
+ for line in lines:
+ if pattern.search(line):
+ print filename
+ break
+
+def find(regexp,dirName = "."):
+ os.path.walk(dirName,grep,re.compile(regexp))
+
+
+if __name__ == "__main__":
+ import sys
+ if len(sys.argv) == 3:
+ directory = sys.argv[2]
+ else:
+ directory = "."
+
+ dir(sys)
+ os.path.walk(directory,grep,re.compile(sys.argv[1]))
diff --git a/ucb/source/ucp/ftp/test_ftpurl.cxx b/ucb/source/ucp/ftp/test_ftpurl.cxx
index 47d1337dffd1..e43e3a4a1a4b 100755
--- a/ucb/source/ucp/ftp/test_ftpurl.cxx
+++ b/ucb/source/ucp/ftp/test_ftpurl.cxx
@@ -1,6 +1,27 @@
+#include <com/sun/star/ucb/OpenMode.hpp>
#include "ftpurl.hxx"
#include "ftploaderthread.hxx"
#include "ftphandleprovider.hxx"
+#include "debughelper.hxx"
+#include <rtl/memory.h>
+#include <vector>
+
+#define TESTEVAL \
+ if(number_of_errors) \
+ fprintf(stderr,"errors in %s: %d\n",name,number_of_errors); \
+ return number_of_errors
+
+
+namespace ccsu = com::sun::star::ucb;
+
+
+struct ServerInfo {
+ rtl::OUString host;
+ rtl::OUString port;
+ rtl::OUString username;
+ rtl::OUString password;
+ rtl::OUString account;
+};
class FTPHandleProviderI
@@ -20,65 +41,214 @@ public:
return p->handle();
}
+ bool forHost(const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ rtl::OUString& password,
+ rtl::OUString& account)
+ {
+ for(unsigned int i = 0; i < m_ServerInfo.size(); ++i)
+ if(host == m_ServerInfo[i].host &&
+ port == m_ServerInfo[i].port &&
+ username == m_ServerInfo[i].username ) {
+ password = m_ServerInfo[i].password;
+ account = m_ServerInfo[i].account;
+ return true;
+ }
+
+ return false;
+ }
+
+ virtual bool setHost(const rtl::OUString& host,
+ const rtl::OUString& port,
+ const rtl::OUString& username,
+ const rtl::OUString& password,
+ const rtl::OUString& account)
+ {
+ ServerInfo inf;
+ inf.host = host;
+ inf.port = port;
+ inf.username = username;
+ inf.password = password;
+ inf.account = account;
+
+ bool present(false);
+ for(unsigned int i = 0; i < m_ServerInfo.size(); ++i)
+ if(host == m_ServerInfo[i].host &&
+ port == m_ServerInfo[i].port) {
+ m_ServerInfo[i] = inf;
+ present = true;
+ }
+
+ if(!present)
+ m_ServerInfo.push_back(inf);
+
+ return !present;
+
+ }
+
+
private:
+ std::vector<ServerInfo> m_ServerInfo;
ftp::FTPLoaderThread *p;
};
+// Here are some test for the parsing of an url.
+
+#define TESTURL \
+{ \
+ftp::FTPURL url(rtl::OUString::createFromAscii(ascii),&prov); \
+if(!url.username().equalsAscii(n)) {\
+++number_of_errors; \
+err_msg("wrong username: ",url.username()); \
+}}
int test_ftpurl(void) {
+ const char* name = "test_ftpurl";
int number_of_errors = 0;
- ftp::FTPURL url1(
- rtl::OUString::createFromAscii(
- "ftp://abi:psswd@host/eins/../drei"));
- if(!url1.username().equalsAscii("abi"))
- ++number_of_errors;
- if(!url1.password().equalsAscii("psswd"))
- ++number_of_errors;
- if(!url1.ident().equalsAscii("ftp://host:21/drei"))
- ++number_of_errors;
+ FTPHandleProviderI prov;
+ char* ascii,*n,*p;
- ftp::FTPURL url2(
- rtl::OUString::createFromAscii(
- "ftp://:psswd@host:22/../../test"));
- if(!url2.username().equalsAscii("anonymous"))
- ++number_of_errors;
- if(!url2.password().equalsAscii("psswd"))
- ++number_of_errors;
- if(!url2.ident().equalsAscii("ftp://host:22/../../test"))
- ++number_of_errors;
+ ascii = "ftp://abi:psswd@host/eins/../drei", n = "abi", p = "psswd";
+ TESTURL;
+
+ ascii = "ftp://:psswd@host:22/eins/../drei", n = "anonymous", p = "psswd";
+ TESTURL;
+
+ ascii = "ftp://host/bla/../../test/", n = "anonymous", p = "";
+ TESTURL;
+
+ TESTEVAL;
+}
+
+
+int test_ftplist(void) {
+ int number_of_errors = 0;
+ const char* name = "test_ftplist";
+ FTPHandleProviderI provider;
- ftp::FTPURL url3(
+ ftp::FTPURL url(
rtl::OUString::createFromAscii(
- "ftp://host/bla/../../test/"));
- if(!url3.username().equalsAscii("anonymous"))
- ++number_of_errors;
- if(!url3.password().equalsAscii(""))
- ++number_of_errors;
- if(!url3.ident().equalsAscii("ftp://host:21/../test"))
+ "ftp://abi:psswd@abi-1/dir"),
+ &provider);
+
+ std::vector<ftp::FTPDirentry> vec =
+ url.list(com::sun::star::ucb::OpenMode::ALL);
+
+ if(vec.size() != 3)
++number_of_errors;
+ if(!(vec[0].m_aName.equalsAscii("dir1") &&
+ vec[1].m_aName.equalsAscii("dir2") &&
+ vec[2].m_aName.equalsAscii("file1")))
+ ++number_of_errors;
- return number_of_errors;
+ TESTEVAL;
}
+#define TESTPARENT \
+ { \
+ ftp::FTPURL url(rtl::OUString::createFromAscii(ascii),&prov); \
+ urlStr = url.parent(); \
+ if(!urlStr.equalsAscii(expect)) \
+ ++number_of_errors; \
+ }
-int test_ftpproperties(void) {
+
+int test_ftpparent(void) {
int number_of_errors = 0;
+ const char* name = "test_ftpparent";
+ FTPHandleProviderI prov;
+
+ rtl::OUString urlStr;
+ char *ascii,*expect;
+
+ ascii = "ftp://abi:psswd@abi-1/file";
+ expect = "ftp://abi:psswd@abi-1/";
+ TESTPARENT;
+
+ ascii = "ftp://abi:psswd@abi-1/dir/../file";
+ expect = "ftp://abi:psswd@abi-1/";
+ TESTPARENT;
+ ascii = "ftp://abi:psswd@abi-1/..";
+ expect = "ftp://abi:psswd@abi-1/../..";
+ TESTPARENT;
+
+ ascii = "ftp://abi:psswd@abi-1/../../dir";
+ expect = "ftp://abi:psswd@abi-1/../..";
+ TESTPARENT;
+
+ ascii = "ftp://abi:psswd@abi-1/";
+ expect = "ftp://abi:psswd@abi-1/..";
+ TESTPARENT;
+
+ TESTEVAL;
+}
+
+
+int test_ftpproperties(void) {
+ int number_of_errors = 0;
+ const char* name = "test_ftpproperties";
FTPHandleProviderI provider;
- ftp::FTPURL url3(
+ ftp::FTPURL url(
rtl::OUString::createFromAscii(
- "ftp://abi:psswd@abi-1/zips"),
+ "ftp://abi:psswd@abi-1/file"),
&provider);
- ftp::FTPDirentry aDE = url3.direntry();
+ ftp::FTPDirentry ade(url.direntry());
- return number_of_errors;
+ if(!(ade.m_aName.equalsAscii("file") &&
+ ade.isFile()))
+ ++number_of_errors;
+
+ TESTEVAL;
}
+
+
+int test_ftpopen(void)
+{
+ int number_of_errors = 0;
+ const char* name = "test_ftpopen";
+
+ FTPHandleProviderI provider;
+ ftp::FTPURL url(
+ rtl::OUString::createFromAscii(
+ "ftp://abi:psswd@abi-1/file"),
+ &provider);
+
+ FILE* file = url.open();
+ if(file) {
+ int nbuf,ndest;
+ const int bffsz = 256;
+ char buff[bffsz];
+ char *dest = (char*) malloc(sizeof(char));
+ dest[0] = 0;
+ do {
+ rtl_zeroMemory((void*)buff,bffsz);
+ fread(buff,bffsz-1,1,file);
+ nbuf = strlen(buff);
+ ndest = strlen(dest);
+ dest = (char*)realloc(dest,ndest + nbuf + 1);
+ strncat(dest,buff,nbuf);
+ } while(nbuf == bffsz-1);
+ fclose(file);
+
+ const char* expected = "You are now looking at the filecontent.\n";
+ if(strcmp(expected,dest))
+ ++number_of_errors;
+ free(dest);
+ } else
+ ++number_of_errors;
+
+ TESTEVAL;
+}
+
+
diff --git a/ucb/source/ucp/ftp/test_ftpurl.hxx b/ucb/source/ucp/ftp/test_ftpurl.hxx
index f5972af07afd..641e29fa8087 100755
--- a/ucb/source/ucp/ftp/test_ftpurl.hxx
+++ b/ucb/source/ucp/ftp/test_ftpurl.hxx
@@ -1,2 +1,5 @@
extern int test_ftpurl(void);
extern int test_ftpproperties(void);
+extern int test_ftpopen(void);
+extern int test_ftplist(void);
+extern int test_ftpparent(void);
diff --git a/ucb/source/ucp/ftp/test_interactionhandler.hxx b/ucb/source/ucp/ftp/test_interactionhandler.hxx
new file mode 100644
index 000000000000..1c179febd518
--- /dev/null
+++ b/ucb/source/ucp/ftp/test_interactionhandler.hxx
@@ -0,0 +1,109 @@
+/*************************************************************************
+ *
+ * $RCSfile: test_interactionhandler.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:19 $
+ *
+ * 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 _TEST_ACTIVEDATASINK_HXX_
+#define _TEST_ACTIVEDATASINK_HXX_
+
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/queryinterface.hxx>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+
+namespace test_ftp {
+
+
+ class Test_InteractionHandler
+ : public cppu::OWeakObject,
+ public com::sun::star::task::XInteractionHandler
+ {
+ public:
+
+ // XInterface
+
+ virtual com::sun::star::uno::Any SAL_CALL
+ queryInterface( const com::sun::star::uno::Type& rType )
+ throw( com::sun::star::uno::RuntimeException );
+
+
+ virtual void SAL_CALL acquire( void ) throw();
+
+ virtual void SAL_CALL release( void ) throw();
+
+
+ // XInteractionHandler
+
+ virtual void SAL_CALL
+ handle( const ::com::sun::star::uno::Reference<
+ ::com::sun::star::task::XInteractionRequest >& Request )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ private:
+
+ };
+
+}
+
+
+#endif
diff --git a/ucb/source/ucp/ftp/test_multiservicefac.hxx b/ucb/source/ucp/ftp/test_multiservicefac.hxx
index 75a71ef355cb..73e089924b3b 100644
--- a/ucb/source/ucp/ftp/test_multiservicefac.hxx
+++ b/ucb/source/ucp/ftp/test_multiservicefac.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: test_multiservicefac.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: abi $ $Date: 2002-08-28 07:29:51 $
+ * last change: $Author: abi $ $Date: 2002-10-15 09:21:19 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -133,3 +133,4 @@ namespace test_ftp {
}
#endif
+