Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / package / inc / ZipFile.hxx
blobf6b1849947293a6f34e7674ab0146c2d5e0f67b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_PACKAGE_INC_ZIPFILE_HXX
20 #define INCLUDED_PACKAGE_INC_ZIPFILE_HXX
22 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
23 #include <com/sun/star/xml/crypto/XDigestContext.hpp>
25 #include <comphelper/refcountedmutex.hxx>
26 #include <package/Inflater.hxx>
27 #include <rtl/ref.hxx>
28 #include "ByteGrabber.hxx"
29 #include "HashMaps.hxx"
30 #include "EncryptionData.hxx"
32 class MemoryByteGrabber;
33 namespace com::sun::star {
34 namespace uno { class XComponentContext; }
35 namespace ucb { class XProgressHandler; }
37 namespace rtl
39 template < class T > class Reference;
43 * We impose arbitrary but reasonable limit on ZIP files.
46 #define ZIP_MAXNAMELEN 512
47 #define ZIP_MAXENTRIES (0x10000 - 2)
49 class ZipEnumeration;
51 class ZipFile
53 rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder;
55 EntryHash aEntries;
56 ByteGrabber aGrabber;
57 ZipUtils::Inflater aInflater;
58 css::uno::Reference < css::io::XInputStream > xStream;
59 const css::uno::Reference < css::uno::XComponentContext > m_xContext;
61 bool bRecoveryMode;
63 // aMediaType parameter is used only for raw stream header creation
64 css::uno::Reference < css::io::XInputStream > createStreamForZipEntry(
65 const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder,
66 ZipEntry const & rEntry,
67 const ::rtl::Reference < EncryptionData > &rData,
68 sal_Int8 nStreamMode,
69 bool bDecrypt,
70 const bool bUseBufferedStream = true,
71 const OUString& aMediaType = OUString() );
73 bool hasValidPassword ( ZipEntry const & rEntry, const rtl::Reference < EncryptionData > &rData );
75 bool checkSizeAndCRC( const ZipEntry& aEntry );
77 sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize );
79 void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC );
81 void readLOC( ZipEntry &rEntry );
82 sal_Int32 readCEN();
83 sal_Int32 findEND();
84 void recover();
85 static void readExtraFields(MemoryByteGrabber& aMemGrabber, sal_Int16 nExtraLen,
86 sal_uInt64& nSize, sal_uInt64& nCompressedSize,
87 sal_uInt64* nOffset);
89 public:
91 ZipFile( rtl::Reference<comphelper::RefCountedMutex> aMutexHolder,
92 css::uno::Reference < css::io::XInputStream > const &xInput,
93 css::uno::Reference < css::uno::XComponentContext > xContext,
94 bool bInitialise );
96 ZipFile( rtl::Reference<comphelper::RefCountedMutex> aMutexHolder,
97 css::uno::Reference < css::io::XInputStream > const &xInput,
98 css::uno::Reference < css::uno::XComponentContext > xContext,
99 bool bInitialise,
100 bool bForceRecover );
102 ~ZipFile();
104 EntryHash& GetEntryHash() { return aEntries; }
106 void setInputStream ( const css::uno::Reference < css::io::XInputStream >& xNewStream );
107 css::uno::Reference< css::io::XInputStream > getRawData(
108 ZipEntry& rEntry,
109 const ::rtl::Reference < EncryptionData > &rData,
110 bool bDecrypt,
111 const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder,
112 const bool bUseBufferedStream = true );
114 static css::uno::Reference< css::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
115 const css::uno::Reference< css::uno::XComponentContext >& xArgContext,
116 const ::rtl::Reference< EncryptionData >& xEncryptionData );
118 static css::uno::Reference< css::xml::crypto::XCipherContext > StaticGetCipher(
119 const css::uno::Reference< css::uno::XComponentContext >& xArgContext,
120 const ::rtl::Reference< EncryptionData >& xEncryptionData,
121 bool bEncrypt );
123 static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
124 sal_Int64 nSize,
125 const OUString& aMediaType,
126 sal_Int8 * & pHeader );
128 static bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > const & rData,
129 sal_Int32 &rEncAlgorithm,
130 sal_Int32 &rChecksumAlgorithm,
131 sal_Int32 &rDerivedKeySize,
132 sal_Int32 &rStartKeyGenID,
133 sal_Int32 &rSize,
134 OUString& aMediaType,
135 const css::uno::Reference < css::io::XInputStream >& rStream );
137 static css::uno::Reference< css::io::XInputStream > StaticGetDataFromRawStream(
138 const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder,
139 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
140 const css::uno::Reference< css::io::XInputStream >& xStream,
141 const ::rtl::Reference < EncryptionData > &rData );
143 static bool StaticHasValidPassword (
144 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
145 const css::uno::Sequence< sal_Int8 > &aReadBuffer,
146 const ::rtl::Reference < EncryptionData > &rData );
148 css::uno::Reference< css::io::XInputStream > getInputStream(
149 ZipEntry& rEntry,
150 const ::rtl::Reference < EncryptionData > &rData,
151 bool bDecrypt,
152 const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder );
154 css::uno::Reference< css::io::XInputStream > getDataStream(
155 ZipEntry& rEntry,
156 const ::rtl::Reference < EncryptionData > &rData,
157 bool bDecrypt,
158 const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder );
160 css::uno::Reference< css::io::XInputStream > getWrappedRawStream(
161 ZipEntry& rEntry,
162 const ::rtl::Reference < EncryptionData > &rData,
163 const OUString& aMediaType,
164 const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder );
166 ZipEnumeration entries();
169 #endif
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */