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

Generated by: LCOV version 1.10