Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef _ZIP_FILE_HXX
20 : #define _ZIP_FILE_HXX
21 :
22 : #include <com/sun/star/packages/zip/ZipException.hpp>
23 : #include <com/sun/star/packages/zip/ZipIOException.hpp>
24 : #include <com/sun/star/packages/NoEncryptionException.hpp>
25 : #include <com/sun/star/packages/WrongPasswordException.hpp>
26 : #include <com/sun/star/xml/crypto/XCipherContext.hpp>
27 : #include <com/sun/star/xml/crypto/XDigestContext.hpp>
28 :
29 : #include <package/Inflater.hxx>
30 : #include <ByteGrabber.hxx>
31 : #include <HashMaps.hxx>
32 : #include <EncryptionData.hxx>
33 :
34 : #include <mutexholder.hxx>
35 :
36 : namespace com { namespace sun { namespace star {
37 : namespace uno { class XComponentContext; }
38 : namespace ucb { class XProgressHandler; }
39 : } } }
40 : namespace rtl
41 : {
42 : template < class T > class Reference;
43 : }
44 :
45 : /*
46 : * We impose arbitrary but reasonable limit on ZIP files.
47 : */
48 :
49 : #define ZIP_MAXNAMELEN 512
50 : #define ZIP_MAXEXTRA 256
51 : #define ZIP_MAXENTRIES (0x10000 - 2)
52 :
53 : class ZipEnumeration;
54 :
55 : class ZipFile
56 : {
57 : protected:
58 : ::osl::Mutex m_aMutex;
59 :
60 : OUString sComment; /* zip file comment */
61 : EntryHash aEntries;
62 : ByteGrabber aGrabber;
63 : ZipUtils::Inflater aInflater;
64 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
65 : com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
66 : const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
67 : ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
68 :
69 : sal_Bool bRecoveryMode;
70 :
71 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream(
72 : ZipEntry & rEntry,
73 : const ::rtl::Reference < EncryptionData > &rData,
74 : sal_Bool bRawStream,
75 : sal_Bool bDecrypt );
76 :
77 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream(
78 : ZipEntry & rEntry,
79 : const ::rtl::Reference < EncryptionData > &rData,
80 : sal_Bool bRawStream,
81 : sal_Bool bDecrypt );
82 :
83 : // aMediaType parameter is used only for raw stream header creation
84 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream(
85 : SotMutexHolderRef aMutexHolder,
86 : ZipEntry & rEntry,
87 : const ::rtl::Reference < EncryptionData > &rData,
88 : sal_Int8 nStreamMode,
89 : sal_Bool bDecrypt,
90 : const OUString& aMediaType = OUString() );
91 :
92 : sal_Bool hasValidPassword ( ZipEntry & rEntry, const rtl::Reference < EncryptionData > &rData );
93 :
94 : sal_Bool checkSizeAndCRC( const ZipEntry& aEntry );
95 :
96 : sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize );
97 :
98 : void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC );
99 :
100 : public:
101 :
102 : ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
103 : const com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > &rxContext,
104 : sal_Bool bInitialise
105 : )
106 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
107 :
108 : ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
109 : const com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > &rxContext,
110 : sal_Bool bInitialise,
111 : sal_Bool bForceRecover,
112 : ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgress
113 : )
114 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
115 :
116 : ~ZipFile();
117 :
118 0 : EntryHash& GetEntryHash() { return aEntries; }
119 :
120 : void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream );
121 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData(
122 : ZipEntry& rEntry,
123 : const ::rtl::Reference < EncryptionData > &rData,
124 : sal_Bool bDecrypt,
125 : SotMutexHolderRef aMutexHolder )
126 : throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
127 :
128 : static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
129 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xArgContext,
130 : const ::rtl::Reference< EncryptionData >& xEncryptionData );
131 :
132 : static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher(
133 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xArgContext,
134 : const ::rtl::Reference< EncryptionData >& xEncryptionData,
135 : bool bEncrypt );
136 :
137 : static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
138 : sal_Int64 nSize,
139 : const OUString& aMediaType,
140 : sal_Int8 * & pHeader );
141 :
142 : static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData,
143 : sal_Int32 &rEncAlgorithm,
144 : sal_Int32 &rChecksumAlgorithm,
145 : sal_Int32 &rDerivedKeySize,
146 : sal_Int32 &rStartKeyGenID,
147 : sal_Int32 &rSize,
148 : OUString& aMediaType,
149 : const ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream );
150 :
151 : static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream(
152 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
153 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream,
154 : const ::rtl::Reference < EncryptionData > &rData )
155 : throw ( ::com::sun::star::packages::WrongPasswordException,
156 : ::com::sun::star::packages::zip::ZipIOException,
157 : ::com::sun::star::uno::RuntimeException );
158 :
159 : static sal_Bool StaticHasValidPassword (
160 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
161 : const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer,
162 : const ::rtl::Reference < EncryptionData > &rData );
163 :
164 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(
165 : ZipEntry& rEntry,
166 : const ::rtl::Reference < EncryptionData > &rData,
167 : sal_Bool bDecrypt,
168 : SotMutexHolderRef aMutexHolder )
169 : throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
170 :
171 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream(
172 : ZipEntry& rEntry,
173 : const ::rtl::Reference < EncryptionData > &rData,
174 : sal_Bool bDecrypt,
175 : SotMutexHolderRef aMutexHolder )
176 : throw ( ::com::sun::star::packages::WrongPasswordException,
177 : ::com::sun::star::io::IOException,
178 : ::com::sun::star::packages::zip::ZipException,
179 : ::com::sun::star::uno::RuntimeException );
180 :
181 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream(
182 : ZipEntry& rEntry,
183 : const ::rtl::Reference < EncryptionData > &rData,
184 : const OUString& aMediaType,
185 : SotMutexHolderRef aMutexHolder )
186 : throw ( ::com::sun::star::packages::NoEncryptionException,
187 : ::com::sun::star::io::IOException,
188 : ::com::sun::star::packages::zip::ZipException,
189 : ::com::sun::star::uno::RuntimeException );
190 :
191 : ZipEnumeration * SAL_CALL entries( );
192 : protected:
193 : sal_Bool readLOC ( ZipEntry &rEntry)
194 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
195 : sal_Int32 readCEN()
196 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
197 : sal_Int32 findEND()
198 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
199 : sal_Int32 recover()
200 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
201 :
202 : };
203 :
204 : #endif
205 :
206 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|