xref: /haiku/headers/private/package/hpkg/PackageReaderImpl.h (revision 1c09002cbee8e797a0f8bbfc5678dfadd39ee1a7)
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 protected:
42 								// from ReaderImplBase
43 	virtual	status_t			ReadAttributeValue(uint8 type, uint8 encoding,
44 									AttributeValue& _value);
45 
46 private:
47 			struct DataAttributeHandler;
48 			struct AttributeAttributeHandler;
49 			struct EntryAttributeHandler;
50 			struct RootAttributeHandler;
51 
52 private:
53 			status_t			_ParseTOC(AttributeHandlerContext* context,
54 									AttributeHandler* rootAttributeHandler);
55 
56 			status_t			_GetTOCBuffer(size_t size,
57 									const void*& _buffer);
58 private:
59 			uint64				fTotalSize;
60 			uint64				fHeapOffset;
61 			uint64				fHeapSize;
62 
63 			SectionInfo			fTOCSection;
64 };
65 
66 
67 inline int
68 PackageReaderImpl::PackageFileFD() const
69 {
70 	return FD();
71 }
72 
73 
74 }	// namespace BPrivate
75 
76 }	// namespace BHPKG
77 
78 }	// namespace BPackageKit
79 
80 
81 #endif	// _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
82