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/GlobalWritableFileInfo.h> 15 #include <package/PackageArchitecture.h> 16 #include <package/PackageFlags.h> 17 #include <package/PackageInfoAttributes.h> 18 #include <package/PackageResolvable.h> 19 #include <package/PackageResolvableExpression.h> 20 #include <package/PackageVersion.h> 21 #include <package/User.h> 22 #include <package/UserSettingsFileInfo.h> 23 24 25 class BEntry; 26 class BFile; 27 28 29 namespace BPackageKit { 30 31 32 /* 33 * Keeps a list of package info elements (e.g. name, version, vendor, ...) which 34 * will be converted to package attributes when creating a package. Usually, 35 * these elements have been parsed from a ".PackageInfo" file. 36 * Alternatively, they can be read from an existing package file. 37 */ 38 class BPackageInfo : public BArchivable { 39 public: 40 struct ParseErrorListener { 41 virtual ~ParseErrorListener(); 42 virtual void OnError(const BString& msg, int line, int col) = 0; 43 }; 44 45 public: 46 BPackageInfo(); 47 BPackageInfo(BMessage* archive, 48 status_t* _error = NULL); 49 virtual ~BPackageInfo(); 50 51 status_t ReadFromConfigFile( 52 const BEntry& packageInfoEntry, 53 ParseErrorListener* listener = NULL); 54 status_t ReadFromConfigFile( 55 BFile& packageInfoFile, 56 ParseErrorListener* listener = NULL); 57 status_t ReadFromConfigString( 58 const BString& packageInfoString, 59 ParseErrorListener* listener = NULL); 60 status_t ReadFromPackageFile(const char* path); 61 status_t ReadFromPackageFile(int fd); 62 63 status_t InitCheck() const; 64 65 const BString& Name() const; 66 const BString& Summary() const; 67 const BString& Description() const; 68 const BString& Vendor() const; 69 const BString& Packager() const; 70 const BString& BasePackage() const; 71 const BString& Checksum() const; 72 const BString& InstallPath() const; 73 BString FileName() const; 74 // the explicitly set file name, if any, or 75 // CanonicalFileName() otherwise 76 77 uint32 Flags() const; 78 79 BPackageArchitecture Architecture() const; 80 81 const BPackageVersion& Version() const; 82 83 const BStringList& CopyrightList() const; 84 const BStringList& LicenseList() const; 85 const BStringList& URLList() const; 86 const BStringList& SourceURLList() const; 87 88 const BObjectList<BGlobalWritableFileInfo>& 89 GlobalWritableFileInfos() const; 90 const BObjectList<BUserSettingsFileInfo>& 91 UserSettingsFileInfos() const; 92 93 const BObjectList<BUser>& Users() const; 94 const BStringList& Groups() const; 95 96 const BStringList& PostInstallScripts() const; 97 98 const BObjectList<BPackageResolvable>& ProvidesList() const; 99 const BObjectList<BPackageResolvableExpression>& 100 RequiresList() const; 101 const BObjectList<BPackageResolvableExpression>& 102 SupplementsList() const; 103 const BObjectList<BPackageResolvableExpression>& 104 ConflictsList() const; 105 const BObjectList<BPackageResolvableExpression>& 106 FreshensList() const; 107 const BStringList& ReplacesList() const; 108 109 BString CanonicalFileName() const; 110 111 bool Matches(const BPackageResolvableExpression& 112 expression) const; 113 114 void SetName(const BString& name); 115 void SetSummary(const BString& summary); 116 void SetDescription(const BString& description); 117 void SetVendor(const BString& vendor); 118 void SetPackager(const BString& packager); 119 void SetBasePackage(const BString& basePackage); 120 void SetChecksum(const BString& checksum); 121 void SetInstallPath(const BString& installPath); 122 void SetFileName(const BString& fileName); 123 124 void SetFlags(uint32 flags); 125 126 void SetArchitecture( 127 BPackageArchitecture architecture); 128 129 void SetVersion(const BPackageVersion& version); 130 131 void ClearCopyrightList(); 132 status_t AddCopyright(const BString& copyright); 133 134 void ClearLicenseList(); 135 status_t AddLicense(const BString& license); 136 137 void ClearURLList(); 138 status_t AddURL(const BString& url); 139 140 void ClearSourceURLList(); 141 status_t AddSourceURL(const BString& url); 142 143 void ClearGlobalWritableFileInfos(); 144 status_t AddGlobalWritableFileInfo( 145 const BGlobalWritableFileInfo& info); 146 147 void ClearUserSettingsFileInfos(); 148 status_t AddUserSettingsFileInfo( 149 const BUserSettingsFileInfo& info); 150 151 void ClearUsers(); 152 status_t AddUser(const BUser& user); 153 154 void ClearGroups(); 155 status_t AddGroup(const BString& group); 156 157 void ClearPostInstallScripts(); 158 status_t AddPostInstallScript(const BString& path); 159 160 void ClearProvidesList(); 161 status_t AddProvides(const BPackageResolvable& provides); 162 163 void ClearRequiresList(); 164 status_t AddRequires( 165 const BPackageResolvableExpression& expr); 166 167 void ClearSupplementsList(); 168 status_t AddSupplements( 169 const BPackageResolvableExpression& expr); 170 171 void ClearConflictsList(); 172 status_t AddConflicts( 173 const BPackageResolvableExpression& expr); 174 175 void ClearFreshensList(); 176 status_t AddFreshens( 177 const BPackageResolvableExpression& expr); 178 179 void ClearReplacesList(); 180 status_t AddReplaces(const BString& replaces); 181 182 void Clear(); 183 184 virtual status_t Archive(BMessage* archive, 185 bool deep = true) const; 186 static BArchivable* Instantiate(BMessage* archive); 187 188 status_t GetConfigString(BString& _string) const; 189 BString ToString() const; 190 191 public: 192 static status_t GetArchitectureByName(const BString& name, 193 BPackageArchitecture& _architecture); 194 195 static status_t ParseVersionString(const BString& string, 196 bool revisionIsOptional, 197 BPackageVersion& _version, 198 ParseErrorListener* listener = NULL); 199 static status_t ParseResolvableExpressionString( 200 const BString& string, 201 BPackageResolvableExpression& _expression, 202 ParseErrorListener* listener = NULL); 203 204 public: 205 static const char* const kElementNames[]; 206 static const char* const kArchitectureNames[]; 207 static const char* const kWritableFileUpdateTypes[]; 208 209 private: 210 class Parser; 211 friend class Parser; 212 struct StringBuilder; 213 struct FieldName; 214 struct PackageFileLocation; 215 216 typedef BObjectList<BPackageResolvable> ResolvableList; 217 typedef BObjectList<BPackageResolvableExpression> 218 ResolvableExpressionList; 219 220 typedef BObjectList<BGlobalWritableFileInfo> 221 GlobalWritableFileInfoList; 222 typedef BObjectList<BUserSettingsFileInfo> 223 UserSettingsFileInfoList; 224 225 typedef BObjectList<BUser> UserList; 226 227 private: 228 status_t _ReadFromPackageFile( 229 const PackageFileLocation& fileLocation); 230 231 static status_t _AddVersion(BMessage* archive, 232 const char* field, 233 const BPackageVersion& version); 234 static status_t _AddResolvables(BMessage* archive, 235 const char* field, 236 const ResolvableList& resolvables); 237 static status_t _AddResolvableExpressions(BMessage* archive, 238 const char* field, 239 const ResolvableExpressionList& 240 expressions); 241 static status_t _AddGlobalWritableFileInfos(BMessage* archive, 242 const char* field, 243 const GlobalWritableFileInfoList& 244 infos); 245 static status_t _AddUserSettingsFileInfos(BMessage* archive, 246 const char* field, 247 const UserSettingsFileInfoList& 248 infos); 249 static status_t _AddUsers(BMessage* archive, const char* field, 250 const UserList& users); 251 252 static status_t _ExtractVersion(BMessage* archive, 253 const char* field, int32 index, 254 BPackageVersion& _version); 255 static status_t _ExtractStringList(BMessage* archive, 256 const char* field, BStringList& _list); 257 static status_t _ExtractResolvables(BMessage* archive, 258 const char* field, 259 ResolvableList& _resolvables); 260 static status_t _ExtractResolvableExpressions(BMessage* archive, 261 const char* field, 262 ResolvableExpressionList& _expressions); 263 static status_t _ExtractGlobalWritableFileInfos( 264 BMessage* archive, const char* field, 265 GlobalWritableFileInfoList& _infos); 266 static status_t _ExtractUserSettingsFileInfos( 267 BMessage* archive, const char* field, 268 UserSettingsFileInfoList& _infos); 269 static status_t _ExtractUsers(BMessage* archive, 270 const char* field, UserList& _users); 271 272 private: 273 BString fName; 274 BString fSummary; 275 BString fDescription; 276 BString fVendor; 277 BString fPackager; 278 BString fBasePackage; 279 280 uint32 fFlags; 281 282 BPackageArchitecture fArchitecture; 283 284 BPackageVersion fVersion; 285 286 BStringList fCopyrightList; 287 BStringList fLicenseList; 288 BStringList fURLList; 289 BStringList fSourceURLList; 290 291 BObjectList<BGlobalWritableFileInfo> fGlobalWritableFileInfos; 292 BObjectList<BUserSettingsFileInfo> fUserSettingsFileInfos; 293 294 UserList fUsers; 295 BStringList fGroups; 296 297 BStringList fPostInstallScripts; 298 299 ResolvableList fProvidesList; 300 301 ResolvableExpressionList fRequiresList; 302 ResolvableExpressionList fSupplementsList; 303 ResolvableExpressionList fConflictsList; 304 ResolvableExpressionList fFreshensList; 305 306 BStringList fReplacesList; 307 308 BString fChecksum; 309 BString fInstallPath; 310 BString fFileName; 311 }; 312 313 314 } // namespace BPackageKit 315 316 317 #endif // _PACKAGE__PACKAGE_INFO_H_ 318