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 : sal_uInt32 GetBlock( sal_Size nStrmPos ) const;
143 : /** Returns the block offset corresponding to the passed stream position. */
144 : sal_uInt16 GetOffset( sal_Size nStrmPos ) const;
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 8218 : 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 992 : 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 2053076 : inline bool IsValid() const { return mbValid; }
316 : /** Returns the current record ID. */
317 2232914 : 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 : XclImpStream& operator>>( sal_Int8& rnValue );
330 : XclImpStream& operator>>( sal_uInt8& rnValue );
331 : XclImpStream& operator>>( sal_Int16& rnValue );
332 : XclImpStream& operator>>( sal_uInt16& rnValue );
333 : XclImpStream& operator>>( sal_Int32& rnValue );
334 : XclImpStream& operator>>( sal_uInt32& rnValue );
335 : XclImpStream& operator>>( float& rfValue );
336 : XclImpStream& operator>>( double& rfValue );
337 :
338 : sal_uInt8 ReaduInt8();
339 : sal_Int16 ReadInt16();
340 : sal_uInt16 ReaduInt16();
341 : sal_Int32 ReadInt32();
342 : sal_uInt32 ReaduInt32();
343 : double ReadDouble();
344 :
345 : /** Reads nBytes bytes to the existing(!) buffer pData.
346 : @return Count of bytes really read. */
347 : sal_Size Read( void* pData, sal_Size nBytes );
348 : /** Copies nBytes bytes to rOutStrm.
349 : @return Count of bytes really written. */
350 : sal_Size CopyToStream( SvStream& rOutStrm, sal_Size nBytes );
351 :
352 : /** Copies the entire record to rOutStrm. The current record position keeps unchanged.
353 : @return Count of bytes really written. */
354 : sal_Size CopyRecordToStream( SvStream& rOutStrm );
355 :
356 : /** Seeks absolute in record content to the specified position.
357 : @descr The value 0 means start of record, independent from physical stream position. */
358 : void Seek( sal_Size nPos );
359 : /** Seeks forward inside the current record. */
360 : void Ignore( sal_Size nBytes );
361 :
362 : // *** special string functions *** ---------------------------------------
363 :
364 : // *** read/ignore unicode strings *** ------------------------------------
365 : /* - look for CONTINUE records even if CONTINUE handling disabled
366 : (only if inside of a CONTINUE record - for TXO import)
367 : - no overread assertions (for Applix wrong string length export bug)
368 :
369 : structure of an Excel unicode string:
370 : (1) 2 byte character count
371 : (2) 1 byte flags (16-bit-characters, rich string, far east string)
372 : (3) [2 byte rich string format run count]
373 : (4) [4 byte far east data size]
374 : (5) character array
375 : (6) [4 * (rich string format run count) byte]
376 : (7) [(far east data size) byte]
377 : header = (1), (2)
378 : ext. header = (3), (4)
379 : ext. data = (6), (7)
380 : */
381 :
382 : /** Reads ext. header, detects 8/16 bit mode, sets all ext. info.
383 : @return Total size of ext. data. */
384 : sal_Size ReadUniStringExtHeader(
385 : bool& rb16Bit, bool& rbRich, bool& rbFareast,
386 : sal_uInt16& rnFormatRuns, sal_uInt32& rnExtInf, sal_uInt8 nFlags );
387 : /** Seeks to begin of character array, detects 8/16 bit mode.
388 : @return Total size of ext. data. */
389 : sal_Size ReadUniStringExtHeader( bool& rb16Bit, sal_uInt8 nFlags );
390 :
391 : /** Sets a replacement character for NUL characters.
392 : @descr NUL characters must be replaced, because Tools strings cannot
393 : handle them. The substitution character is reset to '?' automatically,
394 : if a new record is started using the function StartNextRecord().
395 : @param cNulSubst The character to use for NUL replacement. It is
396 : possible to specify NUL here. in this case strings are terminated when
397 : the first NUL occurs during string import. */
398 1818634 : inline void SetNulSubstChar( sal_Unicode cNulSubst = '?' ) { mcNulSubst = cNulSubst; }
399 :
400 : /** Reads nChars characters and returns the string. */
401 : OUString ReadRawUniString( sal_uInt16 nChars, bool b16Bit );
402 : /** Reads ext. header, nChar characters, ext. data and returns the string. */
403 : OUString ReadUniString( sal_uInt16 nChars, sal_uInt8 nFlags );
404 : /** Reads 8 bit flags, ext. header, nChar characters, ext. data and returns the string. */
405 : OUString ReadUniString( sal_uInt16 nChars );
406 : /** Reads 16 bit character count, 8 bit flags, ext. header, character array,
407 : ext. data and returns the string. */
408 : OUString ReadUniString();
409 :
410 : /** Ignores nChars characters. */
411 : void IgnoreRawUniString( sal_uInt16 nChars, bool b16Bit );
412 : /** Ignores ext. header, nChar characters, ext. data. */
413 : void IgnoreUniString( sal_uInt16 nChars, sal_uInt8 nFlags );
414 : /** Ignores 8 bit flags, ext. header, nChar characters, ext. data. */
415 : void IgnoreUniString( sal_uInt16 nChars );
416 :
417 : // *** read/ignore 8-bit-strings, store in String *** ---------------------
418 :
419 : /** Reads nChar byte characters and returns the string. */
420 : OUString ReadRawByteString( sal_uInt16 nChars );
421 : /** Reads 8/16 bit string length, character array and returns the string. */
422 : OUString ReadByteString( bool b16BitLen );
423 :
424 : // *** SvStream functions *** ---------------------------------------------
425 :
426 : /** Returns the absolute stream position. */
427 893530 : inline sal_Size GetSvStreamPos() const { return mrStrm.Tell(); }
428 : /** Returns the stream size. */
429 144 : inline sal_Size GetSvStreamSize() const { return mnStreamSize; }
430 :
431 : /** Stores current stream position into rPos. */
432 : void StorePosition( XclImpStreamPos& rPos );
433 : /** Restores stream position contained in rPos. */
434 : void RestorePosition( const XclImpStreamPos& rPos );
435 :
436 : private:
437 : /** Seeks to next raw record header and reads record ID and size.
438 : @descr This is a "raw" function, means that stream members are
439 : inconsistent after return. Does only change mnRawRecId, mnRawRecSize,
440 : and the base stream position, but no other members.
441 : @return false = No record header found (end of stream). */
442 : bool ReadNextRawRecHeader();
443 :
444 : /** Initializes the decrypter to read a new record. */
445 : void SetupDecrypter();
446 : /** Initializes all members after base stream has been sought to new raw record. */
447 : void SetupRawRecord();
448 : /** Initializes all members after base stream has been sought to new record. */
449 : void SetupRecord();
450 :
451 : /** Returns true, if the passed ID is real or alternative continuation record ID. */
452 : bool IsContinueId( sal_uInt16 nRecId ) const;
453 :
454 : /** Goes to start of the next CONTINUE record.
455 : @descr Stream must be located at the end of a raw record, and handling
456 : of CONTINUE records must be enabled.
457 : @return Copy of mbValid. */
458 : bool JumpToNextContinue();
459 : /** Goes to start of the next CONTINUE record while reading strings.
460 : @descr Stream must be located at the end of a raw record. If reading
461 : has been started in a CONTINUE record, jumps to an existing following
462 : CONTINUE record, even if handling of CONTINUE records is disabled (This
463 : is a special handling for TXO string data). Reads additional Unicode
464 : flag byte at start of the new raw record and sets or resets rb16Bit.
465 : @return Copy of mbValid. */
466 : bool JumpToNextStringContinue( bool& rb16Bit );
467 :
468 : /** Ensures that reading nBytes bytes is possible with next stream access.
469 : @descr Stream must be located at the end of a raw record, and handling
470 : of CONTINUE records must be enabled.
471 : @return Copy of mbValid. */
472 : bool EnsureRawReadSize( sal_uInt16 nBytes );
473 : /** Returns the maximum size of raw data possible to read in one block. */
474 : sal_uInt16 GetMaxRawReadSize( sal_Size nBytes ) const;
475 :
476 : /** Reads and decrypts nBytes bytes to the existing(!) buffer pData.
477 : @return Count of bytes really read. */
478 : sal_uInt16 ReadRawData( void* pData, sal_uInt16 nBytes );
479 :
480 : /** Reads 8 bit/16 bit string length. */
481 1648 : inline sal_uInt16 ReadByteStrLen( bool b16BitLen )
482 1648 : { return b16BitLen ? ReaduInt16() : ReaduInt8(); }
483 :
484 : private:
485 : typedef ::std::vector< XclImpStreamPos > XclImpStreamPosStack;
486 :
487 : SvStream& mrStrm; /// Reference to the system input stream.
488 : const XclImpRoot& mrRoot; /// Filter root data.
489 :
490 : XclImpDecrypterRef mxDecrypter; /// Provides methods to decrypt data.
491 :
492 : XclImpStreamPos maFirstRec; /// Start position of current record.
493 : XclImpStreamPosStack maPosStack; /// Stack for record positions.
494 :
495 : XclImpStreamPos maGlobPos; /// User defined position elsewhere in stream.
496 : sal_uInt16 mnGlobRecId; /// Record ID for user defined position.
497 : bool mbGlobValidRec; /// Was user position a valid record?
498 : bool mbHasGlobPos; /// Is user position defined?
499 :
500 : sal_Size mnStreamSize; /// Size of system stream.
501 : sal_Size mnNextRecPos; /// Start of next record header.
502 : sal_Size mnCurrRecSize; /// Helper for record position.
503 : sal_Size mnComplRecSize; /// Size of complete record data (with CONTINUEs).
504 : bool mbHasComplRec; /// true = mnComplRecSize is valid.
505 :
506 : sal_uInt16 mnRecId; /// Current record ID (not the CONTINUE ID).
507 : sal_uInt16 mnAltContId; /// Alternative record ID for content continuation.
508 :
509 : sal_uInt16 mnRawRecId; /// Current raw record ID (including CONTINUEs).
510 : sal_uInt16 mnRawRecSize; /// Current raw record size (without following CONTINUEs).
511 : sal_uInt16 mnRawRecLeft; /// Bytes left in current raw record (without following CONTINUEs).
512 :
513 : sal_Unicode mcNulSubst; /// Replacement for NUL characters.
514 :
515 : bool mbCont; /// Automatic CONTINUE lookup on/off.
516 : bool mbUseDecr; /// Usage of decryption.
517 : bool mbValidRec; /// false = No more records to read.
518 : bool mbValid; /// false = Record overread.
519 : };
520 :
521 : #endif
522 :
523 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|