BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / packageinstaller / PackageItem.h
blob24b609a23b6b517ab446dd4d1e052cab73008a0f
1 /*
2 * Copyright 2007-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * Ɓukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 */
8 #ifndef PACKAGE_ITEM_H
9 #define PACKAGE_ITEM_H
12 #include <stdio.h>
14 #include <Directory.h>
15 #include <Entry.h>
16 #include <File.h>
17 #include <Path.h>
18 #include <String.h>
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
30 enum {
31 P_INSTALL_PATH = 0,
32 P_SYSTEM_PATH,
33 P_USER_PATH
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
45 const uint32 P_NO_KIND = 0;
46 const uint32 P_KIND_SCRIPT = 1;
47 const uint32 P_KIND_FILE = 2;
48 const uint32 P_KIND_DIRECTORY = 3;
49 const uint32 P_KIND_SYM_LINK = 4;
51 extern status_t inflate_data(uint8* in, uint32 inSize, uint8* out,
52 uint32 outSize);
55 struct ItemState {
56 ItemState(uint8 _policy)
58 policy(_policy),
59 status(B_NO_INIT)
63 ~ItemState()
67 BPath destination;
68 BDirectory parent;
69 uint8 policy;
70 status_t status;
74 class PackageItem {
75 public:
76 PackageItem(BFile* parent, const BString& path,
77 uint8 type, uint32 ctime, uint32 mtime,
78 uint64 offset = 0, uint64 size = 0);
79 virtual ~PackageItem();
81 virtual status_t DoInstall(const char* path = NULL,
82 ItemState *state = NULL) = 0;
83 virtual void SetTo(BFile* parent, const BString& path,
84 uint8 type, uint32 ctime, uint32 mtime,
85 uint64 offset = 0, uint64 size = 0);
86 virtual const uint32 ItemKind() {return P_NO_KIND;};
88 protected:
89 status_t InitPath(const char* path, BPath* destination);
90 status_t HandleAttributes(BPath* destination, BNode* node,
91 const char* header);
93 status_t ParseAttribute(uint8* buffer, BNode* node,
94 char** attrName, uint32* nameSize,
95 uint32* attrType, uint8** attrData,
96 uint64* dataSize, uint8** temp,
97 uint64* tempSize, uint64* attrCSize,
98 uint64* attrOSize, bool* attrStarted,
99 bool* done);
100 status_t SkipAttribute(uint8* buffer, bool* attrStarted,
101 bool* done);
102 status_t ParseData(uint8* buffer, BFile* file,
103 uint64 originalSize, bool* done);
105 protected:
106 BString fPath;
107 uint64 fOffset;
108 uint64 fSize;
109 uint8 fPathType;
110 uint32 fCreationTime;
111 uint32 fModificationTime;
113 BFile* fPackage;
117 class PackageDirectory : public PackageItem {
118 public:
119 PackageDirectory(BFile* parent, const BString& path,
120 uint8 type, uint32 ctime, uint32 mtime,
121 uint64 offset = 0, uint64 size = 0);
123 virtual status_t DoInstall(const char* path = NULL,
124 ItemState* state = NULL);
125 virtual const uint32 ItemKind();
129 class PackageScript : public PackageItem {
130 public:
131 PackageScript(BFile* parent, const BString& path,
132 uint8 type, uint64 offset = 0, uint64 size = 0,
133 uint64 originalSize = 0);
135 virtual status_t DoInstall(const char* path = NULL,
136 ItemState *state = NULL);
137 virtual const uint32 ItemKind();
139 thread_id GetThreadId() { return fThreadId; }
140 void SetThreadId(thread_id id) { fThreadId = id; }
142 private:
143 status_t _ParseScript(uint8* buffer, uint64 originalSize,
144 BString& script, bool* done);
145 status_t _RunScript(const char* workingDirectory,
146 const BString& script);
148 private:
149 uint64 fOriginalSize;
150 thread_id fThreadId;
154 class PackageFile : public PackageItem {
155 public:
156 PackageFile(BFile* parent, const BString& path,
157 uint8 type, uint32 ctime, uint32 mtime,
158 uint64 offset, uint64 size, uint64 originalSize,
159 uint32 platform, const BString& mime,
160 const BString& signature, uint32 mode);
162 virtual status_t DoInstall(const char* path = NULL,
163 ItemState* state = NULL);
164 virtual const uint32 ItemKind();
166 private:
167 uint64 fOriginalSize;
168 uint32 fPlatform;
169 uint32 fMode;
171 BString fMimeType;
172 BString fSignature;
176 class PackageLink : public PackageItem {
177 public:
178 PackageLink(BFile* parent, const BString& path,
179 const BString& link, uint8 type, uint32 ctime,
180 uint32 mtime, uint32 mode, uint64 offset = 0,
181 uint64 size = 0);
183 virtual status_t DoInstall(const char* path = NULL,
184 ItemState *state = NULL);
185 virtual const uint32 ItemKind();
187 private:
188 uint32 fMode;
189 BString fLink;
192 #endif // PACKAGE_ITEM_H