summaryrefslogtreecommitdiffstats
path: root/reader/src/formats/doc/OleStorage.h
blob: 584ee94dd9886baaf721c2cb689f79217475c0d5 (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
/*
 * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#ifndef __OLESTORAGE_H__
#define __OLESTORAGE_H__

#include <algorithm>
#include <vector>
#include <string>

#include <ZLInputStream.h>

struct OleEntry {
	enum Type {
		DIR = 1,
		STREAM = 2,
		ROOT_DIR = 5,
		LOCK_BYTES =3
	};

	typedef std::vector<unsigned int> Blocks;

	std::string name;
	unsigned int length;
	Type type;
	Blocks blocks;
	bool isBigBlock;
};

class OleStorage {

public:
	static const std::size_t BBD_BLOCK_SIZE;

public:
	OleStorage();
	bool init(shared_ptr<ZLInputStream>, std::size_t streamSize);
	void clear();
	const std::vector<OleEntry> &getEntries() const;
	bool getEntryByName(std::string name, OleEntry &entry) const;

	unsigned int getSectorSize() const;
	unsigned int getShortSectorSize() const;

public: //TODO make private
	bool countFileOffsetOfBlock(const OleEntry &e, unsigned int blockNumber, unsigned int &result) const;

private:
	bool readDIFAT(char *oleBuf);
	bool readBBD(char *oleBuf);
	bool readSBD(char *oleBuf);
	bool readProperties(char *oleBuf);

	bool readAllEntries();
	bool readOleEntry(int propNumber, OleEntry &entry);

private:

	shared_ptr<ZLInputStream> myInputStream;
	unsigned int mySectorSize, myShortSectorSize;

	std::size_t myStreamSize;
	std::vector<int> myDIFAT; //double-indirect file allocation table
	std::vector<int> myBBD; //Big Block Depot
	std::vector<int> mySBD; //Small Block Depot
	std::vector<std::string> myProperties;
	std::vector<OleEntry> myEntries;
	int myRootEntryIndex;

};

inline const std::vector<OleEntry> &OleStorage::getEntries() const { return myEntries; }
inline unsigned int OleStorage::getSectorSize() const { return mySectorSize; }
inline unsigned int OleStorage::getShortSectorSize() const { return myShortSectorSize; }

#endif /* __OLESTORAGE_H__ */