* implemented repository reader and fixed some bugs in writer that

have been exposed during testing of reader

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40494 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2011-02-14 20:25:10 +00:00
parent 973f8e214d
commit 34d56c1bf5
11 changed files with 234 additions and 1929 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ namespace BPrivate {
using BPrivate::RepositoryReaderImpl;
class BErrorOutput;
class BRepositoryContentHandler;
class BPackageContentHandler;
class BRepositoryReader {
@@ -46,7 +46,7 @@ struct hpkg_repo_header {
uint32 magic; // "hpkr"
uint16 header_size;
uint16 version;
uint32 total_size;
uint64 total_size;
// repository info section
uint32 info_compression;
@@ -55,10 +55,10 @@ struct hpkg_repo_header {
// package attributes section
uint32 packages_compression;
uint32 packages_length_compressed;
uint32 packages_length_uncompressed;
uint32 packages_strings_length;
uint32 packages_strings_count;
uint64 packages_length_compressed;
uint64 packages_length_uncompressed;
uint64 packages_strings_length;
uint64 packages_strings_count;
};
@@ -6,14 +6,9 @@
#define _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
#include <SupportDefs.h>
#include <package/hpkg/ReaderImplBase.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>
#include <package/RepositoryInfo.h>
namespace BPackageKit {
@@ -21,165 +16,34 @@ namespace BPackageKit {
namespace BHPKG {
class BPackageEntry;
class BPackageEntryAttribute;
class BErrorOutput;
namespace BPrivate {
class PackageReaderImpl {
class RepositoryReaderImpl : public ReaderImplBase {
typedef ReaderImplBase inherited;
public:
PackageReaderImpl(
RepositoryReaderImpl(
BErrorOutput* errorOutput);
~PackageReaderImpl();
~RepositoryReaderImpl();
status_t Init(const char* fileName);
status_t Init(int fd, bool keepFD);
status_t GetRepositoryInfo(
BRepositoryInfo* _repositoryInfo) const;
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;
SectionInfo fRepositoryInfoSection;
BRepositoryInfo fRepositoryInfo;
};
template<typename Type>
status_t
PackageReaderImpl::_Read(Type& _value)
{
return _ReadSectionBuffer(&_value, sizeof(Type));
}
} // namespace BPrivate
} // namespace BHPKG
+25 -6
View File
@@ -185,13 +185,18 @@ protected:
void WriteBuffer(const void* buffer, size_t size,
off_t offset);
int FD() const;
AbstractDataWriter* DataWriter() const;
const PackageAttributeList& PackageAttributes() const;
PackageAttributeList& PackageAttributes();
inline int FD() const;
void SetDataWriter(AbstractDataWriter* dataWriter);
void SetFinished(bool finished);
inline const PackageAttributeList& PackageAttributes() const;
inline PackageAttributeList& PackageAttributes();
inline const StringCache& PackageStringCache() const;
inline StringCache& PackageStringCache();
inline AbstractDataWriter* DataWriter() const;
inline void SetDataWriter(AbstractDataWriter* dataWriter);
inline void SetFinished(bool finished);
private:
void _WritePackageAttributes(
@@ -283,6 +288,20 @@ WriterImplBase::PackageAttributes()
}
inline const StringCache&
WriterImplBase::PackageStringCache() const
{
return fPackageStringCache;
}
inline StringCache&
WriterImplBase::PackageStringCache()
{
return fPackageStringCache;
}
inline void
WriterImplBase::SetFinished(bool finished)
{