StarZone.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 /* libstaroffice
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 /*
35  * StarZone zone of StarOffice document
36  *
37  */
38 #ifndef STAR_ZONE
39 # define STAR_ZONE
40 
41 #include <vector>
42 #include <stack>
43 
45 
46 #include "STOFFDebug.hxx"
47 #include "StarEncoding.hxx"
48 
49 class StarEncryption;
50 
56 class StarZone
57 {
58 public:
60  StarZone(STOFFInputStreamPtr input, std::string const &ascName, std::string const &zoneName, char const *password);
62  virtual ~StarZone();
64  bool readSWHeader();
65 
67  bool checkEncryption(uint32_t date, uint32_t time, std::vector<uint8_t> const &passwd);
69  bool openSDRHeader(std::string &magic);
71  bool closeSDRHeader(std::string const &debugName);
72 
74  bool openSCHHeader();
76  bool closeSCHHeader(std::string const &debugName);
77 
81  bool closeVersionCompatHeader(std::string const &debugName);
82 
84  int getVersion() const
85  {
86  return m_version;
87  }
89  int getDocumentVersion() const
90  {
91  return m_documentVersion;
92  }
94  int getHeaderVersion() const
95  {
96  return m_headerVersionStack.empty() ? 0 : m_headerVersionStack.top();
97  }
99  int isCompatibleWith(int vers) const
100  {
101  return m_documentVersion>=vers;
102  }
104  int isCompatibleWith(int vers1, int vers2) const
105  {
106  return m_documentVersion>=vers1 && m_documentVersion<vers2;
107  }
109  int isCompatibleWith(int vers1, int vers2, int vers3) const
110  {
111  return (m_documentVersion>=vers1 && m_documentVersion<vers2) ||
112  m_documentVersion>=vers3;
113  }
115  int isCompatibleWith(int vers1, int vers2, int vers3, int vers4) const
116  {
117  return (m_documentVersion>=vers1 && m_documentVersion<vers2) ||
118  (m_documentVersion>=vers3 && m_documentVersion<vers4);
119  }
122  {
123  return m_encoding;
124  }
127  {
128  m_encoding=encod;
129  }
131  int getGuiType() const
132  {
133  return m_guiType;
134  }
136  void setGuiType(int type)
137  {
138  m_guiType=type;
139  }
140  //
141  // basic
142  //
143 
145  bool openRecord();
147  bool closeRecord(std::string const &debugName)
148  {
149  return closeRecord(' ', debugName);
150  }
152  bool openDummyRecord();
155  {
156  return closeRecord('@', "Entries(BadDummy)");
157  }
158  //
159  // sc record
160  //
161 
163  bool openSCRecord();
165  bool closeSCRecord(std::string const &debugName)
166  {
167  return closeRecord('_', debugName);
168  }
169 
170  //
171  // sw record
172  //
173 
175  bool openSWRecord(char &type);
177  bool closeSWRecord(char type, std::string const &debugName)
178  {
179  return closeRecord(type, debugName);
180  }
181 
182  //
183  // sfx record
184  //
185 
187  bool openSfxRecord(char &type);
189  bool closeSfxRecord(char type, std::string const &debugName)
190  {
191  return closeRecord(type, debugName);
192  }
193 
195  int getRecordLevel() const
196  {
197  return (int) m_positionStack.size();
198  }
201  {
202  if (m_positionStack.empty()) {
203  STOFF_DEBUG_MSG(("StarZone::getRecordLastPosition: can not find last position\n"));
204  return 0;
205  }
206  return m_positionStack.top();
207  }
208 
210  unsigned char openFlagZone();
212  void closeFlagZone();
214  long getFlagLastPosition() const
215  {
216  return m_flagEndZone;
217  }
218 
220  bool readString(std::vector<uint32_t> &string, int encoding=-1) const;
222  bool readStringsPool();
224  bool getPoolName(int poolId, librevenge::RVNGString &res) const
225  {
226  res="";
227  if (poolId>=0 && poolId<(int) m_poolList.size()) {
228  res=m_poolList[size_t(poolId)];
229  return true;
230  }
231  if (poolId==0xFFF0) return true;
232  STOFF_DEBUG_MSG(("StarZone::getPoolName: can not find pool name for %d\n", poolId));
233  return false;
234  }
237  {
238  return m_input;
239  }
241  void setInput(STOFFInputStreamPtr input);
244  {
245  return m_ascii;
246  }
248  std::string const &name() const
249  {
250  return m_zoneName;
251  }
252 protected:
253  //
254  // low level
255  //
256 
258  bool readRecordSizes(long pos);
260  bool closeRecord(char type, std::string const &debugName);
261 
262  //
263  // data
264  //
265 
275  std::stack<int> m_headerVersionStack;
281  shared_ptr<StarEncryption> m_encryption;
283  std::string m_asciiName;
285  std::string m_zoneName;
286 
288  std::stack<char> m_typeStack;
290  std::stack<long> m_positionStack;
292  std::map<long, long> m_beginToEndMap;
295 
297  std::vector<librevenge::RVNGString> m_poolList;
298 };
299 #endif
300 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool readRecordSizes(long pos)
try to read the record sizes
Definition: StarZone.cxx:624
long getFlagLastPosition() const
returns the flag last position
Definition: StarZone.hxx:214
bool openDummyRecord()
open a dummy record
Definition: StarZone.cxx:432
std::map< long, long > m_beginToEndMap
other position to end position zone
Definition: StarZone.hxx:292
int getGuiType() const
returns the zone GUI type
Definition: StarZone.hxx:131
bool openSCRecord()
try to open a SC record: size (32 bytes) + size bytes
Definition: StarZone.cxx:470
void closeFlagZone()
close the cflag zone
Definition: StarZone.cxx:605
bool openSWRecord(char &type)
try to open a SW record: type + size (24 bytes)
Definition: StarZone.cxx:494
bool closeSCRecord(std::string const &debugName)
try to close a record
Definition: StarZone.hxx:165
int getVersion() const
returns the StarOffice version: 3-5
Definition: StarZone.hxx:84
STOFFInputStreamPtr m_input
the input stream
Definition: StarZone.hxx:267
shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition: libstaroffice_internal.hxx:482
long m_flagEndZone
end of a cflags zone
Definition: StarZone.hxx:294
int m_documentVersion
the document version
Definition: StarZone.hxx:273
Definition: STOFFDebug.hxx:198
shared_ptr< StarEncryption > m_encryption
the encryption
Definition: StarZone.hxx:281
long getRecordLastPosition() const
returns the actual record last position
Definition: StarZone.hxx:200
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
StarEncoding::Encoding m_encoding
the zone encoding
Definition: StarZone.hxx:277
bool closeSWRecord(char type, std::string const &debugName)
try to close a record
Definition: StarZone.hxx:177
std::stack< long > m_positionStack
the position stack
Definition: StarZone.hxx:290
bool closeSfxRecord(char type, std::string const &debugName)
try to close a record
Definition: StarZone.hxx:189
bool closeSCHHeader(std::string const &debugName)
close a zone header
Definition: StarZone.cxx:353
#define STOFF_DEBUG_MSG(M)
Definition: libstaroffice_internal.hxx:127
int m_guiType
the zone GUI type
Definition: StarZone.hxx:279
Encoding
the different encoding
Definition: StarEncoding.hxx:54
bool closeSDRHeader(std::string const &debugName)
close a zone header
Definition: StarZone.cxx:423
std::string m_asciiName
the file ascii name
Definition: StarZone.hxx:283
bool getPoolName(int poolId, librevenge::RVNGString &res) const
try to return a pool name
Definition: StarZone.hxx:224
StarEncoding::Encoding getEncoding() const
returns the zone encoding
Definition: StarZone.hxx:121
int isCompatibleWith(int vers) const
checks if the document is compatible with vers
Definition: StarZone.hxx:99
libstoff::DebugFile m_ascii
the ascii zone
Definition: StarZone.hxx:269
std::stack< char > m_typeStack
the type stack
Definition: StarZone.hxx:288
std::string m_zoneName
the zone name
Definition: StarZone.hxx:285
int m_version
the zone version
Definition: StarZone.hxx:271
bool readSWHeader()
read the zone header present in a SW file
Definition: StarZone.cxx:179
StarZone(STOFFInputStreamPtr input, std::string const &ascName, std::string const &zoneName, char const *password)
constructor
Definition: StarZone.cxx:49
bool closeRecord(std::string const &debugName)
try to close a record
Definition: StarZone.hxx:147
int getDocumentVersion() const
returns the StarOffice document version
Definition: StarZone.hxx:89
bool readString(std::vector< uint32_t > &string, int encoding=-1) const
try to read an unicode string
Definition: StarZone.cxx:69
virtual ~StarZone()
destructor
Definition: StarZone.cxx:58
unsigned char openFlagZone()
try to open a cflag zone
Definition: StarZone.cxx:598
STOFFInputStreamPtr input()
return the zone input
Definition: StarZone.hxx:236
bool openSfxRecord(char &type)
try to open a Sfx record: type + size (24 bytes)
Definition: StarZone.cxx:537
bool openSCHHeader()
open a zone header present in a SCH file
Definition: StarZone.cxx:328
void setInput(STOFFInputStreamPtr input)
reset the current input
Definition: StarZone.cxx:63
int isCompatibleWith(int vers1, int vers2) const
checks if the document is compatible with vers1 and not vers2
Definition: StarZone.hxx:104
int getHeaderVersion() const
returns the StarOffice header version (if set)
Definition: StarZone.hxx:94
libstoff::DebugFile & ascii()
returns the ascii file
Definition: StarZone.hxx:243
bool checkEncryption(uint32_t date, uint32_t time, std::vector< uint8_t > const &passwd)
check encryption
Definition: StarZone.cxx:163
std::stack< int > m_headerVersionStack
the header version (for SDR zone)
Definition: StarZone.hxx:275
bool openRecord()
try to open a classic record: size (32 bytes) + size-4 bytes
Definition: StarZone.cxx:442
void setEncoding(StarEncoding::Encoding encod)
sets the zone encoding
Definition: StarZone.hxx:126
bool closeDummyRecord()
close a dummy record
Definition: StarZone.hxx:154
the main class to read/.
Definition: StarEncryption.hxx:51
bool readStringsPool()
try to read a pool of strings
Definition: StarZone.cxx:90
int getRecordLevel() const
returns the record level
Definition: StarZone.hxx:195
bool closeVersionCompatHeader(std::string const &debugName)
close a zone header
Definition: StarZone.cxx:384
void setGuiType(int type)
sets the zone GUI type
Definition: StarZone.hxx:136
std::vector< librevenge::RVNGString > m_poolList
the pool name list
Definition: StarZone.hxx:297
a zone in a StarOffice file
Definition: StarZone.hxx:56
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
std::string const & name() const
return the zone name
Definition: StarZone.hxx:248
bool openVersionCompatHeader()
open a version compat header (version+size)
Definition: StarZone.cxx:359
bool openSDRHeader(std::string &magic)
open a zone header present in a SDR file
Definition: StarZone.cxx:390

Generated on Sat Feb 20 2016 07:03:17 for libstaroffice by doxygen 1.8.11