From 5dbc43ead1b7ff5fa0c1f6756a9ca6062c48d033 Mon Sep 17 00:00:00 2001 From: sb Date: Fri, 10 Sep 2010 13:10:07 +0200 Subject: sb129: #i113189# change UNO components to use passive registration --- package/source/manifest/UnoRegister.cxx | 63 --------------------------------- package/source/xstor/makefile.mk | 8 +++++ package/source/xstor/register.cxx | 28 --------------- package/source/xstor/xstor.component | 35 ++++++++++++++++++ package/source/xstor/xstor.dxp | 1 - 5 files changed, 43 insertions(+), 92 deletions(-) create mode 100644 package/source/xstor/xstor.component (limited to 'package/source') diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx index 2405495f321f..34dd874206e1 100644 --- a/package/source/manifest/UnoRegister.cxx +++ b/package/source/manifest/UnoRegister.cxx @@ -46,43 +46,6 @@ using namespace ::com::sun::star::registry; using namespace ::com::sun::star::packages; using namespace ::com::sun::star::packages::manifest; -static sal_Bool writeInfo( void * pRegistryKey, - const OUString & rImplementationName, - Sequence< OUString > const & rServiceNames ) -{ - OUString aKeyName( OUString::createFromAscii( "/" ) ); - aKeyName += rImplementationName; - aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); - - Reference< XRegistryKey > xKey; - try - { - xKey = static_cast< XRegistryKey * >( - pRegistryKey )->createKey( aKeyName ); - } - catch ( InvalidRegistryException const & ) - { - } - - if ( !xKey.is() ) - return sal_False; - - sal_Bool bSuccess = sal_True; - - for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) - { - try - { - xKey->createKey( rServiceNames[ n ] ); - } - catch ( InvalidRegistryException const & ) - { - bSuccess = sal_False; - break; - } - } - return bSuccess; -} // C functions to implement this as a component extern "C" void SAL_CALL component_getImplementationEnvironment( @@ -91,32 +54,6 @@ extern "C" void SAL_CALL component_getImplementationEnvironment( *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; } -/** - * This function creates an implementation section in the registry and another subkey - * for each supported service. - * @param pServiceManager generic uno interface providing a service manager - * @param pRegistryKey generic uno interface providing registry key to write - */ -extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey ) -{ - return pRegistryKey && - writeInfo (pRegistryKey, - ManifestReader::static_getImplementationName(), - ManifestReader::static_getSupportedServiceNames() ) && - writeInfo (pRegistryKey, - ManifestWriter::static_getImplementationName(), - ManifestWriter::static_getSupportedServiceNames() ) && - writeInfo (pRegistryKey, - ZipPackage::static_getImplementationName(), - ZipPackage::static_getSupportedServiceNames() ) && - - writeInfo (pRegistryKey, - OZipFileAccess::impl_staticGetImplementationName(), - OZipFileAccess::impl_staticGetSupportedServiceNames() ); - -} - - /** * This function is called to get service factories for an implementation. * @param pImplName name of implementation diff --git a/package/source/xstor/makefile.mk b/package/source/xstor/makefile.mk index 76494cb7dbe7..5c381ba4c803 100644 --- a/package/source/xstor/makefile.mk +++ b/package/source/xstor/makefile.mk @@ -73,3 +73,11 @@ DEF1EXPORTFILE=$(SHL1TARGET).dxp .INCLUDE : target.mk + +ALLTAR : $(MISC)/xstor.component + +$(MISC)/xstor.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ + xstor.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt xstor.component diff --git a/package/source/xstor/register.cxx b/package/source/xstor/register.cxx index 1e3ae15fe383..808788345bfc 100644 --- a/package/source/xstor/register.cxx +++ b/package/source/xstor/register.cxx @@ -69,33 +69,5 @@ void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServic return pRet; } -sal_Bool SAL_CALL component_writeInfo( void * /*pServiceManager*/, void * pRegistryKey ) -{ - if (pRegistryKey) - { - try - { - uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) ); - - uno::Reference< registry::XRegistryKey > xNewKey; - - xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + - OStorageFactory::impl_staticGetImplementationName() + - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) ); - - const uno::Sequence< ::rtl::OUString > aServices = OStorageFactory::impl_staticGetSupportedServiceNames(); - for( sal_Int32 ind = 0; ind < aServices.getLength(); ind++ ) - xNewKey->createKey( aServices.getConstArray()[ind] ); - - return sal_True; - } - catch (registry::InvalidRegistryException &) - { - OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); - } - } - return sal_False; -} - } // extern "C" diff --git a/package/source/xstor/xstor.component b/package/source/xstor/xstor.component new file mode 100644 index 000000000000..f338d6a546cb --- /dev/null +++ b/package/source/xstor/xstor.component @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/package/source/xstor/xstor.dxp b/package/source/xstor/xstor.dxp index 9630d7e06768..f0e1c69934bc 100644 --- a/package/source/xstor/xstor.dxp +++ b/package/source/xstor/xstor.dxp @@ -1,3 +1,2 @@ component_getImplementationEnvironment -component_writeInfo component_getFactory -- cgit v1.2.3 From 1724393d0044cdc535f635cc15d957176554c6ea Mon Sep 17 00:00:00 2001 From: Mikhail Voytenko Date: Tue, 28 Sep 2010 14:51:09 +0200 Subject: fwk149: #i112602# integrate the patch --- package/inc/ZipPackageFolder.hxx | 7 +------ package/source/xstor/owriteablestream.cxx | 20 +++++--------------- package/source/xstor/xstorage.cxx | 20 +++++--------------- package/source/zippackage/ZipPackage.cxx | 16 +++++----------- package/source/zippackage/ZipPackageFolder.cxx | 15 ++++++++++----- package/source/zippackage/ZipPackageStream.cxx | 15 ++++++++++----- package/source/zippackage/ZipPackageStream.hxx | 6 +----- 7 files changed, 37 insertions(+), 62 deletions(-) (limited to 'package/source') diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx index 89414f18ce65..037c27f1fdd7 100644 --- a/package/inc/ZipPackageFolder.hxx +++ b/package/inc/ZipPackageFolder.hxx @@ -53,8 +53,6 @@ class ZipPackageFolder : public cppu::ImplInheritanceHelper2 ::com::sun::star::container::XEnumerationAccess > { - static com::sun::star::uno::Sequence < sal_Int8 > aImplementationId; - protected: ContentHash maContents; const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; @@ -82,10 +80,7 @@ public: throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); static void copyZipEntry( ZipEntry &rDest, const ZipEntry &rSource); - static ::com::sun::star::uno::Sequence < sal_Int8 > static_getImplementationId() - { - return aImplementationId; - } + static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId(); void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; } void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; } diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index be11586bc4fb..2f58595ab4a3 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -54,6 +54,7 @@ #include #include +#include // since the copying uses 32000 blocks usually, it makes sense to have a smaller size #define MAX_STORCACHE_SIZE 30000 @@ -2173,25 +2174,14 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes() return m_pData->m_pTypeCollection->getTypes() ; } +namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } + //----------------------------------------------- uno::Sequence< sal_Int8 > SAL_CALL OWriteStream::getImplementationId() throw( uno::RuntimeException ) { - static ::cppu::OImplementationId* pID = NULL ; - - if ( pID == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; - - if ( pID == NULL ) - { - static ::cppu::OImplementationId aID( sal_False ) ; - pID = &aID ; - } - } - - return pID->getImplementationId() ; - + ::cppu::OImplementationId &rId = lcl_ImplId::get(); + return rId.getImplementationId(); } //----------------------------------------------- diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 9c90c4ce35dd..01489c5b4f5d 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -2368,25 +2369,14 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() return m_pData->m_pTypeCollection->getTypes() ; } +namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } + //----------------------------------------------- uno::Sequence< sal_Int8 > SAL_CALL OStorage::getImplementationId() throw( uno::RuntimeException ) { - static ::cppu::OImplementationId* pID = NULL ; - - if ( pID == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; - - if ( pID == NULL ) - { - static ::cppu::OImplementationId aID( sal_False ) ; - pID = &aID ; - } - } - - return pID->getImplementationId() ; - + ::cppu::OImplementationId &rID = lcl_ImplId::get(); + return rID.getImplementationId(); } //____________________________________________________________________________________________________ diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 9ba26e0100c5..c99cd22d3b4c 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include "com/sun/star/io/XAsyncOutputMonitor.hpp" @@ -1607,21 +1608,14 @@ uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno:: static_getSupportedServiceNames()); } +namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } + // XUnoTunnel Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void ) throw (RuntimeException) { - static ::cppu::OImplementationId * pId = 0; - if (! pId) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if (! pId) - { - static ::cppu::OImplementationId aId; - pId = &aId; - } - } - return pId->getImplementationId(); + ::cppu::OImplementationId &rId = lcl_ImplId::get(); + return rId.getImplementationId(); } sal_Int64 SAL_CALL ZipPackage::getSomething( const Sequence< sal_Int8 >& aIdentifier ) diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index f0c4a11d22f4..903191deb6be 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #include using namespace com::sun::star::packages::zip::ZipConstants; @@ -59,7 +60,7 @@ using namespace std; using namespace ::com::sun::star; using vos::ORef; -Sequence < sal_Int8 > ZipPackageFolder::aImplementationId = Sequence < sal_Int8 > (); +namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; } ZipPackageFolder::ZipPackageFolder ( const Reference< XMultiServiceFactory >& xFactory, sal_Int32 nFormat, @@ -80,10 +81,9 @@ ZipPackageFolder::ZipPackageFolder ( const Reference< XMultiServiceFactory >& xF aEntry.nCompressedSize = 0; aEntry.nSize = 0; aEntry.nOffset = -1; - if ( !aImplementationId.getLength() ) - { - aImplementationId = getImplementationId(); - } + Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); + if ( !rCachedImplId.getLength() ) + rCachedImplId = getImplementationId(); } @@ -187,6 +187,11 @@ void ZipPackageFolder::copyZipEntry( ZipEntry &rDest, const ZipEntry &rSource) rDest.nExtraLen = rSource.nExtraLen; } +const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageFolder::static_getImplementationId() +{ + return lcl_CachedImplId::get(); +} + // XNameContainer void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 6343607c8711..da44dafa000b 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -46,6 +46,8 @@ #include #include +#include + #include using namespace com::sun::star::packages::zip::ZipConstants; @@ -56,8 +58,12 @@ using namespace com::sun::star; using namespace cppu; using namespace rtl; -Sequence < sal_Int8 > ZipPackageStream::aImplementationId = Sequence < sal_Int8 > (); +namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; } +const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::static_getImplementationId() +{ + return lcl_CachedImplId::get(); +} ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, const Reference< XMultiServiceFactory >& xFactory, @@ -92,10 +98,9 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, aEntry.nPathLen = -1; aEntry.nExtraLen = -1; - if ( !aImplementationId.getLength() ) - { - aImplementationId = getImplementationId(); - } + Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); + if ( !rCachedImplId.getLength() ) + rCachedImplId = getImplementationId(); } ZipPackageStream::~ZipPackageStream( void ) diff --git a/package/source/zippackage/ZipPackageStream.hxx b/package/source/zippackage/ZipPackageStream.hxx index a0d5fad6e4da..38301d5e7d12 100644 --- a/package/source/zippackage/ZipPackageStream.hxx +++ b/package/source/zippackage/ZipPackageStream.hxx @@ -55,7 +55,6 @@ class ZipPackageStream : public cppu::ImplInheritanceHelper2 ::com::sun::star::packages::XDataSinkEncrSupport > { - static com::sun::star::uno::Sequence < sal_Int8 > aImplementationId; protected: com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; @@ -146,10 +145,7 @@ public: ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData() throw(::com::sun::star::uno::RuntimeException); - static ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId() - { - return aImplementationId; - } + static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId(); // XActiveDataSink virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream ) -- cgit v1.2.3 From fcd3252f26e20158ce96af5a7cc3a53e65616a4e Mon Sep 17 00:00:00 2001 From: Mikhail Voytenko Date: Thu, 4 Nov 2010 17:56:39 +0100 Subject: pl08: #163778# use EncryptionData from MediaDescriptor --- package/source/xstor/ohierarchyholder.cxx | 21 +- package/source/xstor/ohierarchyholder.hxx | 18 +- package/source/xstor/owriteablestream.cxx | 206 ++++++----- package/source/xstor/owriteablestream.hxx | 38 +- package/source/xstor/xstorage.cxx | 586 +++++++++++++++++------------- package/source/xstor/xstorage.hxx | 66 +++- package/source/zippackage/ZipPackage.cxx | 2 +- 7 files changed, 552 insertions(+), 385 deletions(-) (limited to 'package/source') diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx index 8e22b2b3a093..32ebc7068ec3 100644 --- a/package/source/xstor/ohierarchyholder.cxx +++ b/package/source/xstor/ohierarchyholder.cxx @@ -29,7 +29,7 @@ #include "precompiled_package.hxx" #include #include -#include +#include #include #include "ohierarchyholder.hxx" @@ -41,7 +41,7 @@ using namespace ::com::sun::star; //=============================================== //----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::rtl::OUString& aPass ) +uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) { uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); @@ -49,7 +49,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStream throw io::IOException(); uno::Reference< embed::XExtendedStorageStream > xResult = - m_xChild->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aPass ); + m_xChild->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData ); if ( !xResult.is() ) throw uno::RuntimeException(); @@ -88,7 +88,7 @@ OStringList_Impl OHierarchyHolder_Impl::GetListPathFromString( const ::rtl::OUSt //=============================================== //----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::rtl::OUString& aPass ) +uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) { ::osl::MutexGuard aGuard( m_aMutex ); @@ -110,11 +110,16 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea if ( !aListPath.size() ) { - uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - if ( !aPass.getLength() ) + if ( !aEncryptionData.size() ) + { + uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); xResult = xHStorage->openStreamElementByHierarchicalName( aNextName, nStreamMode ); + } else - xResult = xHStorage->openEncryptedStreamElementByHierarchicalName( aNextName, nStreamMode, aPass ); + { + uno::Reference< embed::XHierarchicalStorageAccess2 > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); + xResult = xHStorage->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() ); + } uno::Reference< embed::XTransactedObject > xTransact( xResult, uno::UNO_QUERY ); if ( xTransact.is() ) @@ -150,7 +155,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea aElement = new OHierarchyElement_Impl( NULL, xChildStorage ); } - xResult = aElement->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aPass ); + xResult = aElement->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData ); if ( !xResult.is() ) throw uno::RuntimeException(); diff --git a/package/source/xstor/ohierarchyholder.hxx b/package/source/xstor/ohierarchyholder.hxx index 17c14d3a6001..d36d784ac839 100644 --- a/package/source/xstor/ohierarchyholder.hxx +++ b/package/source/xstor/ohierarchyholder.hxx @@ -33,6 +33,8 @@ #include #include +#include + #include #include @@ -90,10 +92,10 @@ public: void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef ); ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > - GetStreamHierarchically( sal_Int32 nStorageMode, - OStringList_Impl& aPath, - sal_Int32 nStreamMode, - const ::rtl::OUString& aPassword = ::rtl::OUString() ); + GetStreamHierarchically( sal_Int32 nStorageMode, + OStringList_Impl& aPath, + sal_Int32 nStreamMode, + const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); void RemoveStreamHierarchically( OStringList_Impl& aListPath ); @@ -127,10 +129,10 @@ public: static OStringList_Impl GetListPathFromString( const ::rtl::OUString& aPath ); ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > - GetStreamHierarchically( sal_Int32 nStorageMode, - OStringList_Impl& aListPath, - sal_Int32 nStreamMode, - const ::rtl::OUString& aPassword = ::rtl::OUString() ); + GetStreamHierarchically( sal_Int32 nStorageMode, + OStringList_Impl& aListPath, + sal_Int32 nStreamMode, + const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); void RemoveStreamHierarchically( OStringList_Impl& aListPath ); }; diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index be11586bc4fb..9eefd8383cb3 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -64,29 +64,25 @@ using namespace ::com::sun::star; namespace package { //----------------------------------------------- -uno::Sequence< sal_Int8 > MakeKeyFromPass( const ::rtl::OUString& aPass, sal_Bool bUseUTF ) +bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 ) { - // MS_1252 encoding was used for SO60 document format password encoding, - // this encoding supports only a minor subset of nonascii characters, - // but for compatibility reasons it has to be used for old document formats - - ::rtl::OString aByteStrPass; - if ( bUseUTF ) - aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_UTF8 ); - else - aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_MS_1252 ); - - sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1]; - rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(), - aByteStrPass.getLength(), - pBuffer, - RTL_DIGEST_LENGTH_SHA1 ); - - if ( nError != rtl_Digest_E_None ) - throw uno::RuntimeException(); - - return uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); + bool bResult = ( aHash1.size() && aHash1.size() == aHash2.size() ); + for ( ::comphelper::SequenceAsHashMap::const_iterator aIter = aHash1.begin(); + bResult && aIter != aHash1.end(); + aIter++ ) + { + uno::Sequence< sal_Int8 > aKey1; + bResult = ( ( aIter->second >>= aKey1 ) && aKey1.getLength() ); + if ( bResult ) + { + uno::Sequence< sal_Int8 > aKey2 = aHash2.getUnpackedValueOrDefault( aIter->first, uno::Sequence< sal_Int8 >() ); + bResult = ( aKey1.getLength() == aKey2.getLength() ); + for ( sal_Int32 nInd = 0; bResult && nInd < aKey1.getLength(); nInd++ ) + bResult = ( aKey1[nInd] == aKey2[nInd] ); + } + } + return bResult; } //----------------------------------------------- @@ -255,8 +251,8 @@ OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent, , m_xFactory( xFactory ) , m_pParent( pParent ) , m_bForceEncrypted( bForceEncrypted ) -, m_bUseCommonPass( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE ) -, m_bHasCachedPassword( sal_False ) +, m_bUseCommonEncryption( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE ) +, m_bHasCachedEncryptionData( sal_False ) , m_bCompressedSetExplicit( !bDefaultCompress ) , m_xPackage( xPackage ) , m_bHasInsertedStreamOptimization( sal_False ) @@ -363,7 +359,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted() if ( m_nStorageType != embed::StorageFormats::PACKAGE ) return sal_False; - if ( m_bForceEncrypted || m_bHasCachedPassword ) + if ( m_bForceEncrypted || m_bHasCachedEncryptionData ) return sal_True; if ( m_aTempURL.getLength() || m_xCacheStream.is() ) @@ -410,7 +406,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted() if ( !bWasEncr && bToBeEncr && !aKey.getLength() ) { // the stream is intended to use common storage password - m_bUseCommonPass = sal_True; + m_bUseCommonEncryption = sal_True; return sal_False; } else @@ -432,8 +428,8 @@ void OWriteStream_Impl::SetDecrypted() // remove encryption m_bForceEncrypted = sal_False; - m_bHasCachedPassword = sal_False; - m_aPass = ::rtl::OUString(); + m_bHasCachedEncryptionData = sal_False; + m_aEncryptionData.clear(); for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) { @@ -443,12 +439,15 @@ void OWriteStream_Impl::SetDecrypted() } //----------------------------------------------- -void OWriteStream_Impl::SetEncryptedWithPass( const ::rtl::OUString& aPass ) +void OWriteStream_Impl::SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData ) { OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" ); if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException(); + if ( !aEncryptionData.size() ) + throw uno::RuntimeException(); + GetStreamProperties(); // let the stream be modified @@ -462,10 +461,10 @@ void OWriteStream_Impl::SetEncryptedWithPass( const ::rtl::OUString& aPass ) m_aProps[nInd].Value <<= sal_True; } - m_bUseCommonPass = sal_False; // very important to set it to false + m_bUseCommonEncryption = sal_False; // very important to set it to false - m_bHasCachedPassword = sal_True; - m_aPass = aPass; + m_bHasCachedEncryptionData = sal_True; + m_aEncryptionData = aEncryptionData; } //----------------------------------------------- @@ -796,7 +795,7 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt xPropertySet->setPropertyValue( aProps[nInd].Name, aProps[nInd].Value ); } else if ( m_nStorageType == embed::StorageFormats::PACKAGE && aProps[nInd].Name.equalsAscii( "UseCommonStoragePasswordEncryption" ) ) - aProps[nInd].Value >>= m_bUseCommonPass; + aProps[nInd].Value >>= m_bUseCommonEncryption; else throw lang::IllegalArgumentException(); @@ -815,7 +814,7 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt m_bCompressedSetExplicit = sal_True; } - if ( m_bUseCommonPass ) + if ( m_bUseCommonEncryption ) { if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException(); @@ -914,7 +913,7 @@ void OWriteStream_Impl::Commit() xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value ); } - if ( m_bUseCommonPass ) + if ( m_bUseCommonEncryption ) { if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException(); @@ -925,13 +924,13 @@ void OWriteStream_Impl::Commit() xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "Encrypted" ), uno::makeAny( sal_True ) ); } - else if ( m_bHasCachedPassword ) + else if ( m_bHasCachedEncryptionData ) { if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException(); xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( ::package::MakeKeyFromPass( m_aPass, sal_True ) ) ); + uno::makeAny( m_aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) ); } // the stream should be free soon, after package is stored @@ -969,9 +968,9 @@ void OWriteStream_Impl::Revert() m_bHasDataToFlush = sal_False; - m_bUseCommonPass = sal_True; - m_bHasCachedPassword = sal_False; - m_aPass = ::rtl::OUString(); + m_bUseCommonEncryption = sal_True; + m_bHasCachedEncryptionData = sal_False; + m_aEncryptionData.clear(); if ( m_nStorageType == embed::StorageFormats::OFOPXML ) { @@ -1007,7 +1006,7 @@ uno::Sequence< beans::PropertyValue > OWriteStream_Impl::GetStreamProperties() //----------------------------------------------- uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps( const uno::Sequence< beans::PropertyValue >& aProps, - sal_Bool bUseCommonPass ) + sal_Bool bUseCommonEncryption ) { uno::Sequence< beans::PropertyValue > aResult( aProps ); sal_Int32 nLen = aResult.getLength(); @@ -1017,13 +1016,13 @@ uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps( for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) if ( aResult[nInd].Name.equalsAscii( "UseCommonStoragePasswordEncryption" ) ) { - aResult[nInd].Value <<= bUseCommonPass; + aResult[nInd].Value <<= bUseCommonEncryption; return aResult; } aResult.realloc( ++nLen ); aResult[nLen - 1].Name = ::rtl::OUString::createFromAscii( "UseCommonStoragePasswordEncryption" ); - aResult[nLen - 1].Value <<= bUseCommonPass; + aResult[nLen - 1].Value <<= bUseCommonEncryption; } else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) { @@ -1172,11 +1171,11 @@ uno::Sequence< beans::PropertyValue > OWriteStream_Impl::ReadPackageStreamProper //----------------------------------------------- void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream, - const ::rtl::OUString& aPass ) + const ::comphelper::SequenceAsHashMap& aEncryptionData ) { ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - OSL_ENSURE( !m_bUseCommonPass, "The stream can not be encrypted!" ); + OSL_ENSURE( !m_bUseCommonEncryption, "The stream can not be encrypted!" ); if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw packages::NoEncryptionException(); @@ -1187,16 +1186,16 @@ void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream } else { - uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aPass, sal_False ); + uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aEncryptionData, sal_False ); if ( !xOwnStream.is() ) throw io::IOException(); // TODO OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); } - uno::Reference< embed::XEncryptionProtectedSource > xEncr( xDestStream, uno::UNO_QUERY ); + uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDestStream, uno::UNO_QUERY ); if ( xEncr.is() ) - xEncr->setEncryptionPassword( aPass ); + xEncr->setEncryptionData( aEncryptionData.getAsConstNamedValueList() ); } //----------------------------------------------- @@ -1236,7 +1235,7 @@ void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream } //----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::rtl::OUString& aPass, sal_Bool bHierarchyAccess ) +uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData, sal_Bool bHierarchyAccess ) { ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; @@ -1254,9 +1253,9 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod if ( !xPropertySet.is() ) throw uno::RuntimeException(); - if ( m_bHasCachedPassword ) + if ( m_bHasCachedEncryptionData ) { - if ( !m_aPass.equals( aPass ) ) + if ( !::package::PackageEncryptionDatasEqual( m_aEncryptionData, aEncryptionData ) ) throw packages::WrongPasswordException(); // the correct key must be set already @@ -1264,26 +1263,26 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod } else { - SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_True ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ); try { xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - m_bUseCommonPass = sal_False; // very important to set it to false - m_bHasCachedPassword = sal_True; - m_aPass = aPass; + m_bUseCommonEncryption = sal_False; // very important to set it to false + m_bHasCachedEncryptionData = sal_True; + m_aEncryptionData = aEncryptionData; } catch( packages::WrongPasswordException& ) { // retry with different encoding - SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_False ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) ); try { // the stream must be cashed to be resaved xResultStream = GetStream_Impl( nStreamMode | embed::ElementModes::SEEKABLE, bHierarchyAccess ); - m_bUseCommonPass = sal_False; // very important to set it to false - m_bHasCachedPassword = sal_True; - m_aPass = aPass; + m_bUseCommonEncryption = sal_False; // very important to set it to false + m_bHasCachedEncryptionData = sal_True; + m_aEncryptionData = aEncryptionData; // the stream must be resaved with new password encryption if ( nStreamMode & embed::ElementModes::WRITE ) @@ -1343,10 +1342,10 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod if ( IsEncrypted() ) { - ::rtl::OUString aGlobalPass; + ::comphelper::SequenceAsHashMap aGlobalEncryptionData; try { - aGlobalPass = GetCommonRootPass(); + aGlobalEncryptionData = GetCommonRootEncryptionData(); } catch( packages::NoEncryptionException& aNoEncryptionException ) { @@ -1356,7 +1355,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod throw packages::WrongPasswordException(); } - xResultStream = GetStream( nStreamMode, aGlobalPass, bHierarchyAccess ); + xResultStream = GetStream( nStreamMode, aGlobalEncryptionData, bHierarchyAccess ); } else xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); @@ -1385,7 +1384,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre if ( !xInStream.is() ) throw io::IOException(); - OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonPass ), m_nStorageType ); + OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); uno::Reference< io::XStream > xCompStream( static_cast< ::cppu::OWeakObject* >( pStream ), uno::UNO_QUERY ); @@ -1410,7 +1409,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre if ( !xInStream.is() ) throw io::IOException(); - OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonPass ), m_nStorageType ); + OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); uno::Reference< io::XStream > xSeekStream( static_cast< ::cppu::OWeakObject* >( pStream ), uno::UNO_QUERY ); @@ -1512,7 +1511,7 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream() } //----------------------------------------------- -::rtl::OUString OWriteStream_Impl::GetCommonRootPass() +::comphelper::SequenceAsHashMap OWriteStream_Impl::GetCommonRootEncryptionData() throw ( packages::NoEncryptionException ) { ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; @@ -1520,7 +1519,7 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream() if ( m_nStorageType != embed::StorageFormats::PACKAGE || !m_pParent ) throw packages::NoEncryptionException(); - return m_pParent->GetCommonRootPass(); + return m_pParent->GetCommonRootEncryptionData(); } //----------------------------------------------- @@ -1559,11 +1558,11 @@ void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference< io: if ( !xInStream.is() ) throw io::IOException(); - // TODO: remember last state of m_bUseCommonPass + // TODO: remember last state of m_bUseCommonEncryption if ( !xTargetStream.is() ) xTargetStream = uno::Reference< io::XStream > ( static_cast< ::cppu::OWeakObject* >( - new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonPass ), m_nStorageType ) ), + new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonEncryption ), m_nStorageType ) ), uno::UNO_QUERY_THROW ); } @@ -1580,10 +1579,10 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar if ( IsEncrypted() ) { // an encrypted stream must contain input stream - ::rtl::OUString aGlobalPass; + ::comphelper::SequenceAsHashMap aGlobalEncryptionData; try { - aGlobalPass = GetCommonRootPass(); + aGlobalEncryptionData = GetCommonRootEncryptionData(); } catch( packages::NoEncryptionException& aNoEncryptionException ) { @@ -1593,7 +1592,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar throw packages::WrongPasswordException(); } - GetCopyOfLastCommit( xTargetStream, aGlobalPass ); + GetCopyOfLastCommit( xTargetStream, aGlobalEncryptionData ); } else { @@ -1602,12 +1601,12 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar // in case of new inserted package stream it is possible that input stream still was not set GetStreamProperties(); - CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonPass, xTargetStream ); + CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream ); } } //----------------------------------------------- -void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::rtl::OUString& aPass ) +void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::comphelper::SequenceAsHashMap& aEncryptionData ) { ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); @@ -1620,12 +1619,12 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar uno::Reference< io::XInputStream > xDataToCopy; - if ( m_bHasCachedPassword ) + if ( m_bHasCachedEncryptionData ) { // TODO: introduce last commited cashed password information and use it here // that means "use common pass" also should be remembered on flash - uno::Sequence< sal_Int8 > aNewKey = ::package::MakeKeyFromPass( aPass, sal_True ); - uno::Sequence< sal_Int8 > aOldKey = ::package::MakeKeyFromPass( aPass, sal_False ); + uno::Sequence< sal_Int8 > aNewKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ); + uno::Sequence< sal_Int8 > aOldKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ); uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY ); if ( !xProps.is() ) @@ -1647,7 +1646,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar else { uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_True ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ); try { xDataToCopy = m_xPackageStream->getDataStream(); @@ -1660,7 +1659,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar } catch( packages::WrongPasswordException& aWrongPasswordException ) { - SetEncryptionKeyProperty_Impl( xPropertySet, ::package::MakeKeyFromPass( aPass, sal_False ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) ); try { xDataToCopy = m_xPackageStream->getDataStream(); @@ -1696,7 +1695,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar // in case of new inserted package stream it is possible that input stream still was not set GetStreamProperties(); - CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonPass, xTargetStream ); + CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream ); } //----------------------------------------------- @@ -2028,6 +2027,7 @@ uno::Any SAL_CALL OWriteStream::queryInterface( const uno::Type& rType ) { aReturn <<= ::cppu::queryInterface ( rType + , static_cast ( this ) , static_cast ( this ) ); } else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) @@ -2080,7 +2080,7 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes() { if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection + ::cppu::OTypeCollection aTmpCollection ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) @@ -2088,11 +2088,15 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes() , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); + , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) ); + + m_pData->m_pTypeCollection = new ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) + , aTmpCollection.getTypes() ); } else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) { @@ -2138,6 +2142,7 @@ uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes() , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); } @@ -2713,7 +2718,7 @@ void SAL_CALL OWriteStream::setEncryptionPassword( const ::rtl::OUString& aPass OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - m_pImpl->SetEncryptedWithPass( aPass ); + m_pImpl->SetEncrypted( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); ModifyParentUnlockMutex_Impl( aGuard ); } @@ -2740,6 +2745,27 @@ void SAL_CALL OWriteStream::removeEncryption() ModifyParentUnlockMutex_Impl( aGuard ); } +//----------------------------------------------- +void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData ) + throw (io::IOException, uno::RuntimeException) +{ + ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + CheckInitOnDemand(); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException(); + } + + OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); + + m_pImpl->SetEncrypted( aEncryptionData ); + + ModifyParentUnlockMutex_Impl( aGuard ); +} + //----------------------------------------------- sal_Bool SAL_CALL OWriteStream::hasByID( const ::rtl::OUString& sID ) throw ( io::IOException, @@ -3181,24 +3207,24 @@ void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyNa else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equalsAscii( "UseCommonStoragePasswordEncryption" ) ) { - sal_Bool bUseCommonPass = sal_False; - if ( aValue >>= bUseCommonPass ) + sal_Bool bUseCommonEncryption = sal_False; + if ( aValue >>= bUseCommonEncryption ) { if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization ) { // the data stream is provided to the packagestream directly - m_pImpl->m_bUseCommonPass = bUseCommonPass; + m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption; } - else if ( bUseCommonPass ) + else if ( bUseCommonEncryption ) { - if ( !m_pImpl->m_bUseCommonPass ) + if ( !m_pImpl->m_bUseCommonEncryption ) { m_pImpl->SetDecrypted(); - m_pImpl->m_bUseCommonPass = sal_True; + m_pImpl->m_bUseCommonEncryption = sal_True; } } else - m_pImpl->m_bUseCommonPass = sal_False; + m_pImpl->m_bUseCommonEncryption = sal_False; } else throw lang::IllegalArgumentException(); //TODO @@ -3293,7 +3319,7 @@ uno::Any SAL_CALL OWriteStream::getPropertyValue( const ::rtl::OUString& aProp ) } else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equalsAscii( "UseCommonStoragePasswordEncryption" ) ) - return uno::makeAny( m_pImpl->m_bUseCommonPass ); + return uno::makeAny( m_pImpl->m_bUseCommonEncryption ); else if ( aPropertyName.equalsAscii( "Size" ) ) { CheckInitOnDemand(); diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx index 0d4a29893887..08f862b22f6c 100644 --- a/package/source/xstor/owriteablestream.hxx +++ b/package/source/xstor/owriteablestream.hxx @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,6 +53,8 @@ #include #include +#include + #include #include "ocompinstream.hxx" @@ -75,7 +77,7 @@ namespace cppu { namespace package { void StaticAddLog( const ::rtl::OUString& aMessage ); - ::com::sun::star::uno::Sequence< sal_Int8 > MakeKeyFromPass( const ::rtl::OUString& aPass, sal_Bool bUseUTF ); + bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 ); } struct WSInternalData_Impl @@ -127,9 +129,9 @@ struct OWriteStream_Impl : public PreCreationStruct sal_Bool m_bForceEncrypted; - sal_Bool m_bUseCommonPass; - sal_Bool m_bHasCachedPassword; - ::rtl::OUString m_aPass; + sal_Bool m_bUseCommonEncryption; + sal_Bool m_bHasCachedEncryptionData; + ::comphelper::SequenceAsHashMap m_aEncryptionData; sal_Bool m_bCompressedSetExplicit; @@ -161,12 +163,12 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream_Impl( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess ); - ::rtl::OUString GetCommonRootPass() throw ( ::com::sun::star::packages::NoEncryptionException ); + ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException ); ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > ReadPackageStreamProperties(); ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > InsertOwnProps( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Bool bUseCommonPass ); + sal_Bool bUseCommonEncryption ); public: OWriteStream_Impl( @@ -186,7 +188,7 @@ public: void AddLog( const ::rtl::OUString& aMessage ); - sal_Bool UsesCommonPass_Impl() { return m_bUseCommonPass; } + sal_Bool UsesCommonEncryption_Impl() { return m_bUseCommonEncryption; } sal_Bool HasTempFile_Impl() { return ( m_aTempURL.getLength() != 0 ); } sal_Bool IsTransacted(); @@ -198,13 +200,14 @@ public: void SetToBeCommited() { m_bFlushed = sal_True; } - sal_Bool HasCachedPassword() { return m_bHasCachedPassword; } - ::rtl::OUString GetCachedPassword() { return m_aPass; } + sal_Bool HasCachedEncryptionData() { return m_bHasCachedEncryptionData; } + ::comphelper::SequenceAsHashMap& GetCachedEncryptionData() { return m_aEncryptionData; } + sal_Bool IsModified() { return m_bHasDataToFlush || m_bFlushed; } sal_Bool IsEncrypted(); void SetDecrypted(); - void SetEncryptedWithPass( const ::rtl::OUString& aPass ); + void SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData ); void DisposeWrappers(); @@ -226,12 +229,12 @@ public: ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetAllRelationshipsIfAny(); void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream, - const ::rtl::OUString& aPass ); + const ::comphelper::SequenceAsHashMap& aEncryptionData ); void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream( sal_Int32 nStreamMode, - const ::rtl::OUString& aPass, + const ::comphelper::SequenceAsHashMap& aEncryptionData, sal_Bool bHierarchyAccess ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream( @@ -247,13 +250,13 @@ public: void CreateReadonlyCopyBasedOnData( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xDataToCopy, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Bool bUseCommonPass, + sal_Bool bUseCommonEncryption, ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ); void GetCopyOfLastCommit( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ); void GetCopyOfLastCommit( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream, - const ::rtl::OUString& aPass ); + const ::comphelper::SequenceAsHashMap& aEncryptionData ); void CommitStreamRelInfo( @@ -272,7 +275,7 @@ class OWriteStream : ::com::sun::star::lang::XTypeProvider , public ::com::sun::star::embed::XExtendedStorageStream , public ::com::sun::star::io::XSeekable , public ::com::sun::star::io::XTruncate - , public ::com::sun::star::embed::XEncryptionProtectedSource + , public ::com::sun::star::embed::XEncryptionProtectedSource2 , public ::com::sun::star::embed::XRelationshipAccess , public ::com::sun::star::embed::XTransactedObject , public ::com::sun::star::embed::XTransactionBroadcaster @@ -366,6 +369,9 @@ public: throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException ); + //XEncryptionProtectedSource2 + virtual void SAL_CALL setEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + //XRelationshipAccess virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 9c90c4ce35dd..db3ca63f649d 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -207,7 +207,7 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > xInputStream, , m_bListCreated( sal_False ) , m_xFactory( xFactory ) , m_xProperties( xProperties ) -, m_bHasCommonPassword( sal_False ) +, m_bHasCommonEncryptionData( sal_False ) , m_pParent( NULL ) , m_bControlMediaType( sal_False ) , m_bMTFallbackUsed( sal_False ) @@ -247,7 +247,7 @@ OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > xStream, , m_bListCreated( sal_False ) , m_xFactory( xFactory ) , m_xProperties( xProperties ) -, m_bHasCommonPassword( sal_False ) +, m_bHasCommonEncryptionData( sal_False ) , m_pParent( NULL ) , m_bControlMediaType( sal_False ) , m_bMTFallbackUsed( sal_False ) @@ -291,7 +291,7 @@ OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent, , m_xPackageFolder( xPackageFolder ) , m_xPackage( xPackage ) , m_xFactory( xFactory ) -, m_bHasCommonPassword( sal_False ) +, m_bHasCommonEncryptionData( sal_False ) , m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage , m_bControlMediaType( sal_False ) , m_bMTFallbackUsed( sal_False ) @@ -748,10 +748,9 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes { try { - ::rtl::OUString aCommonPass = GetCommonRootPass(); - uno::Reference< embed::XEncryptionProtectedSource > xEncr( xDest, uno::UNO_QUERY ); + uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDest, uno::UNO_QUERY ); if ( xEncr.is() ) - xEncr->setEncryptionPassword( aCommonPass ); + xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() ); } catch( packages::NoEncryptionException& aNoEncryptionException ) { @@ -855,7 +854,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, { aStrProps.realloc( ++nNum ); aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ); - aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonPass_Impl() ); + aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonEncryption_Impl() ); } else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) { @@ -913,15 +912,15 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, OSL_ENSURE( sal_False, "Encryption is only supported in package storage!\n" ); throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } - else if ( pElement->m_pStream->HasCachedPassword() + else if ( pElement->m_pStream->HasCachedEncryptionData() && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) ) { - ::rtl::OUString aCommonPass; - sal_Bool bHasCommonPass = sal_False; + ::comphelper::SequenceAsHashMap aCommonEncryptionData; + sal_Bool bHasCommonEncryptionData = sal_False; try { - aCommonPass = GetCommonRootPass(); - bHasCommonPass = sal_True; + aCommonEncryptionData = GetCommonRootEncryptionData(); + bHasCommonEncryptionData = sal_True; } catch( packages::NoEncryptionException& aNoEncryptionException ) { @@ -929,7 +928,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) ); } - if ( bHasCommonPass && pElement->m_pStream->GetCachedPassword().equals( aCommonPass ) ) + if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) ) { // If the stream can be opened with the common storage password // it must be stored with the common storage password as well @@ -947,13 +946,14 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, else { // the stream is already opened for writing or was changed + uno::Reference< embed::XStorage2 > xDest2( xDest, uno::UNO_QUERY_THROW ); uno::Reference< io::XStream > xSubStr = - xDest->openEncryptedStreamElement( aName, + xDest2->openEncryptedStream( aName, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE, - pElement->m_pStream->GetCachedPassword() ); + pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() ); OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); - pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedPassword() ); + pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() ); } } else @@ -1360,7 +1360,7 @@ void OStorage_Impl::Revert() } //----------------------------------------------- -::rtl::OUString OStorage_Impl::GetCommonRootPass() +::comphelper::SequenceAsHashMap OStorage_Impl::GetCommonRootEncryptionData() throw ( packages::NoEncryptionException ) { ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; @@ -1370,17 +1370,17 @@ void OStorage_Impl::Revert() if ( m_bIsRoot ) { - if ( !m_bHasCommonPassword ) + if ( !m_bHasCommonEncryptionData ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return m_aCommonPassword; + return m_aCommonEncryptionData; } else { if ( !m_pParent ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return m_pParent->GetCommonRootPass(); + return m_pParent->GetCommonRootEncryptionData(); } } @@ -1679,8 +1679,8 @@ void OStorage_Impl::ClearElement( SotElement_Impl* pElement ) //----------------------------------------------- void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName, - sal_Bool bPassProvided, - const ::rtl::OUString& aPass, + sal_Bool bEncryptionDataProvided, + const ::comphelper::SequenceAsHashMap& aEncryptionData, uno::Reference< io::XStream >& xTargetStream ) throw ( embed::InvalidStorageException, lang::IllegalArgumentException, @@ -1712,8 +1712,8 @@ void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName, // storage. The only problem is that some package streams can be accessed from outside // at the same time ( now solwed by wrappers that remember own position ). - if ( bPassProvided ) - pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aPass ); + if ( bEncryptionDataProvided ) + pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData ); else pElement->m_pStream->GetCopyOfLastCommit( xTargetStream ); } @@ -2247,6 +2247,7 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) ( rType , static_cast ( this ) , static_cast ( this ) + , static_cast ( this ) , static_cast ( this ) , static_cast ( this ) , static_cast ( this ) @@ -2254,8 +2255,15 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) , static_cast ( this ) , static_cast ( this ) , static_cast ( this ) - , static_cast ( this ) - , static_cast ( this ) ); + , static_cast ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast ( this ) + , static_cast ( this ) ); if ( aReturn.hasValue() == sal_True ) return aReturn ; @@ -2267,7 +2275,8 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) aReturn <<= ::cppu::queryInterface ( rType , static_cast ( this ) - , static_cast ( this ) ); + , static_cast ( this ) + , static_cast ( this ) ); } else { @@ -2322,10 +2331,12 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() m_pData->m_pTypeCollection = new ::cppu::OTypeCollection ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); } @@ -2334,6 +2345,7 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() m_pData->m_pTypeCollection = new ::cppu::OTypeCollection ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) @@ -2576,100 +2588,7 @@ uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement( { RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStreamElement" ); - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - packages::NoEncryptionException(); - - if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( !aPass.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); - - uno::Reference< io::XStream > xResult; - try - { - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = pElement->m_pStream->GetStream( nOpenMode, aPass, sal_False ); - OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" ); - - if ( m_pData->m_bReadOnlyWrap ) - { - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY ); - if ( !xStreamComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStreamComponent ); - } - } - catch( embed::InvalidStorageException& aInvalidStorageException ) - { - m_pImpl->AddLog( aInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( lang::IllegalArgumentException& aIllegalArgumentException ) - { - m_pImpl->AddLog( aIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( packages::NoEncryptionException& aNoEncryptionException ) - { - m_pImpl->AddLog( aNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( packages::WrongPasswordException& aWrongPasswordException ) - { - m_pImpl->AddLog( aWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException ) - { - m_pImpl->AddLog( aStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( io::IOException& aIOException ) - { - m_pImpl->AddLog( aIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); - - return xResult; + return openEncryptedStream( aStreamName, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); } //----------------------------------------------- @@ -2856,7 +2775,7 @@ uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl try { uno::Reference< io::XStream > xResult; - m_pImpl->CloneStreamElement( aStreamName, sal_False, ::rtl::OUString(), xResult ); + m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xResult ); if ( !xResult.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); return xResult; @@ -2923,80 +2842,7 @@ uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement( { RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStreamElement" ); - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - packages::NoEncryptionException(); - - if ( !aPass.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - try - { - uno::Reference< io::XStream > xResult; - m_pImpl->CloneStreamElement( aStreamName, sal_True, aPass, xResult ); - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return xResult; - } - catch( embed::InvalidStorageException& aInvalidStorageException ) - { - m_pImpl->AddLog( aInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( lang::IllegalArgumentException& aIllegalArgumentException ) - { - m_pImpl->AddLog( aIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( packages::NoEncryptionException& aNoEncryptionException ) - { - m_pImpl->AddLog( aNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( packages::WrongPasswordException& aWrongPasswordException ) - { - m_pImpl->AddLog( aWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( io::IOException& aIOException ) - { - m_pImpl->AddLog( aIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException ) - { - m_pImpl->AddLog( aStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } + return cloneEncryptedStream( aStreamName, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); } //----------------------------------------------- @@ -3720,6 +3566,210 @@ void SAL_CALL OStorage::moveElementTo( const ::rtl::OUString& aElementName, BroadcastModifiedIfNecessary(); } +//____________________________________________________________________________________________________ +// XStorage2 +//____________________________________________________________________________________________________ + +//----------------------------------------------- +uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream( + const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::NoEncryptionException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStream" ); + + ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) + packages::NoEncryptionException(); + + if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) + throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied + + if ( !aEncryptionData.getLength() ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); + + uno::Reference< io::XStream > xResult; + try + { + SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True ); + OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); + + xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_False ); + OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" ); + + if ( m_pData->m_bReadOnlyWrap ) + { + // before the storage disposes the stream it must deregister itself as listener + uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY ); + if ( !xStreamComponent.is() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + + MakeLinkToSubComponent_Impl( xStreamComponent ); + } + } + catch( embed::InvalidStorageException& aInvalidStorageException ) + { + m_pImpl->AddLog( aInvalidStorageException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( lang::IllegalArgumentException& aIllegalArgumentException ) + { + m_pImpl->AddLog( aIllegalArgumentException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( packages::NoEncryptionException& aNoEncryptionException ) + { + m_pImpl->AddLog( aNoEncryptionException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( packages::WrongPasswordException& aWrongPasswordException ) + { + m_pImpl->AddLog( aWrongPasswordException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException ) + { + m_pImpl->AddLog( aStorageWrappedTargetException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( io::IOException& aIOException ) + { + m_pImpl->AddLog( aIOException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ), + uno::Reference< io::XInputStream >(), + aCaught ); + } + + aGuard.clear(); + + BroadcastModifiedIfNecessary(); + + return xResult; +} + +//----------------------------------------------- +uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStream( + const ::rtl::OUString& aStreamName, + const uno::Sequence< beans::NamedValue >& aEncryptionData ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::NoEncryptionException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStream" ); + + ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) + packages::NoEncryptionException(); + + if ( !aEncryptionData.getLength() ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + try + { + uno::Reference< io::XStream > xResult; + m_pImpl->CloneStreamElement( aStreamName, sal_True, aEncryptionData, xResult ); + if ( !xResult.is() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + return xResult; + } + catch( embed::InvalidStorageException& aInvalidStorageException ) + { + m_pImpl->AddLog( aInvalidStorageException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( lang::IllegalArgumentException& aIllegalArgumentException ) + { + m_pImpl->AddLog( aIllegalArgumentException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( packages::NoEncryptionException& aNoEncryptionException ) + { + m_pImpl->AddLog( aNoEncryptionException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( packages::WrongPasswordException& aWrongPasswordException ) + { + m_pImpl->AddLog( aWrongPasswordException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( io::IOException& aIOException ) + { + m_pImpl->AddLog( aIOException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException ) + { + m_pImpl->AddLog( aStorageWrappedTargetException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ), + uno::Reference< io::XInputStream >(), + aCaught ); + } +} + + //____________________________________________________________________________________________________ // XStorageRawAccess //____________________________________________________________________________________________________ @@ -4608,6 +4658,15 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) io::IOException ) { RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionPassword" ); + setEncryptionData( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); +} + +//----------------------------------------------- +void SAL_CALL OStorage::removeEncryption() + throw ( uno::RuntimeException, + io::IOException ) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" ); ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); @@ -4620,8 +4679,7 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionPassword() method is not available for nonroot storages!\n" ); - + OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" ); if ( m_pData->m_bIsRoot ) { try { @@ -4639,12 +4697,15 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), + throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), aCaught ); } + // TODO: check if the password is valid + // update all streams that was encrypted with old password + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); if ( !xPackPropSet.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -4652,10 +4713,10 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) try { xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), - uno::makeAny( ::package::MakeKeyFromPass( aPass, sal_True ) ) ); + uno::makeAny( uno::Sequence< sal_Int8 >() ) ); - m_pImpl->m_bHasCommonPassword = sal_True; - m_pImpl->m_aCommonPassword = aPass; + m_pImpl->m_bHasCommonEncryptionData = sal_False; + m_pImpl->m_aCommonEncryptionData.clear(); } catch( uno::Exception& aException ) { @@ -4668,12 +4729,15 @@ void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) } } -//----------------------------------------------- -void SAL_CALL OStorage::removeEncryption() - throw ( uno::RuntimeException, - io::IOException ) +//____________________________________________________________________________________________________ +// XEncryptionProtectedSource2 +//____________________________________________________________________________________________________ + +void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData ) + throw ( io::IOException, + uno::RuntimeException ) { - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" ); + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionData" ); ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); @@ -4686,8 +4750,10 @@ void SAL_CALL OStorage::removeEncryption() if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" ); + if ( !aEncryptionData.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption data!") ), uno::Reference< uno::XInterface >() ); + OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionData() method is not available for nonroot storages!\n" ); if ( m_pData->m_bIsRoot ) { try { @@ -4705,38 +4771,37 @@ void SAL_CALL OStorage::removeEncryption() m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), + throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), aCaught ); } - // TODO: check if the password is valid - // update all streams that was encrypted with old password - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); if ( !xPackPropSet.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); try { + ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + uno::makeAny( aEncryptionMap.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) ); - m_pImpl->m_bHasCommonPassword = sal_False; - m_pImpl->m_aCommonPassword = ::rtl::OUString(); + m_pImpl->m_bHasCommonEncryptionData = sal_True; + m_pImpl->m_aCommonEncryptionData = aEncryptionMap; } catch( uno::Exception& aException ) { m_pImpl->AddLog( aException.Message ); m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" ); throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } } + } + //____________________________________________________________________________________________________ // XPropertySet //____________________________________________________________________________________________________ @@ -5954,7 +6019,7 @@ void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamNam try { uno::Reference< io::XStream > xNonconstRef = xTargetStream; - m_pImpl->CloneStreamElement( aStreamName, sal_False, ::rtl::OUString(), xNonconstRef ); + m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xNonconstRef ); OSL_ENSURE( xNonconstRef == xTargetStream, "The provided stream reference seems not be filled in correctly!\n" ); if ( xNonconstRef != xTargetStream ) @@ -6082,6 +6147,55 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted io::IOException, embed::StorageWrappedTargetException, uno::RuntimeException ) +{ + return openEncryptedStreamByHierarchicalName( aStreamPath, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( sPassword ) ); +} + +//----------------------------------------------- +void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) + throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); + + if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) + throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied + + OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); + OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); + + if ( !m_pData->m_rHierarchyHolder.is() ) + m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( + uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); + + m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath ); +} + +//____________________________________________________________________________________________________ +// XHierarchicalStorageAccess2 +//____________________________________________________________________________________________________ + +uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::NoEncryptionException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) { ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); @@ -6097,7 +6211,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - if ( !sPassword.getLength() ) + if ( !aEncryptionData.getLength() ) throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) @@ -6117,7 +6231,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); xResult = uno::Reference< embed::XExtendedStorageStream >( - pElement->m_pStream->GetStream( nOpenMode, sPassword, sal_True ), + pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_True ), uno::UNO_QUERY_THROW ); } else @@ -6131,7 +6245,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ), aListPath, nOpenMode, - sPassword ); + aEncryptionData ); } if ( !xResult.is() ) @@ -6140,36 +6254,4 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted return xResult; } -//----------------------------------------------- -void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath ); -} diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx index f1c50e4d67bd..a49de3af6f3a 100644 --- a/package/source/xstor/xstorage.hxx +++ b/package/source/xstor/xstorage.hxx @@ -29,14 +29,14 @@ #define __XSTORAGE_HXX_ #include -#include +#include #include -#include +#include #include #include #include #include -#include +#include #include #include #include @@ -52,8 +52,10 @@ #include #include #include + #include #include +#include #include "mutexholder.hxx" @@ -157,8 +159,8 @@ struct OStorage_Impl ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; // ??? may be stored in properties ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; // ??? may be stored in properties ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_xProperties; - sal_Bool m_bHasCommonPassword; - ::rtl::OUString m_aCommonPassword; + sal_Bool m_bHasCommonEncryptionData; + ::comphelper::SequenceAsHashMap m_aCommonEncryptionData; // must be empty in case of root storage OStorage_Impl* m_pParent; @@ -231,7 +233,7 @@ struct OStorage_Impl void Commit(); void Revert(); - ::rtl::OUString GetCommonRootPass() throw ( ::com::sun::star::packages::NoEncryptionException ); + ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException ); void CopyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, sal_Bool bDirect ); @@ -264,7 +266,7 @@ struct OStorage_Impl void CloneStreamElement( const ::rtl::OUString& aStreamName, sal_Bool bPassProvided, - const ::rtl::OUString& aPass, + const ::comphelper::SequenceAsHashMap& aEncryptionData, ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ) throw ( ::com::sun::star::embed::InvalidStorageException, ::com::sun::star::lang::IllegalArgumentException, @@ -289,18 +291,18 @@ struct OStorage_Impl class OStorage : public ::com::sun::star::lang::XTypeProvider - , public ::com::sun::star::embed::XStorage + , public ::com::sun::star::embed::XStorage2 , public ::com::sun::star::embed::XStorageRawAccess , public ::com::sun::star::embed::XTransactedObject , public ::com::sun::star::embed::XTransactionBroadcaster , public ::com::sun::star::util::XModifiable // , public ::com::sun::star::container::XNameAccess // , public ::com::sun::star::lang::XComponent - , public ::com::sun::star::embed::XEncryptionProtectedSource + , public ::com::sun::star::embed::XEncryptionProtectedSource2 , public ::com::sun::star::beans::XPropertySet , public ::com::sun::star::embed::XOptimizedStorage , public ::com::sun::star::embed::XRelationshipAccess - , public ::com::sun::star::embed::XHierarchicalStorageAccess + , public ::com::sun::star::embed::XHierarchicalStorageAccess2 , public ::cppu::OWeakObject { OStorage_Impl* m_pImpl; @@ -489,6 +491,28 @@ public: ::com::sun::star::embed::StorageWrappedTargetException, ::com::sun::star::uno::RuntimeException ); + //____________________________________________________________________________________________________ + // XStorage2 + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStream( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::NoEncryptionException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStream( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::NoEncryptionException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException); + //____________________________________________________________________________________________________ // XStorageRawAccess //____________________________________________________________________________________________________ @@ -615,6 +639,16 @@ public: throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException ); + //____________________________________________________________________________________________________ + // XEncryptionProtectedSource2 + //____________________________________________________________________________________________________ + + virtual void SAL_CALL setEncryptionData( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) + throw ( ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ // XPropertySet //____________________________________________________________________________________________________ @@ -800,6 +834,18 @@ public: ::com::sun::star::embed::StorageWrappedTargetException, ::com::sun::star::uno::RuntimeException); + //____________________________________________________________________________________________________ + // XHierarchicalStorageAccess2 + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::NoEncryptionException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); }; diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 9ba26e0100c5..846ba7710298 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -1650,7 +1650,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) { - if (!( aValue >>= m_aEncryptionKey ) ) + if (!( aValue >>= m_aEncryptionKey ) || m_aEncryptionKey.getLength() == 0 ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); } else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseManifest") ) ) -- cgit v1.2.3 From 1c0809840b24305e976852940e27c9e315ababd4 Mon Sep 17 00:00:00 2001 From: Mikhail Voytenko Date: Mon, 6 Dec 2010 16:25:17 +0100 Subject: fwk162: #i115789# write manifest:version in manifest:manifest element for ODF1.2 and later --- package/source/manifest/ManifestExport.cxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'package/source') diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx index e4b9ec533c60..6175bdc4e613 100644 --- a/package/source/manifest/ManifestExport.cxx +++ b/package/source/manifest/ManifestExport.cxx @@ -166,6 +166,11 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S { // this is ODF12 generation, let encrypted streams contain start-key-generation entry bStoreStartKeyGeneration = sal_True; + + // starting from ODF12 the version should be also in manifest:manifest element + pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ), + sCdataAttribute, + aDocVersion ); } } else -- cgit v1.2.3 From f77f6f81c934b4b4046c8c37eba71723435736c6 Mon Sep 17 00:00:00 2001 From: Mikhail Voytenko Date: Mon, 6 Dec 2010 17:10:08 +0100 Subject: fwk162: #i115743# directories withou mediatype should not have entries in manifest.xml --- package/source/zippackage/ZipPackageFolder.cxx | 61 ++++++++++++++------------ 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'package/source') diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 903191deb6be..ba83b34910ed 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -271,11 +271,10 @@ Sequence< OUString > SAL_CALL ZipPackageFolder::getElementNames( ) { sal_uInt32 i=0, nSize = maContents.size(); Sequence < OUString > aSequence ( nSize ); - OUString *pNames = aSequence.getArray(); for ( ContentHash::const_iterator aIterator = maContents.begin(), aEnd = maContents.end(); aIterator != aEnd; ++i, ++aIterator) - pNames[i] = (*aIterator).first; + aSequence[i] = (*aIterator).first; return aSequence; } sal_Bool SAL_CALL ZipPackageFolder::hasByName( const OUString& aName ) @@ -358,7 +357,6 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr const ContentInfo &rInfo = *(*aCI).second; Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); - PropertyValue *pValue = aPropSet.getArray(); if ( rInfo.bFolder ) pFolder = rInfo.pFolder; @@ -369,12 +367,17 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr { OUString sTempName = rPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); - pValue[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; - pValue[PKG_MNFST_MEDIATYPE].Value <<= pFolder->GetMediaType(); - pValue[PKG_MNFST_VERSION].Name = sVersionProperty; - pValue[PKG_MNFST_VERSION].Value <<= pFolder->GetVersion(); - pValue[PKG_MNFST_FULLPATH].Name = sFullPathProperty; - pValue[PKG_MNFST_FULLPATH].Value <<= sTempName; + if ( pFolder->GetMediaType().getLength() ) + { + aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; + aPropSet[PKG_MNFST_MEDIATYPE].Value <<= pFolder->GetMediaType(); + aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty; + aPropSet[PKG_MNFST_VERSION].Value <<= pFolder->GetVersion(); + aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; + aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName; + } + else + aPropSet.realloc( 0 ); pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool); } @@ -395,12 +398,12 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr sal_Bool bToBeEncrypted = pStream->IsToBeEncrypted() && (bHaveEncryptionKey || pStream->HasOwnKey()); sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : pStream->IsToBeCompressed(); - pValue[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; - pValue[PKG_MNFST_MEDIATYPE].Value <<= pStream->GetMediaType( ); - pValue[PKG_MNFST_VERSION].Name = sVersionProperty; - pValue[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently - pValue[PKG_MNFST_FULLPATH].Name = sFullPathProperty; - pValue[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath; + aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; + aPropSet[PKG_MNFST_MEDIATYPE].Value <<= pStream->GetMediaType( ); + aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty; + aPropSet[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently + aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; + aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath; OSL_ENSURE( pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" ); @@ -522,23 +525,22 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr // a magic header aPropSet.realloc(PKG_SIZE_ENCR_MNFST); - pValue = aPropSet.getArray(); - pValue[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty; - pValue[PKG_MNFST_INIVECTOR].Value <<= pStream->getInitialisationVector(); - pValue[PKG_MNFST_SALT].Name = sSaltProperty; - pValue[PKG_MNFST_SALT].Value <<= pStream->getSalt(); - pValue[PKG_MNFST_ITERATION].Name = sIterationCountProperty; - pValue[PKG_MNFST_ITERATION].Value <<= pStream->getIterationCount (); + aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty; + aPropSet[PKG_MNFST_INIVECTOR].Value <<= pStream->getInitialisationVector(); + aPropSet[PKG_MNFST_SALT].Name = sSaltProperty; + aPropSet[PKG_MNFST_SALT].Value <<= pStream->getSalt(); + aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty; + aPropSet[PKG_MNFST_ITERATION].Value <<= pStream->getIterationCount (); // Need to store the uncompressed size in the manifest OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" ); - pValue[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty; - pValue[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize; + aPropSet[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty; + aPropSet[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize; if ( bRawStream || bTransportOwnEncrStreamAsRaw ) { - pValue[PKG_MNFST_DIGEST].Name = sDigestProperty; - pValue[PKG_MNFST_DIGEST].Value <<= pStream->getDigest(); + aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; + aPropSet[PKG_MNFST_DIGEST].Value <<= pStream->getDigest(); } } } @@ -655,8 +657,8 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr if ( bToBeEncrypted ) { - pValue[PKG_MNFST_DIGEST].Name = sDigestProperty; - pValue[PKG_MNFST_DIGEST].Value <<= pStream->getDigest(); + aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; + aPropSet[PKG_MNFST_DIGEST].Value <<= pStream->getDigest(); pStream->SetIsEncrypted ( sal_True ); } } @@ -695,7 +697,8 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr } // folder can have a mediatype only in package format - if ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) + if ( aPropSet.getLength() + && ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) ) rManList.push_back( aPropSet ); } -- cgit v1.2.3 From 3dee56f59f881e247b576287210fb2ff602d0645 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 11 Mar 2011 12:07:01 -0500 Subject: Re-added a method removed during merge. --- package/source/xstor/owriteablestream.hxx | 1 + 1 file changed, 1 insertion(+) (limited to 'package/source') diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx index e3b8d583ccfb..0e9884bd75cb 100644 --- a/package/source/xstor/owriteablestream.hxx +++ b/package/source/xstor/owriteablestream.hxx @@ -204,6 +204,7 @@ public: sal_Bool HasCachedEncryptionData() { return m_bHasCachedEncryptionData; } ::comphelper::SequenceAsHashMap& GetCachedEncryptionData() { return m_aEncryptionData; } + sal_Bool IsModified() { return m_bHasDataToFlush || m_bFlushed; } sal_Bool IsEncrypted(); void SetDecrypted(); -- cgit v1.2.3