MWAWInputStream.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33 
34 #ifndef MWAW_INPUT_STREAM_H
35 #define MWAW_INPUT_STREAM_H
36 
37 #include <string>
38 #include <vector>
39 
40 #include <libwpd/libwpd.h>
41 #include <libwpd-stream/libwpd-stream.h>
42 #include "libmwaw_internal.hxx"
43 
44 namespace libmwawOLE
45 {
46 class Storage;
47 }
48 
49 class WPXBinaryData;
50 
61 {
62 public:
67  MWAWInputStream(shared_ptr<WPXInputStream> inp, bool inverted);
68 
73  MWAWInputStream(WPXInputStream *input, bool inverted, bool checkCompression=false);
76 
78  shared_ptr<WPXInputStream> input() {
79  return m_stream;
80  }
82  static shared_ptr<MWAWInputStream> get(WPXBinaryData const &data, bool inverted);
83 
85  bool readInverted() const {
86  return m_inverseRead;
87  }
89  void setReadInverted(bool newVal) {
90  m_inverseRead = newVal;
91  }
92  //
93  // Position: access
94  //
95 
100  int seek(long offset, WPX_SEEK_TYPE seekType);
102  long tell();
104  long size() const {
105  return m_streamSize;
106  }
108  bool checkPosition(long pos) const {
109  if (pos < 0) return false;
110  if (m_readLimit > 0 && pos > m_readLimit) return false;
111  return pos<=m_streamSize;
112  }
114  bool atEOS();
115 
119  void pushLimit(long newLimit) {
120  m_prevLimits.push_back(m_readLimit);
121  m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
122  }
124  void popLimit() {
125  if (m_prevLimits.size()) {
126  m_readLimit = m_prevLimits.back();
127  m_prevLimits.pop_back();
128  } else m_readLimit = -1;
129  }
130 
131  //
132  // get data
133  //
134 
136  unsigned long readULong(int num) {
137  return readULong(m_stream.get(), num, 0, m_inverseRead);
138  }
140  long readLong(int num);
142  bool readDouble(double &res, bool &isNotANumber);
143 
147  const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
151  static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
152 
154  bool readDataBlock(long size, WPXBinaryData &data);
156  bool readEndDataBlock(WPXBinaryData &data);
157 
158  //
159  // OLE access
160  //
161 
163  bool isOLEStream();
165  std::vector<std::string> getOLENames();
167  shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
168 
169  //
170  // Finder Info access
171  //
173  bool getFinderInfo(std::string &type, std::string &creator) const {
174  if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
175  type = creator = "";
176  return false;
177  }
178  type = m_fInfoType;
179  creator = m_fInfoCreator;
180  return true;
181  }
182 
183  //
184  // Resource Fork access
185  //
186 
188  bool hasDataFork() const {
189  return bool(m_stream);
190  }
192  bool hasResourceFork() const {
193  return bool(m_resourceFork);
194  }
196  shared_ptr<MWAWInputStream> getResourceForkStream() {
197  return m_resourceFork;
198  }
199 
200 
201 protected:
203  void updateStreamSize();
205  static uint8_t readU8(WPXInputStream *stream);
206 
208  bool createStorageOLE();
209 
211  bool unBinHex();
213  bool unzipStream();
215  bool unMacMIME();
217  bool unMacMIME(MWAWInputStream *input,
218  shared_ptr<WPXInputStream> &dataInput,
219  shared_ptr<WPXInputStream> &rsrcInput) const;
220 
221 private:
222  MWAWInputStream(MWAWInputStream const &orig);
224 
225 protected:
227  shared_ptr<WPXInputStream> m_stream;
230 
233 
237  std::vector<long> m_prevLimits;
238 
240  mutable std::string m_fInfoType;
242  mutable std::string m_fInfoCreator;
244  shared_ptr<MWAWInputStream> m_resourceFork;
246  shared_ptr<libmwawOLE::Storage> m_storageOLE;
247 };
248 
250 class MWAWStringStream: public WPXInputStream
251 {
252 public:
254  MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
257 
261  const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
263  long tell() {
264  return m_offset;
265  }
270  int seek(long offset, WPX_SEEK_TYPE seekType);
272  bool atEOS() {
273  return ((long)m_offset >= (long)m_buffer.size());
274  }
275 
281  return false;
282  }
287  WPXInputStream *getSubStream(const char *) {
288  return 0;
289  }
290 
295  bool isOLEStream() {
296  return isStructuredDocument();
297  }
302  WPXInputStream *getDocumentOLEStream(const char *name) {
303  return getSubStream(name);
304  }
305 
306 private:
308  std::vector<unsigned char> m_buffer;
310  volatile long m_offset;
311 
314 };
315 
316 #endif
317 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool unMacMIME()
check if some stream are in MacMIME format, if so de MacMIME
Definition: MWAWInputStream.cxx:498
shared_ptr< MWAWInputStream > getDocumentOLEStream(std::string name)
return a new stream for a ole zone
Definition: MWAWInputStream.cxx:659
int seek(long offset, WPX_SEEK_TYPE seekType)
seeks to a offset position, from actual or beginning position
Definition: MWAWInputStream.cxx:730
bool isStructuredDocument()
Analyses the content of the input stream to see whether it is an Zip/OLE2 storage.
Definition: MWAWInputStream.hxx:280
long tell()
returns actual offset position
Definition: MWAWInputStream.cxx:127
bool hasDataFork() const
returns true if the data fork block exists
Definition: MWAWInputStream.hxx:188
class used to read/parse an OLE file
Definition: MWAWOLEStream.hxx:48
shared_ptr< WPXInputStream > m_stream
the initial input
Definition: MWAWInputStream.hxx:227
bool readInverted() const
returns the endian mode (see constructor)
Definition: MWAWInputStream.hxx:85
void popLimit()
pops a section defined by pushLimit
Definition: MWAWInputStream.hxx:124
const unsigned char * read(unsigned long numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:750
bool unBinHex()
unbinhex the data in the file is a BinHex 4.0 file of a mac file
Definition: MWAWInputStream.cxx:273
MWAWInputStream & operator=(MWAWInputStream const &orig)
bool isOLEStream()
return true if the stream is ole
Definition: MWAWInputStream.cxx:647
WPXInputStream * getDocumentOLEStream(const char *name)
Tries to extract a stream from a structured document.
Definition: MWAWInputStream.hxx:302
std::vector< unsigned char > m_buffer
a buffer which contains the data
Definition: MWAWInputStream.hxx:308
void setReadInverted(bool newVal)
sets the endian mode
Definition: MWAWInputStream.hxx:89
shared_ptr< MWAWInputStream > m_resourceFork
the resource fork
Definition: MWAWInputStream.hxx:244
std::vector< std::string > getOLENames()
return the list of all ole zone
Definition: MWAWInputStream.cxx:653
long m_readLimit
actual section limit (-1 if no limit)
Definition: MWAWInputStream.hxx:235
long size() const
returns the stream size
Definition: MWAWInputStream.hxx:104
bool m_inverseRead
big or normal endian
Definition: MWAWInputStream.hxx:232
MWAWStringStream & operator=(const MWAWStringStream &)
Internal class used to read the file stream Internal class used to read the file stream, this class adds some usefull functions to the basic WPXInputStream:
Definition: MWAWInputStream.hxx:60
std::string m_fInfoCreator
finder info type
Definition: MWAWInputStream.hxx:242
WPXInputStream * getSubStream(const char *)
Tries to extract a stream from a structured document.
Definition: MWAWInputStream.hxx:287
long tell()
returns actual offset position
Definition: MWAWInputStream.hxx:263
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.hxx:272
shared_ptr< libmwawOLE::Storage > m_storageOLE
the ole storage
Definition: MWAWInputStream.hxx:246
bool unzipStream()
unzip the data in the file is a zip file of a mac file
Definition: MWAWInputStream.cxx:448
static uint8_t readU8(WPXInputStream *stream)
internal function used to read a byte
Definition: MWAWInputStream.cxx:219
shared_ptr< MWAWInputStream > getResourceForkStream()
returns the resource fork if find
Definition: MWAWInputStream.hxx:196
shared_ptr< WPXInputStream > input()
returns the basic WPXInputStream
Definition: MWAWInputStream.hxx:78
an internal class used to return the OLE/Zip InputStream
Definition: MWAWInputStream.hxx:250
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: MWAWInputStream.cxx:201
long m_streamSize
the stream size
Definition: MWAWInputStream.hxx:229
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.cxx:157
bool isOLEStream()
Analyses the content of the input stream to see whether it is an Zip/OLE2 storage.
Definition: MWAWInputStream.hxx:295
bool createStorageOLE()
creates a storage ole
Definition: MWAWInputStream.cxx:675
std::vector< long > m_prevLimits
list of previous limits
Definition: MWAWInputStream.hxx:237
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition: MWAWInputStream.hxx:108
bool readDouble(double &res, bool &isNotANumber)
try to read a double (ppc)
Definition: MWAWInputStream.cxx:232
bool hasResourceFork() const
returns true if the resource fork block exists
Definition: MWAWInputStream.hxx:192
std::string m_fInfoType
finder info type
Definition: MWAWInputStream.hxx:240
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:120
void pushLimit(long newLimit)
defines a new section in the file (from actualPos to newLimit) next call of seek, tell...
Definition: MWAWInputStream.hxx:119
int seek(long offset, WPX_SEEK_TYPE seekType)
seeks to a offset position, from actual or beginning position
Definition: MWAWInputStream.cxx:134
MWAWInputStream(shared_ptr< WPXInputStream > inp, bool inverted)
creates a stream with given endian from
Definition: MWAWInputStream.cxx:49
MWAWStringStream(const unsigned char *data, const unsigned long dataSize)
constructor
Definition: MWAWInputStream.cxx:724
volatile long m_offset
the actual offset in the buffer
Definition: MWAWInputStream.hxx:310
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition: MWAWInputStream.cxx:108
bool readEndDataBlock(WPXBinaryData &data)
reads a WPXBinaryData from actPos to the end of the section/file
Definition: MWAWInputStream.cxx:713
~MWAWStringStream()
destructor
Definition: MWAWInputStream.hxx:256
~MWAWInputStream()
destructor
Definition: MWAWInputStream.cxx:84
bool getFinderInfo(std::string &type, std::string &creator) const
returns the finder info type and creator (if known)
Definition: MWAWInputStream.hxx:173
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition: MWAWInputStream.hxx:136
bool readDataBlock(long size, WPXBinaryData &data)
reads a WPXBinaryData with a given size in the actual section/file
Definition: MWAWInputStream.cxx:694

Generated on Tue Mar 10 2015 17:32:09 for libmwaw by doxygen 1.8.5