LCOV - code coverage report
Current view: top level - package/inc - ZipPackageStream.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 44 70.5 %
Date: 2012-08-25 Functions: 21 28 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 14 57.1 %

           Branch data     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 _ZIP_PACKAGE_STREAM_HXX
      20                 :            : #define _ZIP_PACKAGE_STREAM_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 <ZipPackageEntry.hxx>
      27                 :            : #include <rtl/ref.hxx>
      28                 :            : #include <cppuhelper/implbase2.hxx>
      29                 :            : 
      30                 :            : #include <EncryptionData.hxx>
      31                 :            : #include <mutexholder.hxx>
      32                 :            : 
      33                 :            : #define PACKAGE_STREAM_NOTSET           0
      34                 :            : #define PACKAGE_STREAM_PACKAGEMEMBER    1
      35                 :            : #define PACKAGE_STREAM_DETECT           2
      36                 :            : #define PACKAGE_STREAM_DATA             3
      37                 :            : #define PACKAGE_STREAM_RAW              4
      38                 :            : 
      39                 :            : class ZipPackage;
      40                 :            : struct ZipEntry;
      41                 :            : class ZipPackageStream : public cppu::ImplInheritanceHelper2
      42                 :            : <
      43                 :            :     ZipPackageEntry,
      44                 :            :     ::com::sun::star::io::XActiveDataSink,
      45                 :            :     ::com::sun::star::packages::XDataSinkEncrSupport
      46                 :            : >
      47                 :            : {
      48                 :            : protected:
      49                 :            :     com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
      50                 :            :     const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
      51                 :            :     ZipPackage          &rZipPackage;
      52                 :            :     sal_Bool            bToBeCompressed, bToBeEncrypted, bHaveOwnKey, 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                 :            : 
      67                 :            :     sal_Bool m_bHasSeekable;
      68                 :            : 
      69                 :            :     sal_Bool m_bCompressedIsSetFromOutside;
      70                 :            : 
      71                 :            :     sal_Bool m_bFromManifest;
      72                 :            : 
      73                 :            :     bool m_bUseWinEncoding;
      74                 :            : 
      75                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream();
      76                 :            : 
      77                 :            : public:
      78                 :        673 :     sal_Bool HasOwnKey () const  { return bHaveOwnKey;}
      79                 :       1338 :     sal_Bool IsToBeCompressed () const { return bToBeCompressed;}
      80                 :       1338 :     sal_Bool IsToBeEncrypted () const { return bToBeEncrypted;}
      81                 :       1494 :     sal_Bool IsEncrypted () const    { return bIsEncrypted;}
      82                 :      13368 :     sal_Bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
      83                 :            : 
      84                 :       3035 :     sal_Bool IsFromManifest() const { return m_bFromManifest; }
      85                 :       3035 :     void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; }
      86                 :            : 
      87                 :            :     ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false );
      88                 :            : 
      89                 :            :     ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false );
      90                 :            : 
      91                 :            :     sal_Int32 GetStartKeyGenID();
      92                 :            : 
      93                 :          0 :     const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const
      94                 :          0 :     { return m_xBaseEncryptionData->m_aInitVector;}
      95                 :          0 :     const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const
      96                 :          0 :     { return m_xBaseEncryptionData->m_aDigest;}
      97                 :          0 :     const com::sun::star::uno::Sequence < sal_Int8 > getSalt () const
      98                 :          0 :     { return m_xBaseEncryptionData->m_aSalt;}
      99                 :          0 :     sal_Int32 getIterationCount () const
     100                 :          0 :     { return m_xBaseEncryptionData->m_nIterationCount;}
     101                 :       1338 :     sal_Int32 getSize () const
     102                 :       1338 :     { return aEntry.nSize;}
     103                 :            : 
     104                 :       2614 :     sal_uInt8 GetStreamMode() const { return m_nStreamMode; }
     105                 :          0 :     sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; }
     106                 :          0 :     sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; }
     107                 :            :     sal_Int32 GetEncryptionAlgorithm() const;
     108                 :            :     sal_Int32 GetBlockSize() const;
     109                 :            : 
     110                 :         30 :     void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;}
     111                 :         30 :     void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;}
     112                 :         30 :     void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
     113                 :         30 :     void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
     114                 :         30 :     void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
     115                 :         30 :     void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
     116                 :         60 :     void SetToBeEncrypted (sal_Bool bNewValue)
     117                 :            :     {
     118                 :         60 :         bToBeEncrypted  = bNewValue;
     119 [ +  - ][ +  + ]:         60 :         if ( bToBeEncrypted && !m_xBaseEncryptionData.is())
                 [ +  + ]
     120         [ +  - ]:         30 :             m_xBaseEncryptionData = new BaseEncryptionData;
     121 [ -  + ][ #  # ]:         30 :         else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() )
                 [ -  + ]
     122                 :          0 :             m_xBaseEncryptionData.clear();
     123                 :         60 :     }
     124                 :            :     void SetPackageMember (sal_Bool bNewValue);
     125                 :            : 
     126                 :          0 :     void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey )
     127                 :          0 :     { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); }
     128                 :         30 :     void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector )
     129                 :         30 :     { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
     130                 :         30 :     void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt )
     131                 :         30 :     { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
     132                 :         30 :     void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest )
     133                 :         30 :     { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
     134                 :         30 :     void setIterationCount (const sal_Int32 nNewCount)
     135                 :         30 :     { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
     136                 :            :     void setSize (const sal_Int32 nNewSize);
     137                 :            : 
     138                 :       1106 :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; }
     139                 :            : 
     140                 :            :     void CloseOwnStreamIfAny();
     141                 :            : 
     142                 :            :     ZipPackageStream ( ZipPackage & rNewPackage,
     143                 :            :                         const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& xFactory,
     144                 :            :                         sal_Bool bAllowRemoveOnInsert );
     145                 :            :     virtual ~ZipPackageStream( void );
     146                 :            : 
     147                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
     148                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream(
     149                 :            :                                                                                     sal_Bool bAddHeaderForEncr );
     150                 :            : 
     151                 :            :     sal_Bool ParsePackageRawStream();
     152                 :            : 
     153                 :            :     void setZipEntryOnLoading( const ZipEntry &rInEntry);
     154                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
     155                 :            :         throw(::com::sun::star::uno::RuntimeException);
     156                 :            : 
     157                 :            :     static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId();
     158                 :            : 
     159                 :            :     // XActiveDataSink
     160                 :            :     virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
     161                 :            :         throw(::com::sun::star::uno::RuntimeException);
     162                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(  )
     163                 :            :         throw(::com::sun::star::uno::RuntimeException);
     164                 :            : 
     165                 :            :     // XDataSinkEncrSupport
     166                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream()
     167                 :            :         throw ( ::com::sun::star::packages::WrongPasswordException,
     168                 :            :                 ::com::sun::star::io::IOException,
     169                 :            :                 ::com::sun::star::uno::RuntimeException );
     170                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream()
     171                 :            :         throw ( ::com::sun::star::packages::NoEncryptionException,
     172                 :            :                 ::com::sun::star::io::IOException,
     173                 :            :                 ::com::sun::star::uno::RuntimeException );
     174                 :            :     virtual void SAL_CALL setDataStream(
     175                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
     176                 :            :         throw ( ::com::sun::star::io::IOException,
     177                 :            :                 ::com::sun::star::uno::RuntimeException );
     178                 :            :     virtual void SAL_CALL setRawStream(
     179                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
     180                 :            :         throw ( ::com::sun::star::packages::EncryptionNotAllowedException,
     181                 :            :                 ::com::sun::star::packages::NoRawFormatException,
     182                 :            :                 ::com::sun::star::io::IOException,
     183                 :            :                 ::com::sun::star::uno::RuntimeException );
     184                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream()
     185                 :            :         throw ( ::com::sun::star::io::IOException,
     186                 :            :                 ::com::sun::star::uno::RuntimeException );
     187                 :            : 
     188                 :            :     // XUnoTunnel
     189                 :            :     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
     190                 :            :         throw(::com::sun::star::uno::RuntimeException);
     191                 :            : 
     192                 :            :     // XPropertySet
     193                 :            :     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
     194                 :            :         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);
     195                 :            :     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName )
     196                 :            :         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     197                 :            : 
     198                 :            :     // XServiceInfo
     199                 :            :     virtual ::rtl::OUString SAL_CALL getImplementationName(  )
     200                 :            :         throw (::com::sun::star::uno::RuntimeException);
     201                 :            :     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
     202                 :            :         throw (::com::sun::star::uno::RuntimeException);
     203                 :            :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
     204                 :            :         throw (::com::sun::star::uno::RuntimeException);
     205                 :            : };
     206                 :            : #endif
     207                 :            : 
     208                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10