1 /* 2 * Copyright (c) 2007, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: 6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> 7 */ 8 #ifndef PACKAGEITEM_H 9 #define PACKAGEITEM_H 10 11 #include <String.h> 12 #include <Entry.h> 13 #include <File.h> 14 #include <Path.h> 15 #include <stdio.h> 16 17 //#define DEBUG_PARSER 18 19 // Local macro for the parser debug output 20 #ifdef DEBUG_PARSER 21 #define parser_debug(format, args...) fprintf(stderr, format, ##args) 22 #else 23 #define parser_debug(format, args...) 24 #endif 25 26 27 class PkgDirectory; 28 29 // Since files are derive from directories, which is not too obvious, 30 // we define a type PkgItem to use for base type iterations 31 typedef PkgDirectory PkgItem; 32 33 34 enum { 35 P_INSTALL_PATH = 0, 36 P_SYSTEM_PATH, 37 P_USER_PATH 38 }; 39 40 41 status_t inflate_data(uint8 *in, uint32 in_size, uint8 *out, uint32 out_size); 42 43 44 class PkgDirectory { 45 public: 46 PkgDirectory(BFile *parent, BString path, uint8 type, uint32 ctime, 47 uint32 mtime, uint64 offset = 0, uint64 size = 0); 48 virtual ~PkgDirectory(); 49 50 virtual status_t WriteToPath(const char *path = NULL, BPath *final = NULL); 51 virtual void SetTo(BFile *parent, BString path, uint8 type, 52 uint32 ctime, uint32 mtime, uint64 offset = 0, uint64 size = 0); 53 54 protected: 55 int32 _ItemExists(const char *name); 56 status_t _InitPath(const char *path, BPath *destination); 57 status_t _HandleAttributes(BPath *destination, BNode *node, 58 const char *header); 59 60 inline status_t _ParseAttribute(uint8 *buffer, BNode *node, char **attrName, 61 uint32 *nameSize, uint32 *attrType, uint8 **attrData, uint64 *dataSize, 62 uint8 **temp, uint64 *tempSize, uint64 *attrCSize, uint64 *attrOSize, 63 bool *attrStarted, bool *done); 64 inline status_t _ParseData(uint8 *buffer, BFile *file, uint64 originalSize, 65 bool *done); 66 67 BString fPath; 68 uint64 fOffset; 69 uint64 fSize; 70 uint8 fPathType; 71 uint32 fCreationTime; 72 uint32 fModificationTime; 73 74 BFile *fPackage; 75 }; 76 77 78 class PkgFile : public PkgItem { 79 public: 80 PkgFile(BFile *parent, BString path, uint8 type, uint32 ctime, 81 uint32 mtime, uint64 offset, uint64 size, uint64 originalSize, 82 uint32 platform, BString mime, BString signature, uint32 mode); 83 ~PkgFile(); 84 85 status_t WriteToPath(const char *path = NULL, BPath *final = NULL); 86 87 private: 88 uint64 fOriginalSize; 89 uint32 fPlatform; 90 uint32 fMode; 91 92 BString fMimeType; 93 BString fSignature; 94 }; 95 96 97 class PkgLink : public PkgItem { 98 public: 99 PkgLink(BFile *parent, BString path, BString link, uint8 type, 100 uint32 ctime, uint32 mtime, uint32 mode, uint64 offset = 0, 101 uint64 size = 0); 102 ~PkgLink(); 103 104 status_t WriteToPath(const char *path = NULL, BPath *final = NULL); 105 106 private: 107 uint32 fMode; 108 109 BString fLink; 110 }; 111 112 113 #endif 114 115