fix toolbar import
[ooovba.git] / package / source / zippackage / ZipPackageStream.hxx
blob0ce61574df49d76052f189c5146bcd4732a9214e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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>
37 #ifndef _VOS_REF_H_
38 #include <vos/ref.hxx>
39 #endif
40 #include <EncryptionData.hxx>
41 #ifndef _CPPUHELPER_IMPLBASE2_HXX
42 #include <cppuhelper/implbase2.hxx>
43 #endif
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
52 class ZipPackage;
53 struct ZipEntry;
54 class ZipPackageStream : public cppu::ImplInheritanceHelper2
56 ZipPackageEntry,
57 ::com::sun::star::io::XActiveDataSink,
58 ::com::sun::star::packages::XDataSinkEncrSupport
61 static com::sun::star::uno::Sequence < sal_Int8 > aImplementationId;
62 protected:
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 SotMutexHolderRef m_aSharedMutexRef;
75 sal_Bool m_bHasSeekable;
77 sal_Bool m_bCompressedIsSetFromOutside;
79 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& GetOwnSeekStream();
81 public:
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;}
87 vos::ORef < EncryptionData > & getEncryptionData ()
88 { return xEncryptionData;}
89 const com::sun::star::uno::Sequence < sal_Int8 >& getKey () const
90 { return xEncryptionData->aKey;}
91 const com::sun::star::uno::Sequence < sal_uInt8 >& getInitialisationVector () const
92 { return xEncryptionData->aInitVector;}
93 const com::sun::star::uno::Sequence < sal_uInt8 >& getDigest () const
94 { return xEncryptionData->aDigest;}
95 const com::sun::star::uno::Sequence < sal_uInt8 >& getSalt () const
96 { return xEncryptionData->aSalt;}
97 sal_Int32 getIterationCount () const
98 { return xEncryptionData->nIterationCount;}
99 sal_Int32 getSize () const
100 { return aEntry.nSize;}
102 sal_uInt8 GetStreamMode() const { return m_nStreamMode; }
103 sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; }
104 sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; }
106 void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;}
107 void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;}
108 void SetToBeEncrypted (sal_Bool bNewValue)
110 bToBeEncrypted = bNewValue;
111 if ( bToBeEncrypted && xEncryptionData.isEmpty())
112 xEncryptionData = new EncryptionData;
113 else if ( !bToBeEncrypted && !xEncryptionData.isEmpty() )
114 xEncryptionData.unbind();
116 void SetPackageMember (sal_Bool bNewValue);
117 void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey )
118 { xEncryptionData->aKey = rNewKey;}
119 void setInitialisationVector (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewVector )
120 { xEncryptionData->aInitVector = rNewVector;}
121 void setSalt (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewSalt )
122 { xEncryptionData->aSalt = rNewSalt;}
123 void setDigest (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewDigest )
124 { xEncryptionData->aDigest = rNewDigest;}
125 void setIterationCount (const sal_Int32 nNewCount)
126 { xEncryptionData->nIterationCount = nNewCount;}
127 void setSize (const sal_Int32 nNewSize);
129 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; }
131 void CloseOwnStreamIfAny();
133 ZipPackageStream ( ZipPackage & rNewPackage,
134 const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& xFactory,
135 sal_Bool bAllowRemoveOnInsert );
136 virtual ~ZipPackageStream( void );
138 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
139 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream(
140 sal_Bool bAddHeaderForEncr );
142 sal_Bool ParsePackageRawStream();
144 void setZipEntryOnLoading( const ZipEntry &rInEntry);
145 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
146 throw(::com::sun::star::uno::RuntimeException);
148 static ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId()
150 return aImplementationId;
153 // XActiveDataSink
154 virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
155 throw(::com::sun::star::uno::RuntimeException);
156 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( )
157 throw(::com::sun::star::uno::RuntimeException);
159 // XDataSinkEncrSupport
160 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream()
161 throw ( ::com::sun::star::packages::WrongPasswordException,
162 ::com::sun::star::io::IOException,
163 ::com::sun::star::uno::RuntimeException );
164 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream()
165 throw ( ::com::sun::star::packages::NoEncryptionException,
166 ::com::sun::star::io::IOException,
167 ::com::sun::star::uno::RuntimeException );
168 virtual void SAL_CALL setDataStream(
169 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
170 throw ( ::com::sun::star::io::IOException,
171 ::com::sun::star::uno::RuntimeException );
172 virtual void SAL_CALL setRawStream(
173 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
174 throw ( ::com::sun::star::packages::EncryptionNotAllowedException,
175 ::com::sun::star::packages::NoRawFormatException,
176 ::com::sun::star::io::IOException,
177 ::com::sun::star::uno::RuntimeException );
178 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream()
179 throw ( ::com::sun::star::io::IOException,
180 ::com::sun::star::uno::RuntimeException );
182 // XUnoTunnel
183 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
184 throw(::com::sun::star::uno::RuntimeException);
186 // XPropertySet
187 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
188 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);
189 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName )
190 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
192 // XServiceInfo
193 virtual ::rtl::OUString SAL_CALL getImplementationName( )
194 throw (::com::sun::star::uno::RuntimeException);
195 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
196 throw (::com::sun::star::uno::RuntimeException);
197 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
198 throw (::com::sun::star::uno::RuntimeException);
200 #endif