bump product version to 6.4.0.3
[LibreOffice.git] / package / inc / ZipPackage.hxx
blobd1f956068327eb30ca8c22d3b079a8f95919ca16
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/lang/XUnoTunnel.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/beans/NamedValue.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/xml/crypto/CipherID.hpp>
33 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 #include <comphelper/refcountedmutex.hxx>
36 #include "HashMaps.hxx"
37 #include <osl/file.h>
38 #include <vector>
39 #include <memory>
41 class ZipOutputStream;
42 class ZipPackageFolder;
43 class ZipFile;
44 namespace com { namespace sun { namespace 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; }
50 } } }
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::XUnoTunnel,
65 css::lang::XServiceInfo,
66 css::container::XHierarchicalNameAccess,
67 css::util::XChangesBatch,
68 css::beans::XPropertySet
71 rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder;
73 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
74 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
75 css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > m_aGpgProps;
77 FolderHash m_aRecent;
78 OUString m_aURL;
80 sal_Int32 m_nStartKeyGenerationID;
81 sal_Int32 m_nChecksumDigestID;
82 sal_Int32 m_nCommonEncryptionID;
83 bool m_bHasEncryptedEntries;
84 bool m_bHasNonEncryptedEntries;
86 bool m_bInconsistent;
87 bool m_bForceRecovery;
89 bool m_bMediaTypeFallbackUsed;
90 sal_Int32 m_nFormat;
91 bool m_bAllowRemoveOnInsert;
93 InitialisationMode m_eMode;
95 rtl::Reference < ZipPackageFolder > m_xRootFolder;
96 css::uno::Reference < css::io::XStream > m_xStream;
97 css::uno::Reference < css::io::XInputStream > m_xContentStream;
98 css::uno::Reference < css::io::XSeekable > m_xContentSeek;
99 const css::uno::Reference < css::uno::XComponentContext > m_xContext;
101 std::unique_ptr<ZipFile> m_pZipFile;
102 bool m_bDisableFileSync = false;
104 bool isLocalFile() const;
106 void parseManifest();
107 void parseContentType();
108 void getZipFileContents();
110 void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
111 void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList );
112 void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > >& aManList );
114 css::uno::Reference< css::io::XInputStream > writeTempFile();
115 css::uno::Reference < css::io::XActiveDataStreamer > openOriginalForOutput();
116 void DisconnectFromTargetAndThrowException_Impl(
117 const css::uno::Reference< css::io::XInputStream >& xTempStream );
119 public:
120 ZipPackage( const css::uno::Reference < css::uno::XComponentContext > &xContext );
121 virtual ~ZipPackage() override;
122 ZipFile& getZipFile() { return *m_pZipFile;}
123 sal_Int32 getFormat() const { return m_nFormat; }
125 sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; }
126 sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; }
127 sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; }
128 sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; }
130 rtl::Reference<comphelper::RefCountedMutex>& GetSharedMutexRef() { return m_aMutexHolder; }
132 void ConnectTo( const css::uno::Reference< css::io::XInputStream >& xInStream );
133 css::uno::Sequence< sal_Int8 > GetEncryptionKey();
135 // XInitialization
136 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
137 // XHierarchicalNameAccess
138 virtual css::uno::Any SAL_CALL getByHierarchicalName( const OUString& aName ) override;
139 virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString& aName ) override;
140 // XSingleServiceFactory
141 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) override;
142 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
143 // XChangesBatch
144 virtual void SAL_CALL commitChanges( ) override;
145 virtual sal_Bool SAL_CALL hasPendingChanges( ) override;
146 virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges( ) override;
147 // XUnoTunnel
148 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
149 /// @throws css::uno::RuntimeException
150 static css::uno::Sequence < sal_Int8 > getUnoTunnelId();
151 // XPropertySet
152 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
153 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
154 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
155 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
156 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
157 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
158 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
160 // XServiceInfo
161 virtual OUString SAL_CALL getImplementationName( ) override;
162 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
163 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
165 // Uno componentiseralation
166 static OUString static_getImplementationName();
167 static css::uno::Sequence < OUString > static_getSupportedServiceNames();
168 static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory );
170 #endif
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */