1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
7#define _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
8
9
10#include <package/hpkg/ReaderImplBase.h>
11
12
13namespace BPackageKit {
14
15namespace BHPKG {
16
17
18class BPackageEntry;
19class BPackageEntryAttribute;
20
21
22namespace BPrivate {
23
24
25struct hpkg_header;
26class PackageWriterImpl;
27
28
29class PackageReaderImpl : public ReaderImplBase {
30	typedef	ReaderImplBase		inherited;
31public:
32								PackageReaderImpl(BErrorOutput* errorOutput);
33								~PackageReaderImpl();
34
35			status_t			Init(const char* fileName, uint32 flags);
36			status_t			Init(int fd, bool keepFD, uint32 flags);
37			status_t			Init(BPositionIO* file, bool keepFile,
38									uint32 flags, hpkg_header* _header = NULL);
39			status_t			ParseContent(
40									BPackageContentHandler* contentHandler);
41			status_t			ParseContent(BLowLevelPackageContentHandler*
42										contentHandler);
43
44			BPositionIO*		PackageFile() const;
45
46			uint64				HeapOffset() const;
47			uint64				HeapSize() const;
48
49			PackageFileHeapReader* RawHeapReader() const
50									{ return inherited::RawHeapReader(); }
51			BAbstractBufferedDataReader* HeapReader() const
52									{ return inherited::HeapReader(); }
53
54	inline	const PackageFileSection& TOCSection() const
55									{ return fTOCSection; }
56
57protected:
58								// from ReaderImplBase
59	virtual	status_t			ReadAttributeValue(uint8 type, uint8 encoding,
60									AttributeValue& _value);
61
62private:
63			struct AttributeAttributeHandler;
64			struct EntryAttributeHandler;
65			struct RootAttributeHandler;
66
67			friend class PackageWriterImpl;
68
69private:
70			status_t			_PrepareSections();
71
72			status_t			_ParseTOC(AttributeHandlerContext* context,
73									AttributeHandler* rootAttributeHandler);
74
75			status_t			_GetTOCBuffer(size_t size,
76									const void*& _buffer);
77private:
78			uint64				fHeapOffset;
79			uint64				fHeapSize;
80
81			PackageFileSection	fTOCSection;
82};
83
84
85inline BPositionIO*
86PackageReaderImpl::PackageFile() const
87{
88	return File();
89}
90
91
92inline uint64
93PackageReaderImpl::HeapOffset() const
94{
95	return fHeapOffset;
96}
97
98
99inline uint64
100PackageReaderImpl::HeapSize() const
101{
102	return fHeapSize;
103}
104
105
106}	// namespace BPrivate
107
108}	// namespace BHPKG
109
110}	// namespace BPackageKit
111
112
113#endif	// _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
114