diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2010-01-29 15:36:08 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2010-01-29 15:36:08 +0000 |
commit | 0ea5581ebf8cf414717af74d22d647ed446d63d2 (patch) | |
tree | fa6698372a7ba38d0ef315b0bf5df69c0b6f3cf1 /comphelper/source | |
parent | 04a59adcc7fd221ee6b7644aa1fa53fed8dd3c0e (diff) | |
parent | c0f197f920974f3fdaf8278dad16dc5ecb994d52 (diff) |
ab71: merge with DEV300_m63
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 152 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordrequest.cxx | 153 | ||||
-rw-r--r-- | comphelper/source/misc/makefile.mk | 2 | ||||
-rw-r--r-- | comphelper/source/misc/mediadescriptor.cxx | 21 | ||||
-rw-r--r-- | comphelper/source/misc/uieventslogger.cxx | 14 | ||||
-rw-r--r-- | comphelper/source/property/genericpropertyset.cxx | 3 |
6 files changed, 336 insertions, 9 deletions
diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx new file mode 100644 index 000000000000..1f362c02f881 --- /dev/null +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: docpasswordhelper.cxx,v $ + * $Revision: 1.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_comphelper.hxx" + +#include "comphelper/docpasswordhelper.hxx" +#include <com/sun/star/task/XInteractionHandler.hpp> +#include "comphelper/mediadescriptor.hxx" + +using ::rtl::OUString; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_SET_THROW; +using ::com::sun::star::task::PasswordRequestMode; +using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER; +using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER; +using ::com::sun::star::task::XInteractionHandler; +using ::com::sun::star::task::XInteractionRequest; + +namespace comphelper { + +// ============================================================================ + +IDocPasswordVerifier::~IDocPasswordVerifier() +{ +} + +// ============================================================================ + +/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + const OUString& rMediaPassword, + const Reference< XInteractionHandler >& rxInteractHandler, + const OUString& rDocumentName, + DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords, + bool* pbIsDefaultPassword ) +{ + OUString aPassword; + DocPasswordVerifierResult eResult = DocPasswordVerifierResult_WRONG_PASSWORD; + + // first, try provided default passwords + if( pbIsDefaultPassword ) + *pbIsDefaultPassword = false; + if( pDefaultPasswords ) + { + for( ::std::vector< OUString >::const_iterator aIt = pDefaultPasswords->begin(), aEnd = pDefaultPasswords->end(); (eResult == DocPasswordVerifierResult_WRONG_PASSWORD) && (aIt != aEnd); ++aIt ) + { + aPassword = *aIt; + OSL_ENSURE( aPassword.getLength() > 0, "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" ); + if( aPassword.getLength() > 0 ) + { + eResult = rVerifier.verifyPassword( aPassword ); + if( pbIsDefaultPassword ) + *pbIsDefaultPassword = eResult == DocPasswordVerifierResult_OK; + } + } + } + + // try media password (skip, if result is OK or ABORT) + if( eResult == DocPasswordVerifierResult_WRONG_PASSWORD ) + { + aPassword = rMediaPassword; + if( aPassword.getLength() > 0 ) + eResult = rVerifier.verifyPassword( aPassword ); + } + + // request a password (skip, if result is OK or ABORT) + if( (eResult == DocPasswordVerifierResult_WRONG_PASSWORD) && rxInteractHandler.is() ) try + { + PasswordRequestMode eRequestMode = PasswordRequestMode_PASSWORD_ENTER; + while( eResult == DocPasswordVerifierResult_WRONG_PASSWORD ) + { + DocPasswordRequest* pRequest = new DocPasswordRequest( eRequestType, eRequestMode, rDocumentName ); + Reference< XInteractionRequest > xRequest( pRequest ); + rxInteractHandler->handle( xRequest ); + if( pRequest->isPassword() ) + { + aPassword = pRequest->getPassword(); + if( aPassword.getLength() > 0 ) + eResult = rVerifier.verifyPassword( aPassword ); + } + else + { + eResult = DocPasswordVerifierResult_ABORT; + } + eRequestMode = PasswordRequestMode_PASSWORD_REENTER; + } + } + catch( Exception& ) + { + } + + return (eResult == DocPasswordVerifierResult_OK) ? aPassword : OUString(); +} + +/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + MediaDescriptor& rMediaDesc, + DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords ) +{ + OUString aMediaPassword = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_PASSWORD(), OUString() ); + Reference< XInteractionHandler > xInteractHandler = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_INTERACTIONHANDLER(), Reference< XInteractionHandler >() ); + OUString aDocumentName = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_URL(), OUString() ); + + bool bIsDefaultPassword = false; + OUString aPassword = requestAndVerifyDocPassword( + rVerifier, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword ); + + // insert valid password into media descriptor (but not a default password) + if( (aPassword.getLength() > 0) && !bIsDefaultPassword ) + rMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= aPassword; + + return aPassword; +} + +// ============================================================================ + +} // namespace comphelper + diff --git a/comphelper/source/misc/docpasswordrequest.cxx b/comphelper/source/misc/docpasswordrequest.cxx new file mode 100644 index 000000000000..187642e10fe9 --- /dev/null +++ b/comphelper/source/misc/docpasswordrequest.cxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: docpasswordrequest.cxx,v $ + * $Revision: 1.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_comphelper.hxx" + +#include "comphelper/docpasswordrequest.hxx" +#include <com/sun/star/task/DocumentMSPasswordRequest.hpp> +#include <com/sun/star/task/DocumentPasswordRequest.hpp> +#include <com/sun/star/task/XInteractionAbort.hpp> +#include <com/sun/star/task/XInteractionPassword.hpp> + +using ::rtl::OUString; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::XInterface; +using ::com::sun::star::task::InteractionClassification_QUERY; +using ::com::sun::star::task::DocumentMSPasswordRequest; +using ::com::sun::star::task::DocumentPasswordRequest; +using ::com::sun::star::task::PasswordRequestMode; +using ::com::sun::star::task::XInteractionAbort; +using ::com::sun::star::task::XInteractionContinuation; +using ::com::sun::star::task::XInteractionPassword; + +namespace comphelper { + +// ============================================================================ + +class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort > +{ +public: + inline explicit AbortContinuation() : mbSelected( false ) {} + + inline bool isSelected() const { return mbSelected; } + inline void reset() { mbSelected = false; } + + virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; } + +private: + bool mbSelected; +}; + +// ============================================================================ + +class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword > +{ +public: + inline explicit PasswordContinuation() : mbSelected( false ) {} + + inline bool isSelected() const { return mbSelected; } + inline void reset() { mbSelected = false; } + + virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; } + virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; } + virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; } + +private: + OUString maPassword; + bool mbSelected; +}; + +// ============================================================================ + +DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType, + PasswordRequestMode eMode, const OUString& rDocumentName ) +{ + switch( eType ) + { + case DocPasswordRequestType_STANDARD: + { + DocumentPasswordRequest aRequest( OUString(), Reference< XInterface >(), + InteractionClassification_QUERY, eMode, rDocumentName ); + maRequest <<= aRequest; + } + break; + case DocPasswordRequestType_MS: + { + DocumentMSPasswordRequest aRequest( OUString(), Reference< XInterface >(), + InteractionClassification_QUERY, eMode, rDocumentName ); + maRequest <<= aRequest; + } + break; + /* no 'default', so compilers will complain about missing + implementation of a new enum value. */ + } + + maContinuations.realloc( 2 ); + maContinuations[ 0 ].set( mpAbort = new AbortContinuation ); + maContinuations[ 1 ].set( mpPassword = new PasswordContinuation ); +} + +DocPasswordRequest::~DocPasswordRequest() +{ +} + +bool DocPasswordRequest::isAbort() const +{ + return mpAbort->isSelected(); +} + +bool DocPasswordRequest::isPassword() const +{ + return mpPassword->isSelected(); +} + +OUString DocPasswordRequest::getPassword() const +{ + return mpPassword->getPassword(); +} + +Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException ) +{ + return maRequest; +} + +Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException ) +{ + return maContinuations; +} + +// ============================================================================ + +} // namespace comphelper + diff --git a/comphelper/source/misc/makefile.mk b/comphelper/source/misc/makefile.mk index 2589c5dde6c1..3d27599212b5 100644 --- a/comphelper/source/misc/makefile.mk +++ b/comphelper/source/misc/makefile.mk @@ -57,6 +57,8 @@ SLOFILES= \ $(SLO)$/componentcontext.obj \ $(SLO)$/componentmodule.obj \ $(SLO)$/configurationhelper.obj \ + $(SLO)$/docpasswordhelper.obj \ + $(SLO)$/docpasswordrequest.obj \ $(SLO)$/documentinfo.obj \ $(SLO)$/evtmethodhelper.obj \ $(SLO)$/documentiologring.obj \ diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx index da0dd71a5520..44578f840da9 100644 --- a/comphelper/source/misc/mediadescriptor.cxx +++ b/comphelper/source/misc/mediadescriptor.cxx @@ -114,6 +114,12 @@ namespace css = ::com::sun::star; /*----------------------------------------------- 10.03.2004 07:35 -----------------------------------------------*/ +const ::rtl::OUString& MediaDescriptor::PROP_ABORTED() +{ + static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Aborted")); + return sProp; +} + const ::rtl::OUString& MediaDescriptor::PROP_ASTEMPLATE() { static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); @@ -126,6 +132,12 @@ const ::rtl::OUString& MediaDescriptor::PROP_CHARACTERSET() return sProp; } +const ::rtl::OUString& MediaDescriptor::PROP_COMPONENTDATA() +{ + static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ComponentData")); + return sProp; +} + const ::rtl::OUString& MediaDescriptor::PROP_DEEPDETECTION() { static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DeepDetection")); @@ -726,8 +738,13 @@ class StillReadWriteInteraction : public ::ucbhelper::InterceptedInteraction css::ucb::InteractiveIOException exIO; xRequest->getRequest() >>= exIO; bAbort = ( - (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED ) || - (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION ) + (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED ) + || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION ) +#ifdef MACOSX + // this is a workaround for MAC, on this platform if the file is locked + // the returned error code looks to be wrong + || (exIO.Code == css::ucb::IOErrorCode_GENERAL ) +#endif ); } break; diff --git a/comphelper/source/misc/uieventslogger.cxx b/comphelper/source/misc/uieventslogger.cxx index a55d5b58854d..ae351340bc7a 100644 --- a/comphelper/source/misc/uieventslogger.cxx +++ b/comphelper/source/misc/uieventslogger.cxx @@ -218,11 +218,15 @@ namespace comphelper // public UiEventsLogger interface sal_Bool UiEventsLogger::isEnabled() { - try { - UiEventsLogger_Impl::prepareMutex(); - Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex); - return UiEventsLogger_Impl::getInstance()->m_Active; - } catch(...) { return false; } // never throws + if ( UiEventsLogger_Impl::getEnabledFromCfg() ) + { + try { + UiEventsLogger_Impl::prepareMutex(); + Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex); + return UiEventsLogger_Impl::getInstance()->m_Active; + } catch(...) { return false; } // never throws + } // if ( ) + return sal_False; } sal_Int32 UiEventsLogger::getSessionLogEventCount() diff --git a/comphelper/source/property/genericpropertyset.cxx b/comphelper/source/property/genericpropertyset.cxx index 08dd26dcf0ec..19911709860d 100644 --- a/comphelper/source/property/genericpropertyset.cxx +++ b/comphelper/source/property/genericpropertyset.cxx @@ -180,8 +180,7 @@ void GenericPropertySet::_setPropertyValues( const PropertyMapEntry** ppEntries, aEvt.PropertyName = aPropertyName; aEvt.NewValue = *pValues; aGuard.clear(); - pHelper->forEach<XPropertyChangeListener>( - ::boost::bind(&XPropertyChangeListener::propertyChange,_1,boost::cref(aEvt))); + pHelper->notifyEach( &XPropertyChangeListener::propertyChange, aEvt ); aGuard.reset(); } |