Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef MWAW_INPUT_STREAM_H
00035 #define MWAW_INPUT_STREAM_H
00036
00037 #include <string>
00038 #include <vector>
00039
00040 #include <libwpd/libwpd.h>
00041 #include <libwpd-stream/libwpd-stream.h>
00042 #include "libmwaw_internal.hxx"
00043
00044 namespace libmwawOLE
00045 {
00046 class Storage;
00047 }
00048
00049 class WPXBinaryData;
00050
00060 class MWAWInputStream
00061 {
00062 public:
00067 MWAWInputStream(shared_ptr<WPXInputStream> inp, bool inverted);
00068
00073 MWAWInputStream(WPXInputStream *input, bool inverted, bool checkCompression=false);
00075 ~MWAWInputStream();
00076
00078 shared_ptr<WPXInputStream> input() {
00079 return m_stream;
00080 }
00082 static shared_ptr<MWAWInputStream> get(WPXBinaryData const &data, bool inverted);
00083
00085 bool readInverted() const {
00086 return m_inverseRead;
00087 }
00089 void setReadInverted(bool newVal) {
00090 m_inverseRead = newVal;
00091 }
00092
00093
00094
00095
00100 int seek(long offset, WPX_SEEK_TYPE seekType);
00102 long tell();
00104 long size() const {
00105 return m_streamSize;
00106 }
00108 bool checkPosition(long pos) const {
00109 if (pos < 0) return false;
00110 if (m_readLimit > 0 && pos > m_readLimit) return false;
00111 return pos<=m_streamSize;
00112 }
00114 bool atEOS();
00115
00119 void pushLimit(long newLimit) {
00120 m_prevLimits.push_back(m_readLimit);
00121 m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
00122 }
00124 void popLimit() {
00125 if (m_prevLimits.size()) {
00126 m_readLimit = m_prevLimits.back();
00127 m_prevLimits.pop_back();
00128 } else m_readLimit = -1;
00129 }
00130
00131
00132
00133
00134
00136 unsigned long readULong(int num) {
00137 return readULong(m_stream.get(), num, 0, m_inverseRead);
00138 }
00140 long readLong(int num);
00142 bool readDouble(double &res);
00143
00147 const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
00151 static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
00152
00154 bool readDataBlock(long size, WPXBinaryData &data);
00156 bool readEndDataBlock(WPXBinaryData &data);
00157
00158
00159
00160
00161
00163 bool isOLEStream();
00165 std::vector<std::string> getOLENames();
00167 shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
00168
00169
00170
00171
00173 bool getFinderInfo(std::string &type, std::string &creator) const {
00174 if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
00175 type = creator = "";
00176 return false;
00177 }
00178 type = m_fInfoType;
00179 creator = m_fInfoCreator;
00180 return true;
00181 }
00182
00183
00184
00185
00186
00188 bool hasDataFork() const {
00189 return bool(m_stream);
00190 }
00192 bool hasResourceFork() const {
00193 return bool(m_resourceFork);
00194 }
00196 shared_ptr<MWAWInputStream> getResourceForkStream() {
00197 return m_resourceFork;
00198 }
00199
00200
00201 protected:
00203 void updateStreamSize();
00205 static uint8_t readU8(WPXInputStream *stream);
00206
00208 bool createStorageOLE();
00209
00211 bool unBinHex();
00213 bool unzipStream();
00215 bool unMacMIME();
00217 bool unMacMIME(MWAWInputStream *input,
00218 shared_ptr<WPXInputStream> &dataInput,
00219 shared_ptr<WPXInputStream> &rsrcInput) const;
00220
00221 private:
00222 MWAWInputStream(MWAWInputStream const &orig);
00223 MWAWInputStream &operator=(MWAWInputStream const &orig);
00224
00225 protected:
00227 shared_ptr<WPXInputStream> m_stream;
00229 long m_streamSize;
00230
00232 bool m_inverseRead;
00233
00235 long m_readLimit;
00237 std::vector<long> m_prevLimits;
00238
00240 mutable std::string m_fInfoType;
00242 mutable std::string m_fInfoCreator;
00244 shared_ptr<MWAWInputStream> m_resourceFork;
00246 shared_ptr<libmwawOLE::Storage> m_storageOLE;
00247 };
00248
00250 class MWAWStringStream: public WPXInputStream
00251 {
00252 public:
00254 MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
00256 ~MWAWStringStream() { }
00257
00261 const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
00263 long tell() {
00264 return m_offset;
00265 }
00270 int seek(long offset, WPX_SEEK_TYPE seekType);
00272 bool atEOS() {
00273 return ((long)m_offset >= (long)m_buffer.size());
00274 }
00275
00280 bool isStructuredDocument() {
00281 return false;
00282 }
00287 WPXInputStream *getSubStream(const char *) {
00288 return 0;
00289 }
00290
00295 bool isOLEStream() {
00296 return isStructuredDocument();
00297 }
00302 WPXInputStream *getDocumentOLEStream(const char *name) {
00303 return getSubStream(name);
00304 }
00305
00306 private:
00308 std::vector<unsigned char> m_buffer;
00310 volatile long m_offset;
00311
00312 MWAWStringStream(const MWAWStringStream &);
00313 MWAWStringStream &operator=(const MWAWStringStream &);
00314 };
00315
00316 #endif
00317