summaryrefslogtreecommitdiff
path: root/shell/source/backends/wininetbe/wininetbackend.cxx
diff options
context:
space:
mode:
authorsb <sb@openoffice.org>2009-10-01 10:39:31 +0200
committersb <sb@openoffice.org>2009-10-01 10:39:31 +0200
commit3ffb5481b5e116c4a39dd07335439e711f0ca706 (patch)
tree31a5c69a528a1a0349f5570f612d430dc03a308e /shell/source/backends/wininetbe/wininetbackend.cxx
parent49a83697aafbeccb1a1c5ad8c4f474a567a3af55 (diff)
#i101955# adapted more platform backends to new interface
Diffstat (limited to 'shell/source/backends/wininetbe/wininetbackend.cxx')
-rw-r--r--shell/source/backends/wininetbe/wininetbackend.cxx403
1 files changed, 346 insertions, 57 deletions
diff --git a/shell/source/backends/wininetbe/wininetbackend.cxx b/shell/source/backends/wininetbe/wininetbackend.cxx
index 018560f4f762..344eefa1a08d 100644
--- a/shell/source/backends/wininetbe/wininetbackend.cxx
+++ b/shell/source/backends/wininetbe/wininetbackend.cxx
@@ -31,76 +31,379 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_shell.hxx"
+#include "rtl/ustrbuf.hxx"
+
#include "wininetbackend.hxx"
-#include "wininetlayer.hxx"
-#include <com/sun/star/configuration/backend/ComponentChangeEvent.hpp>
-#include <uno/current_context.hxx>
+
+#if defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#include <windows.h>
+#include <wininet.h>
+#if defined _MSC_VER
+#pragma warning(pop)
+#endif
#define WININET_DLL_NAME "wininet.dll"
+#define EQUAL_SIGN '='
+#define COLON ':'
+#define SPACE ' '
+#define SEMI_COLON ';'
+
+namespace {
+
+struct Library {
+ HMODULE module;
+
+ Library(HMODULE theModule): module(theModule) {}
+
+ ~Library() { if (module) FreeLibrary(module); }
+};
+
+}
-WinInetBackend::WinInetBackend(const uno::Reference<uno::XComponentContext>& xContext)
- throw (backend::BackendAccessException) :
- ::cppu::WeakImplHelper2 < backend::XSingleLayerStratum, lang::XServiceInfo > (),
- m_xContext(xContext)
+typedef struct
{
- m_hWinInetDll = LoadLibrary( WININET_DLL_NAME );
+ rtl::OUString Server;
+ rtl::OUString Port;
+} ProxyEntry;
+
+//------------------------------------------------------------------------
+// helper functions
+//------------------------------------------------------------------------
+
+namespace // private
+{
+ ProxyEntry ReadProxyEntry(const rtl::OUString& aProxy, sal_Int32& i)
+ {
+ ProxyEntry aProxyEntry;
+
+ aProxyEntry.Server = aProxy.getToken( 0, COLON, i );
+ if ( i > -1 )
+ aProxyEntry.Port = aProxy.getToken( 0, COLON, i );
+
+ return aProxyEntry;
+ }
+
+ ProxyEntry FindProxyEntry(const rtl::OUString& aProxyList, const rtl::OUString& aType)
+ {
+ sal_Int32 nIndex = 0;
+
+ do
+ {
+ // get the next token, e.g. ftp=server:port
+ rtl::OUString nextToken = aProxyList.getToken( 0, SPACE, nIndex );
+
+ // split the next token again into the parts separated
+ // through '=', e.g. ftp=server:port -> ftp and server:port
+ sal_Int32 i = 0;
+ if( nextToken.indexOf( EQUAL_SIGN ) > -1 )
+ {
+ if( aType.equals( nextToken.getToken( 0, EQUAL_SIGN, i ) ) )
+ return ReadProxyEntry(nextToken, i);
+ }
+ else if( aType.getLength() == 0)
+ return ReadProxyEntry(nextToken, i);
+
+ } while ( nIndex >= 0 );
+
+ return ProxyEntry();
+ }
+
+} // end private namespace
+
+//------------------------------------------------------------------------------
+
+WinInetBackend::WinInetBackend():
+ hasProxyType_(false), hasNoProxy_(false), hasHttpProxyName_(false),
+ hasHttpProxyPort_(false), hasHttpsProxyName_(false),
+ hasHttpsProxyPort_(false), hasFtpProxyName_(false), hasFtpProxyPort_(false)
+{
+ Library hWinInetDll( LoadLibrary( WININET_DLL_NAME ) );
+ if( hWinInetDll.module )
+ {
+ typedef BOOL ( WINAPI *InternetQueryOption_Proc_T )( HINTERNET, DWORD, LPVOID, LPDWORD );
+
+ InternetQueryOption_Proc_T lpfnInternetQueryOption =
+ reinterpret_cast< InternetQueryOption_Proc_T >(
+ GetProcAddress( hWinInetDll.module, "InternetQueryOptionA" ) );
+ if (lpfnInternetQueryOption)
+ {
+ LPINTERNET_PROXY_INFO lpi = NULL;
+
+ // query for the neccessary space
+ DWORD dwLength = 0;
+ BOOL bRet = lpfnInternetQueryOption(
+ NULL,
+ INTERNET_OPTION_PROXY,
+ (LPVOID)lpi,
+ &dwLength );
+
+ // allocate sufficient space on the heap
+ // insufficient space on the heap results
+ // in a stack overflow exception, we assume
+ // this never happens, because of the relatively
+ // small amount of memory we need
+ // _alloca is nice because it is fast and we don't
+ // have to free the allocated memory, it will be
+ // automatically done
+ lpi = reinterpret_cast< LPINTERNET_PROXY_INFO >(
+ _alloca( dwLength ) );
+
+ bRet = lpfnInternetQueryOption(
+ NULL,
+ INTERNET_OPTION_PROXY,
+ (LPVOID)lpi,
+ &dwLength );
+
+ // if a proxy is disabled, InternetQueryOption returns
+ // an empty proxy list, so we don't have to check if
+ // proxy is enabled or not
+
+ rtl::OUString aProxyList = rtl::OUString::createFromAscii( lpi->lpszProxy );
+ rtl::OUString aProxyBypassList = rtl::OUString::createFromAscii( lpi->lpszProxyBypass );
+
+ // override default for ProxyType, which is "0" meaning "No proxies".
+ sal_Int32 nProperties = 1;
+
+ valueProxyType_ = nProperties;
+ hasProxyType_ = true;
+
+ // fill proxy bypass list
+ if( aProxyBypassList.getLength() > 0 )
+ {
+ rtl::OUStringBuffer aReverseList;
+ sal_Int32 nIndex = 0;
+ do
+ {
+ rtl::OUString aToken = aProxyBypassList.getToken( 0, SPACE, nIndex );
+ if ( aProxyList.indexOf( aToken ) == -1 )
+ {
+ if ( aReverseList.getLength() )
+ {
+ aReverseList.insert( 0, sal_Unicode( SEMI_COLON ) );
+ aReverseList.insert( 0, aToken );
+ }
+ else
+ aReverseList = aToken;
+ }
+ }
+ while ( nIndex >= 0 );
+
+ aProxyBypassList = aReverseList.makeStringAndClear();
+
+ valueNoProxy_ = aProxyBypassList.replace( SPACE, SEMI_COLON );
+ hasNoProxy_ = true;
+ }
+
+ if( aProxyList.getLength() > 0 )
+ {
+ //-------------------------------------------------
+ // this implementation follows the algorithm
+ // of the internet explorer
+ // if there are type-dependent proxy settings
+ // and type independent proxy settings in the
+ // registry the internet explorer chooses the
+ // type independent proxy for all settings
+ // e.g. imagine the following registry entry
+ // ftp=server:port;http=server:port;server:port
+ // the last token server:port is type independent
+ // so the ie chooses this proxy server
+
+ // if there is no port specified for a type independent
+ // server the ie uses the port of an http server if
+ // there is one and it has a port
+ //-------------------------------------------------
+
+ ProxyEntry aTypeIndepProxy = FindProxyEntry( aProxyList, rtl::OUString());
+ ProxyEntry aHttpProxy = FindProxyEntry( aProxyList, rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "http" ) ) );
+ ProxyEntry aHttpsProxy = FindProxyEntry( aProxyList, rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "https" ) ) );
+
+ ProxyEntry aFtpProxy = FindProxyEntry( aProxyList, rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "ftp" ) ) );
+
+ if( aTypeIndepProxy.Server.getLength() )
+ {
+ aHttpProxy.Server = aTypeIndepProxy.Server;
+ aHttpsProxy.Server = aTypeIndepProxy.Server;
+ aFtpProxy.Server = aTypeIndepProxy.Server;
+
+ if( aTypeIndepProxy.Port.getLength() )
+ {
+ aHttpProxy.Port = aTypeIndepProxy.Port;
+ aHttpsProxy.Port = aTypeIndepProxy.Port;
+ aFtpProxy.Port = aTypeIndepProxy.Port;
+ }
+ else
+ {
+ aFtpProxy.Port = aHttpProxy.Port;
+ aHttpsProxy.Port = aHttpProxy.Port;
+ }
+ }
+
+ // http proxy name
+ if( aHttpProxy.Server.getLength() > 0 )
+ {
+ valueHttpProxyName_ = aHttpProxy.Server;
+ hasHttpProxyName_ = true;
+ }
+
+ // http proxy port
+ if( aHttpProxy.Port.getLength() > 0 )
+ {
+ valueHttpProxyPort_ = aHttpProxy.Port.toInt32();
+ hasHttpProxyPort_ = true;
+ }
+
+ // https proxy name
+ if( aHttpsProxy.Server.getLength() > 0 )
+ {
+ valueHttpsProxyName_ = aHttpsProxy.Server;
+ valueHttpsProxyPort_ = true;
+ }
+
+ // https proxy port
+ if( aHttpsProxy.Port.getLength() > 0 )
+ {
+ valueHttpsProxyPort_ = aHttpsProxy.Port.toInt32();
+ hasHttpsProxyPort_ = true;
+ }
+
+ // ftp proxy name
+ if( aFtpProxy.Server.getLength() > 0 )
+ {
+ valueFtpProxyName_ = aFtpProxy.Server;
+ hasFtpProxyName_ = true;
+ }
+
+ // ftp proxy port
+ if( aFtpProxy.Port.getLength() > 0 )
+ {
+ valueFtpProxyPort_ = aFtpProxy.Port.toInt32();
+ hasFtpProxyPort_ = true;
+ }
+ }
+ }
+ }
}
//------------------------------------------------------------------------------
WinInetBackend::~WinInetBackend(void)
{
- if ( m_hWinInetDll )
- FreeLibrary( m_hWinInetDll );
}
//------------------------------------------------------------------------------
-WinInetBackend* WinInetBackend::createInstance(
- const uno::Reference<uno::XComponentContext>& xContext
-)
+WinInetBackend* WinInetBackend::createInstance()
{
- return new WinInetBackend(xContext);
+ return new WinInetBackend;
}
// ---------------------------------------------------------------------------------------
-uno::Reference<backend::XLayer> SAL_CALL WinInetBackend::getLayer(
- const rtl::OUString& aComponent, const rtl::OUString& /*aTimestamp*/)
- throw (backend::BackendAccessException, lang::IllegalArgumentException)
+css::uno::Type WinInetBackend::getElementType() throw(css::uno::RuntimeException)
{
+ return cppu::UnoType< cppu::UnoVoidType >::get();
+}
- if( aComponent.equals( getSupportedComponents()[0]) )
- {
- if( ! m_xSystemLayer.is() && m_hWinInetDll )
- {
- WinInetLayer::InternetQueryOption_Proc_T lpfnInternetQueryOption =
- reinterpret_cast< WinInetLayer::InternetQueryOption_Proc_T >(
- GetProcAddress( m_hWinInetDll, "InternetQueryOptionA" ) );
-
- if( lpfnInternetQueryOption )
- m_xSystemLayer = new WinInetLayer(lpfnInternetQueryOption, m_xContext);
- }
+sal_Bool WinInetBackend::hasElements() throw(css::uno::RuntimeException)
+{
+ return true;
+}
- return m_xSystemLayer;
+css::uno::Any WinInetBackend::getByName(rtl::OUString const & aName)
+ throw (
+ css::container::NoSuchElementException,
+ css::lang::WrappedTargetException, css::uno::RuntimeException)
+{
+ if (aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName"))) {
+ return hasFtpProxyName_
+ ? uno::makeAny( valueFtpProxyName_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")))
+ {
+ return hasFtpProxyPort_
+ ? uno::makeAny( valueFtpProxyPort_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")))
+ {
+ return hasHttpProxyName_
+ ? uno::makeAny( valueHttpProxyName_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")))
+ {
+ return hasHttpProxyPort_
+ ? uno::makeAny( valueHttpProxyPort_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")))
+ {
+ return hasHttpsProxyName_
+ ? uno::makeAny( valueHttpsProxyName_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")))
+ {
+ return hasHttpsProxyPort_
+ ? uno::makeAny( valueHttpsProxyPort_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")))
+ {
+ return hasNoProxy_
+ ? uno::makeAny( valueNoProxy_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else if (aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetProxyType")))
+ {
+ return hasProxyType_
+ ? uno::makeAny( valueProxyType_ )
+ : css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+ } else {
+ throw css::container::NoSuchElementException(
+ aName, static_cast< cppu::OWeakObject * >(this));
}
-
- return uno::Reference<backend::XLayer>();
}
-//------------------------------------------------------------------------------
-
-uno::Reference<backend::XUpdatableLayer> SAL_CALL
-WinInetBackend::getUpdatableLayer(const rtl::OUString& /*aComponent*/)
- throw (backend::BackendAccessException,lang::NoSupportException,
- lang::IllegalArgumentException)
+css::uno::Sequence< rtl::OUString > WinInetBackend::getElementNames()
+ throw (css::uno::RuntimeException)
{
- throw lang::NoSupportException(
- rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
- "WinInetBackend: No Update Operation allowed, Read Only access") ),
- *this) ;
+ css::uno::Sequence< rtl::OUString > names(8);
+ names[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyName"));
+ names[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyPort"));
+ names[2] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyName"));
+ names[3] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyPort"));
+ names[4] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPSProxyName"));
+ names[5] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPSProxyPort"));
+ names[6] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetNoProxy"));
+ names[7] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetProxyType"));
+ return names;
+}
- return NULL;
+sal_Bool WinInetBackend::hasByName(rtl::OUString const & aName)
+ throw (css::uno::RuntimeException)
+{
+ return
+ aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) ||
+ aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) ||
+ aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) ||
+ aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) ||
+ aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) ||
+ aName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) ||
+ aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) ||
+ aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetProxyType"));
}
//------------------------------------------------------------------------------
@@ -121,9 +424,8 @@ rtl::OUString SAL_CALL WinInetBackend::getImplementationName(void)
uno::Sequence<rtl::OUString> SAL_CALL WinInetBackend::getBackendServiceNames(void)
{
- uno::Sequence<rtl::OUString> aServiceNameList(2);
+ uno::Sequence<rtl::OUString> aServiceNameList(1);
aServiceNameList[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.backend.WinInetBackend")) ;
- aServiceNameList[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.backend.PlatformBackend")) ;
return aServiceNameList ;
}
@@ -149,16 +451,3 @@ uno::Sequence<rtl::OUString> SAL_CALL WinInetBackend::getSupportedServiceNames(v
{
return getBackendServiceNames() ;
}
-
-// ---------------------------------------------------------------------------------------
-
-uno::Sequence<rtl::OUString> SAL_CALL WinInetBackend::getSupportedComponents(void)
-{
- uno::Sequence<rtl::OUString> aSupportedComponentList(1);
- aSupportedComponentList[0] = rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet" )
- );
-
- return aSupportedComponentList;
-}
-