xref: /haiku/headers/private/package/hpkg/PackageReaderImpl.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
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 
13 namespace BPackageKit {
14 
15 namespace BHPKG {
16 
17 
18 class BPackageEntry;
19 class BPackageEntryAttribute;
20 
21 
22 namespace BPrivate {
23 
24 
25 class PackageReaderImpl : public ReaderImplBase {
26 	typedef	ReaderImplBase		inherited;
27 public:
28 								PackageReaderImpl(
29 									BErrorOutput* errorOutput);
30 								~PackageReaderImpl();
31 
32 			status_t			Init(const char* fileName);
33 			status_t			Init(int fd, bool keepFD);
34 			status_t			ParseContent(
35 									BPackageContentHandler* contentHandler);
36 			status_t			ParseContent(BLowLevelPackageContentHandler*
37 										contentHandler);
38 
39 			int					PackageFileFD() const;
40 
41 			uint64				HeapOffset() const;
42 			uint64				HeapSize() const;
43 
44 protected:
45 								// from ReaderImplBase
46 	virtual	status_t			ReadAttributeValue(uint8 type, uint8 encoding,
47 									AttributeValue& _value);
48 
49 private:
50 			struct DataAttributeHandler;
51 			struct AttributeAttributeHandler;
52 			struct EntryAttributeHandler;
53 			struct RootAttributeHandler;
54 
55 private:
56 			status_t			_ParseTOC(AttributeHandlerContext* context,
57 									AttributeHandler* rootAttributeHandler);
58 
59 			status_t			_GetTOCBuffer(size_t size,
60 									const void*& _buffer);
61 private:
62 			uint64				fTotalSize;
63 			uint64				fHeapOffset;
64 			uint64				fHeapSize;
65 
66 			SectionInfo			fTOCSection;
67 };
68 
69 
70 inline int
71 PackageReaderImpl::PackageFileFD() const
72 {
73 	return FD();
74 }
75 
76 
77 inline uint64
78 PackageReaderImpl::HeapOffset() const
79 {
80 	return fHeapOffset;
81 }
82 
83 
84 inline uint64
85 PackageReaderImpl::HeapSize() const
86 {
87 	return fHeapSize;
88 }
89 
90 
91 }	// namespace BPrivate
92 
93 }	// namespace BHPKG
94 
95 }	// namespace BPackageKit
96 
97 
98 #endif	// _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
99