Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / package / inc / ZipPackageStream.hxx
blobed0799779273827f246efe29140e4b15477a61bf
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_ZIPPACKAGESTREAM_HXX
20 #define INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX
22 #include <com/sun/star/io/XActiveDataSink.hpp>
23 #include <com/sun/star/io/XSeekable.hpp>
24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/packages/XDataSinkEncrSupport.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <ZipPackageEntry.hxx>
28 #include <rtl/ref.hxx>
29 #include <cppuhelper/implbase.hxx>
31 #include <EncryptionData.hxx>
32 #include <mutexholder.hxx>
34 #define PACKAGE_STREAM_NOTSET 0
35 #define PACKAGE_STREAM_PACKAGEMEMBER 1
36 #define PACKAGE_STREAM_DETECT 2
37 #define PACKAGE_STREAM_DATA 3
38 #define PACKAGE_STREAM_RAW 4
40 class ZipPackage;
41 struct ZipEntry;
42 class ZipPackageStream : public cppu::ImplInheritanceHelper
44 ZipPackageEntry,
45 css::io::XActiveDataSink,
46 css::packages::XDataSinkEncrSupport
49 private:
50 css::uno::Reference < css::io::XInputStream > m_xStream;
51 ZipPackage &m_rZipPackage;
52 bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
54 ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
55 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
56 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
58 sal_Int32 m_nImportedStartKeyAlgorithm;
59 sal_Int32 m_nImportedEncryptionAlgorithm;
60 sal_Int32 m_nImportedChecksumAlgorithm;
61 sal_Int32 m_nImportedDerivedKeySize;
63 sal_uInt8 m_nStreamMode;
64 sal_uInt32 m_nMagicalHackPos;
65 sal_uInt32 m_nMagicalHackSize;
66 sal_Int64 m_nOwnStreamOrigSize;
68 bool m_bHasSeekable;
69 bool m_bCompressedIsSetFromOutside;
70 bool m_bFromManifest;
71 bool m_bUseWinEncoding;
72 bool m_bRawStream;
74 /// Check that m_xStream implements io::XSeekable and return it
75 css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream();
76 /// @throws css::uno::RuntimeException
77 css::uno::Reference< css::io::XInputStream > SAL_CALL getRawData();
79 public:
80 bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
82 bool IsFromManifest() const { return m_bFromManifest; }
83 void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; }
85 ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false );
87 css::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false );
89 sal_Int32 GetStartKeyGenID();
91 sal_Int32 GetEncryptionAlgorithm() const;
92 sal_Int32 GetBlockSize() const;
94 void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;}
95 void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;}
96 void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
97 void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
98 void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
99 void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
100 void SetToBeEncrypted (bool bNewValue)
102 m_bToBeEncrypted = bNewValue;
103 if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is())
104 m_xBaseEncryptionData = new BaseEncryptionData;
105 else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
106 m_xBaseEncryptionData.clear();
108 void SetPackageMember (bool bNewValue);
110 void setInitialisationVector (const css::uno::Sequence < sal_Int8 >& rNewVector )
111 { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
112 void setSalt (const css::uno::Sequence < sal_Int8 >& rNewSalt )
113 { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
114 void setDigest (const css::uno::Sequence < sal_Int8 >& rNewDigest )
115 { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
116 void setIterationCount (const sal_Int32 nNewCount)
117 { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
118 void setSize (const sal_Int64 nNewSize);
120 ZipPackageStream( ZipPackage & rNewPackage,
121 const css::uno::Reference < css::uno::XComponentContext >& xContext,
122 sal_Int32 nFormat,
123 bool bAllowRemoveOnInsert );
124 virtual ~ZipPackageStream() override;
126 css::uno::Reference< css::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
127 css::uno::Reference< css::io::XInputStream > TryToGetRawFromDataStream(bool bAddHeaderForEncr );
129 bool ParsePackageRawStream();
130 virtual bool saveChild( const OUString &rPath,
131 std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
132 ZipOutputStream & rZipOut,
133 const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
134 const rtlRandomPool &rRandomPool ) override;
136 void setZipEntryOnLoading( const ZipEntry &rInEntry);
137 void successfullyWritten( ZipEntry *pEntry );
139 static css::uno::Sequence < sal_Int8 > static_getImplementationId();
141 // XActiveDataSink
142 virtual void SAL_CALL setInputStream( const css::uno::Reference< css::io::XInputStream >& aStream ) override;
143 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
145 // XDataSinkEncrSupport
146 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getDataStream() override;
147 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getRawStream() override;
148 virtual void SAL_CALL setDataStream(
149 const css::uno::Reference< css::io::XInputStream >& aStream ) override;
150 virtual void SAL_CALL setRawStream(
151 const css::uno::Reference< css::io::XInputStream >& aStream ) override;
152 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getPlainRawStream() override;
154 // XUnoTunnel
155 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
157 // XPropertySet
158 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
159 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
161 // XServiceInfo
162 virtual OUString SAL_CALL getImplementationName( ) override;
163 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
164 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
166 #endif
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */