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  long size() const {
101  return m_streamSize;
102  }
104  bool checkPosition(long pos) const {
105  if (pos < 0) return false;
106  if (m_readLimit > 0 && pos > m_readLimit) return false;
107  return pos<=m_streamSize;
108  }
110  bool atEOS();
111 
115  void pushLimit(long newLimit) {
116  m_prevLimits.push_back(m_readLimit);
117  m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
118  }
120  void popLimit() {
121  if (m_prevLimits.size()) {
122  m_readLimit = m_prevLimits.back();
123  m_prevLimits.pop_back();
124  } else m_readLimit = -1;
125  }
126 
127  //
128  // get data
129  //
130 
132  unsigned long readULong(int num) {
133  return readULong(m_stream.get(), num, 0, m_inverseRead);
134  }
136  long readLong(int num);
137 
141  const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
145  static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
146 
148  bool readDataBlock(long size, WPXBinaryData &data);
150  bool readEndDataBlock(WPXBinaryData &data);
151 
152  //
153  // OLE access
154  //
155 
157  bool isOLEStream();
159  std::vector<std::string> getOLENames();
161  shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
162 
163  //
164  // Finder Info access
165  //
167  bool getFinderInfo(std::string &type, std::string &creator) const {
168  if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
169  type = creator = "";
170  return false;
171  }
172  type = m_fInfoType;
173  creator = m_fInfoCreator;
174  return true;
175  }
176 
177  //
178  // Resource Fork access
179  //
180 
182  bool hasDataFork() const {
183  return bool(m_stream);
184  }
186  bool hasResourceFork() const {
187  return bool(m_resourceFork);
188  }
190  shared_ptr<MWAWInputStream> getResourceForkStream() {
191  return m_resourceFork;
192  }
193 
194 
195 protected:
197  void updateStreamSize();
199  static uint8_t readU8(WPXInputStream *stream);
200 
202  bool createStorageOLE();
203 
205  bool unBinHex();
207  bool unzipStream();
209  bool unMacMIME();
211  bool unMacMIME(MWAWInputStream *input,
212  shared_ptr<WPXInputStream> &dataInput,
213  shared_ptr<WPXInputStream> &rsrcInput) const;
214 
215 private:
216  MWAWInputStream(MWAWInputStream const &orig);
218 
219 protected:
221  shared_ptr<WPXInputStream> m_stream;
224 
227 
231  std::vector<long> m_prevLimits;
232 
234  mutable std::string m_fInfoType;
236  mutable std::string m_fInfoCreator;
238  shared_ptr<MWAWInputStream> m_resourceFork;
240  shared_ptr<libmwawOLE::Storage> m_storageOLE;
241 };
242 
244 class MWAWStringStream: public WPXInputStream
245 {
246 public:
248  MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
251 
255  const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
257  long tell() {
258  return m_offset;
259  }
264  int seek(long offset, WPX_SEEK_TYPE seekType);
266  bool atEOS() {
267  return ((long)m_offset >= (long)m_buffer.size());
268  }
269 
275  return false;
276  }
281  WPXInputStream *getSubStream(const char *) {
282  return 0;
283  }
284 
289  bool isOLEStream() {
290  return isStructuredDocument();
291  }
296  WPXInputStream *getDocumentOLEStream(const char *name) {
297  return getSubStream(name);
298  }
299 
300 private:
302  std::vector<unsigned char> m_buffer;
304  volatile long m_offset;
305 
308 };
309 
310 #endif
311 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Mon Jul 1 2013 23:57:59 for libmwaw by doxygen 1.8.4