2010-10-27 12:45:03 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-22 18:32:07 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2014-04-18 22:14:30 +02:00
|
|
|
#ifndef INCLUDED_PACKAGE_INC_ZIPFILE_HXX
|
|
|
|
#define INCLUDED_PACKAGE_INC_ZIPFILE_HXX
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2003-09-11 09:13:55 +00:00
|
|
|
#include <com/sun/star/packages/zip/ZipException.hpp>
|
|
|
|
#include <com/sun/star/packages/zip/ZipIOException.hpp>
|
|
|
|
#include <com/sun/star/packages/NoEncryptionException.hpp>
|
|
|
|
#include <com/sun/star/packages/WrongPasswordException.hpp>
|
2011-08-21 18:12:16 -05:00
|
|
|
#include <com/sun/star/xml/crypto/XCipherContext.hpp>
|
|
|
|
#include <com/sun/star/xml/crypto/XDigestContext.hpp>
|
|
|
|
|
2011-08-26 14:04:17 +02:00
|
|
|
#include <package/Inflater.hxx>
|
2001-04-19 13:11:06 +00:00
|
|
|
#include <ByteGrabber.hxx>
|
2001-09-14 13:45:19 +00:00
|
|
|
#include <HashMaps.hxx>
|
2011-08-21 18:12:16 -05:00
|
|
|
#include <EncryptionData.hxx>
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2009-09-08 08:54:47 +00:00
|
|
|
#include <mutexholder.hxx>
|
2001-11-15 18:55:24 +00:00
|
|
|
|
|
|
|
namespace com { namespace sun { namespace star {
|
2012-10-31 14:58:31 +02:00
|
|
|
namespace uno { class XComponentContext; }
|
2003-03-26 13:16:07 +00:00
|
|
|
namespace ucb { class XProgressHandler; }
|
2001-11-15 18:55:24 +00:00
|
|
|
} } }
|
2010-10-15 12:18:51 -05:00
|
|
|
namespace rtl
|
2001-11-15 18:55:24 +00:00
|
|
|
{
|
2010-10-15 12:18:51 -05:00
|
|
|
template < class T > class Reference;
|
2001-11-15 18:55:24 +00:00
|
|
|
}
|
2011-08-21 18:12:16 -05:00
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
/*
|
2001-09-05 18:32:43 +00:00
|
|
|
* We impose arbitrary but reasonable limit on ZIP files.
|
2000-11-13 12:38:03 +00:00
|
|
|
*/
|
2001-04-27 13:56:07 +00:00
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
#define ZIP_MAXNAMELEN 512
|
|
|
|
#define ZIP_MAXENTRIES (0x10000 - 2)
|
|
|
|
|
2001-04-27 13:56:07 +00:00
|
|
|
class ZipEnumeration;
|
|
|
|
|
|
|
|
class ZipFile
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2001-04-27 13:56:07 +00:00
|
|
|
protected:
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::Mutex m_aMutex;
|
|
|
|
|
2000-11-29 02:21:56 +00:00
|
|
|
EntryHash aEntries;
|
2000-11-13 12:38:03 +00:00
|
|
|
ByteGrabber aGrabber;
|
2011-03-29 14:18:56 +02:00
|
|
|
ZipUtils::Inflater aInflater;
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference < css::io::XInputStream > xStream;
|
|
|
|
css::uno::Reference < css::io::XSeekable > xSeek;
|
|
|
|
const css::uno::Reference < css::uno::XComponentContext > m_xContext;
|
2001-07-04 13:56:37 +00:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bRecoveryMode;
|
2005-03-15 10:49:37 +00:00
|
|
|
|
2003-09-11 09:13:55 +00:00
|
|
|
// aMediaType parameter is used only for raw stream header creation
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference < css::io::XInputStream > createUnbufferedStream(
|
2015-06-29 09:15:16 +02:00
|
|
|
const rtl::Reference<SotMutexHolder>& aMutexHolder,
|
2001-12-04 16:44:39 +00:00
|
|
|
ZipEntry & rEntry,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData,
|
2003-09-11 09:13:55 +00:00
|
|
|
sal_Int8 nStreamMode,
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bDecrypt,
|
2014-03-06 15:29:08 +02:00
|
|
|
const OUString& aMediaType = OUString() );
|
2001-12-04 16:44:39 +00:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
bool hasValidPassword ( ZipEntry & rEntry, const rtl::Reference < EncryptionData > &rData );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
bool checkSizeAndCRC( const ZipEntry& aEntry );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2012-09-21 13:09:29 +01:00
|
|
|
sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2012-09-21 13:09:29 +01:00
|
|
|
void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
public:
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
ZipFile( css::uno::Reference < css::io::XInputStream > &xInput,
|
|
|
|
const css::uno::Reference < css::uno::XComponentContext > &rxContext,
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bInitialise
|
2003-03-26 13:16:07 +00:00
|
|
|
)
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
ZipFile( css::uno::Reference < css::io::XInputStream > &xInput,
|
|
|
|
const css::uno::Reference < css::uno::XComponentContext > &rxContext,
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bInitialise,
|
2015-12-23 16:41:52 +02:00
|
|
|
bool bForceRecover
|
2003-03-26 13:16:07 +00:00
|
|
|
)
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2001-09-05 18:32:43 +00:00
|
|
|
|
|
|
|
~ZipFile();
|
|
|
|
|
2006-10-06 09:48:53 +00:00
|
|
|
EntryHash& GetEntryHash() { return aEntries; }
|
|
|
|
|
2016-04-12 12:08:00 +02:00
|
|
|
void setInputStream ( const css::uno::Reference < css::io::XInputStream >& xNewStream );
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference< css::io::XInputStream > SAL_CALL getRawData(
|
2001-09-14 13:45:19 +00:00
|
|
|
ZipEntry& rEntry,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData,
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bDecrypt,
|
2015-06-29 09:15:16 +02:00
|
|
|
const rtl::Reference<SotMutexHolder>& aMutexHolder )
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
static css::uno::Reference< css::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
|
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& xArgContext,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference< EncryptionData >& xEncryptionData );
|
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
static css::uno::Reference< css::xml::crypto::XCipherContext > StaticGetCipher(
|
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& xArgContext,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference< EncryptionData >& xEncryptionData,
|
|
|
|
bool bEncrypt );
|
|
|
|
|
|
|
|
static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
|
2012-09-21 13:09:29 +01:00
|
|
|
sal_Int64 nSize,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& aMediaType,
|
2003-09-11 09:13:55 +00:00
|
|
|
sal_Int8 * & pHeader );
|
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
static bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData,
|
2011-08-21 18:12:16 -05:00
|
|
|
sal_Int32 &rEncAlgorithm,
|
|
|
|
sal_Int32 &rChecksumAlgorithm,
|
|
|
|
sal_Int32 &rDerivedKeySize,
|
|
|
|
sal_Int32 &rStartKeyGenID,
|
2003-09-11 09:13:55 +00:00
|
|
|
sal_Int32 &rSize,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString& aMediaType,
|
2015-10-23 14:59:15 +02:00
|
|
|
const css::uno::Reference < css::io::XInputStream >& rStream );
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
static css::uno::Reference< css::io::XInputStream > StaticGetDataFromRawStream(
|
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
|
|
|
const css::uno::Reference< css::io::XInputStream >& xStream,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData )
|
2015-10-23 14:59:15 +02:00
|
|
|
throw ( css::packages::WrongPasswordException,
|
|
|
|
css::packages::zip::ZipIOException,
|
|
|
|
css::uno::RuntimeException );
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
static bool StaticHasValidPassword (
|
2015-10-23 14:59:15 +02:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
|
|
|
const css::uno::Sequence< sal_Int8 > &aReadBuffer,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData );
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream(
|
2001-09-14 13:45:19 +00:00
|
|
|
ZipEntry& rEntry,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData,
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bDecrypt,
|
2015-06-29 09:15:16 +02:00
|
|
|
const rtl::Reference<SotMutexHolder>& aMutexHolder )
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference< css::io::XInputStream > SAL_CALL getDataStream(
|
2003-09-11 09:13:55 +00:00
|
|
|
ZipEntry& rEntry,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData,
|
2014-04-17 13:40:46 +02:00
|
|
|
bool bDecrypt,
|
2015-06-29 09:15:16 +02:00
|
|
|
const rtl::Reference<SotMutexHolder>& aMutexHolder )
|
2015-10-23 14:59:15 +02:00
|
|
|
throw ( css::packages::WrongPasswordException,
|
|
|
|
css::io::IOException,
|
|
|
|
css::packages::zip::ZipException,
|
|
|
|
css::uno::RuntimeException );
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference< css::io::XInputStream > SAL_CALL getWrappedRawStream(
|
2003-09-11 09:13:55 +00:00
|
|
|
ZipEntry& rEntry,
|
2011-08-21 18:12:16 -05:00
|
|
|
const ::rtl::Reference < EncryptionData > &rData,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& aMediaType,
|
2015-06-29 09:15:16 +02:00
|
|
|
const rtl::Reference<SotMutexHolder>& aMutexHolder )
|
2015-10-23 14:59:15 +02:00
|
|
|
throw ( css::packages::NoEncryptionException,
|
|
|
|
css::io::IOException,
|
|
|
|
css::packages::zip::ZipException,
|
|
|
|
css::uno::RuntimeException );
|
2003-09-11 09:13:55 +00:00
|
|
|
|
2001-04-27 13:56:07 +00:00
|
|
|
ZipEnumeration * SAL_CALL entries( );
|
2001-07-04 13:56:37 +00:00
|
|
|
protected:
|
2014-04-17 13:40:46 +02:00
|
|
|
bool readLOC ( ZipEntry &rEntry)
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2000-12-04 10:30:09 +00:00
|
|
|
sal_Int32 readCEN()
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2000-12-04 10:30:09 +00:00
|
|
|
sal_Int32 findEND()
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2016-01-14 16:31:47 +02:00
|
|
|
void recover()
|
2015-10-23 14:59:15 +02:00
|
|
|
throw(css::io::IOException, css::packages::zip::ZipException, css::uno::RuntimeException);
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2010-10-27 12:45:03 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|