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:

Generated on Wed May 7 2014 00:30:21 for libmwaw by doxygen 1.8.3.1