LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xistream.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 13 53.8 %
Date: 2012-08-25 Functions: 7 14 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 14 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      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                 :            : private:
     184                 :            :     sal_Size            mnPos;          /// Absolute position of the stream.
     185                 :            :     sal_Size            mnNextPos;      /// Absolute position of next record.
     186                 :            :     sal_Size            mnCurrSize;     /// Current calculated size of the record.
     187                 :            :     sal_uInt16          mnRawRecId;     /// Current raw record ID (including CONTINUEs).
     188                 :            :     sal_uInt16          mnRawRecSize;   /// Current raw record size (without following CONTINUEs).
     189                 :            :     sal_uInt16          mnRawRecLeft;   /// Bytes left in current raw record (without following CONTINUEs).
     190                 :            :     bool                mbValid;        /// Read state: false = record overread.
     191                 :            : };
     192                 :            : 
     193                 :            : // ============================================================================
     194                 :            : 
     195                 :            : /** This class is used to import record oriented streams.
     196                 :            :     @descr  An instance is constructed with an SvStream. The SvStream stream is
     197                 :            :     reset to its start while constructing this stream.
     198                 :            : 
     199                 :            :     To start reading a record call StartNextRecord(). Now it is possible to
     200                 :            :     read all contents of the record using operator>>() or any of the Read***()
     201                 :            :     functions. If some data exceeds the record size limit, the stream looks for
     202                 :            :     a following CONTINUE record and jumps automatically to it. It is NOT
     203                 :            :     allowed that an atomic data type is split into two records (i.e. 4 bytes of
     204                 :            :     a double in one record and the other 4 bytes in a following CONTINUE).
     205                 :            : 
     206                 :            :     Trying to read over the record limits results in a stream error. The
     207                 :            :     IsValid() function indicates that with returning false. From now on it is
     208                 :            :     undefined what data the read functions will return. The error state will be
     209                 :            :     reset, if the record is reset (with the method ResetRecord()) or if the
     210                 :            :     next record is started.
     211                 :            : 
     212                 :            :     To switch off the automatic lookup of CONTINUE records, use ResetRecord()
     213                 :            :     with false parameter. This is useful i.e. on import of Escher objects,
     214                 :            :     where sometimes solely CONTINUE records will occur. The automatic lookup
     215                 :            :     keeps switched off until the method ResetRecord() is called with parameter
     216                 :            :     true. All other settings done on the stream (i.e. alternative CONTINUE
     217                 :            :     record identifier, enabled decryption, NUL substitution character) will be
     218                 :            :     reset to default values, if a new record is started.
     219                 :            : 
     220                 :            :     The import stream supports decrypting the stream data. The contents of a
     221                 :            :     record (not the record header) will be encrypted by Excel if the file has
     222                 :            :     been stored with password protection. The functions SetDecrypter(),
     223                 :            :     EnableDecryption(), and DisableDecryption() control the usage of the
     224                 :            :     decryption algorithms. SetDecrypter() sets a new decryption algorithm and
     225                 :            :     initially enables it. DisableDecryption() may be used to stop the usage of
     226                 :            :     the decryption temporarily (sometimes record contents are never encrypted,
     227                 :            :     i.e. all BOF records or the stream position in BOUNDSHEET). Decryption will
     228                 :            :     be reenabled automatically, if a new record is started with the function
     229                 :            :     StartNextRecord().
     230                 :            : 
     231                 :            :     It is possible to store several stream positions inside a record (including
     232                 :            :     its CONTINUE records). The positions are stored on a stack, which can be
     233                 :            :     controlled with the functions PushPosition(), PopPosition() and
     234                 :            :     RejectPosition(). The stack will be cleared whenever a new record is
     235                 :            :     started with the function StartNextRecord().
     236                 :            : 
     237                 :            :     Additionally a single global stream position can be stored which keeps
     238                 :            :     valid during the whole import process (methods StoreGlobalPosition(),
     239                 :            :     SeekGlobalPosition() and DeleteGlobalPosition()). This is the only way to
     240                 :            :     jump back to a previous record (that is a real jump without return).
     241                 :            : */
     242                 :            : class XclImpStream
     243                 :            : {
     244                 :            : public:
     245                 :            :     /** Detects the BIFF version of the passed workbook stream. */
     246                 :            :     static XclBiff      DetectBiffVersion( SvStream& rStrm );
     247                 :            : 
     248                 :            :     /** Constructs the Excel record import stream using a TOOLS stream object.
     249                 :            :         @param rInStrm  The system input stream. Will be set to its start position.
     250                 :            :         Must exist as long as this object exists.
     251                 :            :         @param bContLookup  Automatic CONTINUE lookup on/off. */
     252                 :            :     explicit            XclImpStream(
     253                 :            :                             SvStream& rInStrm,
     254                 :            :                             const XclImpRoot& rRoot,
     255                 :            :                             bool bContLookup = true );
     256                 :            : 
     257                 :            :                         ~XclImpStream();
     258                 :            : 
     259                 :            :     /** Returns the filter root data. */
     260                 :       1148 :     inline const XclImpRoot& GetRoot() const { return mrRoot; }
     261                 :            : 
     262                 :            :     /** Sets stream pointer to the start of the next record content.
     263                 :            :         @descr  Ignores all CONTINUE records of the current record, if automatic
     264                 :            :         CONTINUE usage is switched on.
     265                 :            :         @return  false = no record found (end of stream). */
     266                 :            :     bool                StartNextRecord();
     267                 :            :     /** Sets stream pointer to the start of the record content for the record
     268                 :            :         at the passed absolute stream position.
     269                 :            :         @return  false = no record found (end of stream). */
     270                 :            :     bool                StartNextRecord( sal_Size nNextRecPos );
     271                 :            :     /** Sets stream pointer to begin of record content.
     272                 :            :         @param bContLookup  Automatic CONTINUE lookup on/off. In difference
     273                 :            :         to other stream settings, this setting is persistent until next call of
     274                 :            :         this function (because it is wanted to receive the next CONTINUE
     275                 :            :         records separately).
     276                 :            :         @param nAltContId  Sets an alternative record ID for content
     277                 :            :         continuation. This value is reset automatically when a new record is
     278                 :            :         started with StartNextRecord(). */
     279                 :            :     void                ResetRecord( bool bContLookup,
     280                 :            :                             sal_uInt16 nAltContId = EXC_ID_UNKNOWN );
     281                 :            : 
     282                 :            :     /** Enables decryption of record contents for the rest of the stream. */
     283                 :            :     void                SetDecrypter( XclImpDecrypterRef xDecrypter );
     284                 :            :     /** Sets decrypter from another stream. */
     285                 :            :     void                CopyDecrypterFrom( const XclImpStream& rStrm );
     286                 :            :     /** Returns true, if a valid decrypter is set at the stream. */
     287                 :            :     bool                HasValidDecrypter() const;
     288                 :            :     /** Switches usage of current decryption algorithm on/off.
     289                 :            :         @descr  Encryption is re-enabled automatically, if a new record is
     290                 :            :         started using the function StartNextRecord(). */
     291                 :            :     void                EnableDecryption( bool bEnable = true );
     292                 :            :     /** Switches usage of current decryption algorithm off.
     293                 :            :         @descr  This is a record-local setting. The function StartNextRecord()
     294                 :            :         always enables decryption. */
     295                 :        385 :     inline void         DisableDecryption() { EnableDecryption( false ); }
     296                 :            : 
     297                 :            :     /** Pushes current position on user position stack.
     298                 :            :         @descr  This stack is emptied when starting a new record with
     299                 :            :         StartNextRecord(). The decryption state (enabled/disabled) is not
     300                 :            :         pushed onto the stack. */
     301                 :            :     void                PushPosition();
     302                 :            :     /** Seeks to last position from user position stack.
     303                 :            :         @descr  This position will be removed from the stack. */
     304                 :            :     void                PopPosition();
     305                 :            : 
     306                 :            :     /** Stores current position. This position keeps valid in all records. */
     307                 :            :     void                StoreGlobalPosition();
     308                 :            :     /** Seeks to the stored global user position. */
     309                 :            :     void                SeekGlobalPosition();
     310                 :            :     /** Invalidates global user position. */
     311                 :            :     inline void         DeleteGlobalPosition() { mbHasGlobPos = false; }
     312                 :            : 
     313                 :            :     /** Returns record reading state: false = record overread. */
     314                 :     204967 :     inline bool         IsValid() const { return mbValid; }
     315                 :            :     /** Returns the current record ID. */
     316                 :      49312 :     inline sal_uInt16   GetRecId() const { return mnRecId; }
     317                 :            :     /** Returns the position inside of the whole record content. */
     318                 :            :     sal_Size            GetRecPos() const;
     319                 :            :     /** Returns the data size of the whole record without record headers. */
     320                 :            :     sal_Size            GetRecSize();
     321                 :            :     /** Returns remaining data size of the whole record without record headers. */
     322                 :            :     sal_Size            GetRecLeft();
     323                 :            :     /** Returns the record ID of the following record. */
     324                 :            :     sal_uInt16          GetNextRecId();
     325                 :            : 
     326                 :            :     sal_uInt16          PeekRecId( sal_Size nPos );
     327                 :            : 
     328                 :            :     XclImpStream&       operator>>( sal_Int8& rnValue );
     329                 :            :     XclImpStream&       operator>>( sal_uInt8& rnValue );
     330                 :            :     XclImpStream&       operator>>( sal_Int16& rnValue );
     331                 :            :     XclImpStream&       operator>>( sal_uInt16& rnValue );
     332                 :            :     XclImpStream&       operator>>( sal_Int32& rnValue );
     333                 :            :     XclImpStream&       operator>>( sal_uInt32& rnValue );
     334                 :            :     XclImpStream&       operator>>( float& rfValue );
     335                 :            :     XclImpStream&       operator>>( double& rfValue );
     336                 :            : 
     337                 :            :     sal_uInt8           ReaduInt8();
     338                 :            :     sal_Int16           ReadInt16();
     339                 :            :     sal_uInt16          ReaduInt16();
     340                 :            :     sal_Int32           ReadInt32();
     341                 :            :     sal_uInt32          ReaduInt32();
     342                 :            :     double              ReadDouble();
     343                 :            : 
     344                 :            :     /** Reads nBytes bytes to the existing(!) buffer pData.
     345                 :            :         @return  Count of bytes really read. */
     346                 :            :     sal_Size            Read( void* pData, sal_Size nBytes );
     347                 :            :     /** Copies nBytes bytes to rOutStrm.
     348                 :            :         @return  Count of bytes really written. */
     349                 :            :     sal_Size            CopyToStream( SvStream& rOutStrm, sal_Size nBytes );
     350                 :            : 
     351                 :            :     /** Copies the entire record to rOutStrm. The current record position keeps unchanged.
     352                 :            :         @return  Count of bytes really written. */
     353                 :            :     sal_Size            CopyRecordToStream( SvStream& rOutStrm );
     354                 :            : 
     355                 :            :     /** Seeks absolute in record content to the specified position.
     356                 :            :         @descr  The value 0 means start of record, independent from physical stream position. */
     357                 :            :     void                Seek( sal_Size nPos );
     358                 :            :     /** Seeks forward inside the current record. */
     359                 :            :     void                Ignore( sal_Size nBytes );
     360                 :            : 
     361                 :            :     // *** special string functions *** ---------------------------------------
     362                 :            : 
     363                 :            :     // *** read/ignore unicode strings *** ------------------------------------
     364                 :            :     /*  - look for CONTINUE records even if CONTINUE handling disabled
     365                 :            :           (only if inside of a CONTINUE record - for TXO import)
     366                 :            :         - no overread assertions (for Applix wrong string length export bug)
     367                 :            : 
     368                 :            :         structure of an Excel unicode string:
     369                 :            :         (1) 2 byte character count
     370                 :            :         (2) 1 byte flags (16-bit-characters, rich string, far east string)
     371                 :            :         (3) [2 byte rich string format run count]
     372                 :            :         (4) [4 byte far east data size]
     373                 :            :         (5) character array
     374                 :            :         (6) [4 * (rich string format run count) byte]
     375                 :            :         (7) [(far east data size) byte]
     376                 :            :         header = (1), (2)
     377                 :            :         ext. header = (3), (4)
     378                 :            :         ext. data = (6), (7)
     379                 :            :      */
     380                 :            : 
     381                 :            :     /** Reads ext. header, detects 8/16 bit mode, sets all ext. info.
     382                 :            :         @return  Total size of ext. data. */
     383                 :            :     sal_Size            ReadUniStringExtHeader(
     384                 :            :                             bool& rb16Bit, bool& rbRich, bool& rbFareast,
     385                 :            :                             sal_uInt16& rnFormatRuns, sal_uInt32& rnExtInf, sal_uInt8 nFlags );
     386                 :            :     /** Seeks to begin of character array, detects 8/16 bit mode.
     387                 :            :         @return  Total size of ext. data. */
     388                 :            :     sal_Size            ReadUniStringExtHeader( bool& rb16Bit, sal_uInt8 nFlags );
     389                 :            : 
     390                 :            :     /** Sets a replacement character for NUL characters.
     391                 :            :         @descr  NUL characters must be replaced, because Tools strings cannot
     392                 :            :         handle them. The substitution character is reset to '?' automatically,
     393                 :            :         if a new record is started using the function StartNextRecord().
     394                 :            :         @param cNulSubst  The character to use for NUL replacement. It is
     395                 :            :         possible to specify NUL here. in this case strings are terminated when
     396                 :            :         the first NUL occurs during string import. */
     397                 :      47894 :     inline void         SetNulSubstChar( sal_Unicode cNulSubst = '?' ) { mcNulSubst = cNulSubst; }
     398                 :            : 
     399                 :            :     /** Reads nChars characters and returns the string. */
     400                 :            :     String              ReadRawUniString( sal_uInt16 nChars, bool b16Bit );
     401                 :            :     /** Reads ext. header, nChar characters, ext. data and returns the string. */
     402                 :            :     String              ReadUniString( sal_uInt16 nChars, sal_uInt8 nFlags );
     403                 :            :     /** Reads 8 bit flags, ext. header, nChar characters, ext. data and returns the string. */
     404                 :            :     String              ReadUniString( sal_uInt16 nChars );
     405                 :            :     /** Reads 16 bit character count, 8 bit flags, ext. header, character array,
     406                 :            :         ext. data and returns the string. */
     407                 :            :     String              ReadUniString();
     408                 :            : 
     409                 :            :     /** Ignores nChars characters. */
     410                 :            :     void                IgnoreRawUniString( sal_uInt16 nChars, bool b16Bit );
     411                 :            :     /** Ignores ext. header, nChar characters, ext. data. */
     412                 :            :     void                IgnoreUniString( sal_uInt16 nChars, sal_uInt8 nFlags );
     413                 :            :     /** Ignores 8 bit flags, ext. header, nChar characters, ext. data. */
     414                 :            :     void                IgnoreUniString( sal_uInt16 nChars );
     415                 :            : 
     416                 :            :     // *** read/ignore 8-bit-strings, store in String *** ---------------------
     417                 :            : 
     418                 :            :     /** Reads nChar byte characters and returns the string. */
     419                 :            :     String              ReadRawByteString( sal_uInt16 nChars );
     420                 :            :     /** Reads 8/16 bit string length, character array and returns the string. */
     421                 :            :     String              ReadByteString( bool b16BitLen );
     422                 :            : 
     423                 :            :     // *** SvStream functions *** ---------------------------------------------
     424                 :            : 
     425                 :            :     /** Returns the absolute stream position. */
     426                 :      22780 :     inline sal_Size     GetSvStreamPos() const { return mrStrm.Tell(); }
     427                 :            :     /** Returns the stream size. */
     428                 :         55 :     inline sal_Size     GetSvStreamSize() const { return mnStreamSize; }
     429                 :            : 
     430                 :            :     /** Stores current stream position into rPos. */
     431                 :            :     void                StorePosition( XclImpStreamPos& rPos );
     432                 :            :     /** Restores stream position contained in rPos. */
     433                 :            :     void                RestorePosition( const XclImpStreamPos& rPos );
     434                 :            : 
     435                 :            : private:
     436                 :            :     /** Seeks to next raw record header and reads record ID and size.
     437                 :            :         @descr  This is a "raw" function, means that stream members are
     438                 :            :         inconsistent after return. Does only change mnRawRecId, mnRawRecSize,
     439                 :            :         and the base stream position, but no other members.
     440                 :            :         @return  false = No record header found (end of stream). */
     441                 :            :     bool                ReadNextRawRecHeader();
     442                 :            : 
     443                 :            :     /** Initializes the decrypter to read a new record. */
     444                 :            :     void                SetupDecrypter();
     445                 :            :     /** Initializes all members after base stream has been seeked to new raw record. */
     446                 :            :     void                SetupRawRecord();
     447                 :            :     /** Initializes all members after base stream has been seeked to new record. */
     448                 :            :     void                SetupRecord();
     449                 :            : 
     450                 :            :     /** Returns true, if the passed ID is real or alternative continuation record ID. */
     451                 :            :     bool                IsContinueId( sal_uInt16 nRecId ) const;
     452                 :            : 
     453                 :            :     /** Goes to start of the next CONTINUE record.
     454                 :            :         @descr  Stream must be located at the end of a raw record, and handling
     455                 :            :         of CONTINUE records must be enabled.
     456                 :            :         @return  Copy of mbValid. */
     457                 :            :     bool                JumpToNextContinue();
     458                 :            :     /** Goes to start of the next CONTINUE record while reading strings.
     459                 :            :         @descr  Stream must be located at the end of a raw record. If reading
     460                 :            :         has been started in a CONTINUE record, jumps to an existing following
     461                 :            :         CONTINUE record, even if handling of CONTINUE records is disabled (This
     462                 :            :         is a special handling for TXO string data). Reads additional Unicode
     463                 :            :         flag byte at start of the new raw record and sets or resets rb16Bit.
     464                 :            :         @return  Copy of mbValid. */
     465                 :            :     bool                JumpToNextStringContinue( bool& rb16Bit );
     466                 :            : 
     467                 :            :     /** Ensures that reading nBytes bytes is possible with next stream access.
     468                 :            :         @descr  Stream must be located at the end of a raw record, and handling
     469                 :            :         of CONTINUE records must be enabled.
     470                 :            :         @return  Copy of mbValid. */
     471                 :            :     bool                EnsureRawReadSize( sal_uInt16 nBytes );
     472                 :            :     /** Returns the maximum size of raw data possible to read in one block. */
     473                 :            :     sal_uInt16          GetMaxRawReadSize( sal_Size nBytes ) const;
     474                 :            : 
     475                 :            :     /** Reads and decrypts nBytes bytes to the existing(!) buffer pData.
     476                 :            :         @return  Count of bytes really read. */
     477                 :            :     sal_uInt16          ReadRawData( void* pData, sal_uInt16 nBytes );
     478                 :            : 
     479                 :            :     /** Reads 8 bit/16 bit string length. */
     480                 :          0 :     inline sal_uInt16   ReadByteStrLen( bool b16BitLen )
     481         [ #  # ]:          0 :                             { return b16BitLen ? ReaduInt16() : ReaduInt8(); }
     482                 :            : 
     483                 :            : private:
     484                 :            :     typedef ::std::vector< XclImpStreamPos > XclImpStreamPosStack;
     485                 :            : 
     486                 :            :     SvStream&           mrStrm;         /// Reference to the system input stream.
     487                 :            :     const XclImpRoot&   mrRoot;         /// Filter root data.
     488                 :            : 
     489                 :            :     XclImpDecrypterRef  mxDecrypter;    /// Provides methods to decrypt data.
     490                 :            : 
     491                 :            :     XclImpStreamPos     maFirstRec;     /// Start position of current record.
     492                 :            :     XclImpStreamPosStack maPosStack;    /// Stack for record positions.
     493                 :            : 
     494                 :            :     XclImpStreamPos     maGlobPos;      /// User defined position elsewhere in stream.
     495                 :            :     sal_uInt16          mnGlobRecId;    /// Record ID for user defined position.
     496                 :            :     bool                mbGlobValidRec; /// Was user position a valid record?
     497                 :            :     bool                mbHasGlobPos;   /// Is user position defined?
     498                 :            : 
     499                 :            :     sal_Size            mnStreamSize;   /// Size of system stream.
     500                 :            :     sal_Size            mnNextRecPos;   /// Start of next record header.
     501                 :            :     sal_Size            mnCurrRecSize;  /// Helper for record position.
     502                 :            :     sal_Size            mnComplRecSize; /// Size of complete record data (with CONTINUEs).
     503                 :            :     bool                mbHasComplRec;  /// true = mnComplRecSize is valid.
     504                 :            : 
     505                 :            :     sal_uInt16          mnRecId;        /// Current record ID (not the CONTINUE ID).
     506                 :            :     sal_uInt16          mnAltContId;    /// Alternative record ID for content continuation.
     507                 :            : 
     508                 :            :     sal_uInt16          mnRawRecId;     /// Current raw record ID (including CONTINUEs).
     509                 :            :     sal_uInt16          mnRawRecSize;   /// Current raw record size (without following CONTINUEs).
     510                 :            :     sal_uInt16          mnRawRecLeft;   /// Bytes left in current raw record (without following CONTINUEs).
     511                 :            : 
     512                 :            :     sal_Unicode         mcNulSubst;     /// Replacement for NUL characters.
     513                 :            : 
     514                 :            :     bool                mbCont;         /// Automatic CONTINUE lookup on/off.
     515                 :            :     bool                mbUseDecr;      /// Usage of decryption.
     516                 :            :     bool                mbValidRec;     /// false = No more records to read.
     517                 :            :     bool                mbValid;        /// false = Record overread.
     518                 :            : };
     519                 :            : 
     520                 :            : // ============================================================================
     521                 :            : 
     522                 :            : #endif
     523                 :            : 
     524                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10