xref: /haiku/headers/os/package/PackageInfo.h (revision 204dee708a999d5a71d0cb9497650ee7cef85d0a)
1 /*
2  * Copyright 2011, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _PACKAGE__PACKAGE_INFO_H_
6 #define _PACKAGE__PACKAGE_INFO_H_
7 
8 
9 #include <Archivable.h>
10 #include <ObjectList.h>
11 #include <String.h>
12 #include <StringList.h>
13 
14 #include <package/PackageArchitecture.h>
15 #include <package/PackageFlags.h>
16 #include <package/PackageInfoAttributes.h>
17 #include <package/PackageResolvable.h>
18 #include <package/PackageResolvableExpression.h>
19 #include <package/PackageVersion.h>
20 
21 
22 class BEntry;
23 class BFile;
24 
25 
26 namespace BPackageKit {
27 
28 
29 /*
30  * Keeps a list of package info elements (e.g. name, version, vendor, ...) which
31  * will be converted to package attributes when creating a package. Usually,
32  * these elements have been parsed from a ".PackageInfo" file.
33  * Alternatively, they can be read from an existing package file.
34  */
35 class BPackageInfo : public BArchivable {
36 public:
37 			struct ParseErrorListener {
38 				virtual	~ParseErrorListener();
39 				virtual void OnError(const BString& msg, int line, int col) = 0;
40 			};
41 
42 public:
43 								BPackageInfo();
44 								BPackageInfo(BMessage* archive,
45 									status_t* _error = NULL);
46 	virtual						~BPackageInfo();
47 
48 			status_t			ReadFromConfigFile(
49 									const BEntry& packageInfoEntry,
50 									ParseErrorListener* listener = NULL);
51 			status_t			ReadFromConfigFile(
52 									BFile& packageInfoFile,
53 									ParseErrorListener* listener = NULL);
54 			status_t			ReadFromConfigString(
55 									const BString& packageInfoString,
56 									ParseErrorListener* listener = NULL);
57 			status_t			ReadFromPackageFile(const char* path);
58 			status_t			ReadFromPackageFile(int fd);
59 
60 			status_t			InitCheck() const;
61 
62 			const BString&		Name() const;
63 			const BString&		Summary() const;
64 			const BString&		Description() const;
65 			const BString&		Vendor() const;
66 			const BString&		Packager() const;
67 			const BString&		Checksum() const;
68 			const BString&		InstallPath() const;
69 
70 			uint32				Flags() const;
71 
72 			BPackageArchitecture	Architecture() const;
73 
74 			const BPackageVersion&	Version() const;
75 
76 			const BStringList&	CopyrightList() const;
77 			const BStringList&	LicenseList() const;
78 			const BStringList&	URLList() const;
79 			const BStringList&	SourceURLList() const;
80 
81 			const BObjectList<BPackageResolvable>&	ProvidesList() const;
82 			const BObjectList<BPackageResolvableExpression>&
83 								RequiresList() const;
84 			const BObjectList<BPackageResolvableExpression>&
85 								SupplementsList() const;
86 			const BObjectList<BPackageResolvableExpression>&
87 								ConflictsList() const;
88 			const BObjectList<BPackageResolvableExpression>&
89 								FreshensList() const;
90 			const BStringList&	ReplacesList() const;
91 
92 			BString				CanonicalFileName() const;
93 
94 			void				SetName(const BString& name);
95 			void				SetSummary(const BString& summary);
96 			void				SetDescription(const BString& description);
97 			void				SetVendor(const BString& vendor);
98 			void				SetPackager(const BString& packager);
99 			void				SetChecksum(const BString& checksum);
100 			void				SetInstallPath(const BString& installPath);
101 
102 			void				SetFlags(uint32 flags);
103 
104 			void				SetArchitecture(
105 									BPackageArchitecture architecture);
106 
107 			void				SetVersion(const BPackageVersion& version);
108 
109 			void				ClearCopyrightList();
110 			status_t			AddCopyright(const BString& copyright);
111 
112 			void				ClearLicenseList();
113 			status_t			AddLicense(const BString& license);
114 
115 			void				ClearURLList();
116 			status_t			AddURL(const BString& url);
117 
118 			void				ClearSourceURLList();
119 			status_t			AddSourceURL(const BString& url);
120 
121 			void				ClearProvidesList();
122 			status_t			AddProvides(const BPackageResolvable& provides);
123 
124 			void				ClearRequiresList();
125 			status_t			AddRequires(
126 									const BPackageResolvableExpression& expr);
127 
128 			void				ClearSupplementsList();
129 			status_t			AddSupplements(
130 									const BPackageResolvableExpression& expr);
131 
132 			void				ClearConflictsList();
133 			status_t			AddConflicts(
134 									const BPackageResolvableExpression& expr);
135 
136 			void				ClearFreshensList();
137 			status_t			AddFreshens(
138 									const BPackageResolvableExpression& expr);
139 
140 			void				ClearReplacesList();
141 			status_t			AddReplaces(const BString& replaces);
142 
143 			void				Clear();
144 
145 	virtual	status_t 			Archive(BMessage* archive,
146 									bool deep = true) const;
147 	static 	BArchivable*		Instantiate(BMessage* archive);
148 
149 			status_t			GetConfigString(BString& _string) const;
150 			BString				ToString() const;
151 
152 public:
153 	static	status_t			GetArchitectureByName(const BString& name,
154 									BPackageArchitecture& _architecture);
155 
156 	static	status_t			ParseVersionString(const BString& string,
157 									bool revisionIsOptional,
158 									BPackageVersion& _version,
159 									ParseErrorListener* listener = NULL);
160 
161 public:
162 	static	const char*			kElementNames[];
163 	static	const char*			kArchitectureNames[];
164 
165 private:
166 			class Parser;
167 			friend class Parser;
168 			struct StringBuilder;
169 			struct FieldName;
170 
171 			typedef BObjectList<BPackageResolvable> ResolvableList;
172 			typedef BObjectList<BPackageResolvableExpression>
173 				ResolvableExpressionList;
174 
175 private:
176 	static	status_t			_AddVersion(BMessage* archive,
177 									const char* field,
178 									const BPackageVersion& version);
179 	static	status_t			_AddResolvables(BMessage* archive,
180 									const char* field,
181 									const ResolvableList& resolvables);
182 	static	status_t			_AddResolvableExpressions(BMessage* archive,
183 									const char* field,
184 									const ResolvableExpressionList&
185 										expressions);
186 	static	status_t			_ExtractVersion(BMessage* archive,
187 									const char* field, int32 index,
188 									BPackageVersion& _version);
189 	static	status_t			_ExtractStringList(BMessage* archive,
190 									const char* field, BStringList& _list);
191 	static	status_t			_ExtractResolvables(BMessage* archive,
192 									const char* field,
193 									ResolvableList& _resolvables);
194 	static	status_t			_ExtractResolvableExpressions(BMessage* archive,
195 									const char* field,
196 									ResolvableExpressionList& _expressions);
197 
198 private:
199 			BString				fName;
200 			BString				fSummary;
201 			BString				fDescription;
202 			BString				fVendor;
203 			BString				fPackager;
204 
205 			uint32				fFlags;
206 
207 			BPackageArchitecture fArchitecture;
208 
209 			BPackageVersion		fVersion;
210 
211 			BStringList			fCopyrightList;
212 			BStringList			fLicenseList;
213 			BStringList			fURLList;
214 			BStringList			fSourceURLList;
215 
216 			ResolvableList		fProvidesList;
217 
218 			ResolvableExpressionList fRequiresList;
219 			ResolvableExpressionList fSupplementsList;
220 			ResolvableExpressionList fConflictsList;
221 			ResolvableExpressionList fFreshensList;
222 
223 			BStringList			fReplacesList;
224 
225 			BString				fChecksum;
226 			BString				fInstallPath;
227 };
228 
229 
230 }	// namespace BPackageKit
231 
232 
233 #endif	// _PACKAGE__PACKAGE_INFO_H_
234