xref: /trunk/main/unotools/source/config/extendedsecurityoptions.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_unotools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32*cdf0e10cSrcweir //  includes
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <unotools/extendedsecurityoptions.hxx>
36*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
37*cdf0e10cSrcweir #include <unotools/configitem.hxx>
38*cdf0e10cSrcweir #include <tools/debug.hxx>
39*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
40*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
41*cdf0e10cSrcweir #include <tools/urlobj.hxx>
42*cdf0e10cSrcweir #include <tools/wldcrd.hxx>
43*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <hash_map>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <rtl/logfile.hxx>
50*cdf0e10cSrcweir #include "itemholder1.hxx"
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53*cdf0e10cSrcweir //  namespaces
54*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::utl                   ;
57*cdf0e10cSrcweir using namespace ::rtl                   ;
58*cdf0e10cSrcweir using namespace ::osl                   ;
59*cdf0e10cSrcweir using namespace ::com::sun::star::uno   ;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62*cdf0e10cSrcweir //  const
63*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #define ROOTNODE_SECURITY               OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Security"))
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir #define SECURE_EXTENSIONS_SET           OUString(RTL_CONSTASCII_USTRINGPARAM("SecureExtensions"))
68*cdf0e10cSrcweir #define EXTENSION_PROPNAME              OUString(RTL_CONSTASCII_USTRINGPARAM("/Extension"))
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir #define PROPERTYNAME_HYPERLINKS_OPEN    OUString(RTL_CONSTASCII_USTRINGPARAM("Hyperlinks/Open"))
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir #define PROPERTYHANDLE_HYPERLINKS_OPEN  0
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir #define PROPERTYCOUNT                   1
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
77*cdf0e10cSrcweir //  private declarations!
78*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir struct OUStringHashCode
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     size_t operator()( const ::rtl::OUString& sString ) const
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         return sString.hashCode();
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir class ExtensionHashMap : public ::std::hash_map< ::rtl::OUString,
89*cdf0e10cSrcweir                                                  sal_Int32,
90*cdf0e10cSrcweir                                                  OUStringHashCode,
91*cdf0e10cSrcweir                                                  ::std::equal_to< ::rtl::OUString > >
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     public:
94*cdf0e10cSrcweir         inline void free()
95*cdf0e10cSrcweir         {
96*cdf0e10cSrcweir             ExtensionHashMap().swap( *this );
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir };
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir class SvtExtendedSecurityOptions_Impl : public ConfigItem
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir     //-------------------------------------------------------------------------------------------------------------
103*cdf0e10cSrcweir     //  public methods
104*cdf0e10cSrcweir     //-------------------------------------------------------------------------------------------------------------
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     public:
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
109*cdf0e10cSrcweir         //  constructor / destructor
110*cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir          SvtExtendedSecurityOptions_Impl();
113*cdf0e10cSrcweir         ~SvtExtendedSecurityOptions_Impl();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
116*cdf0e10cSrcweir         //  overloaded methods of baseclass
117*cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         /*-****************************************************************************************************//**
120*cdf0e10cSrcweir             @short      called for notify of configmanager
121*cdf0e10cSrcweir             @descr      These method is called from the ConfigManager before application ends or from the
122*cdf0e10cSrcweir                         PropertyChangeListener if the sub tree broadcasts changes. You must update your
123*cdf0e10cSrcweir                         internal values.
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir             @seealso    baseclass ConfigItem
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir             @param      "seqPropertyNames" is the list of properties which should be updated.
128*cdf0e10cSrcweir             @return     -
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir             @onerror    -
131*cdf0e10cSrcweir         *//*-*****************************************************************************************************/
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         virtual void Notify( const Sequence< OUString >& seqPropertyNames );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         /*-****************************************************************************************************//**
136*cdf0e10cSrcweir             @short      write changes to configuration
137*cdf0e10cSrcweir             @descr      These method writes the changed values into the sub tree
138*cdf0e10cSrcweir                         and should always called in our destructor to guarantee consistency of config data.
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir             @seealso    baseclass ConfigItem
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir             @param      -
143*cdf0e10cSrcweir             @return     -
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir             @onerror    -
146*cdf0e10cSrcweir         *//*-*****************************************************************************************************/
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         virtual void Commit();
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
151*cdf0e10cSrcweir         //  public interface
152*cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         /*-****************************************************************************************************//**
155*cdf0e10cSrcweir             @short      Access method to check for security problems
156*cdf0e10cSrcweir             @descr      Different methods to check for security related problems.
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir             @seealso    -
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir             @param      -
161*cdf0e10cSrcweir             @return     -
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir             @onerror    -
164*cdf0e10cSrcweir         *//*-*****************************************************************************************************/
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         sal_Bool                                        IsSecureHyperlink( const rtl::OUString& aURL ) const;
167*cdf0e10cSrcweir         Sequence< rtl::OUString >                       GetSecureExtensionList() const;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         SvtExtendedSecurityOptions::OpenHyperlinkMode   GetOpenHyperlinkMode();
170*cdf0e10cSrcweir         void                                            SetOpenHyperlinkMode( SvtExtendedSecurityOptions::OpenHyperlinkMode aMode );
171*cdf0e10cSrcweir         sal_Bool                                        IsOpenHyperlinkModeReadOnly() const;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     //-------------------------------------------------------------------------------------------------------------
174*cdf0e10cSrcweir     //  private methods
175*cdf0e10cSrcweir     //-------------------------------------------------------------------------------------------------------------
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     private:
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         /*-****************************************************************************************************//**
180*cdf0e10cSrcweir             @short      return list of key names of ouer configuration management which represent oue module tree
181*cdf0e10cSrcweir             @descr      These methods return a static const list of key names. We need it to get needed values from our
182*cdf0e10cSrcweir                         configuration management.
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir             @seealso    -
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir             @param      -
187*cdf0e10cSrcweir             @return     A list of needed configuration keys is returned.
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir             @onerror    -
190*cdf0e10cSrcweir         *//*-*****************************************************************************************************/
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir         static Sequence< OUString > GetPropertyNames();
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         /*-****************************************************************************************************//**
195*cdf0e10cSrcweir             @short      Fills the hash map with all extensions known to be secure
196*cdf0e10cSrcweir             @descr      These methods fills the given hash map object with all extensions known to be secure.
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir             @seealso    -
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir             @param      aHashMap
201*cdf0e10cSrcweir                         A hash map to be filled with secure extension strings.
202*cdf0e10cSrcweir             @return     -
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir             @onerror    -
205*cdf0e10cSrcweir         *//*-*****************************************************************************************************/
206*cdf0e10cSrcweir         void FillExtensionHashMap( ExtensionHashMap& aHashMap );
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     //-------------------------------------------------------------------------------------------------------------
209*cdf0e10cSrcweir     //  private member
210*cdf0e10cSrcweir     //-------------------------------------------------------------------------------------------------------------
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     private:
213*cdf0e10cSrcweir         OUString                                        m_aSecureExtensionsSetName;
214*cdf0e10cSrcweir         OUString                                        m_aExtensionPropName;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir         SvtExtendedSecurityOptions::OpenHyperlinkMode   m_eOpenHyperlinkMode;
217*cdf0e10cSrcweir         sal_Bool                                        m_bROOpenHyperlinkMode;
218*cdf0e10cSrcweir         ExtensionHashMap                                m_aExtensionHashMap;
219*cdf0e10cSrcweir };
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
222*cdf0e10cSrcweir //  definitions
223*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir //*****************************************************************************************************************
226*cdf0e10cSrcweir //  constructor
227*cdf0e10cSrcweir //*****************************************************************************************************************
228*cdf0e10cSrcweir SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl()
229*cdf0e10cSrcweir     // Init baseclasses first
230*cdf0e10cSrcweir     :   ConfigItem          ( ROOTNODE_SECURITY         ),
231*cdf0e10cSrcweir     m_aSecureExtensionsSetName( SECURE_EXTENSIONS_SET ),
232*cdf0e10cSrcweir     m_aExtensionPropName( EXTENSION_PROPNAME ),
233*cdf0e10cSrcweir     m_bROOpenHyperlinkMode(sal_False)
234*cdf0e10cSrcweir     // Init member then.
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     // Fill the extension hash map with all secure extension strings
237*cdf0e10cSrcweir     FillExtensionHashMap( m_aExtensionHashMap );
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     Sequence< OUString >    seqNames    = GetPropertyNames();
240*cdf0e10cSrcweir     Sequence< Any >         seqValues   = GetProperties( seqNames );
241*cdf0e10cSrcweir     Sequence< sal_Bool >    seqRO       = GetReadOnlyStates ( seqNames  );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     sal_Int32 nPropertyCount = seqValues.getLength();
244*cdf0e10cSrcweir     for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         // Safe impossible cases.
247*cdf0e10cSrcweir         // Check any for valid value.
248*cdf0e10cSrcweir         DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl()\nInvalid property value detected!\n" );
249*cdf0e10cSrcweir         switch( nProperty )
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir             case PROPERTYHANDLE_HYPERLINKS_OPEN:
252*cdf0e10cSrcweir             {
253*cdf0e10cSrcweir                 DBG_ASSERT( ( seqValues[nProperty].getValueTypeClass() == TypeClass_LONG ), "SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl()\nWho has changed the value type of 'Hyperlink/Open'?" );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir                 sal_Int32 nMode = SvtExtendedSecurityOptions::OPEN_WITHSECURITYCHECK;
256*cdf0e10cSrcweir                 if ( seqValues[nProperty] >>= nMode )
257*cdf0e10cSrcweir                     m_eOpenHyperlinkMode = (SvtExtendedSecurityOptions::OpenHyperlinkMode)nMode;
258*cdf0e10cSrcweir                 else {
259*cdf0e10cSrcweir                     DBG_ERROR("Wrong type for Open mode!");
260*cdf0e10cSrcweir                 }
261*cdf0e10cSrcweir                 m_bROOpenHyperlinkMode = seqRO[nProperty];
262*cdf0e10cSrcweir             }
263*cdf0e10cSrcweir             break;
264*cdf0e10cSrcweir         }
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     // Enable notification mechanism of our baseclass.
268*cdf0e10cSrcweir     // We need it to get information about changes outside these class on ouer used configuration keys!
269*cdf0e10cSrcweir     Sequence< OUString > seqNotifyNames( 1 );
270*cdf0e10cSrcweir     seqNotifyNames[0] = m_aSecureExtensionsSetName;
271*cdf0e10cSrcweir     EnableNotification( seqNotifyNames );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir //*****************************************************************************************************************
275*cdf0e10cSrcweir //  destructor
276*cdf0e10cSrcweir //*****************************************************************************************************************
277*cdf0e10cSrcweir SvtExtendedSecurityOptions_Impl::~SvtExtendedSecurityOptions_Impl()
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir     // We must save our current values .. if user forget it!
280*cdf0e10cSrcweir     if( IsModified() == sal_True )
281*cdf0e10cSrcweir     {
282*cdf0e10cSrcweir         Commit();
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir //*****************************************************************************************************************
287*cdf0e10cSrcweir //  public method
288*cdf0e10cSrcweir //*****************************************************************************************************************
289*cdf0e10cSrcweir void SvtExtendedSecurityOptions_Impl::Notify( const Sequence< OUString >& )
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     // Not implemented
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir //*****************************************************************************************************************
295*cdf0e10cSrcweir //  public method
296*cdf0e10cSrcweir //*****************************************************************************************************************
297*cdf0e10cSrcweir void SvtExtendedSecurityOptions_Impl::Commit()
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir     // Get names of supported properties, create a list for values and copy current values to it.
300*cdf0e10cSrcweir     Sequence< OUString >    seqNames    = GetPropertyNames  ();
301*cdf0e10cSrcweir     sal_Int32               nCount      = seqNames.getLength();
302*cdf0e10cSrcweir     Sequence< Any >         seqValues   ( nCount );
303*cdf0e10cSrcweir     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
304*cdf0e10cSrcweir     {
305*cdf0e10cSrcweir         switch( nProperty )
306*cdf0e10cSrcweir         {
307*cdf0e10cSrcweir             case PROPERTYHANDLE_HYPERLINKS_OPEN:    {
308*cdf0e10cSrcweir                                                         seqValues[nProperty] <<= (sal_Int32)m_eOpenHyperlinkMode;
309*cdf0e10cSrcweir                                                     }
310*cdf0e10cSrcweir                                                     break;
311*cdf0e10cSrcweir         }
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir     // Set properties in configuration.
315*cdf0e10cSrcweir     PutProperties( seqNames, seqValues );
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir //*****************************************************************************************************************
319*cdf0e10cSrcweir //  public method
320*cdf0e10cSrcweir //*****************************************************************************************************************
321*cdf0e10cSrcweir sal_Bool SvtExtendedSecurityOptions_Impl::IsSecureHyperlink( const OUString& aURL ) const
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir     INetURLObject aURLObject( aURL );
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     String aExtension = aURLObject.getExtension();
326*cdf0e10cSrcweir     aExtension.ToLowerAscii();
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     ExtensionHashMap::const_iterator pIter = m_aExtensionHashMap.find( aExtension );
329*cdf0e10cSrcweir     if ( pIter != m_aExtensionHashMap.end() )
330*cdf0e10cSrcweir         return sal_True;
331*cdf0e10cSrcweir     else
332*cdf0e10cSrcweir         return sal_False;
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir //*****************************************************************************************************************
336*cdf0e10cSrcweir //  public method
337*cdf0e10cSrcweir //*****************************************************************************************************************
338*cdf0e10cSrcweir Sequence< OUString > SvtExtendedSecurityOptions_Impl::GetSecureExtensionList() const
339*cdf0e10cSrcweir {
340*cdf0e10cSrcweir     Sequence< OUString > aResult( m_aExtensionHashMap.size() );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir     sal_Int32 nIndex = 0;
343*cdf0e10cSrcweir     for ( ExtensionHashMap::const_iterator pIter = m_aExtensionHashMap.begin();
344*cdf0e10cSrcweir             pIter != m_aExtensionHashMap.end(); pIter++ )
345*cdf0e10cSrcweir     {
346*cdf0e10cSrcweir         aResult[nIndex++] = pIter->first;
347*cdf0e10cSrcweir     }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir     return aResult;
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir //*****************************************************************************************************************
353*cdf0e10cSrcweir //  public method
354*cdf0e10cSrcweir //*****************************************************************************************************************
355*cdf0e10cSrcweir SvtExtendedSecurityOptions::OpenHyperlinkMode SvtExtendedSecurityOptions_Impl::GetOpenHyperlinkMode()
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir     return m_eOpenHyperlinkMode;
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir /* -----------------09.07.2003 11:26-----------------
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir  --------------------------------------------------*/
362*cdf0e10cSrcweir sal_Bool SvtExtendedSecurityOptions_Impl::IsOpenHyperlinkModeReadOnly() const
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir     return m_bROOpenHyperlinkMode;
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir //*****************************************************************************************************************
368*cdf0e10cSrcweir //  public method
369*cdf0e10cSrcweir //*****************************************************************************************************************
370*cdf0e10cSrcweir void SvtExtendedSecurityOptions_Impl::SetOpenHyperlinkMode( SvtExtendedSecurityOptions::OpenHyperlinkMode eNewMode )
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir     m_eOpenHyperlinkMode = eNewMode;
373*cdf0e10cSrcweir     SetModified();
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir //*****************************************************************************************************************
377*cdf0e10cSrcweir //  private method
378*cdf0e10cSrcweir //*****************************************************************************************************************
379*cdf0e10cSrcweir void SvtExtendedSecurityOptions_Impl::FillExtensionHashMap( ExtensionHashMap& aHashMap )
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir     // Get sequence with secure extensions from configuration
382*cdf0e10cSrcweir     Sequence< OUString >    seqNodes = GetNodeNames( m_aSecureExtensionsSetName );
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir     OUString                aValue;
385*cdf0e10cSrcweir     Sequence< Any >         aValues;
386*cdf0e10cSrcweir     Sequence< OUString >    aPropSeq( 1 );
387*cdf0e10cSrcweir     for ( int i = 0; i < seqNodes.getLength(); i++ )
388*cdf0e10cSrcweir     {
389*cdf0e10cSrcweir         // Create access name for property
390*cdf0e10cSrcweir         OUStringBuffer aExtEntryProp( m_aSecureExtensionsSetName );
391*cdf0e10cSrcweir         aExtEntryProp.appendAscii( "/" );
392*cdf0e10cSrcweir         aExtEntryProp.append( seqNodes[i] );
393*cdf0e10cSrcweir         aExtEntryProp.append( m_aExtensionPropName );
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         aPropSeq[0] = aExtEntryProp.makeStringAndClear();
396*cdf0e10cSrcweir         aValues = GetProperties( aPropSeq );
397*cdf0e10cSrcweir         if ( aValues.getLength() == 1 )
398*cdf0e10cSrcweir         {
399*cdf0e10cSrcweir             // Don't use value if sequence has not the correct length
400*cdf0e10cSrcweir             if ( aValues[0] >>= aValue )
401*cdf0e10cSrcweir                 // Add extension into secure extensions hash map
402*cdf0e10cSrcweir                 aHashMap.insert( ExtensionHashMap::value_type( aValue.toAsciiLowerCase(), 1 ) );
403*cdf0e10cSrcweir             else
404*cdf0e10cSrcweir             {
405*cdf0e10cSrcweir                 DBG_ERRORFILE( "SvtExtendedSecurityOptions_Impl::FillExtensionHashMap(): not string value?" );
406*cdf0e10cSrcweir             }
407*cdf0e10cSrcweir         }
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir //*****************************************************************************************************************
412*cdf0e10cSrcweir //  private method (currently not used)
413*cdf0e10cSrcweir //*****************************************************************************************************************
414*cdf0e10cSrcweir Sequence< OUString > SvtExtendedSecurityOptions_Impl::GetPropertyNames()
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir     // Build static list of configuration key names.
417*cdf0e10cSrcweir     static const OUString pProperties[] =
418*cdf0e10cSrcweir     {
419*cdf0e10cSrcweir         PROPERTYNAME_HYPERLINKS_OPEN
420*cdf0e10cSrcweir     };
421*cdf0e10cSrcweir     // Initialize return sequence with these list ...
422*cdf0e10cSrcweir     static const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
423*cdf0e10cSrcweir     // ... and return it.
424*cdf0e10cSrcweir     return seqPropertyNames;
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir //*****************************************************************************************************************
428*cdf0e10cSrcweir //  initialize static member
429*cdf0e10cSrcweir //  DON'T DO IT IN YOUR HEADER!
430*cdf0e10cSrcweir //  see definition for further informations
431*cdf0e10cSrcweir //*****************************************************************************************************************
432*cdf0e10cSrcweir SvtExtendedSecurityOptions_Impl*    SvtExtendedSecurityOptions::m_pDataContainer    = NULL  ;
433*cdf0e10cSrcweir sal_Int32                           SvtExtendedSecurityOptions::m_nRefCount         = 0     ;
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir //*****************************************************************************************************************
436*cdf0e10cSrcweir //  constructor
437*cdf0e10cSrcweir //*****************************************************************************************************************
438*cdf0e10cSrcweir SvtExtendedSecurityOptions::SvtExtendedSecurityOptions()
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     // Global access, must be guarded (multithreading!).
441*cdf0e10cSrcweir     MutexGuard aGuard( GetInitMutex() );
442*cdf0e10cSrcweir     // Increase ouer refcount ...
443*cdf0e10cSrcweir     ++m_nRefCount;
444*cdf0e10cSrcweir     // ... and initialize ouer data container only if it not already exist!
445*cdf0e10cSrcweir     if( m_pDataContainer == NULL )
446*cdf0e10cSrcweir     {
447*cdf0e10cSrcweir        RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtExtendedSecurityOptions_Impl::ctor()");
448*cdf0e10cSrcweir        m_pDataContainer = new SvtExtendedSecurityOptions_Impl;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_EXTENDEDSECURITYOPTIONS);
451*cdf0e10cSrcweir     }
452*cdf0e10cSrcweir }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir //*****************************************************************************************************************
455*cdf0e10cSrcweir //  destructor
456*cdf0e10cSrcweir //*****************************************************************************************************************
457*cdf0e10cSrcweir SvtExtendedSecurityOptions::~SvtExtendedSecurityOptions()
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     // Global access, must be guarded (multithreading!)
460*cdf0e10cSrcweir     MutexGuard aGuard( GetInitMutex() );
461*cdf0e10cSrcweir     // Decrease ouer refcount.
462*cdf0e10cSrcweir     --m_nRefCount;
463*cdf0e10cSrcweir     // If last instance was deleted ...
464*cdf0e10cSrcweir     // we must destroy ouer static data container!
465*cdf0e10cSrcweir     if( m_nRefCount <= 0 )
466*cdf0e10cSrcweir     {
467*cdf0e10cSrcweir         delete m_pDataContainer;
468*cdf0e10cSrcweir         m_pDataContainer = NULL;
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir //*****************************************************************************************************************
473*cdf0e10cSrcweir //  public method
474*cdf0e10cSrcweir //*****************************************************************************************************************
475*cdf0e10cSrcweir sal_Bool SvtExtendedSecurityOptions::IsSecureHyperlink( const rtl::OUString& aURL ) const
476*cdf0e10cSrcweir {
477*cdf0e10cSrcweir     MutexGuard aGuard( GetInitMutex() );
478*cdf0e10cSrcweir     return m_pDataContainer->IsSecureHyperlink( aURL );
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir //*****************************************************************************************************************
482*cdf0e10cSrcweir //  public method
483*cdf0e10cSrcweir //*****************************************************************************************************************
484*cdf0e10cSrcweir Sequence< rtl::OUString > SvtExtendedSecurityOptions::GetSecureExtensionList() const
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir     MutexGuard aGuard( GetInitMutex() );
487*cdf0e10cSrcweir     return m_pDataContainer->GetSecureExtensionList();
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir //*****************************************************************************************************************
491*cdf0e10cSrcweir //  public method
492*cdf0e10cSrcweir //*****************************************************************************************************************
493*cdf0e10cSrcweir SvtExtendedSecurityOptions::OpenHyperlinkMode SvtExtendedSecurityOptions::GetOpenHyperlinkMode()
494*cdf0e10cSrcweir {
495*cdf0e10cSrcweir     MutexGuard aGuard( GetInitMutex() );
496*cdf0e10cSrcweir     return m_pDataContainer->GetOpenHyperlinkMode();
497*cdf0e10cSrcweir }
498*cdf0e10cSrcweir /* -----------------09.07.2003 11:26-----------------
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir  --------------------------------------------------*/
501*cdf0e10cSrcweir sal_Bool SvtExtendedSecurityOptions::IsOpenHyperlinkModeReadOnly() const
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     return m_pDataContainer->IsOpenHyperlinkModeReadOnly();
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir //*****************************************************************************************************************
507*cdf0e10cSrcweir //  public method
508*cdf0e10cSrcweir //*****************************************************************************************************************
509*cdf0e10cSrcweir void SvtExtendedSecurityOptions::SetOpenHyperlinkMode( SvtExtendedSecurityOptions::OpenHyperlinkMode eMode )
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir     MutexGuard aGuard( GetInitMutex() );
512*cdf0e10cSrcweir     m_pDataContainer->SetOpenHyperlinkMode( eMode );
513*cdf0e10cSrcweir }
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir //*****************************************************************************************************************
516*cdf0e10cSrcweir //  private method
517*cdf0e10cSrcweir //*****************************************************************************************************************
518*cdf0e10cSrcweir Mutex& SvtExtendedSecurityOptions::GetInitMutex()
519*cdf0e10cSrcweir {
520*cdf0e10cSrcweir     // Initialize static mutex only for one time!
521*cdf0e10cSrcweir     static Mutex* pMutex = NULL;
522*cdf0e10cSrcweir     // If these method first called (Mutex not already exist!) ...
523*cdf0e10cSrcweir     if( pMutex == NULL )
524*cdf0e10cSrcweir     {
525*cdf0e10cSrcweir         // ... we must create a new one. Protect follow code with the global mutex -
526*cdf0e10cSrcweir         // It must be - we create a static variable!
527*cdf0e10cSrcweir         MutexGuard aGuard( Mutex::getGlobalMutex() );
528*cdf0e10cSrcweir         // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
529*cdf0e10cSrcweir         if( pMutex == NULL )
530*cdf0e10cSrcweir         {
531*cdf0e10cSrcweir             // Create the new mutex and set it for return on static variable.
532*cdf0e10cSrcweir             static Mutex aMutex;
533*cdf0e10cSrcweir             pMutex = &aMutex;
534*cdf0e10cSrcweir         }
535*cdf0e10cSrcweir     }
536*cdf0e10cSrcweir     // Return new created or already existing mutex object.
537*cdf0e10cSrcweir     return *pMutex;
538*cdf0e10cSrcweir }
539