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 const char* ArchitectureName() const; 81 // NULL, if invalid 82 83 const BPackageVersion& Version() const; 84 85 const BStringList& CopyrightList() const; 86 const BStringList& LicenseList() const; 87 const BStringList& URLList() const; 88 const BStringList& SourceURLList() const; 89 90 const BObjectList<BGlobalWritableFileInfo>& 91 GlobalWritableFileInfos() const; 92 const BObjectList<BUserSettingsFileInfo>& 93 UserSettingsFileInfos() const; 94 95 const BObjectList<BUser>& Users() const; 96 const BStringList& Groups() const; 97 98 const BStringList& PostInstallScripts() const; 99 const BStringList& PreUninstallScripts() const; 100 101 const BObjectList<BPackageResolvable>& ProvidesList() const; 102 const BObjectList<BPackageResolvableExpression>& 103 RequiresList() const; 104 const BObjectList<BPackageResolvableExpression>& 105 SupplementsList() const; 106 const BObjectList<BPackageResolvableExpression>& 107 ConflictsList() const; 108 const BObjectList<BPackageResolvableExpression>& 109 FreshensList() const; 110 const BStringList& ReplacesList() const; 111 112 BString CanonicalFileName() const; 113 114 bool Matches(const BPackageResolvableExpression& 115 expression) const; 116 117 void SetName(const BString& name); 118 void SetSummary(const BString& summary); 119 void SetDescription(const BString& description); 120 void SetVendor(const BString& vendor); 121 void SetPackager(const BString& packager); 122 void SetBasePackage(const BString& basePackage); 123 void SetChecksum(const BString& checksum); 124 void SetInstallPath(const BString& installPath); 125 void SetFileName(const BString& fileName); 126 127 void SetFlags(uint32 flags); 128 129 void SetArchitecture( 130 BPackageArchitecture architecture); 131 132 void SetVersion(const BPackageVersion& version); 133 134 void ClearCopyrightList(); 135 status_t AddCopyright(const BString& copyright); 136 137 void ClearLicenseList(); 138 status_t AddLicense(const BString& license); 139 140 void ClearURLList(); 141 status_t AddURL(const BString& url); 142 143 void ClearSourceURLList(); 144 status_t AddSourceURL(const BString& url); 145 146 void ClearGlobalWritableFileInfos(); 147 status_t AddGlobalWritableFileInfo( 148 const BGlobalWritableFileInfo& info); 149 150 void ClearUserSettingsFileInfos(); 151 status_t AddUserSettingsFileInfo( 152 const BUserSettingsFileInfo& info); 153 154 void ClearUsers(); 155 status_t AddUser(const BUser& user); 156 157 void ClearGroups(); 158 status_t AddGroup(const BString& group); 159 160 void ClearPostInstallScripts(); 161 status_t AddPostInstallScript(const BString& path); 162 163 void ClearPreUninstallScripts(); 164 status_t AddPreUninstallScript(const BString& path); 165 166 void ClearProvidesList(); 167 status_t AddProvides(const BPackageResolvable& provides); 168 169 void ClearRequiresList(); 170 status_t AddRequires( 171 const BPackageResolvableExpression& expr); 172 173 void ClearSupplementsList(); 174 status_t AddSupplements( 175 const BPackageResolvableExpression& expr); 176 177 void ClearConflictsList(); 178 status_t AddConflicts( 179 const BPackageResolvableExpression& expr); 180 181 void ClearFreshensList(); 182 status_t AddFreshens( 183 const BPackageResolvableExpression& expr); 184 185 void ClearReplacesList(); 186 status_t AddReplaces(const BString& replaces); 187 188 void Clear(); 189 190 virtual status_t Archive(BMessage* archive, 191 bool deep = true) const; 192 static BArchivable* Instantiate(BMessage* archive); 193 194 status_t GetConfigString(BString& _string) const; 195 BString ToString() const; 196 197 public: 198 static status_t GetArchitectureByName(const BString& name, 199 BPackageArchitecture& _architecture); 200 201 static status_t ParseVersionString(const BString& string, 202 bool revisionIsOptional, 203 BPackageVersion& _version, 204 ParseErrorListener* listener = NULL); 205 static status_t ParseResolvableExpressionString( 206 const BString& string, 207 BPackageResolvableExpression& _expression, 208 ParseErrorListener* listener = NULL); 209 210 public: 211 static const char* const kElementNames[]; 212 static const char* const kArchitectureNames[]; 213 static const char* const kWritableFileUpdateTypes[]; 214 215 private: 216 class Parser; 217 friend class Parser; 218 struct StringBuilder; 219 struct FieldName; 220 struct PackageFileLocation; 221 222 typedef BObjectList<BPackageResolvable> ResolvableList; 223 typedef BObjectList<BPackageResolvableExpression> 224 ResolvableExpressionList; 225 226 typedef BObjectList<BGlobalWritableFileInfo> 227 GlobalWritableFileInfoList; 228 typedef BObjectList<BUserSettingsFileInfo> 229 UserSettingsFileInfoList; 230 231 typedef BObjectList<BUser> UserList; 232 233 private: 234 status_t _ReadFromPackageFile( 235 const PackageFileLocation& fileLocation); 236 237 static status_t _AddVersion(BMessage* archive, 238 const char* field, 239 const BPackageVersion& version); 240 static status_t _AddResolvables(BMessage* archive, 241 const char* field, 242 const ResolvableList& resolvables); 243 static status_t _AddResolvableExpressions(BMessage* archive, 244 const char* field, 245 const ResolvableExpressionList& 246 expressions); 247 static status_t _AddGlobalWritableFileInfos(BMessage* archive, 248 const char* field, 249 const GlobalWritableFileInfoList& 250 infos); 251 static status_t _AddUserSettingsFileInfos(BMessage* archive, 252 const char* field, 253 const UserSettingsFileInfoList& 254 infos); 255 static status_t _AddUsers(BMessage* archive, const char* field, 256 const UserList& users); 257 258 static status_t _ExtractVersion(BMessage* archive, 259 const char* field, int32 index, 260 BPackageVersion& _version); 261 static status_t _ExtractStringList(BMessage* archive, 262 const char* field, BStringList& _list); 263 static status_t _ExtractResolvables(BMessage* archive, 264 const char* field, 265 ResolvableList& _resolvables); 266 static status_t _ExtractResolvableExpressions(BMessage* archive, 267 const char* field, 268 ResolvableExpressionList& _expressions); 269 static status_t _ExtractGlobalWritableFileInfos( 270 BMessage* archive, const char* field, 271 GlobalWritableFileInfoList& _infos); 272 static status_t _ExtractUserSettingsFileInfos( 273 BMessage* archive, const char* field, 274 UserSettingsFileInfoList& _infos); 275 static status_t _ExtractUsers(BMessage* archive, 276 const char* field, UserList& _users); 277 278 private: 279 BString fName; 280 BString fSummary; 281 BString fDescription; 282 BString fVendor; 283 BString fPackager; 284 BString fBasePackage; 285 286 uint32 fFlags; 287 288 BPackageArchitecture fArchitecture; 289 290 BPackageVersion fVersion; 291 292 BStringList fCopyrightList; 293 BStringList fLicenseList; 294 BStringList fURLList; 295 BStringList fSourceURLList; 296 297 BObjectList<BGlobalWritableFileInfo> fGlobalWritableFileInfos; 298 BObjectList<BUserSettingsFileInfo> fUserSettingsFileInfos; 299 300 UserList fUsers; 301 BStringList fGroups; 302 303 BStringList fPostInstallScripts; 304 BStringList fPreUninstallScripts; 305 306 ResolvableList fProvidesList; 307 308 ResolvableExpressionList fRequiresList; 309 ResolvableExpressionList fSupplementsList; 310 ResolvableExpressionList fConflictsList; 311 ResolvableExpressionList fFreshensList; 312 313 BStringList fReplacesList; 314 315 BString fChecksum; 316 BString fInstallPath; 317 BString fFileName; 318 }; 319 320 321 } // namespace BPackageKit 322 323 324 #endif // _PACKAGE__PACKAGE_INFO_H_ 325