2010-10-14 08:27:31 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-07-11 09:51:50 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2002-08-13 11:43:49 +00:00
2015-04-22 09:42:28 +02:00
# include <sal/config.h>
# include <sal/log.hxx>
2009-10-06 07:38:24 +02:00
# include <unotools/extendedsecurityoptions.hxx>
2002-08-13 11:43:49 +00:00
# include <unotools/configmgr.hxx>
# include <unotools/configitem.hxx>
# include <tools/debug.hxx>
# include <com/sun/star/uno/Any.hxx>
# include <com/sun/star/uno/Sequence.hxx>
# include <rtl/ustrbuf.hxx>
2014-11-14 22:52:35 +01:00
# include <osl/diagnose.h>
2002-08-13 11:43:49 +00:00
2009-10-06 07:38:24 +02:00
# include <unotools/pathoptions.hxx>
2002-08-13 11:43:49 +00:00
2004-11-15 16:19:31 +00:00
# include "itemholder1.hxx"
2015-01-01 19:58:59 +00:00
# include <unordered_map>
2014-04-06 18:58:39 +03:00
using namespace : : utl ;
using namespace : : osl ;
using namespace : : com : : sun : : star : : uno ;
2002-08-13 11:43:49 +00:00
2013-03-10 20:44:01 +01:00
# define ROOTNODE_SECURITY OUString("Office.Security")
2002-08-13 11:43:49 +00:00
2013-03-10 20:44:01 +01:00
# define SECURE_EXTENSIONS_SET OUString("SecureExtensions")
# define EXTENSION_PROPNAME OUString(" / Extension")
2002-08-13 11:43:49 +00:00
2013-03-10 20:44:01 +01:00
# define PROPERTYNAME_HYPERLINKS_OPEN OUString("Hyperlinks / Open")
2002-08-13 11:43:49 +00:00
# define PROPERTYHANDLE_HYPERLINKS_OPEN 0
# define PROPERTYCOUNT 1
2015-01-01 19:58:59 +00:00
typedef std : : unordered_map < OUString , sal_Int32 , OUStringHash >
2014-04-07 13:47:22 +02:00
ExtensionHashMap ;
2002-08-13 11:43:49 +00:00
class SvtExtendedSecurityOptions_Impl : public ConfigItem
{
public :
SvtExtendedSecurityOptions_Impl ( ) ;
2014-04-01 19:18:35 +02:00
virtual ~ SvtExtendedSecurityOptions_Impl ( ) ;
2002-08-13 11:43:49 +00:00
2014-02-25 22:46:10 +01:00
/*-****************************************************************************************************
2002-08-13 11:43:49 +00:00
@ short called for notify of configmanager
@ descr These method is called from the ConfigManager before application ends or from the
PropertyChangeListener if the sub tree broadcasts changes . You must update your
internal values .
@ seealso baseclass ConfigItem
@ param " seqPropertyNames " is the list of properties which should be updated .
*/ /*-*****************************************************************************************************/
2014-03-26 16:37:00 +01:00
virtual void Notify ( const Sequence < OUString > & seqPropertyNames ) SAL_OVERRIDE ;
2002-08-13 11:43:49 +00:00
2014-06-09 10:09:42 +02:00
SvtExtendedSecurityOptions : : OpenHyperlinkMode GetOpenHyperlinkMode ( ) { return m_eOpenHyperlinkMode ; }
2015-03-11 16:14:47 +01:00
2002-08-13 11:43:49 +00:00
private :
2015-03-11 16:14:47 +01:00
virtual void ImplCommit ( ) SAL_OVERRIDE ;
2002-08-13 11:43:49 +00:00
2014-02-25 22:46:10 +01:00
/*-****************************************************************************************************
2014-04-06 20:25:20 +03:00
@ short return list of key names of our configuration management which represent oue module tree
2002-08-13 11:43:49 +00:00
@ descr These methods return a static const list of key names . We need it to get needed values from our
configuration management .
@ return A list of needed configuration keys is returned .
*/ /*-*****************************************************************************************************/
static Sequence < OUString > GetPropertyNames ( ) ;
2014-02-25 22:46:10 +01:00
/*-****************************************************************************************************
2002-08-13 11:43:49 +00:00
@ short Fills the hash map with all extensions known to be secure
@ descr These methods fills the given hash map object with all extensions known to be secure .
@ param aHashMap
A hash map to be filled with secure extension strings .
*/ /*-*****************************************************************************************************/
void FillExtensionHashMap ( ExtensionHashMap & aHashMap ) ;
OUString m_aSecureExtensionsSetName ;
OUString m_aExtensionPropName ;
SvtExtendedSecurityOptions : : OpenHyperlinkMode m_eOpenHyperlinkMode ;
2014-02-19 12:30:34 +01:00
bool m_bROOpenHyperlinkMode ;
2002-08-13 11:43:49 +00:00
ExtensionHashMap m_aExtensionHashMap ;
} ;
// constructor
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
SvtExtendedSecurityOptions_Impl : : SvtExtendedSecurityOptions_Impl ( )
// Init baseclasses first
2014-02-18 10:05:58 +00:00
: ConfigItem ( ROOTNODE_SECURITY )
, m_aSecureExtensionsSetName ( SECURE_EXTENSIONS_SET )
, m_aExtensionPropName ( EXTENSION_PROPNAME )
, m_eOpenHyperlinkMode ( SvtExtendedSecurityOptions : : OPEN_NEVER )
2014-02-19 12:30:34 +01:00
, m_bROOpenHyperlinkMode ( false )
2002-08-13 11:43:49 +00:00
// Init member then.
{
// Fill the extension hash map with all secure extension strings
FillExtensionHashMap ( m_aExtensionHashMap ) ;
Sequence < OUString > seqNames = GetPropertyNames ( ) ;
Sequence < Any > seqValues = GetProperties ( seqNames ) ;
2004-04-29 15:46:50 +00:00
Sequence < sal_Bool > seqRO = GetReadOnlyStates ( seqNames ) ;
2002-08-13 11:43:49 +00:00
sal_Int32 nPropertyCount = seqValues . getLength ( ) ;
for ( sal_Int32 nProperty = 0 ; nProperty < nPropertyCount ; + + nProperty )
{
// Safe impossible cases.
// Check any for valid value.
2014-01-21 17:47:16 +01:00
DBG_ASSERT ( seqValues [ nProperty ] . hasValue ( ) , " SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl() \n Invalid property value detected! \n " ) ;
2002-08-13 11:43:49 +00:00
switch ( nProperty )
{
case PROPERTYHANDLE_HYPERLINKS_OPEN :
{
DBG_ASSERT ( ( seqValues [ nProperty ] . getValueTypeClass ( ) = = TypeClass_LONG ) , " SvtExtendedSecurityOptions_Impl::SvtExtendedSecurityOptions_Impl() \n Who has changed the value type of 'Hyperlink/Open'? " ) ;
sal_Int32 nMode = SvtExtendedSecurityOptions : : OPEN_WITHSECURITYCHECK ;
if ( seqValues [ nProperty ] > > = nMode )
m_eOpenHyperlinkMode = ( SvtExtendedSecurityOptions : : OpenHyperlinkMode ) nMode ;
2008-07-01 14:40:19 +00:00
else {
2011-03-01 19:08:19 +01:00
OSL_FAIL ( " Wrong type for Open mode! " ) ;
2008-07-01 14:40:19 +00:00
}
2004-04-29 15:46:50 +00:00
m_bROOpenHyperlinkMode = seqRO [ nProperty ] ;
2002-08-13 11:43:49 +00:00
}
break ;
}
}
// Enable notification mechanism of our baseclass.
2014-04-06 20:25:20 +03:00
// We need it to get information about changes outside these class on our used configuration keys!
2002-08-13 11:43:49 +00:00
Sequence < OUString > seqNotifyNames ( 1 ) ;
seqNotifyNames [ 0 ] = m_aSecureExtensionsSetName ;
EnableNotification ( seqNotifyNames ) ;
}
// destructor
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
SvtExtendedSecurityOptions_Impl : : ~ SvtExtendedSecurityOptions_Impl ( )
{
2015-03-11 16:39:24 +01:00
assert ( ! IsModified ( ) ) ; // should have been committed
2002-08-13 11:43:49 +00:00
}
// public method
2014-02-25 22:46:10 +01:00
2006-06-19 19:43:23 +00:00
void SvtExtendedSecurityOptions_Impl : : Notify ( const Sequence < OUString > & )
2002-08-13 11:43:49 +00:00
{
// Not implemented
}
// public method
2014-02-25 22:46:10 +01:00
2015-03-11 16:14:47 +01:00
void SvtExtendedSecurityOptions_Impl : : ImplCommit ( )
2002-08-13 11:43:49 +00:00
{
// Get names of supported properties, create a list for values and copy current values to it.
Sequence < OUString > seqNames = GetPropertyNames ( ) ;
sal_Int32 nCount = seqNames . getLength ( ) ;
Sequence < Any > seqValues ( nCount ) ;
for ( sal_Int32 nProperty = 0 ; nProperty < nCount ; + + nProperty )
{
switch ( nProperty )
{
case PROPERTYHANDLE_HYPERLINKS_OPEN : {
seqValues [ nProperty ] < < = ( sal_Int32 ) m_eOpenHyperlinkMode ;
}
break ;
}
}
// Set properties in configuration.
PutProperties ( seqNames , seqValues ) ;
}
// public method
2014-02-25 22:46:10 +01:00
2004-04-29 15:46:50 +00:00
2002-08-13 11:43:49 +00:00
// private method
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
void SvtExtendedSecurityOptions_Impl : : FillExtensionHashMap ( ExtensionHashMap & aHashMap )
{
// Get sequence with secure extensions from configuration
Sequence < OUString > seqNodes = GetNodeNames ( m_aSecureExtensionsSetName ) ;
OUString aValue ;
Sequence < Any > aValues ;
Sequence < OUString > aPropSeq ( 1 ) ;
for ( int i = 0 ; i < seqNodes . getLength ( ) ; i + + )
{
// Create access name for property
OUStringBuffer aExtEntryProp ( m_aSecureExtensionsSetName ) ;
aExtEntryProp . appendAscii ( " / " ) ;
aExtEntryProp . append ( seqNodes [ i ] ) ;
aExtEntryProp . append ( m_aExtensionPropName ) ;
aPropSeq [ 0 ] = aExtEntryProp . makeStringAndClear ( ) ;
aValues = GetProperties ( aPropSeq ) ;
if ( aValues . getLength ( ) = = 1 )
{
// Don't use value if sequence has not the correct length
if ( aValues [ 0 ] > > = aValue )
// Add extension into secure extensions hash map
aHashMap . insert ( ExtensionHashMap : : value_type ( aValue . toAsciiLowerCase ( ) , 1 ) ) ;
else
{
2012-01-16 18:03:17 +01:00
SAL_WARN ( " unotools.config " , " SvtExtendedSecurityOptions_Impl::FillExtensionHashMap(): not string value? " ) ;
2002-08-13 11:43:49 +00:00
}
}
}
}
// private method (currently not used)
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
Sequence < OUString > SvtExtendedSecurityOptions_Impl : : GetPropertyNames ( )
{
2011-06-01 09:23:41 +01:00
// Build list of configuration key names.
const OUString pProperties [ ] =
2002-08-13 11:43:49 +00:00
{
PROPERTYNAME_HYPERLINKS_OPEN
} ;
// Initialize return sequence with these list ...
2011-06-01 09:23:41 +01:00
const Sequence < OUString > seqPropertyNames ( pProperties , PROPERTYCOUNT ) ;
2002-08-13 11:43:49 +00:00
// ... and return it.
return seqPropertyNames ;
}
// initialize static member
// DON'T DO IT IN YOUR HEADER!
2013-04-15 04:49:39 +02:00
// see definition for further information
2014-02-25 22:46:10 +01:00
2014-04-06 18:58:39 +03:00
SvtExtendedSecurityOptions_Impl * SvtExtendedSecurityOptions : : m_pDataContainer = NULL ;
sal_Int32 SvtExtendedSecurityOptions : : m_nRefCount = 0 ;
2002-08-13 11:43:49 +00:00
// constructor
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
SvtExtendedSecurityOptions : : SvtExtendedSecurityOptions ( )
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard ( GetInitMutex ( ) ) ;
2014-04-06 20:25:20 +03:00
// Increase our refcount ...
2002-08-13 11:43:49 +00:00
+ + m_nRefCount ;
2014-04-06 20:25:20 +03:00
// ... and initialize our data container only if it not already exist!
2002-08-13 11:43:49 +00:00
if ( m_pDataContainer = = NULL )
{
2004-11-15 16:19:31 +00:00
m_pDataContainer = new SvtExtendedSecurityOptions_Impl ;
2005-11-11 07:48:40 +00:00
ItemHolder1 : : holdConfigItem ( E_EXTENDEDSECURITYOPTIONS ) ;
2002-08-13 11:43:49 +00:00
}
}
// destructor
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
SvtExtendedSecurityOptions : : ~ SvtExtendedSecurityOptions ( )
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard ( GetInitMutex ( ) ) ;
2014-04-06 20:25:20 +03:00
// Decrease our refcount.
2002-08-13 11:43:49 +00:00
- - m_nRefCount ;
// If last instance was deleted ...
2014-04-06 20:25:20 +03:00
// we must destroy our static data container!
2002-08-13 11:43:49 +00:00
if ( m_nRefCount < = 0 )
{
delete m_pDataContainer ;
m_pDataContainer = NULL ;
}
}
// public method
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
SvtExtendedSecurityOptions : : OpenHyperlinkMode SvtExtendedSecurityOptions : : GetOpenHyperlinkMode ( )
{
MutexGuard aGuard ( GetInitMutex ( ) ) ;
return m_pDataContainer - > GetOpenHyperlinkMode ( ) ;
}
2004-04-29 15:46:50 +00:00
2011-04-03 21:34:16 +01:00
namespace
{
class theExtendedSecurityOptionsMutex : public rtl : : Static < osl : : Mutex , theExtendedSecurityOptionsMutex > { } ;
}
2002-08-13 11:43:49 +00:00
// private method
2014-02-25 22:46:10 +01:00
2002-08-13 11:43:49 +00:00
Mutex & SvtExtendedSecurityOptions : : GetInitMutex ( )
{
2011-04-03 21:34:16 +01:00
return theExtendedSecurityOptionsMutex : : get ( ) ;
2002-08-13 11:43:49 +00:00
}
2010-10-14 08:27:31 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */