1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_ZIPPACKAGE_HXX
20 #define INCLUDED_PACKAGE_INC_ZIPPACKAGE_HXX
22 #include <cppuhelper/implbase.hxx>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
25 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
26 #include <com/sun/star/util/XChangesBatch.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/beans/NamedValue.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/xml/crypto/CipherID.hpp>
32 #include <comphelper/refcountedmutex.hxx>
33 #include <rtl/ref.hxx>
34 #include <o3tl/unreachable.hxx>
36 #include "HashMaps.hxx"
37 #include "ZipFile.hxx"
42 class ZipOutputStream
;
43 class ZipPackageFolder
;
45 namespace com::sun::star
{
46 namespace container
{ class XNameContainer
; }
47 namespace io
{ class XStream
; class XOutputStream
; class XInputStream
; class XSeekable
; class XActiveDataStreamer
; }
48 namespace lang
{ class XMultiServiceFactory
; }
49 namespace uno
{ class XComponentContext
; }
50 namespace task
{ class XInteractionHandler
; }
53 enum InitialisationMode
61 sal_Int32
GetDefaultDerivedKeySize(sal_Int32 nCipherID
);
63 class ZipPackage final
: public cppu::WeakImplHelper
65 css::lang::XInitialization
,
66 css::lang::XSingleServiceFactory
,
67 css::lang::XServiceInfo
,
68 css::container::XHierarchicalNameAccess
,
69 css::util::XChangesBatch
,
70 css::beans::XPropertySet
73 rtl::Reference
<comphelper::RefCountedMutex
> m_aMutexHolder
;
75 css::uno::Sequence
< css::beans::NamedValue
> m_aStorageEncryptionKeys
;
76 css::uno::Sequence
< sal_Int8
> m_aEncryptionKey
;
77 css::uno::Sequence
< css::uno::Sequence
< css::beans::NamedValue
> > m_aGpgProps
;
82 sal_Int32 m_nStartKeyGenerationID
;
83 ::std::optional
<sal_Int32
> m_oChecksumDigestID
;
84 sal_Int32 m_nKeyDerivationFunctionID
;
85 sal_Int32 m_nCommonEncryptionID
;
86 bool m_bHasEncryptedEntries
;
87 bool m_bHasNonEncryptedEntries
;
90 bool m_bForceRecovery
;
92 bool m_bMediaTypeFallbackUsed
;
94 bool m_bAllowRemoveOnInsert
;
96 InitialisationMode m_eMode
;
98 rtl::Reference
< ZipPackageFolder
> m_xRootFolder
;
99 css::uno::Reference
< css::io::XStream
> m_xStream
;
100 css::uno::Reference
< css::io::XInputStream
> m_xContentStream
;
101 css::uno::Reference
< css::io::XSeekable
> m_xContentSeek
;
102 const css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
104 std::optional
<ZipFile
> m_pZipFile
;
105 bool m_bDisableFileSync
= false;
107 bool isLocalFile() const;
109 void checkZipEntriesWithDD();
110 void parseManifest();
111 void parseContentType();
112 void getZipFileContents();
114 void WriteMimetypeMagicFile( ZipOutputStream
& aZipOut
);
115 void WriteManifest( ZipOutputStream
& aZipOut
, const ::std::vector
< css::uno::Sequence
< css::beans::PropertyValue
> >& aManList
);
116 void WriteContentTypes( ZipOutputStream
& aZipOut
, const ::std::vector
< css::uno::Sequence
< css::beans::PropertyValue
> >& aManList
);
118 css::uno::Reference
< css::io::XInputStream
> writeTempFile();
119 css::uno::Reference
< css::io::XActiveDataStreamer
> openOriginalForOutput();
120 void DisconnectFromTargetAndThrowException_Impl(
121 const css::uno::Reference
< css::io::XInputStream
>& xTempStream
);
124 ZipPackage( css::uno::Reference
< css::uno::XComponentContext
> xContext
);
125 virtual ~ZipPackage() override
;
126 ZipFile
& getZipFile() { return *m_pZipFile
;}
127 sal_Int32
getFormat() const { return m_nFormat
; }
129 sal_Int32
GetStartKeyGenID() const { return m_nStartKeyGenerationID
; }
130 sal_Int32
GetEncAlgID() const { return m_nCommonEncryptionID
; }
131 const ::std::optional
<sal_Int32
> & GetChecksumAlgID() const { return m_oChecksumDigestID
; }
132 sal_Int32
GetDefaultDerivedKeySize() const {
133 return ::GetDefaultDerivedKeySize(m_nCommonEncryptionID
);
136 rtl::Reference
<comphelper::RefCountedMutex
>& GetSharedMutexRef() { return m_aMutexHolder
; }
138 void ConnectTo( const css::uno::Reference
< css::io::XInputStream
>& xInStream
);
139 css::uno::Sequence
< sal_Int8
> GetEncryptionKey();
142 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
143 // XHierarchicalNameAccess
144 virtual css::uno::Any SAL_CALL
getByHierarchicalName( const OUString
& aName
) override
;
145 virtual sal_Bool SAL_CALL
hasByHierarchicalName( const OUString
& aName
) override
;
146 // XSingleServiceFactory
147 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance( ) override
;
148 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
150 virtual void SAL_CALL
commitChanges( ) override
;
151 virtual sal_Bool SAL_CALL
hasPendingChanges( ) override
;
152 virtual css::uno::Sequence
< css::util::ElementChange
> SAL_CALL
getPendingChanges( ) override
;
154 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
155 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
156 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
157 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
158 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
159 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
160 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
163 virtual OUString SAL_CALL
getImplementationName( ) override
;
164 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
165 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
169 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportZip(SvStream
& rStream
);
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */