diff options
Diffstat (limited to 'src/lib/SDWDocument.cpp')
-rw-r--r-- | src/lib/SDWDocument.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/lib/SDWDocument.cpp b/src/lib/SDWDocument.cpp new file mode 100644 index 0000000..757d5da --- /dev/null +++ b/src/lib/SDWDocument.cpp @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* libsdw + * Version: MPL 2.0 / LGPLv2.1+ + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Major Contributor(s): + * Copyright (C) 2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2003-2004 Marc Maurer (uwog@uwog.net) + * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) + * Copyright (C) 2006, 2007 Andrew Ziem (andrewziem users sourceforge net) + * + * 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.1 or later + * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are + * applicable instead of those above. + * + * For further information visit http://libsdw.sourceforge.net + */ + +#include <libsdw/libsdw.h> +#include "SDWHeader.h" +#include "SDWParser.h" +#include "libsdw_internal.h" + +/** +\mainpage libsdw documentation +This document contains both the libsdw API specification and the normal libsdw +documentation. +\section api_docs libsdw API documentation +The external libsdw API is provided by the SDWDocument class. This class, combined +with the libwpd's WPXDocumentInterface class, are the only two classes that will be +of interest for the application programmer using libsdw. +\section lib_docs libsdw documentation +If you are interrested in the structure of libsdw itself, this whole document +would be a good starting point for exploring the interals of libsdw. Mind that +this document is a work-in-progress, and will most likely not cover libsdw for +the full 100%. + + \warning When compiled with -DDEBUG_WITH__FILES, code is added to store the results of the parsing in different files: one file by Ole parts and some files to store the read pictures. These files are created in the current repository, therefore it is recommended to launch the tests in an empty repository...*/ + +/** +Analyzes the content of an input stream to see if it can be parsed +\param ip The input stream +\return A confidence value which represents the likelyhood that the content from +the input stream can be parsed +*/ +libsdw::SDWConfidence libsdw::SDWDocument::isFileFormatSupported(WPXInputStream *input) +{ + SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n")); + if (!input->isOLEStream()) + return SDW_CONFIDENCE_NONE; + WPXInputStream *starWriterDocument = input->getDocumentOLEStream("StarWriterDocument"); + if (!starWriterDocument) + return SDW_CONFIDENCE_NONE; + + delete starWriterDocument; + return SDW_CONFIDENCE_NONE; +} + +/** +Checks whether the given password was used to encrypt the document +\param input The input stream +\param password The password used to protect the document or NULL if the document is not protected +\return A value which indicates between the given password and the password that was used to protect the document +*/ +bool libsdw::SDWDocument::verifyPassword(WPXInputStream *input, const char *password) +{ + if (!password) + return false; + if (!input) + return false; + + return false; +} + +/** +Parses the input stream content. It will make callbacks to the functions provided by a +WPXDocumentInterface class implementation when needed. This is often commonly called the +'main parsing routine'. +\param ip The input stream +\param documentInterface A SDWListener implementation +*/ +bool libsdw::SDWDocument::parse(WPXInputStream *input, WPXDocumentInterface * /* documentInterface */, const char *password) +{ + SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n")); + if (!input->isOLEStream()) + return false; + WPXInputStream *starWriterDocument = input->getDocumentOLEStream("StarWriterDocument"); + if (!starWriterDocument) + return false; + if (password && !verifyPassword(input, password)) + return false; + + delete starWriterDocument; + return false; +} + +/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |