summaryrefslogtreecommitdiff
path: root/package/source
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2009-06-03 11:26:39 +0000
committerKurt Zenker <kz@openoffice.org>2009-06-03 11:26:39 +0000
commit65d3b7eea08aeb5bb6b510d683a1de602fc856cc (patch)
tree20d65f8e4aa9d14aa9e589f5b9ef9947ebb9f568 /package/source
parent3dc749116026183c4af40e4d3982387de9fab953 (diff)
CWS-TOOLING: integrate CWS os128
2009-04-22 12:58:26 +0200 b_michaelsen r271093 : #i101084# using the frames enumeration for other SwXFrames-queries; also added a complex test to ensure the behavior to be the same 2009-04-20 14:53:03 +0200 mav r270987 : #i101219# adjust the testcases to test memory cache and temporary file cache 2009-04-20 14:52:09 +0200 mav r270986 : #i101219#,#i99077# use memory to cache data; no precopying on commit 2009-04-20 14:39:21 +0200 mav r270984 : #i101219# use memory to cache data 2009-04-20 14:39:08 +0200 mav r270983 : #i101219# use memory to cache data 2009-04-20 14:38:45 +0200 mav r270982 : #i101219# use memory to cache data 2009-04-17 07:37:52 +0200 os r270912 : CWS-TOOLING: rebase CWS os128 to trunk@270723 (milestone: DEV300:m46) 2009-04-15 14:54:18 +0200 b_michaelsen r270845 : #i101084# using frame enumerations for paragraph export for better performance 2009-04-15 14:52:54 +0200 b_michaelsen r270843 : #i101084# implemented XEnumerationAccess interface on framesets 2009-04-03 17:08:10 +0200 mav r270504 : #i100722# do not compress streams of known compressed types per default 2009-04-03 13:49:50 +0200 os r270484 : resync error fixed 2009-04-03 12:55:32 +0200 mav r270470 : #i100722# do not compress streams of known compressed types per default 2009-04-03 10:00:58 +0200 os r270463 : resync error fixed 2009-04-03 09:52:53 +0200 os r270462 : resync error fixed 2009-04-03 09:10:14 +0200 os r270449 : #i99568# string compare operator of hash_map changed 2009-04-03 09:03:49 +0200 os r270446 : #i100683# normalize file URLs 2009-04-02 11:09:27 +0200 os r270381 : #i100683# making URLs relative without file access 2009-04-02 09:04:42 +0200 os r270366 : CWS-TOOLING: rebase CWS os128 to trunk@270033 (milestone: DEV300:m45) 2009-03-31 08:08:37 +0200 os r270258 : #i100683# reducing calls to URIHelper::simpleNormalizeMakeRelative() 2009-03-19 17:06:22 +0100 os r269756 : #i99568# XTolerantMultiPropertySet activated 2009-03-16 11:46:14 +0100 os r269517 : wrong commit to #i97471# removed 2009-03-16 11:36:50 +0100 os r269514 : #i97471# SwDrawTextShell::Init(): mouse double click and key input in group objects at the same time: prevent crash 2009-03-13 11:08:54 +0100 os r269464 : #i99568# static SfxItemPropertySet 2009-03-13 11:03:22 +0100 os r269463 : #i99568# static SfxItemPropertySet 2009-03-11 12:59:27 +0100 os r269320 : #i99568# WhichId of properties handled from ScDocOptionsObj added 2009-03-06 09:09:58 +0100 os r268972 : #i99568# SfxItemPropertySet improvements 2009-03-05 20:54:43 +0100 os r268942 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 20:19:52 +0100 os r268941 : #i99568# SfxItemPropertySet improvements 2009-03-05 20:05:03 +0100 os r268940 : #i99568# SfxItemPropertySet improvements 2009-03-05 18:54:47 +0100 os r268936 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 17:51:38 +0100 os r268931 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 17:33:03 +0100 os r268930 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:53:00 +0100 os r268920 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:52:50 +0100 os r268919 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:50:41 +0100 os r268918 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:41:04 +0100 os r268916 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:40:40 +0100 os r268915 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 10:16:20 +0100 os r268881 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 10:15:55 +0100 os r268880 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-03 08:40:09 +0100 os r268704 : ScTableSheetObj::GetItemPropertyMap fixed 2009-03-03 07:50:00 +0100 os r268703 : SfxItemProperty set as pointer 2009-03-03 07:49:46 +0100 os r268702 : SfxItemProperty set as pointer 2009-03-02 08:15:37 +0100 os r268631 : minor fix 2009-03-02 07:58:38 +0100 os r268630 : minor fix 2009-02-27 13:03:25 +0100 os r268584 : exports 2009-02-27 11:17:04 +0100 os r268567 : debug code removed 2009-02-27 11:04:07 +0100 os r268565 : duplicate return removed 2009-02-27 10:17:37 +0100 os r268558 : syntax fixed 2009-02-27 09:56:14 +0100 os r268554 : #i99568# type mix fixed 2009-02-27 09:40:56 +0100 os r268553 : #i99568# exports changes reverted 2009-02-25 12:50:54 +0100 os r268433 : #i99568# SfxItemPropertySet rework 2009-02-25 12:13:39 +0100 os r268432 : #i99568# SfxItemPropertySet rework 2009-02-25 12:12:47 +0100 os r268431 : #i99568# SfxItemPropertySet rework 2009-02-25 12:10:27 +0100 os r268430 : #i99568# SfxItemPropertySet rework 2009-02-25 12:09:36 +0100 os r268429 : #i99568# SfxItemPropertySet rework 2009-02-25 12:07:39 +0100 os r268428 : #i99568# SfxItemPropertySet rework 2009-02-25 11:59:35 +0100 os r268427 : #i99568# SfxItemPropertySet rework 2009-02-25 11:52:52 +0100 os r268425 : #i99568# SfxItemPropertySet rework 2009-02-25 11:49:17 +0100 os r268424 : #i99568# SfxItemPropertySet rework 2009-02-25 11:45:17 +0100 os r268423 : #i99568# SfxItemPropertySet rework 2009-02-11 11:39:04 +0100 os r267587 : #i57008# use registration of index marks at SwUnoCallback
Diffstat (limited to 'package/source')
-rw-r--r--package/source/xstor/owriteablestream.cxx560
-rw-r--r--package/source/xstor/owriteablestream.hxx14
-rw-r--r--package/source/xstor/xstorage.cxx6
-rw-r--r--package/source/zipapi/XFileStream.cxx2
-rw-r--r--package/source/zipapi/XUnbufferedStream.cxx4
-rw-r--r--package/source/zipapi/ZipFile.cxx13
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx13
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx15
8 files changed, 466 insertions, 161 deletions
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index b3b9ec6affa2..079b23d7c17a 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -58,10 +58,42 @@
#include <rtl/digest.h>
#include <rtl/logfile.hxx>
+// since the copying uses 32000 blocks usually, it makes sense to have a smaller size
+#define MAX_STORCACHE_SIZE 30000
+
using namespace ::com::sun::star;
//-----------------------------------------------
+uno::Sequence< sal_Int8 > MakeKeyFromPass( ::rtl::OUString aPass, sal_Bool bUseUTF )
+{
+ // MS_1252 encoding was used for SO60 document format password encoding,
+ // this encoding supports only a minor subset of nonascii characters,
+ // but for compatibility reasons it has to be used for old document formats
+
+ ::rtl::OString aByteStrPass;
+ if ( bUseUTF )
+ aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_UTF8 );
+ else
+ aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_MS_1252 );
+
+ sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1];
+ rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(),
+ aByteStrPass.getLength(),
+ pBuffer,
+ RTL_DIGEST_LENGTH_SHA1 );
+
+ if ( nError != rtl_Digest_E_None )
+ throw uno::RuntimeException();
+
+ return uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 );
+
+}
+
+// ================================================================
+namespace
+{
+//-----------------------------------------------
void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet,
const uno::Sequence< sal_Int8 >& aKey )
{
@@ -142,7 +174,6 @@ sal_Bool KillFile( const ::rtl::OUString& aURL, const uno::Reference< lang::XMul
const sal_Int32 n_ConstBufferSize = 32000;
//-----------------------------------------------
-
::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory )
{
::rtl::OUString aTempURL;
@@ -169,31 +200,16 @@ const sal_Int32 n_ConstBufferSize = 32000;
return aTempURL;
}
-uno::Sequence< sal_Int8 > MakeKeyFromPass( ::rtl::OUString aPass, sal_Bool bUseUTF )
+//-----------------------------------------------
+uno::Reference< io::XStream > CreateMemoryStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
{
- // MS_1252 encoding was used for SO60 document format password encoding,
- // this encoding supports only a minor subset of nonascii characters,
- // but for compatibility reasons it has to be used for old document formats
-
- ::rtl::OString aByteStrPass;
- if ( bUseUTF )
- aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_UTF8 );
- else
- aByteStrPass = ::rtl::OUStringToOString( aPass, RTL_TEXTENCODING_MS_1252 );
-
- sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1];
- rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(),
- aByteStrPass.getLength(),
- pBuffer,
- RTL_DIGEST_LENGTH_SHA1 );
-
- if ( nError != rtl_Digest_E_None )
+ if ( !xFactory.is() )
throw uno::RuntimeException();
- return uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 );
-
+ return uno::Reference< io::XStream >( xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.comp.MemoryStream" ) ), uno::UNO_QUERY_THROW );
}
+} // anonymous namespace
// ================================================================
//-----------------------------------------------
@@ -203,6 +219,7 @@ OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent,
const uno::Reference< lang::XMultiServiceFactory >& xFactory,
sal_Bool bForceEncrypted,
sal_Int16 nStorageType,
+ sal_Bool bDefaultCompress,
const uno::Reference< io::XInputStream >& xRelInfoStream )
: m_pAntiImpl( NULL )
, m_bHasDataToFlush( sal_False )
@@ -213,6 +230,7 @@ OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent,
, m_bForceEncrypted( bForceEncrypted )
, m_bUseCommonPass( !bForceEncrypted && nStorageType == PACKAGE_STORAGE )
, m_bHasCachedPassword( sal_False )
+, m_bCompressedSetExplicit( !bDefaultCompress )
, m_xPackage( xPackage )
, m_bHasInsertedStreamOptimization( sal_False )
, m_nStorageType( nStorageType )
@@ -238,6 +256,36 @@ OWriteStream_Impl::~OWriteStream_Impl()
KillFile( m_aTempURL, GetServiceFactory() );
m_aTempURL = ::rtl::OUString();
}
+
+ CleanCacheStream();
+}
+
+//-----------------------------------------------
+void OWriteStream_Impl::CleanCacheStream()
+{
+ if ( m_xCacheStream.is() )
+ {
+ try
+ {
+ uno::Reference< io::XInputStream > xInputCache = m_xCacheStream->getInputStream();
+ if ( xInputCache.is() )
+ xInputCache->closeInput();
+ }
+ catch( uno::Exception& )
+ {}
+
+ try
+ {
+ uno::Reference< io::XOutputStream > xOutputCache = m_xCacheStream->getOutputStream();
+ if ( xOutputCache.is() )
+ xOutputCache->closeOutput();
+ }
+ catch( uno::Exception& )
+ {}
+
+ m_xCacheStream = uno::Reference< io::XStream >();
+ m_xCacheSeek = uno::Reference< io::XSeekable >();
+ }
}
//-----------------------------------------------
@@ -269,7 +317,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted()
if ( m_bForceEncrypted || m_bHasCachedPassword )
return sal_True;
- if ( m_aTempURL.getLength() )
+ if ( m_aTempURL.getLength() || m_xCacheStream.is() )
return sal_False;
GetStreamProperties();
@@ -330,7 +378,7 @@ void OWriteStream_Impl::SetDecrypted()
GetStreamProperties();
// let the stream be modified
- GetFilledTempFile();
+ FillTempGetFileName();
m_bHasDataToFlush = sal_True;
// remove encryption
@@ -355,7 +403,7 @@ void OWriteStream_Impl::SetEncryptedWithPass( const ::rtl::OUString& aPass )
GetStreamProperties();
// let the stream be modified
- GetFilledTempFile();
+ FillTempGetFileName();
m_bHasDataToFlush = sal_True;
// introduce encryption info
@@ -412,14 +460,14 @@ uno::Reference< lang::XMultiServiceFactory > OWriteStream_Impl::GetServiceFactor
}
//-----------------------------------------------
-::rtl::OUString OWriteStream_Impl::GetFilledTempFile()
+::rtl::OUString OWriteStream_Impl::GetFilledTempFileIfNo( const uno::Reference< io::XInputStream >& xStream )
{
if ( !m_aTempURL.getLength() )
{
- m_aTempURL = GetNewTempFileURL( GetServiceFactory() );
+ ::rtl::OUString aTempURL = GetNewTempFileURL( GetServiceFactory() );
try {
- if ( m_aTempURL )
+ if ( aTempURL && xStream.is() )
{
uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
GetServiceFactory()->createInstance (
@@ -430,64 +478,155 @@ uno::Reference< lang::XMultiServiceFactory > OWriteStream_Impl::GetServiceFactor
throw uno::RuntimeException(); // TODO:
- // in case of new inserted package stream it is possible that input stream still was not set
- uno::Reference< io::XInputStream > xOrigStream = m_xPackageStream->getDataStream();
- if ( xOrigStream.is() )
+ uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aTempURL );
+ if ( xTempOutStream.is() )
{
- uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( m_aTempURL );
- if ( xTempOutStream.is() )
- {
- // copy stream contents to the file
- ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream );
- xTempOutStream->closeOutput();
- xTempOutStream = uno::Reference< io::XOutputStream >();
- }
- else
- throw io::IOException(); // TODO:
+ // the current position of the original stream should be still OK, copy further
+ ::comphelper::OStorageHelper::CopyInputToOutput( xStream, xTempOutStream );
+ xTempOutStream->closeOutput();
+ xTempOutStream = uno::Reference< io::XOutputStream >();
}
+ else
+ throw io::IOException(); // TODO:
}
}
catch( packages::WrongPasswordException& )
{
- KillFile( m_aTempURL, GetServiceFactory() );
- m_aTempURL = ::rtl::OUString();
-
+ KillFile( aTempURL, GetServiceFactory() );
throw;
}
catch( uno::Exception& )
{
- KillFile( m_aTempURL, GetServiceFactory() );
- m_aTempURL = ::rtl::OUString();
+ KillFile( aTempURL, GetServiceFactory() );
}
+
+ if ( aTempURL.getLength() )
+ CleanCacheStream();
+
+ m_aTempURL = aTempURL;
}
return m_aTempURL;
}
//-----------------------------------------------
-uno::Reference< io::XStream > OWriteStream_Impl::GetTempFileAsStream()
+::rtl::OUString OWriteStream_Impl::FillTempGetFileName()
{
- uno::Reference< io::XStream > xTempStream;
+ // should try to create cache first, if the amount of contents is too big, the temp file should be taken
+ if ( !m_xCacheStream.is() && !m_aTempURL.getLength() )
+ {
+ uno::Reference< io::XInputStream > xOrigStream = m_xPackageStream->getDataStream();
+ if ( !xOrigStream.is() )
+ {
+ // in case of new inserted package stream it is possible that input stream still was not set
+ uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() );
+ OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" );
+ m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW );
+ m_xCacheStream = xCacheStream;
+ }
+ else
+ {
+ sal_Int32 nRead = 0;
+ uno::Sequence< sal_Int8 > aData( MAX_STORCACHE_SIZE + 1 );
+ nRead = xOrigStream->readBytes( aData, MAX_STORCACHE_SIZE + 1 );
+ if ( aData.getLength() > nRead )
+ aData.realloc( nRead );
- if ( !m_aTempURL.getLength() )
- m_aTempURL = GetFilledTempFile();
+ if ( nRead && nRead <= MAX_STORCACHE_SIZE )
+ {
+ uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() );
+ OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" );
+
+ uno::Reference< io::XOutputStream > xOutStream( xCacheStream->getOutputStream(), uno::UNO_SET_THROW );
+ xOutStream->writeBytes( aData );
+ m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW );
+ m_xCacheStream = xCacheStream;
+ m_xCacheSeek->seek( 0 );
+ }
+ else if ( nRead && !m_aTempURL.getLength() )
+ {
+ m_aTempURL = GetNewTempFileURL( GetServiceFactory() );
- uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
- GetServiceFactory()->createInstance (
- ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
- uno::UNO_QUERY );
+ try {
+ if ( m_aTempURL.getLength() )
+ {
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ GetServiceFactory()->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
- if ( !xTempAccess.is() )
- throw uno::RuntimeException(); // TODO:
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
- try
- {
- xTempStream = xTempAccess->openFileReadWrite( m_aTempURL );
+
+ uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( m_aTempURL );
+ if ( xTempOutStream.is() )
+ {
+ // copy stream contents to the file
+ xTempOutStream->writeBytes( aData );
+
+ // the current position of the original stream should be still OK, copy further
+ ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream );
+ xTempOutStream->closeOutput();
+ xTempOutStream = uno::Reference< io::XOutputStream >();
+ }
+ else
+ throw io::IOException(); // TODO:
+ }
+ }
+ catch( packages::WrongPasswordException& )
+ {
+ KillFile( m_aTempURL, GetServiceFactory() );
+ m_aTempURL = ::rtl::OUString();
+
+ throw;
+ }
+ catch( uno::Exception& )
+ {
+ KillFile( m_aTempURL, GetServiceFactory() );
+ m_aTempURL = ::rtl::OUString();
+ }
+ }
+ }
}
- catch( uno::Exception& )
+
+ return m_aTempURL;
+}
+
+//-----------------------------------------------
+uno::Reference< io::XStream > OWriteStream_Impl::GetTempFileAsStream()
+{
+ uno::Reference< io::XStream > xTempStream;
+
+ if ( !m_xCacheStream.is() )
{
+ if ( !m_aTempURL.getLength() )
+ m_aTempURL = FillTempGetFileName();
+
+ if ( m_aTempURL.getLength() )
+ {
+ // the temporary file is not used if the cache is used
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ GetServiceFactory()->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
+
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ try
+ {
+ xTempStream = xTempAccess->openFileReadWrite( m_aTempURL );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
}
+ if ( m_xCacheStream.is() )
+ xTempStream = m_xCacheStream;
+
// the method must always return a stream
// in case the stream can not be open
// an exception should be thrown
@@ -502,25 +641,35 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetTempFileAsInputStream()
{
uno::Reference< io::XInputStream > xInputStream;
- if ( !m_aTempURL.getLength() )
- m_aTempURL = GetFilledTempFile();
+ if ( !m_xCacheStream.is() )
+ {
+ if ( !m_aTempURL.getLength() )
+ m_aTempURL = FillTempGetFileName();
- uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
- GetServiceFactory()->createInstance (
- ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
- uno::UNO_QUERY );
+ if ( m_aTempURL.getLength() )
+ {
+ // the temporary file is not used if the cache is used
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ GetServiceFactory()->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
- if ( !xTempAccess.is() )
- throw uno::RuntimeException(); // TODO:
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
- try
- {
- xInputStream = xTempAccess->openFileRead( m_aTempURL );
- }
- catch( uno::Exception& )
- {
+ try
+ {
+ xInputStream = xTempAccess->openFileRead( m_aTempURL );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
}
+ if ( m_xCacheStream.is() )
+ xInputStream = m_xCacheStream->getInputStream();
+
// the method must always return a stream
// in case the stream can not be open
// an exception should be thrown
@@ -534,29 +683,54 @@ uno::Reference< io::XInputStream > OWriteStream_Impl::GetTempFileAsInputStream()
void OWriteStream_Impl::CopyTempFileToOutput( uno::Reference< io::XOutputStream > xOutStream )
{
OSL_ENSURE( xOutStream.is(), "The stream must be specified!\n" );
- OSL_ENSURE( m_aTempURL.getLength(), "The temporary must exist!\n" );
-
- uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
- GetServiceFactory()->createInstance (
- ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
- uno::UNO_QUERY );
-
- if ( !xTempAccess.is() )
- throw uno::RuntimeException(); // TODO:
+ OSL_ENSURE( m_aTempURL.getLength() || m_xCacheStream.is(), "The temporary must exist!\n" );
uno::Reference< io::XInputStream > xTempInStream;
- try
+
+ if ( m_xCacheStream.is() )
{
- xTempInStream = xTempAccess->openFileRead( m_aTempURL );
+ if ( !m_xCacheSeek.is() )
+ throw uno::RuntimeException();
+ sal_Int64 nPos = m_xCacheSeek->getPosition();
+
+ try
+ {
+ m_xCacheSeek->seek( 0 );
+ uno::Reference< io::XInputStream > xTempInp = m_xCacheStream->getInputStream();
+ if ( xTempInp.is() )
+ ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream );
+ }
+ catch( uno::Exception& )
+ {
+ m_xCacheSeek->seek( nPos );
+ throw io::IOException(); //TODO:
+ }
+
+ m_xCacheSeek->seek( nPos );
}
- catch( uno::Exception& )
+ else if ( m_aTempURL.getLength() )
{
- }
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ GetServiceFactory()->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
- if ( !xTempInStream.is() )
- throw io::IOException(); //TODO:
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ try
+ {
+ xTempInStream = xTempAccess->openFileRead( m_aTempURL );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ if ( !xTempInStream.is() )
+ throw io::IOException(); //TODO:
- ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream );
+ ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream );
+ }
}
// =================================================================================================
@@ -576,7 +750,7 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt
if ( m_bHasDataToFlush )
throw io::IOException();
- OSL_ENSURE( !m_aTempURL.getLength(), "The temporary must not exist!\n" );
+ OSL_ENSURE( !m_aTempURL.getLength() && !m_xCacheStream.is(), "The temporary must not exist!\n" );
// use new file as current persistent representation
// the new file will be removed after it's stream is closed
@@ -624,7 +798,10 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt
}
if ( bCompressedIsSet )
- xPropertySet->setPropertyValue( aComprPropName, uno::makeAny( (sal_Bool)bCompressed ) );
+ {
+ xPropertySet->setPropertyValue( aComprPropName, uno::makeAny( (sal_Bool)bCompressed ) );
+ m_bCompressedSetExplicit = sal_True;
+ }
if ( m_bUseCommonPass )
{
@@ -655,34 +832,57 @@ void OWriteStream_Impl::Commit()
return;
uno::Reference< packages::XDataSinkEncrSupport > xNewPackageStream;
+ uno::Sequence< uno::Any > aSeq( 1 );
+ aSeq[0] <<= sal_False;
- OSL_ENSURE( m_bHasInsertedStreamOptimization || m_aTempURL.getLength(), "The temporary must exist!\n" );
- if ( m_aTempURL.getLength() )
+ if ( m_xCacheStream.is() )
{
- uno::Reference < io::XOutputStream > xTempOut(
- GetServiceFactory()->createInstance (
- ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
- uno::UNO_QUERY );
- uno::Reference < io::XInputStream > xTempIn( xTempOut, uno::UNO_QUERY );
+ uno::Reference< io::XInputStream > xInStream( m_xCacheStream->getInputStream(), uno::UNO_SET_THROW );
- if ( !xTempOut.is() || !xTempIn.is() )
- throw io::IOException();
+ xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >(
+ m_xPackage->createInstanceWithArguments( aSeq ),
+ uno::UNO_QUERY_THROW );
+
+ xNewPackageStream->setDataStream( xInStream );
+
+ m_xCacheStream = uno::Reference< io::XStream >();
+ m_xCacheSeek = uno::Reference< io::XSeekable >();
+
+ if ( m_pAntiImpl )
+ m_pAntiImpl->DeInit();
+ }
+ else if ( m_aTempURL.getLength() )
+ {
+ uno::Reference < ucb::XSimpleFileAccess > xTempAccess(
+ GetServiceFactory()->createInstance (
+ ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+ uno::UNO_QUERY );
+
+ if ( !xTempAccess.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ uno::Reference< io::XInputStream > xInStream;
+ try
+ {
+ xInStream = xTempAccess->openFileRead( m_aTempURL );
+ }
+ catch( uno::Exception& )
+ {
+ }
- // Copy temporary file to a new one
- CopyTempFileToOutput( xTempOut );
- xTempOut->closeOutput();
+ if ( !xInStream.is() )
+ throw io::IOException();
- uno::Sequence< uno::Any > aSeq( 1 );
- aSeq[0] <<= sal_False;
xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >(
m_xPackage->createInstanceWithArguments( aSeq ),
- uno::UNO_QUERY );
- if ( !xNewPackageStream.is() )
- throw uno::RuntimeException();
+ uno::UNO_QUERY_THROW );
+
+ // TODO/NEW: Let the temporary file be removed after commit
+ xNewPackageStream->setDataStream( xInStream );
+ m_aTempURL = ::rtl::OUString();
- // use new file as current persistent representation
- // the new file will be removed after it's stream is closed
- xNewPackageStream->setDataStream( xTempIn );
+ if ( m_pAntiImpl )
+ m_pAntiImpl->DeInit();
}
else // if ( m_bHasInsertedStreamOptimization )
{
@@ -746,7 +946,13 @@ void OWriteStream_Impl::Revert()
if ( !m_bHasDataToFlush )
return; // nothing to do
- OSL_ENSURE( m_aTempURL.getLength(), "The temporary must exist!\n" );
+ OSL_ENSURE( m_aTempURL.getLength() || m_xCacheStream.is(), "The temporary must exist!\n" );
+
+ if ( m_xCacheStream.is() )
+ {
+ m_xCacheStream = uno::Reference< io::XStream >();
+ m_xCacheSeek = uno::Reference< io::XSeekable >();
+ }
if ( m_aTempURL.getLength() )
{
@@ -1071,7 +1277,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod
// the stream must be resaved with new password encryption
if ( nStreamMode & embed::ElementModes::WRITE )
{
- GetFilledTempFile();
+ FillTempGetFileName();
m_bHasDataToFlush = sal_True;
// TODO/LATER: should the notification be done?
@@ -1149,7 +1355,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre
if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::READ )
{
uno::Reference< io::XInputStream > xInStream;
- if ( m_aTempURL.getLength() )
+ if ( m_xCacheStream.is() || m_aTempURL.getLength() )
xInStream = GetTempFileAsInputStream(); //TODO:
else
xInStream = m_xPackageStream->getDataStream();
@@ -1170,7 +1376,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre
}
else if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::SEEKABLEREAD )
{
- if ( !m_aTempURL.getLength() && !( m_xPackageStream->getDataStream().is() ) )
+ if ( !m_xCacheStream.is() && !m_aTempURL.getLength() && !( m_xPackageStream->getDataStream().is() ) )
{
// The stream does not exist in the storage
throw io::IOException();
@@ -1202,10 +1408,12 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre
if ( ( nStreamMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
{
if ( m_aTempURL.getLength() )
+ {
KillFile( m_aTempURL, GetServiceFactory() );
-
- // open new empty temp file
- m_aTempURL = GetNewTempFileURL( GetServiceFactory() );
+ m_aTempURL = ::rtl::OUString();
+ }
+ if ( m_xCacheStream.is() )
+ CleanCacheStream();
m_bHasDataToFlush = sal_True;
@@ -1213,11 +1421,13 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStre
if ( m_pParent )
m_pParent->m_bIsModified = sal_True;
- xStream = GetTempFileAsStream();
+ xStream = CreateMemoryStream( GetServiceFactory() );
+ m_xCacheSeek.set( xStream, uno::UNO_QUERY_THROW );
+ m_xCacheStream = xStream;
}
else if ( !m_bHasInsertedStreamOptimization )
{
- if ( !m_aTempURL.getLength() && !( m_xPackageStream->getDataStream().is() ) )
+ if ( !m_aTempURL.getLength() && !m_xCacheStream.is() && !( m_xPackageStream->getDataStream().is() ) )
{
// The stream does not exist in the storage
m_bHasDataToFlush = sal_True;
@@ -1572,6 +1782,7 @@ OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, sal_Bool bTransacted )
: m_pImpl( pImpl )
, m_bInStreamDisconnected( sal_False )
, m_bInitOnDemand( sal_True )
+, m_nInitPosition( 0 )
, m_bTransacted( bTransacted )
{
OSL_ENSURE( pImpl, "No base implementation!\n" );
@@ -1588,6 +1799,7 @@ OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, uno::Reference< io::XStrea
: m_pImpl( pImpl )
, m_bInStreamDisconnected( sal_False )
, m_bInitOnDemand( sal_False )
+, m_nInitPosition( 0 )
, m_bTransacted( bTransacted )
{
OSL_ENSURE( pImpl && xStream.is(), "No base implementation!\n" );
@@ -1631,6 +1843,21 @@ OWriteStream::~OWriteStream()
}
//-----------------------------------------------
+void OWriteStream::DeInit()
+{
+ if ( !m_pImpl )
+ return; // do nothing
+
+ if ( m_xSeekable.is() )
+ m_nInitPosition = m_xSeekable->getPosition();
+
+ m_xInStream = uno::Reference< io::XInputStream >();
+ m_xOutStream = uno::Reference< io::XOutputStream >();
+ m_xSeekable = uno::Reference< io::XSeekable >();
+ m_bInitOnDemand = sal_True;
+}
+
+//-----------------------------------------------
void OWriteStream::CheckInitOnDemand()
{
if ( !m_pImpl )
@@ -1642,11 +1869,12 @@ void OWriteStream::CheckInitOnDemand()
uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream();
if ( xStream.is() )
{
- m_xInStream = xStream->getInputStream();
- m_xOutStream = xStream->getOutputStream();
- m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY );
- OSL_ENSURE( m_xInStream.is() && m_xOutStream.is() && m_xSeekable.is(), "Stream implementation is incomplete!\n" );
+ m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW );
+ m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW );
+ m_xSeekable.set( xStream, uno::UNO_QUERY_THROW );
+ m_xSeekable->seek( m_nInitPosition );
+ m_nInitPosition = 0;
m_bInitOnDemand = sal_False;
}
}
@@ -2072,11 +2300,54 @@ void SAL_CALL OWriteStream::writeBytes( const uno::Sequence< sal_Int8 >& aData )
{
::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
- CheckInitOnDemand();
+ // the write method makes initialization itself, since it depends from the aData length
+ // NO CheckInitOnDemand()!
if ( !m_pImpl )
throw lang::DisposedException();
+ if ( !m_bInitOnDemand )
+ {
+ if ( !m_xOutStream.is() || !m_xSeekable.is())
+ throw io::NotConnectedException();
+
+ if ( m_pImpl->m_xCacheStream.is() )
+ {
+ // check whether the cache should be turned off
+ sal_Int64 nPos = m_xSeekable->getPosition();
+ if ( nPos + aData.getLength() > MAX_STORCACHE_SIZE )
+ {
+ // disconnect the cache and copy the data to the temporary file
+ m_xSeekable->seek( 0 );
+
+ // it is enough to copy the cached stream, the cache should already contain everything
+ if ( m_pImpl->GetFilledTempFileIfNo( m_xInStream ).getLength() )
+ {
+ DeInit();
+ // the last position is known and it is differs from the current stream position
+ m_nInitPosition = nPos;
+ }
+ }
+ }
+ }
+
+ if ( m_bInitOnDemand )
+ {
+ RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" );
+ uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream();
+ if ( xStream.is() )
+ {
+ m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW );
+ m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW );
+ m_xSeekable.set( xStream, uno::UNO_QUERY_THROW );
+ m_xSeekable->seek( m_nInitPosition );
+
+ m_nInitPosition = 0;
+ m_bInitOnDemand = sal_False;
+ }
+ }
+
+
if ( !m_xOutStream.is() )
throw io::NotConnectedException();
@@ -2735,11 +3006,35 @@ void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyNa
throw lang::DisposedException();
m_pImpl->GetStreamProperties();
+ ::rtl::OUString aCompressedString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) );
+ ::rtl::OUString aMediaTypeString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
+ if ( m_pData->m_nStorageType == PACKAGE_STORAGE && aPropertyName.equals( aMediaTypeString ) )
+ {
+ // if the "Compressed" property is not set explicitly, the MediaType can change the default value
+ sal_Bool bCompressedValueFromType = sal_True;
+ ::rtl::OUString aType;
+ aValue >>= aType;
- if ( ( m_pData->m_nStorageType == PACKAGE_STORAGE || m_pData->m_nStorageType == OFOPXML_STORAGE )
- && aPropertyName.equalsAscii( "MediaType" )
- || aPropertyName.equalsAscii( "Compressed" ) )
+ if ( !m_pImpl->m_bCompressedSetExplicit )
+ {
+ if ( aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/jpeg" ) ) )
+ || aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ) )
+ || aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/gif" ) ) ) )
+ bCompressedValueFromType = sal_False;
+ }
+
+ for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
+ {
+ if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
+ m_pImpl->m_aProps[nInd].Value = aValue;
+ else if ( !m_pImpl->m_bCompressedSetExplicit && aCompressedString.equals( m_pImpl->m_aProps[nInd].Name ) )
+ m_pImpl->m_aProps[nInd].Value <<= bCompressedValueFromType;
+ }
+ }
+ else if ( m_pData->m_nStorageType == PACKAGE_STORAGE && aPropertyName.equalsAscii( "Compressed" ) )
{
+ // if the "Compressed" property is not set explicitly, the MediaType can change the default value
+ m_pImpl->m_bCompressedSetExplicit = sal_True;
for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
{
if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
@@ -2771,6 +3066,15 @@ void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyNa
else
throw lang::IllegalArgumentException(); //TODO
}
+ else if ( m_pData->m_nStorageType == OFOPXML_STORAGE
+ && ( aPropertyName.equalsAscii( "MediaType" ) || aPropertyName.equalsAscii( "Compressed" ) ) )
+ {
+ for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
+ {
+ if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
+ m_pImpl->m_aProps[nInd].Value = aValue;
+ }
+ }
else if ( m_pData->m_nStorageType == OFOPXML_STORAGE && aPropertyName.equalsAscii( "RelationsInfoStream" ) )
{
uno::Reference< io::XInputStream > xInRelStream;
diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx
index e9b10ce8ebc0..a3ee6d91862e 100644
--- a/package/source/xstor/owriteablestream.hxx
+++ b/package/source/xstor/owriteablestream.hxx
@@ -34,7 +34,6 @@
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/io/XStream.hpp>
-#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XSeekable.hpp>
#include <com/sun/star/io/XTruncate.hpp>
#include <com/sun/star/packages/XDataSinkEncrSupport.hpp>
@@ -106,6 +105,9 @@ struct OWriteStream_Impl : public PreCreationStruct
OWriteStream* m_pAntiImpl;
::rtl::OUString m_aTempURL;
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xCacheStream;
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xCacheSeek;
+
InputStreamsList_Impl m_aInputStreamsList;
sal_Bool m_bHasDataToFlush; // only modified elements will be sent to the original content
@@ -125,6 +127,8 @@ struct OWriteStream_Impl : public PreCreationStruct
sal_Bool m_bHasCachedPassword;
::rtl::OUString m_aPass;
+ sal_Bool m_bCompressedSetExplicit;
+
::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage;
sal_Bool m_bHasInsertedStreamOptimization;
@@ -145,7 +149,8 @@ struct OWriteStream_Impl : public PreCreationStruct
private:
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > GetServiceFactory();
- ::rtl::OUString GetFilledTempFile();
+ ::rtl::OUString GetFilledTempFileIfNo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream );
+ ::rtl::OUString FillTempGetFileName();
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetTempFileAsStream();
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetTempFileAsInputStream();
@@ -169,11 +174,14 @@ public:
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
sal_Bool bForceEncrypted,
sal_Int16 nStorageType,
+ sal_Bool bDefaultCompress,
const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xRelInfoStream =
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >() );
~OWriteStream_Impl();
+ void CleanCacheStream();
+
sal_Bool UsesCommonPass_Impl() { return m_bUseCommonPass; }
sal_Bool HasTempFile_Impl() { return ( m_aTempURL.getLength() != 0 ); }
sal_Bool IsTransacted();
@@ -279,6 +287,7 @@ protected:
sal_Bool m_bInStreamDisconnected;
sal_Bool m_bInitOnDemand;
+ sal_Int64 m_nInitPosition;
sal_Bool m_bTransacted;
@@ -298,6 +307,7 @@ public:
virtual ~OWriteStream();
void CheckInitOnDemand();
+ void DeInit();
// XInterface
virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType )
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 0d0b011aec35..3705e560890c 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -1384,7 +1384,7 @@ SotElement_Impl* OStorage_Impl::InsertStream( ::rtl::OUString aName, sal_Bool bE
// the mode is not needed for storage stream internal implementation
SotElement_Impl* pNewElement = InsertElement( aName, sal_False );
- pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, bEncr, m_nStorageType );
+ pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, bEncr, m_nStorageType, sal_True );
m_aChildrenList.push_back( pNewElement );
m_bIsModified = sal_True;
@@ -1425,7 +1425,7 @@ SotElement_Impl* OStorage_Impl::InsertRawStream( ::rtl::OUString aName, const un
// the mode is not needed for storage stream internal implementation
SotElement_Impl* pNewElement = InsertElement( aName, sal_False );
- pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_True, m_nStorageType );
+ pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_True, m_nStorageType, sal_False );
// the stream is inserted and must be treated as a commited one
pNewElement->m_pStream->SetToBeCommited();
@@ -1564,7 +1564,7 @@ void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement )
throw uno::RuntimeException(); // TODO
// the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction
- pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_False, m_nStorageType, GetRelInfoStreamForName( pElement->m_aOriginalName ) );
+ pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_False, m_nStorageType, sal_False, GetRelInfoStreamForName( pElement->m_aOriginalName ) );
}
}
diff --git a/package/source/zipapi/XFileStream.cxx b/package/source/zipapi/XFileStream.cxx
index 220c7e8f1b0e..09df729809d4 100644
--- a/package/source/zipapi/XFileStream.cxx
+++ b/package/source/zipapi/XFileStream.cxx
@@ -84,7 +84,7 @@ XFileStream::XFileStream( ZipEntry & rEntry,
if ( bHaveEncryptData )
{
if ( !bNewRawStream )
- ZipFile::StaticGetCipher ( rData, maCipher );
+ ZipFile::StaticGetCipher ( rData, maCipher, sal_True );
else
{
// Put in the EncryptedDataHeader
diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx
index ff8a085e6b8d..cb99c085bc28 100644
--- a/package/source/zipapi/XUnbufferedStream.cxx
+++ b/package/source/zipapi/XUnbufferedStream.cxx
@@ -93,7 +93,7 @@ XUnbufferedStream::XUnbufferedStream( ZipEntry & rEntry,
sal_Bool bMustDecrypt = ( nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False;
if ( bMustDecrypt )
- ZipFile::StaticGetCipher ( rData, maCipher );
+ ZipFile::StaticGetCipher ( rData, maCipher, sal_True );
if ( bHaveEncryptData && mbWrappedRaw && bIsEncrypted )
{
// if we have the data needed to decrypt it, but didn't want it decrypted (or
@@ -147,7 +147,7 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre
mnZipEnd = mnZipCurrent + mnZipSize;
- ZipFile::StaticGetCipher ( rData, maCipher );
+ ZipFile::StaticGetCipher ( rData, maCipher, sal_True );
}
XUnbufferedStream::~XUnbufferedStream()
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 291357c1adb2..0be136e75d6f 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -127,8 +127,9 @@ void ZipFile::setInputStream ( Reference < XInputStream > xNewStream )
aGrabber.setInputStream ( xStream );
}
-void ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher )
+sal_Bool ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode )
{
+ sal_Bool bResult = sal_False;
if ( ! xEncryptionData.isEmpty() )
{
Sequence < sal_uInt8 > aDerivedKey (16);
@@ -144,13 +145,17 @@ void ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData,
xEncryptionData->nIterationCount );
rCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
- aResult = rtl_cipher_init( rCipher, rtl_Cipher_DirectionDecode,
+ aResult = rtl_cipher_init( rCipher, bDecode ? rtl_Cipher_DirectionDecode : rtl_Cipher_DirectionEncode,
aDerivedKey.getConstArray(),
aDerivedKey.getLength(),
reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aInitVector.getConstArray() ),
xEncryptionData->aInitVector.getLength());
OSL_ASSERT (aResult == rtl_Cipher_E_None);
+
+ bResult = ( aResult == rtl_Cipher_E_None );
}
+
+ return bResult;
}
void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData,
@@ -335,7 +340,7 @@ sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffe
// make a temporary cipher
rtlCipher aCipher;
- StaticGetCipher ( rData, aCipher );
+ StaticGetCipher ( rData, aCipher, sal_True );
Sequence < sal_Int8 > aDecryptBuffer ( nSize );
rtlDigest aDigest = rtl_digest_createSHA1();
@@ -434,7 +439,7 @@ Reference < XInputStream > ZipFile::createMemoryStream(
if ( bMustDecrypt )
{
- StaticGetCipher ( rData, aCipher );
+ StaticGetCipher ( rData, aCipher, sal_True );
aDecryptBuffer.realloc ( nSize );
}
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index a1504f0aa526..8954db47d63c 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -36,6 +36,7 @@
#include <EncryptionData.hxx>
#include <PackageConstants.hxx>
#include <ZipEntry.hxx>
+#include <ZipFile.hxx>
#ifndef _VOS_REF_H_
#include <vos/ref.hxx>
#endif
@@ -103,15 +104,9 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry,
if (bEncrypt)
{
bEncryptCurrentEntry = sal_True;
- rtlCipherError aResult;
-
- aCipher = rtl_cipher_create ( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
- aResult = rtl_cipher_init( aCipher, rtl_Cipher_DirectionEncode,
- reinterpret_cast < const sal_uInt8 * > (xEncryptData->aKey.getConstArray() ),
- xEncryptData->aKey.getLength(),
- reinterpret_cast < const sal_uInt8 * > ( xEncryptData->aInitVector.getConstArray() ),
- xEncryptData->aInitVector.getLength());
- OSL_ASSERT( aResult == rtl_Cipher_E_None );
+
+ ZipFile::StaticGetCipher( xEncryptData, aCipher, sal_False );
+
aDigest = rtl_digest_createSHA1();
mnDigested = 0;
rEntry.nFlag |= 1 << 4;
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index 1d5e900e28fe..8e0c8718dbfb 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -449,25 +449,16 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw )
{
Sequence < sal_uInt8 > aSalt ( 16 ), aVector ( 8 );
- Sequence < sal_Int8 > aKey ( 16 );
rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 );
rtl_random_getBytes ( rRandomPool, aVector.getArray(), 8 );
sal_Int32 nIterationCount = 1024;
- if ( pStream->HasOwnKey() )
- rtl_digest_PBKDF2 ( reinterpret_cast < sal_uInt8 * > (aKey.getArray()), 16,
- reinterpret_cast < const sal_uInt8 * > (pStream->getKey().getConstArray()), pStream->getKey().getLength(),
- reinterpret_cast < const sal_uInt8 * > ( aSalt.getConstArray() ), 16,
- nIterationCount );
- else
- rtl_digest_PBKDF2 ( reinterpret_cast < sal_uInt8 * > (aKey.getArray()), 16,
- reinterpret_cast < const sal_uInt8 * > (rEncryptionKey.getConstArray()), rEncryptionKey.getLength(),
- reinterpret_cast < const sal_uInt8 * > ( aSalt.getConstArray() ), 16,
- nIterationCount );
+ if ( !pStream->HasOwnKey() )
+ pStream->setKey ( rEncryptionKey );
+
pStream->setInitialisationVector ( aVector );
pStream->setSalt ( aSalt );
pStream->setIterationCount ( nIterationCount );
- pStream->setKey ( aKey );
}
// last property is digest, which is inserted later if we didn't have