LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/package/inc - ZipFile.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1 100.0 %
Date: 2013-07-09 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          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_FILE_HXX
      20             : #define _ZIP_FILE_HXX
      21             : 
      22             : #include <com/sun/star/packages/zip/ZipException.hpp>
      23             : #include <com/sun/star/packages/zip/ZipIOException.hpp>
      24             : #include <com/sun/star/packages/NoEncryptionException.hpp>
      25             : #include <com/sun/star/packages/WrongPasswordException.hpp>
      26             : #include <com/sun/star/xml/crypto/XCipherContext.hpp>
      27             : #include <com/sun/star/xml/crypto/XDigestContext.hpp>
      28             : 
      29             : #include <package/Inflater.hxx>
      30             : #include <ByteGrabber.hxx>
      31             : #include <HashMaps.hxx>
      32             : #include <EncryptionData.hxx>
      33             : 
      34             : #include <mutexholder.hxx>
      35             : 
      36             : namespace com { namespace sun { namespace star {
      37             :     namespace uno { class XComponentContext; }
      38             :     namespace ucb  { class XProgressHandler; }
      39             : } } }
      40             : namespace rtl
      41             : {
      42             :     template < class T > class Reference;
      43             : }
      44             : 
      45             : /*
      46             :  * We impose arbitrary but reasonable limit on ZIP files.
      47             :  */
      48             : 
      49             : #define ZIP_MAXNAMELEN 512
      50             : #define ZIP_MAXEXTRA 256
      51             : #define ZIP_MAXENTRIES (0x10000 - 2)
      52             : 
      53             : class ZipEnumeration;
      54             : 
      55             : class ZipFile
      56             : {
      57             : protected:
      58             :     ::osl::Mutex    m_aMutex;
      59             : 
      60             :     OUString sComment;       /* zip file comment */
      61             :     EntryHash       aEntries;
      62             :     ByteGrabber     aGrabber;
      63             :     ZipUtils::Inflater aInflater;
      64             :     com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
      65             :     com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
      66             :     const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
      67             :     ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
      68             : 
      69             :     sal_Bool bRecoveryMode;
      70             : 
      71             :     com::sun::star::uno::Reference < com::sun::star::io::XInputStream >  createMemoryStream(
      72             :             ZipEntry & rEntry,
      73             :             const ::rtl::Reference < EncryptionData > &rData,
      74             :             sal_Bool bRawStream,
      75             :             sal_Bool bDecrypt );
      76             : 
      77             :     com::sun::star::uno::Reference < com::sun::star::io::XInputStream >  createFileStream(
      78             :             ZipEntry & rEntry,
      79             :             const ::rtl::Reference < EncryptionData > &rData,
      80             :             sal_Bool bRawStream,
      81             :             sal_Bool bDecrypt );
      82             : 
      83             :     // aMediaType parameter is used only for raw stream header creation
      84             :     com::sun::star::uno::Reference < com::sun::star::io::XInputStream >  createUnbufferedStream(
      85             :             SotMutexHolderRef aMutexHolder,
      86             :             ZipEntry & rEntry,
      87             :             const ::rtl::Reference < EncryptionData > &rData,
      88             :             sal_Int8 nStreamMode,
      89             :             sal_Bool bDecrypt,
      90             :             OUString aMediaType = OUString() );
      91             : 
      92             :     sal_Bool hasValidPassword ( ZipEntry & rEntry, const rtl::Reference < EncryptionData > &rData );
      93             : 
      94             :     sal_Bool checkSizeAndCRC( const ZipEntry& aEntry );
      95             : 
      96             :     sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize );
      97             : 
      98             :     void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC );
      99             : 
     100             : public:
     101             : 
     102             :     ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
     103             :              const com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > &rxContext,
     104             :              sal_Bool bInitialise
     105             :              )
     106             :         throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
     107             : 
     108             :     ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
     109             :              const com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > &rxContext,
     110             :              sal_Bool bInitialise,
     111             :              sal_Bool bForceRecover,
     112             :              ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgress
     113             :              )
     114             :         throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
     115             : 
     116             :     ~ZipFile();
     117             : 
     118       27518 :     EntryHash& GetEntryHash() { return aEntries; }
     119             : 
     120             :     void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream );
     121             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData(
     122             :             ZipEntry& rEntry,
     123             :             const ::rtl::Reference < EncryptionData > &rData,
     124             :             sal_Bool bDecrypt,
     125             :             SotMutexHolderRef aMutexHolder )
     126             :         throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
     127             : 
     128             : 
     129             :     static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
     130             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xArgContext,
     131             :             const ::rtl::Reference< EncryptionData >& xEncryptionData );
     132             : 
     133             :     static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher(
     134             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xArgContext,
     135             :             const ::rtl::Reference< EncryptionData >& xEncryptionData,
     136             :             bool bEncrypt );
     137             : 
     138             :     static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
     139             :                                     sal_Int64 nSize,
     140             :                                     const OUString& aMediaType,
     141             :                                     sal_Int8 * & pHeader );
     142             : 
     143             :     static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData,
     144             :                                      sal_Int32 &rEncAlgorithm,
     145             :                                      sal_Int32 &rChecksumAlgorithm,
     146             :                                      sal_Int32 &rDerivedKeySize,
     147             :                                      sal_Int32 &rStartKeyGenID,
     148             :                                      sal_Int32 &rSize,
     149             :                                      OUString& aMediaType,
     150             :                                      const ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream );
     151             : 
     152             :     static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream(
     153             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
     154             :             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream,
     155             :             const ::rtl::Reference < EncryptionData > &rData )
     156             :         throw ( ::com::sun::star::packages::WrongPasswordException,
     157             :                 ::com::sun::star::packages::zip::ZipIOException,
     158             :                 ::com::sun::star::uno::RuntimeException );
     159             : 
     160             :     static sal_Bool StaticHasValidPassword (
     161             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
     162             :             const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer,
     163             :             const ::rtl::Reference < EncryptionData > &rData );
     164             : 
     165             : 
     166             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(
     167             :             ZipEntry& rEntry,
     168             :             const ::rtl::Reference < EncryptionData > &rData,
     169             :             sal_Bool bDecrypt,
     170             :             SotMutexHolderRef aMutexHolder )
     171             :         throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
     172             : 
     173             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream(
     174             :             ZipEntry& rEntry,
     175             :             const ::rtl::Reference < EncryptionData > &rData,
     176             :             sal_Bool bDecrypt,
     177             :             SotMutexHolderRef aMutexHolder )
     178             :         throw ( ::com::sun::star::packages::WrongPasswordException,
     179             :                 ::com::sun::star::io::IOException,
     180             :                 ::com::sun::star::packages::zip::ZipException,
     181             :                 ::com::sun::star::uno::RuntimeException );
     182             : 
     183             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream(
     184             :             ZipEntry& rEntry,
     185             :             const ::rtl::Reference < EncryptionData > &rData,
     186             :             const OUString& aMediaType,
     187             :             SotMutexHolderRef aMutexHolder )
     188             :         throw ( ::com::sun::star::packages::NoEncryptionException,
     189             :                 ::com::sun::star::io::IOException,
     190             :                 ::com::sun::star::packages::zip::ZipException,
     191             :                 ::com::sun::star::uno::RuntimeException );
     192             : 
     193             :     ZipEnumeration * SAL_CALL entries(  );
     194             : protected:
     195             :     sal_Bool        readLOC ( ZipEntry &rEntry)
     196             :         throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
     197             :     sal_Int32       readCEN()
     198             :         throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
     199             :     sal_Int32       findEND()
     200             :         throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
     201             :     sal_Int32       recover()
     202             :         throw(::com::sun::star::io::IOException, com::sun::star::packages::zip::ZipException, com::sun::star::uno::RuntimeException);
     203             : 
     204             : };
     205             : 
     206             : #endif
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10