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
00035
00036
00037
00038 #ifndef STAR_ZONE
00039 # define STAR_ZONE
00040
00041 #include <vector>
00042 #include <stack>
00043
00044 #include "libstaroffice_internal.hxx"
00045
00046 #include "STOFFDebug.hxx"
00047 #include "StarEncoding.hxx"
00048
00049 class StarEncryption;
00050
00056 class StarZone
00057 {
00058 public:
00060 StarZone(STOFFInputStreamPtr input, std::string const &ascName, std::string const &zoneName, char const *password);
00062 virtual ~StarZone();
00064 bool readSWHeader();
00065
00067 bool checkEncryption(uint32_t date, uint32_t time, std::vector<uint8_t> const &passwd);
00069 bool openSDRHeader(std::string &magic);
00071 bool closeSDRHeader(std::string const &debugName);
00072
00074 bool openSCHHeader();
00076 bool closeSCHHeader(std::string const &debugName);
00077
00079 bool openVersionCompatHeader();
00081 bool closeVersionCompatHeader(std::string const &debugName);
00082
00084 int getVersion() const
00085 {
00086 return m_version;
00087 }
00089 int getDocumentVersion() const
00090 {
00091 return m_documentVersion;
00092 }
00094 int getHeaderVersion() const
00095 {
00096 return m_headerVersionStack.empty() ? 0 : m_headerVersionStack.top();
00097 }
00099 int isCompatibleWith(int vers) const
00100 {
00101 return m_documentVersion>=vers;
00102 }
00104 int isCompatibleWith(int vers1, int vers2) const
00105 {
00106 return m_documentVersion>=vers1 && m_documentVersion<vers2;
00107 }
00109 int isCompatibleWith(int vers1, int vers2, int vers3) const
00110 {
00111 return (m_documentVersion>=vers1 && m_documentVersion<vers2) ||
00112 m_documentVersion>=vers3;
00113 }
00115 int isCompatibleWith(int vers1, int vers2, int vers3, int vers4) const
00116 {
00117 return (m_documentVersion>=vers1 && m_documentVersion<vers2) ||
00118 (m_documentVersion>=vers3 && m_documentVersion<vers4);
00119 }
00121 StarEncoding::Encoding getEncoding() const
00122 {
00123 return m_encoding;
00124 }
00126 void setEncoding(StarEncoding::Encoding encod)
00127 {
00128 m_encoding=encod;
00129 }
00131 int getGuiType() const
00132 {
00133 return m_guiType;
00134 }
00136 void setGuiType(int type)
00137 {
00138 m_guiType=type;
00139 }
00140
00141
00142
00143
00145 bool openRecord();
00147 bool closeRecord(std::string const &debugName)
00148 {
00149 return closeRecord(' ', debugName);
00150 }
00152 bool openDummyRecord();
00154 bool closeDummyRecord()
00155 {
00156 return closeRecord('@', "Entries(BadDummy)");
00157 }
00158
00159
00160
00161
00163 bool openSCRecord();
00165 bool closeSCRecord(std::string const &debugName)
00166 {
00167 return closeRecord('_', debugName);
00168 }
00169
00170
00171
00172
00173
00175 bool openSWRecord(char &type);
00177 bool closeSWRecord(char type, std::string const &debugName)
00178 {
00179 return closeRecord(type, debugName);
00180 }
00181
00182
00183
00184
00185
00187 bool openSfxRecord(char &type);
00189 bool closeSfxRecord(char type, std::string const &debugName)
00190 {
00191 return closeRecord(type, debugName);
00192 }
00193
00195 int getRecordLevel() const
00196 {
00197 return int(m_positionStack.size());
00198 }
00200 long getRecordLastPosition() const
00201 {
00202 if (m_positionStack.empty()) {
00203 STOFF_DEBUG_MSG(("StarZone::getRecordLastPosition: can not find last position\n"));
00204 return 0;
00205 }
00206 return m_positionStack.top();
00207 }
00208
00210 unsigned char openFlagZone();
00212 void closeFlagZone();
00214 long getFlagLastPosition() const
00215 {
00216 return m_flagEndZone;
00217 }
00218
00220 bool readString(std::vector<uint32_t> &string, int encoding=-1) const
00221 {
00222 std::vector<size_t> srcPositions;
00223 return readString(string, srcPositions, encoding);
00224 }
00226 bool readString(std::vector<uint32_t> &string, std::vector<size_t> &srcPositions, int encoding=-1, bool checkEncryption=false) const;
00228 bool readStringsPool();
00230 bool getPoolName(int poolId, librevenge::RVNGString &res) const
00231 {
00232 res="";
00233 if (poolId>=0 && poolId<int(m_poolList.size())) {
00234 res=m_poolList[size_t(poolId)];
00235 return true;
00236 }
00237 if (poolId==0xFFF0) return true;
00238 STOFF_DEBUG_MSG(("StarZone::getPoolName: can not find pool name for %d\n", poolId));
00239 return false;
00240 }
00242 STOFFInputStreamPtr input()
00243 {
00244 return m_input;
00245 }
00247 void setInput(STOFFInputStreamPtr input);
00249 libstoff::DebugFile &ascii()
00250 {
00251 return m_ascii;
00252 }
00254 std::string const &name() const
00255 {
00256 return m_zoneName;
00257 }
00258 protected:
00259
00260
00261
00262
00264 bool readRecordSizes(long pos);
00266 bool closeRecord(char type, std::string const &debugName);
00267
00268
00269
00270
00271
00273 STOFFInputStreamPtr m_input;
00275 libstoff::DebugFile m_ascii;
00277 int m_version;
00279 int m_documentVersion;
00281 std::stack<int> m_headerVersionStack;
00283 StarEncoding::Encoding m_encoding;
00285 int m_guiType;
00287 shared_ptr<StarEncryption> m_encryption;
00289 std::string m_asciiName;
00291 std::string m_zoneName;
00292
00294 std::stack<char> m_typeStack;
00296 std::stack<long> m_positionStack;
00298 std::map<long, long> m_beginToEndMap;
00300 long m_flagEndZone;
00301
00303 std::vector<librevenge::RVNGString> m_poolList;
00304 };
00305 #endif
00306