1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: kdeinetlayer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
33 #include "kdeinetlayer.hxx"
34 #include <com/sun/star/configuration/backend/PropertyInfo.hpp>
35 #ifndef _COM_SUN_STAR_CONFIGURATION_BACKEND_XLAYERCONTENTDESCIBER_HPP_
36 #include <com/sun/star/configuration/backend/XLayerContentDescriber.hpp>
38 #include <com/sun/star/uno/Sequence.hxx>
41 #define SEMI_COLON ';'
43 //==============================================================================
45 KDEInetLayer::KDEInetLayer(const uno::Reference
<uno::XComponentContext
>& xContext
)
47 //Create instance of LayerContentDescriber Service
48 rtl::OUString
const k_sLayerDescriberService(RTL_CONSTASCII_USTRINGPARAM(
49 "com.sun.star.comp.configuration.backend.LayerDescriber"));
51 typedef uno::Reference
<backend::XLayerContentDescriber
> LayerDescriber
;
52 uno::Reference
< lang::XMultiComponentFactory
> xServiceManager
= xContext
->getServiceManager();
53 if( xServiceManager
.is() )
55 m_xLayerContentDescriber
= LayerDescriber::query(
56 xServiceManager
->createInstanceWithContext(k_sLayerDescriberService
, xContext
));
60 OSL_TRACE("Could not retrieve ServiceManager");
64 //------------------------------------------------------------------------------
66 void SAL_CALL
KDEInetLayer::readData( const uno::Reference
<backend::XLayerHandler
>& xHandler
)
67 throw ( backend::MalformedDataException
, lang::NullPointerException
,
68 lang::WrappedTargetException
, uno::RuntimeException
)
70 if( ! m_xLayerContentDescriber
.is() )
72 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
73 "Could not create com.sun.star.configuration.backend.LayerContentDescriber Service"
74 ) ), static_cast < backend::XLayer
* > (this) );
77 uno::Sequence
<backend::PropertyInfo
> aPropInfoList(8);
78 sal_Int32 nProperties
= 0;
80 switch ( KProtocolManager::proxyType() )
82 case KProtocolManager::ManualProxy
: // Proxies are manually configured
83 setProxy(aPropInfoList
, nProperties
, 1,
84 KProtocolManager::noProxyFor(),
85 KProtocolManager::proxyFor( "HTTP" ),
86 KProtocolManager::proxyFor( "FTP" ),
87 KProtocolManager::proxyFor( "HTTPS" ));
89 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
90 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
91 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
92 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
93 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
94 // The best we can do here is to ask the current value for a given address.
95 setProxy(aPropInfoList
, nProperties
, 1,
96 KProtocolManager::noProxyFor(),
97 KProtocolManager::proxyForURL( "http://www.openoffice.org" ),
98 KProtocolManager::proxyForURL( "ftp://ftp.openoffice.org" ),
99 KProtocolManager::proxyForURL( "https://www.openoffice.org" ));
101 default: // No proxy is used
102 setProxy(aPropInfoList
, nProperties
, 0);
105 if ( nProperties
> 0 )
107 aPropInfoList
.realloc(nProperties
);
108 m_xLayerContentDescriber
->describeLayer(xHandler
, aPropInfoList
);
112 //------------------------------------------------------------------------------
114 rtl::OUString SAL_CALL
KDEInetLayer::getTimestamp(void)
115 throw (uno::RuntimeException
)
117 // Return the value as timestamp to avoid regenerating the binary cache
118 // on each office launch.
120 QString aProxyType
, aNoProxyFor
, aHTTPProxy
, aHTTPSProxy
, aFTPProxy
;
122 switch ( KProtocolManager::proxyType() )
124 case KProtocolManager::ManualProxy
:
126 aNoProxyFor
= KProtocolManager::noProxyFor();
127 aHTTPProxy
= KProtocolManager::proxyFor( "HTTP" );
128 aHTTPProxy
= KProtocolManager::proxyFor( "HTTPS" );
129 aFTPProxy
= KProtocolManager::proxyFor( "FTP" );
131 case KProtocolManager::PACProxy
:
132 case KProtocolManager::WPADProxy
:
133 case KProtocolManager::EnvVarProxy
:
135 aNoProxyFor
= KProtocolManager::noProxyFor();
136 aHTTPProxy
= KProtocolManager::proxyForURL( "http://www.openoffice.org" );
137 aHTTPSProxy
= KProtocolManager::proxyForURL( "https://www.openoffice.org" );
138 aFTPProxy
= KProtocolManager::proxyForURL( "ftp://ftp.openoffice.org" );
144 ::rtl::OUString sTimeStamp
,
145 sep( RTL_CONSTASCII_USTRINGPARAM( "$" ) );
147 sTimeStamp
= (const sal_Unicode
*) aProxyType
.ucs2();
149 sTimeStamp
+= (const sal_Unicode
*) aNoProxyFor
.ucs2();
151 sTimeStamp
+= (const sal_Unicode
*) aHTTPProxy
.ucs2();
153 sTimeStamp
+= (const sal_Unicode
*) aHTTPSProxy
.ucs2();
155 sTimeStamp
+= (const sal_Unicode
*) aFTPProxy
.ucs2();
160 //------------------------------------------------------------------------------
162 void SAL_CALL
KDEInetLayer::setProxy
163 (uno::Sequence
<backend::PropertyInfo
> &aPropInfoList
, sal_Int32
&nProperties
,
164 int nProxyType
, const QString
&aNoProxy
, const QString
&aHTTPProxy
, const QString
&aFTPProxy
, const QString
&aHTTPSProxy
) const
166 aPropInfoList
[nProperties
].Name
= rtl::OUString(
167 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetProxyType") );
168 aPropInfoList
[nProperties
].Type
= rtl::OUString(
169 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
170 aPropInfoList
[nProperties
].Protected
= sal_False
;
171 aPropInfoList
[nProperties
++].Value
= uno::makeAny( (sal_Int32
) nProxyType
);
173 if (nProxyType
== 0) return;
175 if ( !aNoProxy
.isEmpty() )
177 QString
aNoProxyFor(aNoProxy
);
178 ::rtl::OUString sNoProxyFor
;
180 aNoProxyFor
= aNoProxyFor
.replace( COMMA
, SEMI_COLON
);
181 sNoProxyFor
= (const sal_Unicode
*) aNoProxyFor
.ucs2();
183 aPropInfoList
[nProperties
].Name
= rtl::OUString(
184 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetNoProxy") );
185 aPropInfoList
[nProperties
].Type
= rtl::OUString(
186 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
187 aPropInfoList
[nProperties
].Protected
= sal_False
;
188 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sNoProxyFor
);
191 if ( !aHTTPProxy
.isEmpty() )
193 KURL
aProxy(aHTTPProxy
);
194 ::rtl::OUString sProxy
= (const sal_Unicode
*) aProxy
.host().ucs2();
195 sal_Int32 nPort
= aProxy
.port();
197 aPropInfoList
[nProperties
].Name
= rtl::OUString(
198 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPProxyName") );
199 aPropInfoList
[nProperties
].Type
= rtl::OUString(
200 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
201 aPropInfoList
[nProperties
].Protected
= sal_False
;
202 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sProxy
);
204 aPropInfoList
[nProperties
].Name
= rtl::OUString(
205 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPProxyPort") );
206 aPropInfoList
[nProperties
].Type
= rtl::OUString(
207 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
208 aPropInfoList
[nProperties
].Protected
= sal_False
;
209 aPropInfoList
[nProperties
++].Value
= uno::makeAny( nPort
);
212 if ( !aHTTPSProxy
.isEmpty() )
214 KURL
aProxy(aHTTPSProxy
);
215 ::rtl::OUString sProxy
= (const sal_Unicode
*) aProxy
.host().ucs2();
216 sal_Int32 nPort
= aProxy
.port();
218 aPropInfoList
[nProperties
].Name
= rtl::OUString(
219 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPSProxyName") );
220 aPropInfoList
[nProperties
].Type
= rtl::OUString(
221 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
222 aPropInfoList
[nProperties
].Protected
= sal_False
;
223 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sProxy
);
225 aPropInfoList
[nProperties
].Name
= rtl::OUString(
226 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPSProxyPort") );
227 aPropInfoList
[nProperties
].Type
= rtl::OUString(
228 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
229 aPropInfoList
[nProperties
].Protected
= sal_False
;
230 aPropInfoList
[nProperties
++].Value
= uno::makeAny( nPort
);
233 if ( !aFTPProxy
.isEmpty() )
235 KURL
aProxy(aFTPProxy
);
236 ::rtl::OUString sProxy
= (const sal_Unicode
*) aProxy
.host().ucs2();
237 sal_Int32 nPort
= aProxy
.port();
239 aPropInfoList
[nProperties
].Name
= rtl::OUString(
240 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetFTPProxyName") );
241 aPropInfoList
[nProperties
].Type
= rtl::OUString(
242 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
243 aPropInfoList
[nProperties
].Protected
= sal_False
;
244 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sProxy
);
246 aPropInfoList
[nProperties
].Name
= rtl::OUString(
247 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetFTPProxyPort") );
248 aPropInfoList
[nProperties
].Type
= rtl::OUString(
249 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
250 aPropInfoList
[nProperties
].Protected
= sal_False
;
251 aPropInfoList
[nProperties
++].Value
= uno::makeAny( nPort
);