Clone read support functionality for HPKG format version 1
It uses sub-namespace BPackage::BHPKG::V1. Unlike the one for the current format version, the V1 version of BPackageInfoContentHandler lives in BHPKG(::V1) sub-namespace and is private.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/HPKGDefs.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageAttributeValue.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageContentHandler.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageData.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageDataReader.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageEntry.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageEntryAttribute.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../os/package/hpkg/v1/PackageReader.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../private/package/hpkg/v1/HPKGDefsPrivate.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../private/package/hpkg/v1/PackageInfoContentHandler.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../private/package/hpkg/v1/PackageReaderImpl.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../private/package/hpkg/v1/ReaderImplBase.h>
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__HPKG_DEFS_H_
|
||||
#define _PACKAGE__HPKG__V1__HPKG_DEFS_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
// magic & version of package and repository files
|
||||
enum {
|
||||
B_HPKG_MAGIC = 'hpkg',
|
||||
B_HPKG_VERSION = 1,
|
||||
//
|
||||
B_HPKG_REPO_MAGIC = 'hpkr',
|
||||
B_HPKG_REPO_VERSION = 1
|
||||
};
|
||||
|
||||
|
||||
// package attribute IDs
|
||||
enum BHPKGPackageSectionID {
|
||||
B_HPKG_SECTION_HEADER = 0,
|
||||
B_HPKG_SECTION_HEAP = 1,
|
||||
B_HPKG_SECTION_PACKAGE_TOC = 2,
|
||||
B_HPKG_SECTION_PACKAGE_ATTRIBUTES = 3,
|
||||
B_HPKG_SECTION_REPOSITORY_INFO = 4,
|
||||
//
|
||||
B_HPKG_SECTION_ENUM_COUNT
|
||||
};
|
||||
|
||||
|
||||
// attribute types
|
||||
enum {
|
||||
// types
|
||||
B_HPKG_ATTRIBUTE_TYPE_INVALID = 0,
|
||||
B_HPKG_ATTRIBUTE_TYPE_INT = 1,
|
||||
B_HPKG_ATTRIBUTE_TYPE_UINT = 2,
|
||||
B_HPKG_ATTRIBUTE_TYPE_STRING = 3,
|
||||
B_HPKG_ATTRIBUTE_TYPE_RAW = 4,
|
||||
//
|
||||
B_HPKG_ATTRIBUTE_TYPE_ENUM_COUNT
|
||||
};
|
||||
|
||||
|
||||
// attribute encodings
|
||||
enum {
|
||||
// signed/unsigned int encodings
|
||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT = 0,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_INT_16_BIT = 1,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT = 2,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_INT_64_BIT = 3,
|
||||
|
||||
// string encodings
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_INLINE = 0,
|
||||
// null-terminated string
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE = 1,
|
||||
// unsigned LEB128 index into string table
|
||||
|
||||
// raw data encodings
|
||||
B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE = 0,
|
||||
// unsigned LEB128 size, raw bytes
|
||||
B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP = 1
|
||||
// unsigned LEB128 size, unsigned LEB128 offset into the heap
|
||||
};
|
||||
|
||||
|
||||
// maximum number of bytes of data to be encoded inline; more will be allocated
|
||||
// on the heap
|
||||
enum {
|
||||
B_HPKG_MAX_INLINE_DATA_SIZE = 8
|
||||
};
|
||||
|
||||
|
||||
// name of file containing package information (in package's root folder)
|
||||
extern const char* const B_HPKG_PACKAGE_INFO_FILE_NAME;
|
||||
|
||||
|
||||
// package attribute IDs
|
||||
enum BHPKGAttributeID {
|
||||
B_HPKG_ATTRIBUTE_ID_DIRECTORY_ENTRY = 0,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_TYPE = 1,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_PERMISSIONS = 2,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_USER = 3,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_GROUP = 4,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATIME = 5,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_MTIME = 6,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_CRTIME = 7,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATIME_NANOS = 8,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_MTIME_NANOS = 9,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_CRTIM_NANOS = 10,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE = 11,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE_TYPE = 12,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA = 13,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA_SIZE = 14,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA_COMPRESSION = 15,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA_CHUNK_SIZE = 16,
|
||||
B_HPKG_ATTRIBUTE_ID_SYMLINK_PATH = 17,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_NAME = 18,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_SUMMARY = 19,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_DESCRIPTION = 20,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VENDOR = 21,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_PACKAGER = 22,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_FLAGS = 23,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_ARCHITECTURE = 24,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MAJOR = 25,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MINOR = 26,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MICRO = 27,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_REVISION = 28,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_COPYRIGHT = 29,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_LICENSE = 30,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES = 31,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES_TYPE = 32,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_REQUIRES = 33,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_SUPPLEMENTS = 34,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_CONFLICTS = 35,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_FRESHENS = 36,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_REPLACES = 37,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_RESOLVABLE_OPERATOR = 38,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_CHECKSUM = 39,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_PRE_RELEASE = 40,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES_COMPATIBLE = 41,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_URL = 42,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_SOURCE_URL = 43,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_INSTALL_PATH = 44,
|
||||
//
|
||||
B_HPKG_ATTRIBUTE_ID_ENUM_COUNT,
|
||||
};
|
||||
|
||||
|
||||
// compression types
|
||||
enum {
|
||||
B_HPKG_COMPRESSION_NONE = 0,
|
||||
B_HPKG_COMPRESSION_ZLIB = 1
|
||||
};
|
||||
|
||||
|
||||
// file types (B_HPKG_ATTRIBUTE_ID_FILE_TYPE)
|
||||
enum {
|
||||
B_HPKG_FILE_TYPE_FILE = 0,
|
||||
B_HPKG_FILE_TYPE_DIRECTORY = 1,
|
||||
B_HPKG_FILE_TYPE_SYMLINK = 2
|
||||
};
|
||||
|
||||
|
||||
// default values
|
||||
enum {
|
||||
B_HPKG_DEFAULT_FILE_TYPE = B_HPKG_FILE_TYPE_FILE,
|
||||
B_HPKG_DEFAULT_FILE_PERMISSIONS = 0644,
|
||||
B_HPKG_DEFAULT_DIRECTORY_PERMISSIONS = 0755,
|
||||
B_HPKG_DEFAULT_SYMLINK_PERMISSIONS = 0777,
|
||||
B_HPKG_DEFAULT_DATA_COMPRESSION = B_HPKG_COMPRESSION_NONE,
|
||||
B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB = 64 * 1024
|
||||
};
|
||||
|
||||
|
||||
// Writer Init() flags
|
||||
enum {
|
||||
B_HPKG_WRITER_UPDATE_PACKAGE = 0x01,
|
||||
// update the package (don't truncate)
|
||||
B_HPKG_WRITER_FORCE_ADD = 0x02,
|
||||
// when updating a pre-existing entry, don't fail, but replace the
|
||||
// entry, if possible (directories will be merged, but won't replace a
|
||||
// non-directory)
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__HPKG_DEFS_H_
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_ATTRIBUTE_VALUE_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_ATTRIBUTE_VALUE_H_
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <package/hpkg/v1/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
struct BPackageAttributeValue {
|
||||
union {
|
||||
int64 signedInt;
|
||||
uint64 unsignedInt;
|
||||
const char* string;
|
||||
struct {
|
||||
uint64 size;
|
||||
union {
|
||||
uint64 offset;
|
||||
uint8 raw[B_HPKG_MAX_INLINE_DATA_SIZE];
|
||||
};
|
||||
} data;
|
||||
};
|
||||
uint8 type;
|
||||
uint8 encoding;
|
||||
|
||||
public:
|
||||
inline BPackageAttributeValue();
|
||||
|
||||
inline void SetTo(int8 value);
|
||||
inline void SetTo(uint8 value);
|
||||
inline void SetTo(int16 value);
|
||||
inline void SetTo(uint16 value);
|
||||
inline void SetTo(int32 value);
|
||||
inline void SetTo(uint32 value);
|
||||
inline void SetTo(int64 value);
|
||||
inline void SetTo(uint64 value);
|
||||
inline void SetTo(const char* value);
|
||||
inline void SetToData(uint64 size, uint64 offset);
|
||||
inline void SetToData(uint64 size, const void* rawData);
|
||||
};
|
||||
|
||||
|
||||
BPackageAttributeValue::BPackageAttributeValue()
|
||||
:
|
||||
type(B_HPKG_ATTRIBUTE_TYPE_INVALID)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(int8 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(uint8 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(int16 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(uint16 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(int32 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(uint32 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(int64 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(uint64 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetTo(const char* value)
|
||||
{
|
||||
string = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_STRING;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetToData(uint64 size, uint64 offset)
|
||||
{
|
||||
data.size = size;
|
||||
data.offset = offset;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_RAW;
|
||||
encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageAttributeValue::SetToData(uint64 size, const void* rawData)
|
||||
{
|
||||
data.size = size;
|
||||
if (size > 0)
|
||||
memcpy(data.raw, rawData, size);
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_RAW;
|
||||
encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE;
|
||||
}
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_ATTRIBUTE_VALUE_H_
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_CONTENT_HANDLER_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_CONTENT_HANDLER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/v1/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BPackageInfoAttributeValue;
|
||||
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageAttributeValue;
|
||||
class BPackageEntry;
|
||||
class BPackageEntryAttribute;
|
||||
|
||||
|
||||
class BLowLevelPackageContentHandler {
|
||||
public:
|
||||
virtual ~BLowLevelPackageContentHandler();
|
||||
|
||||
virtual status_t HandleSectionStart(
|
||||
BHPKGPackageSectionID sectionID,
|
||||
bool& _handleSection) = 0;
|
||||
virtual status_t HandleSectionEnd(
|
||||
BHPKGPackageSectionID sectionID) = 0;
|
||||
|
||||
virtual status_t HandleAttribute(BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value,
|
||||
void* parentToken, void*& _token) = 0;
|
||||
virtual status_t HandleAttributeDone(
|
||||
BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value,
|
||||
void* parentToken, void* token) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
|
||||
protected:
|
||||
static const char* AttributeNameForID(uint8 id);
|
||||
};
|
||||
|
||||
|
||||
class BPackageContentHandler {
|
||||
public:
|
||||
virtual ~BPackageContentHandler();
|
||||
|
||||
virtual status_t HandleEntry(BPackageEntry* entry) = 0;
|
||||
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
|
||||
BPackageEntryAttribute* attribute) = 0;
|
||||
virtual status_t HandleEntryDone(BPackageEntry* entry) = 0;
|
||||
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value
|
||||
) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_CONTENT_HANDLER_H_
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_DATA_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_DATA_H_
|
||||
|
||||
|
||||
#include <package/hpkg/v1/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageData {
|
||||
public:
|
||||
BPackageData();
|
||||
|
||||
uint64 CompressedSize() const
|
||||
{ return fCompressedSize; }
|
||||
uint64 UncompressedSize() const
|
||||
{ return fUncompressedSize; }
|
||||
uint64 Offset() const
|
||||
{ return fEncodedInline ? 0 : fOffset; }
|
||||
uint32 Compression() const { return fCompression; }
|
||||
uint32 ChunkSize() const { return fChunkSize; }
|
||||
|
||||
bool IsEncodedInline() const
|
||||
{ return fEncodedInline; }
|
||||
const uint8* InlineData() const { return fInlineData; }
|
||||
|
||||
void SetData(uint64 size, uint64 offset);
|
||||
void SetData(uint8 size, const void* data);
|
||||
|
||||
void SetCompression(uint32 compression)
|
||||
{ fCompression = compression; }
|
||||
void SetUncompressedSize(uint64 size)
|
||||
{ fUncompressedSize = size; }
|
||||
void SetChunkSize(uint32 size)
|
||||
{ fChunkSize = size; }
|
||||
|
||||
private:
|
||||
uint64 fCompressedSize;
|
||||
uint64 fUncompressedSize;
|
||||
union {
|
||||
uint64 fOffset;
|
||||
uint8 fInlineData[B_HPKG_MAX_INLINE_DATA_SIZE];
|
||||
};
|
||||
uint32 fChunkSize;
|
||||
uint32 fCompression;
|
||||
bool fEncodedInline;
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_DATA_H_
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_DATA_READER_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_DATA_READER_H_
|
||||
|
||||
|
||||
#include <package/hpkg/DataReader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BBufferCache;
|
||||
class BDataOutput;
|
||||
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageData;
|
||||
|
||||
|
||||
class BPackageDataReader : public BDataReader {
|
||||
public:
|
||||
BPackageDataReader(BDataReader* dataReader);
|
||||
virtual ~BPackageDataReader();
|
||||
|
||||
virtual status_t Init(const BPackageData& data) = 0;
|
||||
|
||||
virtual status_t ReadData(off_t offset, void* buffer,
|
||||
size_t size);
|
||||
virtual status_t ReadDataToOutput(off_t offset, size_t size,
|
||||
BDataOutput* output) = 0;
|
||||
|
||||
virtual uint64 Size() const = 0;
|
||||
virtual size_t BlockSize() const = 0;
|
||||
|
||||
protected:
|
||||
BDataReader* fDataReader;
|
||||
};
|
||||
|
||||
|
||||
class BPackageDataReaderFactory {
|
||||
public:
|
||||
BPackageDataReaderFactory(
|
||||
BBufferCache* bufferCache);
|
||||
|
||||
status_t CreatePackageDataReader(BDataReader* dataReader,
|
||||
const BPackageData& data,
|
||||
BPackageDataReader*& _reader);
|
||||
|
||||
private:
|
||||
BBufferCache* fBufferCache;
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_DATA_READER_H_
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_ENTRY_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_ENTRY_H_
|
||||
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <package/hpkg/v1/PackageData.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageEntry {
|
||||
public:
|
||||
BPackageEntry(BPackageEntry* parent,
|
||||
const char* name);
|
||||
|
||||
const BPackageEntry* Parent() const { return fParent; }
|
||||
const char* Name() const { return fName; }
|
||||
void* UserToken() const { return fUserToken; }
|
||||
|
||||
mode_t Mode() const { return fMode; }
|
||||
|
||||
const timespec& AccessTime() const
|
||||
{ return fAccessTime; }
|
||||
const timespec& ModifiedTime() const
|
||||
{ return fModifiedTime; }
|
||||
const timespec& CreationTime() const
|
||||
{ return fCreationTime; }
|
||||
|
||||
BPackageData& Data() { return fData; }
|
||||
|
||||
const char* SymlinkPath() const { return fSymlinkPath; }
|
||||
|
||||
void SetUserToken(void* token)
|
||||
{ fUserToken = token; }
|
||||
|
||||
void SetType(uint32 type);
|
||||
void SetPermissions(uint32 permissions);
|
||||
|
||||
void SetAccessTime(uint32 seconds)
|
||||
{ fAccessTime.tv_sec = seconds; }
|
||||
void SetAccessTimeNanos(uint32 nanos)
|
||||
{ fAccessTime.tv_nsec = nanos; }
|
||||
void SetModifiedTime(uint32 seconds)
|
||||
{ fModifiedTime.tv_sec = seconds; }
|
||||
void SetModifiedTimeNanos(uint32 nanos)
|
||||
{ fModifiedTime.tv_nsec = nanos; }
|
||||
void SetCreationTime(uint32 seconds)
|
||||
{ fCreationTime.tv_sec = seconds; }
|
||||
void SetCreationTimeNanos(uint32 nanos)
|
||||
{ fCreationTime.tv_nsec = nanos; }
|
||||
|
||||
void SetSymlinkPath(const char* path)
|
||||
{ fSymlinkPath = path; }
|
||||
private:
|
||||
BPackageEntry* fParent;
|
||||
const char* fName;
|
||||
void* fUserToken;
|
||||
mode_t fMode;
|
||||
timespec fAccessTime;
|
||||
timespec fModifiedTime;
|
||||
timespec fCreationTime;
|
||||
BPackageData fData;
|
||||
const char* fSymlinkPath;
|
||||
};
|
||||
|
||||
|
||||
inline void
|
||||
BPackageEntry::SetType(uint32 type)
|
||||
{
|
||||
fMode = (fMode & ~(uint32)S_IFMT) | (type & S_IFMT);
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BPackageEntry::SetPermissions(uint32 permissions)
|
||||
{
|
||||
fMode = (fMode & ~(uint32)ALLPERMS) | (permissions & ALLPERMS);
|
||||
}
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_ENTRY_H_
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_ENTRY_ATTRIBUTE_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_ENTRY_ATTRIBUTE_H_
|
||||
|
||||
|
||||
#include <package/hpkg/v1/PackageData.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageEntryAttribute {
|
||||
public:
|
||||
BPackageEntryAttribute(const char* name);
|
||||
|
||||
const char* Name() const { return fName; }
|
||||
uint32 Type() const { return fType; }
|
||||
|
||||
BPackageData& Data() { return fData; }
|
||||
|
||||
void SetType(uint32 type) { fType = type; }
|
||||
|
||||
private:
|
||||
const char* fName;
|
||||
uint32 fType;
|
||||
BPackageData fData;
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_ENTRY_ATTRIBUTE_H_
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2009,2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_READER_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_READER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BErrorOutput;
|
||||
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class PackageReaderImpl;
|
||||
}
|
||||
using BPrivate::PackageReaderImpl;
|
||||
|
||||
class BLowLevelPackageContentHandler;
|
||||
class BPackageContentHandler;
|
||||
|
||||
|
||||
class BPackageReader {
|
||||
public:
|
||||
BPackageReader(
|
||||
BErrorOutput* errorOutput);
|
||||
~BPackageReader();
|
||||
|
||||
status_t Init(const char* fileName);
|
||||
status_t Init(int fd, bool keepFD);
|
||||
status_t ParseContent(
|
||||
BPackageContentHandler* contentHandler);
|
||||
status_t ParseContent(BLowLevelPackageContentHandler*
|
||||
contentHandler);
|
||||
|
||||
int PackageFileFD();
|
||||
private:
|
||||
PackageReaderImpl* fImpl;
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_READER_H_
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PRIVATE__HAIKU_PACKAGE_H_
|
||||
#define _PACKAGE__HPKG__V1__PRIVATE__HAIKU_PACKAGE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
// header
|
||||
struct hpkg_header {
|
||||
uint32 magic; // "hpkg"
|
||||
uint16 header_size;
|
||||
uint16 version;
|
||||
uint64 total_size;
|
||||
|
||||
// package attributes section
|
||||
uint32 attributes_compression;
|
||||
uint32 attributes_length_compressed;
|
||||
uint32 attributes_length_uncompressed;
|
||||
uint32 attributes_strings_length;
|
||||
uint32 attributes_strings_count;
|
||||
|
||||
// TOC section
|
||||
uint32 toc_compression;
|
||||
uint64 toc_length_compressed;
|
||||
uint64 toc_length_uncompressed;
|
||||
uint64 toc_strings_length;
|
||||
uint64 toc_strings_count;
|
||||
};
|
||||
|
||||
|
||||
// header
|
||||
struct hpkg_repo_header {
|
||||
uint32 magic; // "hpkr"
|
||||
uint16 header_size;
|
||||
uint16 version;
|
||||
uint64 total_size;
|
||||
|
||||
// repository info section
|
||||
uint32 info_compression;
|
||||
uint32 info_length_compressed;
|
||||
uint32 info_length_uncompressed;
|
||||
|
||||
// package attributes section
|
||||
uint32 packages_compression;
|
||||
uint64 packages_length_compressed;
|
||||
uint64 packages_length_uncompressed;
|
||||
uint64 packages_strings_length;
|
||||
uint64 packages_strings_count;
|
||||
};
|
||||
|
||||
|
||||
// attribute tag arithmetics
|
||||
// (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding)
|
||||
static inline uint16
|
||||
compose_attribute_tag(uint16 id, uint16 type, uint16 encoding, bool hasChildren)
|
||||
{
|
||||
return ((encoding << 10) | (uint16(hasChildren ? 1 : 0) << 9) | (type << 6)
|
||||
| id)
|
||||
+ 1;
|
||||
}
|
||||
|
||||
|
||||
static inline uint16
|
||||
attribute_tag_encoding(uint16 tag)
|
||||
{
|
||||
return ((tag - 1) >> 10) & 0x3;
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
attribute_tag_has_children(uint16 tag)
|
||||
{
|
||||
return (((tag - 1) >> 9) & 0x1) != 0;
|
||||
}
|
||||
|
||||
|
||||
static inline uint16
|
||||
attribute_tag_type(uint16 tag)
|
||||
{
|
||||
return ((tag - 1) >> 6) & 0x7;
|
||||
}
|
||||
|
||||
|
||||
static inline uint16
|
||||
attribute_tag_id(uint16 tag)
|
||||
{
|
||||
return (tag - 1) & 0x3f;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PRIVATE__HAIKU_PACKAGE_H_
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PACKAGE_INFO_CONTENT_HANDLER_H_
|
||||
#define _PACKAGE__HPKG__V1__PACKAGE_INFO_CONTENT_HANDLER_H_
|
||||
|
||||
|
||||
#include <package/hpkg/v1/PackageContentHandler.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
class BPackageInfo;
|
||||
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BErrorOutput;
|
||||
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageInfoContentHandler : public BPackageContentHandler {
|
||||
public:
|
||||
BPackageInfoContentHandler(
|
||||
BPackageInfo& packageInfo,
|
||||
BHPKG::BErrorOutput* errorOutput = NULL);
|
||||
virtual ~BPackageInfoContentHandler();
|
||||
|
||||
virtual status_t HandleEntry(BPackageEntry* entry);
|
||||
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
|
||||
BPackageEntryAttribute* attribute);
|
||||
virtual status_t HandleEntryDone(BPackageEntry* entry);
|
||||
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BHPKG::BPackageInfoAttributeValue&
|
||||
value);
|
||||
|
||||
virtual void HandleErrorOccurred();
|
||||
|
||||
protected:
|
||||
BPackageInfo& fPackageInfo;
|
||||
BHPKG::BErrorOutput* fErrorOutput;
|
||||
};
|
||||
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PACKAGE_INFO_CONTENT_HANDLER_H_
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PRIVATE__PACKAGE_READER_IMPL_H_
|
||||
#define _PACKAGE__HPKG__V1__PRIVATE__PACKAGE_READER_IMPL_H_
|
||||
|
||||
|
||||
#include <package/hpkg/v1/ReaderImplBase.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace V1 {
|
||||
|
||||
|
||||
class BPackageEntry;
|
||||
class BPackageEntryAttribute;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class PackageReaderImpl : public ReaderImplBase {
|
||||
typedef ReaderImplBase inherited;
|
||||
public:
|
||||
PackageReaderImpl(
|
||||
BErrorOutput* errorOutput);
|
||||
~PackageReaderImpl();
|
||||
|
||||
status_t Init(const char* fileName);
|
||||
status_t Init(int fd, bool keepFD);
|
||||
status_t ParseContent(
|
||||
BPackageContentHandler* contentHandler);
|
||||
status_t ParseContent(BLowLevelPackageContentHandler*
|
||||
contentHandler);
|
||||
|
||||
int PackageFileFD() const;
|
||||
|
||||
uint64 HeapOffset() const;
|
||||
uint64 HeapSize() const;
|
||||
|
||||
protected:
|
||||
// from ReaderImplBase
|
||||
virtual status_t ReadAttributeValue(uint8 type, uint8 encoding,
|
||||
AttributeValue& _value);
|
||||
|
||||
private:
|
||||
struct DataAttributeHandler;
|
||||
struct AttributeAttributeHandler;
|
||||
struct EntryAttributeHandler;
|
||||
struct RootAttributeHandler;
|
||||
|
||||
private:
|
||||
status_t _ParseTOC(AttributeHandlerContext* context,
|
||||
AttributeHandler* rootAttributeHandler);
|
||||
|
||||
status_t _GetTOCBuffer(size_t size,
|
||||
const void*& _buffer);
|
||||
private:
|
||||
uint64 fTotalSize;
|
||||
uint64 fHeapOffset;
|
||||
uint64 fHeapSize;
|
||||
|
||||
SectionInfo fTOCSection;
|
||||
};
|
||||
|
||||
|
||||
inline int
|
||||
PackageReaderImpl::PackageFileFD() const
|
||||
{
|
||||
return FD();
|
||||
}
|
||||
|
||||
|
||||
inline uint64
|
||||
PackageReaderImpl::HeapOffset() const
|
||||
{
|
||||
return fHeapOffset;
|
||||
}
|
||||
|
||||
|
||||
inline uint64
|
||||
PackageReaderImpl::HeapSize() const
|
||||
{
|
||||
return fHeapSize;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PRIVATE__PACKAGE_READER_IMPL_H_
|
||||
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__V1__PRIVATE__READER_IMPL_BASE_H_
|
||||
#define _PACKAGE__HPKG__V1__PRIVATE__READER_IMPL_BASE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <util/SinglyLinkedList.h>
|
||||
|
||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||
#include <package/hpkg/v1/PackageAttributeValue.h>
|
||||
#include <package/hpkg/v1/PackageContentHandler.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BErrorOutput;
|
||||
|
||||
|
||||
namespace V1 {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ReaderImplBase {
|
||||
protected:
|
||||
ReaderImplBase(
|
||||
BErrorOutput* errorOutput);
|
||||
virtual ~ReaderImplBase();
|
||||
|
||||
virtual status_t Init(int fd, bool keepFD);
|
||||
|
||||
int FD() const;
|
||||
|
||||
BErrorOutput* ErrorOutput() const;
|
||||
|
||||
protected:
|
||||
struct AttributeHandlerContext {
|
||||
BErrorOutput* errorOutput;
|
||||
union {
|
||||
BPackageContentHandler* packageContentHandler;
|
||||
BLowLevelPackageContentHandler* lowLevelHandler;
|
||||
};
|
||||
bool hasLowLevelHandler;
|
||||
|
||||
uint64 heapOffset;
|
||||
uint64 heapSize;
|
||||
|
||||
BHPKGPackageSectionID section;
|
||||
|
||||
AttributeHandlerContext(BErrorOutput* errorOutput,
|
||||
BPackageContentHandler* packageContentHandler,
|
||||
BHPKGPackageSectionID section);
|
||||
|
||||
AttributeHandlerContext(BErrorOutput* errorOutput,
|
||||
BLowLevelPackageContentHandler* lowLevelHandler,
|
||||
BHPKGPackageSectionID section);
|
||||
|
||||
void ErrorOccurred();
|
||||
};
|
||||
|
||||
|
||||
typedef BPackageAttributeValue AttributeValue;
|
||||
|
||||
struct AttributeHandler
|
||||
: SinglyLinkedListLinkImpl<AttributeHandler> {
|
||||
virtual ~AttributeHandler();
|
||||
|
||||
void SetLevel(int level);
|
||||
virtual status_t HandleAttribute(
|
||||
AttributeHandlerContext* context, uint8 id,
|
||||
const AttributeValue& value, AttributeHandler** _handler);
|
||||
|
||||
virtual status_t Delete(AttributeHandlerContext* context);
|
||||
|
||||
protected:
|
||||
int fLevel;
|
||||
};
|
||||
|
||||
|
||||
struct IgnoreAttributeHandler : AttributeHandler {
|
||||
};
|
||||
|
||||
|
||||
struct PackageVersionAttributeHandler : AttributeHandler {
|
||||
PackageVersionAttributeHandler(
|
||||
BPackageInfoAttributeValue& packageInfoValue,
|
||||
BPackageVersionData& versionData, bool notify);
|
||||
|
||||
virtual status_t HandleAttribute(
|
||||
AttributeHandlerContext* context, uint8 id,
|
||||
const AttributeValue& value, AttributeHandler** _handler);
|
||||
|
||||
virtual status_t Delete(AttributeHandlerContext* context);
|
||||
|
||||
private:
|
||||
BPackageInfoAttributeValue& fPackageInfoValue;
|
||||
BPackageVersionData& fPackageVersionData;
|
||||
bool fNotify;
|
||||
};
|
||||
|
||||
|
||||
struct PackageResolvableAttributeHandler : AttributeHandler {
|
||||
PackageResolvableAttributeHandler(
|
||||
BPackageInfoAttributeValue& packageInfoValue);
|
||||
|
||||
virtual status_t HandleAttribute(
|
||||
AttributeHandlerContext* context, uint8 id,
|
||||
const AttributeValue& value, AttributeHandler** _handler);
|
||||
|
||||
virtual status_t Delete(AttributeHandlerContext* context);
|
||||
|
||||
private:
|
||||
BPackageInfoAttributeValue& fPackageInfoValue;
|
||||
};
|
||||
|
||||
|
||||
struct PackageResolvableExpressionAttributeHandler
|
||||
: AttributeHandler {
|
||||
PackageResolvableExpressionAttributeHandler(
|
||||
BPackageInfoAttributeValue& packageInfoValue);
|
||||
|
||||
virtual status_t HandleAttribute(
|
||||
AttributeHandlerContext* context, uint8 id,
|
||||
const AttributeValue& value, AttributeHandler** _handler);
|
||||
|
||||
virtual status_t Delete(AttributeHandlerContext* context);
|
||||
|
||||
private:
|
||||
BPackageInfoAttributeValue& fPackageInfoValue;
|
||||
};
|
||||
|
||||
|
||||
struct PackageAttributeHandler : AttributeHandler {
|
||||
virtual status_t HandleAttribute(
|
||||
AttributeHandlerContext* context, uint8 id,
|
||||
const AttributeValue& value, AttributeHandler** _handler);
|
||||
|
||||
private:
|
||||
BPackageInfoAttributeValue fPackageInfoValue;
|
||||
};
|
||||
|
||||
|
||||
struct LowLevelAttributeHandler : AttributeHandler {
|
||||
LowLevelAttributeHandler();
|
||||
LowLevelAttributeHandler(uint8 id,
|
||||
const BPackageAttributeValue& value, void* parentToken,
|
||||
void* token);
|
||||
|
||||
virtual status_t HandleAttribute(
|
||||
AttributeHandlerContext* context, uint8 id,
|
||||
const AttributeValue& value, AttributeHandler** _handler);
|
||||
virtual status_t Delete(AttributeHandlerContext* context);
|
||||
|
||||
private:
|
||||
void* fParentToken;
|
||||
void* fToken;
|
||||
uint8 fID;
|
||||
AttributeValue fValue;
|
||||
};
|
||||
|
||||
|
||||
struct SectionInfo {
|
||||
uint32 compression;
|
||||
uint32 compressedLength;
|
||||
uint32 uncompressedLength;
|
||||
uint8* data;
|
||||
uint64 offset;
|
||||
uint64 currentOffset;
|
||||
uint64 stringsLength;
|
||||
uint64 stringsCount;
|
||||
char** strings;
|
||||
const char* name;
|
||||
|
||||
SectionInfo(const char* _name)
|
||||
:
|
||||
data(NULL),
|
||||
strings(NULL),
|
||||
name(_name)
|
||||
{
|
||||
}
|
||||
|
||||
~SectionInfo()
|
||||
{
|
||||
delete[] strings;
|
||||
delete[] data;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
||||
|
||||
protected:
|
||||
const char* CheckCompression(
|
||||
const SectionInfo& section) const;
|
||||
|
||||
status_t ParseStrings();
|
||||
|
||||
status_t ParsePackageAttributesSection(
|
||||
AttributeHandlerContext* context,
|
||||
AttributeHandler* rootAttributeHandler);
|
||||
status_t ParseAttributeTree(
|
||||
AttributeHandlerContext* context,
|
||||
bool& _sectionHandled);
|
||||
|
||||
virtual status_t ReadAttributeValue(uint8 type, uint8 encoding,
|
||||
AttributeValue& _value);
|
||||
|
||||
status_t ReadUnsignedLEB128(uint64& _value);
|
||||
|
||||
status_t ReadBuffer(off_t offset, void* buffer,
|
||||
size_t size);
|
||||
status_t ReadCompressedBuffer(
|
||||
const SectionInfo& section);
|
||||
|
||||
inline AttributeHandler* CurrentAttributeHandler() const;
|
||||
inline void PushAttributeHandler(
|
||||
AttributeHandler* handler);
|
||||
inline AttributeHandler* PopAttributeHandler();
|
||||
inline void ClearAttributeHandlerStack();
|
||||
|
||||
inline SectionInfo* CurrentSection();
|
||||
inline void SetCurrentSection(SectionInfo* section);
|
||||
|
||||
protected:
|
||||
SectionInfo fPackageAttributesSection;
|
||||
|
||||
private:
|
||||
status_t _ParseAttributeTree(
|
||||
AttributeHandlerContext* context);
|
||||
|
||||
template<typename Type>
|
||||
inline status_t _Read(Type& _value);
|
||||
|
||||
status_t _ReadSectionBuffer(void* buffer, size_t size);
|
||||
|
||||
status_t _ReadAttribute(uint8& _id,
|
||||
AttributeValue& _value,
|
||||
bool* _hasChildren = NULL,
|
||||
uint64* _tag = NULL);
|
||||
|
||||
status_t _ReadString(const char*& _string,
|
||||
size_t* _stringLength = NULL);
|
||||
|
||||
private:
|
||||
BErrorOutput* fErrorOutput;
|
||||
int fFD;
|
||||
bool fOwnsFD;
|
||||
|
||||
SectionInfo* fCurrentSection;
|
||||
|
||||
AttributeHandlerList fAttributeHandlerStack;
|
||||
|
||||
uint8* fScratchBuffer;
|
||||
size_t fScratchBufferSize;
|
||||
};
|
||||
|
||||
|
||||
inline int
|
||||
ReaderImplBase::FD() const
|
||||
{
|
||||
return fFD;
|
||||
}
|
||||
|
||||
|
||||
inline BErrorOutput*
|
||||
ReaderImplBase::ErrorOutput() const
|
||||
{
|
||||
return fErrorOutput;
|
||||
}
|
||||
|
||||
|
||||
ReaderImplBase::SectionInfo*
|
||||
ReaderImplBase::CurrentSection()
|
||||
{
|
||||
return fCurrentSection;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ReaderImplBase::SetCurrentSection(SectionInfo* section)
|
||||
{
|
||||
fCurrentSection = section;
|
||||
}
|
||||
|
||||
|
||||
template<typename Type>
|
||||
status_t
|
||||
ReaderImplBase::_Read(Type& _value)
|
||||
{
|
||||
return _ReadSectionBuffer(&_value, sizeof(Type));
|
||||
}
|
||||
|
||||
|
||||
inline ReaderImplBase::AttributeHandler*
|
||||
ReaderImplBase::CurrentAttributeHandler() const
|
||||
{
|
||||
return fAttributeHandlerStack.Head();
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
ReaderImplBase::PushAttributeHandler(AttributeHandler* handler)
|
||||
{
|
||||
fAttributeHandlerStack.Add(handler);
|
||||
}
|
||||
|
||||
|
||||
inline ReaderImplBase::AttributeHandler*
|
||||
ReaderImplBase::PopAttributeHandler()
|
||||
{
|
||||
return fAttributeHandlerStack.RemoveHead();
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
ReaderImplBase::ClearAttributeHandlerStack()
|
||||
{
|
||||
fAttributeHandlerStack.MakeEmpty();
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace V1
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__V1__PRIVATE__READER_IMPL_BASE_H_
|
||||
Reference in New Issue
Block a user