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-stream/libwpd-stream.h>
41 #include "libmwaw_internal.hxx"
42 
43 namespace libmwawOLE
44 {
45 class Storage;
46 }
47 
48 class WPXBinaryData;
49 
60 {
61 public:
66  MWAWInputStream(shared_ptr<WPXInputStream> inp, bool inverted);
67 
72  MWAWInputStream(WPXInputStream *input, bool inverted, bool checkCompression=false);
75 
77  shared_ptr<WPXInputStream> input() {
78  return m_stream;
79  }
81  bool readInverted() const {
82  return m_inverseRead;
83  }
85  void setReadInverted(bool newVal) {
86  m_inverseRead = newVal;
87  }
88  //
89  // Position: access
90  //
91 
96  int seek(long offset, WPX_SEEK_TYPE seekType);
98  long tell();
100  bool atEOS();
101 
105  void pushLimit(long newLimit) {
106  m_prevLimits.push_back(m_readLimit);
107  m_readLimit = newLimit;
108  }
110  void popLimit() {
111  if (m_prevLimits.size()) {
112  m_readLimit = m_prevLimits.back();
113  m_prevLimits.pop_back();
114  } else m_readLimit = -1;
115  }
116 
117  //
118  // get data
119  //
120 
122  unsigned long readULong(int num) {
123  return readULong(m_stream.get(), num, 0, m_inverseRead);
124  }
126  long readLong(int num);
127 
131  const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
135  static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
136 
138  bool readDataBlock(long size, WPXBinaryData &data);
140  bool readEndDataBlock(WPXBinaryData &data);
141 
142  //
143  // OLE access
144  //
145 
147  bool isOLEStream();
149  std::vector<std::string> getOLENames();
151  shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
152 
153  //
154  // Finder Info access
155  //
157  bool getFinderInfo(std::string &type, std::string &creator) const {
158  if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
159  type = creator = "";
160  return false;
161  }
162  type = m_fInfoType;
163  creator = m_fInfoCreator;
164  return true;
165  }
166 
167  //
168  // Resource Fork access
169  //
170 
172  bool hasDataFork() const {
173  return bool(m_stream);
174  }
176  bool hasResourceFork() const {
177  return bool(m_resourceFork);
178  }
180  shared_ptr<MWAWInputStream> getResourceForkStream() {
181  return m_resourceFork;
182  }
183 
184 
185 protected:
187  static uint8_t readU8(WPXInputStream *stream);
188 
190  bool createStorageOLE();
191 
193  bool unBinHex();
195  bool unzipStream();
197  bool unMacMIME();
199  bool unMacMIME(MWAWInputStream *input,
200  shared_ptr<WPXInputStream> &dataInput,
201  shared_ptr<WPXInputStream> &rsrcInput) const;
202 
203 private:
204  MWAWInputStream(MWAWInputStream const &orig);
206 
207 protected:
209  shared_ptr<WPXInputStream> m_stream;
212 
216  std::vector<long> m_prevLimits;
217 
219  mutable std::string m_fInfoType;
221  mutable std::string m_fInfoCreator;
223  shared_ptr<MWAWInputStream> m_resourceFork;
225  shared_ptr<libmwawOLE::Storage> m_storageOLE;
226 };
227 
229 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
230 
232 class MWAWStringStream: public WPXInputStream
233 {
234 public:
235  MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
237 
238  const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
239  long tell() {
240  return m_offset;
241  }
242  int seek(long offset, WPX_SEEK_TYPE seekType);
243  bool atEOS() {
244  return ((long)m_offset >= (long)m_buffer.size());
245  }
246 
248  return false;
249  }
250  WPXInputStream *getSubStream(const char *) {
251  return 0;
252  }
253 
254  bool isOLEStream() {
255  return isStructuredDocument();
256  }
257  WPXInputStream *getDocumentOLEStream(const char *name) {
258  return getSubStream(name);
259  }
260 
261 private:
262  std::vector<unsigned char> m_buffer;
263  volatile long m_offset;
266 };
267 
268 #endif
269 // 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:399
shared_ptr< MWAWInputStream > getDocumentOLEStream(std::string name)
return a new stream for a ole zone
Definition: MWAWInputStream.cxx:560
int seek(long offset, WPX_SEEK_TYPE seekType)
Definition: MWAWInputStream.cxx:642
bool isStructuredDocument()
Definition: MWAWInputStream.hxx:247
long tell()
returns actual offset position
Definition: MWAWInputStream.cxx:85
bool hasDataFork() const
returns true if the data fork block exists
Definition: MWAWInputStream.hxx:172
class used to read/parse an OLE file
Definition: MWAWOLEStream.hxx:48
shared_ptr< WPXInputStream > m_stream
the initial input
Definition: MWAWInputStream.hxx:209
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
bool readInverted() const
returns the endian mode (see constructor)
Definition: MWAWInputStream.hxx:81
void popLimit()
pops a section defined by pushLimit
Definition: MWAWInputStream.hxx:110
const unsigned char * read(unsigned long numBytes, unsigned long &numBytesRead)
Definition: MWAWInputStream.cxx:660
bool unBinHex()
unbinhex the data in the file is a BinHex 4.0 file of a mac file
Definition: MWAWInputStream.cxx:167
MWAWInputStream & operator=(MWAWInputStream const &orig)
bool isOLEStream()
return true if the stream is ole
Definition: MWAWInputStream.cxx:548
WPXInputStream * getDocumentOLEStream(const char *name)
Definition: MWAWInputStream.hxx:257
std::vector< unsigned char > m_buffer
Definition: MWAWInputStream.hxx:262
void setReadInverted(bool newVal)
sets the endian mode
Definition: MWAWInputStream.hxx:85
shared_ptr< MWAWInputStream > m_resourceFork
the resource fork
Definition: MWAWInputStream.hxx:223
std::vector< std::string > getOLENames()
return the list of all ole zone
Definition: MWAWInputStream.cxx:554
long m_readLimit
actual section limit (-1 if no limit)
Definition: MWAWInputStream.hxx:214
bool m_inverseRead
big or normal endian
Definition: MWAWInputStream.hxx:211
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:59
std::string m_fInfoCreator
finder info type
Definition: MWAWInputStream.hxx:221
WPXInputStream * getSubStream(const char *)
Definition: MWAWInputStream.hxx:250
long tell()
Definition: MWAWInputStream.hxx:239
bool atEOS()
Definition: MWAWInputStream.hxx:243
shared_ptr< libmwawOLE::Storage > m_storageOLE
the ole storage
Definition: MWAWInputStream.hxx:225
bool unzipStream()
unzip the data in the file is a zip file of a mac file
Definition: MWAWInputStream.cxx:349
static uint8_t readU8(WPXInputStream *stream)
internal function used to read a byte
Definition: MWAWInputStream.cxx:149
shared_ptr< MWAWInputStream > getResourceForkStream()
returns the resource fork if find
Definition: MWAWInputStream.hxx:180
shared_ptr< WPXInputStream > input()
returns the basic WPXInputStream
Definition: MWAWInputStream.hxx:77
an internal class used to return the OLE/Zip InputStream
Definition: MWAWInputStream.hxx:232
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: MWAWInputStream.cxx:131
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.cxx:111
bool isOLEStream()
Definition: MWAWInputStream.hxx:254
bool createStorageOLE()
creates a storage ole
Definition: MWAWInputStream.cxx:576
std::vector< long > m_prevLimits
list of previous limits
Definition: MWAWInputStream.hxx:216
bool hasResourceFork() const
returns true if the resource fork block exists
Definition: MWAWInputStream.hxx:176
std::string m_fInfoType
finder info type
Definition: MWAWInputStream.hxx:219
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:78
void pushLimit(long newLimit)
defines a new section in the file (from actualPos to newLimit) next call of seek, tell...
Definition: MWAWInputStream.hxx:105
int seek(long offset, WPX_SEEK_TYPE seekType)
seeks to a offset position, from actual or beginning position
Definition: MWAWInputStream.cxx:92
MWAWInputStream(shared_ptr< WPXInputStream > inp, bool inverted)
creates a stream with given endian from
Definition: MWAWInputStream.cxx:45
MWAWStringStream(const unsigned char *data, const unsigned long dataSize)
Definition: MWAWInputStream.cxx:636
volatile long m_offset
Definition: MWAWInputStream.hxx:263
bool readEndDataBlock(WPXBinaryData &data)
reads a WPXBinaryData from actPos to the end of the section/file
Definition: MWAWInputStream.cxx:619
~MWAWStringStream()
Definition: MWAWInputStream.hxx:236
~MWAWInputStream()
destructor
Definition: MWAWInputStream.cxx:74
bool getFinderInfo(std::string &type, std::string &creator) const
returns the finder info type and creator (if known)
Definition: MWAWInputStream.hxx:157
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition: MWAWInputStream.hxx:122
bool readDataBlock(long size, WPXBinaryData &data)
reads a WPXBinaryData with a given size in the actual section/file
Definition: MWAWInputStream.cxx:595

Generated for libmwaw by doxygen 1.8.5