1 /* 2 * Copyright 2009-2011, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PACKAGE__HPKG__PACKAGE_INFO_ATTRIBUTE_VALUE_H_ 6 #define _PACKAGE__HPKG__PACKAGE_INFO_ATTRIBUTE_VALUE_H_ 7 8 9 #include <SupportDefs.h> 10 11 #include <string.h> 12 13 #include <package/PackageArchitecture.h> 14 #include <package/PackageInfoAttributes.h> 15 #include <package/PackageResolvableOperator.h> 16 #include <package/WritableFileUpdateType.h> 17 18 19 namespace BPackageKit { 20 21 namespace BHPKG { 22 23 24 struct BPackageVersionData { 25 const char* major; 26 const char* minor; 27 const char* micro; 28 const char* preRelease; 29 uint32 revision; 30 }; 31 32 33 struct BPackageResolvableData { 34 const char* name; 35 bool haveVersion; 36 bool haveCompatibleVersion; 37 BPackageVersionData version; 38 BPackageVersionData compatibleVersion; 39 }; 40 41 42 struct BPackageResolvableExpressionData { 43 const char* name; 44 bool haveOpAndVersion; 45 BPackageResolvableOperator op; 46 BPackageVersionData version; 47 }; 48 49 50 struct BGlobalWritableFileInfoData { 51 const char* path; 52 BWritableFileUpdateType updateType; 53 bool isDirectory; 54 }; 55 56 57 struct BUserSettingsFileInfoData { 58 const char* path; 59 const char* templatePath; 60 bool isDirectory; 61 }; 62 63 64 struct BUserData { 65 const char* name; 66 const char* realName; 67 const char* home; 68 const char* shell; 69 const char* const* groups; 70 size_t groupCount; 71 }; 72 73 74 struct BPackageInfoAttributeValue { 75 union { 76 uint64 unsignedInt; 77 const char* string; 78 BPackageVersionData version; 79 BPackageResolvableData resolvable; 80 BPackageResolvableExpressionData resolvableExpression; 81 BGlobalWritableFileInfoData globalWritableFileInfo; 82 BUserSettingsFileInfoData userSettingsFileInfo; 83 BUserData user; 84 }; 85 BPackageInfoAttributeID attributeID; 86 87 public: 88 BPackageInfoAttributeValue(); 89 90 void SetTo(BPackageInfoAttributeID id, 91 uint8 value); 92 void SetTo(BPackageInfoAttributeID id, 93 const char* value); 94 95 void Clear(); 96 }; 97 98 99 inline 100 BPackageInfoAttributeValue::BPackageInfoAttributeValue() 101 { 102 Clear(); 103 } 104 105 106 inline void 107 BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id, uint8 value) 108 { 109 attributeID = id; 110 unsignedInt = value; 111 } 112 113 114 inline void 115 BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id, 116 const char* value) 117 { 118 attributeID = id; 119 string = value; 120 } 121 122 123 inline void 124 BPackageInfoAttributeValue::Clear() 125 { 126 unsignedInt = 0; 127 string = NULL; 128 memset(&version, 0, sizeof(version)); 129 memset(&resolvable, 0, sizeof(resolvable)); 130 memset(&resolvableExpression, 0, sizeof(resolvableExpression)); 131 memset(&globalWritableFileInfo, 0, sizeof(globalWritableFileInfo)); 132 memset(&userSettingsFileInfo, 0, sizeof(userSettingsFileInfo)); 133 memset(&user, 0, sizeof(user)); 134 attributeID = B_PACKAGE_INFO_ENUM_COUNT; 135 } 136 137 138 } // namespace BHPKG 139 140 } // namespace BPackageKit 141 142 143 #endif // _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_ 144