2010-10-27 12:45:03 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +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_ZIPPACKAGE_HXX
|
|
|
|
#define INCLUDED_PACKAGE_INC_ZIPPACKAGE_HXX
|
2000-11-24 09:25:35 +00:00
|
|
|
|
2015-08-25 16:10:12 +09:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
2000-11-24 09:25:35 +00:00
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/util/XChangesBatch.hpp>
|
2000-12-13 16:00:47 +00:00
|
|
|
#include <com/sun/star/lang/XUnoTunnel.hpp>
|
2001-04-27 13:56:07 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2009-09-08 08:54:47 +00:00
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
2011-03-09 17:29:09 +01:00
|
|
|
#include <com/sun/star/beans/NamedValue.hpp>
|
2001-11-15 18:58:49 +00:00
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
2011-03-09 17:29:09 +01:00
|
|
|
#include <com/sun/star/xml/crypto/CipherID.hpp>
|
2001-11-15 18:58:49 +00:00
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
2017-06-19 17:06:34 +02:00
|
|
|
#include <comphelper/refcountedmutex.hxx>
|
2011-03-09 17:29:09 +01:00
|
|
|
|
2017-10-23 22:34:57 +02:00
|
|
|
#include "HashMaps.hxx"
|
2001-11-15 18:58:49 +00:00
|
|
|
#include <osl/file.h>
|
2011-02-05 21:44:51 -08:00
|
|
|
#include <vector>
|
2017-01-11 19:39:25 -05:00
|
|
|
#include <memory>
|
2009-09-08 08:54:47 +00:00
|
|
|
|
2002-04-29 13:31:07 +00:00
|
|
|
class ZipOutputStream;
|
2000-12-13 16:00:47 +00:00
|
|
|
class ZipPackageFolder;
|
2001-04-19 13:11:06 +00:00
|
|
|
class ZipFile;
|
2001-11-15 18:58:49 +00:00
|
|
|
namespace com { namespace sun { namespace star {
|
|
|
|
namespace container { class XNameContainer; }
|
2002-02-27 14:51:57 +00:00
|
|
|
namespace io { class XStream; class XOutputStream; class XInputStream; class XSeekable; class XActiveDataStreamer; }
|
2001-11-15 18:58:49 +00:00
|
|
|
namespace lang { class XMultiServiceFactory; }
|
2013-01-31 17:08:44 +02:00
|
|
|
namespace uno { class XComponentContext; }
|
2001-11-15 18:58:49 +00:00
|
|
|
namespace task { class XInteractionHandler; }
|
|
|
|
} } }
|
2001-10-02 21:04:04 +00:00
|
|
|
|
|
|
|
enum InitialisationMode
|
|
|
|
{
|
|
|
|
e_IMode_None,
|
|
|
|
e_IMode_URL,
|
|
|
|
e_IMode_XInputStream,
|
|
|
|
e_IMode_XStream
|
|
|
|
};
|
|
|
|
|
2017-10-31 14:15:25 +02:00
|
|
|
class ZipPackage final : public cppu::WeakImplHelper
|
2001-10-02 21:04:04 +00:00
|
|
|
<
|
2015-10-23 14:59:15 +02:00
|
|
|
css::lang::XInitialization,
|
|
|
|
css::lang::XSingleServiceFactory,
|
|
|
|
css::lang::XUnoTunnel,
|
|
|
|
css::lang::XServiceInfo,
|
|
|
|
css::container::XHierarchicalNameAccess,
|
|
|
|
css::util::XChangesBatch,
|
|
|
|
css::beans::XPropertySet
|
2001-10-02 21:04:04 +00:00
|
|
|
>
|
2000-11-24 09:25:35 +00:00
|
|
|
{
|
2017-06-19 17:06:34 +02:00
|
|
|
rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder;
|
2009-09-08 08:54:47 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
|
|
|
|
css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
|
2017-08-20 03:38:05 +02:00
|
|
|
css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > m_aGpgProps;
|
2011-03-09 17:29:09 +01:00
|
|
|
|
|
|
|
FolderHash m_aRecent;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString m_aURL;
|
2004-08-12 10:54:23 +00:00
|
|
|
|
2011-03-09 17:29:09 +01:00
|
|
|
sal_Int32 m_nStartKeyGenerationID;
|
|
|
|
sal_Int32 m_nChecksumDigestID;
|
|
|
|
sal_Int32 m_nCommonEncryptionID;
|
2014-04-17 13:40:46 +02:00
|
|
|
bool m_bHasEncryptedEntries;
|
|
|
|
bool m_bHasNonEncryptedEntries;
|
2011-03-09 17:29:09 +01:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
bool m_bInconsistent;
|
|
|
|
bool m_bForceRecovery;
|
2011-03-09 17:29:09 +01:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
bool m_bMediaTypeFallbackUsed;
|
2011-03-09 17:29:09 +01:00
|
|
|
sal_Int32 m_nFormat;
|
2014-04-17 13:40:46 +02:00
|
|
|
bool m_bAllowRemoveOnInsert;
|
2004-08-12 10:54:23 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
InitialisationMode m_eMode;
|
2001-05-31 08:39:40 +00:00
|
|
|
|
2017-01-08 16:33:55 +00:00
|
|
|
rtl::Reference < ZipPackageFolder > m_xRootFolder;
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference < css::io::XStream > m_xStream;
|
|
|
|
css::uno::Reference < css::io::XInputStream > m_xContentStream;
|
|
|
|
css::uno::Reference < css::io::XSeekable > m_xContentSeek;
|
|
|
|
const css::uno::Reference < css::uno::XComponentContext > m_xContext;
|
2001-05-31 08:39:40 +00:00
|
|
|
|
2017-01-11 19:39:25 -05:00
|
|
|
std::unique_ptr<ZipFile> m_pZipFile;
|
2018-01-11 17:11:06 +01:00
|
|
|
bool m_bDisableFileSync = false;
|
2001-05-31 08:39:40 +00:00
|
|
|
|
2014-04-17 13:40:46 +02:00
|
|
|
bool isLocalFile() const;
|
2012-09-14 18:08:57 +02:00
|
|
|
|
2006-10-13 10:42:27 +00:00
|
|
|
void parseManifest();
|
|
|
|
void parseContentType();
|
2000-11-29 02:21:56 +00:00
|
|
|
void getZipFileContents();
|
2009-09-08 08:54:47 +00:00
|
|
|
|
2002-04-29 13:31:07 +00:00
|
|
|
void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
|
2015-10-23 14:59:15 +02:00
|
|
|
void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList );
|
|
|
|
void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList );
|
2009-09-08 08:54:47 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
css::uno::Reference< css::io::XInputStream > writeTempFile();
|
|
|
|
css::uno::Reference < css::io::XActiveDataStreamer > openOriginalForOutput();
|
2004-10-04 20:07:34 +00:00
|
|
|
void DisconnectFromTargetAndThrowException_Impl(
|
2015-10-23 14:59:15 +02:00
|
|
|
const css::uno::Reference< css::io::XInputStream >& xTempStream );
|
2000-12-13 16:00:47 +00:00
|
|
|
|
2000-11-24 09:25:35 +00:00
|
|
|
public:
|
2015-10-23 14:59:15 +02:00
|
|
|
ZipPackage( const css::uno::Reference < css::uno::XComponentContext > &xContext );
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~ZipPackage() override;
|
2009-09-17 13:53:54 +00:00
|
|
|
ZipFile& getZipFile() { return *m_pZipFile;}
|
2010-04-14 12:07:08 +02:00
|
|
|
sal_Int32 getFormat() const { return m_nFormat; }
|
2001-04-27 13:56:07 +00:00
|
|
|
|
2011-03-24 13:44:49 +01:00
|
|
|
sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; }
|
2011-03-09 17:29:09 +01:00
|
|
|
sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; }
|
|
|
|
sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; }
|
2015-10-23 14:59:15 +02:00
|
|
|
sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; }
|
2011-03-09 17:29:09 +01:00
|
|
|
|
2017-06-19 17:06:34 +02:00
|
|
|
rtl::Reference<comphelper::RefCountedMutex>& GetSharedMutexRef() { return m_aMutexHolder; }
|
2009-09-08 08:54:47 +00:00
|
|
|
|
2015-10-23 14:59:15 +02:00
|
|
|
void ConnectTo( const css::uno::Reference< css::io::XInputStream >& xInStream );
|
|
|
|
const css::uno::Sequence< sal_Int8 > GetEncryptionKey();
|
2009-09-08 08:54:47 +00:00
|
|
|
|
2000-11-24 09:25:35 +00:00
|
|
|
// XInitialization
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
|
2000-11-24 09:25:35 +00:00
|
|
|
// XHierarchicalNameAccess
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Any SAL_CALL getByHierarchicalName( const OUString& aName ) override;
|
|
|
|
virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString& aName ) override;
|
2000-11-24 09:25:35 +00:00
|
|
|
// XSingleServiceFactory
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) override;
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
|
2000-11-24 09:25:35 +00:00
|
|
|
// XChangesBatch
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL commitChanges( ) override;
|
|
|
|
virtual sal_Bool SAL_CALL hasPendingChanges( ) override;
|
|
|
|
virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges( ) override;
|
2001-04-19 13:11:06 +00:00
|
|
|
// XUnoTunnel
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
|
2017-01-19 17:54:53 +01:00
|
|
|
/// @throws css::uno::RuntimeException
|
2017-01-26 12:28:58 +01:00
|
|
|
static css::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId();
|
2001-04-27 13:56:07 +00:00
|
|
|
// XPropertySet
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
|
|
|
|
virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
|
|
|
|
virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
|
|
|
|
virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
|
|
|
|
virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
|
|
|
|
virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
|
|
|
|
virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
|
2001-07-04 13:56:37 +00:00
|
|
|
|
2001-11-15 18:58:49 +00:00
|
|
|
// XServiceInfo
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual OUString SAL_CALL getImplementationName( ) override;
|
|
|
|
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
|
|
|
|
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
|
2001-11-15 18:58:49 +00:00
|
|
|
|
2001-04-19 13:11:06 +00:00
|
|
|
// Uno componentiseralation
|
2013-04-07 12:06:47 +02:00
|
|
|
static OUString static_getImplementationName();
|
2015-10-23 14:59:15 +02:00
|
|
|
static css::uno::Sequence < OUString > static_getSupportedServiceNames();
|
|
|
|
static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory );
|
2000-11-24 09:25:35 +00:00
|
|
|
};
|
|
|
|
#endif
|
2010-10-27 12:45:03 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|