[Libreoffice-commits] core.git: 10 commits - include/oox oox/source package/inc package/Library_package2.mk package/source sax/source

Matúš Kukan matus.kukan at collabora.com
Thu Oct 23 05:31:28 PDT 2014


 include/oox/token/tokenmap.hxx                 |    9 
 oox/source/token/tokenmap.cxx                  |    7 
 package/Library_package2.mk                    |    1 
 package/inc/ZipOutputEntry.hxx                 |   79 +++
 package/inc/ZipOutputStream.hxx                |   49 --
 package/inc/ZipPackageEntry.hxx                |   17 
 package/inc/ZipPackageFolder.hxx               |   25 -
 package/inc/ZipPackageStream.hxx               |   52 --
 package/source/zipapi/ZipOutputEntry.cxx       |  367 +++++++++++++++++
 package/source/zipapi/ZipOutputStream.cxx      |  351 ----------------
 package/source/zippackage/ZipPackage.cxx       |   42 +
 package/source/zippackage/ZipPackageEntry.cxx  |    5 
 package/source/zippackage/ZipPackageFolder.cxx |  433 +-------------------
 package/source/zippackage/ZipPackageStream.cxx |  526 +++++++++++++++++++++----
 sax/source/tools/CachedOutputStream.hxx        |   49 ++
 sax/source/tools/fastserializer.cxx            |  108 +++--
 sax/source/tools/fastserializer.hxx            |   17 
 sax/source/tools/fshelper.cxx                  |    2 
 18 files changed, 1140 insertions(+), 999 deletions(-)

New commits:
commit 0e63397d7fda5325e83eaf439cdd745f797f885c
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Wed Oct 15 13:07:43 2014 +0200

    Remove pointless functions now that saveChild() is ZipPackageStream's member
    
    Change-Id: Id43ec2e7ddb1035d3306170523764bb9a74c03b8

diff --git a/package/inc/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx
index 758dbb8..356d42b 100644
--- a/package/inc/ZipPackageStream.hxx
+++ b/package/inc/ZipPackageStream.hxx
@@ -75,9 +75,6 @@ private:
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream();
 
 public:
-    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;}
 
@@ -90,20 +87,6 @@ public:
 
     sal_Int32 GetStartKeyGenID();
 
-    const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const
-    { return m_xBaseEncryptionData->m_aInitVector;}
-    const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const
-    { return m_xBaseEncryptionData->m_aDigest;}
-    const com::sun::star::uno::Sequence < sal_Int8 > getSalt () const
-    { return m_xBaseEncryptionData->m_aSalt;}
-    sal_Int32 getIterationCount () const
-    { return m_xBaseEncryptionData->m_nIterationCount;}
-    sal_Int64 getSize () const
-    { return aEntry.nSize;}
-
-    sal_uInt8 GetStreamMode() const { return m_nStreamMode; }
-    sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; }
-    sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; }
     sal_Int32 GetEncryptionAlgorithm() const;
     sal_Int32 GetBlockSize() const;
 
@@ -123,8 +106,6 @@ public:
     }
     void SetPackageMember (bool bNewValue);
 
-    void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey )
-    { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); }
     void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector )
     { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
     void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt )
@@ -135,8 +116,6 @@ public:
     { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
     void setSize (const sal_Int64 nNewSize);
 
-    ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return m_xStream; }
-
     void CloseOwnStreamIfAny();
 
     ZipPackageStream( ZipPackage & rNewPackage,
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index d5d35e9..a4651d7 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -175,8 +175,8 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop
         throw ZipIOException(THROW_WHERE "The stream must be seekable!" );
 
     // skip header
-    xSeek->seek( n_ConstHeaderSize + getInitialisationVector().getLength() +
-                    getSalt().getLength() + getDigest().getLength() );
+    xSeek->seek( n_ConstHeaderSize + m_xBaseEncryptionData->m_aInitVector.getLength() +
+                    m_xBaseEncryptionData->m_aSalt.getLength() + m_xBaseEncryptionData->m_aDigest.getLength() );
 
     // create temporary stream
     uno::Reference < io::XTempFile > xTempFile = io::TempFile::create(m_xContext);
@@ -485,8 +485,8 @@ bool ZipPackageStream::saveChild(
     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();
+    bool bToBeEncrypted = m_bToBeEncrypted && (rEncryptionKey.getLength() || m_bHaveOwnKey);
+    bool bToBeCompressed = bToBeEncrypted ? sal_True : m_bToBeCompressed;
 
     aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
     aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType( );
@@ -495,18 +495,18 @@ bool ZipPackageStream::saveChild(
     aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
     aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
 
-    OSL_ENSURE( GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
+    OSL_ENSURE( m_nStreamMode != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
 
     bool bRawStream = false;
-    if ( GetStreamMode() == PACKAGE_STREAM_DETECT )
+    if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
         bRawStream = ParsePackageRawStream();
-    else if ( GetStreamMode() == PACKAGE_STREAM_RAW )
+    else if ( m_nStreamMode == 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();
+    sal_Int64 nOwnStreamOrigSize = bRawStream ? m_nMagicalHackSize : aEntry.nSize;
 
     bool bUseNonSeekableAccess = false;
     uno::Reference < io::XInputStream > xStream;
@@ -516,7 +516,7 @@ bool ZipPackageStream::saveChild(
         // it should not be encrypted and it should be compressed,
         // in this case nonseekable access can be used
 
-        xStream = GetOwnStreamNoWrap();
+        xStream = m_xStream;
         uno::Reference < io::XSeekable > xSeek ( xStream, uno::UNO_QUERY );
 
         bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
@@ -544,7 +544,7 @@ 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 ? GetMagicalHackPos() : 0 );
+                    xSeek->seek ( bRawStream ? m_nMagicalHackPos : 0 );
                     ImplSetStoredData ( *pTempEntry, xStream );
 
                     // TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
@@ -567,7 +567,7 @@ bool ZipPackageStream::saveChild(
                 if ( IsPackageMember() )
                 {
                     // if the password has been changed than the stream should not be package member any more
-                    if ( IsEncrypted() && IsToBeEncrypted() )
+                    if ( m_bIsEncrypted && m_bToBeEncrypted )
                     {
                         // Should be handled close to the raw stream handling
                         bTransportOwnEncrStreamAsRaw = true;
@@ -601,8 +601,11 @@ bool ZipPackageStream::saveChild(
                 rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() );
                 sal_Int32 nIterationCount = 1024;
 
-                if ( !HasOwnKey() )
-                    setKey ( rEncryptionKey );
+                if ( !m_bHaveOwnKey )
+                {
+                    m_aEncryptionKey = rEncryptionKey;
+                    m_aStorageEncryptionKeys.realloc( 0 );
+                }
 
                 setInitialisationVector ( aVector );
                 setSalt ( aSalt );
@@ -614,11 +617,11 @@ bool ZipPackageStream::saveChild(
             aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
 
             aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
-            aPropSet[PKG_MNFST_INIVECTOR].Value <<= getInitialisationVector();
+            aPropSet[PKG_MNFST_INIVECTOR].Value <<= m_xBaseEncryptionData->m_aInitVector;
             aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
-            aPropSet[PKG_MNFST_SALT].Value <<= getSalt();
+            aPropSet[PKG_MNFST_SALT].Value <<= m_xBaseEncryptionData->m_aSalt;
             aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
-            aPropSet[PKG_MNFST_ITERATION].Value <<= getIterationCount ();
+            aPropSet[PKG_MNFST_ITERATION].Value <<= m_xBaseEncryptionData->m_nIterationCount;
 
             // Need to store the uncompressed size in the manifest
             OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
@@ -632,7 +635,7 @@ bool ZipPackageStream::saveChild(
                     throw uno::RuntimeException();
 
                 aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
-                aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
+                aPropSet[PKG_MNFST_DIGEST].Value <<= m_xBaseEncryptionData->m_aDigest;
                 aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
                 aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
                 aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
@@ -669,7 +672,7 @@ bool ZipPackageStream::saveChild(
         try
         {
             if ( bRawStream )
-                xStream->skipBytes( GetMagicalHackPos() );
+                xStream->skipBytes( m_nMagicalHackPos );
 
             ZipOutputEntry aZipEntry(m_xContext, rZipOut.getChucker(), *pTempEntry, this, false);
             // the entry is provided to the ZipOutputStream that will delete it
@@ -761,7 +764,7 @@ bool ZipPackageStream::saveChild(
                 throw uno::RuntimeException();
 
             aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
-            aPropSet[PKG_MNFST_DIGEST].Value <<= getDigest();
+            aPropSet[PKG_MNFST_DIGEST].Value <<= m_xBaseEncryptionData->m_aDigest;
             aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
             aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
             aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
commit 4b609883f908f566be4990f04c3368d1a5f27826
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 17b144f..d5d35e9 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 1b3122a1895e6eff7341fda39a5f68d7a60c7aa0
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 d7c19f1..758dbb8 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 01defa9..17b144f 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 152c4afef44d6e6456777a7cd0de4e3a3a2a9338
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 45c008a..d7c19f1 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 430ba00..01defa9 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 )
commit 3a8bddc18e4218210f74a9b0192f1528536a58a2
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Thu Oct 9 15:22:54 2014 +0200

    package: Add ZipOutputEntry to isolate deflating of streams.
    
    Preparation commit for deflating streams in parallel.
    We still use the same single XOutputStream (ByteChucker :-) for
    sequential writing but this can now be changed more easily.
    
    Change-Id: Idf26cc2187461660e31ac2e12c4708e761596fb2

diff --git a/package/Library_package2.mk b/package/Library_package2.mk
index 269cf81..f563d0a 100644
--- a/package/Library_package2.mk
+++ b/package/Library_package2.mk
@@ -55,6 +55,7 @@ $(eval $(call gb_Library_add_exception_objects,package2,\
 	package/source/zipapi/XUnbufferedStream \
 	package/source/zipapi/ZipEnumeration \
 	package/source/zipapi/ZipFile \
+	package/source/zipapi/ZipOutputEntry \
 	package/source/zipapi/ZipOutputStream \
 	package/source/zippackage/wrapstreamforshare \
 	package/source/zippackage/zipfileaccess \
diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx
new file mode 100644
index 0000000..a1d03d3
--- /dev/null
+++ b/package/inc/ZipOutputEntry.hxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX
+#define INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/xml/crypto/XCipherContext.hpp>
+#include <com/sun/star/xml/crypto/XDigestContext.hpp>
+
+#include <package/Deflater.hxx>
+#include <ByteChucker.hxx>
+#include <CRC32.hxx>
+
+struct ZipEntry;
+class ZipPackageStream;
+
+class ZipOutputEntry
+{
+    ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
+    ZipUtils::Deflater  m_aDeflater;
+
+    ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
+    ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext;
+
+    CRC32               m_aCRC;
+    ByteChucker         &m_rChucker;
+    ZipEntry            *m_pCurrentEntry;
+    sal_Int16           m_nDigested;
+    bool                m_bEncryptCurrentEntry;
+    ZipPackageStream*   m_pCurrentStream;
+
+public:
+    ZipOutputEntry(
+        const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
+        ByteChucker& rChucker, ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false);
+
+    ~ZipOutputEntry();
+
+    // rawWrite to support a direct write to the output stream
+    void SAL_CALL rawWrite( ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
+        throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+    void SAL_CALL rawCloseEntry(  )
+        throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+
+    // XZipOutputEntry interfaces
+    void SAL_CALL closeEntry(  )
+        throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+    void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
+        throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+    static sal_uInt32 getCurrentDosTime ( );
+
+private:
+    void doDeflate();
+    sal_Int32 writeLOC( const ZipEntry &rEntry )
+        throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+    void writeEXT( const ZipEntry &rEntry )

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list