Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / package / inc / ZipPackage.hxx
blob42f04801b643330d7a1daec8c59f7aec01f361f4
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>
35 #include <HashMaps.hxx>
36 #include <osl/file.h>
37 #include <mutexholder.hxx>
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 : 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 protected:
72 rtl::Reference<SotMutexHolder> m_aMutexHolder;
74 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
75 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
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;
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( const 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<SotMutexHolder>& GetSharedMutexRef() { return m_aMutexHolder; }
131 void ConnectTo( const css::uno::Reference< css::io::XInputStream >& xInStream );
132 const 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 // XUnoTunnel
147 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
148 /// @throws css::uno::RuntimeException
149 static css::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId();
150 // XPropertySet
151 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
152 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
153 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
154 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
155 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
156 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
157 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
159 // XServiceInfo
160 virtual OUString SAL_CALL getImplementationName( ) override;
161 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
162 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
164 // Uno componentiseralation
165 static OUString static_getImplementationName();
166 static css::uno::Sequence < OUString > static_getSupportedServiceNames();
167 static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory );
169 #endif
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */