package kit: some fixes for multi-version support

* Use enums/constants/functions instead of preprocessor macros.
* Missing include in PackageInfoAttributeValue.h.
* PackageReaderImpl::Init(): Check version before header size and
  return B_MISMATCHED_VALUES instead of B_BAD_DATA, if the version
  doesn't match. This allows callers to determine the condition and
  try a reader for a different version. A more flexible interface for
  that case would be nice, but since we want to support the old package
  version only temporarily, the current solution should be good enough.
This commit is contained in:
Ingo Weinhold
2013-05-25 01:12:21 +02:00
parent 7e7232aca8
commit 171fd58c4b
14 changed files with 87 additions and 31 deletions
+4 -2
View File
@@ -73,11 +73,13 @@ 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
enum {
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"
extern const char* const B_HPKG_PACKAGE_INFO_FILE_NAME;
// package attribute IDs
@@ -8,6 +8,8 @@
#include <SupportDefs.h>
#include <string.h>
#include <package/PackageArchitecture.h>
#include <package/PackageInfoAttributes.h>
#include <package/PackageResolvableOperator.h>
+35 -11
View File
@@ -64,17 +64,41 @@ struct hpkg_repo_header {
// 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)
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