Kaydet (Commit) cc506f01 authored tarafından Andreas Bille's avatar Andreas Bille

#104432# Changed to proxyconfig helper class

üst 7c6b58e4
......@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontent.cxx,v $
*
* $Revision: 1.16 $
* $Revision: 1.17 $
*
* last change: $Author: abi $ $Date: 2002-10-25 08:53:17 $
* last change: $Author: abi $ $Date: 2002-10-29 12:43:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -317,6 +317,7 @@ enum ACTION { NOACTION,
THROWINTERACTIVECONNECT,
THROWRESOLVENAME,
THROWQUOTE,
THROWNOFILE,
THROWGENERAL };
......@@ -428,6 +429,19 @@ Any SAL_CALL FTPContent::execute(
ucbhelper::cancelCommandExecution(
aRet,
Environment);
} else if(action == THROWNOFILE) {
Sequence<Any> seq(1);
PropertyValue value;
value.Name =
rtl::OUString::createFromAscii("Uri");
value.Handle = -1;
value.Value <<= m_aFTPURL.ident(false,false);
value.State = PropertyState_DIRECT_VALUE;
seq[0] <<= value;
ucbhelper::cancelCommandExecution(
IOErrorCode_NO_FILE,
seq,
Environment);
} else if(action == THROWQUOTE ||
action == THROWGENERAL) {
ucbhelper::cancelCommandExecution(
......@@ -580,6 +594,8 @@ Any SAL_CALL FTPContent::execute(
action = THROWACCESSDENIED;
else if(e.code() == CURLE_FTP_QUOTE_ERROR)
action = THROWQUOTE;
else if(e.code() == CURLE_FTP_COULDNT_RETR_FILE)
action = THROWNOFILE;
else
// nothing known about the course of the error
action = THROWGENERAL;
......@@ -647,7 +663,7 @@ FTPContent::getParent( )
throw (RuntimeException)
{
Reference<XContentIdentifier>
xIdent(new FTPContentIdentifier(m_aFTPURL.parent(),m_pFCP));
xIdent(new FTPContentIdentifier(m_aFTPURL.parent(false)));
Reference<XContent> xContent(m_xProvider->queryContent(xIdent));
return Reference<XInterface>(xContent,UNO_QUERY);
}
......@@ -861,7 +877,11 @@ Sequence<Any> FTPContent::setPropertyValues(
}
}
if(evt.getLength())
if(evt.getLength()) {
// title has changed
notifyPropertiesChange(evt);
exchange(new FTPContentIdentifier(m_aFTPURL.ident(false,false)));
}
return ret;
}
......@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentidentifier.cxx,v $
*
* $Revision: 1.5 $
* $Revision: 1.6 $
*
* last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
* last change: $Author: abi $ $Date: 2002-10-29 12:43:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -70,13 +70,13 @@
using namespace ftp;
using namespace com::sun::star::uno;
using namespace com::sun::star::ucb;
using namespace com::sun::star::lang;
FTPContentIdentifier::FTPContentIdentifier(
const rtl::OUString& aIdent,
FTPContentProvider* pFCP
const rtl::OUString& ident
)
: m_pURL(aIdent,pFCP)
: m_ident(ident)
{
}
......@@ -96,40 +96,79 @@ FTPContentIdentifier::queryInterface(
{
Any aRet =
::cppu::queryInterface(rType,
SAL_STATIC_CAST(XTypeProvider*,this),
SAL_STATIC_CAST(XContentIdentifier*,this));
return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
}
void SAL_CALL FTPContentIdentifier::acquire( void ) throw() {
OWeakObject::acquire();
}
void SAL_CALL FTPContentIdentifier::release( void ) throw() {
OWeakObject::release();
}
::rtl::OUString SAL_CALL
Sequence<sal_Int8> SAL_CALL
FTPContentIdentifier::getImplementationId()
throw(RuntimeException)
{
static cppu::OImplementationId* pId = NULL;
if(!pId)
{
osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
if ( !pId )
{
static cppu::OImplementationId id( sal_False );
pId = &id;
}
}
return (*pId).getImplementationId();
}
Sequence<Type> SAL_CALL
FTPContentIdentifier::getTypes(
void )
throw(RuntimeException)
{
static cppu::OTypeCollection* pCollection = NULL;
if ( !pCollection ) {
osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
if ( !pCollection )
{
static cppu::OTypeCollection collection(
getCppuType(
static_cast<Reference<XTypeProvider>*>(0)),
getCppuType(
static_cast<Reference<XContentIdentifier>*>(0)));
pCollection = &collection;
}
}
return (*pCollection).getTypes();
}
rtl::OUString SAL_CALL
FTPContentIdentifier::getContentIdentifier(
)
throw (
::com::sun::star::uno::RuntimeException
com::sun::star::uno::RuntimeException
)
{
return m_pURL.ident(false,false);
return m_ident;
}
::rtl::OUString SAL_CALL
rtl::OUString SAL_CALL
FTPContentIdentifier::getContentProviderScheme(
)
throw (
::com::sun::star::uno::RuntimeException
com::sun::star::uno::RuntimeException
)
{
return rtl::OUString::createFromAscii("ftp");
......
......@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentidentifier.hxx,v $
*
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* last change: $Author: abi $ $Date: 2002-10-15 09:21:16 $
* last change: $Author: abi $ $Date: 2002-10-29 12:43:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -73,12 +73,12 @@
#include <cppuhelper/weak.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <com/sun/star/ucb/XContentIdentifier.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
#include "ftpdirp.hxx"
#include "ftpurl.hxx"
namespace ftp {
......@@ -87,12 +87,12 @@ namespace ftp {
class FTPContentIdentifier
: public cppu::OWeakObject,
public com::sun::star::lang::XTypeProvider,
public com::sun::star::ucb::XContentIdentifier
{
public:
FTPContentIdentifier(const rtl::OUString& ident,
FTPContentProvider* pFCP = 0);
FTPContentIdentifier(const rtl::OUString& ident);
~FTPContentIdentifier();
......@@ -106,6 +106,23 @@ namespace ftp {
virtual void SAL_CALL release( void ) throw();
// XTypeProvider
virtual
com::sun::star::uno::Sequence<com::sun::star::uno::Type> SAL_CALL
getTypes(
)
throw(
com::sun::star::uno::RuntimeException
);
virtual com::sun::star::uno::Sequence<sal_Int8> SAL_CALL
getImplementationId(
)
throw(
com::sun::star::uno::RuntimeException
);
// XContentIdentifier
......@@ -113,7 +130,7 @@ namespace ftp {
getContentIdentifier(
)
throw (
::com::sun::star::uno::RuntimeException
com::sun::star::uno::RuntimeException
);
virtual ::rtl::OUString SAL_CALL
......@@ -126,7 +143,7 @@ namespace ftp {
private:
FTPURL m_pURL;
rtl::OUString m_ident;
};
}
......
......@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentprovider.cxx,v $
*
* $Revision: 1.7 $
* $Revision: 1.8 $
*
* last change: $Author: abi $ $Date: 2002-10-23 08:00:05 $
* last change: $Author: abi $ $Date: 2002-10-29 12:43:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -93,7 +93,8 @@ using namespace com::sun::star::beans;
FTPContentProvider::FTPContentProvider(const Reference< XMultiServiceFactory >& rSMgr)
: ::ucb::ContentProviderImplHelper(rSMgr),
m_ftpLoaderThread(NULL)
m_ftpLoaderThread(0),
m_pProxyDecider(0)
{
}
......@@ -102,6 +103,7 @@ FTPContentProvider::FTPContentProvider(const Reference< XMultiServiceFactory >&
FTPContentProvider::~FTPContentProvider()
{
delete m_ftpLoaderThread;
delete m_pProxyDecider;
}
//=========================================================================
......@@ -110,13 +112,10 @@ FTPContentProvider::~FTPContentProvider()
//
//=========================================================================
XINTERFACE_IMPL_6(FTPContentProvider,
XINTERFACE_IMPL_3(FTPContentProvider,
XTypeProvider,
XServiceInfo,
XContentProvider,
XComponent,
XEventListener,
XContainerListener);
XContentProvider)
//=========================================================================
//
......@@ -124,13 +123,10 @@ XINTERFACE_IMPL_6(FTPContentProvider,
//
//=========================================================================
XTYPEPROVIDER_IMPL_6(FTPContentProvider,
XTYPEPROVIDER_IMPL_3(FTPContentProvider,
XTypeProvider,
XServiceInfo,
XContentProvider,
XComponent,
XEventListener,
XContainerListener);
XContentProvider)
//=========================================================================
//
......@@ -177,10 +173,15 @@ FTPContentProvider::queryContent(
{
// Initialize
osl::MutexGuard aGuard( m_aMutex );
if(!m_ftpLoaderThread)
if(!m_ftpLoaderThread || !m_pProxyDecider)
{
try {
init();
if(!m_ftpLoaderThread)
} catch( ... ) {
throw RuntimeException();
}
if(!m_ftpLoaderThread || !m_pProxyDecider)
throw RuntimeException();
}
}
......@@ -188,7 +189,11 @@ FTPContentProvider::queryContent(
try {
FTPURL aURL(xCanonicId->getContentIdentifier(),
this);
if(!ShouldUseFtpProxy(aURL))
if(!m_pProxyDecider->shouldUseProxy(
rtl::OUString::createFromAscii("ftp"),
aURL.host(),
aURL.port().toInt32()))
xContent = new FTPContent(m_xSMgr,this,xCanonicId,aURL);
else {
Reference<XContentProvider>
......@@ -208,134 +213,10 @@ FTPContentProvider::queryContent(
// from inetoptions
enum ProxyType { NONE, AUTOMATIC, MANUAL };
bool FTPContentProvider::ShouldUseFtpProxy(const FTPURL& aURL) const
{
// Check URL.
if(m_eType == NONE)
return false;
if(! m_aFtpProxy.getLength())
return false;
if(m_aNoProxyList.getLength())
{
// Setup Endpoint.
rtl::OUString host(aURL.host());
if(!host.getLength())
return false;
osl::SocketAddr aAddr(host,21); // port does not matter here
host = aAddr.getHostname().toAsciiLowerCase();
sal_Int32 port = aURL.port().toInt32();
// Match NoProxyList.
sal_Int32 nIndex = 0;
do {
rtl::OUString aDomain =
m_aNoProxyList.getToken(0,';',nIndex).toAsciiLowerCase();
rtl::OUString aPort;
sal_Int32 i(aDomain.indexOf(':',0));
if(i != -1) {
aPort = aDomain.copy(1+i);
aDomain = aDomain.copy(0,i).trim();
}
if(!aDomain.getLength())
continue;
if(host == aDomain)
if(aPort.getLength() == 0 || port == aPort.toInt32())
return false;
else
return true;
i = host.lastIndexOf(aDomain);
if(i!=-1 &&
// i == 0 not possible here anymore!
// really last part of string of the string?:
host.getLength() == i+aDomain.getLength() &&
// ensure not to match "xy.z" on "x.z" or ".x.z"
(aDomain.getStr()[0] == '.' || host.getStr()[i-1] == '.') &&
// does the port match?
(aPort.getLength() == 0 || port == aPort.toInt32()))
return false;
}
while ( nIndex != -1 );
}
return true;
}
void SAL_CALL
FTPContentProvider::elementReplaced(const ContainerEvent& Event)
throw(RuntimeException)
{
rtl::OUString accessor;
Event.Accessor >>= accessor;
if(accessor.compareToAscii("ooInetFTPProxyName") == 0) {
rtl::OUString replacedElement,element;
if((Event.ReplacedElement >>= replacedElement) &&
(Event.Element >>= element) )
{
osl::MutexGuard aGuard(m_aMutex);
m_aFtpProxy = element;
}
} else if(accessor.compareToAscii("ooInetNoProxy") == 0) {
rtl::OUString replacedElement,element;
if((Event.ReplacedElement >>= replacedElement) &&
(Event.Element >>= element))
{
osl::MutexGuard aGuard(m_aMutex);
m_aNoProxyList = element;
}
}
else if(accessor.compareToAscii("ooInetProxyType") == 0) {
sal_Int32 replacedElement,element;
if((Event.ReplacedElement >>= replacedElement) &&
(Event.Element >>= element))
{
osl::MutexGuard aGuard(m_aMutex);
m_eType = element;
}
}
}
void FTPContentProvider::init() {
m_ftpLoaderThread = new FTPLoaderThread();
Reference< XMultiServiceFactory > sProvider( getConfiguration());
Reference< XHierarchicalNameAccess > xHierAccess(
getHierAccess(sProvider,"org.openoffice.Inet"));
m_aFtpProxy = getKey(xHierAccess,
"Settings/ooInetFTPProxyName");
m_aNoProxyList = getKey(xHierAccess,
"Settings/ooInetNoProxy");
m_eType = getIntKey(xHierAccess,
"Settings/ooInetProxyType");
try
{
// add as configuration change listener for the proxy settings
Reference<XNameAccess> xAccess(xHierAccess,UNO_QUERY);
Any aAny =
xAccess->getByName(rtl::OUString::createFromAscii("Settings"));
aAny >>= m_xContainer;
if(m_xContainer.is())
m_xContainer->addContainerListener(this);
}
catch(const com::sun::star::uno::Exception& )
{
}
m_pProxyDecider = new ucbhelper::InternetProxyDecider(m_xSMgr);
}
......@@ -401,154 +282,28 @@ bool FTPContentProvider::setHost(
}
Reference<XMultiServiceFactory>
FTPContentProvider::getConfiguration() const
{
Reference< XMultiServiceFactory > sProvider;
if(m_xSMgr.is())
{
Any aAny;
aAny <<= rtl::OUString::createFromAscii( "plugin" );
PropertyValue aProp(
rtl::OUString::createFromAscii( "servertype" ),
-1,
aAny,
PropertyState_DIRECT_VALUE );
Sequence<Any> seq(1);
seq[0] <<= aProp;
try
{
rtl::OUString sProviderService =
rtl::OUString::createFromAscii(
"com.sun.star.configuration.ConfigurationProvider" );
sProvider =
Reference<XMultiServiceFactory>(
m_xSMgr->createInstanceWithArguments(
sProviderService,seq ),
UNO_QUERY );
}
catch( const com::sun::star::uno::Exception& )
{
OSL_ENSURE( sProvider.is(),"cant instantiate configuration" );
}
}
return sProvider;
}
Reference<XHierarchicalNameAccess>
FTPContentProvider::getHierAccess(
const Reference<XMultiServiceFactory >& sProvider,
const char* file ) const
{
Reference<XHierarchicalNameAccess>
xHierAccess;
if( sProvider.is() )
{
Sequence<Any> seq(1);
rtl::OUString sReaderService =
rtl::OUString::createFromAscii(
"com.sun.star.configuration.ConfigurationAccess" );
seq[0] <<= rtl::OUString::createFromAscii(file);
try
{
xHierAccess =
Reference<
XHierarchicalNameAccess >(
sProvider->createInstanceWithArguments(
sReaderService,seq ),
UNO_QUERY );
}
catch( const Exception& )
{
}
}
return xHierAccess;
}
rtl::OUString
FTPContentProvider::getKey(
const Reference<XHierarchicalNameAccess>& xHierAccess,
const char* key ) const
{
rtl::OUString val;
if( xHierAccess.is() )
{
Any aAny;
try
{
aAny =
xHierAccess->getByHierarchicalName(
rtl::OUString::createFromAscii(key));
}
catch( const NoSuchElementException& )
{
}
aAny >>= val;
}
return val;
}
sal_Int32
FTPContentProvider::getIntKey(
const Reference<XHierarchicalNameAccess>& xHierAccess,
const char* key ) const
{
sal_Int32 val = 0;
if( xHierAccess.is() )
{
Any aAny;
try
{
aAny =
xHierAccess->getByHierarchicalName(
rtl::OUString::createFromAscii(key));
}
catch( const NoSuchElementException& )
{
}
aAny >>= val;
}
return val;
}
Reference<XContentProvider>
FTPContentProvider::getHttpProvider()
throw(RuntimeException)
{
osl::MutexGuard aGuard(m_aMutex);
if (!m_xManager.is())
{
if (!m_xManager.is())
{
ucb::ContentBroker * pBroker = ucb::ContentBroker::get();
if (pBroker)
{
m_xManager = pBroker->getContentProviderManagerInterface();
if (!m_xManager.is())
// used for access to ftp-proxy
ucb::ContentBroker *pBroker = ucb::ContentBroker::get();
if(pBroker) {
Reference<XContentProviderManager > xManager(
pBroker->getContentProviderManagerInterface());
if(xManager.is())
return
xManager->queryContentProvider(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http:")));
else
throw RuntimeException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"bad ucb::ContentBroker")),
*this);
}
if (!m_xManager.is())
} else
return 0;
}
}
return m_xManager->
queryContentProvider(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"http:")));
//TODO! input ok?
}
......@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontentprovider.hxx,v $
*
* $Revision: 1.6 $
* $Revision: 1.7 $
*
* last change: $Author: abi $ $Date: 2002-10-23 08:00:07 $
* last change: $Author: abi $ $Date: 2002-10-29 12:43:14 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -65,6 +65,7 @@
#include <vector>
#include <osl/mutex.hxx>
#include <ucbhelper/macros.hxx>
#include <ucbhelper/proxydecider.hxx>
#include <ucbhelper/providerhelper.hxx>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
......@@ -100,8 +101,7 @@ namespace ftp {
class FTPContentProvider:
public ::ucb::ContentProviderImplHelper,
public ::com::sun::star::container::XContainerListener,
public ::com::sun::star::lang::XComponent,
// public ::com::sun::star::lang::XComponent,
public FTPHandleProvider
{
public:
......@@ -125,62 +125,7 @@ namespace ftp {
throw( com::sun::star::ucb::IllegalIdentifierException,
com::sun::star::uno::RuntimeException );
// XComponent
virtual void SAL_CALL
dispose( )
throw (::com::sun::star::uno::RuntimeException)
{
if(m_xContainer.is())
{
m_xContainer->removeContainerListener(this);
m_xContainer =
com::sun::star::uno::Reference<
com::sun::star::container::XContainer>(0);
}
}
virtual void SAL_CALL
addEventListener(
const ::com::sun::star::uno::Reference<
::com::sun::star::lang::XEventListener >& xListener )
throw (::com::sun::star::uno::RuntimeException) { }
virtual void SAL_CALL
removeEventListener(
const ::com::sun::star::uno::Reference<
::com::sun::star::lang::XEventListener >& aListener )
throw (::com::sun::star::uno::RuntimeException) { }
// XConainerListener ( deriver from XEventListener )
virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject& Source )
throw (::com::sun::star::uno::RuntimeException)
{
m_xContainer =
com::sun::star::uno::Reference<
com::sun::star::container::XContainer>(0);
}
virtual void SAL_CALL
elementInserted(
const ::com::sun::star::container::ContainerEvent& Event )
throw (::com::sun::star::uno::RuntimeException) { }
virtual void SAL_CALL
elementRemoved(
const ::com::sun::star::container::ContainerEvent& Event )
throw (::com::sun::star::uno::RuntimeException) { }
virtual void SAL_CALL
elementReplaced(
const ::com::sun::star::container::ContainerEvent& Event )
throw (::com::sun::star::uno::RuntimeException);
/** FTPHandleProvider.
*/
// FTPHandleProvider.
virtual CURL* handle();
......@@ -209,51 +154,15 @@ namespace ftp {
osl::Mutex m_aMutex;
FTPLoaderThread *m_ftpLoaderThread;
sal_Int32 m_eType;
rtl::OUString m_aFtpProxy;
rtl::OUString m_aNoProxyList;
// used for access to ftp-proxy
com::sun::star::uno::Reference<
com::sun::star::ucb::XContentProviderManager > m_xManager;
com::sun::star::uno::Reference<
com::sun::star::container::XContainer> m_xContainer;
ucbhelper::InternetProxyDecider *m_pProxyDecider;
std::vector<ServerInfo> m_ServerInfo;
void init();
com::sun::star::uno::Reference<
com::sun::star::lang::XMultiServiceFactory >
getConfiguration() const;
com::sun::star::uno::Reference<
com::sun::star::container::XHierarchicalNameAccess >
getHierAccess(
const com::sun::star::uno::Reference<
com::sun::star::lang::XMultiServiceFactory >& sProvider,
const char* file ) const;
rtl::OUString
getKey(
const com::sun::star::uno::Reference<
com::sun::star::container::XHierarchicalNameAccess >& xHierAccess,
const char* key) const;
sal_Int32
getIntKey(
const com::sun::star::uno::Reference<
com::sun::star::container::XHierarchicalNameAccess >& xHierAccess,
const char* key) const;
com::sun::star::uno::Reference<com::sun::star::ucb::XContentProvider>
getHttpProvider()
throw(com::sun::star::uno::RuntimeException);
bool ShouldUseFtpProxy(const FTPURL& aURL) const;
}; // end class FTPContentProvider
} // end namespace ftp
......
......@@ -2,9 +2,9 @@
*
* $RCSfile: ftpurl.cxx,v $
*
* $Revision: 1.12 $
* $Revision: 1.13 $
*
* last change: $Author: abi $ $Date: 2002-10-25 12:09:11 $
* last change: $Author: abi $ $Date: 2002-10-29 12:43:14 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -460,6 +460,9 @@ extern "C" int no_func(void *client, char *prompt, char*
FILE* FTPURL::open()
throw(curl_exception)
{
if(!m_aPathSegmentVec.size())
throw curl_exception(CURLE_FTP_COULDNT_RETR_FILE);
CURL *curl = m_pFCP->handle();
SET_CONTROL_CONTAINER;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment