vfs: check userland buffers before reading them.
[haiku.git] / src / bin / package / PackageInfoPrinter.h
blob7284312cb6a4424a34f35d4672a37052a857336a
1 /*
2 * Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef PACKAGE_INFO_PRINTER_H
6 #define PACKAGE_INFO_PRINTER_H
9 #include <stdio.h>
11 #include <package/hpkg/PackageInfoAttributeValue.h>
12 #include <package/PackageInfo.h>
15 using namespace BPackageKit;
16 using BPackageKit::BHPKG::BGlobalWritableFileInfoData;
17 using BPackageKit::BHPKG::BPackageInfoAttributeValue;
18 using BPackageKit::BHPKG::BUserData;
19 using BPackageKit::BHPKG::BUserSettingsFileInfoData;
22 class PackageInfoPrinter {
23 public:
24 void PrintPackageInfo(const BPackageInfo& info)
26 PrintName(info.Name());
27 PrintSummary(info.Summary());
28 PrintDescription(info.Description());
29 PrintVendor(info.Vendor());
30 PrintPackager(info.Packager());
32 if (!info.BasePackage().IsEmpty())
33 PrintBasePackage(info.BasePackage());
35 PrintFlags(info.Flags());
36 PrintArchitecture((uint32)info.Architecture());
37 PrintVersion(info.Version());
39 int32 count = info.CopyrightList().CountStrings();
40 for (int32 i = 0; i < count; i++)
41 PrintCopyright(info.CopyrightList().StringAt(i));
43 count = info.LicenseList().CountStrings();
44 for (int32 i = 0; i < count; i++)
45 PrintLicense(info.LicenseList().StringAt(i));
47 count = info.URLList().CountStrings();
48 for (int32 i = 0; i < count; i++)
49 PrintUrl(info.URLList().StringAt(i));
51 count = info.SourceURLList().CountStrings();
52 for (int32 i = 0; i < count; i++)
53 PrintSourceUrl(info.SourceURLList().StringAt(i));
55 count = info.ProvidesList().CountItems();
56 for (int32 i = 0; i < count; i++)
57 PrintProvides(*info.ProvidesList().ItemAt(i));
59 count = info.RequiresList().CountItems();
60 for (int32 i = 0; i < count; i++)
61 PrintRequires(*info.RequiresList().ItemAt(i));
63 count = info.SupplementsList().CountItems();
64 for (int32 i = 0; i < count; i++)
65 PrintSupplements(*info.SupplementsList().ItemAt(i));
67 count = info.ConflictsList().CountItems();
68 for (int32 i = 0; i < count; i++)
69 PrintConflicts(*info.ConflictsList().ItemAt(i));
71 count = info.FreshensList().CountItems();
72 for (int32 i = 0; i < count; i++)
73 PrintFreshens(*info.FreshensList().ItemAt(i));
75 count = info.ReplacesList().CountStrings();
76 for (int32 i = 0; i < count; i++)
77 PrintReplaces(info.ReplacesList().StringAt(i));
79 count = info.GlobalWritableFileInfos().CountItems();
80 for (int32 i = 0; i < count; i++)
81 PrintGlobalWritableFile(*info.GlobalWritableFileInfos().ItemAt(i));
83 count = info.UserSettingsFileInfos().CountItems();
84 for (int32 i = 0; i < count; i++)
85 PrintUserSettingsFile(*info.UserSettingsFileInfos().ItemAt(i));
87 count = info.Users().CountItems();
88 for (int32 i = 0; i < count; i++)
89 PrintUser(*info.Users().ItemAt(i));
91 count = info.Groups().CountStrings();
92 for (int32 i = 0; i < count; i++)
93 PrintGroup(info.Groups().StringAt(i));
95 count = info.PostInstallScripts().CountStrings();
96 for (int32 i = 0; i < count; i++)
97 PrintPostInstallScript(info.PostInstallScripts().StringAt(i));
99 count = info.PostInstallScripts().CountStrings();
100 for (int32 i = 0; i < count; i++)
101 PrintPostInstallScript(info.PostInstallScripts().StringAt(i));
103 if (!info.InstallPath().IsEmpty())
104 PrintInstallPath(info.InstallPath());
107 bool PrintAttribute(const BPackageInfoAttributeValue& value)
109 switch (value.attributeID) {
110 case B_PACKAGE_INFO_NAME:
111 PrintName(value.string);
112 break;
114 case B_PACKAGE_INFO_SUMMARY:
115 PrintSummary(value.string);
116 break;
118 case B_PACKAGE_INFO_DESCRIPTION:
119 PrintDescription(value.string);
120 break;
122 case B_PACKAGE_INFO_VENDOR:
123 PrintVendor(value.string);
124 break;
126 case B_PACKAGE_INFO_PACKAGER:
127 PrintPackager(value.string);
128 break;
130 case B_PACKAGE_INFO_BASE_PACKAGE:
131 PrintBasePackage(value.string);
132 break;
134 case B_PACKAGE_INFO_FLAGS:
135 PrintFlags(value.unsignedInt);
136 break;
138 case B_PACKAGE_INFO_ARCHITECTURE:
139 PrintArchitecture(value.unsignedInt);
140 break;
142 case B_PACKAGE_INFO_VERSION:
143 PrintVersion(value.version);
144 break;
146 case B_PACKAGE_INFO_COPYRIGHTS:
147 PrintCopyright(value.string);
148 break;
150 case B_PACKAGE_INFO_LICENSES:
151 PrintLicense(value.string);
152 break;
154 case B_PACKAGE_INFO_URLS:
155 PrintUrl(value.string);
156 break;
158 case B_PACKAGE_INFO_SOURCE_URLS:
159 PrintSourceUrl(value.string);
160 break;
162 case B_PACKAGE_INFO_PROVIDES:
163 PrintProvides(value.resolvable);
164 break;
166 case B_PACKAGE_INFO_REQUIRES:
167 PrintRequires(value.resolvableExpression);
168 break;
170 case B_PACKAGE_INFO_SUPPLEMENTS:
171 PrintSupplements(value.resolvableExpression);
172 break;
174 case B_PACKAGE_INFO_CONFLICTS:
175 PrintConflicts(value.resolvableExpression);
176 break;
178 case B_PACKAGE_INFO_FRESHENS:
179 PrintFreshens(value.resolvableExpression);
180 break;
182 case B_PACKAGE_INFO_REPLACES:
183 PrintReplaces(value.string);
184 break;
186 case B_PACKAGE_INFO_GLOBAL_WRITABLE_FILES:
187 PrintGlobalWritableFile(value.globalWritableFileInfo);
188 break;
190 case B_PACKAGE_INFO_USER_SETTINGS_FILES:
191 PrintUserSettingsFile(value.userSettingsFileInfo);
192 break;
194 case B_PACKAGE_INFO_USERS:
195 PrintUser(value.user);
196 break;
198 case B_PACKAGE_INFO_GROUPS:
199 PrintGroup(value.string);
200 break;
202 case B_PACKAGE_INFO_POST_INSTALL_SCRIPTS:
203 PrintPostInstallScript(value.string);
204 break;
206 case B_PACKAGE_INFO_INSTALL_PATH:
207 PrintInstallPath(value.string);
208 break;
210 case B_PACKAGE_INFO_CHECKSUM:
211 PrintChecksum(value.string);
212 break;
214 default:
215 return false;
218 return true;
221 void PrintName(const char* name) const
223 printf("\tname: %s\n", name);
226 void PrintSummary(const char* summary) const
228 printf("\tsummary: %s\n", summary);
231 void PrintDescription(const char* description) const
233 printf("\tdescription: %s\n", description);
236 void PrintVendor(const char* vendor) const
238 printf("\tvendor: %s\n", vendor);
241 void PrintPackager(const char* packager) const
243 printf("\tpackager: %s\n", packager);
246 void PrintBasePackage(const char* basePackage) const
248 printf("\tbase package: %s\n", basePackage);
251 void PrintFlags(uint32 flags) const
253 if (flags == 0)
254 return;
256 printf("\tflags:\n");
257 if ((flags & B_PACKAGE_FLAG_APPROVE_LICENSE) != 0)
258 printf("\t\tapprove_license\n");
259 if ((flags & B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0)
260 printf("\t\tsystem_package\n");
263 void PrintArchitecture(uint32 architecture) const
265 printf("\tarchitecture: %s\n",
266 architecture < B_PACKAGE_ARCHITECTURE_ENUM_COUNT
267 ? BPackageInfo::kArchitectureNames[architecture]
268 : "<invalid>");
271 void PrintVersion(const BPackageVersion& version) const
273 printf("\tversion: %s\n", version.ToString().String());
276 void PrintCopyright(const char* copyright) const
278 printf("\tcopyright: %s\n", copyright);
281 void PrintLicense(const char* license) const
283 printf("\tlicense: %s\n", license);
286 void PrintUrl(const char* url) const
288 printf("\tURL: %s\n", url);
291 void PrintSourceUrl(const char* sourceUrl) const
293 printf("\tsource URL: %s\n", sourceUrl);
296 void PrintProvides(const BPackageResolvable& provides) const
298 printf("\tprovides: %s", provides.Name().String());
299 if (provides.Version().InitCheck() == B_OK)
300 printf(" = %s", provides.Version().ToString().String());
302 if (provides.CompatibleVersion().InitCheck() == B_OK) {
303 printf(" (compatible >= %s)",
304 provides.CompatibleVersion().ToString().String());
306 printf("\n");
309 void PrintRequires(const BPackageResolvableExpression& requires) const
311 _PrintResolvableExpression("requires", requires);
314 void PrintSupplements(const BPackageResolvableExpression& supplements)
315 const
317 _PrintResolvableExpression("supplements", supplements);
320 void PrintConflicts(const BPackageResolvableExpression& conflicts) const
322 _PrintResolvableExpression("conflicts", conflicts);
325 void PrintFreshens(const BPackageResolvableExpression& freshens) const
327 _PrintResolvableExpression("freshens", freshens);
330 void PrintReplaces(const char* replaces) const
332 printf("\treplaces: %s\n", replaces);
335 void PrintGlobalWritableFile(const BGlobalWritableFileInfo& info) const
337 printf("\tglobal writable file: %s", info.Path().String());
338 if (info.IsDirectory())
339 printf( " directory");
340 if (info.UpdateType() < B_WRITABLE_FILE_UPDATE_TYPE_ENUM_COUNT) {
341 printf(" %s\n",
342 BPackageInfo::kWritableFileUpdateTypes[info.UpdateType()]);
343 } else
344 printf("\n");
347 void PrintUserSettingsFile(const BUserSettingsFileInfo& info) const
349 printf("\tuser settings file: %s", info.Path().String());
350 if (info.IsDirectory())
351 printf( " directory\n");
352 else if (!info.TemplatePath().IsEmpty())
353 printf(" template %s\n", info.TemplatePath().String());
354 else
355 printf("\n");
358 void PrintUser(const BUser& user) const
360 printf("\tuser: %s\n", user.Name().String());
361 if (!user.RealName().IsEmpty())
362 printf("\t\treal name: %s\n", user.RealName().String());
363 if (!user.Home().IsEmpty())
364 printf("\t\thome: %s\n", user.Home().String());
365 if (!user.Shell().IsEmpty())
366 printf("\t\tshell: %s\n", user.Shell().String());
368 int32 groupCount = user.Groups().CountStrings();
369 for (int32 i = 0; i < groupCount; i++)
370 printf("\t\tgroup: %s\n", user.Groups().StringAt(i).String());
373 void PrintGroup(const char* group) const
375 printf("\tgroup: %s\n", group);
378 void PrintPostInstallScript(const char* script) const
380 printf("\tpost install script: %s\n", script);
383 void PrintInstallPath(const char* path) const
385 printf("\tinstall path: %s\n", path);
388 void PrintChecksum(const char* checksum) const
390 printf("\tchecksum: %s\n", checksum);
393 private:
394 void _PrintResolvableExpression(const char* fieldName,
395 const BPackageResolvableExpression& expression) const
397 printf("\t%s: %s\n", fieldName, expression.ToString().String());
402 #endif // PACKAGE_INFO_PRINTER_H