LibreOffice Module package (master) 1
ZipPackage.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGE_HXX
20#define INCLUDED_PACKAGE_INC_ZIPPACKAGE_HXX
21
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>
33#include <rtl/ref.hxx>
34
35#include "HashMaps.hxx"
36#include "ZipFile.hxx"
37#include <vector>
38#include <optional>
39
40class SvStream;
41class ZipOutputStream;
43class ZipFile;
44namespace 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; }
50}
51
53{
58};
59
60class ZipPackage final : public cppu::WeakImplHelper
61 <
62 css::lang::XInitialization,
63 css::lang::XSingleServiceFactory,
64 css::lang::XServiceInfo,
65 css::container::XHierarchicalNameAccess,
66 css::util::XChangesBatch,
67 css::beans::XPropertySet
68 >
69{
71
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;
75
77 OUString m_aURL;
78
84
87
89 sal_Int32 m_nFormat;
91
93
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;
99
100 std::optional<ZipFile> m_pZipFile;
101 bool m_bDisableFileSync = false;
102
103 bool isLocalFile() const;
104
105 void parseManifest();
106 void parseContentType();
107 void getZipFileContents();
108
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 );
112
113 css::uno::Reference< css::io::XInputStream > writeTempFile();
114 css::uno::Reference < css::io::XActiveDataStreamer > openOriginalForOutput();
116 const css::uno::Reference< css::io::XInputStream >& xTempStream );
117
118public:
119 ZipPackage( css::uno::Reference < css::uno::XComponentContext > xContext );
120 virtual ~ZipPackage() override;
122 sal_Int32 getFormat() const { return m_nFormat; }
123
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; }
128
130
131 void ConnectTo( const css::uno::Reference< css::io::XInputStream >& xInStream );
132 css::uno::Sequence< sal_Int8 > GetEncryptionKey();
133
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;
154
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;
159};
160#endif
161
162extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportZip(SvStream& rStream);
163
164/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< OUString, ZipPackageFolder * > FolderHash
Definition: HashMaps.hxx:26
SAL_DLLPUBLIC_EXPORT bool TestImportZip(SvStream &rStream)
InitialisationMode
Definition: ZipPackage.hxx:53
@ e_IMode_XInputStream
Definition: ZipPackage.hxx:56
@ e_IMode_XStream
Definition: ZipPackage.hxx:57
@ e_IMode_None
Definition: ZipPackage.hxx:54
@ e_IMode_URL
Definition: ZipPackage.hxx:55
bool m_bMediaTypeFallbackUsed
Definition: ZipPackage.hxx:88
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::optional< ZipFile > m_pZipFile
Definition: ZipPackage.hxx:100
ZipFile & getZipFile()
Definition: ZipPackage.hxx:121
virtual void SAL_CALL commitChanges() override
sal_Int32 m_nStartKeyGenerationID
Definition: ZipPackage.hxx:79
bool isLocalFile() const
Definition: ZipPackage.cxx:160
sal_Int32 getFormat() const
Definition: ZipPackage.hxx:122
virtual ~ZipPackage() override
Definition: ZipPackage.cxx:156
void parseManifest()
Definition: ZipPackage.cxx:165
void DisconnectFromTargetAndThrowException_Impl(const css::uno::Reference< css::io::XInputStream > &xTempStream)
css::uno::Reference< css::io::XActiveDataStreamer > openOriginalForOutput()
css::uno::Sequence< sal_Int8 > m_aEncryptionKey
Definition: ZipPackage.hxx:73
const css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: ZipPackage.hxx:98
css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > m_aGpgProps
Definition: ZipPackage.hxx:74
bool m_bAllowRemoveOnInsert
Definition: ZipPackage.hxx:90
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
void WriteMimetypeMagicFile(ZipOutputStream &aZipOut)
bool m_bDisableFileSync
Definition: ZipPackage.hxx:101
virtual css::uno::Any SAL_CALL getByHierarchicalName(const OUString &aName) override
Definition: ZipPackage.cxx:792
bool m_bHasEncryptedEntries
Definition: ZipPackage.hxx:82
InitialisationMode m_eMode
Definition: ZipPackage.hxx:92
rtl::Reference< comphelper::RefCountedMutex > m_aMutexHolder
Definition: ZipPackage.hxx:70
void getZipFileContents()
Definition: ZipPackage.cxx:507
rtl::Reference< comphelper::RefCountedMutex > & GetSharedMutexRef()
Definition: ZipPackage.hxx:129
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
sal_Int32 m_nFormat
Definition: ZipPackage.hxx:89
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: ZipPackage.cxx:586
void ConnectTo(const css::uno::Reference< css::io::XInputStream > &xInStream)
sal_Int32 m_nCommonEncryptionID
Definition: ZipPackage.hxx:81
bool m_bHasNonEncryptedEntries
Definition: ZipPackage.hxx:83
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
sal_Int32 GetStartKeyGenID() const
Definition: ZipPackage.hxx:124
void WriteContentTypes(ZipOutputStream &aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > > &aManList)
virtual sal_Bool SAL_CALL hasPendingChanges() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: ZipPackage.cxx:988
css::uno::Reference< css::io::XStream > m_xStream
Definition: ZipPackage.hxx:95
virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges() override
rtl::Reference< ZipPackageFolder > m_xRootFolder
Definition: ZipPackage.hxx:94
sal_Int32 GetDefaultDerivedKeySize() const
Definition: ZipPackage.hxx:127
bool m_bInconsistent
Definition: ZipPackage.hxx:85
bool m_bForceRecovery
Definition: ZipPackage.hxx:86
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
void WriteManifest(ZipOutputStream &aZipOut, const ::std::vector< css::uno::Sequence< css::beans::PropertyValue > > &aManList)
sal_Int32 m_nChecksumDigestID
Definition: ZipPackage.hxx:80
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
sal_Int32 GetChecksumAlgID() const
Definition: ZipPackage.hxx:126
void parseContentType()
Definition: ZipPackage.cxx:444
css::uno::Reference< css::io::XInputStream > writeTempFile()
FolderHash m_aRecent
Definition: ZipPackage.hxx:76
sal_Int32 GetEncAlgID() const
Definition: ZipPackage.hxx:125
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::io::XSeekable > m_xContentSeek
Definition: ZipPackage.hxx:97
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance() override
Definition: ZipPackage.cxx:982
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
ZipPackage(css::uno::Reference< css::uno::XComponentContext > xContext)
Definition: ZipPackage.cxx:138
virtual sal_Bool SAL_CALL hasByHierarchicalName(const OUString &aName) override
Definition: ZipPackage.cxx:886
OUString m_aURL
Definition: ZipPackage.hxx:77
css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys
Definition: ZipPackage.hxx:72
css::uno::Sequence< sal_Int8 > GetEncryptionKey()
css::uno::Reference< css::io::XInputStream > m_xContentStream
Definition: ZipPackage.hxx:96
unsigned char sal_Bool