1*a3872823SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a3872823SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a3872823SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a3872823SAndrew Rist  * distributed with this work for additional information
6*a3872823SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a3872823SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a3872823SAndrew Rist  * "License"); you may not use this file except in compliance
9*a3872823SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a3872823SAndrew Rist  *
11*a3872823SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a3872823SAndrew Rist  *
13*a3872823SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a3872823SAndrew Rist  * software distributed under the License is distributed on an
15*a3872823SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a3872823SAndrew Rist  * KIND, either express or implied.  See the License for the
17*a3872823SAndrew Rist  * specific language governing permissions and limitations
18*a3872823SAndrew Rist  * under the License.
19*a3872823SAndrew Rist  *
20*a3872823SAndrew Rist  *************************************************************/
21*a3872823SAndrew Rist 
22*a3872823SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER( update_precomp.py ): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_package.hxx"
26cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipConstants.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/StorageFormats.hpp>
28cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipIOException.hpp>
29cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
32cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
33cdf0e10cSrcweir #include <com/sun/star/xml/crypto/DigestID.hpp>
34cdf0e10cSrcweir #include <com/sun/star/xml/crypto/CipherID.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <ZipPackageStream.hxx>
38cdf0e10cSrcweir #include <ZipPackage.hxx>
39cdf0e10cSrcweir #include <ZipFile.hxx>
40cdf0e10cSrcweir #include <EncryptedDataHeader.hxx>
41cdf0e10cSrcweir #include <vos/diagnose.hxx>
42cdf0e10cSrcweir #include "wrapstreamforshare.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <comphelper/seekableinput.hxx>
45cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <rtl/instance.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <PackageConstants.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using namespace com::sun::star::packages::zip::ZipConstants;
52cdf0e10cSrcweir using namespace com::sun::star::packages::zip;
53cdf0e10cSrcweir using namespace com::sun::star::uno;
54cdf0e10cSrcweir using namespace com::sun::star::lang;
55cdf0e10cSrcweir using namespace com::sun::star;
56cdf0e10cSrcweir using namespace cppu;
57cdf0e10cSrcweir using namespace rtl;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; }
60cdf0e10cSrcweir 
static_getImplementationId()61cdf0e10cSrcweir const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::static_getImplementationId()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     return lcl_CachedImplId::get();
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
ZipPackageStream(ZipPackage & rNewPackage,const uno::Reference<XMultiServiceFactory> & xFactory,sal_Bool bAllowRemoveOnInsert)66cdf0e10cSrcweir ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
67cdf0e10cSrcweir 									const uno::Reference< XMultiServiceFactory >& xFactory,
68cdf0e10cSrcweir 									sal_Bool bAllowRemoveOnInsert )
69cdf0e10cSrcweir : m_xFactory( xFactory )
70cdf0e10cSrcweir , rZipPackage( rNewPackage )
71cdf0e10cSrcweir , bToBeCompressed ( sal_True )
72cdf0e10cSrcweir , bToBeEncrypted ( sal_False )
73cdf0e10cSrcweir , bHaveOwnKey ( sal_False )
74cdf0e10cSrcweir , bIsEncrypted ( sal_False )
75cdf0e10cSrcweir , m_nImportedStartKeyAlgorithm( 0 )
76cdf0e10cSrcweir , m_nImportedEncryptionAlgorithm( 0 )
77cdf0e10cSrcweir , m_nImportedChecksumAlgorithm( 0 )
78cdf0e10cSrcweir , m_nImportedDerivedKeySize( 0 )
79cdf0e10cSrcweir , m_nStreamMode( PACKAGE_STREAM_NOTSET )
80cdf0e10cSrcweir , m_nMagicalHackPos( 0 )
81cdf0e10cSrcweir , m_nMagicalHackSize( 0 )
82cdf0e10cSrcweir , m_bHasSeekable( sal_False )
83cdf0e10cSrcweir , m_bCompressedIsSetFromOutside( sal_False )
84cdf0e10cSrcweir , m_bFromManifest( sal_False )
85cdf0e10cSrcweir , m_bUseWinEncoding( false )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	OSL_ENSURE( m_xFactory.is(), "No factory is provided to ZipPackageStream!\n" );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	SetFolder ( sal_False );
92cdf0e10cSrcweir 	aEntry.nVersion		= -1;
93cdf0e10cSrcweir 	aEntry.nFlag		= 0;
94cdf0e10cSrcweir 	aEntry.nMethod		= -1;
95cdf0e10cSrcweir 	aEntry.nTime		= -1;
96cdf0e10cSrcweir 	aEntry.nCrc			= -1;
97cdf0e10cSrcweir 	aEntry.nCompressedSize	= -1;
98cdf0e10cSrcweir 	aEntry.nSize		= -1;
99cdf0e10cSrcweir 	aEntry.nOffset		= -1;
100cdf0e10cSrcweir 	aEntry.nPathLen		= -1;
101cdf0e10cSrcweir 	aEntry.nExtraLen	= -1;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get();
104cdf0e10cSrcweir 	if ( !rCachedImplId.getLength() )
105cdf0e10cSrcweir 	    rCachedImplId = getImplementationId();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
~ZipPackageStream(void)108cdf0e10cSrcweir ZipPackageStream::~ZipPackageStream( void )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
setZipEntryOnLoading(const ZipEntry & rInEntry)112cdf0e10cSrcweir void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	aEntry.nVersion = rInEntry.nVersion;
115cdf0e10cSrcweir 	aEntry.nFlag = rInEntry.nFlag;
116cdf0e10cSrcweir 	aEntry.nMethod = rInEntry.nMethod;
117cdf0e10cSrcweir 	aEntry.nTime = rInEntry.nTime;
118cdf0e10cSrcweir 	aEntry.nCrc = rInEntry.nCrc;
119cdf0e10cSrcweir 	aEntry.nCompressedSize = rInEntry.nCompressedSize;
120cdf0e10cSrcweir 	aEntry.nSize = rInEntry.nSize;
121cdf0e10cSrcweir 	aEntry.nOffset = rInEntry.nOffset;
122cdf0e10cSrcweir 	aEntry.sPath = rInEntry.sPath;
123cdf0e10cSrcweir 	aEntry.nPathLen = rInEntry.nPathLen;
124cdf0e10cSrcweir 	aEntry.nExtraLen = rInEntry.nExtraLen;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	if ( aEntry.nMethod == STORED )
127cdf0e10cSrcweir 		bToBeCompressed = sal_False;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //--------------------------------------------------------------------------
CloseOwnStreamIfAny()131cdf0e10cSrcweir void ZipPackageStream::CloseOwnStreamIfAny()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	if ( xStream.is() )
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		xStream->closeInput();
136cdf0e10cSrcweir 		xStream = uno::Reference< io::XInputStream >();
137cdf0e10cSrcweir 		m_bHasSeekable = sal_False;
138cdf0e10cSrcweir 	}
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //--------------------------------------------------------------------------
GetOwnSeekStream()142cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream()
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	if ( !m_bHasSeekable && xStream.is() )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		// The package component requires that every stream either be FROM a package or it must support XSeekable!
147cdf0e10cSrcweir 		// The only exception is a nonseekable stream that is provided only for storing, if such a stream
148cdf0e10cSrcweir 		// is accessed before commit it MUST be wrapped.
149cdf0e10cSrcweir 		// Wrap the stream in case it is not seekable
150cdf0e10cSrcweir 		xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xStream, m_xFactory );
151cdf0e10cSrcweir 		uno::Reference< io::XSeekable > xSeek( xStream, UNO_QUERY );
152cdf0e10cSrcweir 		if ( !xSeek.is() )
153cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ),
154cdf0e10cSrcweir 									uno::Reference< XInterface >() );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		m_bHasSeekable = sal_True;
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	return xStream;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //--------------------------------------------------------------------------
GetRawEncrStreamNoHeaderCopy()163cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCopy()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	if ( m_nStreamMode != PACKAGE_STREAM_RAW || !GetOwnSeekStream().is() )
166cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	if ( m_xBaseEncryptionData.is() )
169cdf0e10cSrcweir 		throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Encrypted stream without encryption data!\n" ) ),
170cdf0e10cSrcweir 							uno::Reference< XInterface >() );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeek( GetOwnSeekStream(), UNO_QUERY );
173cdf0e10cSrcweir 	if ( !xSeek.is() )
174cdf0e10cSrcweir 		throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must be seekable!\n" ) ),
175cdf0e10cSrcweir 							uno::Reference< XInterface >() );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	// skip header
178cdf0e10cSrcweir 	xSeek->seek( n_ConstHeaderSize + getInitialisationVector().getLength() +
179cdf0e10cSrcweir 					getSalt().getLength() + getDigest().getLength() );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	// create temporary stream
182cdf0e10cSrcweir 	uno::Reference < io::XOutputStream > xTempOut(
183cdf0e10cSrcweir 						m_xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
184cdf0e10cSrcweir 						uno::UNO_QUERY );
185cdf0e10cSrcweir 	uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY );
186cdf0e10cSrcweir 	uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY );
187cdf0e10cSrcweir 	if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() )
188cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	// copy the raw stream to the temporary file starting from the current position
191cdf0e10cSrcweir 	::comphelper::OStorageHelper::CopyInputToOutput( GetOwnSeekStream(), xTempOut );
192cdf0e10cSrcweir 	xTempOut->closeOutput();
193cdf0e10cSrcweir 	xTempSeek->seek( 0 );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	return xTempIn;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir //--------------------------------------------------------------------------
GetEncryptionAlgorithm() const199cdf0e10cSrcweir sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : rZipPackage.GetEncAlgID();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir //--------------------------------------------------------------------------
GetBlockSize() const205cdf0e10cSrcweir sal_Int32 ZipPackageStream::GetBlockSize() const
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     return GetEncryptionAlgorithm() == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 8;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //--------------------------------------------------------------------------
GetEncryptionData(bool bUseWinEncoding)211cdf0e10cSrcweir ::rtl::Reference< EncryptionData > ZipPackageStream::GetEncryptionData( bool bUseWinEncoding )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     ::rtl::Reference< EncryptionData > xResult;
214cdf0e10cSrcweir     if ( m_xBaseEncryptionData.is() )
215cdf0e10cSrcweir         xResult = new EncryptionData(
216cdf0e10cSrcweir             *m_xBaseEncryptionData,
217cdf0e10cSrcweir             GetEncryptionKey( bUseWinEncoding ),
218cdf0e10cSrcweir             GetEncryptionAlgorithm(),
219cdf0e10cSrcweir             m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(),
220cdf0e10cSrcweir             m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(),
221cdf0e10cSrcweir             GetStartKeyGenID() );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     return xResult;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //--------------------------------------------------------------------------
SetBaseEncryptionData(const::rtl::Reference<BaseEncryptionData> & xData)227cdf0e10cSrcweir void ZipPackageStream::SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     m_xBaseEncryptionData = xData;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir //--------------------------------------------------------------------------
GetEncryptionKey(bool bUseWinEncoding)233cdf0e10cSrcweir uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     uno::Sequence< sal_Int8 > aResult;
236cdf0e10cSrcweir     sal_Int32 nKeyGenID = GetStartKeyGenID();
237cdf0e10cSrcweir     bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() )
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         ::rtl::OUString aNameToFind;
242cdf0e10cSrcweir         if ( nKeyGenID == xml::crypto::DigestID::SHA256 )
243cdf0e10cSrcweir             aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8;
244cdf0e10cSrcweir         else if ( nKeyGenID == xml::crypto::DigestID::SHA1 )
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             aNameToFind = bUseWinEncoding ? PACKAGE_ENCRYPTIONDATA_SHA1MS1252 : PACKAGE_ENCRYPTIONDATA_SHA1UTF8;
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir         else
249cdf0e10cSrcweir             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ )
252cdf0e10cSrcweir             if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) )
253cdf0e10cSrcweir                 m_aStorageEncryptionKeys[nInd].Value >>= aResult;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         // empty keys are not allowed here
256cdf0e10cSrcweir         // so it is not important whether there is no key, or the key is empty, it is an error
257cdf0e10cSrcweir         if ( !aResult.getLength() )
258cdf0e10cSrcweir             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() );
259cdf0e10cSrcweir     }
260cdf0e10cSrcweir     else
261cdf0e10cSrcweir         aResult = m_aEncryptionKey;
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     if ( !aResult.getLength() || !bHaveOwnKey )
264cdf0e10cSrcweir         aResult = rZipPackage.GetEncryptionKey();
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     return aResult;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir //--------------------------------------------------------------------------
GetStartKeyGenID()270cdf0e10cSrcweir sal_Int32 ZipPackageStream::GetStartKeyGenID()
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     // generally should all the streams use the same Start Key
273cdf0e10cSrcweir     // but if raw copy without password takes place, we should preserve the imported algorithm
274cdf0e10cSrcweir     return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetStartKeyGenID();
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir //--------------------------------------------------------------------------
TryToGetRawFromDataStream(sal_Bool bAddHeaderForEncr)278cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !bToBeEncrypted ) )
281cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	Sequence< sal_Int8 > aKey;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	if ( bToBeEncrypted )
286cdf0e10cSrcweir 	{
287cdf0e10cSrcweir 		aKey = GetEncryptionKey();
288cdf0e10cSrcweir 		if ( !aKey.getLength() )
289cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
290cdf0e10cSrcweir 	}
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	try
293cdf0e10cSrcweir 	{
294cdf0e10cSrcweir 		// create temporary file
295cdf0e10cSrcweir 		uno::Reference < io::XStream > xTempStream(
296cdf0e10cSrcweir 							m_xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
297cdf0e10cSrcweir 							uno::UNO_QUERY );
298cdf0e10cSrcweir 		if ( !xTempStream.is() )
299cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 		// create a package based on it
302cdf0e10cSrcweir 		ZipPackage* pPackage = new ZipPackage( m_xFactory );
303cdf0e10cSrcweir 		uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) );
304cdf0e10cSrcweir 		if ( !xPackageAsFactory.is() )
305cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 		Sequence< Any > aArgs( 1 );
308cdf0e10cSrcweir 		aArgs[0] <<= xTempStream;
309cdf0e10cSrcweir 		pPackage->initialize( aArgs );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 		// create a new package stream
312cdf0e10cSrcweir 		uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY );
313cdf0e10cSrcweir 		if ( !xNewPackStream.is() )
314cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 		xNewPackStream->setDataStream( static_cast< io::XInputStream* >(
317cdf0e10cSrcweir 													new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 		uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY );
320cdf0e10cSrcweir 		if ( !xNewPSProps.is() )
321cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 		// copy all the properties of this stream to the new stream
324cdf0e10cSrcweir 		xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), makeAny( sMediaType ) );
325cdf0e10cSrcweir 		xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( bToBeCompressed ) );
326cdf0e10cSrcweir 		if ( bToBeEncrypted )
327cdf0e10cSrcweir 		{
328cdf0e10cSrcweir 			xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ), makeAny( aKey ) );
329cdf0e10cSrcweir 			xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ), makeAny( sal_True ) );
330cdf0e10cSrcweir 		}
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 		// insert a new stream in the package
333cdf0e10cSrcweir 		uno::Reference< XUnoTunnel > xTunnel;
334cdf0e10cSrcweir 		Any aRoot = pPackage->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) );
335cdf0e10cSrcweir 		aRoot >>= xTunnel;
336cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY );
337cdf0e10cSrcweir 		if ( !xRootNameContainer.is() )
338cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 		uno::Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY );
341cdf0e10cSrcweir 		xRootNameContainer->insertByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummy" ) ), makeAny( xNPSTunnel ) );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 		// commit the temporary package
344cdf0e10cSrcweir 		pPackage->commitChanges();
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 		// get raw stream from the temporary package
347cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xInRaw;
348cdf0e10cSrcweir 		if ( bAddHeaderForEncr )
349cdf0e10cSrcweir 			xInRaw = xNewPackStream->getRawStream();
350cdf0e10cSrcweir 		else
351cdf0e10cSrcweir 			xInRaw = xNewPackStream->getPlainRawStream();
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		// create another temporary file
354cdf0e10cSrcweir 		uno::Reference < io::XOutputStream > xTempOut(
355cdf0e10cSrcweir 							m_xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
356cdf0e10cSrcweir 							uno::UNO_QUERY );
357cdf0e10cSrcweir 		uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY );
358cdf0e10cSrcweir 		uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY );
359cdf0e10cSrcweir 		if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() )
360cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 		// copy the raw stream to the temporary file
363cdf0e10cSrcweir 		::comphelper::OStorageHelper::CopyInputToOutput( xInRaw, xTempOut );
364cdf0e10cSrcweir 		xTempOut->closeOutput();
365cdf0e10cSrcweir 		xTempSeek->seek( 0 );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 		// close raw stream, package stream and folder
368cdf0e10cSrcweir 		xInRaw = uno::Reference< io::XInputStream >();
369cdf0e10cSrcweir 		xNewPSProps = uno::Reference< XPropertySet >();
370cdf0e10cSrcweir 		xNPSTunnel = uno::Reference< XUnoTunnel >();
371cdf0e10cSrcweir 		xNewPackStream = uno::Reference< XDataSinkEncrSupport >();
372cdf0e10cSrcweir 		xTunnel = uno::Reference< XUnoTunnel >();
373cdf0e10cSrcweir 		xRootNameContainer = uno::Reference< container::XNameContainer >();
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 		// return the stream representing the first temporary file
376cdf0e10cSrcweir 		return xTempIn;
377cdf0e10cSrcweir 	}
378cdf0e10cSrcweir 	catch ( RuntimeException& )
379cdf0e10cSrcweir 	{
380cdf0e10cSrcweir 		throw;
381cdf0e10cSrcweir 	}
382cdf0e10cSrcweir 	catch ( Exception& )
383cdf0e10cSrcweir 	{
384cdf0e10cSrcweir 	}
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir //--------------------------------------------------------------------------
ParsePackageRawStream()390cdf0e10cSrcweir sal_Bool ZipPackageStream::ParsePackageRawStream()
391cdf0e10cSrcweir {
392cdf0e10cSrcweir 	OSL_ENSURE( GetOwnSeekStream().is(), "A stream must be provided!\n" );
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 	if ( !GetOwnSeekStream().is() )
395cdf0e10cSrcweir 		return sal_False;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	::rtl::Reference< BaseEncryptionData > xTempEncrData;
400cdf0e10cSrcweir 	sal_Int32 nMagHackSize = 0;
401cdf0e10cSrcweir 	Sequence < sal_Int8 > aHeader ( 4 );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 	try
404cdf0e10cSrcweir 	{
405cdf0e10cSrcweir 		if ( GetOwnSeekStream()->readBytes ( aHeader, 4 ) == 4 )
406cdf0e10cSrcweir 		{
407cdf0e10cSrcweir 			const sal_Int8 *pHeader = aHeader.getConstArray();
408cdf0e10cSrcweir 			sal_uInt32 nHeader = ( pHeader [0] & 0xFF )       |
409cdf0e10cSrcweir 							 	( pHeader [1] & 0xFF ) << 8  |
410cdf0e10cSrcweir 							 	( pHeader [2] & 0xFF ) << 16 |
411cdf0e10cSrcweir 							 	( pHeader [3] & 0xFF ) << 24;
412cdf0e10cSrcweir 			if ( nHeader == n_ConstHeader )
413cdf0e10cSrcweir 			{
414cdf0e10cSrcweir 				// this is one of our god-awful, but extremely devious hacks, everyone cheer
415cdf0e10cSrcweir 				xTempEncrData = new BaseEncryptionData;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 				::rtl::OUString aMediaType;
418cdf0e10cSrcweir                 sal_Int32 nEncAlgorithm = 0;
419cdf0e10cSrcweir                 sal_Int32 nChecksumAlgorithm = 0;
420cdf0e10cSrcweir                 sal_Int32 nDerivedKeySize = 0;
421cdf0e10cSrcweir                 sal_Int32 nStartKeyGenID = 0;
422cdf0e10cSrcweir 				if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nStartKeyGenID, nMagHackSize, aMediaType, GetOwnSeekStream() ) )
423cdf0e10cSrcweir 				{
424cdf0e10cSrcweir 					// We'll want to skip the data we've just read, so calculate how much we just read
425cdf0e10cSrcweir 					// and remember it
426cdf0e10cSrcweir 					m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->m_aSalt.getLength()
427cdf0e10cSrcweir 														+ xTempEncrData->m_aInitVector.getLength()
428cdf0e10cSrcweir 														+ xTempEncrData->m_aDigest.getLength()
429cdf0e10cSrcweir 														+ aMediaType.getLength() * sizeof( sal_Unicode );
430cdf0e10cSrcweir                     m_nImportedEncryptionAlgorithm = nEncAlgorithm;
431cdf0e10cSrcweir                     m_nImportedChecksumAlgorithm = nChecksumAlgorithm;
432cdf0e10cSrcweir                     m_nImportedDerivedKeySize = nDerivedKeySize;
433cdf0e10cSrcweir                     m_nImportedStartKeyAlgorithm = nStartKeyGenID;
434cdf0e10cSrcweir 					m_nMagicalHackSize = nMagHackSize;
435cdf0e10cSrcweir 					sMediaType = aMediaType;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 					bOk = sal_True;
438cdf0e10cSrcweir 				}
439cdf0e10cSrcweir 			}
440cdf0e10cSrcweir 		}
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 	catch( Exception& )
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir 	}
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	if ( !bOk )
447cdf0e10cSrcweir 	{
448cdf0e10cSrcweir 		// the provided stream is not a raw stream
449cdf0e10cSrcweir 		return sal_False;
450cdf0e10cSrcweir 	}
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 	m_xBaseEncryptionData = xTempEncrData;
453cdf0e10cSrcweir 	SetIsEncrypted ( sal_True );
454cdf0e10cSrcweir 	// it's already compressed and encrypted
455cdf0e10cSrcweir 	bToBeEncrypted = bToBeCompressed = sal_False;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 	return sal_True;
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
SetPackageMember(sal_Bool bNewValue)460cdf0e10cSrcweir void ZipPackageStream::SetPackageMember( sal_Bool bNewValue )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir 	if ( bNewValue )
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir 		m_nStreamMode = PACKAGE_STREAM_PACKAGEMEMBER;
465cdf0e10cSrcweir 		m_nMagicalHackPos = 0;
466cdf0e10cSrcweir 		m_nMagicalHackSize = 0;
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir 	else if ( m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER )
469cdf0e10cSrcweir 		m_nStreamMode = PACKAGE_STREAM_NOTSET; // must be reset
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir // XActiveDataSink
473cdf0e10cSrcweir //--------------------------------------------------------------------------
setInputStream(const uno::Reference<io::XInputStream> & aStream)474cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInputStream >& aStream )
475cdf0e10cSrcweir 		throw( RuntimeException )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir 	// if seekable access is required the wrapping will be done on demand
478cdf0e10cSrcweir 	xStream = aStream;
479cdf0e10cSrcweir     m_nImportedEncryptionAlgorithm = 0;
480cdf0e10cSrcweir 	m_bHasSeekable = sal_False;
481cdf0e10cSrcweir 	SetPackageMember ( sal_False );
482cdf0e10cSrcweir 	aEntry.nTime = -1;
483cdf0e10cSrcweir 	m_nStreamMode = PACKAGE_STREAM_DETECT;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir //--------------------------------------------------------------------------
getRawData()487cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData()
488cdf0e10cSrcweir 		throw( RuntimeException )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir 	try
491cdf0e10cSrcweir 	{
492cdf0e10cSrcweir 		if ( IsPackageMember() )
493cdf0e10cSrcweir 		{
494cdf0e10cSrcweir 			return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
495cdf0e10cSrcweir 		}
496cdf0e10cSrcweir 		else if ( GetOwnSeekStream().is() )
497cdf0e10cSrcweir 		{
498cdf0e10cSrcweir 			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
499cdf0e10cSrcweir 		}
500cdf0e10cSrcweir 		else
501cdf0e10cSrcweir 			return uno::Reference < io::XInputStream > ();
502cdf0e10cSrcweir 	}
503cdf0e10cSrcweir 	catch ( ZipException & )//rException )
504cdf0e10cSrcweir 	{
505cdf0e10cSrcweir 		VOS_ENSURE( 0, "ZipException thrown" );//rException.Message );
506cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
507cdf0e10cSrcweir 	}
508cdf0e10cSrcweir 	catch ( Exception & )
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" );
511cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
512cdf0e10cSrcweir 	}
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir //--------------------------------------------------------------------------
getInputStream()516cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream()
517cdf0e10cSrcweir 		throw( RuntimeException )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir 	try
520cdf0e10cSrcweir 	{
521cdf0e10cSrcweir 		if ( IsPackageMember() )
522cdf0e10cSrcweir 		{
523cdf0e10cSrcweir 			return rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
524cdf0e10cSrcweir 		}
525cdf0e10cSrcweir 		else if ( GetOwnSeekStream().is() )
526cdf0e10cSrcweir 		{
527cdf0e10cSrcweir 			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
528cdf0e10cSrcweir 		}
529cdf0e10cSrcweir 		else
530cdf0e10cSrcweir 			return uno::Reference < io::XInputStream > ();
531cdf0e10cSrcweir 	}
532cdf0e10cSrcweir 	catch ( ZipException & )//rException )
533cdf0e10cSrcweir 	{
534cdf0e10cSrcweir 		VOS_ENSURE( 0,"ZipException thrown" );//rException.Message );
535cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
536cdf0e10cSrcweir 	}
537cdf0e10cSrcweir 	catch ( Exception & )
538cdf0e10cSrcweir 	{
539cdf0e10cSrcweir 		VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" );
540cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
541cdf0e10cSrcweir 	}
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir // XDataSinkEncrSupport
545cdf0e10cSrcweir //--------------------------------------------------------------------------
getDataStream()546cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
547cdf0e10cSrcweir 		throw ( packages::WrongPasswordException,
548cdf0e10cSrcweir 				io::IOException,
549cdf0e10cSrcweir 				RuntimeException )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir 	// There is no stream attached to this object
552cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
553cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 	// this method can not be used together with old approach
556cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
557cdf0e10cSrcweir 		throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 	if ( IsPackageMember() )
560cdf0e10cSrcweir 	{
561cdf0e10cSrcweir         uno::Reference< io::XInputStream > xResult;
562cdf0e10cSrcweir         try
563cdf0e10cSrcweir         {
564cdf0e10cSrcweir 		    xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
565cdf0e10cSrcweir         }
566cdf0e10cSrcweir         catch( packages::WrongPasswordException& )
567cdf0e10cSrcweir         {
568cdf0e10cSrcweir             // workaround for the encrypted documents generated with the old OOo1.x bug.
569cdf0e10cSrcweir             if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding )
570cdf0e10cSrcweir             {
571cdf0e10cSrcweir                 xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
572cdf0e10cSrcweir                 m_bUseWinEncoding = true;
573cdf0e10cSrcweir             }
574cdf0e10cSrcweir             else
575cdf0e10cSrcweir                 throw;
576cdf0e10cSrcweir         }
577cdf0e10cSrcweir         return xResult;
578cdf0e10cSrcweir 	}
579cdf0e10cSrcweir 	else if ( m_nStreamMode == PACKAGE_STREAM_RAW )
580cdf0e10cSrcweir 		return ZipFile::StaticGetDataFromRawStream( m_xFactory, GetOwnSeekStream(), GetEncryptionData() );
581cdf0e10cSrcweir 	else if ( GetOwnSeekStream().is() )
582cdf0e10cSrcweir 	{
583cdf0e10cSrcweir 		return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
584cdf0e10cSrcweir 	}
585cdf0e10cSrcweir 	else
586cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir //--------------------------------------------------------------------------
getRawStream()590cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream()
591cdf0e10cSrcweir 		throw ( packages::NoEncryptionException,
592cdf0e10cSrcweir 				io::IOException,
593cdf0e10cSrcweir 				uno::RuntimeException )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir 	// There is no stream attached to this object
596cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
597cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 	// this method can not be used together with old approach
600cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
601cdf0e10cSrcweir 		throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 	if ( IsPackageMember() )
604cdf0e10cSrcweir 	{
605cdf0e10cSrcweir 		if ( !bIsEncrypted || !GetEncryptionData().is() )
606cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 		return rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), sMediaType, rZipPackage.GetSharedMutexRef() );
609cdf0e10cSrcweir 	}
610cdf0e10cSrcweir 	else if ( GetOwnSeekStream().is() )
611cdf0e10cSrcweir 	{
612cdf0e10cSrcweir 		if ( m_nStreamMode == PACKAGE_STREAM_RAW )
613cdf0e10cSrcweir 		{
614cdf0e10cSrcweir 			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
615cdf0e10cSrcweir 		}
616cdf0e10cSrcweir 		else if ( m_nStreamMode == PACKAGE_STREAM_DATA && bToBeEncrypted )
617cdf0e10cSrcweir 			return TryToGetRawFromDataStream( sal_True );
618cdf0e10cSrcweir 	}
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 	throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
621cdf0e10cSrcweir }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 
624cdf0e10cSrcweir //--------------------------------------------------------------------------
setDataStream(const uno::Reference<io::XInputStream> & aStream)625cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setDataStream( const uno::Reference< io::XInputStream >& aStream )
626cdf0e10cSrcweir 		throw ( io::IOException,
627cdf0e10cSrcweir 				RuntimeException )
628cdf0e10cSrcweir {
629cdf0e10cSrcweir 	setInputStream( aStream );
630cdf0e10cSrcweir 	m_nStreamMode = PACKAGE_STREAM_DATA;
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir //--------------------------------------------------------------------------
setRawStream(const uno::Reference<io::XInputStream> & aStream)634cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputStream >& aStream )
635cdf0e10cSrcweir 		throw ( packages::EncryptionNotAllowedException,
636cdf0e10cSrcweir 				packages::NoRawFormatException,
637cdf0e10cSrcweir 				io::IOException,
638cdf0e10cSrcweir 				RuntimeException )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir 	// wrap the stream in case it is not seekable
641cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory );
642cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY );
643cdf0e10cSrcweir 	if ( !xSeek.is() )
644cdf0e10cSrcweir 		throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ),
645cdf0e10cSrcweir 									uno::Reference< XInterface >() );
646cdf0e10cSrcweir 
647cdf0e10cSrcweir 	xSeek->seek( 0 );
648cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xOldStream = xStream;
649cdf0e10cSrcweir 	xStream = xNewStream;
650cdf0e10cSrcweir 	if ( !ParsePackageRawStream() )
651cdf0e10cSrcweir 	{
652cdf0e10cSrcweir 		xStream = xOldStream;
653cdf0e10cSrcweir 		throw packages::NoRawFormatException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
654cdf0e10cSrcweir 	}
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	// the raw stream MUST have seekable access
657cdf0e10cSrcweir 	m_bHasSeekable = sal_True;
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 	SetPackageMember ( sal_False );
660cdf0e10cSrcweir 	aEntry.nTime = -1;
661cdf0e10cSrcweir 	m_nStreamMode = PACKAGE_STREAM_RAW;
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
664cdf0e10cSrcweir //--------------------------------------------------------------------------
getPlainRawStream()665cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream()
666cdf0e10cSrcweir 		throw ( io::IOException,
667cdf0e10cSrcweir 				uno::RuntimeException )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir 	// There is no stream attached to this object
670cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
671cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	// this method can not be used together with old approach
674cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
675cdf0e10cSrcweir 		throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 	if ( IsPackageMember() )
678cdf0e10cSrcweir 	{
679cdf0e10cSrcweir 		return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
680cdf0e10cSrcweir 	}
681cdf0e10cSrcweir 	else if ( GetOwnSeekStream().is() )
682cdf0e10cSrcweir 	{
683cdf0e10cSrcweir 		if ( m_nStreamMode == PACKAGE_STREAM_RAW )
684cdf0e10cSrcweir 		{
685cdf0e10cSrcweir 			// the header should not be returned here
686cdf0e10cSrcweir 			return GetRawEncrStreamNoHeaderCopy();
687cdf0e10cSrcweir 		}
688cdf0e10cSrcweir 		else if ( m_nStreamMode == PACKAGE_STREAM_DATA )
689cdf0e10cSrcweir 			return TryToGetRawFromDataStream( sal_False );
690cdf0e10cSrcweir 	}
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 	return uno::Reference< io::XInputStream >();
693cdf0e10cSrcweir }
694cdf0e10cSrcweir 
695cdf0e10cSrcweir // XUnoTunnel
696cdf0e10cSrcweir 
697cdf0e10cSrcweir //--------------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & aIdentifier)698cdf0e10cSrcweir sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier )
699cdf0e10cSrcweir 	throw( RuntimeException )
700cdf0e10cSrcweir {
701cdf0e10cSrcweir 	sal_Int64 nMe = 0;
702cdf0e10cSrcweir 	if ( aIdentifier.getLength() == 16 &&
703cdf0e10cSrcweir 		 0 == rtl_compareMemory( static_getImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
704cdf0e10cSrcweir 		nMe = reinterpret_cast < sal_Int64 > ( this );
705cdf0e10cSrcweir 	return nMe;
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir // XPropertySet
709cdf0e10cSrcweir //--------------------------------------------------------------------------
setPropertyValue(const OUString & aPropertyName,const Any & aValue)710cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
711cdf0e10cSrcweir 		throw( beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir 	if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" )) )
714cdf0e10cSrcweir 	{
715cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && rZipPackage.getFormat() != embed::StorageFormats::OFOPXML )
716cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 		if ( aValue >>= sMediaType )
719cdf0e10cSrcweir 		{
720cdf0e10cSrcweir 			if ( sMediaType.getLength() > 0 )
721cdf0e10cSrcweir 			{
722cdf0e10cSrcweir 				if ( sMediaType.indexOf ( OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1
723cdf0e10cSrcweir 			 	|| sMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM ( "application/vnd.sun.star.oleobject" ) ) ) )
724cdf0e10cSrcweir 					bToBeCompressed = sal_True;
725cdf0e10cSrcweir 				else if ( !m_bCompressedIsSetFromOutside )
726cdf0e10cSrcweir 					bToBeCompressed = sal_False;
727cdf0e10cSrcweir 			}
728cdf0e10cSrcweir 		}
729cdf0e10cSrcweir 		else
730cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MediaType must be a string!\n" ) ),
731cdf0e10cSrcweir 											uno::Reference< XInterface >(),
732cdf0e10cSrcweir 											2 );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	}
735cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
736cdf0e10cSrcweir 	{
737cdf0e10cSrcweir 		if ( !( aValue >>= aEntry.nSize ) )
738cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Size property!\n" ) ),
739cdf0e10cSrcweir 											uno::Reference< XInterface >(),
740cdf0e10cSrcweir 											2 );
741cdf0e10cSrcweir 	}
742cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) )
743cdf0e10cSrcweir 	{
744cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
745cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 		sal_Bool bEnc = sal_False;
748cdf0e10cSrcweir 		if ( aValue >>= bEnc )
749cdf0e10cSrcweir 		{
750cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
751cdf0e10cSrcweir 			if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW )
752cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ),
753cdf0e10cSrcweir 												uno::Reference< XInterface >(),
754cdf0e10cSrcweir 												2 );
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 			bToBeEncrypted = bEnc;
757cdf0e10cSrcweir 			if ( bToBeEncrypted && !m_xBaseEncryptionData.is() )
758cdf0e10cSrcweir 				m_xBaseEncryptionData = new BaseEncryptionData;
759cdf0e10cSrcweir 		}
760cdf0e10cSrcweir 		else
761cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Encrypted property!\n" ) ),
762cdf0e10cSrcweir 											uno::Reference< XInterface >(),
763cdf0e10cSrcweir 											2 );
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 	}
766cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) )
767cdf0e10cSrcweir 	{
768cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
769cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 		uno::Sequence< sal_Int8 > aNewKey;
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 		if ( !( aValue >>= aNewKey ) )
774cdf0e10cSrcweir 		{
775cdf0e10cSrcweir 			OUString sTempString;
776cdf0e10cSrcweir 			if ( ( aValue >>= sTempString ) )
777cdf0e10cSrcweir 			{
778cdf0e10cSrcweir 				sal_Int32 nPathLength = sTempString.getLength();
779cdf0e10cSrcweir 				Sequence < sal_Int8 > aSequence ( nPathLength );
780cdf0e10cSrcweir 				sal_Int8 *pArray = aSequence.getArray();
781cdf0e10cSrcweir 				const sal_Unicode *pChar = sTempString.getStr();
782cdf0e10cSrcweir 				for ( sal_Int16 i = 0; i < nPathLength; i++ )
783cdf0e10cSrcweir 					pArray[i] = static_cast < const sal_Int8 > ( pChar[i] );
784cdf0e10cSrcweir 				aNewKey = aSequence;
785cdf0e10cSrcweir 			}
786cdf0e10cSrcweir 			else
787cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for EncryptionKey property!\n" ) ),
788cdf0e10cSrcweir 												uno::Reference< XInterface >(),
789cdf0e10cSrcweir 												2 );
790cdf0e10cSrcweir 		}
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 		if ( aNewKey.getLength() )
793cdf0e10cSrcweir 		{
794cdf0e10cSrcweir 			if ( !m_xBaseEncryptionData.is() )
795cdf0e10cSrcweir 				m_xBaseEncryptionData = new BaseEncryptionData;
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 			m_aEncryptionKey = aNewKey;
798cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
799cdf0e10cSrcweir 			bHaveOwnKey = sal_True;
800cdf0e10cSrcweir 			if ( m_nStreamMode != PACKAGE_STREAM_RAW )
801cdf0e10cSrcweir 				bToBeEncrypted = sal_True;
802cdf0e10cSrcweir 		}
803cdf0e10cSrcweir 		else
804cdf0e10cSrcweir         {
805cdf0e10cSrcweir 			bHaveOwnKey = sal_False;
806cdf0e10cSrcweir             m_aEncryptionKey.realloc( 0 );
807cdf0e10cSrcweir         }
808cdf0e10cSrcweir 
809cdf0e10cSrcweir         m_aStorageEncryptionKeys.realloc( 0 );
810cdf0e10cSrcweir 	}
811cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) )
812cdf0e10cSrcweir 	{
813cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
814cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 		uno::Sequence< beans::NamedValue > aKeys;
817cdf0e10cSrcweir 		if ( !( aValue >>= aKeys ) )
818cdf0e10cSrcweir 		{
819cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for StorageEncryptionKeys property!\n" ) ),
820cdf0e10cSrcweir 												uno::Reference< XInterface >(),
821cdf0e10cSrcweir 												2 );
822cdf0e10cSrcweir 		}
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 		if ( aKeys.getLength() )
825cdf0e10cSrcweir 		{
826cdf0e10cSrcweir 			if ( !m_xBaseEncryptionData.is() )
827cdf0e10cSrcweir 				m_xBaseEncryptionData = new BaseEncryptionData;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 			m_aStorageEncryptionKeys = aKeys;
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
832cdf0e10cSrcweir 			bHaveOwnKey = sal_True;
833cdf0e10cSrcweir 			if ( m_nStreamMode != PACKAGE_STREAM_RAW )
834cdf0e10cSrcweir 				bToBeEncrypted = sal_True;
835cdf0e10cSrcweir 		}
836cdf0e10cSrcweir 		else
837cdf0e10cSrcweir         {
838cdf0e10cSrcweir 			bHaveOwnKey = sal_False;
839cdf0e10cSrcweir             m_aStorageEncryptionKeys.realloc( 0 );
840cdf0e10cSrcweir         }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir         m_aEncryptionKey.realloc( 0 );
843cdf0e10cSrcweir 	}
844cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
845cdf0e10cSrcweir 	{
846cdf0e10cSrcweir 		sal_Bool bCompr = sal_False;
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 		if ( aValue >>= bCompr )
849cdf0e10cSrcweir 		{
850cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
851cdf0e10cSrcweir 			if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW )
852cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ),
853cdf0e10cSrcweir 												uno::Reference< XInterface >(),
854cdf0e10cSrcweir 												2 );
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 			bToBeCompressed = bCompr;
857cdf0e10cSrcweir 			m_bCompressedIsSetFromOutside = sal_True;
858cdf0e10cSrcweir 		}
859cdf0e10cSrcweir 		else
860cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Compressed property!\n" ) ),
861cdf0e10cSrcweir 											uno::Reference< XInterface >(),
862cdf0e10cSrcweir 											2 );
863cdf0e10cSrcweir 	}
864cdf0e10cSrcweir 	else
865cdf0e10cSrcweir 		throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
866cdf0e10cSrcweir }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir //--------------------------------------------------------------------------
getPropertyValue(const OUString & PropertyName)869cdf0e10cSrcweir Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName )
870cdf0e10cSrcweir 		throw( beans::UnknownPropertyException, WrappedTargetException, RuntimeException )
871cdf0e10cSrcweir {
872cdf0e10cSrcweir 	Any aAny;
873cdf0e10cSrcweir 	if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
874cdf0e10cSrcweir 	{
875cdf0e10cSrcweir 		aAny <<= sMediaType;
876cdf0e10cSrcweir 		return aAny;
877cdf0e10cSrcweir 	}
878cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) )
879cdf0e10cSrcweir 	{
880cdf0e10cSrcweir 		aAny <<= aEntry.nSize;
881cdf0e10cSrcweir 		return aAny;
882cdf0e10cSrcweir 	}
883cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) )
884cdf0e10cSrcweir 	{
885cdf0e10cSrcweir 		aAny <<= ( m_nStreamMode == PACKAGE_STREAM_RAW ) ? sal_True : bToBeEncrypted;
886cdf0e10cSrcweir 		return aAny;
887cdf0e10cSrcweir 	}
888cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) )
889cdf0e10cSrcweir 	{
890cdf0e10cSrcweir 		aAny <<= bIsEncrypted;
891cdf0e10cSrcweir 		return aAny;
892cdf0e10cSrcweir 	}
893cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
894cdf0e10cSrcweir 	{
895cdf0e10cSrcweir 		aAny <<= bToBeCompressed;
896cdf0e10cSrcweir 		return aAny;
897cdf0e10cSrcweir 	}
898cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) )
899cdf0e10cSrcweir 	{
900cdf0e10cSrcweir 		aAny <<= m_aEncryptionKey;
901cdf0e10cSrcweir 		return aAny;
902cdf0e10cSrcweir 	}
903cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) )
904cdf0e10cSrcweir 	{
905cdf0e10cSrcweir 		aAny <<= m_aStorageEncryptionKeys;
906cdf0e10cSrcweir 		return aAny;
907cdf0e10cSrcweir 	}
908cdf0e10cSrcweir 	else
909cdf0e10cSrcweir 		throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
910cdf0e10cSrcweir }
911cdf0e10cSrcweir 
912cdf0e10cSrcweir //--------------------------------------------------------------------------
setSize(const sal_Int32 nNewSize)913cdf0e10cSrcweir void ZipPackageStream::setSize ( const sal_Int32 nNewSize )
914cdf0e10cSrcweir {
915cdf0e10cSrcweir 	if ( aEntry.nCompressedSize != nNewSize )
916cdf0e10cSrcweir 		aEntry.nMethod = DEFLATED;
917cdf0e10cSrcweir 	aEntry.nSize = nNewSize;
918cdf0e10cSrcweir }
919cdf0e10cSrcweir //--------------------------------------------------------------------------
getImplementationName()920cdf0e10cSrcweir OUString ZipPackageStream::getImplementationName()
921cdf0e10cSrcweir 	throw ( RuntimeException )
922cdf0e10cSrcweir {
923cdf0e10cSrcweir 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageStream" ) );
924cdf0e10cSrcweir }
925cdf0e10cSrcweir 
926cdf0e10cSrcweir //--------------------------------------------------------------------------
getSupportedServiceNames()927cdf0e10cSrcweir Sequence< OUString > ZipPackageStream::getSupportedServiceNames()
928cdf0e10cSrcweir 	throw ( RuntimeException )
929cdf0e10cSrcweir {
930cdf0e10cSrcweir 	Sequence< OUString > aNames( 1 );
931cdf0e10cSrcweir 	aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageStream" ) );
932cdf0e10cSrcweir 	return aNames;
933cdf0e10cSrcweir }
934cdf0e10cSrcweir //--------------------------------------------------------------------------
supportsService(OUString const & rServiceName)935cdf0e10cSrcweir sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName )
936cdf0e10cSrcweir 	throw ( RuntimeException )
937cdf0e10cSrcweir {
938cdf0e10cSrcweir 	return rServiceName == getSupportedServiceNames()[0];
939cdf0e10cSrcweir }
940cdf0e10cSrcweir 
941