[haiku-commits] r40466 - in haiku/trunk: headers/os/package headers/os/package/hpkg headers/private/package/hpkg src/add-ons/kernel/file_systems/packagefs src/bin/package ...

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 12 Feb 2011 20:21:37 +0100 (CET)

Author: zooey
Date: 2011-02-12 20:21:37 +0100 (Sat, 12 Feb 2011)
New Revision: 40466
Changeset: http://dev.haiku-os.org/changeset/40466

Added:
   haiku/trunk/headers/os/package/hpkg/RepositoryContentHandler.h
   haiku/trunk/headers/os/package/hpkg/RepositoryReader.h
   haiku/trunk/headers/private/package/hpkg/HPKGDefsPrivate.h
   haiku/trunk/headers/private/package/hpkg/RepositoryReaderImpl.h
   haiku/trunk/src/kits/package/hpkg/RepositoryReader.cpp
   haiku/trunk/src/kits/package/hpkg/RepositoryReaderImpl.cpp
Removed:
   haiku/trunk/headers/private/package/hpkg/haiku_package.h
Modified:
   haiku/trunk/headers/os/package/PackageInfoAttributes.h
   haiku/trunk/headers/os/package/hpkg/HPKGDefs.h
   haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h
   haiku/trunk/headers/os/package/hpkg/PackageInfoAttributeValue.h
   haiku/trunk/headers/os/package/hpkg/PackageWriter.h
   haiku/trunk/headers/private/package/hpkg/PackageReaderImpl.h
   haiku/trunk/headers/private/package/hpkg/PackageWriterImpl.h
   haiku/trunk/headers/private/package/hpkg/WriterImplBase.h
   haiku/trunk/src/add-ons/kernel/file_systems/packagefs/GlobalFactory.cpp
   haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp
   haiku/trunk/src/bin/package/command_create.cpp
   haiku/trunk/src/bin/package/command_dump.cpp
   haiku/trunk/src/bin/package/command_extract.cpp
   haiku/trunk/src/bin/package/command_list.cpp
   haiku/trunk/src/bin/package_repo/command_list.cpp
   haiku/trunk/src/kits/package/PackageVersion.cpp
   haiku/trunk/src/kits/package/hpkg/PackageContentHandler.cpp
   haiku/trunk/src/kits/package/hpkg/PackageData.cpp
   haiku/trunk/src/kits/package/hpkg/PackageDataReader.cpp
   haiku/trunk/src/kits/package/hpkg/PackageReaderImpl.cpp
   haiku/trunk/src/kits/package/hpkg/PackageWriterImpl.cpp
   haiku/trunk/src/kits/package/hpkg/RepositoryWriterImpl.cpp
   haiku/trunk/src/kits/package/hpkg/WriterImplBase.cpp
Log:
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)


Modified: haiku/trunk/headers/os/package/PackageInfoAttributes.h
===================================================================
--- haiku/trunk/headers/os/package/PackageInfoAttributes.h      2011-02-12 
18:33:21 UTC (rev 40465)
+++ haiku/trunk/headers/os/package/PackageInfoAttributes.h      2011-02-12 
19:21:37 UTC (rev 40466)
@@ -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

Modified: haiku/trunk/headers/os/package/hpkg/HPKGDefs.h
===================================================================
--- haiku/trunk/headers/os/package/hpkg/HPKGDefs.h      2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/headers/os/package/hpkg/HPKGDefs.h      2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -69,29 +69,49 @@
 
 
 // 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 @@
 };
 
 
-// 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,

Modified: haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h
===================================================================
--- haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h 2011-02-12 
18:33:21 UTC (rev 40465)
+++ haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h 2011-02-12 
19:21:37 UTC (rev 40466)
@@ -8,7 +8,9 @@
 
 #include <SupportDefs.h>
 
+#include <package/hpkg/HPKGDefs.h>
 
+
 namespace BPackageKit {
 
 namespace BHPKG {
@@ -24,14 +26,18 @@
 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 @@
        virtual status_t                        HandlePackageAttribute(
                                                                        const 
BPackageInfoAttributeValue& value
                                                                        ) = 0;
-       virtual status_t                        HandlePackageAttributesDone() = 
0;
 
        virtual void                            HandleErrorOccurred() = 0;
 };

Modified: haiku/trunk/headers/os/package/hpkg/PackageInfoAttributeValue.h
===================================================================
--- haiku/trunk/headers/os/package/hpkg/PackageInfoAttributeValue.h     
2011-02-12 18:33:21 UTC (rev 40465)
+++ haiku/trunk/headers/os/package/hpkg/PackageInfoAttributeValue.h     
2011-02-12 19:21:37 UTC (rev 40466)
@@ -51,42 +51,52 @@
                                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

Modified: haiku/trunk/headers/os/package/hpkg/PackageWriter.h
===================================================================
--- haiku/trunk/headers/os/package/hpkg/PackageWriter.h 2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/headers/os/package/hpkg/PackageWriter.h 2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -29,9 +29,7 @@
 
        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,

Added: haiku/trunk/headers/os/package/hpkg/RepositoryContentHandler.h
===================================================================
--- haiku/trunk/headers/os/package/hpkg/RepositoryContentHandler.h              
                (rev 0)
+++ haiku/trunk/headers/os/package/hpkg/RepositoryContentHandler.h      
2011-02-12 19:21:37 UTC (rev 40466)
@@ -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_

Added: haiku/trunk/headers/os/package/hpkg/RepositoryReader.h
===================================================================
--- haiku/trunk/headers/os/package/hpkg/RepositoryReader.h                      
        (rev 0)
+++ haiku/trunk/headers/os/package/hpkg/RepositoryReader.h      2011-02-12 
19:21:37 UTC (rev 40466)
@@ -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_

Copied: haiku/trunk/headers/private/package/hpkg/HPKGDefsPrivate.h (from rev 
40426, haiku/trunk/headers/private/package/hpkg/haiku_package.h)
===================================================================
--- haiku/trunk/headers/private/package/hpkg/HPKGDefsPrivate.h                  
        (rev 0)
+++ haiku/trunk/headers/private/package/hpkg/HPKGDefsPrivate.h  2011-02-12 
19:21:37 UTC (rev 40466)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * 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_

Modified: haiku/trunk/headers/private/package/hpkg/PackageReaderImpl.h
===================================================================
--- haiku/trunk/headers/private/package/hpkg/PackageReaderImpl.h        
2011-02-12 18:33:21 UTC (rev 40465)
+++ haiku/trunk/headers/private/package/hpkg/PackageReaderImpl.h        
2011-02-12 19:21:37 UTC (rev 40466)
@@ -46,16 +46,18 @@
                        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 @@
                        const char*                     _CheckCompression(
                                                                        const 
SectionInfo& section) const;
 
-                       status_t                        
_ParseTOCAttributeTypes();
-
                        status_t                        _ParseStrings();
 
                        status_t                        
_ParseContent(AttributeHandlerContext* context,
@@ -117,7 +117,7 @@
                                                                        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 @@
                        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 @@
                        uint64                          fHeapOffset;
                        uint64                          fHeapSize;
 
-                       uint64                          
fTOCAttributeTypesLength;
-                       uint64                          fTOCAttributeTypesCount;
-
                        SectionInfo                     fTOCSection;
                        SectionInfo                     
fPackageAttributesSection;
                        SectionInfo*            fCurrentSection;
 
-                       AttributeTypeReference* fAttributeTypes;
-
                        AttributeHandlerList* fAttributeHandlerStack;
 
                        uint8*                          fScratchBuffer;

Modified: haiku/trunk/headers/private/package/hpkg/PackageWriterImpl.h
===================================================================
--- haiku/trunk/headers/private/package/hpkg/PackageWriterImpl.h        
2011-02-12 18:33:21 UTC (rev 40465)
+++ haiku/trunk/headers/private/package/hpkg/PackageWriterImpl.h        
2011-02-12 19:21:37 UTC (rev 40466)
@@ -42,16 +42,10 @@
                        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 @@
                        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 @@
                        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 @@
                        Attribute*                      fTopAttribute;
 
                        StringCache                     fStringCache;
-                       AttributeTypeTable*     fAttributeTypes;
 
                        BPackageInfo            fPackageInfo;
 };

Added: haiku/trunk/headers/private/package/hpkg/RepositoryReaderImpl.h
===================================================================
--- haiku/trunk/headers/private/package/hpkg/RepositoryReaderImpl.h             
                (rev 0)
+++ haiku/trunk/headers/private/package/hpkg/RepositoryReaderImpl.h     
2011-02-12 19:21:37 UTC (rev 40466)
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2011, Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
+ * 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_

Modified: haiku/trunk/headers/private/package/hpkg/WriterImplBase.h
===================================================================
--- haiku/trunk/headers/private/package/hpkg/WriterImplBase.h   2011-02-12 
18:33:21 UTC (rev 40465)
+++ haiku/trunk/headers/private/package/hpkg/WriterImplBase.h   2011-02-12 
19:21:37 UTC (rev 40466)
@@ -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 @@
                        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();
 

Modified: 
haiku/trunk/src/add-ons/kernel/file_systems/packagefs/GlobalFactory.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/packagefs/GlobalFactory.cpp     
2011-02-12 18:33:21 UTC (rev 40465)
+++ haiku/trunk/src/add-ons/kernel/file_systems/packagefs/GlobalFactory.cpp     
2011-02-12 19:21:37 UTC (rev 40466)
@@ -8,7 +8,7 @@
 
 #include <new>
 
-#include <package/hpkg/haiku_package.h>
+#include <package/hpkg/HPKGDefsPrivate.h>
 
 
 static const uint32 kMaxCachedBuffers = 32;

Modified: haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp    
2011-02-12 18:33:21 UTC (rev 40465)
+++ haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp    
2011-02-12 19:21:37 UTC (rev 40466)
@@ -264,12 +264,6 @@
                return B_OK;
        }
 
-       virtual status_t HandlePackageAttributesDone()
-       {
-               // TODO!
-               return B_OK;
-       }
-
        virtual void HandleErrorOccurred()
        {
                fErrorOccurred = true;

Modified: haiku/trunk/src/bin/package/command_create.cpp
===================================================================
--- haiku/trunk/src/bin/package/command_create.cpp      2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/src/bin/package/command_create.cpp      2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -46,16 +46,13 @@
                printf("\t%s\n", path);
        }
 
-       virtual void OnTOCSizeInfo(uint64 uncompressedAttributeTypesSize,
-               uint64 uncompressedStringsSize, uint64 uncompressedMainSize,
-               uint64 uncompressedTOCSize)
+       virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize,
+               uint64 uncompressedMainSize, uint64 uncompressedTOCSize)
        {
                if (fQuiet || !fVerbose)
                        return;
 
                printf("----- TOC Info -----------------------------------\n");
-               printf("attribute types size:    %10llu (uncompressed)\n",
-                       uncompressedAttributeTypesSize);
                printf("cached strings size:     %10llu (uncompressed)\n",
                        uncompressedStringsSize);
                printf("TOC main size:           %10llu (uncompressed)\n",

Modified: haiku/trunk/src/bin/package/command_dump.cpp
===================================================================
--- haiku/trunk/src/bin/package/command_dump.cpp        2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/src/bin/package/command_dump.cpp        2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -34,13 +34,13 @@
        {
        }
 
-       virtual status_t HandleAttribute(const char* attributeName,
+       virtual status_t HandleAttribute(BHPKGAttributeID attributeID,
                const BPackageAttributeValue& value, void* parentToken, void*& 
_token)
        {
                if (fErrorOccurred)
                        return B_OK;
 
-               printf("%*s>%s: ", fLevel * 2, "", attributeName);
+               printf("%*s>%s: ", fLevel * 2, "", 
AttributeNameForID(attributeID));
                _PrintValue(value);
                printf("\n");
 
@@ -49,7 +49,7 @@
                return B_OK;
        }
 
-       virtual status_t HandleAttributeDone(const char* attributeName,
+       virtual status_t HandleAttributeDone(BHPKGAttributeID attributeID,
                const BPackageAttributeValue& value, void* token)
        {
                if (fErrorOccurred)
@@ -58,7 +58,7 @@
                fLevel--;
 
                if (fHasChildren)
-                       printf("%*s<%s\n", fLevel * 2, "", attributeName);
+                       printf("%*s<%s\n", fLevel * 2, "", 
AttributeNameForID(attributeID));
 
                fHasChildren = true;
                return B_OK;
@@ -144,14 +144,12 @@
        StandardErrorOutput errorOutput;
        BPackageReader packageReader(&errorOutput);
        status_t error = packageReader.Init(packageFileName);
-printf("Init(): %s\n", strerror(error));
        if (error != B_OK)
                return 1;
 
        // list
        PackageContentDumpHandler handler;
        error = packageReader.ParseContent(&handler);
-printf("ParseContent(): %s\n", strerror(error));
        if (error != B_OK)
                return 1;
 

Modified: haiku/trunk/src/bin/package/command_extract.cpp
===================================================================
--- haiku/trunk/src/bin/package/command_extract.cpp     2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/src/bin/package/command_extract.cpp     2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -229,11 +229,6 @@
                return B_OK;
        }
 
-       virtual status_t HandlePackageAttributesDone()
-       {
-               return B_OK;
-       }
-
        virtual void HandleErrorOccurred()
        {
                fErrorOccurred = true;

Modified: haiku/trunk/src/bin/package/command_list.cpp
===================================================================
--- haiku/trunk/src/bin/package/command_list.cpp        2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/src/bin/package/command_list.cpp        2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -111,7 +111,7 @@
        virtual status_t HandlePackageAttribute(
                const BPackageInfoAttributeValue& value)
        {
-               switch (value.attributeIndex) {
+               switch (value.attributeID) {
                        case B_PACKAGE_INFO_NAME:
                                printf("package-attributes:\n");
                                printf("\tname: %s\n", value.string);
@@ -218,19 +218,13 @@
                        default:
                                printf(
                                        "*** Invalid package attribute section: 
unexpected "
-                                       "package attribute index %d 
encountered\n",
-                                       value.attributeIndex);
+                                       "package attribute id %d 
encountered\n", value.attributeID);
                                return B_BAD_DATA;
                }
 
                return B_OK;
        }
 
-       virtual status_t HandlePackageAttributesDone()
-       {
-               return B_OK;
-       }
-
        virtual void HandleErrorOccurred()
        {
        }
@@ -308,14 +302,12 @@
        StandardErrorOutput errorOutput;
        BPackageReader packageReader(&errorOutput);
        status_t error = packageReader.Init(packageFileName);
-printf("Init(): %s\n", strerror(error));
        if (error != B_OK)
                return 1;
 
        // list
        PackageContentListHandler handler(listAttributes);
        error = packageReader.ParseContent(&handler);
-printf("ParseContent(): %s\n", strerror(error));
        if (error != B_OK)
                return 1;
 

Modified: haiku/trunk/src/bin/package_repo/command_list.cpp
===================================================================
--- haiku/trunk/src/bin/package_repo/command_list.cpp   2011-02-12 18:33:21 UTC 
(rev 40465)
+++ haiku/trunk/src/bin/package_repo/command_list.cpp   2011-02-12 19:21:37 UTC 
(rev 40466)
@@ -26,7 +26,7 @@
 using namespace BPackageKit::BHPKG;
 using namespace BPackageKit;
 
-
+/*
 struct PackageContentListHandler : BPackageContentHandler {
        PackageContentListHandler(bool listAttributes)
                :
@@ -265,8 +265,8 @@
        int             fLevel;
        bool    fListAttribute;
 };
+*/
 
-
 int
 command_list(int argc, const char* const* argv)
 {
@@ -305,19 +305,17 @@
        const char* packageFileName = argv[optind++];
 
        // open package
-       StandardErrorOutput errorOutput;
-       BPackageReader packageReader(&errorOutput);
-       status_t error = packageReader.Init(packageFileName);
-printf("Init(): %s\n", strerror(error));
-       if (error != B_OK)
-               return 1;
+//     StandardErrorOutput errorOutput;
+//     BPackageReader packageReader(&errorOutput);
+//     status_t error = packageReader.Init(packageFileName);
+//     if (error != B_OK)
+//             return 1;

[... truncated: 4372 lines follow ...]

Other related posts:

  • » [haiku-commits] r40466 - in haiku/trunk: headers/os/package headers/os/package/hpkg headers/private/package/hpkg src/add-ons/kernel/file_systems/packagefs src/bin/package ... - zooey