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 INCLUDED_PACKAGE_INC_ZIPFILE_HXX
20 : #define INCLUDED_PACKAGE_INC_ZIPFILE_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_MAXENTRIES (0x10000 - 2)
51 :
52 : class ZipEnumeration;
53 :
54 : class ZipFile
55 : {
56 : protected:
57 : ::osl::Mutex m_aMutex;
58 :
59 : OUString sComment; /* zip file comment */
60 : EntryHash aEntries;
61 : ByteGrabber aGrabber;
62 : ZipUtils::Inflater aInflater;
63 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
64 : com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
65 : const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
66 : ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
67 :
68 : bool bRecoveryMode;
69 :
70 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream(
71 : ZipEntry & rEntry,
72 : const ::rtl::Reference < EncryptionData > &rData,
73 : bool bRawStream,
74 : bool bDecrypt );
75 :
76 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream(
77 : ZipEntry & rEntry,
78 : const ::rtl::Reference < EncryptionData > &rData,
79 : bool bRawStream,
80 : bool bDecrypt );
81 :
82 : // aMediaType parameter is used only for raw stream header creation
83 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream(
84 : SotMutexHolderRef aMutexHolder,
85 : ZipEntry & rEntry,
86 : const ::rtl::Reference < EncryptionData > &rData,
87 : sal_Int8 nStreamMode,
88 : bool bDecrypt,
89 : const OUString& aMediaType = OUString() );
90 :
91 : bool hasValidPassword ( ZipEntry & rEntry, const rtl::Reference < EncryptionData > &rData );
92 :
93 : bool checkSizeAndCRC( const ZipEntry& aEntry );
94 :
95 : sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize );
96 :
97 : void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC );
98 :
99 : public:
100 :
101 : ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
102 : const com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > &rxContext,
103 : bool bInitialise
104 : )
105 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
106 :
107 : ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
108 : const com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > &rxContext,
109 : bool bInitialise,
110 : bool bForceRecover,
111 : ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgress
112 : )
113 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
114 :
115 : ~ZipFile();
116 :
117 192081 : EntryHash& GetEntryHash() { return aEntries; }
118 :
119 : void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream );
120 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData(
121 : ZipEntry& rEntry,
122 : const ::rtl::Reference < EncryptionData > &rData,
123 : bool bDecrypt,
124 : SotMutexHolderRef aMutexHolder )
125 : throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
126 :
127 : static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
128 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xArgContext,
129 : const ::rtl::Reference< EncryptionData >& xEncryptionData );
130 :
131 : static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher(
132 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xArgContext,
133 : const ::rtl::Reference< EncryptionData >& xEncryptionData,
134 : bool bEncrypt );
135 :
136 : static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
137 : sal_Int64 nSize,
138 : const OUString& aMediaType,
139 : sal_Int8 * & pHeader );
140 :
141 : static bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData,
142 : sal_Int32 &rEncAlgorithm,
143 : sal_Int32 &rChecksumAlgorithm,
144 : sal_Int32 &rDerivedKeySize,
145 : sal_Int32 &rStartKeyGenID,
146 : sal_Int32 &rSize,
147 : OUString& aMediaType,
148 : const ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream );
149 :
150 : static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream(
151 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
152 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream,
153 : const ::rtl::Reference < EncryptionData > &rData )
154 : throw ( ::com::sun::star::packages::WrongPasswordException,
155 : ::com::sun::star::packages::zip::ZipIOException,
156 : ::com::sun::star::uno::RuntimeException );
157 :
158 : static bool StaticHasValidPassword (
159 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
160 : const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer,
161 : const ::rtl::Reference < EncryptionData > &rData );
162 :
163 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(
164 : ZipEntry& rEntry,
165 : const ::rtl::Reference < EncryptionData > &rData,
166 : bool bDecrypt,
167 : SotMutexHolderRef aMutexHolder )
168 : throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
169 :
170 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream(
171 : ZipEntry& rEntry,
172 : const ::rtl::Reference < EncryptionData > &rData,
173 : bool bDecrypt,
174 : SotMutexHolderRef aMutexHolder )
175 : throw ( ::com::sun::star::packages::WrongPasswordException,
176 : ::com::sun::star::io::IOException,
177 : ::com::sun::star::packages::zip::ZipException,
178 : ::com::sun::star::uno::RuntimeException );
179 :
180 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream(
181 : ZipEntry& rEntry,
182 : const ::rtl::Reference < EncryptionData > &rData,
183 : const OUString& aMediaType,
184 : SotMutexHolderRef aMutexHolder )
185 : throw ( ::com::sun::star::packages::NoEncryptionException,
186 : ::com::sun::star::io::IOException,
187 : ::com::sun::star::packages::zip::ZipException,
188 : ::com::sun::star::uno::RuntimeException );
189 :
190 : ZipEnumeration * SAL_CALL entries( );
191 : protected:
192 : bool readLOC ( ZipEntry &rEntry)
193 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
194 : sal_Int32 readCEN()
195 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
196 : sal_Int32 findEND()
197 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
198 : sal_Int32 recover()
199 : throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
200 :
201 : };
202 :
203 : #endif
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|