merge the formfield patch from ooo-build
[ooovba.git] / package / inc / ZipFile.hxx
blob4857dcf797af12c7e813d864bfb4ef35c934c4df
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: ZipFile.hxx,v $
10 * $Revision: 1.24 $
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_FILE_HXX
31 #define _ZIP_FILE_HXX
33 #include <com/sun/star/packages/zip/ZipException.hpp>
34 #include <com/sun/star/packages/zip/ZipIOException.hpp>
35 #include <com/sun/star/packages/NoEncryptionException.hpp>
36 #include <com/sun/star/packages/WrongPasswordException.hpp>
37 #include <ByteGrabber.hxx>
38 #include <HashMaps.hxx>
39 #ifndef _INFLATER_HXX
40 #include <Inflater.hxx>
41 #endif
43 #include <mutexholder.hxx>
45 namespace com { namespace sun { namespace star {
46 namespace lang { class XMultiServiceFactory; }
47 namespace ucb { class XProgressHandler; }
48 } } }
49 namespace vos
51 template < class T > class ORef;
53 /*
54 * We impose arbitrary but reasonable limit on ZIP files.
55 */
57 #define ZIP_MAXNAMELEN 512
58 #define ZIP_MAXEXTRA 256
59 #define ZIP_MAXENTRIES (0x10000 - 2)
61 typedef void* rtlCipher;
62 class ZipEnumeration;
63 class EncryptionData;
65 class ZipFile
67 protected:
68 ::rtl::OUString sComment; /* zip file comment */
69 EntryHash aEntries;
70 ByteGrabber aGrabber;
71 Inflater aInflater;
72 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
73 com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
74 const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xFactory;
75 ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
77 sal_Bool bRecoveryMode;
79 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream(
80 ZipEntry & rEntry,
81 const vos::ORef < EncryptionData > &rData,
82 sal_Bool bRawStream,
83 sal_Bool bDecrypt );
85 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream(
86 ZipEntry & rEntry,
87 const vos::ORef < EncryptionData > &rData,
88 sal_Bool bRawStream,
89 sal_Bool bDecrypt );
91 // aMediaType parameter is used only for raw stream header creation
92 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream(
93 SotMutexHolderRef aMutexHolder,
94 ZipEntry & rEntry,
95 const vos::ORef < EncryptionData > &rData,
96 sal_Int8 nStreamMode,
97 sal_Bool bDecrypt,
98 ::rtl::OUString aMediaType = ::rtl::OUString() );
100 sal_Bool hasValidPassword ( ZipEntry & rEntry, const vos::ORef < EncryptionData > &rData );
102 sal_Bool checkSizeAndCRC( const ZipEntry& aEntry );
104 sal_Int32 getCRC( sal_Int32 nOffset, sal_Int32 nSize );
106 void getSizeAndCRC( sal_Int32 nOffset, sal_Int32 nCompressedSize, sal_Int32 *nSize, sal_Int32 *nCRC );
108 public:
110 ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
111 const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory,
112 sal_Bool bInitialise
114 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
116 ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
117 const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory,
118 sal_Bool bInitialise,
119 sal_Bool bForceRecover,
120 ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgress
122 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
124 ~ZipFile();
126 EntryHash& GetEntryHash() { return aEntries; }
128 void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream );
129 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData(
130 ZipEntry& rEntry,
131 const vos::ORef < EncryptionData > &rData,
132 sal_Bool bDecrypt,
133 SotMutexHolderRef aMutexHolder )
134 throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
136 static sal_Bool StaticGetCipher ( const vos::ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode );
138 static void StaticFillHeader ( const vos::ORef < EncryptionData > & rData,
139 sal_Int32 nSize,
140 const ::rtl::OUString& aMediaType,
141 sal_Int8 * & pHeader );
143 static sal_Bool StaticFillData ( vos::ORef < EncryptionData > & rData,
144 sal_Int32 &rSize,
145 ::rtl::OUString& aMediaType,
146 ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &rStream );
148 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream(
149 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream,
150 const vos::ORef < EncryptionData > &rData )
151 throw ( ::com::sun::star::packages::WrongPasswordException,
152 ::com::sun::star::packages::zip::ZipIOException,
153 ::com::sun::star::uno::RuntimeException );
155 static sal_Bool StaticHasValidPassword ( const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer,
156 const vos::ORef < EncryptionData > &rData );
159 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(
160 ZipEntry& rEntry,
161 const vos::ORef < EncryptionData > &rData,
162 sal_Bool bDecrypt,
163 SotMutexHolderRef aMutexHolder )
164 throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
166 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream(
167 ZipEntry& rEntry,
168 const vos::ORef < EncryptionData > &rData,
169 sal_Bool bDecrypt,
170 SotMutexHolderRef aMutexHolder )
171 throw ( ::com::sun::star::packages::WrongPasswordException,
172 ::com::sun::star::io::IOException,
173 ::com::sun::star::packages::zip::ZipException,
174 ::com::sun::star::uno::RuntimeException );
176 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream(
177 ZipEntry& rEntry,
178 const vos::ORef < EncryptionData > &rData,
179 const ::rtl::OUString& aMediaType,
180 SotMutexHolderRef aMutexHolder )
181 throw ( ::com::sun::star::packages::NoEncryptionException,
182 ::com::sun::star::io::IOException,
183 ::com::sun::star::packages::zip::ZipException,
184 ::com::sun::star::uno::RuntimeException );
186 ZipEnumeration * SAL_CALL entries( );
187 protected:
188 sal_Bool readLOC ( ZipEntry &rEntry)
189 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
190 sal_Int32 readCEN()
191 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
192 sal_Int32 findEND()
193 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
194 sal_Int32 recover()
195 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
199 #endif