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(BErrorOutput* errorOutput); 29 ~PackageReaderImpl(); 30 31 status_t Init(const char* fileName, uint32 flags); 32 status_t Init(int fd, bool keepFD, uint32 flags); 33 status_t ParseContent( 34 BPackageContentHandler* contentHandler); 35 status_t ParseContent(BLowLevelPackageContentHandler* 36 contentHandler); 37 38 int PackageFileFD() const; 39 40 uint64 HeapOffset() const; 41 uint64 HeapSize() const; 42 43 PackageFileHeapReader* RawHeapReader() const 44 { return inherited::RawHeapReader(); } 45 BAbstractBufferedDataReader* HeapReader() const 46 { return inherited::HeapReader(); } 47 48 protected: 49 // from ReaderImplBase 50 virtual status_t ReadAttributeValue(uint8 type, uint8 encoding, 51 AttributeValue& _value); 52 53 private: 54 struct AttributeAttributeHandler; 55 struct EntryAttributeHandler; 56 struct RootAttributeHandler; 57 58 private: 59 status_t _ParseTOC(AttributeHandlerContext* context, 60 AttributeHandler* rootAttributeHandler); 61 62 status_t _GetTOCBuffer(size_t size, 63 const void*& _buffer); 64 private: 65 uint64 fHeapOffset; 66 uint64 fHeapSize; 67 68 PackageFileSection fTOCSection; 69 }; 70 71 72 inline int 73 PackageReaderImpl::PackageFileFD() const 74 { 75 return FD(); 76 } 77 78 79 inline uint64 80 PackageReaderImpl::HeapOffset() const 81 { 82 return fHeapOffset; 83 } 84 85 86 inline uint64 87 PackageReaderImpl::HeapSize() const 88 { 89 return fHeapSize; 90 } 91 92 93 } // namespace BPrivate 94 95 } // namespace BHPKG 96 97 } // namespace BPackageKit 98 99 100 #endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_ 101