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: kde4inetlayer.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"
34 #include <kprotocolmanager.h>
36 #include "kde4inetlayer.hxx"
37 #include <com/sun/star/configuration/backend/PropertyInfo.hpp>
38 #include <com/sun/star/configuration/backend/XLayerContentDescriber.hpp>
39 #include <com/sun/star/uno/Sequence.hxx>
42 #define SEMI_COLON ';'
44 //==============================================================================
46 KDEInetLayer::KDEInetLayer(const uno::Reference
<uno::XComponentContext
>& xContext
)
48 //Create instance of LayerContentDescriber Service
49 rtl::OUString
const k_sLayerDescriberService(RTL_CONSTASCII_USTRINGPARAM(
50 "com.sun.star.comp.configuration.backend.LayerDescriber"));
52 typedef uno::Reference
<backend::XLayerContentDescriber
> LayerDescriber
;
53 uno::Reference
< lang::XMultiComponentFactory
> xServiceManager
= xContext
->getServiceManager();
54 if( xServiceManager
.is() )
56 m_xLayerContentDescriber
= LayerDescriber::query(
57 xServiceManager
->createInstanceWithContext(k_sLayerDescriberService
, xContext
));
61 OSL_TRACE("Could not retrieve ServiceManager");
65 //------------------------------------------------------------------------------
67 void SAL_CALL
KDEInetLayer::readData( const uno::Reference
<backend::XLayerHandler
>& xHandler
)
68 throw ( backend::MalformedDataException
, lang::NullPointerException
,
69 lang::WrappedTargetException
, uno::RuntimeException
)
71 if( ! m_xLayerContentDescriber
.is() )
73 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
74 "Could not create com.sun.star.configuration.backend.LayerContentDescriber Service"
75 ) ), static_cast < backend::XLayer
* > (this) );
78 uno::Sequence
<backend::PropertyInfo
> aPropInfoList(8);
79 sal_Int32 nProperties
= 0;
81 switch ( KProtocolManager::proxyType() )
83 case KProtocolManager::ManualProxy
: // Proxies are manually configured
84 setProxy(aPropInfoList
, nProperties
, 1,
85 KProtocolManager::noProxyFor(),
86 KProtocolManager::proxyFor( "HTTP" ),
87 KProtocolManager::proxyFor( "FTP" ),
88 KProtocolManager::proxyFor( "HTTPS" ));
90 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
91 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
92 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
93 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
94 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
95 // The best we can do here is to ask the current value for a given address.
96 setProxy(aPropInfoList
, nProperties
, 1,
97 KProtocolManager::noProxyFor(),
98 KProtocolManager::proxyForUrl( KUrl("http://www.openoffice.org") ),
99 KProtocolManager::proxyForUrl( KUrl("ftp://ftp.openoffice.org") ),
100 KProtocolManager::proxyForUrl( KUrl("https://www.openoffice.org") ));
102 default: // No proxy is used
103 setProxy(aPropInfoList
, nProperties
, 0);
106 if ( nProperties
> 0 )
108 aPropInfoList
.realloc(nProperties
);
109 m_xLayerContentDescriber
->describeLayer(xHandler
, aPropInfoList
);
113 //------------------------------------------------------------------------------
115 rtl::OUString SAL_CALL
KDEInetLayer::getTimestamp(void)
116 throw (uno::RuntimeException
)
118 // Return the value as timestamp to avoid regenerating the binary cache
119 // on each office launch.
121 QString aProxyType
, aNoProxyFor
, aHTTPProxy
, aHTTPSProxy
, aFTPProxy
;
123 switch ( KProtocolManager::proxyType() )
125 case KProtocolManager::ManualProxy
:
127 aNoProxyFor
= KProtocolManager::noProxyFor();
128 aHTTPProxy
= KProtocolManager::proxyFor( "HTTP" );
129 aHTTPProxy
= KProtocolManager::proxyFor( "HTTPS" );
130 aFTPProxy
= KProtocolManager::proxyFor( "FTP" );
132 case KProtocolManager::PACProxy
:
133 case KProtocolManager::WPADProxy
:
134 case KProtocolManager::EnvVarProxy
:
136 aNoProxyFor
= KProtocolManager::noProxyFor();
137 aHTTPProxy
= KProtocolManager::proxyForUrl( KUrl("http://www.openoffice.org") );
138 aHTTPSProxy
= KProtocolManager::proxyForUrl( KUrl("https://www.openoffice.org") );
139 aFTPProxy
= KProtocolManager::proxyForUrl( KUrl("ftp://ftp.openoffice.org") );
145 ::rtl::OUString sTimeStamp
,
146 sep( RTL_CONSTASCII_USTRINGPARAM( "$" ) );
148 sTimeStamp
= (const sal_Unicode
*) aProxyType
.utf16();
150 sTimeStamp
+= (const sal_Unicode
*) aNoProxyFor
.utf16();
152 sTimeStamp
+= (const sal_Unicode
*) aHTTPProxy
.utf16();
154 sTimeStamp
+= (const sal_Unicode
*) aHTTPSProxy
.utf16();
156 sTimeStamp
+= (const sal_Unicode
*) aFTPProxy
.utf16();
161 //------------------------------------------------------------------------------
163 void SAL_CALL
KDEInetLayer::setProxy
164 (uno::Sequence
<backend::PropertyInfo
> &aPropInfoList
, sal_Int32
&nProperties
,
165 int nProxyType
, const QString
&aNoProxy
, const QString
&aHTTPProxy
, const QString
&aFTPProxy
, const QString
&aHTTPSProxy
) const
167 aPropInfoList
[nProperties
].Name
= rtl::OUString(
168 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetProxyType") );
169 aPropInfoList
[nProperties
].Type
= rtl::OUString(
170 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
171 aPropInfoList
[nProperties
].Protected
= sal_False
;
172 aPropInfoList
[nProperties
++].Value
= uno::makeAny( (sal_Int32
) nProxyType
);
174 if (nProxyType
== 0) return;
176 if ( !aNoProxy
.isEmpty() )
178 QString
aNoProxyFor(aNoProxy
);
179 ::rtl::OUString sNoProxyFor
;
181 aNoProxyFor
= aNoProxyFor
.replace( COMMA
, SEMI_COLON
);
182 sNoProxyFor
= (const sal_Unicode
*) aNoProxyFor
.utf16();
184 aPropInfoList
[nProperties
].Name
= rtl::OUString(
185 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetNoProxy") );
186 aPropInfoList
[nProperties
].Type
= rtl::OUString(
187 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
188 aPropInfoList
[nProperties
].Protected
= sal_False
;
189 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sNoProxyFor
);
192 if ( !aHTTPProxy
.isEmpty() )
194 KUrl
aProxy(aHTTPProxy
);
195 ::rtl::OUString sProxy
= (const sal_Unicode
*) aProxy
.host().utf16();
196 sal_Int32 nPort
= aProxy
.port();
198 aPropInfoList
[nProperties
].Name
= rtl::OUString(
199 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPProxyName") );
200 aPropInfoList
[nProperties
].Type
= rtl::OUString(
201 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
202 aPropInfoList
[nProperties
].Protected
= sal_False
;
203 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sProxy
);
205 aPropInfoList
[nProperties
].Name
= rtl::OUString(
206 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPProxyPort") );
207 aPropInfoList
[nProperties
].Type
= rtl::OUString(
208 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
209 aPropInfoList
[nProperties
].Protected
= sal_False
;
210 aPropInfoList
[nProperties
++].Value
= uno::makeAny( nPort
);
213 if ( !aHTTPSProxy
.isEmpty() )
215 KUrl
aProxy(aHTTPSProxy
);
216 ::rtl::OUString sProxy
= (const sal_Unicode
*) aProxy
.host().utf16();
217 sal_Int32 nPort
= aProxy
.port();
219 aPropInfoList
[nProperties
].Name
= rtl::OUString(
220 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPSProxyName") );
221 aPropInfoList
[nProperties
].Type
= rtl::OUString(
222 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
223 aPropInfoList
[nProperties
].Protected
= sal_False
;
224 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sProxy
);
226 aPropInfoList
[nProperties
].Name
= rtl::OUString(
227 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetHTTPSProxyPort") );
228 aPropInfoList
[nProperties
].Type
= rtl::OUString(
229 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
230 aPropInfoList
[nProperties
].Protected
= sal_False
;
231 aPropInfoList
[nProperties
++].Value
= uno::makeAny( nPort
);
234 if ( !aFTPProxy
.isEmpty() )
236 KUrl
aProxy(aFTPProxy
);
237 ::rtl::OUString sProxy
= (const sal_Unicode
*) aProxy
.host().utf16();
238 sal_Int32 nPort
= aProxy
.port();
240 aPropInfoList
[nProperties
].Name
= rtl::OUString(
241 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetFTPProxyName") );
242 aPropInfoList
[nProperties
].Type
= rtl::OUString(
243 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
244 aPropInfoList
[nProperties
].Protected
= sal_False
;
245 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sProxy
);
247 aPropInfoList
[nProperties
].Name
= rtl::OUString(
248 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings/ooInetFTPProxyPort") );
249 aPropInfoList
[nProperties
].Type
= rtl::OUString(
250 RTL_CONSTASCII_USTRINGPARAM( "int" ) );
251 aPropInfoList
[nProperties
].Protected
= sal_False
;
252 aPropInfoList
[nProperties
++].Value
= uno::makeAny( nPort
);