Bump for 3.6-28
[LibreOffice.git] / package / inc / ZipFile.hxx
blobbb348f3c3262163892c0f8db7029be3711c53dec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef _ZIP_FILE_HXX
29 #define _ZIP_FILE_HXX
31 #include <com/sun/star/packages/zip/ZipException.hpp>
32 #include <com/sun/star/packages/zip/ZipIOException.hpp>
33 #include <com/sun/star/packages/NoEncryptionException.hpp>
34 #include <com/sun/star/packages/WrongPasswordException.hpp>
35 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
36 #include <com/sun/star/xml/crypto/XDigestContext.hpp>
38 #include <package/Inflater.hxx>
39 #include <ByteGrabber.hxx>
40 #include <HashMaps.hxx>
41 #include <EncryptionData.hxx>
43 #include <mutexholder.hxx>
45 namespace com { namespace sun { namespace star {
46 namespace lang { class XMultiServiceFactory; }
47 namespace ucb { class XProgressHandler; }
48 } } }
49 namespace rtl
51 template < class T > class Reference;
55 * We impose arbitrary but reasonable limit on ZIP files.
58 #define ZIP_MAXNAMELEN 512
59 #define ZIP_MAXEXTRA 256
60 #define ZIP_MAXENTRIES (0x10000 - 2)
62 class ZipEnumeration;
64 class ZipFile
66 protected:
67 ::osl::Mutex m_aMutex;
69 ::rtl::OUString sComment; /* zip file comment */
70 EntryHash aEntries;
71 ByteGrabber aGrabber;
72 ZipUtils::Inflater aInflater;
73 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
74 com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
75 const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
76 ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
78 sal_Bool bRecoveryMode;
80 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream(
81 ZipEntry & rEntry,
82 const ::rtl::Reference < EncryptionData > &rData,
83 sal_Bool bRawStream,
84 sal_Bool bDecrypt );
86 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream(
87 ZipEntry & rEntry,
88 const ::rtl::Reference < EncryptionData > &rData,
89 sal_Bool bRawStream,
90 sal_Bool bDecrypt );
92 // aMediaType parameter is used only for raw stream header creation
93 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream(
94 SotMutexHolderRef aMutexHolder,
95 ZipEntry & rEntry,
96 const ::rtl::Reference < EncryptionData > &rData,
97 sal_Int8 nStreamMode,
98 sal_Bool bDecrypt,
99 ::rtl::OUString aMediaType = ::rtl::OUString() );
101 sal_Bool hasValidPassword ( ZipEntry & rEntry, const rtl::Reference < EncryptionData > &rData );
103 sal_Bool checkSizeAndCRC( const ZipEntry& aEntry );
105 sal_Int32 getCRC( sal_Int32 nOffset, sal_Int32 nSize );
107 void getSizeAndCRC( sal_Int32 nOffset, sal_Int32 nCompressedSize, sal_Int32 *nSize, sal_Int32 *nCRC );
109 public:
111 ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
112 const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory,
113 sal_Bool bInitialise
115 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
117 ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
118 const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory,
119 sal_Bool bInitialise,
120 sal_Bool bForceRecover,
121 ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgress
123 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
125 ~ZipFile();
127 EntryHash& GetEntryHash() { return aEntries; }
129 void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream );
130 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData(
131 ZipEntry& rEntry,
132 const ::rtl::Reference < EncryptionData > &rData,
133 sal_Bool bDecrypt,
134 SotMutexHolderRef aMutexHolder )
135 throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
138 static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
139 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory,
140 const ::rtl::Reference< EncryptionData >& xEncryptionData );
142 static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher(
143 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory,
144 const ::rtl::Reference< EncryptionData >& xEncryptionData,
145 bool bEncrypt );
147 static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
148 sal_Int32 nSize,
149 const ::rtl::OUString& aMediaType,
150 sal_Int8 * & pHeader );
152 static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData,
153 sal_Int32 &rEncAlgorithm,
154 sal_Int32 &rChecksumAlgorithm,
155 sal_Int32 &rDerivedKeySize,
156 sal_Int32 &rStartKeyGenID,
157 sal_Int32 &rSize,
158 ::rtl::OUString& aMediaType,
159 const ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream );
161 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream(
162 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
163 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream,
164 const ::rtl::Reference < EncryptionData > &rData )
165 throw ( ::com::sun::star::packages::WrongPasswordException,
166 ::com::sun::star::packages::zip::ZipIOException,
167 ::com::sun::star::uno::RuntimeException );
169 static sal_Bool StaticHasValidPassword (
170 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
171 const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer,
172 const ::rtl::Reference < EncryptionData > &rData );
175 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(
176 ZipEntry& rEntry,
177 const ::rtl::Reference < EncryptionData > &rData,
178 sal_Bool bDecrypt,
179 SotMutexHolderRef aMutexHolder )
180 throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
182 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream(
183 ZipEntry& rEntry,
184 const ::rtl::Reference < EncryptionData > &rData,
185 sal_Bool bDecrypt,
186 SotMutexHolderRef aMutexHolder )
187 throw ( ::com::sun::star::packages::WrongPasswordException,
188 ::com::sun::star::io::IOException,
189 ::com::sun::star::packages::zip::ZipException,
190 ::com::sun::star::uno::RuntimeException );
192 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream(
193 ZipEntry& rEntry,
194 const ::rtl::Reference < EncryptionData > &rData,
195 const ::rtl::OUString& aMediaType,
196 SotMutexHolderRef aMutexHolder )
197 throw ( ::com::sun::star::packages::NoEncryptionException,
198 ::com::sun::star::io::IOException,
199 ::com::sun::star::packages::zip::ZipException,
200 ::com::sun::star::uno::RuntimeException );
202 ZipEnumeration * SAL_CALL entries( );
203 protected:
204 sal_Bool readLOC ( ZipEntry &rEntry)
205 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
206 sal_Int32 readCEN()
207 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
208 sal_Int32 findEND()
209 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
210 sal_Int32 recover()
211 throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
215 #endif
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */