Largish adjustments to PackagerReaderImpl and package attribute
handling: * package attributes are now compatible with the low level attribute handling of other HPKG attributes (such that 'package dump' now shows package attributes, too) * dropped type names from hpkg format, the attributes were identified by IDs already and this simplifies the code considerably. Type names are now handled in BLowLevelPackageHandler only. * instead of rolling their own mechanism, high-level package attributes handling is now implemented via a corresonding set of AttributeHandler-subclasses * adjusted package writer to only write package attributes that are needed (empty ones are left out) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40466 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
enum BPackageInfoAttributeIndex {
|
||||
enum BPackageInfoAttributeID {
|
||||
B_PACKAGE_INFO_NAME = 0,
|
||||
B_PACKAGE_INFO_SUMMARY, // single line
|
||||
B_PACKAGE_INFO_DESCRIPTION, // multiple lines possible
|
||||
|
||||
@@ -69,29 +69,49 @@ enum {
|
||||
|
||||
|
||||
// package attribute IDs
|
||||
enum BPackageAttributeID {
|
||||
B_PACKAGE_ATTRIBUTE_NAME = 0,
|
||||
B_PACKAGE_ATTRIBUTE_SUMMARY,
|
||||
B_PACKAGE_ATTRIBUTE_DESCRIPTION,
|
||||
B_PACKAGE_ATTRIBUTE_VENDOR,
|
||||
B_PACKAGE_ATTRIBUTE_PACKAGER,
|
||||
B_PACKAGE_ATTRIBUTE_ARCHITECTURE,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_MAJOR,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_MINOR,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_MICRO,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_RELEASE,
|
||||
B_PACKAGE_ATTRIBUTE_COPYRIGHT,
|
||||
B_PACKAGE_ATTRIBUTE_LICENSE,
|
||||
B_PACKAGE_ATTRIBUTE_PROVIDES,
|
||||
B_PACKAGE_ATTRIBUTE_PROVIDES_TYPE,
|
||||
B_PACKAGE_ATTRIBUTE_REQUIRES,
|
||||
B_PACKAGE_ATTRIBUTE_SUPPLEMENTS,
|
||||
B_PACKAGE_ATTRIBUTE_CONFLICTS,
|
||||
B_PACKAGE_ATTRIBUTE_FRESHENS,
|
||||
B_PACKAGE_ATTRIBUTE_REPLACES,
|
||||
B_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
||||
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_RELEASE = 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_PACKAGE_ATTRIBUTE_ENUM_COUNT,
|
||||
B_HPKG_ATTRIBUTE_ID_ENUM_COUNT,
|
||||
};
|
||||
|
||||
|
||||
@@ -102,7 +122,7 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
// file types (HPKG_ATTRIBUTE_NAME_FILE_TYPE)
|
||||
// file types (B_HPKG_ATTRIBUTE_ID_FILE_TYPE)
|
||||
enum {
|
||||
B_HPKG_FILE_TYPE_FILE = 0,
|
||||
B_HPKG_FILE_TYPE_DIRECTORY = 1,
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
@@ -24,14 +26,18 @@ class BLowLevelPackageContentHandler {
|
||||
public:
|
||||
virtual ~BLowLevelPackageContentHandler();
|
||||
|
||||
virtual status_t HandleAttribute(const char* attributeName,
|
||||
virtual status_t HandleAttribute(BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value,
|
||||
void* parentToken, void*& _token) = 0;
|
||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
||||
virtual status_t HandleAttributeDone(
|
||||
BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value,
|
||||
void* token) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
|
||||
protected:
|
||||
static const char* AttributeNameForID(uint8 id);
|
||||
};
|
||||
|
||||
|
||||
@@ -47,7 +53,6 @@ public:
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value
|
||||
) = 0;
|
||||
virtual status_t HandlePackageAttributesDone() = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
@@ -51,42 +51,52 @@ struct BPackageInfoAttributeValue {
|
||||
BPackageResolvableData resolvable;
|
||||
BPackageResolvableExpressionData resolvableExpression;
|
||||
};
|
||||
uint8 attributeIndex;
|
||||
BPackageInfoAttributeID attributeID;
|
||||
|
||||
public:
|
||||
inline BPackageInfoAttributeValue();
|
||||
BPackageInfoAttributeValue();
|
||||
|
||||
inline void SetTo(BPackageInfoAttributeIndex index,
|
||||
void SetTo(BPackageInfoAttributeID id,
|
||||
uint8 value);
|
||||
inline void SetTo(BPackageInfoAttributeIndex index,
|
||||
void SetTo(BPackageInfoAttributeID id,
|
||||
const char* value);
|
||||
|
||||
void Clear();
|
||||
};
|
||||
|
||||
|
||||
inline
|
||||
BPackageInfoAttributeValue::BPackageInfoAttributeValue()
|
||||
:
|
||||
attributeIndex(B_PACKAGE_INFO_ENUM_COUNT)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeIndex index, uint8 value)
|
||||
inline void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id, uint8 value)
|
||||
{
|
||||
attributeIndex = index;
|
||||
attributeID = id;
|
||||
unsignedInt = value;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeIndex index,
|
||||
inline void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id,
|
||||
const char* value)
|
||||
{
|
||||
attributeIndex = index;
|
||||
attributeID = id;
|
||||
string = value;
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BPackageInfoAttributeValue::Clear()
|
||||
{
|
||||
memset(this, 0, sizeof(BPackageInfoAttributeValue));
|
||||
attributeID = B_PACKAGE_INFO_ENUM_COUNT;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
@@ -29,9 +29,7 @@ public:
|
||||
|
||||
virtual void OnEntryAdded(const char* path) = 0;
|
||||
|
||||
virtual void OnTOCSizeInfo(
|
||||
uint64 uncompressedAttributeTypesSize,
|
||||
uint64 uncompressedStringsSize,
|
||||
virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize,
|
||||
uint64 uncompressedMainSize,
|
||||
uint64 uncompressedTOCSize) = 0;
|
||||
virtual void OnPackageAttributesSizeInfo(uint32 stringCount,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__REPOSITORY_CONTENT_HANDLER_H_
|
||||
#define _PACKAGE__HPKG__REPOSITORY_CONTENT_HANDLER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
class BPackageInfo;
|
||||
class BRepositoryInfo;
|
||||
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BRepositoryContentHandler {
|
||||
public:
|
||||
virtual ~BRepositoryContentHandler();
|
||||
|
||||
virtual status_t HandleRepositoryInfo(
|
||||
const BRepositoryInfo& info) = 0;
|
||||
virtual status_t HandlePackage(const BPackageInfo& info) = 0;
|
||||
virtual status_t HandlePackagesDone() = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__REPOSITORY_CONTENT_HANDLER_H_
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__REPOSITORY_READER_H_
|
||||
#define _PACKAGE__HPKG__REPOSITORY_READER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class RepositoryReaderImpl;
|
||||
}
|
||||
using BPrivate::RepositoryReaderImpl;
|
||||
|
||||
class BErrorOutput;
|
||||
class BRepositoryContentHandler;
|
||||
|
||||
|
||||
class BRepositoryReader {
|
||||
public:
|
||||
BRepositoryReader(BErrorOutput* errorOutput);
|
||||
~BRepositoryReader();
|
||||
|
||||
status_t Init(const char* fileName);
|
||||
status_t ParseContent(
|
||||
BPackageContentHandler* contentHandler);
|
||||
|
||||
private:
|
||||
RepositoryReaderImpl* fImpl;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__REPOSITORY_READER_H_
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
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;
|
||||
uint32 total_size;
|
||||
|
||||
// repository info section
|
||||
uint32 info_compression;
|
||||
uint32 info_length_compressed;
|
||||
uint32 info_length_uncompressed;
|
||||
|
||||
// package attributes section
|
||||
uint32 packages_compression;
|
||||
uint32 packages_length_compressed;
|
||||
uint32 packages_length_uncompressed;
|
||||
uint32 packages_strings_length;
|
||||
uint32 packages_strings_count;
|
||||
};
|
||||
|
||||
|
||||
// attribute tag arithmetics
|
||||
// (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding)
|
||||
#define HPKG_ATTRIBUTE_TAG_COMPOSE(id, type, encoding, hasChildren) \
|
||||
(((uint16(encoding) << 10) | (uint16((hasChildren) ? 1 : 0) << 9) \
|
||||
| (uint16(type) << 6) | (uint16(id))) + 1)
|
||||
#define HPKG_ATTRIBUTE_TAG_ENCODING(tag) \
|
||||
((uint16((tag) - 1) >> 10) & 0x3)
|
||||
#define HPKG_ATTRIBUTE_TAG_HAS_CHILDREN(tag) \
|
||||
(((uint16((tag) - 1) >> 9) & 0x1) != 0)
|
||||
#define HPKG_ATTRIBUTE_TAG_TYPE(tag) \
|
||||
((uint16((tag) - 1) >> 6) & 0x7)
|
||||
#define HPKG_ATTRIBUTE_TAG_ID(tag) \
|
||||
(uint16((tag) - 1) & 0x3f)
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
@@ -46,16 +46,18 @@ public:
|
||||
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 PackageVersionAttributeHandler;
|
||||
struct PackageResolvableAttributeHandler;
|
||||
struct PackageResolvableExpressionAttributeHandler;
|
||||
struct RootAttributeHandler;
|
||||
struct LowLevelAttributeHandler;
|
||||
struct PackageContentListHandler;
|
||||
|
||||
struct SectionInfo {
|
||||
@@ -94,8 +96,6 @@ private:
|
||||
const char* _CheckCompression(
|
||||
const SectionInfo& section) const;
|
||||
|
||||
status_t _ParseTOCAttributeTypes();
|
||||
|
||||
status_t _ParseStrings();
|
||||
|
||||
status_t _ParseContent(AttributeHandlerContext* context,
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
const char* resolvableName,
|
||||
bool hasChildren);
|
||||
|
||||
status_t _ReadPackageAttribute(uint8& _id,
|
||||
status_t _ReadAttribute(uint8& _id,
|
||||
AttributeValue& _value,
|
||||
bool* _hasChildren = NULL,
|
||||
uint64* _tag = NULL);
|
||||
@@ -141,8 +141,6 @@ private:
|
||||
status_t _ReadCompressedBuffer(
|
||||
const SectionInfo& section);
|
||||
|
||||
static int8 _GetStandardIndex(const AttributeType* type);
|
||||
|
||||
inline AttributeHandler* _CurrentAttributeHandler() const;
|
||||
inline void _PushAttributeHandler(
|
||||
AttributeHandler* handler);
|
||||
@@ -157,15 +155,10 @@ private:
|
||||
uint64 fHeapOffset;
|
||||
uint64 fHeapSize;
|
||||
|
||||
uint64 fTOCAttributeTypesLength;
|
||||
uint64 fTOCAttributeTypesCount;
|
||||
|
||||
SectionInfo fTOCSection;
|
||||
SectionInfo fPackageAttributesSection;
|
||||
SectionInfo* fCurrentSection;
|
||||
|
||||
AttributeTypeReference* fAttributeTypes;
|
||||
|
||||
AttributeHandlerList* fAttributeHandlerStack;
|
||||
|
||||
uint8* fScratchBuffer;
|
||||
|
||||
@@ -42,16 +42,10 @@ public:
|
||||
status_t Finish();
|
||||
|
||||
private:
|
||||
struct AttributeTypeKey;
|
||||
struct AttributeType;
|
||||
struct AttributeTypeHashDefinition;
|
||||
struct Attribute;
|
||||
struct AttributeTypeUsageGreater;
|
||||
struct Entry;
|
||||
struct SubPathAdder;
|
||||
|
||||
typedef BOpenHashTable<AttributeTypeHashDefinition>
|
||||
AttributeTypeTable;
|
||||
typedef DoublyLinkedList<Entry> EntryList;
|
||||
|
||||
private:
|
||||
@@ -66,9 +60,8 @@ private:
|
||||
status_t _CheckLicenses();
|
||||
|
||||
void _WriteTOC(hpkg_header& header);
|
||||
int32 _WriteTOCSections(uint64& _attributeTypesSize,
|
||||
uint64& _stringsSize, uint64& _mainSize);
|
||||
void _WriteAttributeTypes();
|
||||
int32 _WriteTOCSections(uint64& _stringsSize,
|
||||
uint64& _mainSize);
|
||||
void _WriteAttributeChildren(Attribute* attribute);
|
||||
|
||||
void _WritePackageAttributes(hpkg_header& header);
|
||||
@@ -76,23 +69,21 @@ private:
|
||||
void _AddEntry(int dirFD, Entry* entry,
|
||||
const char* fileName, char* pathBuffer);
|
||||
|
||||
Attribute* _AddAttribute(const char* attributeName,
|
||||
Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
||||
const AttributeValue& value);
|
||||
|
||||
template<typename Type>
|
||||
inline Attribute* _AddAttribute(const char* attributeName,
|
||||
inline Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
||||
Type value);
|
||||
|
||||
Attribute* _AddStringAttribute(const char* attributeName,
|
||||
Attribute* _AddStringAttribute(
|
||||
BHPKGAttributeID attributeID,
|
||||
const char* value);
|
||||
Attribute* _AddDataAttribute(const char* attributeName,
|
||||
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
||||
uint64 dataSize, uint64 dataOffset);
|
||||
Attribute* _AddDataAttribute(const char* attributeName,
|
||||
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
||||
uint64 dataSize, const uint8* data);
|
||||
|
||||
AttributeType* _GetAttributeType(const char* attributeName,
|
||||
uint8 type);
|
||||
|
||||
status_t _AddData(BDataReader& dataReader, off_t size);
|
||||
|
||||
status_t _WriteUncompressedData(BDataReader& dataReader,
|
||||
@@ -117,7 +108,6 @@ private:
|
||||
Attribute* fTopAttribute;
|
||||
|
||||
StringCache fStringCache;
|
||||
AttributeTypeTable* fAttributeTypes;
|
||||
|
||||
BPackageInfo fPackageInfo;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <util/SinglyLinkedList.h>
|
||||
|
||||
#include <package/hpkg/PackageAttributeValue.h>
|
||||
#include <package/hpkg/PackageContentHandler.h>
|
||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||
#include <package/hpkg/PackageReader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BPackageEntry;
|
||||
class BPackageEntryAttribute;
|
||||
class BErrorOutput;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class PackageReaderImpl {
|
||||
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() { 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;
|
||||
|
||||
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 BPackageAttributeValue AttributeValue;
|
||||
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
||||
|
||||
private:
|
||||
status_t _Init(const char* fileName);
|
||||
|
||||
const char* _CheckCompression(
|
||||
const SectionInfo& section) const;
|
||||
|
||||
status_t _ParseTOCAttributeTypes();
|
||||
|
||||
status_t _ParseStrings();
|
||||
|
||||
status_t _ParseContent(AttributeHandlerContext* context,
|
||||
AttributeHandler* rootAttributeHandler);
|
||||
status_t _ParseAttributeTree(
|
||||
AttributeHandlerContext* context);
|
||||
|
||||
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);
|
||||
|
||||
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 _ReadSectionBuffer(void* buffer, size_t size);
|
||||
|
||||
status_t _ReadBuffer(off_t offset, void* buffer,
|
||||
size_t size);
|
||||
status_t _ReadCompressedBuffer(
|
||||
const SectionInfo& section);
|
||||
|
||||
static int8 _GetStandardIndex(const AttributeType* type);
|
||||
|
||||
inline AttributeHandler* _CurrentAttributeHandler() const;
|
||||
inline void _PushAttributeHandler(
|
||||
AttributeHandler* handler);
|
||||
inline AttributeHandler* _PopAttributeHandler();
|
||||
|
||||
private:
|
||||
BErrorOutput* fErrorOutput;
|
||||
int fFD;
|
||||
bool fOwnsFD;
|
||||
|
||||
uint64 fTotalSize;
|
||||
uint64 fHeapOffset;
|
||||
uint64 fHeapSize;
|
||||
|
||||
uint64 fTOCAttributeTypesLength;
|
||||
uint64 fTOCAttributeTypesCount;
|
||||
|
||||
SectionInfo fTOCSection;
|
||||
SectionInfo fPackageAttributesSection;
|
||||
SectionInfo* fCurrentSection;
|
||||
|
||||
AttributeTypeReference* fAttributeTypes;
|
||||
|
||||
AttributeHandlerList* fAttributeHandlerStack;
|
||||
|
||||
uint8* fScratchBuffer;
|
||||
size_t fScratchBufferSize;
|
||||
};
|
||||
|
||||
|
||||
template<typename Type>
|
||||
status_t
|
||||
PackageReaderImpl::_Read(Type& _value)
|
||||
{
|
||||
return _ReadSectionBuffer(&_value, sizeof(Type));
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <util/DoublyLinkedList.h>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/DataOutput.h>
|
||||
#include <package/hpkg/Strings.h>
|
||||
@@ -79,10 +79,10 @@ protected:
|
||||
struct PackageAttribute :
|
||||
public DoublyLinkedListLinkImpl<PackageAttribute>,
|
||||
public AttributeValue {
|
||||
HPKGPackageAttributeID id;
|
||||
BHPKGAttributeID id;
|
||||
DoublyLinkedList<PackageAttribute> children;
|
||||
|
||||
PackageAttribute(HPKGPackageAttributeID id_, uint8 type,
|
||||
PackageAttribute(BHPKGAttributeID id_, uint8 type,
|
||||
uint8 encoding);
|
||||
~PackageAttribute();
|
||||
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
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_attribute_types_length;
|
||||
uint64 toc_attribute_types_count;
|
||||
uint64 toc_strings_length;
|
||||
uint64 toc_strings_count;
|
||||
};
|
||||
|
||||
|
||||
// header
|
||||
struct hpkg_repo_header {
|
||||
uint32 magic; // "hpkr"
|
||||
uint16 header_size;
|
||||
uint16 version;
|
||||
uint32 total_size;
|
||||
|
||||
// repository info section
|
||||
uint32 info_compression;
|
||||
uint32 info_length_compressed;
|
||||
uint32 info_length_uncompressed;
|
||||
|
||||
// package attributes section
|
||||
uint32 packages_compression;
|
||||
uint32 packages_length_compressed;
|
||||
uint32 packages_length_uncompressed;
|
||||
uint32 packages_strings_length;
|
||||
uint32 packages_strings_count;
|
||||
};
|
||||
|
||||
|
||||
// attribute tag arithmetics
|
||||
#define HPKG_ATTRIBUTE_TAG_COMPOSE(index, encoding, hasChildren) \
|
||||
(((uint64(index) << 3) | uint64(encoding) << 1 \
|
||||
| ((hasChildren) ? 1 : 0)) + 1)
|
||||
#define HPKG_ATTRIBUTE_TAG_INDEX(tag) (uint64((tag) - 1) >> 3)
|
||||
#define HPKG_ATTRIBUTE_TAG_ENCODING(tag) ((uint64((tag) - 1) >> 1) & 0x3)
|
||||
#define HPKG_ATTRIBUTE_TAG_HAS_CHILDREN(tag) ((uint64((tag) - 1) & 0x1) != 0)
|
||||
|
||||
// package attribute tag arithmetics
|
||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_COMPOSE(id, type, encoding, hasChildren) \
|
||||
(((uint16(encoding) << 9) | (((hasChildren) ? 1 : 0) << 8) \
|
||||
| (uint16(type) << 5) | (uint16(id))) + 1)
|
||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_ENCODING(tag) \
|
||||
((uint16((tag) - 1) >> 9) & 0x3)
|
||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_HAS_CHILDREN(tag) \
|
||||
(((uint16((tag) - 1) >> 8) & 0x1) != 0)
|
||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_TYPE(tag) \
|
||||
((uint16((tag) - 1) >> 5) & 0x7)
|
||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_ID(tag) \
|
||||
(uint16((tag) - 1) & 0x1f)
|
||||
|
||||
|
||||
// standard attribute names
|
||||
#define HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY "dir:entry"
|
||||
// path/entry name (string)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_TYPE "file:type"
|
||||
// file type (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS "file:permissions"
|
||||
// file permissions (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_USER "file:user"
|
||||
// file user (string)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_GROUP "file:group"
|
||||
// file group (string)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATIME "file:atime"
|
||||
// file access time in seconds (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_MTIME "file:mtime"
|
||||
// file modification time in seconds (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_CRTIME "file:crtime"
|
||||
// file creation time in seconds (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATIME_NANOS "file:atime:nanos"
|
||||
// file access time nanoseconds fraction (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_MTIME_NANOS "file:mtime:nanos"
|
||||
// file modification time nanoseconds fraction (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_CRTIM_NANOS "file:crtime:nanos"
|
||||
// file creation time nanoseconds fraction (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE "file:attribute"
|
||||
// file attribute (string)
|
||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE "file:attribute:type"
|
||||
// file attribute type (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_DATA "data"
|
||||
// (file/attribute) data (raw)
|
||||
#define HPKG_ATTRIBUTE_NAME_DATA_COMPRESSION "data:compression"
|
||||
// (file/attribute) data compression (uint, default: none)
|
||||
#define HPKG_ATTRIBUTE_NAME_DATA_SIZE "data:size"
|
||||
// (file/attribute) uncompressed data size (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_DATA_CHUNK_SIZE "data:chunk_size"
|
||||
// the size of compressed (file/attribute) data chunks (uint)
|
||||
#define HPKG_ATTRIBUTE_NAME_SYMLINK_PATH "symlink:path"
|
||||
// symlink path (string)
|
||||
|
||||
|
||||
// package attribute IDs
|
||||
enum HPKGPackageAttributeID {
|
||||
HPKG_PACKAGE_ATTRIBUTE_NAME = 0,
|
||||
HPKG_PACKAGE_ATTRIBUTE_SUMMARY,
|
||||
HPKG_PACKAGE_ATTRIBUTE_DESCRIPTION,
|
||||
HPKG_PACKAGE_ATTRIBUTE_VENDOR,
|
||||
HPKG_PACKAGE_ATTRIBUTE_PACKAGER,
|
||||
HPKG_PACKAGE_ATTRIBUTE_FLAGS,
|
||||
HPKG_PACKAGE_ATTRIBUTE_ARCHITECTURE,
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MAJOR,
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MINOR,
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MICRO,
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_RELEASE,
|
||||
HPKG_PACKAGE_ATTRIBUTE_COPYRIGHT,
|
||||
HPKG_PACKAGE_ATTRIBUTE_LICENSE,
|
||||
HPKG_PACKAGE_ATTRIBUTE_PROVIDES,
|
||||
HPKG_PACKAGE_ATTRIBUTE_PROVIDES_TYPE,
|
||||
HPKG_PACKAGE_ATTRIBUTE_REQUIRES,
|
||||
HPKG_PACKAGE_ATTRIBUTE_SUPPLEMENTS,
|
||||
HPKG_PACKAGE_ATTRIBUTE_CONFLICTS,
|
||||
HPKG_PACKAGE_ATTRIBUTE_FRESHENS,
|
||||
HPKG_PACKAGE_ATTRIBUTE_REPLACES,
|
||||
HPKG_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
||||
HPKG_PACKAGE_ATTRIBUTE_CHECKSUM,
|
||||
//
|
||||
HPKG_PACKAGE_ATTRIBUTE_ENUM_COUNT,
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
Reference in New Issue
Block a user