StarZone.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 -*- */
/* libstaroffice
* 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.
*/
/*
* StarZone zone of StarOffice document
*
*/
#ifndef STAR_ZONE
# define STAR_ZONE
#include <vector>
#include <stack>
#include "libstaroffice_internal.hxx"
#include "STOFFDebug.hxx"
#include "StarEncoding.hxx"
class StarEncryption;
class StarZone
{
public:
StarZone(STOFFInputStreamPtr const &input, std::string const &ascName, std::string const &zoneName, char const *password);
virtual ~StarZone();
bool readSWHeader();
bool checkEncryption(uint32_t date, uint32_t time, std::vector<uint8_t> const &passwd);
bool openSDRHeader(std::string &magic);
bool closeSDRHeader(std::string const &debugName);
bool openSCHHeader();
bool closeSCHHeader(std::string const &debugName);
bool openVersionCompatHeader();
bool closeVersionCompatHeader(std::string const &debugName);
int getVersion() const
{
return m_version;
}
int getDocumentVersion() const
{
return m_documentVersion;
}
int getHeaderVersion() const
{
return m_headerVersionStack.empty() ? 0 : m_headerVersionStack.top();
}
int isCompatibleWith(int vers) const
{
return m_documentVersion>=vers;
}
int isCompatibleWith(int vers1, int vers2) const
{
return m_documentVersion>=vers1 && m_documentVersion<vers2;
}
int isCompatibleWith(int vers1, int vers2, int vers3) const
{
return (m_documentVersion>=vers1 && m_documentVersion<vers2) ||
m_documentVersion>=vers3;
}
int isCompatibleWith(int vers1, int vers2, int vers3, int vers4) const
{
return (m_documentVersion>=vers1 && m_documentVersion<vers2) ||
(m_documentVersion>=vers3 && m_documentVersion<vers4);
}
StarEncoding::Encoding getEncoding() const
{
return m_encoding;
}
void setEncoding(StarEncoding::Encoding encod)
{
m_encoding=encod;
}
int getGuiType() const
{
return m_guiType;
}
void setGuiType(int type)
{
m_guiType=type;
}
//
// basic
//
bool openRecord();
bool closeRecord(std::string const &debugName)
{
return closeRecord(' ', debugName);
}
bool openDummyRecord();
bool closeDummyRecord()
{
return closeRecord('@', "Entries(BadDummy)");
}
//
// sc record
//
bool openSCRecord();
bool closeSCRecord(std::string const &debugName)
{
return closeRecord('_', debugName);
}
//
// sw record
//
bool openSWRecord(unsigned char &type);
bool closeSWRecord(unsigned char type, std::string const &debugName)
{
return closeRecord(type, debugName);
}
//
// sfx record
//
bool openSfxRecord(unsigned char &type);
bool closeSfxRecord(unsigned char type, std::string const &debugName)
{
return closeRecord(type, debugName);
}
int getRecordLevel() const
{
return int(m_positionStack.size());
}
long getRecordLastPosition() const
{
if (m_positionStack.empty()) {
STOFF_DEBUG_MSG(("StarZone::getRecordLastPosition: can not find last position\n"));
return 0;
}
return m_positionStack.top();
}
unsigned char openFlagZone();
void closeFlagZone();
long getFlagLastPosition() const
{
return m_flagEndZone;
}
bool readString(std::vector<uint32_t> &string, int encoding=-1) const
{
std::vector<size_t> srcPositions;
return readString(string, srcPositions, encoding);
}
bool readString(std::vector<uint32_t> &string, std::vector<size_t> &srcPositions, int encoding=-1, bool checkEncryption=false) const;
bool readStringsPool();
int getNumPoolNames() const
{
return int(m_poolList.size());
}
bool getPoolName(int poolId, librevenge::RVNGString &res) const
{
res="";
if (poolId>=0 && poolId<int(m_poolList.size())) {
res=m_poolList[size_t(poolId)];
return true;
}
if (poolId==0xFFF0) return true;
STOFF_DEBUG_MSG(("StarZone::getPoolName: can not find pool name for %d\n", poolId));
return false;
}
STOFFInputStreamPtr input()
{
return m_input;
}
void setInput(STOFFInputStreamPtr input);
libstoff::DebugFile &ascii()
{
return m_ascii;
}
std::string const &name() const
{
return m_zoneName;
}
protected:
//
// low level
//
bool readRecordSizes(long pos);
bool closeRecord(unsigned char type, std::string const &debugName);
//
// data
//
STOFFInputStreamPtr m_input;
libstoff::DebugFile m_ascii;
int m_version;
int m_documentVersion;
std::stack<int> m_headerVersionStack;
StarEncoding::Encoding m_encoding;
int m_guiType;
std::shared_ptr<StarEncryption> m_encryption;
std::string m_asciiName;
std::string m_zoneName;
std::stack<unsigned char> m_typeStack;
std::stack<long> m_positionStack;
std::map<long, long> m_beginToEndMap;
long m_flagEndZone;
std::vector<librevenge::RVNGString> m_poolList;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFDebug.hxx
StarEncoding.hxx
StarEncoding::Encoding
Encoding
the different encoding
Definition StarEncoding.hxx:54
StarEncryption
the main class to read/.
Definition StarEncryption.hxx:52
StarZone::m_flagEndZone
long m_flagEndZone
end of a cflags zone
Definition StarZone.hxx:305
StarZone::closeVersionCompatHeader
bool closeVersionCompatHeader(std::string const &debugName)
close a zone header
Definition StarZone.cxx:399
StarZone::closeSDRHeader
bool closeSDRHeader(std::string const &debugName)
close a zone header
Definition StarZone.cxx:442
StarZone::openSWRecord
bool openSWRecord(unsigned char &type)
try to open a SW record: type + size (24 bytes)
Definition StarZone.cxx:513
StarZone::openSCRecord
bool openSCRecord()
try to open a SC record: size (32 bytes) + size bytes
Definition StarZone.cxx:489
StarZone::openVersionCompatHeader
bool openVersionCompatHeader()
open a version compat header (version+size)
Definition StarZone.cxx:374
StarZone::StarZone
StarZone(STOFFInputStreamPtr const &input, std::string const &ascName, std::string const &zoneName, char const *password)
constructor
Definition StarZone.cxx:51
StarZone::m_headerVersionStack
std::stack< int > m_headerVersionStack
the header version (for SDR zone)
Definition StarZone.hxx:286
StarZone::m_version
int m_version
the zone version
Definition StarZone.hxx:282
StarZone::getPoolName
bool getPoolName(int poolId, librevenge::RVNGString &res) const
try to return a pool name
Definition StarZone.hxx:235
StarZone::closeRecord
bool closeRecord(std::string const &debugName)
try to close a record
Definition StarZone.hxx:147
StarZone::closeSWRecord
bool closeSWRecord(unsigned char type, std::string const &debugName)
try to close a record
Definition StarZone.hxx:177
StarZone::m_poolList
std::vector< librevenge::RVNGString > m_poolList
the pool name list
Definition StarZone.hxx:308
StarZone::m_documentVersion
int m_documentVersion
the document version
Definition StarZone.hxx:284
StarZone::m_input
STOFFInputStreamPtr m_input
the input stream
Definition StarZone.hxx:278
StarZone::readRecordSizes
bool readRecordSizes(long pos)
try to read the record sizes
Definition StarZone.cxx:647
StarZone::m_typeStack
std::stack< unsigned char > m_typeStack
the type stack
Definition StarZone.hxx:299
StarZone::isCompatibleWith
int isCompatibleWith(int vers) const
checks if the document is compatible with vers
Definition StarZone.hxx:99
StarZone::getRecordLastPosition
long getRecordLastPosition() const
returns the actual record last position
Definition StarZone.hxx:200
StarZone::openSDRHeader
bool openSDRHeader(std::string &magic)
open a zone header present in a SDR file
Definition StarZone.cxx:405
StarZone::getHeaderVersion
int getHeaderVersion() const
returns the StarOffice header version (if set)
Definition StarZone.hxx:94
StarZone::openSfxRecord
bool openSfxRecord(unsigned char &type)
try to open a Sfx record: type + size (24 bytes)
Definition StarZone.cxx:560
StarZone::isCompatibleWith
int isCompatibleWith(int vers1, int vers2, int vers3, int vers4) const
checks if the document is compatible with vers1 and not vers2 or vers3 and not vers4
Definition StarZone.hxx:115
StarZone::checkEncryption
bool checkEncryption(uint32_t date, uint32_t time, std::vector< uint8_t > const &passwd)
check encryption
Definition StarZone.cxx:176
StarZone::openRecord
bool openRecord()
try to open a classic record: size (32 bytes) + size-4 bytes
Definition StarZone.cxx:461
StarZone::getGuiType
int getGuiType() const
returns the zone GUI type
Definition StarZone.hxx:131
StarZone::isCompatibleWith
int isCompatibleWith(int vers1, int vers2) const
checks if the document is compatible with vers1 and not vers2
Definition StarZone.hxx:104
StarZone::input
STOFFInputStreamPtr input()
return the zone input
Definition StarZone.hxx:247
StarZone::ascii
libstoff::DebugFile & ascii()
returns the ascii file
Definition StarZone.hxx:254
StarZone::m_asciiName
std::string m_asciiName
the file ascii name
Definition StarZone.hxx:294
StarZone::closeSCHHeader
bool closeSCHHeader(std::string const &debugName)
close a zone header
Definition StarZone.cxx:368
StarZone::closeFlagZone
void closeFlagZone()
close the cflag zone
Definition StarZone.cxx:628
StarZone::getEncoding
StarEncoding::Encoding getEncoding() const
returns the zone encoding
Definition StarZone.hxx:121
StarZone::openSCHHeader
bool openSCHHeader()
open a zone header present in a SCH file
Definition StarZone.cxx:343
StarZone::closeSCRecord
bool closeSCRecord(std::string const &debugName)
try to close a record
Definition StarZone.hxx:165
StarZone::m_encoding
StarEncoding::Encoding m_encoding
the zone encoding
Definition StarZone.hxx:288
StarZone::getVersion
int getVersion() const
returns the StarOffice version: 3-5
Definition StarZone.hxx:84
StarZone::openFlagZone
unsigned char openFlagZone()
try to open a cflag zone
Definition StarZone.cxx:621
StarZone::m_beginToEndMap
std::map< long, long > m_beginToEndMap
other position to end position zone
Definition StarZone.hxx:303
StarZone::closeSfxRecord
bool closeSfxRecord(unsigned char type, std::string const &debugName)
try to close a record
Definition StarZone.hxx:189
StarZone::m_positionStack
std::stack< long > m_positionStack
the position stack
Definition StarZone.hxx:301
StarZone::isCompatibleWith
int isCompatibleWith(int vers1, int vers2, int vers3) const
checks if the document is compatible with vers1 and not vers2 or vers3
Definition StarZone.hxx:109
StarZone::~StarZone
virtual ~StarZone()
destructor
Definition StarZone.cxx:72
StarZone::closeDummyRecord
bool closeDummyRecord()
close a dummy record
Definition StarZone.hxx:154
StarZone::readSWHeader
bool readSWHeader()
read the zone header present in a SW file
Definition StarZone.cxx:192
StarZone::m_encryption
std::shared_ptr< StarEncryption > m_encryption
the encryption
Definition StarZone.hxx:292
StarZone::m_ascii
libstoff::DebugFile m_ascii
the ascii zone
Definition StarZone.hxx:280
StarZone::openDummyRecord
bool openDummyRecord()
open a dummy record
Definition StarZone.cxx:451
StarZone::setInput
void setInput(STOFFInputStreamPtr input)
reset the current input
Definition StarZone.cxx:77
StarZone::getNumPoolNames
int getNumPoolNames() const
return the number of pool name
Definition StarZone.hxx:230
StarZone::setEncoding
void setEncoding(StarEncoding::Encoding encod)
sets the zone encoding
Definition StarZone.hxx:126
StarZone::name
std::string const & name() const
return the zone name
Definition StarZone.hxx:259
StarZone::getDocumentVersion
int getDocumentVersion() const
returns the StarOffice document version
Definition StarZone.hxx:89
StarZone::readStringsPool
bool readStringsPool()
try to read a pool of strings
Definition StarZone.cxx:105
StarZone::setGuiType
void setGuiType(int type)
sets the zone GUI type
Definition StarZone.hxx:136
StarZone::m_zoneName
std::string m_zoneName
the zone name
Definition StarZone.hxx:296
StarZone::getFlagLastPosition
long getFlagLastPosition() const
returns the flag last position
Definition StarZone.hxx:214
StarZone::getRecordLevel
int getRecordLevel() const
returns the record level
Definition StarZone.hxx:195
StarZone::readString
bool readString(std::vector< uint32_t > &string, int encoding=-1) const
try to read an unicode string
Definition StarZone.hxx:220
StarZone::m_guiType
int m_guiType
the zone GUI type
Definition StarZone.hxx:290
libstoff::DebugFile
Definition STOFFDebug.hxx:211
libstaroffice_internal.hxx
STOFFInputStreamPtr
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition libstaroffice_internal.hxx:489
STOFF_DEBUG_MSG
#define STOFF_DEBUG_MSG(M)
Definition libstaroffice_internal.hxx:129