LCOV - code coverage report
Current view: top level - unotools/source/config - extendedsecurityoptions.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 78 0.0 %
Date: 2014-04-11 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <unotools/extendedsecurityoptions.hxx>
      21             : #include <unotools/configmgr.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <rtl/ustrbuf.hxx>
      27             : 
      28             : #include <unotools/pathoptions.hxx>
      29             : 
      30             : #include <boost/unordered_map.hpp>
      31             : 
      32             : #include "itemholder1.hxx"
      33             : 
      34             : using namespace ::utl;
      35             : using namespace ::rtl;
      36             : using namespace ::osl;
      37             : using namespace ::com::sun::star::uno;
      38             : 
      39             : #define ROOTNODE_SECURITY               OUString("Office.Security")
      40             : 
      41             : #define SECURE_EXTENSIONS_SET           OUString("SecureExtensions")
      42             : #define EXTENSION_PROPNAME              OUString("/Extension")
      43             : 
      44             : #define PROPERTYNAME_HYPERLINKS_OPEN    OUString("Hyperlinks/Open")
      45             : 
      46             : #define PROPERTYHANDLE_HYPERLINKS_OPEN  0
      47             : 
      48             : #define PROPERTYCOUNT                   1
      49             : 
      50             : typedef boost::unordered_map<OUString, sal_Int32, OUStringHash>
      51             :     ExtensionHashMap;
      52             : 
      53             : class SvtExtendedSecurityOptions_Impl : public ConfigItem
      54             : {
      55             :     public:
      56             :          SvtExtendedSecurityOptions_Impl();
      57             :         virtual ~SvtExtendedSecurityOptions_Impl();
      58             : 
      59             :         /*-****************************************************************************************************
      60             :             @short      called for notify of configmanager
      61             :             @descr      These method is called from the ConfigManager before application ends or from the
      62             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
      63             :                         internal values.
      64             : 
      65             :             @seealso    baseclass ConfigItem
      66             : 
      67             :             @param      "seqPropertyNames" is the list of properties which should be updated.
      68             :         *//*-*****************************************************************************************************/
      69             : 
      70             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
      71             : 
      72             :         /*-****************************************************************************************************
      73             :             @short      write changes to configuration
      74             :             @descr      These method writes the changed values into the sub tree
      75             :                         and should always called in our destructor to guarantee consistency of config data.
      76             : 
      77             :             @seealso    baseclass ConfigItem
      78             :         *//*-*****************************************************************************************************/
      79             : 
      80             :         virtual void Commit() SAL_OVERRIDE;
      81             : 
      82             :         SvtExtendedSecurityOptions::OpenHyperlinkMode   GetOpenHyperlinkMode();
      83             :     private:
      84             : 
      85             :         /*-****************************************************************************************************
      86             :             @short      return list of key names of our configuration management which represent oue module tree
      87             :             @descr      These methods return a static const list of key names. We need it to get needed values from our
      88             :                         configuration management.
      89             :             @return     A list of needed configuration keys is returned.
      90             :         *//*-*****************************************************************************************************/
      91             : 
      92             :         static Sequence< OUString > GetPropertyNames();
      93             : 
      94             :         /*-****************************************************************************************************
      95             :             @short      Fills the hash map with all extensions known to be secure
      96             :             @descr      These methods fills the given hash map object with all extensions known to be secure.
      97             :             @param      aHashMap
      98             :                         A hash map to be filled with secure extension strings.
      99             :         *//*-*****************************************************************************************************/
     100             :         void FillExtensionHashMap( ExtensionHashMap& aHashMap );
     101             : 
     102             :         OUString                                        m_aSecureExtensionsSetName;
     103             :         OUString                                        m_aExtensionPropName;
     104             : 
     105             :         SvtExtendedSecurityOptions::OpenHyperlinkMode   m_eOpenHyperlinkMode;
     106             :         bool                                        m_bROOpenHyperlinkMode;
     107             :         ExtensionHashMap                                m_aExtensionHashMap;
     108             : };
     109             : 
     110             : //  constructor
     111             : 
     112           0 : SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl()
     113             :     // Init baseclasses first
     114             :     :   ConfigItem          ( ROOTNODE_SECURITY         )
     115             :     , m_aSecureExtensionsSetName( SECURE_EXTENSIONS_SET )
     116             :     , m_aExtensionPropName( EXTENSION_PROPNAME )
     117             :     , m_eOpenHyperlinkMode(SvtExtendedSecurityOptions::OPEN_NEVER)
     118           0 :     , m_bROOpenHyperlinkMode(false)
     119             :     // Init member then.
     120             : {
     121             :     // Fill the extension hash map with all secure extension strings
     122           0 :     FillExtensionHashMap( m_aExtensionHashMap );
     123             : 
     124           0 :     Sequence< OUString >    seqNames    = GetPropertyNames();
     125           0 :     Sequence< Any >         seqValues   = GetProperties( seqNames );
     126           0 :     Sequence< sal_Bool >    seqRO       = GetReadOnlyStates ( seqNames  );
     127             : 
     128           0 :     sal_Int32 nPropertyCount = seqValues.getLength();
     129           0 :     for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
     130             :     {
     131             :         // Safe impossible cases.
     132             :         // Check any for valid value.
     133             :         DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl()\nInvalid property value detected!\n" );
     134           0 :         switch( nProperty )
     135             :         {
     136             :             case PROPERTYHANDLE_HYPERLINKS_OPEN:
     137             :             {
     138             :                 DBG_ASSERT( ( seqValues[nProperty].getValueTypeClass() == TypeClass_LONG ), "SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl()\nWho has changed the value type of 'Hyperlink/Open'?" );
     139             : 
     140           0 :                 sal_Int32 nMode = SvtExtendedSecurityOptions::OPEN_WITHSECURITYCHECK;
     141           0 :                 if ( seqValues[nProperty] >>= nMode )
     142           0 :                     m_eOpenHyperlinkMode = (SvtExtendedSecurityOptions::OpenHyperlinkMode)nMode;
     143             :                 else {
     144             :                     OSL_FAIL("Wrong type for Open mode!");
     145             :                 }
     146           0 :                 m_bROOpenHyperlinkMode = seqRO[nProperty];
     147             :             }
     148           0 :             break;
     149             :         }
     150             :     }
     151             : 
     152             :     // Enable notification mechanism of our baseclass.
     153             :     // We need it to get information about changes outside these class on our used configuration keys!
     154           0 :     Sequence< OUString > seqNotifyNames( 1 );
     155           0 :     seqNotifyNames[0] = m_aSecureExtensionsSetName;
     156           0 :     EnableNotification( seqNotifyNames );
     157           0 : }
     158             : 
     159             : //  destructor
     160             : 
     161           0 : SvtExtendedSecurityOptions_Impl::~SvtExtendedSecurityOptions_Impl()
     162             : {
     163             :     // We must save our current values .. if user forget it!
     164           0 :     if( IsModified() )
     165             :     {
     166           0 :         Commit();
     167             :     }
     168           0 : }
     169             : 
     170             : //  public method
     171             : 
     172           0 : void SvtExtendedSecurityOptions_Impl::Notify( const Sequence< OUString >& )
     173             : {
     174             :     // Not implemented
     175           0 : }
     176             : 
     177             : //  public method
     178             : 
     179           0 : void SvtExtendedSecurityOptions_Impl::Commit()
     180             : {
     181             :     // Get names of supported properties, create a list for values and copy current values to it.
     182           0 :     Sequence< OUString >    seqNames    = GetPropertyNames  ();
     183           0 :     sal_Int32               nCount      = seqNames.getLength();
     184           0 :     Sequence< Any >         seqValues   ( nCount );
     185           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     186             :     {
     187           0 :         switch( nProperty )
     188             :         {
     189             :             case PROPERTYHANDLE_HYPERLINKS_OPEN:    {
     190           0 :                                                         seqValues[nProperty] <<= (sal_Int32)m_eOpenHyperlinkMode;
     191             :                                                     }
     192           0 :                                                     break;
     193             :         }
     194             :     }
     195             : 
     196             :     // Set properties in configuration.
     197           0 :     PutProperties( seqNames, seqValues );
     198           0 : }
     199             : 
     200             : //  public method
     201             : 
     202           0 : SvtExtendedSecurityOptions::OpenHyperlinkMode SvtExtendedSecurityOptions_Impl::GetOpenHyperlinkMode()
     203             : {
     204           0 :     return m_eOpenHyperlinkMode;
     205             : }
     206             : 
     207             : //  private method
     208             : 
     209           0 : void SvtExtendedSecurityOptions_Impl::FillExtensionHashMap( ExtensionHashMap& aHashMap )
     210             : {
     211             :     // Get sequence with secure extensions from configuration
     212           0 :     Sequence< OUString >    seqNodes = GetNodeNames( m_aSecureExtensionsSetName );
     213             : 
     214           0 :     OUString                aValue;
     215           0 :     Sequence< Any >         aValues;
     216           0 :     Sequence< OUString >    aPropSeq( 1 );
     217           0 :     for ( int i = 0; i < seqNodes.getLength(); i++ )
     218             :     {
     219             :         // Create access name for property
     220           0 :         OUStringBuffer aExtEntryProp( m_aSecureExtensionsSetName );
     221           0 :         aExtEntryProp.appendAscii( "/" );
     222           0 :         aExtEntryProp.append( seqNodes[i] );
     223           0 :         aExtEntryProp.append( m_aExtensionPropName );
     224             : 
     225           0 :         aPropSeq[0] = aExtEntryProp.makeStringAndClear();
     226           0 :         aValues = GetProperties( aPropSeq );
     227           0 :         if ( aValues.getLength() == 1 )
     228             :         {
     229             :             // Don't use value if sequence has not the correct length
     230           0 :             if ( aValues[0] >>= aValue )
     231             :                 // Add extension into secure extensions hash map
     232           0 :                 aHashMap.insert( ExtensionHashMap::value_type( aValue.toAsciiLowerCase(), 1 ) );
     233             :             else
     234             :             {
     235             :                 SAL_WARN( "unotools.config", "SvtExtendedSecurityOptions_Impl::FillExtensionHashMap(): not string value?" );
     236             :             }
     237             :         }
     238           0 :     }
     239           0 : }
     240             : 
     241             : //  private method (currently not used)
     242             : 
     243           0 : Sequence< OUString > SvtExtendedSecurityOptions_Impl::GetPropertyNames()
     244             : {
     245             :     // Build list of configuration key names.
     246             :     const OUString pProperties[] =
     247             :     {
     248             :         PROPERTYNAME_HYPERLINKS_OPEN
     249           0 :     };
     250             :     // Initialize return sequence with these list ...
     251           0 :     const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
     252             :     // ... and return it.
     253           0 :     return seqPropertyNames;
     254             : }
     255             : 
     256             : //  initialize static member
     257             : //  DON'T DO IT IN YOUR HEADER!
     258             : //  see definition for further information
     259             : 
     260             : SvtExtendedSecurityOptions_Impl*    SvtExtendedSecurityOptions::m_pDataContainer    = NULL;
     261             : sal_Int32                           SvtExtendedSecurityOptions::m_nRefCount         = 0;
     262             : 
     263             : //  constructor
     264             : 
     265           0 : SvtExtendedSecurityOptions::SvtExtendedSecurityOptions()
     266             : {
     267             :     // Global access, must be guarded (multithreading!).
     268           0 :     MutexGuard aGuard( GetInitMutex() );
     269             :     // Increase our refcount ...
     270           0 :     ++m_nRefCount;
     271             :     // ... and initialize our data container only if it not already exist!
     272           0 :     if( m_pDataContainer == NULL )
     273             :     {
     274           0 :        m_pDataContainer = new SvtExtendedSecurityOptions_Impl;
     275             : 
     276           0 :         ItemHolder1::holdConfigItem(E_EXTENDEDSECURITYOPTIONS);
     277           0 :     }
     278           0 : }
     279             : 
     280             : //  destructor
     281             : 
     282           0 : SvtExtendedSecurityOptions::~SvtExtendedSecurityOptions()
     283             : {
     284             :     // Global access, must be guarded (multithreading!)
     285           0 :     MutexGuard aGuard( GetInitMutex() );
     286             :     // Decrease our refcount.
     287           0 :     --m_nRefCount;
     288             :     // If last instance was deleted ...
     289             :     // we must destroy our static data container!
     290           0 :     if( m_nRefCount <= 0 )
     291             :     {
     292           0 :         delete m_pDataContainer;
     293           0 :         m_pDataContainer = NULL;
     294           0 :     }
     295           0 : }
     296             : 
     297             : //  public method
     298             : 
     299           0 : SvtExtendedSecurityOptions::OpenHyperlinkMode SvtExtendedSecurityOptions::GetOpenHyperlinkMode()
     300             : {
     301           0 :     MutexGuard aGuard( GetInitMutex() );
     302           0 :     return m_pDataContainer->GetOpenHyperlinkMode();
     303             : }
     304             : 
     305             : namespace
     306             : {
     307             :     class theExtendedSecurityOptionsMutex : public rtl::Static<osl::Mutex, theExtendedSecurityOptionsMutex>{};
     308             : }
     309             : 
     310             : //  private method
     311             : 
     312           0 : Mutex& SvtExtendedSecurityOptions::GetInitMutex()
     313             : {
     314           0 :     return theExtendedSecurityOptionsMutex::get();
     315             : }
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10