StarZone.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libstaroffice
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /*
00035  * StarZone zone of StarOffice document
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   // basic
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   // sc record
00160   //
00161 
00163   bool openSCRecord();
00165   bool closeSCRecord(std::string const &debugName)
00166   {
00167     return closeRecord('_', debugName);
00168   }
00169 
00170   //
00171   // sw record
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   // sfx record
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   // low level
00261   //
00262 
00264   bool readRecordSizes(long pos);
00266   bool closeRecord(char type, std::string const &debugName);
00267 
00268   //
00269   // data
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 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: