Kaydet (Commit) 1b3122a1 authored tarafından Matúš Kukan's avatar Matúš Kukan

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
üst 152c4afe
...@@ -21,13 +21,19 @@ ...@@ -21,13 +21,19 @@
#include <com/sun/star/container/XChild.hpp> #include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/container/XNamed.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/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <ZipEntry.hxx> #include <ZipEntry.hxx>
#include <cppuhelper/implbase5.hxx> #include <cppuhelper/implbase5.hxx>
#include <vector>
typedef void* rtlRandomPool;
class ZipOutputStream;
class ZipPackageFolder; class ZipPackageFolder;
class ZipPackageEntry : public cppu::WeakImplHelper5 class ZipPackageEntry : public cppu::WeakImplHelper5
...@@ -40,15 +46,18 @@ class ZipPackageEntry : public cppu::WeakImplHelper5 ...@@ -40,15 +46,18 @@ class ZipPackageEntry : public cppu::WeakImplHelper5
> >
{ {
protected: protected:
css::uno::Reference< css::uno::XComponentContext > m_xContext;
OUString msName; OUString msName;
bool mbIsFolder:1; bool mbIsFolder:1;
bool mbAllowRemoveOnInsert:1; bool mbAllowRemoveOnInsert:1;
// com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xParent; // com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xParent;
OUString msMediaType; OUString msMediaType;
ZipPackageFolder* mpParent; ZipPackageFolder* mpParent;
sal_Int32 m_nFormat;
public: public:
ZipEntry aEntry; ZipEntry aEntry;
ZipPackageEntry ( bool bNewFolder = false ); ZipPackageEntry();
virtual ~ZipPackageEntry( void ); virtual ~ZipPackageEntry( void );
const OUString& GetMediaType () const { return msMediaType; } const OUString& GetMediaType () const { return msMediaType; }
...@@ -58,6 +67,12 @@ public: ...@@ -58,6 +67,12 @@ public:
const ZipPackageFolder* GetParent () const { return mpParent; } const ZipPackageFolder* GetParent () const { return mpParent; }
void SetFolder ( bool bSetFolder ) { mbIsFolder = bSetFolder; } 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 ) void clearParent ( void )
{ {
// xParent.clear(); // xParent.clear();
......
...@@ -28,20 +28,8 @@ ...@@ -28,20 +28,8 @@
#include <cppuhelper/implbase2.hxx> #include <cppuhelper/implbase2.hxx>
#include <vector> #include <vector>
namespace com { namespace sun { namespace star {
namespace beans
{
struct PropertyValue;
}
namespace packages
{
class ContentInfo;
}
} } }
class ZipOutputStream; class ZipOutputStream;
struct ZipEntry; struct ZipEntry;
typedef void* rtlRandomPool;
class ZipPackageFolder : public cppu::ImplInheritanceHelper2 class ZipPackageFolder : public cppu::ImplInheritanceHelper2
< <
...@@ -51,14 +39,12 @@ class ZipPackageFolder : public cppu::ImplInheritanceHelper2 ...@@ -51,14 +39,12 @@ class ZipPackageFolder : public cppu::ImplInheritanceHelper2
> >
{ {
private: private:
css::uno::Reference< css::uno::XComponentContext> m_xContext;
ContentHash maContents; ContentHash maContents;
sal_Int32 m_nFormat;
OUString m_sVersion; OUString m_sVersion;
public: public:
ZipPackageFolder( css::uno::Reference< css::uno::XComponentContext> xContext, ZipPackageFolder( const css::uno::Reference < css::uno::XComponentContext >& xContext,
sal_Int32 nFormat, sal_Int32 nFormat,
bool bAllowRemoveOnInsert ); bool bAllowRemoveOnInsert );
virtual ~ZipPackageFolder(); virtual ~ZipPackageFolder();
...@@ -80,7 +66,13 @@ public: ...@@ -80,7 +66,13 @@ public:
static ::com::sun::star::uno::Sequence < sal_Int8 > static_getImplementationId(); static ::com::sun::star::uno::Sequence < sal_Int8 > static_getImplementationId();
void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; } 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 // Recursive functions
void saveContents( void saveContents(
......
...@@ -48,7 +48,6 @@ class ZipPackageStream : public cppu::ImplInheritanceHelper2 ...@@ -48,7 +48,6 @@ class ZipPackageStream : public cppu::ImplInheritanceHelper2
{ {
private: private:
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_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 &m_rZipPackage; ZipPackage &m_rZipPackage;
bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted; bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
...@@ -140,9 +139,10 @@ public: ...@@ -140,9 +139,10 @@ public:
void CloseOwnStreamIfAny(); void CloseOwnStreamIfAny();
ZipPackageStream ( ZipPackage & rNewPackage, ZipPackageStream( ZipPackage & rNewPackage,
const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext >& xContext, const css::uno::Reference < css::uno::XComponentContext >& xContext,
bool bAllowRemoveOnInsert ); sal_Int32 nFormat,
bool bAllowRemoveOnInsert );
virtual ~ZipPackageStream( void ); virtual ~ZipPackageStream( void );
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy(); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
...@@ -150,6 +150,11 @@ public: ...@@ -150,6 +150,11 @@ public:
bool bAddHeaderForEncr ); bool bAddHeaderForEncr );
bool ParsePackageRawStream(); 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); void setZipEntryOnLoading( const ZipEntry &rInEntry);
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData() ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
......
...@@ -556,7 +556,7 @@ void ZipPackage::getZipFileContents() ...@@ -556,7 +556,7 @@ void ZipPackage::getZipFileContents()
{ {
nStreamIndex++; nStreamIndex++;
sTemp = rName.copy( nStreamIndex, rName.getLength() - 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->SetPackageMember( true );
pPkgStream->setZipEntryOnLoading( rEntry ); pPkgStream->setZipEntryOnLoading( rEntry );
pPkgStream->setName( sTemp ); pPkgStream->setName( sTemp );
...@@ -942,7 +942,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) ...@@ -942,7 +942,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance() uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance()
throw( Exception, RuntimeException, std::exception ) 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; return xRef;
} }
...@@ -954,9 +954,9 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c ...@@ -954,9 +954,9 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c
if ( aArguments.getLength() ) if ( aArguments.getLength() )
aArguments[0] >>= bArg; aArguments[0] >>= bArg;
if ( bArg ) if ( bArg )
xRef = *new ZipPackageFolder ( m_xContext, m_nFormat, m_bAllowRemoveOnInsert ); xRef = *new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
else else
xRef = *new ZipPackageStream ( *this, m_xContext, m_bAllowRemoveOnInsert ); xRef = *new ZipPackageStream( *this, m_xContext, m_nFormat, m_bAllowRemoveOnInsert );
return xRef; return xRef;
} }
......
...@@ -40,9 +40,8 @@ using namespace com::sun::star::packages::zip::ZipConstants; ...@@ -40,9 +40,8 @@ using namespace com::sun::star::packages::zip::ZipConstants;
#define THROW_WHERE "" #define THROW_WHERE ""
#endif #endif
ZipPackageEntry::ZipPackageEntry ( bool bNewFolder ) ZipPackageEntry::ZipPackageEntry()
: mbIsFolder ( bNewFolder ) : mbIsFolder( false )
, mbAllowRemoveOnInsert( true )
, mpParent ( NULL ) , mpParent ( NULL )
{ {
} }
......
...@@ -61,14 +61,13 @@ using namespace ::com::sun::star; ...@@ -61,14 +61,13 @@ using namespace ::com::sun::star;
namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationId, lcl_CachedImplId > {}; } namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationId, lcl_CachedImplId > {}; }
ZipPackageFolder::ZipPackageFolder ( css::uno::Reference< css::uno::XComponentContext> xContext, ZipPackageFolder::ZipPackageFolder( const css::uno::Reference < css::uno::XComponentContext >& xContext,
sal_Int32 nFormat, sal_Int32 nFormat,
bool bAllowRemoveOnInsert ) bool bAllowRemoveOnInsert )
: m_xContext( xContext )
, m_nFormat( nFormat )
{ {
this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert; m_xContext = xContext;
m_nFormat = nFormat;
mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
SetFolder ( true ); SetFolder ( true );
aEntry.nVersion = -1; aEntry.nVersion = -1;
aEntry.nFlag = 0; aEntry.nFlag = 0;
...@@ -297,14 +296,12 @@ static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream> ...@@ -297,14 +296,12 @@ static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream>
rEntry.nCrc = aCRC32.getValue(); rEntry.nCrc = aCRC32.getValue();
} }
static bool ZipPackageFolder_saveChild( bool ZipPackageFolder::saveChild(
const ContentInfo &rInfo,
const OUString &rPath, const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList, std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut, ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey, const uno::Sequence < sal_Int8 >& rEncryptionKey,
const rtlRandomPool &rRandomPool, const rtlRandomPool &rRandomPool)
sal_Int32 nFormat)
{ {
bool bSuccess = true; bool bSuccess = true;
...@@ -313,42 +310,35 @@ static bool ZipPackageFolder_saveChild( ...@@ -313,42 +310,35 @@ static bool ZipPackageFolder_saveChild(
const OUString sFullPathProperty ("FullPath"); const OUString sFullPathProperty ("FullPath");
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
assert( rInfo.bFolder && rInfo.pFolder && "A valid child object is expected!" );
OUString sTempName = rPath + "/"; OUString sTempName = rPath + "/";
if ( !rInfo.pFolder->GetMediaType().isEmpty() ) if ( !GetMediaType().isEmpty() )
{ {
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; 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].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].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName; aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName;
} }
else else
aPropSet.realloc( 0 ); 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 // folder can have a mediatype only in package format
if ( aPropSet.getLength() if ( aPropSet.getLength() && ( m_nFormat == embed::StorageFormats::PACKAGE ) )
&& ( nFormat == embed::StorageFormats::PACKAGE || ( nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
rManList.push_back( aPropSet ); rManList.push_back( aPropSet );
return bSuccess; return bSuccess;
} }
static bool ZipPackageStream_saveChild( bool ZipPackageStream::saveChild(
css::uno::Reference< css::uno::XComponentContext> xContext,
const ContentInfo &rInfo,
const OUString &rPath, const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList, std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut, ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey, const uno::Sequence < sal_Int8 >& rEncryptionKey,
const rtlRandomPool &rRandomPool, const rtlRandomPool &rRandomPool)
sal_Int32 nFormat)
{ {
bool bSuccess = true; bool bSuccess = true;
...@@ -367,8 +357,6 @@ static bool ZipPackageStream_saveChild( ...@@ -367,8 +357,6 @@ static bool ZipPackageStream_saveChild(
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); 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 // if pTempEntry is necessary, it will be released and passed to the ZipOutputStream
// and be deleted in the ZipOutputStream destructor // and be deleted in the ZipOutputStream destructor
unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry ); unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry );
...@@ -377,42 +365,42 @@ static bool ZipPackageStream_saveChild( ...@@ -377,42 +365,42 @@ static bool ZipPackageStream_saveChild(
// In case the entry we are reading is also the entry we are writing, we will // In case the entry we are reading is also the entry we are writing, we will
// store the ZipEntry data in pTempEntry // store the ZipEntry data in pTempEntry
ZipPackageFolder::copyZipEntry ( *pTempEntry, rInfo.pStream->aEntry ); ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
pTempEntry->sPath = rPath; pTempEntry->sPath = rPath;
pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() ); pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
bool bToBeEncrypted = rInfo.pStream->IsToBeEncrypted() && (rEncryptionKey.getLength() || rInfo.pStream->HasOwnKey()); bool bToBeEncrypted = IsToBeEncrypted() && (rEncryptionKey.getLength() || HasOwnKey());
bool bToBeCompressed = bToBeEncrypted ? sal_True : rInfo.pStream->IsToBeCompressed(); bool bToBeCompressed = bToBeEncrypted ? sal_True : IsToBeCompressed();
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; 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].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= OUString(); // no version is stored for streams currently aPropSet[PKG_MNFST_VERSION].Value <<= OUString(); // no version is stored for streams currently
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath; 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; bool bRawStream = false;
if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_DETECT ) if ( GetStreamMode() == PACKAGE_STREAM_DETECT )
bRawStream = rInfo.pStream->ParsePackageRawStream(); bRawStream = ParsePackageRawStream();
else if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_RAW ) else if ( GetStreamMode() == PACKAGE_STREAM_RAW )
bRawStream = true; bRawStream = true;
bool bTransportOwnEncrStreamAsRaw = false; bool bTransportOwnEncrStreamAsRaw = false;
// During the storing the original size of the stream can be changed // During the storing the original size of the stream can be changed
// TODO/LATER: get rid of this hack // 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; bool bUseNonSeekableAccess = false;
uno::Reference < XInputStream > xStream; 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, // the stream is not a package member, not a raw stream,
// it should not be encrypted and it should be compressed, // it should not be encrypted and it should be compressed,
// in this case nonseekable access can be used // in this case nonseekable access can be used
xStream = rInfo.pStream->GetOwnStreamNoWrap(); xStream = GetOwnStreamNoWrap();
uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY );
bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() ); bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
...@@ -420,7 +408,7 @@ static bool ZipPackageStream_saveChild( ...@@ -420,7 +408,7 @@ static bool ZipPackageStream_saveChild(
if ( !bUseNonSeekableAccess ) if ( !bUseNonSeekableAccess )
{ {
xStream = rInfo.pStream->getRawData(); xStream = getRawData();
if ( !xStream.is() ) if ( !xStream.is() )
{ {
...@@ -440,7 +428,7 @@ static bool ZipPackageStream_saveChild( ...@@ -440,7 +428,7 @@ static bool ZipPackageStream_saveChild(
{ {
// The raw stream can neither be encrypted nor connected // The raw stream can neither be encrypted nor connected
OSL_ENSURE( !bRawStream || !(bToBeCompressed || bToBeEncrypted), "The stream is already encrypted!\n" ); 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 ); ImplSetStoredData ( *pTempEntry, xStream );
// TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties! // TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
...@@ -460,10 +448,10 @@ static bool ZipPackageStream_saveChild( ...@@ -460,10 +448,10 @@ static bool ZipPackageStream_saveChild(
// check if it's one of our own streams, if it is then we know that // 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 // each time we ask for it we'll get a new stream that will be
// at position zero...otherwise, assert and skip this stream... // 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 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 // Should be handled close to the raw stream handling
bTransportOwnEncrStreamAsRaw = true; bTransportOwnEncrStreamAsRaw = true;
...@@ -492,17 +480,17 @@ static bool ZipPackageStream_saveChild( ...@@ -492,17 +480,17 @@ static bool ZipPackageStream_saveChild(
{ {
if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw ) 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, aSalt.getArray(), 16 );
rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() ); rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() );
sal_Int32 nIterationCount = 1024; sal_Int32 nIterationCount = 1024;
if ( !rInfo.pStream->HasOwnKey() ) if ( !HasOwnKey() )
rInfo.pStream->setKey ( rEncryptionKey ); setKey ( rEncryptionKey );
rInfo.pStream->setInitialisationVector ( aVector ); setInitialisationVector ( aVector );
rInfo.pStream->setSalt ( aSalt ); setSalt ( aSalt );
rInfo.pStream->setIterationCount ( nIterationCount ); setIterationCount ( nIterationCount );
} }
// last property is digest, which is inserted later if we didn't have // last property is digest, which is inserted later if we didn't have
...@@ -510,11 +498,11 @@ static bool ZipPackageStream_saveChild( ...@@ -510,11 +498,11 @@ static bool ZipPackageStream_saveChild(
aPropSet.realloc(PKG_SIZE_ENCR_MNFST); aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty; 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].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].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 // Need to store the uncompressed size in the manifest
OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" ); OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
...@@ -523,12 +511,12 @@ static bool ZipPackageStream_saveChild( ...@@ -523,12 +511,12 @@ static bool ZipPackageStream_saveChild(
if ( bRawStream || bTransportOwnEncrStreamAsRaw ) if ( bRawStream || bTransportOwnEncrStreamAsRaw )
{ {
::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
if ( !xEncData.is() ) if ( !xEncData.is() )
throw uno::RuntimeException(); throw uno::RuntimeException();
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; 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].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg; aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty; aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
...@@ -545,15 +533,15 @@ static bool ZipPackageStream_saveChild( ...@@ -545,15 +533,15 @@ static bool ZipPackageStream_saveChild(
// want for this write...copy it raw // want for this write...copy it raw
if ( !bUseNonSeekableAccess if ( !bUseNonSeekableAccess
&& ( bRawStream || bTransportOwnEncrStreamAsRaw && ( bRawStream || bTransportOwnEncrStreamAsRaw
|| ( rInfo.pStream->IsPackageMember() && !bToBeEncrypted || ( IsPackageMember() && !bToBeEncrypted
&& ( ( rInfo.pStream->aEntry.nMethod == DEFLATED && bToBeCompressed ) && ( ( aEntry.nMethod == DEFLATED && bToBeCompressed )
|| ( rInfo.pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) ) || ( aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
{ {
// If it's a PackageMember, then it's an unbuffered stream and we need // 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. // 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() ) if ( !xStream.is() )
{ {
// Make sure that we actually _got_ a new one ! // Make sure that we actually _got_ a new one !
...@@ -565,9 +553,9 @@ static bool ZipPackageStream_saveChild( ...@@ -565,9 +553,9 @@ static bool ZipPackageStream_saveChild(
try try
{ {
if ( bRawStream ) 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 // the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release(); pAutoTempEntry.release();
...@@ -605,9 +593,9 @@ static bool ZipPackageStream_saveChild( ...@@ -605,9 +593,9 @@ static bool ZipPackageStream_saveChild(
// If it's a PackageMember, then our previous reference held a 'raw' stream // 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 // so we need to re-get it, unencrypted, uncompressed and positioned at the
// beginning of the stream // beginning of the stream
if ( rInfo.pStream->IsPackageMember() ) if ( IsPackageMember() )
{ {
xStream = rInfo.pStream->getInputStream(); xStream = getInputStream();
if ( !xStream.is() ) if ( !xStream.is() )
{ {
// Make sure that we actually _got_ a new one ! // Make sure that we actually _got_ a new one !
...@@ -625,7 +613,7 @@ static bool ZipPackageStream_saveChild( ...@@ -625,7 +613,7 @@ static bool ZipPackageStream_saveChild(
try 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 // the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release(); pAutoTempEntry.release();
...@@ -652,12 +640,12 @@ static bool ZipPackageStream_saveChild( ...@@ -652,12 +640,12 @@ static bool ZipPackageStream_saveChild(
if ( bToBeEncrypted ) if ( bToBeEncrypted )
{ {
::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); ::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
if ( !xEncData.is() ) if ( !xEncData.is() )
throw uno::RuntimeException(); throw uno::RuntimeException();
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; 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].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg; aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty; aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
...@@ -667,45 +655,44 @@ static bool ZipPackageStream_saveChild( ...@@ -667,45 +655,44 @@ static bool ZipPackageStream_saveChild(
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
rInfo.pStream->SetIsEncrypted ( true ); SetIsEncrypted ( true );
} }
} }
if( bSuccess ) if( bSuccess )
{ {
if ( !rInfo.pStream->IsPackageMember() ) if ( !IsPackageMember() )
{ {
rInfo.pStream->CloseOwnStreamIfAny(); CloseOwnStreamIfAny();
rInfo.pStream->SetPackageMember ( true ); SetPackageMember ( true );
} }
if ( bRawStream ) if ( bRawStream )
{ {
// the raw stream was integrated and now behaves // the raw stream was integrated and now behaves
// as usual encrypted stream // as usual encrypted stream
rInfo.pStream->SetToBeEncrypted( true ); SetToBeEncrypted( true );
} }
// Then copy it back afterwards... // Then copy it back afterwards...
ZipPackageFolder::copyZipEntry ( rInfo.pStream->aEntry, *pTempEntry ); ZipPackageFolder::copyZipEntry ( aEntry, *pTempEntry );
// Remove hacky bit from entry flags // Remove hacky bit from entry flags
if ( rInfo.pStream->aEntry.nFlag & ( 1 << 4 ) ) if ( aEntry.nFlag & ( 1 << 4 ) )
{ {
rInfo.pStream->aEntry.nFlag &= ~( 1 << 4 ); aEntry.nFlag &= ~( 1 << 4 );
rInfo.pStream->aEntry.nMethod = STORED; aEntry.nMethod = STORED;
} }
// TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving ) // TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
if ( rInfo.pStream->IsEncrypted() ) if ( IsEncrypted() )
rInfo.pStream->setSize( nOwnStreamOrigSize ); setSize( nOwnStreamOrigSize );
rInfo.pStream->aEntry.nOffset *= -1; aEntry.nOffset *= -1;
} }
// folder can have a mediatype only in package format
if ( aPropSet.getLength() 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 ); rManList.push_back( aPropSet );
return bSuccess; return bSuccess;
...@@ -755,8 +742,8 @@ void ZipPackageFolder::saveContents( ...@@ -755,8 +742,8 @@ void ZipPackageFolder::saveContents(
if ( aIter != maContents.end() && !(*aIter).second->bFolder ) if ( aIter != maContents.end() && !(*aIter).second->bFolder )
{ {
bMimeTypeStreamStored = true; bMimeTypeStreamStored = true;
bWritingFailed = !ZipPackageStream_saveChild( m_xContext, bWritingFailed = !aIter->second->pStream->saveChild(
*aIter->second, rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat ); rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool );
} }
} }
...@@ -771,13 +758,13 @@ void ZipPackageFolder::saveContents( ...@@ -771,13 +758,13 @@ void ZipPackageFolder::saveContents(
{ {
if (rInfo.bFolder) if (rInfo.bFolder)
{ {
bWritingFailed = !ZipPackageFolder_saveChild( bWritingFailed = !rInfo.pFolder->saveChild(
rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat ); rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool );
} }
else else
{ {
bWritingFailed = !ZipPackageStream_saveChild( m_xContext, bWritingFailed = !rInfo.pStream->saveChild(
rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat ); rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool );
} }
} }
} }
......
...@@ -69,9 +69,9 @@ namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationI ...@@ -69,9 +69,9 @@ namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationI
ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
const uno::Reference< XComponentContext >& xContext, const uno::Reference< XComponentContext >& xContext,
sal_Int32 nFormat,
bool bAllowRemoveOnInsert ) bool bAllowRemoveOnInsert )
: m_xContext( xContext ) : m_rZipPackage( rNewPackage )
, m_rZipPackage( rNewPackage )
, m_bToBeCompressed ( true ) , m_bToBeCompressed ( true )
, m_bToBeEncrypted ( false ) , m_bToBeEncrypted ( false )
, m_bHaveOwnKey ( false ) , m_bHaveOwnKey ( false )
...@@ -88,10 +88,9 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, ...@@ -88,10 +88,9 @@ ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
, m_bFromManifest( false ) , m_bFromManifest( false )
, m_bUseWinEncoding( false ) , m_bUseWinEncoding( false )
{ {
OSL_ENSURE( m_xContext.is(), "No factory is provided to ZipPackageStream!\n" ); m_xContext = xContext;
m_nFormat = nFormat;
this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert; mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
SetFolder ( false ); SetFolder ( false );
aEntry.nVersion = -1; aEntry.nVersion = -1;
aEntry.nFlag = 0; aEntry.nFlag = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment