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);
141 
145  const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
149  static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
150 
152  bool readDataBlock(long size, WPXBinaryData &data);
154  bool readEndDataBlock(WPXBinaryData &data);
155 
156  //
157  // OLE access
158  //
159 
161  bool isOLEStream();
163  std::vector<std::string> getOLENames();
165  shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
166 
167  //
168  // Finder Info access
169  //
171  bool getFinderInfo(std::string &type, std::string &creator) const {
172  if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
173  type = creator = "";
174  return false;
175  }
176  type = m_fInfoType;
177  creator = m_fInfoCreator;
178  return true;
179  }
180 
181  //
182  // Resource Fork access
183  //
184 
186  bool hasDataFork() const {
187  return bool(m_stream);
188  }
190  bool hasResourceFork() const {
191  return bool(m_resourceFork);
192  }
194  shared_ptr<MWAWInputStream> getResourceForkStream() {
195  return m_resourceFork;
196  }
197 
198 
199 protected:
201  void updateStreamSize();
203  static uint8_t readU8(WPXInputStream *stream);
204 
206  bool createStorageOLE();
207 
209  bool unBinHex();
211  bool unzipStream();
213  bool unMacMIME();
215  bool unMacMIME(MWAWInputStream *input,
216  shared_ptr<WPXInputStream> &dataInput,
217  shared_ptr<WPXInputStream> &rsrcInput) const;
218 
219 private:
220  MWAWInputStream(MWAWInputStream const &orig);
222 
223 protected:
225  shared_ptr<WPXInputStream> m_stream;
228 
231 
235  std::vector<long> m_prevLimits;
236 
238  mutable std::string m_fInfoType;
240  mutable std::string m_fInfoCreator;
242  shared_ptr<MWAWInputStream> m_resourceFork;
244  shared_ptr<libmwawOLE::Storage> m_storageOLE;
245 };
246 
248 class MWAWStringStream: public WPXInputStream
249 {
250 public:
252  MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
255 
259  const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
261  long tell() {
262  return m_offset;
263  }
268  int seek(long offset, WPX_SEEK_TYPE seekType);
270  bool atEOS() {
271  return ((long)m_offset >= (long)m_buffer.size());
272  }
273 
279  return false;
280  }
285  WPXInputStream *getSubStream(const char *) {
286  return 0;
287  }
288 
293  bool isOLEStream() {
294  return isStructuredDocument();
295  }
300  WPXInputStream *getDocumentOLEStream(const char *name) {
301  return getSubStream(name);
302  }
303 
304 private:
306  std::vector<unsigned char> m_buffer;
308  volatile long m_offset;
309 
312 };
313 
314 #endif
315 // 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:460
shared_ptr< MWAWInputStream > getDocumentOLEStream(std::string name)
return a new stream for a ole zone
Definition: MWAWInputStream.cxx:621
int seek(long offset, WPX_SEEK_TYPE seekType)
seeks to a offset position, from actual or beginning position
Definition: MWAWInputStream.cxx:692
bool isStructuredDocument()
Analyses the content of the input stream to see whether it is an Zip/OLE2 storage.
Definition: MWAWInputStream.hxx:278
long tell()
returns actual offset position
Definition: MWAWInputStream.cxx:125
bool hasDataFork() const
returns true if the data fork block exists
Definition: MWAWInputStream.hxx:186
class used to read/parse an OLE file
Definition: MWAWOLEStream.hxx:48
shared_ptr< WPXInputStream > m_stream
the initial input
Definition: MWAWInputStream.hxx:225
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:712
bool unBinHex()
unbinhex the data in the file is a BinHex 4.0 file of a mac file
Definition: MWAWInputStream.cxx:235
MWAWInputStream & operator=(MWAWInputStream const &orig)
bool isOLEStream()
return true if the stream is ole
Definition: MWAWInputStream.cxx:609
WPXInputStream * getDocumentOLEStream(const char *name)
Tries to extract a stream from a structured document.
Definition: MWAWInputStream.hxx:300
std::vector< unsigned char > m_buffer
a buffer which contains the data
Definition: MWAWInputStream.hxx:306
void setReadInverted(bool newVal)
sets the endian mode
Definition: MWAWInputStream.hxx:89
shared_ptr< MWAWInputStream > m_resourceFork
the resource fork
Definition: MWAWInputStream.hxx:242
std::vector< std::string > getOLENames()
return the list of all ole zone
Definition: MWAWInputStream.cxx:615
long m_readLimit
actual section limit (-1 if no limit)
Definition: MWAWInputStream.hxx:233
long size() const
returns the stream size
Definition: MWAWInputStream.hxx:104
bool m_inverseRead
big or normal endian
Definition: MWAWInputStream.hxx:230
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:240
WPXInputStream * getSubStream(const char *)
Tries to extract a stream from a structured document.
Definition: MWAWInputStream.hxx:285
long tell()
returns actual offset position
Definition: MWAWInputStream.hxx:261
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.hxx:270
shared_ptr< libmwawOLE::Storage > m_storageOLE
the ole storage
Definition: MWAWInputStream.hxx:244
bool unzipStream()
unzip the data in the file is a zip file of a mac file
Definition: MWAWInputStream.cxx:410
static uint8_t readU8(WPXInputStream *stream)
internal function used to read a byte
Definition: MWAWInputStream.cxx:217
shared_ptr< MWAWInputStream > getResourceForkStream()
returns the resource fork if find
Definition: MWAWInputStream.hxx:194
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:248
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: MWAWInputStream.cxx:199
long m_streamSize
the stream size
Definition: MWAWInputStream.hxx:227
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.cxx:155
bool isOLEStream()
Analyses the content of the input stream to see whether it is an Zip/OLE2 storage.
Definition: MWAWInputStream.hxx:293
bool createStorageOLE()
creates a storage ole
Definition: MWAWInputStream.cxx:637
std::vector< long > m_prevLimits
list of previous limits
Definition: MWAWInputStream.hxx:235
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition: MWAWInputStream.hxx:108
bool hasResourceFork() const
returns true if the resource fork block exists
Definition: MWAWInputStream.hxx:190
std::string m_fInfoType
finder info type
Definition: MWAWInputStream.hxx:238
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:118
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:132
MWAWInputStream(shared_ptr< WPXInputStream > inp, bool inverted)
creates a stream with given endian from
Definition: MWAWInputStream.cxx:47
MWAWStringStream(const unsigned char *data, const unsigned long dataSize)
constructor
Definition: MWAWInputStream.cxx:686
volatile long m_offset
the actual offset in the buffer
Definition: MWAWInputStream.hxx:308
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition: MWAWInputStream.cxx:106
bool readEndDataBlock(WPXBinaryData &data)
reads a WPXBinaryData from actPos to the end of the section/file
Definition: MWAWInputStream.cxx:675
~MWAWStringStream()
destructor
Definition: MWAWInputStream.hxx:254
~MWAWInputStream()
destructor
Definition: MWAWInputStream.cxx:82
bool getFinderInfo(std::string &type, std::string &creator) const
returns the finder info type and creator (if known)
Definition: MWAWInputStream.hxx:171
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:656

Generated on Fri May 2 2014 15:21:31 for libmwaw by doxygen 1.8.5