Line data Source code
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_ZIPPACKAGESTREAM_HXX
20 : #define INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX
21 :
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/implbase2.hxx>
30 :
31 : #include <EncryptionData.hxx>
32 : #include <mutexholder.hxx>
33 :
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
39 :
40 : class ZipPackage;
41 : struct ZipEntry;
42 : class ZipPackageStream : public cppu::ImplInheritanceHelper2
43 : <
44 : ZipPackageEntry,
45 : ::com::sun::star::io::XActiveDataSink,
46 : ::com::sun::star::packages::XDataSinkEncrSupport
47 : >
48 : {
49 : private:
50 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xStream;
51 : ZipPackage &m_rZipPackage;
52 : bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
53 :
54 : ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
55 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys;
56 : ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey;
57 :
58 : sal_Int32 m_nImportedStartKeyAlgorithm;
59 : sal_Int32 m_nImportedEncryptionAlgorithm;
60 : sal_Int32 m_nImportedChecksumAlgorithm;
61 : sal_Int32 m_nImportedDerivedKeySize;
62 :
63 : sal_uInt8 m_nStreamMode;
64 : sal_uInt32 m_nMagicalHackPos;
65 : sal_uInt32 m_nMagicalHackSize;
66 : sal_Int64 m_nOwnStreamOrigSize;
67 :
68 : bool m_bHasSeekable;
69 : bool m_bCompressedIsSetFromOutside;
70 : bool m_bFromManifest;
71 : bool m_bUseWinEncoding;
72 : bool m_bRawStream;
73 :
74 : /// Check that m_xStream implements io::XSeekable and return it
75 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream();
76 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
77 : throw(::com::sun::star::uno::RuntimeException);
78 :
79 : public:
80 10167 : bool IsEncrypted () const { return m_bIsEncrypted;}
81 111622 : bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
82 :
83 7572 : bool IsFromManifest() const { return m_bFromManifest; }
84 7596 : void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; }
85 :
86 : ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false );
87 :
88 : ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false );
89 :
90 : sal_Int32 GetStartKeyGenID();
91 :
92 : sal_Int32 GetEncryptionAlgorithm() const;
93 : sal_Int32 GetBlockSize() const;
94 :
95 24 : void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;}
96 29 : void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;}
97 24 : void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
98 24 : void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
99 24 : void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
100 24 : void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
101 49 : void SetToBeEncrypted (bool bNewValue)
102 : {
103 49 : m_bToBeEncrypted = bNewValue;
104 49 : if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is())
105 24 : m_xBaseEncryptionData = new BaseEncryptionData;
106 25 : else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
107 0 : m_xBaseEncryptionData.clear();
108 49 : }
109 : void SetPackageMember (bool bNewValue);
110 :
111 28 : void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector )
112 28 : { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
113 28 : void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt )
114 28 : { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
115 28 : void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest )
116 28 : { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
117 28 : void setIterationCount (const sal_Int32 nNewCount)
118 28 : { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
119 : void setSize (const sal_Int64 nNewSize);
120 :
121 : void CloseOwnStreamIfAny();
122 :
123 : ZipPackageStream( ZipPackage & rNewPackage,
124 : const css::uno::Reference < css::uno::XComponentContext >& xContext,
125 : sal_Int32 nFormat,
126 : bool bAllowRemoveOnInsert );
127 : virtual ~ZipPackageStream();
128 :
129 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
130 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream(
131 : bool bAddHeaderForEncr );
132 :
133 : bool ParsePackageRawStream();
134 : virtual bool saveChild( const OUString &rPath,
135 : std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
136 : ZipOutputStream & rZipOut,
137 : const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
138 : const rtlRandomPool &rRandomPool ) SAL_OVERRIDE;
139 :
140 : void setZipEntryOnLoading( const ZipEntry &rInEntry);
141 : void successfullyWritten( ZipEntry *pEntry );
142 :
143 : static ::com::sun::star::uno::Sequence < sal_Int8 > static_getImplementationId();
144 :
145 : // XActiveDataSink
146 : virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
147 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( )
149 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
150 :
151 : // XDataSinkEncrSupport
152 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream()
153 : throw ( ::com::sun::star::packages::WrongPasswordException, ::com::sun::star::packages::zip::ZipException,
154 : ::com::sun::star::io::IOException,
155 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
156 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream()
157 : throw ( ::com::sun::star::packages::NoEncryptionException,
158 : ::com::sun::star::io::IOException,
159 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
160 : virtual void SAL_CALL setDataStream(
161 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
162 : throw ( ::com::sun::star::io::IOException,
163 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
164 : virtual void SAL_CALL setRawStream(
165 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
166 : throw ( ::com::sun::star::packages::EncryptionNotAllowedException,
167 : ::com::sun::star::packages::NoRawFormatException,
168 : ::com::sun::star::io::IOException,
169 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
170 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream()
171 : throw ( ::com::sun::star::io::IOException, ::com::sun::star::packages::NoEncryptionException,
172 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
173 :
174 : // XUnoTunnel
175 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
176 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 :
178 : // XPropertySet
179 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
180 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
181 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName )
182 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
183 :
184 : // XServiceInfo
185 : virtual OUString SAL_CALL getImplementationName( )
186 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
187 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
188 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
189 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
190 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
191 : };
192 : #endif
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|