2009-11-13 13:45:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-30 15:05:38 +00:00
|
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
|
|
|
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
2009-11-13 13:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
|
|
#include <util/SinglyLinkedList.h>
|
|
|
|
|
2011-01-27 23:17:03 +00:00
|
|
|
#include <package/hpkg/PackageAttributeValue.h>
|
2011-01-30 15:05:38 +00:00
|
|
|
#include <package/hpkg/PackageContentHandler.h>
|
2011-02-04 17:43:07 +00:00
|
|
|
#include <package/hpkg/PackageInfoAttributeValue.h>
|
2011-01-30 15:05:38 +00:00
|
|
|
#include <package/hpkg/PackageReader.h>
|
2011-01-27 23:17:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
namespace BHPKG {
|
2011-01-27 23:17:03 +00:00
|
|
|
|
2009-11-13 13:45:49 +00:00
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
class BPackageEntry;
|
|
|
|
class BPackageEntryAttribute;
|
|
|
|
class BErrorOutput;
|
2009-11-13 13:45:49 +00:00
|
|
|
|
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
namespace BPrivate {
|
2009-11-13 13:45:49 +00:00
|
|
|
|
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
class PackageReaderImpl {
|
2009-11-13 13:45:49 +00:00
|
|
|
public:
|
2011-01-30 15:05:38 +00:00
|
|
|
PackageReaderImpl(
|
|
|
|
BErrorOutput* errorOutput);
|
|
|
|
~PackageReaderImpl();
|
2009-11-13 13:45:49 +00:00
|
|
|
|
|
|
|
status_t Init(const char* fileName);
|
2009-11-17 11:33:50 +00:00
|
|
|
status_t Init(int fd, bool keepFD);
|
2009-11-13 13:45:49 +00:00
|
|
|
status_t ParseContent(
|
2011-01-30 15:05:38 +00:00
|
|
|
BPackageContentHandler* contentHandler);
|
|
|
|
status_t ParseContent(BLowLevelPackageContentHandler*
|
2009-11-13 13:45:49 +00:00
|
|
|
contentHandler);
|
|
|
|
|
|
|
|
int PackageFileFD() { return fFD; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct AttributeType;
|
|
|
|
struct AttributeTypeReference;
|
|
|
|
struct AttributeHandlerContext;
|
|
|
|
struct AttributeHandler;
|
|
|
|
struct IgnoreAttributeHandler;
|
|
|
|
struct DataAttributeHandler;
|
|
|
|
struct AttributeAttributeHandler;
|
|
|
|
struct EntryAttributeHandler;
|
|
|
|
struct RootAttributeHandler;
|
|
|
|
struct PackageAttributeHandler;
|
|
|
|
struct PackageContentListHandler;
|
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
typedef BPackageAttributeValue AttributeValue;
|
2009-11-13 13:45:49 +00:00
|
|
|
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
|
|
|
|
|
|
|
private:
|
|
|
|
status_t _Init(const char* fileName);
|
|
|
|
|
|
|
|
const char* _CheckCompression(uint32 compression,
|
|
|
|
uint64 compressedLength,
|
|
|
|
uint64 uncompressedLength) const;
|
|
|
|
|
|
|
|
status_t _ParseTOCAttributeTypes();
|
|
|
|
status_t _ParseTOCStrings();
|
|
|
|
|
|
|
|
status_t _ParseContent(AttributeHandlerContext* context,
|
|
|
|
AttributeHandler* rootAttributeHandler);
|
|
|
|
status_t _ParseAttributeTree(
|
|
|
|
AttributeHandlerContext* context);
|
|
|
|
|
2011-02-04 17:43:07 +00:00
|
|
|
status_t _ParsePackageAttributes(
|
|
|
|
AttributeHandlerContext* context);
|
|
|
|
status_t _ParsePackageVersion(
|
|
|
|
BPackageVersionData& _version,
|
|
|
|
const char* major = NULL);
|
|
|
|
status_t _ParsePackageProvides(
|
|
|
|
BPackageResolvableData& _resolvable,
|
|
|
|
BPackageResolvableType providesType);
|
|
|
|
status_t _ParsePackageResolvableExpression(
|
|
|
|
BPackageResolvableExpressionData&
|
|
|
|
_resolvableExpression,
|
|
|
|
const char* resolvableName,
|
|
|
|
bool hasChildren);
|
|
|
|
|
|
|
|
status_t _ReadPackageAttribute(uint8& _id,
|
|
|
|
AttributeValue& _value,
|
|
|
|
bool* _hasChildren = NULL,
|
|
|
|
uint64* _tag = NULL);
|
|
|
|
|
2009-11-13 13:45:49 +00:00
|
|
|
status_t _ReadAttributeValue(uint8 type, uint8 encoding,
|
|
|
|
AttributeValue& _value);
|
|
|
|
|
|
|
|
status_t _ReadUnsignedLEB128(uint64& _value);
|
|
|
|
status_t _ReadString(const char*& _string,
|
|
|
|
size_t* _stringLength = NULL);
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
inline status_t _Read(Type& _value);
|
|
|
|
|
|
|
|
status_t _GetTOCBuffer(size_t size,
|
|
|
|
const void*& _buffer);
|
|
|
|
status_t _ReadTOCBuffer(void* buffer, size_t size);
|
|
|
|
|
2011-02-04 17:43:07 +00:00
|
|
|
status_t _ReadPackageAttributesBuffer(void* buffer,
|
|
|
|
size_t size);
|
|
|
|
|
2009-11-15 21:29:53 +00:00
|
|
|
status_t _ReadBuffer(off_t offset, void* buffer,
|
|
|
|
size_t size);
|
|
|
|
status_t _ReadCompressedBuffer(off_t offset,
|
|
|
|
void* buffer, size_t compressedSize,
|
|
|
|
size_t uncompressedSize,
|
|
|
|
uint32 compression);
|
2009-11-13 13:45:49 +00:00
|
|
|
|
|
|
|
static int8 _GetStandardIndex(const AttributeType* type);
|
|
|
|
|
|
|
|
inline AttributeHandler* _CurrentAttributeHandler() const;
|
|
|
|
inline void _PushAttributeHandler(
|
|
|
|
AttributeHandler* handler);
|
|
|
|
inline AttributeHandler* _PopAttributeHandler();
|
|
|
|
|
|
|
|
private:
|
2011-02-04 17:43:07 +00:00
|
|
|
BErrorOutput* fErrorOutput;
|
2009-11-13 13:45:49 +00:00
|
|
|
int fFD;
|
2009-11-17 11:33:50 +00:00
|
|
|
bool fOwnsFD;
|
2009-11-13 13:45:49 +00:00
|
|
|
|
|
|
|
uint64 fTotalSize;
|
|
|
|
uint64 fHeapOffset;
|
|
|
|
uint64 fHeapSize;
|
|
|
|
|
|
|
|
uint32 fTOCCompression;
|
|
|
|
uint64 fTOCCompressedLength;
|
|
|
|
uint64 fTOCUncompressedLength;
|
|
|
|
uint64 fTOCSectionOffset;
|
|
|
|
uint64 fTOCAttributeTypesLength;
|
|
|
|
uint64 fTOCAttributeTypesCount;
|
|
|
|
uint64 fTOCStringsLength;
|
|
|
|
uint64 fTOCStringsCount;
|
|
|
|
|
2011-02-04 17:43:07 +00:00
|
|
|
bool fInPackageAttributes;
|
|
|
|
|
2009-11-13 13:45:49 +00:00
|
|
|
uint32 fPackageAttributesCompression;
|
|
|
|
uint32 fPackageAttributesCompressedLength;
|
|
|
|
uint32 fPackageAttributesUncompressedLength;
|
|
|
|
uint64 fPackageAttributesOffset;
|
|
|
|
|
|
|
|
uint8* fTOCSection;
|
|
|
|
uint64 fCurrentTOCOffset;
|
2011-02-04 17:43:07 +00:00
|
|
|
|
|
|
|
uint8* fPackageAttributesSection;
|
|
|
|
uint64 fCurrentPackageAttributesOffset;
|
|
|
|
|
2009-11-13 13:45:49 +00:00
|
|
|
AttributeTypeReference* fAttributeTypes;
|
|
|
|
char** fStrings;
|
|
|
|
|
|
|
|
AttributeHandlerList* fAttributeHandlerStack;
|
2009-11-15 21:29:53 +00:00
|
|
|
|
|
|
|
uint8* fScratchBuffer;
|
|
|
|
size_t fScratchBufferSize;
|
2009-11-13 13:45:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
status_t
|
2011-01-30 15:05:38 +00:00
|
|
|
PackageReaderImpl::_Read(Type& _value)
|
2009-11-13 13:45:49 +00:00
|
|
|
{
|
2011-02-04 17:43:07 +00:00
|
|
|
return fInPackageAttributes
|
|
|
|
? _ReadPackageAttributesBuffer(&_value, sizeof(Type))
|
|
|
|
: _ReadTOCBuffer(&_value, sizeof(Type));
|
2009-11-13 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 23:17:03 +00:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
} // namespace BHPKG
|
2011-01-27 23:17:03 +00:00
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
2011-01-30 15:05:38 +00:00
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|