STOFFOLEParser.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  *  freely inspired from istorage :
00036  * ------------------------------------------------------------
00037  *      Generic OLE Zones furnished with a copy of the file header
00038  *
00039  * Compound Storage (32 bit version)
00040  * Storage implementation
00041  *
00042  * This file contains the compound file implementation
00043  * of the storage interface.
00044  *
00045  * Copyright 1999 Francis Beaudet
00046  * Copyright 1999 Sylvain St-Germain
00047  * Copyright 1999 Thuy Nguyen
00048  * Copyright 2005 Mike McCormack
00049  *
00050  * This library is free software; you can redistribute it and/or
00051  * modify it under the terms of the GNU Lesser General Public
00052  * License as published by the Free Software Foundation; either
00053  * version 2.1 of the License, or (at your option) any later version.
00054  *
00055  * This library is distributed in the hope that it will be useful,
00056  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00057  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00058  * Lesser General Public License for more details.
00059  *
00060  * ------------------------------------------------------------
00061  */
00062 
00063 #ifndef STOFF_OLE_PARSER_H
00064 #define STOFF_OLE_PARSER_H
00065 
00066 #include <string>
00067 #include <vector>
00068 
00069 #include <librevenge-stream/librevenge-stream.h>
00070 
00071 #include <libstaroffice/STOFFDocument.hxx>
00072 
00073 #include "libstaroffice_internal.hxx"
00074 #include "STOFFPosition.hxx"
00075 
00076 #include "STOFFDebug.hxx"
00077 
00078 namespace STOFFOLEParserInternal
00079 {
00080 struct State;
00081 }
00082 
00086 class STOFFOLEParser
00087 {
00088 public:
00089   struct OleDirectory;
00090 
00092   STOFFOLEParser();
00093 
00095   ~STOFFOLEParser();
00096 
00099   bool parse(STOFFInputStreamPtr fileInput);
00100 
00102   std::vector<shared_ptr<OleDirectory> > &getDirectoryList();
00104   shared_ptr<OleDirectory> getDirectory(std::string const &dir);
00105 
00107   struct OleContent {
00109     OleContent(std::string const &dir, std::string const &base) :
00110       m_dir(dir), m_base(base), m_isParsed(false), m_position(), m_imageData(), m_imageType("")
00111     {
00112     }
00114     std::string getBaseName()
00115     {
00116       return m_base;
00117     }
00119     std::string getOleName() const
00120     {
00121       if (m_dir.empty()) return m_base;
00122       return m_dir+"/"+m_base;
00123     }
00125     bool isParsed() const
00126     {
00127       return m_isParsed;
00128     }
00130     void setParsed(bool flag=true)
00131     {
00132       m_isParsed=flag;
00133     }
00135     STOFFPosition const &getPosition() const
00136     {
00137       return m_position;
00138     }
00140     void setPosition(STOFFPosition const &pos)
00141     {
00142       m_position=pos;
00143     }
00145     bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
00146     {
00147       if (m_imageData.empty()) {
00148         data.clear();
00149         type="";
00150         return false;
00151       }
00152       data=m_imageData;
00153       type=m_imageType;
00154       return true;
00155     }
00157     void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
00158     {
00159       m_imageData=data;
00160       m_imageType=type;
00161     }
00162   protected:
00164     std::string m_dir;
00166     std::string m_base;
00168     bool m_isParsed;
00170     STOFFPosition m_position;
00172     librevenge::RVNGBinaryData m_imageData;
00174     std::string m_imageType;
00175   };
00176 
00178   struct OleDirectory {
00180     OleDirectory(STOFFInputStreamPtr input, std::string const &dir) : m_input(input), m_dir(dir), m_contentList(), m_kind(STOFFDocument::STOFF_K_UNKNOWN),
00181       m_hasCompObj(false), m_clsName(""), m_clipName(""), m_parsed(false), m_inUse(false) { }
00183     void addNewBase(std::string const &base)
00184     {
00185       if (base=="CompObj")
00186         m_hasCompObj=true;
00187       else
00188         m_contentList.push_back(OleContent(m_dir,base));
00189     }
00191     std::vector<std::string> getUnparsedOles() const
00192     {
00193       std::vector<std::string> res;
00194       for (size_t i=0; i<m_contentList.size(); ++i) {
00195         if (m_contentList[i].isParsed()) continue;
00196         res.push_back(m_contentList[i].getOleName());
00197       }
00198       return res;
00199     }
00201     STOFFInputStreamPtr m_input;
00203     std::string m_dir;
00205     std::vector<OleContent> m_contentList;
00207     STOFFDocument::Kind m_kind;
00209     bool m_hasCompObj;
00211     std::string m_clsName;
00213     std::string m_clipName;
00215     bool m_parsed;
00217     mutable bool m_inUse;
00218   };
00219 
00220 protected:
00222   static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName,
00223                                      libstoff::DebugFile &ascii);
00224 
00226   static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName,
00227                       libstoff::DebugFile &ascii);
00229   static bool readObjInfo(STOFFInputStreamPtr input, std::string const &oleName,
00230                           libstoff::DebugFile &ascii);
00232   bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory);
00233 
00235   static  bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName);
00239   static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content);
00240 
00242   static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName);
00246   static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content);
00247 
00251   bool readContents(STOFFInputStreamPtr input, OleContent &content);
00252 
00258   bool readCONTENTS(STOFFInputStreamPtr input, OleContent &content);
00259 
00260 protected:
00261   //
00262   // data
00263   //
00264 
00266   shared_ptr<STOFFOLEParserInternal::State> m_state;
00267 };
00268 
00269 #endif
00270 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: