1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _XUNBUFFERED_STREAM_HXX
24 #define _XUNBUFFERED_STREAM_HXX
25 
26 #include <com/sun/star/io/XOutputStream.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <com/sun/star/io/XSeekable.hpp>
29 #include <com/sun/star/io/XInputStream.hpp>
30 #include <com/sun/star/io/XOutputStream.hpp>
31 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
32 
33 #include <cppuhelper/implbase1.hxx>
34 #include <rtl/ref.hxx>
35 #include <Inflater.hxx>
36 #include <ZipEntry.hxx>
37 #include <CRC32.hxx>
38 #include <mutexholder.hxx>
39 
40 #define UNBUFF_STREAM_DATA			0
41 #define UNBUFF_STREAM_RAW			1
42 #define UNBUFF_STREAM_WRAPPEDRAW	2
43 
44 class EncryptionData;
45 class XUnbufferedStream : public cppu::WeakImplHelper1
46 <
47 	com::sun::star::io::XInputStream
48 >
49 {
50 protected:
51     SotMutexHolderRef maMutexHolder;
52 
53 	com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream;
54 	com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek;
55 	com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader;
56 	ZipEntry maEntry;
57 	::rtl::Reference< EncryptionData > mxData;
58     sal_Int32 mnBlockSize;
59     ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
60 	Inflater maInflater;
61 	sal_Bool mbRawStream, mbWrappedRaw, mbFinished;
62 	sal_Int16 mnHeaderToRead;
63 	sal_Int64 mnZipCurrent, mnZipEnd, mnZipSize, mnMyCurrent;
64 	CRC32 maCRC;
65 	sal_Bool mbCheckCRC;
66 
67 public:
68 	XUnbufferedStream(
69                  const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
70                  SotMutexHolderRef aMutexHolder,
71                  ZipEntry & rEntry,
72 				 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream,
73 				 const ::rtl::Reference< EncryptionData >& rData,
74 				 sal_Int8 nStreamMode,
75 				 sal_Bool bIsEncrypted,
76 				 const ::rtl::OUString& aMediaType,
77 				 sal_Bool bRecoveryMode );
78 
79 	// allows to read package raw stream
80 	XUnbufferedStream(
81                  const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
82                  const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream,
83 				 const ::rtl::Reference< EncryptionData >& rData );
84 
85 
86 	virtual ~XUnbufferedStream();
87 
88 	// XInputStream
89     virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
90 		throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
91     virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
92 		throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
93     virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
94 		throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
95     virtual sal_Int32 SAL_CALL available(  )
96 		throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
97     virtual void SAL_CALL closeInput(  )
98 		throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
99 	// XSeekable
100 	/*
101     virtual void SAL_CALL seek( sal_Int64 location )
102 		throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
103     virtual sal_Int64 SAL_CALL getPosition(  )
104 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
105     virtual sal_Int64 SAL_CALL getLength(  )
106 		throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
107 	*/
108 };
109 #endif
110