LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/inc - xistream.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 14 50.0 %
Date: 2012-12-27 Functions: 7 15 46.7 %
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             : 
      20             : #ifndef SC_XISTREAM_HXX
      21             : #define SC_XISTREAM_HXX
      22             : 
      23             : #include <comphelper/docpasswordhelper.hxx>
      24             : #include <filter/msfilter/mscodec.hxx>
      25             : #include <boost/shared_ptr.hpp>
      26             : #include "xlstream.hxx"
      27             : #include "xlconst.hxx"
      28             : 
      29             : class XclImpRoot;
      30             : 
      31             : /* ============================================================================
      32             : Input stream class for Excel import
      33             : - CONTINUE record handling
      34             : - Decryption
      35             : ============================================================================ */
      36             : 
      37             : // ============================================================================
      38             : // Decryption
      39             : // ============================================================================
      40             : 
      41             : class XclImpDecrypter;
      42             : typedef boost::shared_ptr< XclImpDecrypter > XclImpDecrypterRef;
      43             : 
      44             : /** Base class for BIFF stream decryption. */
      45             : class XclImpDecrypter : public ::comphelper::IDocPasswordVerifier
      46             : {
      47             : public:
      48             :     explicit            XclImpDecrypter();
      49             :     virtual             ~XclImpDecrypter();
      50             : 
      51             :     /** Returns the current error code of the decrypter. */
      52           0 :     inline ErrCode      GetError() const { return mnError; }
      53             :     /** Returns true, if the decoder has been initialized correctly. */
      54           0 :     inline bool         IsValid() const { return mnError == ERRCODE_NONE; }
      55             : 
      56             :     /** Creates a (ref-counted) copy of this decrypter object. */
      57             :     XclImpDecrypterRef  Clone() const;
      58             : 
      59             :     /** Implementation of the ::comphelper::IDocPasswordVerifier interface */
      60             :     virtual ::comphelper::DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData );
      61             :     virtual ::comphelper::DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData );
      62             : 
      63             :     /** Updates the decrypter on start of a new record or after seeking stream. */
      64             :     void                Update( SvStream& rStrm, sal_uInt16 nRecSize );
      65             :     /** Reads and decrypts nBytes bytes and stores data into the existing(!) buffer pData.
      66             :         @return  Count of bytes really read. */
      67             :     sal_uInt16          Read( SvStream& rStrm, void* pData, sal_uInt16 nBytes );
      68             : 
      69             : protected:
      70             :     /** Protected copy c'tor for OnClone(). */
      71             :     explicit            XclImpDecrypter( const XclImpDecrypter& rSrc );
      72             : 
      73             : private:
      74             :     /** Implementation of cloning this object. */
      75             :     virtual XclImpDecrypter* OnClone() const = 0;
      76             :     /** Derived classes implement password verification and initialization of
      77             :         the decoder. */
      78             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
      79             :         OnVerifyPassword( const ::rtl::OUString& rPassword ) = 0;
      80             :     virtual bool OnVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) = 0;
      81             : 
      82             :     /** Implementation of updating the decrypter. */
      83             :     virtual void        OnUpdate( sal_Size nOldStrmPos, sal_Size nNewStrmPos, sal_uInt16 nRecSize ) = 0;
      84             :     /** Implementation of the decryption. */
      85             :     virtual sal_uInt16  OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes ) = 0;
      86             : 
      87             : private:
      88             :     ErrCode             mnError;        /// Decrypter error code.
      89             :     sal_Size            mnOldPos;       /// Last known stream position.
      90             :     sal_uInt16          mnRecSize;      /// Current record size.
      91             : };
      92             : 
      93             : // ----------------------------------------------------------------------------
      94             : 
      95             : /** Decrypts BIFF5 stream contents. */
      96           0 : class XclImpBiff5Decrypter : public XclImpDecrypter
      97             : {
      98             : public:
      99             :     explicit            XclImpBiff5Decrypter( sal_uInt16 nKey, sal_uInt16 nHash );
     100             : 
     101             : private:
     102             :     /** Private copy c'tor for OnClone(). */
     103             :     explicit            XclImpBiff5Decrypter( const XclImpBiff5Decrypter& rSrc );
     104             : 
     105             :     /** Implementation of cloning this object. */
     106             :     virtual XclImpBiff5Decrypter* OnClone() const;
     107             :     /** Implements password verification and initialization of the decoder. */
     108             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
     109             :         OnVerifyPassword( const ::rtl::OUString& rPassword );
     110             :     virtual bool OnVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData );
     111             :     /** Implementation of updating the decrypter. */
     112             :     virtual void        OnUpdate( sal_Size nOldStrmPos, sal_Size nNewStrmPos, sal_uInt16 nRecSize );
     113             :     /** Implementation of the decryption. */
     114             :     virtual sal_uInt16  OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes );
     115             : 
     116             : private:
     117             :     ::msfilter::MSCodec_XorXLS95 maCodec;       /// Crypto algorithm implementation.
     118             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
     119             :     sal_uInt16          mnKey;
     120             :     sal_uInt16          mnHash;
     121             : };
     122             : 
     123             : // ----------------------------------------------------------------------------
     124             : 
     125             : /** Decrypts BIFF8 stream contents using the given document identifier. */
     126           0 : class XclImpBiff8Decrypter : public XclImpDecrypter
     127             : {
     128             : public:
     129             :     explicit            XclImpBiff8Decrypter( sal_uInt8 pnSalt[ 16 ],
     130             :                             sal_uInt8 pnVerifier[ 16 ], sal_uInt8 pnVerifierHash[ 16 ] );
     131             : 
     132             : private:
     133             :     /** Private copy c'tor for OnClone(). */
     134             :     explicit            XclImpBiff8Decrypter( const XclImpBiff8Decrypter& rSrc );
     135             : 
     136             :     /** Implementation of cloning this object. */
     137             :     virtual XclImpBiff8Decrypter* OnClone() const;
     138             :     /** Implements password verification and initialization of the decoder. */
     139             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
     140             :         OnVerifyPassword( const ::rtl::OUString& rPassword );
     141             :     virtual bool OnVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData );
     142             :     /** Implementation of updating the decrypter. */
     143             :     virtual void        OnUpdate( sal_Size nOldStrmPos, sal_Size nNewStrmPos, sal_uInt16 nRecSize );
     144             :     /** Implementation of the decryption. */
     145             :     virtual sal_uInt16  OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes );
     146             : 
     147             :     /** Returns the block number corresponding to the passed stream position. */
     148             :     sal_uInt32          GetBlock( sal_Size nStrmPos ) const;
     149             :     /** Returns the block offset corresponding to the passed stream position. */
     150             :     sal_uInt16          GetOffset( sal_Size nStrmPos ) const;
     151             : 
     152             : private:
     153             :     ::msfilter::MSCodec_Std97 maCodec;       /// Crypto algorithm implementation.
     154             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
     155             :     ::std::vector< sal_uInt8 > maSalt;
     156             :     ::std::vector< sal_uInt8 > maVerifier;
     157             :     ::std::vector< sal_uInt8 > maVerifierHash;
     158             : };
     159             : 
     160             : // ============================================================================
     161             : // Stream
     162             : // ============================================================================
     163             : 
     164             : /** This class represents an Excel stream position.
     165             :     @descr  It contains the relevant data for a stream position inside of a record
     166             :     (including CONTINUE records). */
     167             : class XclImpStreamPos
     168             : {
     169             : public:
     170             :     /** Constructs an invalid stream position data object. */
     171             :     explicit            XclImpStreamPos();
     172             : 
     173             :     /** Sets the stream position data to the passed values. */
     174             :     void                Set( const SvStream& rStrm, sal_Size nNextPos, sal_Size nCurrSize,
     175             :                             sal_uInt16 nRawRecId, sal_uInt16 nRawRecSize, sal_uInt16 nRawRecLeft,
     176             :                             bool bValid );
     177             : 
     178             :     /** Writes the contained stream position data to the given variables. */
     179             :     void                Get( SvStream& rStrm, sal_Size& rnNextPos, sal_Size& rnCurrSize,
     180             :                             sal_uInt16& rnRawRecId, sal_uInt16& rnRawRecSize, sal_uInt16& rnRawRecLeft,
     181             :                             bool& rbValid ) const;
     182             : 
     183             :     /** Returns the stored stream position. */
     184           0 :     inline sal_Size     GetPos() const { return mnPos; }
     185             : 
     186             : private:
     187             :     sal_Size            mnPos;          /// Absolute position of the stream.
     188             :     sal_Size            mnNextPos;      /// Absolute position of next record.
     189             :     sal_Size            mnCurrSize;     /// Current calculated size of the record.
     190             :     sal_uInt16          mnRawRecId;     /// Current raw record ID (including CONTINUEs).
     191             :     sal_uInt16          mnRawRecSize;   /// Current raw record size (without following CONTINUEs).
     192             :     sal_uInt16          mnRawRecLeft;   /// Bytes left in current raw record (without following CONTINUEs).
     193             :     bool                mbValid;        /// Read state: false = record overread.
     194             : };
     195             : 
     196             : // ============================================================================
     197             : 
     198             : /** This class is used to import record oriented streams.
     199             :     @descr  An instance is constructed with an SvStream. The SvStream stream is
     200             :     reset to its start while constructing this stream.
     201             : 
     202             :     To start reading a record call StartNextRecord(). Now it is possible to
     203             :     read all contents of the record using operator>>() or any of the Read***()
     204             :     functions. If some data exceeds the record size limit, the stream looks for
     205             :     a following CONTINUE record and jumps automatically to it. It is NOT
     206             :     allowed that an atomic data type is split into two records (i.e. 4 bytes of
     207             :     a double in one record and the other 4 bytes in a following CONTINUE).
     208             : 
     209             :     Trying to read over the record limits results in a stream error. The
     210             :     IsValid() function indicates that with returning false. From now on it is
     211             :     undefined what data the read functions will return. The error state will be
     212             :     reset, if the record is reset (with the method ResetRecord()) or if the
     213             :     next record is started.
     214             : 
     215             :     To switch off the automatic lookup of CONTINUE records, use ResetRecord()
     216             :     with false parameter. This is useful i.e. on import of Escher objects,
     217             :     where sometimes solely CONTINUE records will occur. The automatic lookup
     218             :     keeps switched off until the method ResetRecord() is called with parameter
     219             :     true. All other settings done on the stream (i.e. alternative CONTINUE
     220             :     record identifier, enabled decryption, NUL substitution character) will be
     221             :     reset to default values, if a new record is started.
     222             : 
     223             :     The import stream supports decrypting the stream data. The contents of a
     224             :     record (not the record header) will be encrypted by Excel if the file has
     225             :     been stored with password protection. The functions SetDecrypter(),
     226             :     EnableDecryption(), and DisableDecryption() control the usage of the
     227             :     decryption algorithms. SetDecrypter() sets a new decryption algorithm and
     228             :     initially enables it. DisableDecryption() may be used to stop the usage of
     229             :     the decryption temporarily (sometimes record contents are never encrypted,
     230             :     i.e. all BOF records or the stream position in BOUNDSHEET). Decryption will
     231             :     be reenabled automatically, if a new record is started with the function
     232             :     StartNextRecord().
     233             : 
     234             :     It is possible to store several stream positions inside a record (including
     235             :     its CONTINUE records). The positions are stored on a stack, which can be
     236             :     controlled with the functions PushPosition(), PopPosition() and
     237             :     RejectPosition(). The stack will be cleared whenever a new record is
     238             :     started with the function StartNextRecord().
     239             : 
     240             :     Additionally a single global stream position can be stored which keeps
     241             :     valid during the whole import process (methods StoreGlobalPosition(),
     242             :     SeekGlobalPosition() and DeleteGlobalPosition()). This is the only way to
     243             :     jump back to a previous record (that is a real jump without return).
     244             : */
     245             : class XclImpStream
     246             : {
     247             : public:
     248             :     /** Detects the BIFF version of the passed workbook stream. */
     249             :     static XclBiff      DetectBiffVersion( SvStream& rStrm );
     250             : 
     251             :     /** Constructs the Excel record import stream using a TOOLS stream object.
     252             :         @param rInStrm  The system input stream. Will be set to its start position.
     253             :         Must exist as long as this object exists.
     254             :         @param bContLookup  Automatic CONTINUE lookup on/off. */
     255             :     explicit            XclImpStream(
     256             :                             SvStream& rInStrm,
     257             :                             const XclImpRoot& rRoot,
     258             :                             bool bContLookup = true );
     259             : 
     260             :                         ~XclImpStream();
     261             : 
     262             :     /** Returns the filter root data. */
     263        2766 :     inline const XclImpRoot& GetRoot() const { return mrRoot; }
     264             : 
     265             :     /** Sets stream pointer to the start of the next record content.
     266             :         @descr  Ignores all CONTINUE records of the current record, if automatic
     267             :         CONTINUE usage is switched on.
     268             :         @return  false = no record found (end of stream). */
     269             :     bool                StartNextRecord();
     270             :     /** Sets stream pointer to the start of the record content for the record
     271             :         at the passed absolute stream position.
     272             :         @return  false = no record found (end of stream). */
     273             :     bool                StartNextRecord( sal_Size nNextRecPos );
     274             :     /** Sets stream pointer to begin of record content.
     275             :         @param bContLookup  Automatic CONTINUE lookup on/off. In difference
     276             :         to other stream settings, this setting is persistent until next call of
     277             :         this function (because it is wanted to receive the next CONTINUE
     278             :         records separately).
     279             :         @param nAltContId  Sets an alternative record ID for content
     280             :         continuation. This value is reset automatically when a new record is
     281             :         started with StartNextRecord(). */
     282             :     void                ResetRecord( bool bContLookup,
     283             :                             sal_uInt16 nAltContId = EXC_ID_UNKNOWN );
     284             :     /** Sets stream pointer before current record and invalidates stream.
     285             :         @descr  The next call to StartNextRecord() will start again the current
     286             :         record. This can be used in situations where a loop or a function
     287             :         leaves on a specific record, but the parent context expects to start
     288             :         this record by itself. The stream is invalid as long as the first
     289             :         record has not been started (it is not allowed to call any other stream
     290             :         operation then). */
     291             :     void                RewindRecord();
     292             : 
     293             :     /** Enables decryption of record contents for the rest of the stream. */
     294             :     void                SetDecrypter( XclImpDecrypterRef xDecrypter );
     295             :     /** Sets decrypter from another stream. */
     296             :     void                CopyDecrypterFrom( const XclImpStream& rStrm );
     297             :     /** Returns true, if a valid decrypter is set at the stream. */
     298             :     bool                HasValidDecrypter() const;
     299             :     /** Switches usage of current decryption algorithm on/off.
     300             :         @descr  Encryption is re-enabled automatically, if a new record is
     301             :         started using the function StartNextRecord(). */
     302             :     void                EnableDecryption( bool bEnable = true );
     303             :     /** Switches usage of current decryption algorithm off.
     304             :         @descr  This is a record-local setting. The function StartNextRecord()
     305             :         always enables decryption. */
     306         171 :     inline void         DisableDecryption() { EnableDecryption( false ); }
     307             : 
     308             :     /** Pushes current position on user position stack.
     309             :         @descr  This stack is emptied when starting a new record with
     310             :         StartNextRecord(). The decryption state (enabled/disabled) is not
     311             :         pushed onto the stack. */
     312             :     void                PushPosition();
     313             :     /** Seeks to last position from user position stack.
     314             :         @descr  This position will be removed from the stack. */
     315             :     void                PopPosition();
     316             : 
     317             :     /** Stores current position. This position keeps valid in all records. */
     318             :     void                StoreGlobalPosition();
     319             :     /** Seeks to the stored global user position. */
     320             :     void                SeekGlobalPosition();
     321             :     /** Invalidates global user position. */
     322             :     inline void         DeleteGlobalPosition() { mbHasGlobPos = false; }
     323             : 
     324             :     /** Returns record reading state: false = record overread. */
     325      150657 :     inline bool         IsValid() const { return mbValid; }
     326             :     /** Returns the current record ID. */
     327       90560 :     inline sal_uInt16   GetRecId() const { return mnRecId; }
     328             :     /** Returns the position inside of the whole record content. */
     329             :     sal_Size            GetRecPos() const;
     330             :     /** Returns the data size of the whole record without record headers. */
     331             :     sal_Size            GetRecSize();
     332             :     /** Returns remaining data size of the whole record without record headers. */
     333             :     sal_Size            GetRecLeft();
     334             :     /** Returns the record ID of the following record. */
     335             :     sal_uInt16          GetNextRecId();
     336             : 
     337             :     sal_uInt16          PeekRecId( sal_Size nPos );
     338             : 
     339             :     XclImpStream&       operator>>( sal_Int8& rnValue );
     340             :     XclImpStream&       operator>>( sal_uInt8& rnValue );
     341             :     XclImpStream&       operator>>( sal_Int16& rnValue );
     342             :     XclImpStream&       operator>>( sal_uInt16& rnValue );
     343             :     XclImpStream&       operator>>( sal_Int32& rnValue );
     344             :     XclImpStream&       operator>>( sal_uInt32& rnValue );
     345             :     XclImpStream&       operator>>( float& rfValue );
     346             :     XclImpStream&       operator>>( double& rfValue );
     347             : 
     348             :     sal_uInt8           ReaduInt8();
     349             :     sal_Int16           ReadInt16();
     350             :     sal_uInt16          ReaduInt16();
     351             :     sal_Int32           ReadInt32();
     352             :     sal_uInt32          ReaduInt32();
     353             :     double              ReadDouble();
     354             : 
     355             :     /** Reads nBytes bytes to the existing(!) buffer pData.
     356             :         @return  Count of bytes really read. */
     357             :     sal_Size            Read( void* pData, sal_Size nBytes );
     358             :     /** Copies nBytes bytes to rOutStrm.
     359             :         @return  Count of bytes really written. */
     360             :     sal_Size            CopyToStream( SvStream& rOutStrm, sal_Size nBytes );
     361             : 
     362             :     /** Copies the entire record to rOutStrm. The current record position keeps unchanged.
     363             :         @return  Count of bytes really written. */
     364             :     sal_Size            CopyRecordToStream( SvStream& rOutStrm );
     365             : 
     366             :     /** Seeks absolute in record content to the specified position.
     367             :         @descr  The value 0 means start of record, independent from physical stream position. */
     368             :     void                Seek( sal_Size nPos );
     369             :     /** Seeks forward inside the current record. */
     370             :     void                Ignore( sal_Size nBytes );
     371             : 
     372             :     // *** special string functions *** ---------------------------------------
     373             : 
     374             :     // *** read/ignore unicode strings *** ------------------------------------
     375             :     /*  - look for CONTINUE records even if CONTINUE handling disabled
     376             :           (only if inside of a CONTINUE record - for TXO import)
     377             :         - no overread assertions (for Applix wrong string length export bug)
     378             : 
     379             :         structure of an Excel unicode string:
     380             :         (1) 2 byte character count
     381             :         (2) 1 byte flags (16-bit-characters, rich string, far east string)
     382             :         (3) [2 byte rich string format run count]
     383             :         (4) [4 byte far east data size]
     384             :         (5) character array
     385             :         (6) [4 * (rich string format run count) byte]
     386             :         (7) [(far east data size) byte]
     387             :         header = (1), (2)
     388             :         ext. header = (3), (4)
     389             :         ext. data = (6), (7)
     390             :      */
     391             : 
     392             :     /** Reads ext. header, detects 8/16 bit mode, sets all ext. info.
     393             :         @return  Total size of ext. data. */
     394             :     sal_Size            ReadUniStringExtHeader(
     395             :                             bool& rb16Bit, bool& rbRich, bool& rbFareast,
     396             :                             sal_uInt16& rnFormatRuns, sal_uInt32& rnExtInf, sal_uInt8 nFlags );
     397             :     /** Seeks to begin of character array, detects 8/16 bit mode.
     398             :         @return  Total size of ext. data. */
     399             :     sal_Size            ReadUniStringExtHeader( bool& rb16Bit, sal_uInt8 nFlags );
     400             : 
     401             :     /** Sets a replacement character for NUL characters.
     402             :         @descr  NUL characters must be replaced, because Tools strings cannot
     403             :         handle them. The substitution character is reset to '?' automatically,
     404             :         if a new record is started using the function StartNextRecord().
     405             :         @param cNulSubst  The character to use for NUL replacement. It is
     406             :         possible to specify NUL here. in this case strings are terminated when
     407             :         the first NUL occurs during string import. */
     408       81182 :     inline void         SetNulSubstChar( sal_Unicode cNulSubst = '?' ) { mcNulSubst = cNulSubst; }
     409             : 
     410             :     /** Reads nChars characters and returns the string. */
     411             :     String              ReadRawUniString( sal_uInt16 nChars, bool b16Bit );
     412             :     /** Reads ext. header, nChar characters, ext. data and returns the string. */
     413             :     String              ReadUniString( sal_uInt16 nChars, sal_uInt8 nFlags );
     414             :     /** Reads 8 bit flags, ext. header, nChar characters, ext. data and returns the string. */
     415             :     String              ReadUniString( sal_uInt16 nChars );
     416             :     /** Reads 16 bit character count, 8 bit flags, ext. header, character array,
     417             :         ext. data and returns the string. */
     418             :     String              ReadUniString();
     419             : 
     420             :     /** Ignores nChars characters. */
     421             :     void                IgnoreRawUniString( sal_uInt16 nChars, bool b16Bit );
     422             :     /** Ignores ext. header, nChar characters, ext. data. */
     423             :     void                IgnoreUniString( sal_uInt16 nChars, sal_uInt8 nFlags );
     424             :     /** Ignores 8 bit flags, ext. header, nChar characters, ext. data. */
     425             :     void                IgnoreUniString( sal_uInt16 nChars );
     426             : 
     427             :     // *** read/ignore 8-bit-strings, store in String *** ---------------------
     428             : 
     429             :     /** Reads nChar byte characters and returns the string. */
     430             :     String              ReadRawByteString( sal_uInt16 nChars );
     431             :     /** Reads 8/16 bit string length, character array and returns the string. */
     432             :     String              ReadByteString( bool b16BitLen );
     433             : 
     434             :     // *** SvStream functions *** ---------------------------------------------
     435             : 
     436             :     /** Returns the absolute stream position. */
     437       33214 :     inline sal_Size     GetSvStreamPos() const { return mrStrm.Tell(); }
     438             :     /** Returns the stream size. */
     439          20 :     inline sal_Size     GetSvStreamSize() const { return mnStreamSize; }
     440             : 
     441             :     /** Stores current stream position into rPos. */
     442             :     void                StorePosition( XclImpStreamPos& rPos );
     443             :     /** Restores stream position contained in rPos. */
     444             :     void                RestorePosition( const XclImpStreamPos& rPos );
     445             : 
     446             : private:
     447             :     /** Seeks to next raw record header and reads record ID and size.
     448             :         @descr  This is a "raw" function, means that stream members are
     449             :         inconsistent after return. Does only change mnRawRecId, mnRawRecSize,
     450             :         and the base stream position, but no other members.
     451             :         @return  false = No record header found (end of stream). */
     452             :     bool                ReadNextRawRecHeader();
     453             : 
     454             :     /** Initializes the decrypter to read a new record. */
     455             :     void                SetupDecrypter();
     456             :     /** Initializes all members after base stream has been seeked to new raw record. */
     457             :     void                SetupRawRecord();
     458             :     /** Initializes all members after base stream has been seeked to new record. */
     459             :     void                SetupRecord();
     460             : 
     461             :     /** Returns true, if the passed ID is real or alternative continuation record ID. */
     462             :     bool                IsContinueId( sal_uInt16 nRecId ) const;
     463             : 
     464             :     /** Goes to start of the next CONTINUE record.
     465             :         @descr  Stream must be located at the end of a raw record, and handling
     466             :         of CONTINUE records must be enabled.
     467             :         @return  Copy of mbValid. */
     468             :     bool                JumpToNextContinue();
     469             :     /** Goes to start of the next CONTINUE record while reading strings.
     470             :         @descr  Stream must be located at the end of a raw record. If reading
     471             :         has been started in a CONTINUE record, jumps to an existing following
     472             :         CONTINUE record, even if handling of CONTINUE records is disabled (This
     473             :         is a special handling for TXO string data). Reads additional Unicode
     474             :         flag byte at start of the new raw record and sets or resets rb16Bit.
     475             :         @return  Copy of mbValid. */
     476             :     bool                JumpToNextStringContinue( bool& rb16Bit );
     477             : 
     478             :     /** Ensures that reading nBytes bytes is possible with next stream access.
     479             :         @descr  Stream must be located at the end of a raw record, and handling
     480             :         of CONTINUE records must be enabled.
     481             :         @return  Copy of mbValid. */
     482             :     bool                EnsureRawReadSize( sal_uInt16 nBytes );
     483             :     /** Returns the maximum size of raw data possible to read in one block. */
     484             :     sal_uInt16          GetMaxRawReadSize( sal_Size nBytes ) const;
     485             : 
     486             :     /** Reads and decrypts nBytes bytes to the existing(!) buffer pData.
     487             :         @return  Count of bytes really read. */
     488             :     sal_uInt16          ReadRawData( void* pData, sal_uInt16 nBytes );
     489             : 
     490             :     /** Reads 8 bit/16 bit string length. */
     491           0 :     inline sal_uInt16   ReadByteStrLen( bool b16BitLen )
     492           0 :                             { return b16BitLen ? ReaduInt16() : ReaduInt8(); }
     493             : 
     494             : private:
     495             :     typedef ::std::vector< XclImpStreamPos > XclImpStreamPosStack;
     496             : 
     497             :     SvStream&           mrStrm;         /// Reference to the system input stream.
     498             :     const XclImpRoot&   mrRoot;         /// Filter root data.
     499             : 
     500             :     XclImpDecrypterRef  mxDecrypter;    /// Provides methods to decrypt data.
     501             : 
     502             :     XclImpStreamPos     maFirstRec;     /// Start position of current record.
     503             :     XclImpStreamPosStack maPosStack;    /// Stack for record positions.
     504             : 
     505             :     XclImpStreamPos     maGlobPos;      /// User defined position elsewhere in stream.
     506             :     sal_uInt16          mnGlobRecId;    /// Record ID for user defined position.
     507             :     bool                mbGlobValidRec; /// Was user position a valid record?
     508             :     bool                mbHasGlobPos;   /// Is user position defined?
     509             : 
     510             :     sal_Size            mnStreamSize;   /// Size of system stream.
     511             :     sal_Size            mnNextRecPos;   /// Start of next record header.
     512             :     sal_Size            mnCurrRecSize;  /// Helper for record position.
     513             :     sal_Size            mnComplRecSize; /// Size of complete record data (with CONTINUEs).
     514             :     bool                mbHasComplRec;  /// true = mnComplRecSize is valid.
     515             : 
     516             :     sal_uInt16          mnRecId;        /// Current record ID (not the CONTINUE ID).
     517             :     sal_uInt16          mnAltContId;    /// Alternative record ID for content continuation.
     518             : 
     519             :     sal_uInt16          mnRawRecId;     /// Current raw record ID (including CONTINUEs).
     520             :     sal_uInt16          mnRawRecSize;   /// Current raw record size (without following CONTINUEs).
     521             :     sal_uInt16          mnRawRecLeft;   /// Bytes left in current raw record (without following CONTINUEs).
     522             : 
     523             :     sal_Unicode         mcNulSubst;     /// Replacement for NUL characters.
     524             : 
     525             :     bool                mbCont;         /// Automatic CONTINUE lookup on/off.
     526             :     bool                mbUseDecr;      /// Usage of decryption.
     527             :     bool                mbValidRec;     /// false = No more records to read.
     528             :     bool                mbValid;        /// false = Record overread.
     529             : };
     530             : 
     531             : // ============================================================================
     532             : 
     533             : #endif
     534             : 
     535             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10