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