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

Generated by: LCOV version 1.11