xref: /haiku/src/kits/package/hpkg/v1/PackageInfoContentHandlerV1.cpp (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
1 /*
2  * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <package/hpkg/v1/PackageInfoContentHandler.h>
8 
9 #include <package/PackageInfo.h>
10 #include <package/hpkg/ErrorOutput.h>
11 #include <package/hpkg/PackageInfoAttributeValue.h>
12 
13 
14 namespace BPackageKit {
15 
16 namespace BHPKG {
17 
18 namespace V1 {
19 
20 
21 BPackageInfoContentHandler::BPackageInfoContentHandler(
22 	BPackageInfo& packageInfo, BErrorOutput* errorOutput)
23 	:
24 	fPackageInfo(packageInfo),
25 	fErrorOutput(errorOutput)
26 {
27 }
28 
29 
30 BPackageInfoContentHandler::~BPackageInfoContentHandler()
31 {
32 }
33 
34 
35 status_t
36 BPackageInfoContentHandler::HandleEntry(BPackageEntry* entry)
37 {
38 	return B_OK;
39 }
40 
41 
42 status_t
43 BPackageInfoContentHandler::HandleEntryAttribute(BPackageEntry* entry,
44 	BPackageEntryAttribute* attribute)
45 {
46 	return B_OK;
47 }
48 
49 
50 status_t
51 BPackageInfoContentHandler::HandleEntryDone(BPackageEntry* entry)
52 {
53 	return B_OK;
54 }
55 
56 
57 status_t
58 BPackageInfoContentHandler::HandlePackageAttribute(
59 	const BPackageInfoAttributeValue& value)
60 {
61 	switch (value.attributeID) {
62 		case B_PACKAGE_INFO_NAME:
63 			fPackageInfo.SetName(value.string);
64 			break;
65 
66 		case B_PACKAGE_INFO_SUMMARY:
67 			fPackageInfo.SetSummary(value.string);
68 			break;
69 
70 		case B_PACKAGE_INFO_DESCRIPTION:
71 			fPackageInfo.SetDescription(value.string);
72 			break;
73 
74 		case B_PACKAGE_INFO_VENDOR:
75 			fPackageInfo.SetVendor(value.string);
76 			break;
77 
78 		case B_PACKAGE_INFO_PACKAGER:
79 			fPackageInfo.SetPackager(value.string);
80 			break;
81 
82 		case B_PACKAGE_INFO_FLAGS:
83 			fPackageInfo.SetFlags(value.unsignedInt);
84 			break;
85 
86 		case B_PACKAGE_INFO_ARCHITECTURE:
87 			fPackageInfo.SetArchitecture(
88 				(BPackageArchitecture)value.unsignedInt);
89 			break;
90 
91 		case B_PACKAGE_INFO_VERSION:
92 			fPackageInfo.SetVersion(value.version);
93 			break;
94 
95 		case B_PACKAGE_INFO_COPYRIGHTS:
96 			fPackageInfo.AddCopyright(value.string);
97 			break;
98 
99 		case B_PACKAGE_INFO_LICENSES:
100 			fPackageInfo.AddLicense(value.string);
101 			break;
102 
103 		case B_PACKAGE_INFO_PROVIDES:
104 			fPackageInfo.AddProvides(value.resolvable);
105 			break;
106 
107 		case B_PACKAGE_INFO_REQUIRES:
108 			fPackageInfo.AddRequires(value.resolvableExpression);
109 			break;
110 
111 		case B_PACKAGE_INFO_SUPPLEMENTS:
112 			fPackageInfo.AddSupplements(value.resolvableExpression);
113 			break;
114 
115 		case B_PACKAGE_INFO_CONFLICTS:
116 			fPackageInfo.AddConflicts(value.resolvableExpression);
117 			break;
118 
119 		case B_PACKAGE_INFO_FRESHENS:
120 			fPackageInfo.AddFreshens(value.resolvableExpression);
121 			break;
122 
123 		case B_PACKAGE_INFO_REPLACES:
124 			fPackageInfo.AddReplaces(value.string);
125 			break;
126 
127 		case B_PACKAGE_INFO_URLS:
128 			fPackageInfo.AddURL(value.string);
129 			break;
130 
131 		case B_PACKAGE_INFO_SOURCE_URLS:
132 			fPackageInfo.AddSourceURL(value.string);
133 			break;
134 
135 		case B_PACKAGE_INFO_CHECKSUM:
136 			fPackageInfo.SetChecksum(value.string);
137 			break;
138 
139 		case B_PACKAGE_INFO_INSTALL_PATH:
140 			fPackageInfo.SetInstallPath(value.string);
141 			break;
142 
143 		default:
144 			if (fErrorOutput != NULL) {
145 				fErrorOutput->PrintError(
146 					"Invalid package attribute section: unexpected package "
147 					"attribute id %d encountered\n", value.attributeID);
148 			}
149 			return B_BAD_DATA;
150 	}
151 
152 	return B_OK;
153 }
154 
155 
156 void
157 BPackageInfoContentHandler::HandleErrorOccurred()
158 {
159 }
160 
161 
162 }	// namespace V1
163 
164 }	// namespace BHPKG
165 
166 }	// namespace BPackageKit
167