26#include <com/sun/star/uno/XComponentContext.hpp>
28#include <rtl/ustrbuf.hxx>
33#if !defined WIN32_LEAN_AND_MEAN
34# define WIN32_LEAN_AND_MEAN
40#define WININET_DLL_NAME L"wininet.dll"
62 ProxyEntry ReadProxyEntry(std::u16string_view aProxy, std::size_t&
i)
64 ProxyEntry aProxyEntry;
67 if (
i != std::u16string_view::npos )
73 ProxyEntry FindProxyEntry(std::u16string_view aProxyList, std::u16string_view aType)
85 if( nextToken.find(
EQUAL_SIGN ) != std::u16string_view::npos )
88 return ReadProxyEntry(nextToken,
i);
90 else if( aType.empty())
91 return ReadProxyEntry(nextToken,
i);
93 }
while (
nIndex != std::u16string_view::npos );
103 if( hWinInetDll.module )
105 typedef BOOL ( WINAPI *InternetQueryOption_Proc_T )( HINTERNET, DWORD, LPVOID, LPDWORD );
107 InternetQueryOption_Proc_T lpfnInternetQueryOption =
108 reinterpret_cast< InternetQueryOption_Proc_T
>(
109 GetProcAddress( hWinInetDll.module,
"InternetQueryOptionW" ) );
110 if (lpfnInternetQueryOption)
118 INTERNET_PROXY_INFO pi;
119 LPINTERNET_PROXY_INFO lpi = π
120 DWORD dwLength =
sizeof (pi);
121 bool ok = lpfnInternetQueryOption(
123 INTERNET_OPTION_PROXY,
128 DWORD
err = GetLastError();
129 if (
err == ERROR_INSUFFICIENT_BUFFER)
139 lpi =
static_cast< LPINTERNET_PROXY_INFO
>(
140 alloca( dwLength ) );
141 ok = lpfnInternetQueryOption(
143 INTERNET_OPTION_PROXY,
148 err = GetLastError();
155 "InternetQueryOption INTERNET_OPTION_PROXY"
156 " GetLastError=" <<
err);
171 OUString aProxyList = OUString::createFromAscii( lpi->lpszProxy );
172 OUString aProxyBypassList = OUString::createFromAscii( lpi->lpszProxyBypass );
179 if( aProxyBypassList.getLength() > 0 )
181 OUStringBuffer aReverseList;
185 OUString aToken = aProxyBypassList.getToken( 0,
SPACE,
nIndex );
186 if ( aProxyList.indexOf( aToken ) == -1 )
188 if ( aReverseList.getLength() )
191 aReverseList.insert( 0, aToken );
194 aReverseList = aToken;
199 aProxyBypassList = aReverseList.makeStringAndClear();
205 if( aProxyList.getLength() > 0 )
224 ProxyEntry aTypeIndepProxy = FindProxyEntry( aProxyList,
u"");
225 ProxyEntry aHttpProxy = FindProxyEntry( aProxyList,
u"http" );
226 ProxyEntry aHttpsProxy = FindProxyEntry( aProxyList,
u"https" );
228 ProxyEntry aFtpProxy = FindProxyEntry( aProxyList,
u"ftp" );
230 if( aTypeIndepProxy.Server.getLength() )
232 aHttpProxy.Server = aTypeIndepProxy.Server;
233 aHttpsProxy.Server = aTypeIndepProxy.Server;
234 aFtpProxy.Server = aTypeIndepProxy.Server;
236 if( aTypeIndepProxy.Port.getLength() )
238 aHttpProxy.Port = aTypeIndepProxy.Port;
239 aHttpsProxy.Port = aTypeIndepProxy.Port;
240 aFtpProxy.Port = aTypeIndepProxy.Port;
244 aFtpProxy.Port = aHttpProxy.Port;
245 aHttpsProxy.Port = aHttpProxy.Port;
250 if( aHttpProxy.Server.getLength() > 0 )
257 if( aHttpProxy.Port.getLength() > 0 )
264 if( aHttpsProxy.Server.getLength() > 0 )
271 if( aHttpsProxy.Port.getLength() > 0 )
278 if( aFtpProxy.Server.getLength() > 0 )
285 if( aFtpProxy.Port.getLength() > 0 )
300 OUString
const &, css::uno::Any
const &)
302 throw css::lang::IllegalArgumentException(
303 "setPropertyValue not supported",
308 OUString
const & PropertyName)
310 if ( PropertyName ==
"ooInetFTPProxyName" )
313 }
else if ( PropertyName ==
"ooInetFTPProxyPort" )
316 }
else if ( PropertyName ==
"ooInetHTTPProxyName" )
319 }
else if ( PropertyName ==
"ooInetHTTPProxyPort" )
322 }
else if ( PropertyName ==
"ooInetHTTPSProxyName" )
325 }
else if ( PropertyName ==
"ooInetHTTPSProxyPort" )
328 }
else if ( PropertyName ==
"ooInetNoProxy" )
331 }
else if ( PropertyName ==
"ooInetProxyType" )
335 throw css::beans::UnknownPropertyException(
336 PropertyName, getXWeak());
342 return "com.sun.star.comp.configuration.backend.WinInetBackend" ;
352 return {
"com.sun.star.configuration.backend.WinInetBackend" };
355extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
357 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
~WinInetBackend() override
Destructor.
css::beans::Optional< css::uno::Any > valueFtpProxyPort_
css::beans::Optional< css::uno::Any > valueHttpsProxyPort_
WinInetBackend()
Service constructor from a service factory.
virtual void SAL_CALL setPropertyValue(OUString const &, css::uno::Any const &) override
virtual css::uno::Any SAL_CALL getPropertyValue(OUString const &PropertyName) override
virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::beans::Optional< css::uno::Any > valueFtpProxyName_
css::beans::Optional< css::uno::Any > valueNoProxy_
virtual sal_Bool SAL_CALL supportsService(const OUString &aServiceName) override
virtual OUString SAL_CALL getImplementationName() override
css::beans::Optional< css::uno::Any > valueHttpProxyPort_
css::beans::Optional< css::uno::Any > valueHttpProxyName_
css::beans::Optional< css::uno::Any > valueHttpsProxyName_
css::beans::Optional< css::uno::Any > valueProxyType_
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
const wchar_t *typedef BOOL
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * shell_WinInetBackend_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)