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 ************************************************************************/
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
; }
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)
67 ::osl::Mutex m_aMutex
;
69 ::rtl::OUString sComment
; /* zip file comment */
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(
82 const ::rtl::Reference
< EncryptionData
> &rData
,
86 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> createFileStream(
88 const ::rtl::Reference
< EncryptionData
> &rData
,
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
,
96 const ::rtl::Reference
< EncryptionData
> &rData
,
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
);
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
,
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
);
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(
132 const ::rtl::Reference
< EncryptionData
> &rData
,
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
,
147 static void StaticFillHeader ( const ::rtl::Reference
< EncryptionData
> & rData
,
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
,
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(
177 const ::rtl::Reference
< EncryptionData
> &rData
,
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(
184 const ::rtl::Reference
< EncryptionData
> &rData
,
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(
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( );
204 sal_Bool
readLOC ( ZipEntry
&rEntry
)
205 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
207 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
209 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
211 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */