Refactored hpkg implementation to provide some separation between
public and private API (still far from ideal, but a start): * moved several HPKG-classes into the public namespace BPackageKit::HPKG * added fImpl-wrappers around PackageReader and PackageWriter to hide most of the gory details * adjusted 'package'-binary and packagefs accordingly git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40320 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
||||
#define _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/BufferCache.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class BlockBufferCacheImpl;
|
||||
}
|
||||
using BPrivate::BlockBufferCacheImpl;
|
||||
|
||||
|
||||
class BBlockBufferCache : public BBufferCache, public BBufferCacheLockable {
|
||||
public:
|
||||
BBlockBufferCache(size_t blockSize,
|
||||
uint32 maxCachedBlocks);
|
||||
virtual ~BBlockBufferCache();
|
||||
|
||||
virtual status_t Init();
|
||||
|
||||
virtual CachedBuffer* GetBuffer(size_t size,
|
||||
CachedBuffer** owner = NULL,
|
||||
bool* _newBuffer = NULL);
|
||||
virtual void PutBufferAndCache(CachedBuffer** owner);
|
||||
virtual void PutBuffer(CachedBuffer** owner);
|
||||
|
||||
private:
|
||||
BlockBufferCacheImpl* fImpl;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__BUFFER_CACHE_H_
|
||||
#define _PACKAGE__HPKG__BUFFER_CACHE_H_
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class CachedBuffer;
|
||||
}
|
||||
using BPrivate::CachedBuffer;
|
||||
|
||||
|
||||
class BBufferCache {
|
||||
public:
|
||||
virtual ~BBufferCache();
|
||||
|
||||
virtual CachedBuffer* GetBuffer(size_t size,
|
||||
CachedBuffer** owner = NULL,
|
||||
bool* _newBuffer = NULL) = 0;
|
||||
virtual void PutBufferAndCache(CachedBuffer** owner) = 0;
|
||||
// caller is buffer owner and wants the
|
||||
// buffer cached, if possible
|
||||
virtual void PutBuffer(CachedBuffer** owner) = 0;
|
||||
// puts the buffer for good, owner might
|
||||
// have called PutBufferAndCache() before
|
||||
// and might not own a buffer anymore
|
||||
};
|
||||
|
||||
|
||||
class BBufferCacheLockable {
|
||||
public:
|
||||
virtual ~BBufferCacheLockable();
|
||||
|
||||
virtual bool Lock() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__BUFFER_CACHE_H_
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef DATA_OUTPUT_H
|
||||
#define DATA_OUTPUT_H
|
||||
#ifndef _PACKAGE__HPKG__DATA_OUTPUT_H_
|
||||
#define _PACKAGE__HPKG__DATA_OUTPUT_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
@@ -11,22 +11,20 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class DataOutput {
|
||||
class BDataOutput {
|
||||
public:
|
||||
virtual ~DataOutput();
|
||||
virtual ~BDataOutput();
|
||||
|
||||
virtual status_t WriteData(const void* buffer, size_t size) = 0;
|
||||
};
|
||||
|
||||
|
||||
class BufferDataOutput : public DataOutput {
|
||||
class BBufferDataOutput : public BDataOutput {
|
||||
public:
|
||||
BufferDataOutput(void* buffer, size_t size);
|
||||
BBufferDataOutput(void* buffer, size_t size);
|
||||
|
||||
size_t BytesWritten() const { return fBytesWritten; }
|
||||
|
||||
@@ -39,11 +37,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // DATA_OUTPUT_H
|
||||
#endif // _PACKAGE__HPKG__DATA_OUTPUT_H_
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef DATA_READER_H
|
||||
#define DATA_READER_H
|
||||
#ifndef _PACKAGE__HPKG__DATA_READER_H_
|
||||
#define _PACKAGE__HPKG__DATA_READER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
@@ -11,23 +11,21 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class DataReader {
|
||||
class BDataReader {
|
||||
public:
|
||||
virtual ~DataReader();
|
||||
virtual ~BDataReader();
|
||||
|
||||
virtual status_t ReadData(off_t offset, void* buffer,
|
||||
size_t size) = 0;
|
||||
};
|
||||
|
||||
|
||||
class FDDataReader : public DataReader {
|
||||
class BFDDataReader : public BDataReader {
|
||||
public:
|
||||
FDDataReader(int fd);
|
||||
BFDDataReader(int fd);
|
||||
|
||||
virtual status_t ReadData(off_t offset, void* buffer,
|
||||
size_t size);
|
||||
@@ -37,9 +35,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class AttributeDataReader : public DataReader {
|
||||
class BAttributeDataReader : public BDataReader {
|
||||
public:
|
||||
AttributeDataReader(int fd,
|
||||
BAttributeDataReader(int fd,
|
||||
const char* attribute, uint32 type);
|
||||
|
||||
virtual status_t ReadData(off_t offset, void* buffer,
|
||||
@@ -52,9 +50,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class BufferDataReader : public DataReader {
|
||||
class BBufferDataReader : public BDataReader {
|
||||
public:
|
||||
BufferDataReader(const void* data, size_t size);
|
||||
BBufferDataReader(const void* data, size_t size);
|
||||
|
||||
virtual status_t ReadData(off_t offset, void* buffer,
|
||||
size_t size);
|
||||
@@ -65,11 +63,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // DATA_READER_H
|
||||
#endif // _PACKAGE__HPKG__DATA_READER_H_
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ERROR_OUTPUT_H
|
||||
#define ERROR_OUTPUT_H
|
||||
#ifndef _PACKAGE__HPKG__ERROR_OUTPUT_H_
|
||||
#define _PACKAGE__HPKG__ERROR_OUTPUT_H_
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
@@ -13,14 +13,12 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class ErrorOutput {
|
||||
class BErrorOutput {
|
||||
public:
|
||||
virtual ~ErrorOutput();
|
||||
virtual ~BErrorOutput();
|
||||
|
||||
virtual void PrintErrorVarArgs(const char* format,
|
||||
va_list args) = 0;
|
||||
@@ -28,11 +26,9 @@ public:
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // ERROR_OUTPUT_H
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_OUTPUT_H_
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__HPKG_DEFS_H_
|
||||
#define _PACKAGE__HPKG__HPKG_DEFS_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
// magic, version
|
||||
enum {
|
||||
B_HPKG_MAGIC = 'hpkg',
|
||||
B_HPKG_VERSION = 1
|
||||
};
|
||||
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
|
||||
// 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
|
||||
#define B_HPKG_MAX_INLINE_DATA_SIZE 8
|
||||
|
||||
|
||||
// name of file containing package information (in package's root folder)
|
||||
#define B_HPKG_PACKAGE_INFO_FILE_NAME ".PackageInfo"
|
||||
|
||||
|
||||
// default values
|
||||
enum {
|
||||
B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB = 64 * 1024
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__HPKG_DEFS_H_
|
||||
+20
-24
@@ -2,23 +2,21 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_ATTRIBUTE_VALUE_H
|
||||
#define PACKAGE_ATTRIBUTE_VALUE_H
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
struct PackageAttributeValue {
|
||||
struct BPackageAttributeValue {
|
||||
union {
|
||||
int64 signedInt;
|
||||
uint64 unsignedInt;
|
||||
@@ -35,7 +33,7 @@ struct PackageAttributeValue {
|
||||
uint8 encoding;
|
||||
|
||||
public:
|
||||
inline PackageAttributeValue();
|
||||
inline BPackageAttributeValue();
|
||||
|
||||
inline void SetTo(int8 value);
|
||||
inline void SetTo(uint8 value);
|
||||
@@ -51,7 +49,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
PackageAttributeValue::PackageAttributeValue()
|
||||
BPackageAttributeValue::BPackageAttributeValue()
|
||||
:
|
||||
type(B_HPKG_ATTRIBUTE_TYPE_INVALID)
|
||||
{
|
||||
@@ -59,7 +57,7 @@ PackageAttributeValue::PackageAttributeValue()
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(int8 value)
|
||||
BPackageAttributeValue::SetTo(int8 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
@@ -67,7 +65,7 @@ PackageAttributeValue::SetTo(int8 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(uint8 value)
|
||||
BPackageAttributeValue::SetTo(uint8 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
@@ -75,7 +73,7 @@ PackageAttributeValue::SetTo(uint8 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(int16 value)
|
||||
BPackageAttributeValue::SetTo(int16 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
@@ -83,7 +81,7 @@ PackageAttributeValue::SetTo(int16 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(uint16 value)
|
||||
BPackageAttributeValue::SetTo(uint16 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
@@ -91,7 +89,7 @@ PackageAttributeValue::SetTo(uint16 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(int32 value)
|
||||
BPackageAttributeValue::SetTo(int32 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
@@ -99,7 +97,7 @@ PackageAttributeValue::SetTo(int32 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(uint32 value)
|
||||
BPackageAttributeValue::SetTo(uint32 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
@@ -107,7 +105,7 @@ PackageAttributeValue::SetTo(uint32 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(int64 value)
|
||||
BPackageAttributeValue::SetTo(int64 value)
|
||||
{
|
||||
signedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
||||
@@ -115,7 +113,7 @@ PackageAttributeValue::SetTo(int64 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(uint64 value)
|
||||
BPackageAttributeValue::SetTo(uint64 value)
|
||||
{
|
||||
unsignedInt = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
||||
@@ -123,7 +121,7 @@ PackageAttributeValue::SetTo(uint64 value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetTo(const char* value)
|
||||
BPackageAttributeValue::SetTo(const char* value)
|
||||
{
|
||||
string = value;
|
||||
type = B_HPKG_ATTRIBUTE_TYPE_STRING;
|
||||
@@ -131,7 +129,7 @@ PackageAttributeValue::SetTo(const char* value)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetToData(uint64 size, uint64 offset)
|
||||
BPackageAttributeValue::SetToData(uint64 size, uint64 offset)
|
||||
{
|
||||
data.size = size;
|
||||
data.offset = offset;
|
||||
@@ -141,7 +139,7 @@ PackageAttributeValue::SetToData(uint64 size, uint64 offset)
|
||||
|
||||
|
||||
void
|
||||
PackageAttributeValue::SetToData(uint64 size, const void* rawData)
|
||||
BPackageAttributeValue::SetToData(uint64 size, const void* rawData)
|
||||
{
|
||||
data.size = size;
|
||||
if (size > 0)
|
||||
@@ -151,11 +149,9 @@ PackageAttributeValue::SetToData(uint64 size, const void* rawData)
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_ATTRIBUTE_VALUE_H
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BPackageAttributeValue;
|
||||
class BPackageEntry;
|
||||
class BPackageEntryAttribute;
|
||||
|
||||
|
||||
class BLowLevelPackageContentHandler {
|
||||
public:
|
||||
virtual ~BLowLevelPackageContentHandler();
|
||||
|
||||
virtual status_t HandleAttribute(const char* attributeName,
|
||||
const BPackageAttributeValue& value,
|
||||
void* parentToken, void*& _token) = 0;
|
||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
||||
const BPackageAttributeValue& value,
|
||||
void* token) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
|
||||
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 void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_
|
||||
@@ -2,23 +2,21 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_DATA_H
|
||||
#define PACKAGE_DATA_H
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_DATA_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_DATA_H_
|
||||
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class PackageData {
|
||||
class BPackageData {
|
||||
public:
|
||||
PackageData();
|
||||
BPackageData();
|
||||
|
||||
uint64 CompressedSize() const
|
||||
{ return fCompressedSize; }
|
||||
@@ -56,11 +54,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_DATA_H
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_DATA_H_
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_DATA_READER_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_DATA_READER_H_
|
||||
|
||||
|
||||
#include <package/hpkg/DataReader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BBufferCache;
|
||||
class BDataOutput;
|
||||
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 BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_DATA_READER_H_
|
||||
+13
-17
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_ENTRY_H
|
||||
#define PACKAGE_ENTRY_H
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_ENTRY_H_
|
||||
|
||||
|
||||
#include <sys/stat.h>
|
||||
@@ -13,17 +13,15 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class PackageEntry {
|
||||
class BPackageEntry {
|
||||
public:
|
||||
PackageEntry(PackageEntry* parent,
|
||||
BPackageEntry(BPackageEntry* parent,
|
||||
const char* name);
|
||||
|
||||
const PackageEntry* Parent() const { return fParent; }
|
||||
const BPackageEntry* Parent() const { return fParent; }
|
||||
const char* Name() const { return fName; }
|
||||
void* UserToken() const { return fUserToken; }
|
||||
|
||||
@@ -36,7 +34,7 @@ public:
|
||||
const timespec& CreationTime() const
|
||||
{ return fCreationTime; }
|
||||
|
||||
PackageData& Data() { return fData; }
|
||||
BPackageData& Data() { return fData; }
|
||||
|
||||
const char* SymlinkPath() const { return fSymlinkPath; }
|
||||
|
||||
@@ -62,37 +60,35 @@ public:
|
||||
void SetSymlinkPath(const char* path)
|
||||
{ fSymlinkPath = path; }
|
||||
private:
|
||||
PackageEntry* fParent;
|
||||
BPackageEntry* fParent;
|
||||
const char* fName;
|
||||
void* fUserToken;
|
||||
mode_t fMode;
|
||||
timespec fAccessTime;
|
||||
timespec fModifiedTime;
|
||||
timespec fCreationTime;
|
||||
PackageData fData;
|
||||
BPackageData fData;
|
||||
const char* fSymlinkPath;
|
||||
};
|
||||
|
||||
|
||||
inline void
|
||||
PackageEntry::SetType(uint32 type)
|
||||
BPackageEntry::SetType(uint32 type)
|
||||
{
|
||||
fMode = (fMode & ~(uint32)S_IFMT) | (type & S_IFMT);
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
PackageEntry::SetPermissions(uint32 permissions)
|
||||
BPackageEntry::SetPermissions(uint32 permissions)
|
||||
{
|
||||
fMode = (fMode & ~(uint32)ALLPERMS) | (permissions & ALLPERMS);
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_ENTRY_H
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_ENTRY_H_
|
||||
+9
-13
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_ENTRY_ATTRIBUTE_H
|
||||
#define PACKAGE_ENTRY_ATTRIBUTE_H
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_
|
||||
|
||||
|
||||
#include <package/hpkg/PackageData.h>
|
||||
@@ -11,34 +11,30 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class PackageEntryAttribute {
|
||||
class BPackageEntryAttribute {
|
||||
public:
|
||||
PackageEntryAttribute(const char* name);
|
||||
BPackageEntryAttribute(const char* name);
|
||||
|
||||
const char* Name() const { return fName; }
|
||||
uint32 Type() const { return fType; }
|
||||
|
||||
PackageData& Data() { return fData; }
|
||||
BPackageData& Data() { return fData; }
|
||||
|
||||
void SetType(uint32 type) { fType = type; }
|
||||
|
||||
private:
|
||||
const char* fName;
|
||||
uint32 fType;
|
||||
PackageData fData;
|
||||
BPackageData fData;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_ENTRY_ATTRIBUTE_H
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_READER_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_READER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class PackageReaderImpl;
|
||||
}
|
||||
using BPrivate::PackageReaderImpl;
|
||||
|
||||
class BErrorOutput;
|
||||
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 BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_H_
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PACKAGE_WRITER_H_
|
||||
#define _PACKAGE__HPKG__PACKAGE_WRITER_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class PackageWriterImpl;
|
||||
}
|
||||
using BPrivate::PackageWriterImpl;
|
||||
|
||||
|
||||
class BPackageWriter {
|
||||
public:
|
||||
BPackageWriter();
|
||||
~BPackageWriter();
|
||||
|
||||
status_t Init(const char* fileName);
|
||||
status_t AddEntry(const char* fileName);
|
||||
status_t Finish();
|
||||
|
||||
private:
|
||||
PackageWriterImpl* fImpl;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PACKAGE_WRITER_H_
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
||||
#define _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
||||
|
||||
|
||||
#include <package/hpkg/BufferCache.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class BlockBufferCache : public BufferCache {
|
||||
public:
|
||||
BlockBufferCache(size_t blockSize,
|
||||
uint32 maxCachedBlocks);
|
||||
virtual ~BlockBufferCache();
|
||||
|
||||
virtual status_t Init();
|
||||
|
||||
virtual CachedBuffer* GetBuffer(size_t size,
|
||||
CachedBuffer** owner = NULL,
|
||||
bool* _newBuffer = NULL);
|
||||
virtual void PutBufferAndCache(CachedBuffer** owner);
|
||||
virtual void PutBuffer(CachedBuffer** owner);
|
||||
|
||||
virtual bool Lock() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
private:
|
||||
typedef DoublyLinkedList<CachedBuffer> BufferList;
|
||||
|
||||
private:
|
||||
CachedBuffer* _AllocateBuffer(size_t size,
|
||||
CachedBuffer** owner, bool* _newBuffer);
|
||||
// object must not be locked
|
||||
|
||||
private:
|
||||
size_t fBlockSize;
|
||||
uint32 fMaxCachedBlocks;
|
||||
uint32 fAllocatedBlocks;
|
||||
BufferList fUnusedBuffers;
|
||||
BufferList fCachedBuffers;
|
||||
};
|
||||
|
||||
|
||||
class BlockBufferCacheNoLock : public BlockBufferCache {
|
||||
public:
|
||||
BlockBufferCacheNoLock(size_t blockSize,
|
||||
uint32 maxCachedBlocks);
|
||||
virtual ~BlockBufferCacheNoLock();
|
||||
|
||||
virtual bool Lock();
|
||||
virtual void Unlock();
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <util/DoublyLinkedList.h>
|
||||
|
||||
#include <package/hpkg/BufferCache.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class CachedBuffer;
|
||||
|
||||
|
||||
class BlockBufferCacheImpl : public BBufferCache {
|
||||
public:
|
||||
BlockBufferCacheImpl(size_t blockSize,
|
||||
uint32 maxCachedBlocks,
|
||||
BBufferCacheLockable* lockable);
|
||||
~BlockBufferCacheImpl();
|
||||
|
||||
status_t Init();
|
||||
|
||||
CachedBuffer* GetBuffer(size_t size,
|
||||
CachedBuffer** owner = NULL,
|
||||
bool* _newBuffer = NULL);
|
||||
void PutBufferAndCache(CachedBuffer** owner);
|
||||
void PutBuffer(CachedBuffer** owner);
|
||||
|
||||
private:
|
||||
typedef DoublyLinkedList<CachedBuffer> BufferList;
|
||||
|
||||
private:
|
||||
CachedBuffer* _AllocateBuffer(size_t size,
|
||||
CachedBuffer** owner, bool* _newBuffer);
|
||||
// object must not be locked
|
||||
|
||||
private:
|
||||
size_t fBlockSize;
|
||||
uint32 fMaxCachedBlocks;
|
||||
uint32 fAllocatedBlocks;
|
||||
BufferList fUnusedBuffers;
|
||||
BufferList fCachedBuffers;
|
||||
BBufferCacheLockable* fLockable;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_
|
||||
+10
-25
@@ -2,18 +2,20 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__BUFFER_CACHE_H_
|
||||
#define _PACKAGE__HPKG__BUFFER_CACHE_H_
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <util/DoublyLinkedList.h>
|
||||
|
||||
#include <package/hpkg/BufferCache.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@@ -43,26 +45,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class BufferCache {
|
||||
public:
|
||||
virtual ~BufferCache();
|
||||
|
||||
virtual CachedBuffer* GetBuffer(size_t size,
|
||||
CachedBuffer** owner = NULL,
|
||||
bool* _newBuffer = NULL) = 0;
|
||||
virtual void PutBufferAndCache(CachedBuffer** owner) = 0;
|
||||
// caller is buffer owner and wants the
|
||||
// buffer cached, if possible
|
||||
virtual void PutBuffer(CachedBuffer** owner) = 0;
|
||||
// puts the buffer for good, owner might
|
||||
// have called PutBufferAndCache() before
|
||||
// and might not own a buffer anymore
|
||||
};
|
||||
|
||||
|
||||
class CachedBufferPutter {
|
||||
public:
|
||||
CachedBufferPutter(BufferCache* cache, CachedBuffer** owner)
|
||||
CachedBufferPutter(BBufferCache* cache, CachedBuffer** owner)
|
||||
:
|
||||
fCache(cache),
|
||||
fOwner(owner),
|
||||
@@ -70,7 +55,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
CachedBufferPutter(BufferCache* cache, CachedBuffer* buffer)
|
||||
CachedBufferPutter(BBufferCache* cache, CachedBuffer* buffer)
|
||||
:
|
||||
fCache(cache),
|
||||
fOwner(NULL),
|
||||
@@ -89,7 +74,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
BufferCache* fCache;
|
||||
BBufferCache* fCache;
|
||||
CachedBuffer** fOwner;
|
||||
CachedBuffer* fBuffer;
|
||||
};
|
||||
@@ -97,9 +82,9 @@ private:
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__BUFFER_CACHE_H_
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
||||
@@ -2,15 +2,13 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef FD_CLOSER_H
|
||||
#define FD_CLOSER_H
|
||||
#ifndef _PACKAGE__HPKG__FD_CLOSER_H_
|
||||
#define _PACKAGE__HPKG__FD_CLOSER_H_
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
struct FDCloser {
|
||||
@@ -31,11 +29,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // FD_CLOSER_H
|
||||
#endif // _PACKAGE__HPKG__FD_CLOSER_H_
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_DATA_READER_H
|
||||
#define PACKAGE_DATA_READER_H
|
||||
|
||||
|
||||
#include <package/hpkg/DataReader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class BufferCache;
|
||||
class DataOutput;
|
||||
class PackageData;
|
||||
|
||||
|
||||
class PackageDataReader : public DataReader {
|
||||
public:
|
||||
PackageDataReader(DataReader* dataReader);
|
||||
virtual ~PackageDataReader();
|
||||
|
||||
virtual status_t Init(const PackageData& data) = 0;
|
||||
|
||||
virtual status_t ReadData(off_t offset, void* buffer,
|
||||
size_t size);
|
||||
virtual status_t ReadDataToOutput(off_t offset, size_t size,
|
||||
DataOutput* output) = 0;
|
||||
|
||||
virtual uint64 Size() const = 0;
|
||||
virtual size_t BlockSize() const = 0;
|
||||
|
||||
protected:
|
||||
DataReader* fDataReader;
|
||||
};
|
||||
|
||||
|
||||
class PackageDataReaderFactory {
|
||||
public:
|
||||
PackageDataReaderFactory(
|
||||
BufferCache* bufferCache);
|
||||
|
||||
status_t CreatePackageDataReader(DataReader* dataReader,
|
||||
const PackageData& data,
|
||||
PackageDataReader*& _reader);
|
||||
|
||||
private:
|
||||
BufferCache* fBufferCache;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_DATA_READER_H
|
||||
+22
-47
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_READER_H
|
||||
#define PACKAGE_READER_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
@@ -11,59 +11,34 @@
|
||||
#include <util/SinglyLinkedList.h>
|
||||
|
||||
#include <package/hpkg/PackageAttributeValue.h>
|
||||
#include <package/hpkg/PackageContentHandler.h>
|
||||
#include <package/hpkg/PackageReader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BPackageEntry;
|
||||
class BPackageEntryAttribute;
|
||||
class BErrorOutput;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ErrorOutput;
|
||||
class PackageEntry;
|
||||
class PackageEntryAttribute;
|
||||
|
||||
|
||||
class LowLevelPackageContentHandler {
|
||||
class PackageReaderImpl {
|
||||
public:
|
||||
virtual ~LowLevelPackageContentHandler();
|
||||
|
||||
virtual status_t HandleAttribute(const char* attributeName,
|
||||
const PackageAttributeValue& value,
|
||||
void* parentToken, void*& _token) = 0;
|
||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
||||
const PackageAttributeValue& value,
|
||||
void* token) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
|
||||
class PackageContentHandler {
|
||||
public:
|
||||
virtual ~PackageContentHandler();
|
||||
|
||||
virtual status_t HandleEntry(PackageEntry* entry) = 0;
|
||||
virtual status_t HandleEntryAttribute(PackageEntry* entry,
|
||||
PackageEntryAttribute* attribute) = 0;
|
||||
virtual status_t HandleEntryDone(PackageEntry* entry) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
||||
|
||||
class PackageReader {
|
||||
public:
|
||||
PackageReader(ErrorOutput* errorOutput);
|
||||
~PackageReader();
|
||||
PackageReaderImpl(
|
||||
BErrorOutput* errorOutput);
|
||||
~PackageReaderImpl();
|
||||
|
||||
status_t Init(const char* fileName);
|
||||
status_t Init(int fd, bool keepFD);
|
||||
status_t ParseContent(
|
||||
PackageContentHandler* contentHandler);
|
||||
status_t ParseContent(
|
||||
LowLevelPackageContentHandler*
|
||||
BPackageContentHandler* contentHandler);
|
||||
status_t ParseContent(BLowLevelPackageContentHandler*
|
||||
contentHandler);
|
||||
|
||||
int PackageFileFD() { return fFD; }
|
||||
@@ -81,7 +56,7 @@ private:
|
||||
struct PackageAttributeHandler;
|
||||
struct PackageContentListHandler;
|
||||
|
||||
typedef PackageAttributeValue AttributeValue;
|
||||
typedef BPackageAttributeValue AttributeValue;
|
||||
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
||||
|
||||
private:
|
||||
@@ -128,7 +103,7 @@ private:
|
||||
inline AttributeHandler* _PopAttributeHandler();
|
||||
|
||||
private:
|
||||
ErrorOutput* fErrorOutput;
|
||||
BErrorOutput* fErrorOutput;
|
||||
int fFD;
|
||||
bool fOwnsFD;
|
||||
|
||||
@@ -164,7 +139,7 @@ private:
|
||||
|
||||
template<typename Type>
|
||||
status_t
|
||||
PackageReader::_Read(Type& _value)
|
||||
PackageReaderImpl::_Read(Type& _value)
|
||||
{
|
||||
return _ReadTOCBuffer(&_value, sizeof(Type));
|
||||
}
|
||||
@@ -172,9 +147,9 @@ PackageReader::_Read(Type& _value)
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_READER_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
||||
+19
-17
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_WRITER_H
|
||||
#define PACKAGE_WRITER_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
||||
|
||||
|
||||
#include <util/DoublyLinkedList.h>
|
||||
@@ -14,23 +14,25 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
|
||||
class BPackageInfo;
|
||||
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BDataReader;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class DataReader;
|
||||
struct hpkg_header;
|
||||
|
||||
namespace BPackageKit {
|
||||
class BPackageInfo;
|
||||
}
|
||||
|
||||
|
||||
class PackageWriter {
|
||||
class PackageWriterImpl {
|
||||
public:
|
||||
PackageWriter();
|
||||
~PackageWriter();
|
||||
PackageWriterImpl();
|
||||
~PackageWriterImpl();
|
||||
|
||||
status_t Init(const char* fileName);
|
||||
status_t AddEntry(const char* fileName);
|
||||
@@ -104,10 +106,10 @@ private:
|
||||
AttributeType* _GetAttributeType(const char* attributeName,
|
||||
uint8 type);
|
||||
|
||||
status_t _AddData(DataReader& dataReader, off_t size);
|
||||
status_t _WriteUncompressedData(DataReader& dataReader,
|
||||
status_t _AddData(BDataReader& dataReader, off_t size);
|
||||
status_t _WriteUncompressedData(BDataReader& dataReader,
|
||||
off_t size, uint64 writeOffset);
|
||||
status_t _WriteZlibCompressedData(DataReader& dataReader,
|
||||
status_t _WriteZlibCompressedData(BDataReader& dataReader,
|
||||
off_t size, uint64 writeOffset,
|
||||
uint64& _compressedSize);
|
||||
|
||||
@@ -134,9 +136,9 @@ private:
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // PACKAGE_WRITER_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
||||
@@ -2,13 +2,13 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef STACKER_H
|
||||
#define STACKER_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__STACKER_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__STACKER_H_
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@@ -46,9 +46,9 @@ private:
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // STACKER_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__STACKER_H_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef STRINGS_H
|
||||
#define STRINGS_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__STRINGS_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__STRINGS_H_
|
||||
|
||||
|
||||
#include <util/OpenHashTable.h>
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@@ -88,9 +88,9 @@ struct CachedStringUsageGreater {
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // STRINGS_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__STRINGS_H_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ZLIB_COMPRESSION_BASE_H
|
||||
#define ZLIB_COMPRESSION_BASE_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@@ -24,9 +24,9 @@ public:
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // ZLIB_COMPRESSION_BASE_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ZLIB_COMPRESSOR_H
|
||||
#define ZLIB_COMPRESSOR_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
|
||||
|
||||
|
||||
#include <zlib.h>
|
||||
@@ -13,17 +13,18 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BDataOutput;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class DataOutput;
|
||||
|
||||
|
||||
class ZlibCompressor : public ZlibCompressionBase {
|
||||
public:
|
||||
ZlibCompressor(DataOutput* output);
|
||||
ZlibCompressor(BDataOutput* output);
|
||||
~ZlibCompressor();
|
||||
|
||||
status_t Init();
|
||||
@@ -37,16 +38,16 @@ public:
|
||||
|
||||
private:
|
||||
z_stream fStream;
|
||||
DataOutput* fOutput;
|
||||
BDataOutput* fOutput;
|
||||
bool fStreamInitialized;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // ZLIB_COMPRESSOR_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ZLIB_DECOMPRESSOR_H
|
||||
#define ZLIB_DECOMPRESSOR_H
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
|
||||
|
||||
|
||||
#include <zlib.h>
|
||||
@@ -13,17 +13,18 @@
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BDataOutput;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class DataOutput;
|
||||
|
||||
|
||||
class ZlibDecompressor : public ZlibCompressionBase {
|
||||
public:
|
||||
ZlibDecompressor(DataOutput* output);
|
||||
ZlibDecompressor(BDataOutput* output);
|
||||
~ZlibDecompressor();
|
||||
|
||||
status_t Init();
|
||||
@@ -38,7 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
z_stream fStream;
|
||||
DataOutput* fOutput;
|
||||
BDataOutput* fOutput;
|
||||
bool fStreamInitialized;
|
||||
bool fFinished;
|
||||
};
|
||||
@@ -46,9 +47,9 @@ private:
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // ZLIB_DECOMPRESSOR_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU_PACKAGE_H
|
||||
#define _HAIKU_PACKAGE_H
|
||||
#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 BHaikuPackage {
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@@ -40,13 +42,6 @@ struct hpkg_header {
|
||||
};
|
||||
|
||||
|
||||
// magic, version
|
||||
enum {
|
||||
B_HPKG_MAGIC = 'hpkg',
|
||||
B_HPKG_VERSION = 1
|
||||
};
|
||||
|
||||
|
||||
// compression types
|
||||
enum {
|
||||
B_HPKG_COMPRESSION_NONE = 0,
|
||||
@@ -54,39 +49,6 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
|
||||
// attribute tag arithmetics
|
||||
#define B_HPKG_ATTRIBUTE_TAG_COMPOSE(index, encoding, hasChildren) \
|
||||
(((uint64(index) << 3) | uint64(encoding) << 1 \
|
||||
@@ -143,15 +105,6 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
// maximum number of bytes of data to be encoded inline; more will be allocated
|
||||
// on the heap
|
||||
#define B_HPKG_MAX_INLINE_DATA_SIZE 8
|
||||
|
||||
|
||||
// name of file containing package information (in package's root folder)
|
||||
#define B_HPKG_PACKAGE_INFO_FILE_NAME ".PackageInfo"
|
||||
|
||||
|
||||
// default values
|
||||
enum {
|
||||
B_HPKG_DEFAULT_FILE_TYPE = B_HPKG_FILE_TYPE_FILE,
|
||||
@@ -159,15 +112,14 @@ enum {
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHaikuPackage
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _HAIKU_PACKAGE_H
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||
|
||||
Reference in New Issue
Block a user