MWAWInputStream.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef MWAW_INPUT_STREAM_H
#define MWAW_INPUT_STREAM_H
#include <string>
#include <vector>
#include <libwpd/libwpd.h>
#include <libwpd-stream/libwpd-stream.h>
#include "libmwaw_internal.hxx"
namespace libmwawOLE
{
class Storage;
}
class WPXBinaryData;
class MWAWInputStream
{
public:
MWAWInputStream(shared_ptr<WPXInputStream> inp, bool inverted);
MWAWInputStream(WPXInputStream *input, bool inverted, bool checkCompression=false);
~MWAWInputStream();
shared_ptr<WPXInputStream> input() {
return m_stream;
}
static shared_ptr<MWAWInputStream> get(WPXBinaryData const &data, bool inverted);
bool readInverted() const {
return m_inverseRead;
}
void setReadInverted(bool newVal) {
m_inverseRead = newVal;
}
//
// Position: access
//
int seek(long offset, WPX_SEEK_TYPE seekType);
long tell();
long size() const {
return m_streamSize;
}
bool checkPosition(long pos) const {
if (pos < 0) return false;
if (m_readLimit > 0 && pos > m_readLimit) return false;
return pos<=m_streamSize;
}
bool atEOS();
void pushLimit(long newLimit) {
m_prevLimits.push_back(m_readLimit);
m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
}
void popLimit() {
if (m_prevLimits.size()) {
m_readLimit = m_prevLimits.back();
m_prevLimits.pop_back();
} else m_readLimit = -1;
}
//
// get data
//
unsigned long readULong(int num) {
return readULong(m_stream.get(), num, 0, m_inverseRead);
}
long readLong(int num);
const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
bool readDataBlock(long size, WPXBinaryData &data);
bool readEndDataBlock(WPXBinaryData &data);
//
// OLE access
//
bool isOLEStream();
std::vector<std::string> getOLENames();
shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
//
// Finder Info access
//
bool getFinderInfo(std::string &type, std::string &creator) const {
if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
type = creator = "";
return false;
}
type = m_fInfoType;
creator = m_fInfoCreator;
return true;
}
//
// Resource Fork access
//
bool hasDataFork() const {
return bool(m_stream);
}
bool hasResourceFork() const {
return bool(m_resourceFork);
}
shared_ptr<MWAWInputStream> getResourceForkStream() {
return m_resourceFork;
}
protected:
void updateStreamSize();
static uint8_t readU8(WPXInputStream *stream);
bool createStorageOLE();
bool unBinHex();
bool unzipStream();
bool unMacMIME();
bool unMacMIME(MWAWInputStream *input,
shared_ptr<WPXInputStream> &dataInput,
shared_ptr<WPXInputStream> &rsrcInput) const;
private:
MWAWInputStream(MWAWInputStream const &orig);
MWAWInputStream &operator=(MWAWInputStream const &orig);
protected:
shared_ptr<WPXInputStream> m_stream;
long m_streamSize;
bool m_inverseRead;
long m_readLimit;
std::vector<long> m_prevLimits;
mutable std::string m_fInfoType;
mutable std::string m_fInfoCreator;
shared_ptr<MWAWInputStream> m_resourceFork;
shared_ptr<libmwawOLE::Storage> m_storageOLE;
};
class MWAWStringStream: public WPXInputStream
{
public:
MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
~MWAWStringStream() { }
const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
long tell() {
return m_offset;
}
int seek(long offset, WPX_SEEK_TYPE seekType);
bool atEOS() {
return ((long)m_offset >= (long)m_buffer.size());
}
bool isStructuredDocument() {
return false;
}
WPXInputStream *getSubStream(const char *) {
return 0;
}
bool isOLEStream() {
return isStructuredDocument();
}
WPXInputStream *getDocumentOLEStream(const char *name) {
return getSubStream(name);
}
private:
std::vector<unsigned char> m_buffer;
volatile long m_offset;
MWAWStringStream(const MWAWStringStream &);
MWAWStringStream &operator=(const MWAWStringStream &);
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWInputStream::unMacMIME
bool unMacMIME()
check if some stream are in MacMIME format, if so de MacMIME
Definition: MWAWInputStream.cxx:460
MWAWInputStream::getDocumentOLEStream
shared_ptr< MWAWInputStream > getDocumentOLEStream(std::string name)
return a new stream for a ole zone
Definition: MWAWInputStream.cxx:621
MWAWStringStream::seek
int seek(long offset, WPX_SEEK_TYPE seekType)
seeks to a offset position, from actual or beginning position
Definition: MWAWInputStream.cxx:692
MWAWStringStream::isStructuredDocument
bool isStructuredDocument()
Analyses the content of the input stream to see whether it is an Zip/OLE2 storage.
Definition: MWAWInputStream.hxx:278
MWAWInputStream::tell
long tell()
returns actual offset position
Definition: MWAWInputStream.cxx:125
MWAWInputStream::hasDataFork
bool hasDataFork() const
returns true if the data fork block exists
Definition: MWAWInputStream.hxx:186
libmwawOLE::Storage
class used to read/parse an OLE file
Definition: MWAWOLEStream.hxx:48
MWAWInputStream::m_stream
shared_ptr< WPXInputStream > m_stream
the initial input
Definition: MWAWInputStream.hxx:225
libmwaw_internal.hxx
MWAWInputStream::readInverted
bool readInverted() const
returns the endian mode (see constructor)
Definition: MWAWInputStream.hxx:85
MWAWInputStream::popLimit
void popLimit()
pops a section defined by pushLimit
Definition: MWAWInputStream.hxx:124
MWAWStringStream::read
const unsigned char * read(unsigned long numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:712
MWAWInputStream::unBinHex
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 & operator=(MWAWInputStream const &orig)
MWAWInputStream::isOLEStream
bool isOLEStream()
return true if the stream is ole
Definition: MWAWInputStream.cxx:609
MWAWStringStream::getDocumentOLEStream
WPXInputStream * getDocumentOLEStream(const char *name)
Tries to extract a stream from a structured document.
Definition: MWAWInputStream.hxx:300
MWAWStringStream::m_buffer
std::vector< unsigned char > m_buffer
a buffer which contains the data
Definition: MWAWInputStream.hxx:306
MWAWInputStream::setReadInverted
void setReadInverted(bool newVal)
sets the endian mode
Definition: MWAWInputStream.hxx:89
MWAWInputStream::m_resourceFork
shared_ptr< MWAWInputStream > m_resourceFork
the resource fork
Definition: MWAWInputStream.hxx:242
MWAWInputStream::getOLENames
std::vector< std::string > getOLENames()
return the list of all ole zone
Definition: MWAWInputStream.cxx:615
MWAWInputStream::m_readLimit
long m_readLimit
actual section limit (-1 if no limit)
Definition: MWAWInputStream.hxx:233
MWAWInputStream::size
long size() const
returns the stream size
Definition: MWAWInputStream.hxx:104
MWAWInputStream::m_inverseRead
bool m_inverseRead
big or normal endian
Definition: MWAWInputStream.hxx:230
MWAWStringStream::operator=
MWAWStringStream & operator=(const MWAWStringStream &)
MWAWInputStream
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
MWAWInputStream::m_fInfoCreator
std::string m_fInfoCreator
finder info type
Definition: MWAWInputStream.hxx:240
MWAWStringStream::getSubStream
WPXInputStream * getSubStream(const char *)
Tries to extract a stream from a structured document.
Definition: MWAWInputStream.hxx:285
MWAWStringStream::tell
long tell()
returns actual offset position
Definition: MWAWInputStream.hxx:261
MWAWStringStream::atEOS
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.hxx:270
MWAWInputStream::m_storageOLE
shared_ptr< libmwawOLE::Storage > m_storageOLE
the ole storage
Definition: MWAWInputStream.hxx:244
MWAWInputStream::unzipStream
bool unzipStream()
unzip the data in the file is a zip file of a mac file
Definition: MWAWInputStream.cxx:410
MWAWInputStream::readU8
static uint8_t readU8(WPXInputStream *stream)
internal function used to read a byte
Definition: MWAWInputStream.cxx:217
MWAWInputStream::getResourceForkStream
shared_ptr< MWAWInputStream > getResourceForkStream()
returns the resource fork if find
Definition: MWAWInputStream.hxx:194
MWAWInputStream::input
shared_ptr< WPXInputStream > input()
returns the basic WPXInputStream
Definition: MWAWInputStream.hxx:78
MWAWStringStream
an internal class used to return the OLE/Zip InputStream
Definition: MWAWInputStream.hxx:248
MWAWInputStream::readLong
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: MWAWInputStream.cxx:199
MWAWInputStream::m_streamSize
long m_streamSize
the stream size
Definition: MWAWInputStream.hxx:227
MWAWInputStream::atEOS
bool atEOS()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.cxx:155
MWAWStringStream::isOLEStream
bool isOLEStream()
Analyses the content of the input stream to see whether it is an Zip/OLE2 storage.
Definition: MWAWInputStream.hxx:293
MWAWInputStream::createStorageOLE
bool createStorageOLE()
creates a storage ole
Definition: MWAWInputStream.cxx:637
MWAWInputStream::m_prevLimits
std::vector< long > m_prevLimits
list of previous limits
Definition: MWAWInputStream.hxx:235
MWAWInputStream::checkPosition
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition: MWAWInputStream.hxx:108
MWAWInputStream::hasResourceFork
bool hasResourceFork() const
returns true if the resource fork block exists
Definition: MWAWInputStream.hxx:190
MWAWInputStream::m_fInfoType
std::string m_fInfoType
finder info type
Definition: MWAWInputStream.hxx:238
MWAWInputStream::read
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:118
MWAWInputStream::pushLimit
void pushLimit(long newLimit)
defines a new section in the file (from actualPos to newLimit) next call of seek, tell...
Definition: MWAWInputStream.hxx:119
MWAWInputStream::seek
int seek(long offset, WPX_SEEK_TYPE seekType)
seeks to a offset position, from actual or beginning position
Definition: MWAWInputStream.cxx:132
MWAWInputStream::MWAWInputStream
MWAWInputStream(shared_ptr< WPXInputStream > inp, bool inverted)
creates a stream with given endian from
Definition: MWAWInputStream.cxx:47
MWAWStringStream::MWAWStringStream
MWAWStringStream(const unsigned char *data, const unsigned long dataSize)
constructor
Definition: MWAWInputStream.cxx:686
MWAWStringStream::m_offset
volatile long m_offset
the actual offset in the buffer
Definition: MWAWInputStream.hxx:308
MWAWInputStream::updateStreamSize
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition: MWAWInputStream.cxx:106
MWAWInputStream::readEndDataBlock
bool readEndDataBlock(WPXBinaryData &data)
reads a WPXBinaryData from actPos to the end of the section/file
Definition: MWAWInputStream.cxx:675
MWAWStringStream::~MWAWStringStream
~MWAWStringStream()
destructor
Definition: MWAWInputStream.hxx:254
MWAWInputStream::~MWAWInputStream
~MWAWInputStream()
destructor
Definition: MWAWInputStream.cxx:82
MWAWInputStream::getFinderInfo
bool getFinderInfo(std::string &type, std::string &creator) const
returns the finder info type and creator (if known)
Definition: MWAWInputStream.hxx:171
MWAWInputStream::readULong
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition: MWAWInputStream.hxx:136
MWAWInputStream::readDataBlock
bool readDataBlock(long size, WPXBinaryData &data)
reads a WPXBinaryData with a given size in the actual section/file
Definition: MWAWInputStream.cxx:656