1 /* 2 * Copyright 2007-2009, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: 6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> 7 */ 8 #ifndef PACKAGE_ITEM_H 9 #define PACKAGE_ITEM_H 10 11 12 #include <stdio.h> 13 14 #include <Directory.h> 15 #include <Entry.h> 16 #include <File.h> 17 #include <Path.h> 18 #include <String.h> 19 20 21 // Local macro for the parser debug output 22 //#define DEBUG_PARSER 23 #ifdef DEBUG_PARSER 24 # define parser_debug(format, args...) fprintf(stderr, format, ##args) 25 #else 26 # define parser_debug(format, args...) 27 #endif 28 29 30 enum { 31 P_INSTALL_PATH = 0, 32 P_SYSTEM_PATH, 33 P_USER_PATH 34 }; 35 36 // Existing item overwriting policy of a single file 37 enum { 38 P_EXISTS_ASK = 0, 39 P_EXISTS_OVERWRITE, 40 P_EXISTS_SKIP, 41 P_EXISTS_ABORT, 42 P_EXISTS_NONE 43 }; 44 45 extern status_t inflate_data(uint8* in, uint32 inSize, uint8* out, 46 uint32 outSize); 47 48 49 struct ItemState { 50 ItemState() : policy(P_EXISTS_NONE), status(B_NO_INIT) {} 51 ~ItemState() {} 52 53 inline void Reset(int32 currentPolicy) 54 { 55 destination.Unset(); 56 parent.Unset(); 57 status = B_NO_INIT; 58 policy = currentPolicy; 59 } 60 61 BPath destination; 62 BDirectory parent; 63 uint8 policy; 64 status_t status; 65 }; 66 67 68 class PackageItem { 69 public: 70 PackageItem(BFile* parent, const BString& path, 71 uint8 type, uint32 ctime, uint32 mtime, 72 uint64 offset = 0, uint64 size = 0); 73 virtual ~PackageItem(); 74 75 virtual status_t WriteToPath(const char* path = NULL, 76 ItemState *state = NULL) = 0; 77 virtual void SetTo(BFile* parent, const BString& path, 78 uint8 type, uint32 ctime, uint32 mtime, 79 uint64 offset = 0, uint64 size = 0); 80 virtual const char* ItemKind() = 0; 81 82 protected: 83 status_t InitPath(const char* path, BPath* destination); 84 status_t HandleAttributes(BPath* destination, BNode* node, 85 const char* header); 86 87 status_t ParseAttribute(uint8* buffer, BNode* node, 88 char** attrName, uint32* nameSize, 89 uint32* attrType, uint8** attrData, 90 uint64* dataSize, uint8** temp, 91 uint64* tempSize, uint64* attrCSize, 92 uint64* attrOSize, bool* attrStarted, 93 bool* done); 94 status_t ParseData(uint8* buffer, BFile* file, 95 uint64 originalSize, bool* done); 96 97 BString fPath; 98 uint64 fOffset; 99 uint64 fSize; 100 uint8 fPathType; 101 uint32 fCreationTime; 102 uint32 fModificationTime; 103 104 BFile* fPackage; 105 }; 106 107 108 class PackageDirectory : public PackageItem { 109 public: 110 PackageDirectory(BFile* parent, const BString& path, 111 uint8 type, uint32 ctime, uint32 mtime, 112 uint64 offset = 0, uint64 size = 0); 113 114 virtual status_t WriteToPath(const char* path = NULL, 115 ItemState *state = NULL); 116 virtual const char* ItemKind(); 117 }; 118 119 120 class PackageFile : public PackageItem { 121 public: 122 PackageFile(BFile* parent, const BString& path, 123 uint8 type, uint32 ctime, uint32 mtime, 124 uint64 offset, uint64 size, uint64 originalSize, 125 uint32 platform, const BString& mime, 126 const BString& signature, uint32 mode); 127 128 virtual status_t WriteToPath(const char* path = NULL, 129 ItemState *state = NULL); 130 virtual const char* ItemKind(); 131 132 private: 133 uint64 fOriginalSize; 134 uint32 fPlatform; 135 uint32 fMode; 136 137 BString fMimeType; 138 BString fSignature; 139 }; 140 141 142 class PackageLink : public PackageItem { 143 public: 144 PackageLink(BFile* parent, const BString& path, 145 const BString& link, uint8 type, uint32 ctime, 146 uint32 mtime, uint32 mode, uint64 offset = 0, 147 uint64 size = 0); 148 149 virtual status_t WriteToPath(const char* path = NULL, 150 ItemState *state = NULL); 151 virtual const char* ItemKind(); 152 153 private: 154 uint32 fMode; 155 BString fLink; 156 }; 157 158 #endif // PACKAGE_ITEM_H 159