Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / package / inc / ZipPackage.hxx
blobe8395824124745187d5d65b2b4d5128b3c241fe7
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_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>
35 #include "HashMaps.hxx"
36 #include "ZipFile.hxx"
37 #include <vector>
38 #include <optional>
40 class SvStream;
41 class ZipOutputStream;
42 class ZipPackageFolder;
43 class ZipFile;
44 namespace com::sun::star {
45 namespace container { class XNameContainer; }
46 namespace io { class XStream; class XOutputStream; class XInputStream; class XSeekable; class XActiveDataStreamer; }
47 namespace lang { class XMultiServiceFactory; }
48 namespace uno { class XComponentContext; }
49 namespace task { class XInteractionHandler; }
52 enum InitialisationMode
54 e_IMode_None,
55 e_IMode_URL,
56 e_IMode_XInputStream,
57 e_IMode_XStream
60 class ZipPackage final : public cppu::WeakImplHelper
62 css::lang::XInitialization,
63 css::lang::XSingleServiceFactory,
64 css::lang::XServiceInfo,
65 css::container::XHierarchicalNameAccess,
66 css::util::XChangesBatch,
67 css::beans::XPropertySet
70 rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder;
72 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
73 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
74 css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > m_aGpgProps;
76 FolderHash m_aRecent;
77 OUString m_aURL;
79 sal_Int32 m_nStartKeyGenerationID;
80 sal_Int32 m_nChecksumDigestID;
81 sal_Int32 m_nCommonEncryptionID;
82 bool m_bHasEncryptedEntries;
83 bool m_bHasNonEncryptedEntries;
85 bool m_bInconsistent;
86 bool m_bForceRecovery;
88 bool m_bMediaTypeFallbackUsed;
89 sal_Int32 m_nFormat;
90 bool m_bAllowRemoveOnInsert;
92 InitialisationMode m_eMode;
94 rtl::Reference < ZipPackageFolder > m_xRootFolder;
95 css::uno::Reference < css::io::XStream > m_xStream;
96 css::uno::Reference < css::io::XInputStream > m_xContentStream;
97 css::uno::Reference < css::io::XSeekable > m_xContentSeek;
98 const css::uno::Reference < css::uno::XComponentContext > m_xContext;
100 std::optional<ZipFile> m_pZipFile;
101 bool m_bDisableFileSync = false;
103 bool isLocalFile() const;
105 void parseManifest();
106 void parseContentType();
107 void getZipFileContents();
109 void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
110 void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList );
111 void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList );
113 css::uno::Reference< css::io::XInputStream > writeTempFile();
114 css::uno::Reference < css::io::XActiveDataStreamer > openOriginalForOutput();
115 void DisconnectFromTargetAndThrowException_Impl(
116 const css::uno::Reference< css::io::XInputStream >& xTempStream );
118 public:
119 ZipPackage( css::uno::Reference < css::uno::XComponentContext > xContext );
120 virtual ~ZipPackage() override;
121 ZipFile& getZipFile() { return *m_pZipFile;}
122 sal_Int32 getFormat() const { return m_nFormat; }
124 sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; }
125 sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; }
126 sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; }
127 sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; }
129 rtl::Reference<comphelper::RefCountedMutex>& GetSharedMutexRef() { return m_aMutexHolder; }
131 void ConnectTo( const css::uno::Reference< css::io::XInputStream >& xInStream );
132 css::uno::Sequence< sal_Int8 > GetEncryptionKey();
134 // XInitialization
135 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
136 // XHierarchicalNameAccess
137 virtual css::uno::Any SAL_CALL getByHierarchicalName( const OUString& aName ) override;
138 virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString& aName ) override;
139 // XSingleServiceFactory
140 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) override;
141 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
142 // XChangesBatch
143 virtual void SAL_CALL commitChanges( ) override;
144 virtual sal_Bool SAL_CALL hasPendingChanges( ) override;
145 virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges( ) override;
146 // XPropertySet
147 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
148 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
149 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
150 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
151 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
152 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
153 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
155 // XServiceInfo
156 virtual OUString SAL_CALL getImplementationName( ) override;
157 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
158 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
160 #endif
162 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportZip(SvStream& rStream);
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */