1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZipPackageStream.hxx,v $
10 * $Revision: 1.23.20.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _ZIP_PACKAGE_STREAM_HXX
31 #define _ZIP_PACKAGE_STREAM_HXX
33 #include <com/sun/star/io/XActiveDataSink.hpp>
34 #include <com/sun/star/io/XSeekable.hpp>
35 #include <com/sun/star/packages/XDataSinkEncrSupport.hpp>
36 #include <ZipPackageEntry.hxx>
38 #include <vos/ref.hxx>
40 #include <EncryptionData.hxx>
41 #ifndef _CPPUHELPER_IMPLBASE2_HXX
42 #include <cppuhelper/implbase2.hxx>
44 #include <mutexholder.hxx>
46 #define PACKAGE_STREAM_NOTSET 0
47 #define PACKAGE_STREAM_PACKAGEMEMBER 1
48 #define PACKAGE_STREAM_DETECT 2
49 #define PACKAGE_STREAM_DATA 3
50 #define PACKAGE_STREAM_RAW 4
54 class ZipPackageStream
: public cppu::ImplInheritanceHelper2
57 ::com::sun::star::io::XActiveDataSink
,
58 ::com::sun::star::packages::XDataSinkEncrSupport
61 static com::sun::star::uno::Sequence
< sal_Int8
> aImplementationId
;
63 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> xStream
;
64 const ::com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> m_xFactory
;
65 ZipPackage
&rZipPackage
;
66 sal_Bool bToBeCompressed
, bToBeEncrypted
, bHaveOwnKey
, bIsEncrypted
;
67 vos::ORef
< EncryptionData
> xEncryptionData
;
69 sal_uInt8 m_nStreamMode
;
70 sal_uInt32 m_nMagicalHackPos
;
71 sal_uInt32 m_nMagicalHackSize
;
73 sal_Bool m_bHasSeekable
;
75 sal_Bool m_bCompressedIsSetFromOutside
;
77 sal_Bool m_bFromManifest
;
79 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& GetOwnSeekStream();
82 sal_Bool
HasOwnKey () const { return bHaveOwnKey
;}
83 sal_Bool
IsToBeCompressed () const { return bToBeCompressed
;}
84 sal_Bool
IsToBeEncrypted () const { return bToBeEncrypted
;}
85 sal_Bool
IsEncrypted () const { return bIsEncrypted
;}
86 sal_Bool
IsPackageMember () const { return m_nStreamMode
== PACKAGE_STREAM_PACKAGEMEMBER
;}
88 sal_Bool
IsFromManifest() const { return m_bFromManifest
; }
89 void SetFromManifest( sal_Bool bValue
) { m_bFromManifest
= bValue
; }
91 vos::ORef
< EncryptionData
> & getEncryptionData ()
92 { return xEncryptionData
;}
93 const com::sun::star::uno::Sequence
< sal_Int8
>& getKey () const
94 { return xEncryptionData
->aKey
;}
95 const com::sun::star::uno::Sequence
< sal_uInt8
>& getInitialisationVector () const
96 { return xEncryptionData
->aInitVector
;}
97 const com::sun::star::uno::Sequence
< sal_uInt8
>& getDigest () const
98 { return xEncryptionData
->aDigest
;}
99 const com::sun::star::uno::Sequence
< sal_uInt8
>& getSalt () const
100 { return xEncryptionData
->aSalt
;}
101 sal_Int32
getIterationCount () const
102 { return xEncryptionData
->nIterationCount
;}
103 sal_Int32
getSize () const
104 { return aEntry
.nSize
;}
106 sal_uInt8
GetStreamMode() const { return m_nStreamMode
; }
107 sal_uInt32
GetMagicalHackPos() const { return m_nMagicalHackPos
; }
108 sal_uInt32
GetMagicalHackSize() const { return m_nMagicalHackSize
; }
110 void SetToBeCompressed (sal_Bool bNewValue
) { bToBeCompressed
= bNewValue
;}
111 void SetIsEncrypted (sal_Bool bNewValue
) { bIsEncrypted
= bNewValue
;}
112 void SetToBeEncrypted (sal_Bool bNewValue
)
114 bToBeEncrypted
= bNewValue
;
115 if ( bToBeEncrypted
&& xEncryptionData
.isEmpty())
116 xEncryptionData
= new EncryptionData
;
117 else if ( !bToBeEncrypted
&& !xEncryptionData
.isEmpty() )
118 xEncryptionData
.unbind();
120 void SetPackageMember (sal_Bool bNewValue
);
121 void setKey (const com::sun::star::uno::Sequence
< sal_Int8
>& rNewKey
)
122 { xEncryptionData
->aKey
= rNewKey
;}
123 void setInitialisationVector (const com::sun::star::uno::Sequence
< sal_uInt8
>& rNewVector
)
124 { xEncryptionData
->aInitVector
= rNewVector
;}
125 void setSalt (const com::sun::star::uno::Sequence
< sal_uInt8
>& rNewSalt
)
126 { xEncryptionData
->aSalt
= rNewSalt
;}
127 void setDigest (const com::sun::star::uno::Sequence
< sal_uInt8
>& rNewDigest
)
128 { xEncryptionData
->aDigest
= rNewDigest
;}
129 void setIterationCount (const sal_Int32 nNewCount
)
130 { xEncryptionData
->nIterationCount
= nNewCount
;}
131 void setSize (const sal_Int32 nNewSize
);
133 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> GetOwnStreamNoWrap() { return xStream
; }
135 void CloseOwnStreamIfAny();
137 ZipPackageStream ( ZipPackage
& rNewPackage
,
138 const ::com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>& xFactory
,
139 sal_Bool bAllowRemoveOnInsert
);
140 virtual ~ZipPackageStream( void );
142 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> GetRawEncrStreamNoHeaderCopy();
143 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> TryToGetRawFromDataStream(
144 sal_Bool bAddHeaderForEncr
);
146 sal_Bool
ParsePackageRawStream();
148 void setZipEntryOnLoading( const ZipEntry
&rInEntry
);
149 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getRawData()
150 throw(::com::sun::star::uno::RuntimeException
);
152 static ::com::sun::star::uno::Sequence
< sal_Int8
>& static_getImplementationId()
154 return aImplementationId
;
158 virtual void SAL_CALL
setInputStream( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& aStream
)
159 throw(::com::sun::star::uno::RuntimeException
);
160 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getInputStream( )
161 throw(::com::sun::star::uno::RuntimeException
);
163 // XDataSinkEncrSupport
164 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getDataStream()
165 throw ( ::com::sun::star::packages::WrongPasswordException
,
166 ::com::sun::star::io::IOException
,
167 ::com::sun::star::uno::RuntimeException
);
168 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getRawStream()
169 throw ( ::com::sun::star::packages::NoEncryptionException
,
170 ::com::sun::star::io::IOException
,
171 ::com::sun::star::uno::RuntimeException
);
172 virtual void SAL_CALL
setDataStream(
173 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& aStream
)
174 throw ( ::com::sun::star::io::IOException
,
175 ::com::sun::star::uno::RuntimeException
);
176 virtual void SAL_CALL
setRawStream(
177 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& aStream
)
178 throw ( ::com::sun::star::packages::EncryptionNotAllowedException
,
179 ::com::sun::star::packages::NoRawFormatException
,
180 ::com::sun::star::io::IOException
,
181 ::com::sun::star::uno::RuntimeException
);
182 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getPlainRawStream()
183 throw ( ::com::sun::star::io::IOException
,
184 ::com::sun::star::uno::RuntimeException
);
187 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
)
188 throw(::com::sun::star::uno::RuntimeException
);
191 virtual void SAL_CALL
setPropertyValue( const ::rtl::OUString
& aPropertyName
, const ::com::sun::star::uno::Any
& aValue
)
192 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
193 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const ::rtl::OUString
& PropertyName
)
194 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
197 virtual ::rtl::OUString SAL_CALL
getImplementationName( )
198 throw (::com::sun::star::uno::RuntimeException
);
199 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
)
200 throw (::com::sun::star::uno::RuntimeException
);
201 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( )
202 throw (::com::sun::star::uno::RuntimeException
);