[Libreoffice-commits] core.git: Branch 'feature/perfwork2' - 3 commits - package/inc package/source
Matúš Kukan
matus.kukan at collabora.com
Wed Oct 15 01:46:12 PDT 2014
package/inc/ZipPackageEntry.hxx | 17
package/inc/ZipPackageFolder.hxx | 24 -
package/inc/ZipPackageStream.hxx | 39 +
package/source/zippackage/ZipPackage.cxx | 8
package/source/zippackage/ZipPackageEntry.cxx | 5
package/source/zippackage/ZipPackageFolder.cxx | 432 --------------------
package/source/zippackage/ZipPackageStream.cxx | 519 +++++++++++++++++++++----
7 files changed, 522 insertions(+), 522 deletions(-)
New commits:
commit f1224493312010c3f180c51dfa550c5a242722a6
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Mon Oct 13 12:37:13 2014 +0200
Move ZipPackageStream::saveChild to proper source file
Change-Id: Icd108215874e830e5c9587f7dbb38a7f11ee27c8
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index 60b2296..4420fdc 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -35,9 +35,7 @@
#include <rtl/digest.h>
#include <ContentInfo.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
#include <EncryptedDataHeader.hxx>
-#include <rtl/random.h>
#include <rtl/instance.hxx>
#include <boost/scoped_ptr.hpp>
@@ -50,8 +48,6 @@ using namespace com::sun::star::beans;
using namespace com::sun::star::lang;
using namespace com::sun::star::io;
using namespace cppu;
-using namespace std;
-using namespace ::com::sun::star;
#if OSL_DEBUG_LEVEL > 0
#define THROW_WHERE SAL_WHERE
@@ -284,18 +280,6 @@ void SAL_CALL ZipPackageFolder::replaceByName( const OUString& aName, const uno:
insertByName(aName, aElement);
}
-static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream> & rStream )
-{
- // It's very annoying that we have to do this, but lots of zip packages
- // don't allow data descriptors for STORED streams, meaning we have to
- // know the size and CRC32 of uncompressed streams before we actually
- // write them !
- CRC32 aCRC32;
- rEntry.nMethod = STORED;
- rEntry.nCompressedSize = rEntry.nSize = aCRC32.updateStream ( rStream );
- rEntry.nCrc = aCRC32.getValue();
-}
-
bool ZipPackageFolder::saveChild(
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
@@ -333,371 +317,6 @@ bool ZipPackageFolder::saveChild(
return bSuccess;
}
-bool ZipPackageStream::saveChild(
- const OUString &rPath,
- std::vector < uno::Sequence < PropertyValue > > &rManList,
- ZipOutputStream & rZipOut,
- const uno::Sequence < sal_Int8 >& rEncryptionKey,
- const rtlRandomPool &rRandomPool)
-{
- bool bSuccess = true;
-
- const OUString sMediaTypeProperty ("MediaType");
- const OUString sVersionProperty ("Version");
- const OUString sFullPathProperty ("FullPath");
- const OUString sInitialisationVectorProperty ("InitialisationVector");
- const OUString sSaltProperty ("Salt");
- const OUString sIterationCountProperty ("IterationCount");
- const OUString sSizeProperty ("Size");
- const OUString sDigestProperty ("Digest");
- const OUString sEncryptionAlgProperty ("EncryptionAlgorithm");
- const OUString sStartKeyAlgProperty ("StartKeyAlgorithm");
- const OUString sDigestAlgProperty ("DigestAlgorithm");
- const OUString sDerivedKeySizeProperty ("DerivedKeySize");
-
- uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
-
- // if pTempEntry is necessary, it will be released and passed to the ZipOutputStream
- // and be deleted in the ZipOutputStream destructor
- unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry );
- ZipEntry* pTempEntry = pAutoTempEntry.get();
-
- // In case the entry we are reading is also the entry we are writing, we will
- // store the ZipEntry data in pTempEntry
-
- ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
- pTempEntry->sPath = rPath;
- pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
-
- bool bToBeEncrypted = IsToBeEncrypted() && (rEncryptionKey.getLength() || HasOwnKey());
- bool bToBeCompressed = bToBeEncrypted ? sal_True : IsToBeCompressed();
-
- aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
- aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType( );
- aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
- aPropSet[PKG_MNFST_VERSION].Value <<= OUString(); // no version is stored for streams currently
- aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
- aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
-
- OSL_ENSURE( GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
-
- bool bRawStream = false;
- if ( GetStreamMode() == PACKAGE_STREAM_DETECT )
- bRawStream = ParsePackageRawStream();
- else if ( GetStreamMode() == PACKAGE_STREAM_RAW )
- bRawStream = true;
-
- bool bTransportOwnEncrStreamAsRaw = false;
- // During the storing the original size of the stream can be changed
- // TODO/LATER: get rid of this hack
- sal_Int64 nOwnStreamOrigSize = bRawStream ? GetMagicalHackSize() : getSize();
-
- bool bUseNonSeekableAccess = false;
- uno::Reference < XInputStream > xStream;
- if ( !IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
- {
- // the stream is not a package member, not a raw stream,
- // it should not be encrypted and it should be compressed,
- // in this case nonseekable access can be used
-
- xStream = GetOwnStreamNoWrap();
- uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY );
-
- bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
- }
-
- if ( !bUseNonSeekableAccess )
- {
- xStream = getRawData();
-
- if ( !xStream.is() )
- {
- OSL_FAIL( "ZipPackageStream didn't have a stream associated with it, skipping!" );
- bSuccess = false;
- return bSuccess;
- }
-
- uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY );
- try
- {
- if ( xSeek.is() )
- {
- // If the stream is a raw one, then we should be positioned
- // at the beginning of the actual data
- if ( !bToBeCompressed || bRawStream )
- {
- // The raw stream can neither be encrypted nor connected
- OSL_ENSURE( !bRawStream || !(bToBeCompressed || bToBeEncrypted), "The stream is already encrypted!\n" );
- xSeek->seek ( bRawStream ? GetMagicalHackPos() : 0 );
- ImplSetStoredData ( *pTempEntry, xStream );
-
- // TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
- }
- else if ( bToBeEncrypted )
- {
- // this is the correct original size
- pTempEntry->nSize = xSeek->getLength();
- nOwnStreamOrigSize = pTempEntry->nSize;
- }
-
- xSeek->seek ( 0 );
- }
- else
- {
- // Okay, we don't have an xSeekable stream. This is possibly bad.
- // check if it's one of our own streams, if it is then we know that
- // each time we ask for it we'll get a new stream that will be
- // at position zero...otherwise, assert and skip this stream...
- if ( IsPackageMember() )
- {
- // if the password has been changed than the stream should not be package member any more
- if ( IsEncrypted() && IsToBeEncrypted() )
- {
- // Should be handled close to the raw stream handling
- bTransportOwnEncrStreamAsRaw = true;
- pTempEntry->nMethod = STORED;
-
- // TODO/LATER: get rid of this situation
- // this size should be different from the one that will be stored in manifest.xml
- // it is used in storing algorithms and after storing the correct size will be set
- pTempEntry->nSize = pTempEntry->nCompressedSize;
- }
- }
- else
- {
- bSuccess = false;
- return bSuccess;
- }
- }
- }
- catch ( uno::Exception& )
- {
- bSuccess = false;
- return bSuccess;
- }
-
- if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw )
- {
- if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw )
- {
- uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( GetBlockSize() );
- rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 );
- rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() );
- sal_Int32 nIterationCount = 1024;
-
- if ( !HasOwnKey() )
- setKey ( rEncryptionKey );
-
- setInitialisationVector ( aVector );
- setSalt ( aSalt );
- setIterationCount ( nIterationCount );
- }
-
- // last property is digest, which is inserted later if we didn't have
- // a magic header
- aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
-
- aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
- aPropSet[PKG_MNFST_INIVECTOR].Value <<= getInitialisationVector();
- aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
- aPropSet[PKG_MNFST_SALT].Value <<= getSalt();
- aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
- aPropSet[PKG_MNFST_ITERATION].Value <<= getIterationCount ();
-
- // Need to store the uncompressed size in the manifest
- OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
- aPropSet[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty;
- aPropSet[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize;
-
- if ( bRawStream || bTransportOwnEncrStreamAsRaw )
- {
- ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
- if ( !xEncData.is() )
- throw uno::RuntimeException();
-
- aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
- aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
- aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
- aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
- aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
- aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
- aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
- aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
- aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
- aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
- }
- }
- }
-
- // If the entry is already stored in the zip file in the format we
- // want for this write...copy it raw
- if ( !bUseNonSeekableAccess
- && ( bRawStream || bTransportOwnEncrStreamAsRaw
- || ( IsPackageMember() && !bToBeEncrypted
- && ( ( aEntry.nMethod == DEFLATED && bToBeCompressed )
- || ( aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
- {
- // If it's a PackageMember, then it's an unbuffered stream and we need
- // to get a new version of it as we can't seek backwards.
- if ( IsPackageMember() )
- {
- xStream = getRawData();
- if ( !xStream.is() )
- {
- // Make sure that we actually _got_ a new one !
- bSuccess = false;
- return bSuccess;
- }
- }
-
- try
- {
- if ( bRawStream )
- xStream->skipBytes( GetMagicalHackPos() );
-
- ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, false);
- // the entry is provided to the ZipOutputStream that will delete it
- pAutoTempEntry.release();
-
- uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
- sal_Int32 nLength;
-
- do
- {
- nLength = xStream->readBytes( aSeq, n_ConstBufferSize );
- aZipEntry.rawWrite(aSeq, 0, nLength);
- }
- while ( nLength == n_ConstBufferSize );
-
- aZipEntry.rawCloseEntry();
- rZipOut.addEntry(pTempEntry);
- }
- catch ( ZipException& )
- {
- bSuccess = false;
- }
- catch ( IOException& )
- {
- bSuccess = false;
- }
- }
- else
- {
- // This stream is defenitly not a raw stream
-
- // If nonseekable access is used the stream should be at the beginning and
- // is useless after the storing. Thus if the storing fails the package should
- // be thrown away ( as actually it is done currently )!
- // To allow to reuse the package after the error, the optimization must be removed!
-
- // If it's a PackageMember, then our previous reference held a 'raw' stream
- // so we need to re-get it, unencrypted, uncompressed and positioned at the
- // beginning of the stream
- if ( IsPackageMember() )
- {
- xStream = getInputStream();
- if ( !xStream.is() )
- {
- // Make sure that we actually _got_ a new one !
- bSuccess = false;
- return bSuccess;
- }
- }
-
- if ( bToBeCompressed )
- {
- pTempEntry->nMethod = DEFLATED;
- pTempEntry->nCrc = -1;
- pTempEntry->nCompressedSize = pTempEntry->nSize = -1;
- }
-
- try
- {
- ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, bToBeEncrypted);
- // the entry is provided to the ZipOutputStream that will delete it
- pAutoTempEntry.release();
-
- sal_Int32 nLength;
- uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize);
- do
- {
- nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
- aZipEntry.write(aSeq, 0, nLength);
- }
- while ( nLength == n_ConstBufferSize );
-
- aZipEntry.closeEntry();
- rZipOut.addEntry(pTempEntry);
- }
- catch ( ZipException& )
- {
- bSuccess = false;
- }
- catch ( IOException& )
- {
- bSuccess = false;
- }
-
- if ( bToBeEncrypted )
- {
- ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
- if ( !xEncData.is() )
- throw uno::RuntimeException();
-
- aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
- aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
- aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
- aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
- aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
- aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
- aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
- aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
- aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
- aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
-
- SetIsEncrypted ( true );
- }
- }
-
- if( bSuccess )
- {
- if ( !IsPackageMember() )
- {
- CloseOwnStreamIfAny();
- SetPackageMember ( true );
- }
-
- if ( bRawStream )
- {
- // the raw stream was integrated and now behaves
- // as usual encrypted stream
- SetToBeEncrypted( true );
- }
-
- // Then copy it back afterwards...
- ZipPackageFolder::copyZipEntry ( aEntry, *pTempEntry );
-
- // Remove hacky bit from entry flags
- if ( aEntry.nFlag & ( 1 << 4 ) )
- {
- aEntry.nFlag &= ~( 1 << 4 );
- aEntry.nMethod = STORED;
- }
-
- // TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
- if ( IsEncrypted() )
- setSize( nOwnStreamOrigSize );
-
- aEntry.nOffset *= -1;
- }
-
- if ( aPropSet.getLength()
- && ( m_nFormat == embed::StorageFormats::PACKAGE || m_nFormat == embed::StorageFormats::OFOPXML ) )
- rManList.push_back( aPropSet );
-
- return bSuccess;
-}
-
void ZipPackageFolder::saveContents(
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 10ea847..1f161cd 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <ZipPackageStream.hxx>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/packages/zip/ZipConstants.hpp>
#include <com/sun/star/embed/StorageFormats.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
@@ -30,8 +33,11 @@
#include <string.h>
-#include <ZipPackageStream.hxx>
+#include <CRC32.hxx>
+#include <ZipOutputEntry.hxx>
+#include <ZipOutputStream.hxx>
#include <ZipPackage.hxx>
+#include <ZipPackageFolder.hxx>
#include <ZipFile.hxx>
#include <EncryptedDataHeader.hxx>
#include <osl/diagnose.h>
@@ -44,6 +50,7 @@
#include <cppuhelper/typeprovider.hxx>
#include <rtl/instance.hxx>
+#include <rtl/random.h>
#include <PackageConstants.hxx>
@@ -430,6 +437,383 @@ bool ZipPackageStream::ParsePackageRawStream()
return true;
}
+static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< io::XInputStream> & rStream )
+{
+ // It's very annoying that we have to do this, but lots of zip packages
+ // don't allow data descriptors for STORED streams, meaning we have to
+ // know the size and CRC32 of uncompressed streams before we actually
+ // write them !
+ CRC32 aCRC32;
+ rEntry.nMethod = STORED;
+ rEntry.nCompressedSize = rEntry.nSize = aCRC32.updateStream ( rStream );
+ rEntry.nCrc = aCRC32.getValue();
+}
+
+bool ZipPackageStream::saveChild(
+ const OUString &rPath,
+ std::vector < uno::Sequence < beans::PropertyValue > > &rManList,
+ ZipOutputStream & rZipOut,
+ const uno::Sequence < sal_Int8 >& rEncryptionKey,
+ const rtlRandomPool &rRandomPool)
+{
+ bool bSuccess = true;
+
+ const OUString sMediaTypeProperty ("MediaType");
+ const OUString sVersionProperty ("Version");
+ const OUString sFullPathProperty ("FullPath");
+ const OUString sInitialisationVectorProperty ("InitialisationVector");
+ const OUString sSaltProperty ("Salt");
+ const OUString sIterationCountProperty ("IterationCount");
+ const OUString sSizeProperty ("Size");
+ const OUString sDigestProperty ("Digest");
+ const OUString sEncryptionAlgProperty ("EncryptionAlgorithm");
+ const OUString sStartKeyAlgProperty ("StartKeyAlgorithm");
+ const OUString sDigestAlgProperty ("DigestAlgorithm");
+ const OUString sDerivedKeySizeProperty ("DerivedKeySize");
+
+ uno::Sequence < beans::PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
+
+ // if pTempEntry is necessary, it will be released and passed to the ZipOutputStream
+ // and be deleted in the ZipOutputStream destructor
+ std::unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry );
+ ZipEntry* pTempEntry = pAutoTempEntry.get();
+
+ // In case the entry we are reading is also the entry we are writing, we will
+ // store the ZipEntry data in pTempEntry
+
+ ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
+ pTempEntry->sPath = rPath;
+ pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
+
+ bool bToBeEncrypted = IsToBeEncrypted() && (rEncryptionKey.getLength() || HasOwnKey());
+ bool bToBeCompressed = bToBeEncrypted ? sal_True : IsToBeCompressed();
+
+ aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
+ aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType( );
+ aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
+ aPropSet[PKG_MNFST_VERSION].Value <<= OUString(); // no version is stored for streams currently
+ aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
+ aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
+
+ OSL_ENSURE( GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
+
+ bool bRawStream = false;
+ if ( GetStreamMode() == PACKAGE_STREAM_DETECT )
+ bRawStream = ParsePackageRawStream();
+ else if ( GetStreamMode() == PACKAGE_STREAM_RAW )
+ bRawStream = true;
+
+ bool bTransportOwnEncrStreamAsRaw = false;
+ // During the storing the original size of the stream can be changed
+ // TODO/LATER: get rid of this hack
+ sal_Int64 nOwnStreamOrigSize = bRawStream ? GetMagicalHackSize() : getSize();
+
+ bool bUseNonSeekableAccess = false;
+ uno::Reference < io::XInputStream > xStream;
+ if ( !IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
+ {
+ // the stream is not a package member, not a raw stream,
+ // it should not be encrypted and it should be compressed,
+ // in this case nonseekable access can be used
+
+ xStream = GetOwnStreamNoWrap();
+ uno::Reference < io::XSeekable > xSeek ( xStream, uno::UNO_QUERY );
+
+ bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
+ }
+
+ if ( !bUseNonSeekableAccess )
+ {
+ xStream = getRawData();
+
+ if ( !xStream.is() )
+ {
+ OSL_FAIL( "ZipPackageStream didn't have a stream associated with it, skipping!" );
+ bSuccess = false;
+ return bSuccess;
+ }
+
+ uno::Reference < io::XSeekable > xSeek ( xStream, uno::UNO_QUERY );
+ try
+ {
+ if ( xSeek.is() )
+ {
+ // If the stream is a raw one, then we should be positioned
+ // at the beginning of the actual data
+ if ( !bToBeCompressed || bRawStream )
+ {
+ // The raw stream can neither be encrypted nor connected
+ OSL_ENSURE( !bRawStream || !(bToBeCompressed || bToBeEncrypted), "The stream is already encrypted!\n" );
+ xSeek->seek ( bRawStream ? GetMagicalHackPos() : 0 );
+ ImplSetStoredData ( *pTempEntry, xStream );
+
+ // TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
+ }
+ else if ( bToBeEncrypted )
+ {
+ // this is the correct original size
+ pTempEntry->nSize = xSeek->getLength();
+ nOwnStreamOrigSize = pTempEntry->nSize;
+ }
+
+ xSeek->seek ( 0 );
+ }
+ else
+ {
+ // Okay, we don't have an xSeekable stream. This is possibly bad.
+ // check if it's one of our own streams, if it is then we know that
+ // each time we ask for it we'll get a new stream that will be
+ // at position zero...otherwise, assert and skip this stream...
+ if ( IsPackageMember() )
+ {
+ // if the password has been changed than the stream should not be package member any more
+ if ( IsEncrypted() && IsToBeEncrypted() )
+ {
+ // Should be handled close to the raw stream handling
+ bTransportOwnEncrStreamAsRaw = true;
+ pTempEntry->nMethod = STORED;
+
+ // TODO/LATER: get rid of this situation
+ // this size should be different from the one that will be stored in manifest.xml
+ // it is used in storing algorithms and after storing the correct size will be set
+ pTempEntry->nSize = pTempEntry->nCompressedSize;
+ }
+ }
+ else
+ {
+ bSuccess = false;
+ return bSuccess;
+ }
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ bSuccess = false;
+ return bSuccess;
+ }
+
+ if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw )
+ {
+ if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw )
+ {
+ uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( GetBlockSize() );
+ rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 );
+ rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() );
+ sal_Int32 nIterationCount = 1024;
+
+ if ( !HasOwnKey() )
+ setKey ( rEncryptionKey );
+
+ setInitialisationVector ( aVector );
+ setSalt ( aSalt );
+ setIterationCount ( nIterationCount );
+ }
+
+ // last property is digest, which is inserted later if we didn't have
+ // a magic header
+ aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
+
+ aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
+ aPropSet[PKG_MNFST_INIVECTOR].Value <<= getInitialisationVector();
+ aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
+ aPropSet[PKG_MNFST_SALT].Value <<= getSalt();
+ aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
+ aPropSet[PKG_MNFST_ITERATION].Value <<= getIterationCount ();
+
+ // Need to store the uncompressed size in the manifest
+ OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
+ aPropSet[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty;
+ aPropSet[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize;
+
+ if ( bRawStream || bTransportOwnEncrStreamAsRaw )
+ {
+ ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
+ if ( !xEncData.is() )
+ throw uno::RuntimeException();
+
+ aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
+ aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
+ aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
+ aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
+ aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
+ aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
+ aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
+ aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
+ aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
+ aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
+ }
+ }
+ }
+
+ // If the entry is already stored in the zip file in the format we
+ // want for this write...copy it raw
+ if ( !bUseNonSeekableAccess
+ && ( bRawStream || bTransportOwnEncrStreamAsRaw
+ || ( IsPackageMember() && !bToBeEncrypted
+ && ( ( aEntry.nMethod == DEFLATED && bToBeCompressed )
+ || ( aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
+ {
+ // If it's a PackageMember, then it's an unbuffered stream and we need
+ // to get a new version of it as we can't seek backwards.
+ if ( IsPackageMember() )
+ {
+ xStream = getRawData();
+ if ( !xStream.is() )
+ {
+ // Make sure that we actually _got_ a new one !
+ bSuccess = false;
+ return bSuccess;
+ }
+ }
+
+ try
+ {
+ if ( bRawStream )
+ xStream->skipBytes( GetMagicalHackPos() );
+
+ ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, false);
+ // the entry is provided to the ZipOutputStream that will delete it
+ pAutoTempEntry.release();
+
+ uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
+ sal_Int32 nLength;
+
+ do
+ {
+ nLength = xStream->readBytes( aSeq, n_ConstBufferSize );
+ aZipEntry.rawWrite(aSeq, 0, nLength);
+ }
+ while ( nLength == n_ConstBufferSize );
+
+ aZipEntry.rawCloseEntry();
+ rZipOut.addEntry(pTempEntry);
+ }
+ catch ( ZipException& )
+ {
+ bSuccess = false;
+ }
+ catch ( io::IOException& )
+ {
+ bSuccess = false;
+ }
+ }
+ else
+ {
+ // This stream is defenitly not a raw stream
+
+ // If nonseekable access is used the stream should be at the beginning and
+ // is useless after the storing. Thus if the storing fails the package should
+ // be thrown away ( as actually it is done currently )!
+ // To allow to reuse the package after the error, the optimization must be removed!
+
+ // If it's a PackageMember, then our previous reference held a 'raw' stream
+ // so we need to re-get it, unencrypted, uncompressed and positioned at the
+ // beginning of the stream
+ if ( IsPackageMember() )
+ {
+ xStream = getInputStream();
+ if ( !xStream.is() )
+ {
+ // Make sure that we actually _got_ a new one !
+ bSuccess = false;
+ return bSuccess;
+ }
+ }
+
+ if ( bToBeCompressed )
+ {
+ pTempEntry->nMethod = DEFLATED;
+ pTempEntry->nCrc = -1;
+ pTempEntry->nCompressedSize = pTempEntry->nSize = -1;
+ }
+
+ try
+ {
+ ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, bToBeEncrypted);
+ // the entry is provided to the ZipOutputStream that will delete it
+ pAutoTempEntry.release();
+
+ sal_Int32 nLength;
+ uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize);
+ do
+ {
+ nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
+ aZipEntry.write(aSeq, 0, nLength);
+ }
+ while ( nLength == n_ConstBufferSize );
+
+ aZipEntry.closeEntry();
+ rZipOut.addEntry(pTempEntry);
+ }
+ catch ( ZipException& )
+ {
+ bSuccess = false;
+ }
+ catch ( io::IOException& )
+ {
+ bSuccess = false;
+ }
+
+ if ( bToBeEncrypted )
+ {
+ ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
+ if ( !xEncData.is() )
+ throw uno::RuntimeException();
+
+ aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
+ aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
+ aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
+ aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
+ aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
+ aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
+ aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
+ aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
+ aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
+ aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
+
+ SetIsEncrypted ( true );
+ }
+ }
+
+ if( bSuccess )
+ {
+ if ( !IsPackageMember() )
+ {
+ CloseOwnStreamIfAny();
+ SetPackageMember ( true );
+ }
+
+ if ( bRawStream )
+ {
+ // the raw stream was integrated and now behaves
+ // as usual encrypted stream
+ SetToBeEncrypted( true );
+ }
+
+ // Then copy it back afterwards...
+ ZipPackageFolder::copyZipEntry ( aEntry, *pTempEntry );
+
+ // Remove hacky bit from entry flags
+ if ( aEntry.nFlag & ( 1 << 4 ) )
+ {
+ aEntry.nFlag &= ~( 1 << 4 );
+ aEntry.nMethod = STORED;
+ }
+
+ // TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
+ if ( IsEncrypted() )
+ setSize( nOwnStreamOrigSize );
+
+ aEntry.nOffset *= -1;
+ }
+
+ if ( aPropSet.getLength()
+ && ( m_nFormat == embed::StorageFormats::PACKAGE || m_nFormat == embed::StorageFormats::OFOPXML ) )
+ rManList.push_back( aPropSet );
+
+ return bSuccess;
+}
+
void ZipPackageStream::SetPackageMember( bool bNewValue )
{
if ( bNewValue )
commit d3d60a1ac374dde9581d8307c88d0dbb397d7f2f
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Mon Oct 13 09:54:28 2014 +0200
package: Add pure virtual ZipPackageEntry::saveChild()
..and adapt what needs to be changed.
So that, we can kill at least some usages of horrible ContentInfo struct.
Change-Id: I32d41f3b8ce2dfb65f0d1df18a540a3f67dcab6d
diff --git a/package/inc/ZipPackageEntry.hxx b/package/inc/ZipPackageEntry.hxx
index cfe1895..d1ff8de 100644
--- a/package/inc/ZipPackageEntry.hxx
+++ b/package/inc/ZipPackageEntry.hxx
@@ -21,13 +21,19 @@
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
#include <ZipEntry.hxx>
#include <cppuhelper/implbase5.hxx>
+#include <vector>
+
+typedef void* rtlRandomPool;
+class ZipOutputStream;
class ZipPackageFolder;
class ZipPackageEntry : public cppu::WeakImplHelper5
@@ -40,15 +46,18 @@ class ZipPackageEntry : public cppu::WeakImplHelper5
>
{
protected:
+ css::uno::Reference< css::uno::XComponentContext > m_xContext;
OUString msName;
bool mbIsFolder:1;
bool mbAllowRemoveOnInsert:1;
// com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xParent;
OUString msMediaType;
ZipPackageFolder* mpParent;
+ sal_Int32 m_nFormat;
+
public:
ZipEntry aEntry;
- ZipPackageEntry ( bool bNewFolder = false );
+ ZipPackageEntry();
virtual ~ZipPackageEntry( void );
const OUString& GetMediaType () const { return msMediaType; }
@@ -58,6 +67,12 @@ public:
const ZipPackageFolder* GetParent () const { return mpParent; }
void SetFolder ( bool bSetFolder ) { mbIsFolder = bSetFolder; }
+ virtual bool saveChild( const OUString &rPath,
+ std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
+ ZipOutputStream & rZipOut,
+ const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
+ const rtlRandomPool &rRandomPool ) = 0;
+
void clearParent ( void )
{
// xParent.clear();
diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx
index dd0ff95..52a64e6 100644
--- a/package/inc/ZipPackageFolder.hxx
+++ b/package/inc/ZipPackageFolder.hxx
@@ -28,20 +28,8 @@
#include <cppuhelper/implbase2.hxx>
#include <vector>
-namespace com { namespace sun { namespace star {
-namespace beans
-{
- struct PropertyValue;
-}
-namespace packages
-{
- class ContentInfo;
-}
-} } }
-
class ZipOutputStream;
struct ZipEntry;
-typedef void* rtlRandomPool;
class ZipPackageFolder : public cppu::ImplInheritanceHelper2
<
@@ -51,14 +39,12 @@ class ZipPackageFolder : public cppu::ImplInheritanceHelper2
>
{
private:
- css::uno::Reference< css::uno::XComponentContext> m_xContext;
ContentHash maContents;
- sal_Int32 m_nFormat;
OUString m_sVersion;
public:
- ZipPackageFolder( css::uno::Reference< css::uno::XComponentContext> xContext,
+ ZipPackageFolder( const css::uno::Reference < css::uno::XComponentContext >& xContext,
sal_Int32 nFormat,
bool bAllowRemoveOnInsert );
virtual ~ZipPackageFolder();
@@ -80,7 +66,13 @@ public:
static ::com::sun::star::uno::Sequence < sal_Int8 > static_getImplementationId();
void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; }
- void setRemoveOnInsertMode_Impl( bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; }
+ void setRemoveOnInsertMode_Impl( bool bRemove ) { mbAllowRemoveOnInsert = bRemove; }
+
+ virtual bool saveChild( const OUString &rPath,
+ std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
+ ZipOutputStream & rZipOut,
+ const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
+ const rtlRandomPool &rRandomPool ) SAL_OVERRIDE;
// Recursive functions
void saveContents(
diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx
index 0e395a3..3fec409 100644
--- a/package/inc/ZipPackageStream.hxx
+++ b/package/inc/ZipPackageStream.hxx
@@ -48,7 +48,6 @@ class ZipPackageStream : public cppu::ImplInheritanceHelper2
{
private:
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xStream;
- const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
ZipPackage &m_rZipPackage;
bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
@@ -140,9 +139,10 @@ public:
void CloseOwnStreamIfAny();
- ZipPackageStream ( ZipPackage & rNewPackage,
- const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext >& xContext,
- bool bAllowRemoveOnInsert );
+ ZipPackageStream( ZipPackage & rNewPackage,
+ const css::uno::Reference < css::uno::XComponentContext >& xContext,
+ sal_Int32 nFormat,
+ bool bAllowRemoveOnInsert );
virtual ~ZipPackageStream( void );
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
@@ -150,6 +150,11 @@ public:
bool bAddHeaderForEncr );
bool ParsePackageRawStream();
+ virtual bool saveChild( const OUString &rPath,
+ std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
+ ZipOutputStream & rZipOut,
+ const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
+ const rtlRandomPool &rRandomPool ) SAL_OVERRIDE;
void setZipEntryOnLoading( const ZipEntry &rInEntry);
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 0a26c5a..63fee5d 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -556,7 +556,7 @@ void ZipPackage::getZipFileContents()
{
nStreamIndex++;
sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex );
- pPkgStream = new ZipPackageStream( *this, m_xContext, m_bAllowRemoveOnInsert );
+ pPkgStream = new ZipPackageStream( *this, m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
pPkgStream->SetPackageMember( true );
pPkgStream->setZipEntryOnLoading( rEntry );
pPkgStream->setName( sTemp );
@@ -942,7 +942,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance()
throw( Exception, RuntimeException, std::exception )
{
- uno::Reference < XInterface > xRef = *( new ZipPackageStream ( *this, m_xContext, m_bAllowRemoveOnInsert ) );
+ uno::Reference < XInterface > xRef = *( new ZipPackageStream( *this, m_xContext, m_nFormat, m_bAllowRemoveOnInsert ) );
return xRef;
}
@@ -954,9 +954,9 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c
if ( aArguments.getLength() )
aArguments[0] >>= bArg;
if ( bArg )
- xRef = *new ZipPackageFolder ( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
+ xRef = *new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
else
- xRef = *new ZipPackageStream ( *this, m_xContext, m_bAllowRemoveOnInsert );
+ xRef = *new ZipPackageStream( *this, m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
return xRef;
}
diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx
index 860f717..4d5d63d 100644
--- a/package/source/zippackage/ZipPackageEntry.cxx
+++ b/package/source/zippackage/ZipPackageEntry.cxx
@@ -40,9 +40,8 @@ using namespace com::sun::star::packages::zip::ZipConstants;
#define THROW_WHERE ""
#endif
-ZipPackageEntry::ZipPackageEntry ( bool bNewFolder )
-: mbIsFolder ( bNewFolder )
-, mbAllowRemoveOnInsert( true )
+ZipPackageEntry::ZipPackageEntry()
+: mbIsFolder( false )
, mpParent ( NULL )
{
}
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index c6a3b37..60b2296 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -61,14 +61,13 @@ using namespace ::com::sun::star;
namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationId, lcl_CachedImplId > {}; }
-ZipPackageFolder::ZipPackageFolder ( css::uno::Reference< css::uno::XComponentContext> xContext,
- sal_Int32 nFormat,
- bool bAllowRemoveOnInsert )
- : m_xContext( xContext )
- , m_nFormat( nFormat )
+ZipPackageFolder::ZipPackageFolder( const css::uno::Reference < css::uno::XComponentContext >& xContext,
+ sal_Int32 nFormat,
+ bool bAllowRemoveOnInsert )
{
- this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
-
+ m_xContext = xContext;
+ m_nFormat = nFormat;
+ mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
SetFolder ( true );
aEntry.nVersion = -1;
aEntry.nFlag = 0;
@@ -297,14 +296,12 @@ static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream>
rEntry.nCrc = aCRC32.getValue();
}
-static bool ZipPackageFolder_saveChild(
- const ContentInfo &rInfo,
+bool ZipPackageFolder::saveChild(
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey,
- const rtlRandomPool &rRandomPool,
- sal_Int32 nFormat)
+ const rtlRandomPool &rRandomPool)
{
bool bSuccess = true;
@@ -313,42 +310,35 @@ static bool ZipPackageFolder_saveChild(
const OUString sFullPathProperty ("FullPath");
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
-
- assert( rInfo.bFolder && rInfo.pFolder && "A valid child object is expected!" );
-
OUString sTempName = rPath + "/";
- if ( !rInfo.pFolder->GetMediaType().isEmpty() )
+ if ( !GetMediaType().isEmpty() )
{
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
- aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pFolder->GetMediaType();
+ aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType();
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
- aPropSet[PKG_MNFST_VERSION].Value <<= rInfo.pFolder->GetVersion();
+ aPropSet[PKG_MNFST_VERSION].Value <<= GetVersion();
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName;
}
else
aPropSet.realloc( 0 );
- rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
+ saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
// folder can have a mediatype only in package format
- if ( aPropSet.getLength()
- && ( nFormat == embed::StorageFormats::PACKAGE || ( nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
+ if ( aPropSet.getLength() && ( m_nFormat == embed::StorageFormats::PACKAGE ) )
rManList.push_back( aPropSet );
return bSuccess;
}
-static bool ZipPackageStream_saveChild(
- css::uno::Reference< css::uno::XComponentContext> xContext,
- const ContentInfo &rInfo,
+bool ZipPackageStream::saveChild(
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey,
- const rtlRandomPool &rRandomPool,
- sal_Int32 nFormat)
+ const rtlRandomPool &rRandomPool)
{
bool bSuccess = true;
@@ -367,8 +357,6 @@ static bool ZipPackageStream_saveChild(
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
- assert( !rInfo.bFolder && rInfo.pStream && "A valid child object is expected!" );
-
// if pTempEntry is necessary, it will be released and passed to the ZipOutputStream
// and be deleted in the ZipOutputStream destructor
unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry );
@@ -377,42 +365,42 @@ static bool ZipPackageStream_saveChild(
// In case the entry we are reading is also the entry we are writing, we will
// store the ZipEntry data in pTempEntry
- ZipPackageFolder::copyZipEntry ( *pTempEntry, rInfo.pStream->aEntry );
+ ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
pTempEntry->sPath = rPath;
pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
- bool bToBeEncrypted = rInfo.pStream->IsToBeEncrypted() && (rEncryptionKey.getLength() || rInfo.pStream->HasOwnKey());
- bool bToBeCompressed = bToBeEncrypted ? sal_True : rInfo.pStream->IsToBeCompressed();
+ bool bToBeEncrypted = IsToBeEncrypted() && (rEncryptionKey.getLength() || HasOwnKey());
+ bool bToBeCompressed = bToBeEncrypted ? sal_True : IsToBeCompressed();
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
- aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pStream->GetMediaType( );
+ aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType( );
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= OUString(); // no version is stored for streams currently
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
- OSL_ENSURE( rInfo.pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
+ OSL_ENSURE( GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
bool bRawStream = false;
- if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_DETECT )
- bRawStream = rInfo.pStream->ParsePackageRawStream();
- else if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_RAW )
+ if ( GetStreamMode() == PACKAGE_STREAM_DETECT )
+ bRawStream = ParsePackageRawStream();
+ else if ( GetStreamMode() == PACKAGE_STREAM_RAW )
bRawStream = true;
bool bTransportOwnEncrStreamAsRaw = false;
// During the storing the original size of the stream can be changed
// TODO/LATER: get rid of this hack
- sal_Int64 nOwnStreamOrigSize = bRawStream ? rInfo.pStream->GetMagicalHackSize() : rInfo.pStream->getSize();
+ sal_Int64 nOwnStreamOrigSize = bRawStream ? GetMagicalHackSize() : getSize();
bool bUseNonSeekableAccess = false;
uno::Reference < XInputStream > xStream;
- if ( !rInfo.pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
+ if ( !IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
{
// the stream is not a package member, not a raw stream,
// it should not be encrypted and it should be compressed,
// in this case nonseekable access can be used
- xStream = rInfo.pStream->GetOwnStreamNoWrap();
+ xStream = GetOwnStreamNoWrap();
uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY );
bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
@@ -420,7 +408,7 @@ static bool ZipPackageStream_saveChild(
if ( !bUseNonSeekableAccess )
{
- xStream = rInfo.pStream->getRawData();
+ xStream = getRawData();
if ( !xStream.is() )
{
@@ -440,7 +428,7 @@ static bool ZipPackageStream_saveChild(
{
// The raw stream can neither be encrypted nor connected
OSL_ENSURE( !bRawStream || !(bToBeCompressed || bToBeEncrypted), "The stream is already encrypted!\n" );
- xSeek->seek ( bRawStream ? rInfo.pStream->GetMagicalHackPos() : 0 );
+ xSeek->seek ( bRawStream ? GetMagicalHackPos() : 0 );
ImplSetStoredData ( *pTempEntry, xStream );
// TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
@@ -460,10 +448,10 @@ static bool ZipPackageStream_saveChild(
// check if it's one of our own streams, if it is then we know that
// each time we ask for it we'll get a new stream that will be
// at position zero...otherwise, assert and skip this stream...
- if ( rInfo.pStream->IsPackageMember() )
+ if ( IsPackageMember() )
{
// if the password has been changed than the stream should not be package member any more
- if ( rInfo.pStream->IsEncrypted() && rInfo.pStream->IsToBeEncrypted() )
+ if ( IsEncrypted() && IsToBeEncrypted() )
{
// Should be handled close to the raw stream handling
bTransportOwnEncrStreamAsRaw = true;
@@ -492,17 +480,17 @@ static bool ZipPackageStream_saveChild(
{
if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw )
{
- uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( rInfo.pStream->GetBlockSize() );
+ uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( GetBlockSize() );
rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 );
rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() );
sal_Int32 nIterationCount = 1024;
- if ( !rInfo.pStream->HasOwnKey() )
- rInfo.pStream->setKey ( rEncryptionKey );
+ if ( !HasOwnKey() )
+ setKey ( rEncryptionKey );
- rInfo.pStream->setInitialisationVector ( aVector );
- rInfo.pStream->setSalt ( aSalt );
- rInfo.pStream->setIterationCount ( nIterationCount );
+ setInitialisationVector ( aVector );
+ setSalt ( aSalt );
+ setIterationCount ( nIterationCount );
}
// last property is digest, which is inserted later if we didn't have
@@ -510,11 +498,11 @@ static bool ZipPackageStream_saveChild(
aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
- aPropSet[PKG_MNFST_INIVECTOR].Value <<= rInfo.pStream->getInitialisationVector();
+ aPropSet[PKG_MNFST_INIVECTOR].Value <<= getInitialisationVector();
aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
- aPropSet[PKG_MNFST_SALT].Value <<= rInfo.pStream->getSalt();
+ aPropSet[PKG_MNFST_SALT].Value <<= getSalt();
aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
- aPropSet[PKG_MNFST_ITERATION].Value <<= rInfo.pStream->getIterationCount ();
+ aPropSet[PKG_MNFST_ITERATION].Value <<= getIterationCount ();
// Need to store the uncompressed size in the manifest
OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
@@ -523,12 +511,12 @@ static bool ZipPackageStream_saveChild(
if ( bRawStream || bTransportOwnEncrStreamAsRaw )
{
- ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData();
+ ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
if ( !xEncData.is() )
throw uno::RuntimeException();
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
- aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest();
+ aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
@@ -545,15 +533,15 @@ static bool ZipPackageStream_saveChild(
// want for this write...copy it raw
if ( !bUseNonSeekableAccess
&& ( bRawStream || bTransportOwnEncrStreamAsRaw
- || ( rInfo.pStream->IsPackageMember() && !bToBeEncrypted
- && ( ( rInfo.pStream->aEntry.nMethod == DEFLATED && bToBeCompressed )
- || ( rInfo.pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
+ || ( IsPackageMember() && !bToBeEncrypted
+ && ( ( aEntry.nMethod == DEFLATED && bToBeCompressed )
+ || ( aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
{
// If it's a PackageMember, then it's an unbuffered stream and we need
// to get a new version of it as we can't seek backwards.
- if ( rInfo.pStream->IsPackageMember() )
+ if ( IsPackageMember() )
{
- xStream = rInfo.pStream->getRawData();
+ xStream = getRawData();
if ( !xStream.is() )
{
// Make sure that we actually _got_ a new one !
@@ -565,9 +553,9 @@ static bool ZipPackageStream_saveChild(
try
{
if ( bRawStream )
- xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() );
+ xStream->skipBytes( GetMagicalHackPos() );
- ZipOutputEntry aZipEntry(xContext, rZipOut.getChucker(), *pTempEntry, rInfo.pStream, false);
+ ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, false);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
@@ -605,9 +593,9 @@ static bool ZipPackageStream_saveChild(
// If it's a PackageMember, then our previous reference held a 'raw' stream
// so we need to re-get it, unencrypted, uncompressed and positioned at the
// beginning of the stream
- if ( rInfo.pStream->IsPackageMember() )
+ if ( IsPackageMember() )
{
- xStream = rInfo.pStream->getInputStream();
+ xStream = getInputStream();
if ( !xStream.is() )
{
// Make sure that we actually _got_ a new one !
@@ -625,7 +613,7 @@ static bool ZipPackageStream_saveChild(
try
{
- ZipOutputEntry aZipEntry(xContext, rZipOut.getChucker(), *pTempEntry, rInfo.pStream, bToBeEncrypted);
+ ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, bToBeEncrypted);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
@@ -652,12 +640,12 @@ static bool ZipPackageStream_saveChild(
if ( bToBeEncrypted )
{
- ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData();
+ ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
if ( !xEncData.is() )
throw uno::RuntimeException();
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
- aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest();
+ aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
@@ -667,45 +655,44 @@ static bool ZipPackageStream_saveChild(
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
- rInfo.pStream->SetIsEncrypted ( true );
+ SetIsEncrypted ( true );
}
}
if( bSuccess )
{
- if ( !rInfo.pStream->IsPackageMember() )
+ if ( !IsPackageMember() )
{
- rInfo.pStream->CloseOwnStreamIfAny();
- rInfo.pStream->SetPackageMember ( true );
+ CloseOwnStreamIfAny();
+ SetPackageMember ( true );
}
if ( bRawStream )
{
// the raw stream was integrated and now behaves
// as usual encrypted stream
- rInfo.pStream->SetToBeEncrypted( true );
+ SetToBeEncrypted( true );
}
// Then copy it back afterwards...
- ZipPackageFolder::copyZipEntry ( rInfo.pStream->aEntry, *pTempEntry );
+ ZipPackageFolder::copyZipEntry ( aEntry, *pTempEntry );
// Remove hacky bit from entry flags
- if ( rInfo.pStream->aEntry.nFlag & ( 1 << 4 ) )
+ if ( aEntry.nFlag & ( 1 << 4 ) )
{
- rInfo.pStream->aEntry.nFlag &= ~( 1 << 4 );
- rInfo.pStream->aEntry.nMethod = STORED;
+ aEntry.nFlag &= ~( 1 << 4 );
+ aEntry.nMethod = STORED;
}
// TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
- if ( rInfo.pStream->IsEncrypted() )
- rInfo.pStream->setSize( nOwnStreamOrigSize );
+ if ( IsEncrypted() )
+ setSize( nOwnStreamOrigSize );
- rInfo.pStream->aEntry.nOffset *= -1;
+ aEntry.nOffset *= -1;
}
- // folder can have a mediatype only in package format
if ( aPropSet.getLength()
- && ( nFormat == embed::StorageFormats::PACKAGE || ( nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
+ && ( m_nFormat == embed::StorageFormats::PACKAGE || m_nFormat == embed::StorageFormats::OFOPXML ) )
rManList.push_back( aPropSet );
return bSuccess;
@@ -755,8 +742,8 @@ void ZipPackageFolder::saveContents(
if ( aIter != maContents.end() && !(*aIter).second->bFolder )
{
bMimeTypeStreamStored = true;
- bWritingFailed = !ZipPackageStream_saveChild( m_xContext,
- *aIter->second, rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
+ bWritingFailed = !aIter->second->pStream->saveChild(
+ rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool );
}
}
@@ -771,13 +758,13 @@ void ZipPackageFolder::saveContents(
{
if (rInfo.bFolder)
{
- bWritingFailed = !ZipPackageFolder_saveChild(
- rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
+ bWritingFailed = !rInfo.pFolder->saveChild(
+ rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool );
}
else
{
- bWritingFailed = !ZipPackageStream_saveChild( m_xContext,
- rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
+ bWritingFailed = !rInfo.pStream->saveChild(
+ rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool );
}
}
}
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 94579d7..10ea847 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -69,9 +69,9 @@ namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationI
ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
const uno::Reference< XComponentContext >& xContext,
+ sal_Int32 nFormat,
bool bAllowRemoveOnInsert )
-: m_xContext( xContext )
-, m_rZipPackage( rNewPackage )
+: m_rZipPackage( rNewPackage )
, m_bToBeCompressed ( true )
, m_bToBeEncrypted ( false )
, m_bHaveOwnKey ( false )
@@ -88,10 +88,9 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
, m_bFromManifest( false )
, m_bUseWinEncoding( false )
{
- OSL_ENSURE( m_xContext.is(), "No factory is provided to ZipPackageStream!\n" );
-
- this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
-
+ m_xContext = xContext;
+ m_nFormat = nFormat;
+ mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
SetFolder ( false );
aEntry.nVersion = -1;
aEntry.nFlag = 0;
commit e5e758467e365f072778f75548895828202b7bfa
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Wed Oct 15 10:19:56 2014 +0200
package: ZipPackageStream: prefix members
Change-Id: I02a1c3189c6b52f4f539b0eaa8878985cae8b321
diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx
index cabc620..0e395a3 100644
--- a/package/inc/ZipPackageStream.hxx
+++ b/package/inc/ZipPackageStream.hxx
@@ -47,10 +47,10 @@ class ZipPackageStream : public cppu::ImplInheritanceHelper2
>
{
private:
- com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
+ com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xStream;
const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
- ZipPackage &rZipPackage;
- bool bToBeCompressed, bToBeEncrypted, bHaveOwnKey, bIsEncrypted;
+ ZipPackage &m_rZipPackage;
+ bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys;
@@ -76,10 +76,10 @@ private:
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream();
public:
- bool HasOwnKey () const { return bHaveOwnKey;}
- bool IsToBeCompressed () const { return bToBeCompressed;}
- bool IsToBeEncrypted () const { return bToBeEncrypted;}
- bool IsEncrypted () const { return bIsEncrypted;}
+ bool HasOwnKey () const { return m_bHaveOwnKey;}
+ bool IsToBeCompressed () const { return m_bToBeCompressed;}
+ bool IsToBeEncrypted () const { return m_bToBeEncrypted;}
+ bool IsEncrypted () const { return m_bIsEncrypted;}
bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
bool IsFromManifest() const { return m_bFromManifest; }
@@ -108,18 +108,18 @@ public:
sal_Int32 GetEncryptionAlgorithm() const;
sal_Int32 GetBlockSize() const;
- void SetToBeCompressed (bool bNewValue) { bToBeCompressed = bNewValue;}
- void SetIsEncrypted (bool bNewValue) { bIsEncrypted = bNewValue;}
+ void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;}
+ void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;}
void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
void SetToBeEncrypted (bool bNewValue)
{
- bToBeEncrypted = bNewValue;
- if ( bToBeEncrypted && !m_xBaseEncryptionData.is())
+ m_bToBeEncrypted = bNewValue;
+ if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is())
m_xBaseEncryptionData = new BaseEncryptionData;
- else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() )
+ else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
m_xBaseEncryptionData.clear();
}
void SetPackageMember (bool bNewValue);
@@ -136,7 +136,7 @@ public:
{ m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
void setSize (const sal_Int64 nNewSize);
- ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; }
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return m_xStream; }
void CloseOwnStreamIfAny();
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index fee38a6..94579d7 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -71,11 +71,11 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
const uno::Reference< XComponentContext >& xContext,
bool bAllowRemoveOnInsert )
: m_xContext( xContext )
-, rZipPackage( rNewPackage )
-, bToBeCompressed ( true )
-, bToBeEncrypted ( false )
-, bHaveOwnKey ( false )
-, bIsEncrypted ( false )
+, m_rZipPackage( rNewPackage )
+, m_bToBeCompressed ( true )
+, m_bToBeEncrypted ( false )
+, m_bHaveOwnKey ( false )
+, m_bIsEncrypted ( false )
, m_nImportedStartKeyAlgorithm( 0 )
, m_nImportedEncryptionAlgorithm( 0 )
, m_nImportedChecksumAlgorithm( 0 )
@@ -124,36 +124,36 @@ void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry )
aEntry.nExtraLen = rInEntry.nExtraLen;
if ( aEntry.nMethod == STORED )
- bToBeCompressed = false;
+ m_bToBeCompressed = false;
}
void ZipPackageStream::CloseOwnStreamIfAny()
{
- if ( xStream.is() )
+ if ( m_xStream.is() )
{
- xStream->closeInput();
- xStream = uno::Reference< io::XInputStream >();
+ m_xStream->closeInput();
+ m_xStream = uno::Reference< io::XInputStream >();
m_bHasSeekable = false;
}
}
uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream()
{
- if ( !m_bHasSeekable && xStream.is() )
+ if ( !m_bHasSeekable && m_xStream.is() )
{
// The package component requires that every stream either be FROM a package or it must support XSeekable!
// The only exception is a nonseekable stream that is provided only for storing, if such a stream
// is accessed before commit it MUST be wrapped.
// Wrap the stream in case it is not seekable
- xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xStream, m_xContext );
- uno::Reference< io::XSeekable > xSeek( xStream, UNO_QUERY );
+ m_xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xStream, m_xContext );
+ uno::Reference< io::XSeekable > xSeek( m_xStream, UNO_QUERY );
if ( !xSeek.is() )
throw RuntimeException( THROW_WHERE "The stream must support XSeekable!" );
m_bHasSeekable = true;
}
- return xStream;
+ return m_xStream;
}
uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCopy()
@@ -188,7 +188,7 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop
sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const
{
- return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : rZipPackage.GetEncAlgID();
+ return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : m_rZipPackage.GetEncAlgID();
}
sal_Int32 ZipPackageStream::GetBlockSize() const
@@ -204,8 +204,8 @@ sal_Int32 ZipPackageStream::GetBlockSize() const
*m_xBaseEncryptionData,
GetEncryptionKey( bUseWinEncoding ),
GetEncryptionAlgorithm(),
- m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(),
- m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(),
+ m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : m_rZipPackage.GetChecksumAlgID(),
+ m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : m_rZipPackage.GetDefaultDerivedKeySize(),
GetStartKeyGenID() );
return xResult;
@@ -217,7 +217,7 @@ uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncodi
sal_Int32 nKeyGenID = GetStartKeyGenID();
bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding );
- if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() )
+ if ( m_bHaveOwnKey && m_aStorageEncryptionKeys.getLength() )
{
OUString aNameToFind;
if ( nKeyGenID == xml::crypto::DigestID::SHA256 )
@@ -241,8 +241,8 @@ uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncodi
else
aResult = m_aEncryptionKey;
- if ( !aResult.getLength() || !bHaveOwnKey )
- aResult = rZipPackage.GetEncryptionKey();
+ if ( !aResult.getLength() || !m_bHaveOwnKey )
+ aResult = m_rZipPackage.GetEncryptionKey();
return aResult;
}
@@ -251,17 +251,17 @@ sal_Int32 ZipPackageStream::GetStartKeyGenID()
{
// generally should all the streams use the same Start Key
// but if raw copy without password takes place, we should preserve the imported algorithm
- return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetStartKeyGenID();
+ return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : m_rZipPackage.GetStartKeyGenID();
}
uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( bool bAddHeaderForEncr )
{
- if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !bToBeEncrypted ) )
+ if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !m_bToBeEncrypted ) )
throw packages::NoEncryptionException(THROW_WHERE );
Sequence< sal_Int8 > aKey;
- if ( bToBeEncrypted )
+ if ( m_bToBeEncrypted )
{
aKey = GetEncryptionKey();
if ( !aKey.getLength() )
@@ -291,7 +291,7 @@ uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream(
throw RuntimeException(THROW_WHERE );
xNewPackStream->setDataStream( static_cast< io::XInputStream* >(
- new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) );
+ new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() ) ) );
uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY );
if ( !xNewPSProps.is() )
@@ -299,8 +299,8 @@ uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream(
// copy all the properties of this stream to the new stream
xNewPSProps->setPropertyValue("MediaType", makeAny( msMediaType ) );
- xNewPSProps->setPropertyValue("Compressed", makeAny( bToBeCompressed ) );
- if ( bToBeEncrypted )
+ xNewPSProps->setPropertyValue("Compressed", makeAny( m_bToBeCompressed ) );
+ if ( m_bToBeEncrypted )
{
xNewPSProps->setPropertyValue(ENCRYPTION_KEY_PROPERTY, makeAny( aKey ) );
xNewPSProps->setPropertyValue("Encrypted", makeAny( true ) );
@@ -426,7 +426,7 @@ bool ZipPackageStream::ParsePackageRawStream()
m_xBaseEncryptionData = xTempEncrData;
SetIsEncrypted ( true );
// it's already compressed and encrypted
- bToBeEncrypted = bToBeCompressed = false;
+ m_bToBeEncrypted = m_bToBeCompressed = false;
return true;
}
@@ -448,7 +448,7 @@ void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInput
throw( RuntimeException, std::exception )
{
// if seekable access is required the wrapping will be done on demand
- xStream = aStream;
+ m_xStream = aStream;
m_nImportedEncryptionAlgorithm = 0;
m_bHasSeekable = false;
SetPackageMember ( false );
@@ -463,11 +463,11 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData()
{
if ( IsPackageMember() )
{
- return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+ return m_rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
- return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
+ return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
else
return uno::Reference < io::XInputStream > ();
@@ -491,11 +491,11 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream()
{
if ( IsPackageMember() )
{
- return rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+ return m_rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
- return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
+ return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
else
return uno::Reference < io::XInputStream > ();
@@ -533,11 +533,11 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
uno::Reference< io::XInputStream > xResult;
try
{
- xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+ xResult = m_rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
}
catch( const packages::WrongPasswordException& )
{
- if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 )
+ if ( m_rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 )
{
try
{
@@ -548,7 +548,7 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
// force SHA256 and see if that works
m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA256;
- xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+ xResult = m_rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
return xResult;
}
catch (const packages::WrongPasswordException&)
@@ -561,7 +561,7 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
// workaround for the encrypted documents generated with the old OOo1.x bug.
if ( !m_bUseWinEncoding )
{
- xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+ xResult = m_rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
m_bUseWinEncoding = true;
}
else
@@ -576,7 +576,7 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
return ZipFile::StaticGetDataFromRawStream( m_xContext, GetOwnSeekStream(), GetEncryptionData() );
else if ( GetOwnSeekStream().is() )
{
- return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
+ return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
else
return uno::Reference< io::XInputStream >();
@@ -597,18 +597,18 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream()
if ( IsPackageMember() )
{
- if ( !bIsEncrypted || !GetEncryptionData().is() )
+ if ( !m_bIsEncrypted || !GetEncryptionData().is() )
throw packages::NoEncryptionException(THROW_WHERE );
- return rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), msMediaType, rZipPackage.GetSharedMutexRef() );
+ return m_rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), msMediaType, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
if ( m_nStreamMode == PACKAGE_STREAM_RAW )
{
- return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
+ return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
- else if ( m_nStreamMode == PACKAGE_STREAM_DATA && bToBeEncrypted )
+ else if ( m_nStreamMode == PACKAGE_STREAM_DATA && m_bToBeEncrypted )
return TryToGetRawFromDataStream( true );
}
@@ -636,11 +636,11 @@ void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputSt
throw RuntimeException(THROW_WHERE "The stream must support XSeekable!" );
xSeek->seek( 0 );
- uno::Reference< io::XInputStream > xOldStream = xStream;
- xStream = xNewStream;
+ uno::Reference< io::XInputStream > xOldStream = m_xStream;
+ m_xStream = xNewStream;
if ( !ParsePackageRawStream() )
{
- xStream = xOldStream;
+ m_xStream = xOldStream;
throw packages::NoRawFormatException(THROW_WHERE );
}
@@ -666,7 +666,7 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream(
if ( IsPackageMember() )
{
- return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+ return m_rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
@@ -700,7 +700,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
{
if ( aPropertyName == "MediaType" )
{
- if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && rZipPackage.getFormat() != embed::StorageFormats::OFOPXML )
+ if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && m_rZipPackage.getFormat() != embed::StorageFormats::OFOPXML )
throw beans::PropertyVetoException(THROW_WHERE );
if ( aValue >>= msMediaType )
@@ -709,9 +709,9 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
{
if ( msMediaType.indexOf ( "text" ) != -1
|| msMediaType == "application/vnd.sun.star.oleobject" )
- bToBeCompressed = true;
+ m_bToBeCompressed = true;
else if ( !m_bCompressedIsSetFromOutside )
- bToBeCompressed = false;
+ m_bToBeCompressed = false;
}
}
else
@@ -729,7 +729,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
}
else if ( aPropertyName == "Encrypted" )
{
- if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
+ if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
throw beans::PropertyVetoException(THROW_WHERE );
bool bEnc = false;
@@ -741,8 +741,8 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
uno::Reference< XInterface >(),
2 );
- bToBeEncrypted = bEnc;
- if ( bToBeEncrypted && !m_xBaseEncryptionData.is() )
+ m_bToBeEncrypted = bEnc;
+ if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is() )
m_xBaseEncryptionData = new BaseEncryptionData;
}
else
@@ -753,7 +753,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
}
else if ( aPropertyName == ENCRYPTION_KEY_PROPERTY )
{
- if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
+ if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
throw beans::PropertyVetoException(THROW_WHERE );
uno::Sequence< sal_Int8 > aNewKey;
@@ -784,13 +784,13 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
m_aEncryptionKey = aNewKey;
// In case of new raw stream, the stream must not be encrypted on storing
- bHaveOwnKey = true;
+ m_bHaveOwnKey = true;
if ( m_nStreamMode != PACKAGE_STREAM_RAW )
- bToBeEncrypted = true;
+ m_bToBeEncrypted = true;
}
else
{
- bHaveOwnKey = false;
+ m_bHaveOwnKey = false;
m_aEncryptionKey.realloc( 0 );
}
@@ -798,7 +798,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
}
else if ( aPropertyName == STORAGE_ENCRYPTION_KEYS_PROPERTY )
{
- if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
+ if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
throw beans::PropertyVetoException(THROW_WHERE );
uno::Sequence< beans::NamedValue > aKeys;
@@ -817,13 +817,13 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
m_aStorageEncryptionKeys = aKeys;
// In case of new raw stream, the stream must not be encrypted on storing
- bHaveOwnKey = true;
+ m_bHaveOwnKey = true;
if ( m_nStreamMode != PACKAGE_STREAM_RAW )
- bToBeEncrypted = true;
+ m_bToBeEncrypted = true;
}
else
{
- bHaveOwnKey = false;
+ m_bHaveOwnKey = false;
m_aStorageEncryptionKeys.realloc( 0 );
}
@@ -841,7 +841,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
uno::Reference< XInterface >(),
2 );
- bToBeCompressed = bCompr;
+ m_bToBeCompressed = bCompr;
m_bCompressedIsSetFromOutside = true;
}
else
@@ -869,17 +869,17 @@ Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName )
}
else if ( PropertyName == "Encrypted" )
{
- aAny <<= ((m_nStreamMode == PACKAGE_STREAM_RAW) || bToBeEncrypted);
+ aAny <<= ((m_nStreamMode == PACKAGE_STREAM_RAW) || m_bToBeEncrypted);
return aAny;
}
else if ( PropertyName == "WasEncrypted" )
{
- aAny <<= bIsEncrypted;
+ aAny <<= m_bIsEncrypted;
return aAny;
}
else if ( PropertyName == "Compressed" )
{
- aAny <<= bToBeCompressed;
+ aAny <<= m_bToBeCompressed;
return aAny;
}
else if ( PropertyName == ENCRYPTION_KEY_PROPERTY )
More information about the Libreoffice-commits
mailing list