summaryrefslogtreecommitdiff
path: root/src/lib/SDWDocument.cpp
blob: 695ce8f2fc8d18269dc0e448d622948147a71af8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* -*- 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, const char *password)
{
	SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n"));
	if (!input->isOLEStream())
		return SDW_CONFIDENCE_NONE;
	WPXInputStream *starWriterDocument = input->getDocumentOLEStream("StarWriterDocument");
	if (!starWriterDocument)
		return SDW_CONFIDENCE_NONE;

	SDWHeader header(starWriterDocument, password);
	if (!header.isValid())
	{
		delete 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: */