110b8f702SIngo Weinhold/*
256b43ecaSIngo Weinhold * Copyright 2011-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
310b8f702SIngo Weinhold * Distributed under the terms of the MIT License.
410b8f702SIngo Weinhold */
510b8f702SIngo Weinhold
610b8f702SIngo Weinhold
710b8f702SIngo Weinhold#include <package/PackageInfoContentHandler.h>
810b8f702SIngo Weinhold
910b8f702SIngo Weinhold#include <package/PackageInfo.h>
1010b8f702SIngo Weinhold#include <package/hpkg/ErrorOutput.h>
1110b8f702SIngo Weinhold#include <package/hpkg/PackageInfoAttributeValue.h>
1210b8f702SIngo Weinhold
1310b8f702SIngo Weinhold
1410b8f702SIngo Weinholdnamespace BPackageKit {
1510b8f702SIngo Weinhold
1610b8f702SIngo Weinhold
1710b8f702SIngo Weinholdusing namespace BHPKG;
1810b8f702SIngo Weinhold
1910b8f702SIngo Weinhold
2010b8f702SIngo WeinholdBPackageInfoContentHandler::BPackageInfoContentHandler(
2110b8f702SIngo Weinhold	BPackageInfo& packageInfo, BErrorOutput* errorOutput)
2210b8f702SIngo Weinhold	:
2310b8f702SIngo Weinhold	fPackageInfo(packageInfo),
2410b8f702SIngo Weinhold	fErrorOutput(errorOutput)
2510b8f702SIngo Weinhold{
2610b8f702SIngo Weinhold}
2710b8f702SIngo Weinhold
2810b8f702SIngo Weinhold
2910b8f702SIngo WeinholdBPackageInfoContentHandler::~BPackageInfoContentHandler()
3010b8f702SIngo Weinhold{
3110b8f702SIngo Weinhold}
3210b8f702SIngo Weinhold
3310b8f702SIngo Weinhold
3410b8f702SIngo Weinholdstatus_t
3510b8f702SIngo WeinholdBPackageInfoContentHandler::HandleEntry(BPackageEntry* entry)
3610b8f702SIngo Weinhold{
3710b8f702SIngo Weinhold	return B_OK;
3810b8f702SIngo Weinhold}
3910b8f702SIngo Weinhold
4010b8f702SIngo Weinhold
4110b8f702SIngo Weinholdstatus_t
4210b8f702SIngo WeinholdBPackageInfoContentHandler::HandleEntryAttribute(BPackageEntry* entry,
4310b8f702SIngo Weinhold	BPackageEntryAttribute* attribute)
4410b8f702SIngo Weinhold{
4510b8f702SIngo Weinhold	return B_OK;
4610b8f702SIngo Weinhold}
4710b8f702SIngo Weinhold
4810b8f702SIngo Weinhold
4910b8f702SIngo Weinholdstatus_t
5010b8f702SIngo WeinholdBPackageInfoContentHandler::HandleEntryDone(BPackageEntry* entry)
5110b8f702SIngo Weinhold{
5210b8f702SIngo Weinhold	return B_OK;
5310b8f702SIngo Weinhold}
5410b8f702SIngo Weinhold
5510b8f702SIngo Weinhold
5610b8f702SIngo Weinholdstatus_t
5710b8f702SIngo WeinholdBPackageInfoContentHandler::HandlePackageAttribute(
5810b8f702SIngo Weinhold	const BPackageInfoAttributeValue& value)
5910b8f702SIngo Weinhold{
6010b8f702SIngo Weinhold	switch (value.attributeID) {
6110b8f702SIngo Weinhold		case B_PACKAGE_INFO_NAME:
6210b8f702SIngo Weinhold			fPackageInfo.SetName(value.string);
6310b8f702SIngo Weinhold			break;
6410b8f702SIngo Weinhold
6510b8f702SIngo Weinhold		case B_PACKAGE_INFO_SUMMARY:
6610b8f702SIngo Weinhold			fPackageInfo.SetSummary(value.string);
6710b8f702SIngo Weinhold			break;
6810b8f702SIngo Weinhold
6910b8f702SIngo Weinhold		case B_PACKAGE_INFO_DESCRIPTION:
7010b8f702SIngo Weinhold			fPackageInfo.SetDescription(value.string);
7110b8f702SIngo Weinhold			break;
7210b8f702SIngo Weinhold
7310b8f702SIngo Weinhold		case B_PACKAGE_INFO_VENDOR:
7410b8f702SIngo Weinhold			fPackageInfo.SetVendor(value.string);
7510b8f702SIngo Weinhold			break;
7610b8f702SIngo Weinhold
7710b8f702SIngo Weinhold		case B_PACKAGE_INFO_PACKAGER:
7810b8f702SIngo Weinhold			fPackageInfo.SetPackager(value.string);
7910b8f702SIngo Weinhold			break;
8010b8f702SIngo Weinhold
8110b8f702SIngo Weinhold		case B_PACKAGE_INFO_FLAGS:
8210b8f702SIngo Weinhold			fPackageInfo.SetFlags(value.unsignedInt);
8310b8f702SIngo Weinhold			break;
8410b8f702SIngo Weinhold
8510b8f702SIngo Weinhold		case B_PACKAGE_INFO_ARCHITECTURE:
8610b8f702SIngo Weinhold			fPackageInfo.SetArchitecture(
8710b8f702SIngo Weinhold				(BPackageArchitecture)value.unsignedInt);
8810b8f702SIngo Weinhold			break;
8910b8f702SIngo Weinhold
9010b8f702SIngo Weinhold		case B_PACKAGE_INFO_VERSION:
9110b8f702SIngo Weinhold			fPackageInfo.SetVersion(value.version);
9210b8f702SIngo Weinhold			break;
9310b8f702SIngo Weinhold
9410b8f702SIngo Weinhold		case B_PACKAGE_INFO_COPYRIGHTS:
95dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddCopyright(value.string);
9610b8f702SIngo Weinhold
9710b8f702SIngo Weinhold		case B_PACKAGE_INFO_LICENSES:
98dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddLicense(value.string);
9910b8f702SIngo Weinhold
10010b8f702SIngo Weinhold		case B_PACKAGE_INFO_PROVIDES:
101dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddProvides(value.resolvable);
10210b8f702SIngo Weinhold
10310b8f702SIngo Weinhold		case B_PACKAGE_INFO_REQUIRES:
104dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddRequires(value.resolvableExpression);
10510b8f702SIngo Weinhold
10610b8f702SIngo Weinhold		case B_PACKAGE_INFO_SUPPLEMENTS:
107dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddSupplements(value.resolvableExpression);
10810b8f702SIngo Weinhold
10910b8f702SIngo Weinhold		case B_PACKAGE_INFO_CONFLICTS:
110dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddConflicts(value.resolvableExpression);
11110b8f702SIngo Weinhold
11210b8f702SIngo Weinhold		case B_PACKAGE_INFO_FRESHENS:
113dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddFreshens(value.resolvableExpression);
11410b8f702SIngo Weinhold
11510b8f702SIngo Weinhold		case B_PACKAGE_INFO_REPLACES:
116dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddReplaces(value.string);
11710b8f702SIngo Weinhold
11810b8f702SIngo Weinhold		case B_PACKAGE_INFO_URLS:
119dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddURL(value.string);
12010b8f702SIngo Weinhold
12110b8f702SIngo Weinhold		case B_PACKAGE_INFO_SOURCE_URLS:
122dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddSourceURL(value.string);
12310b8f702SIngo Weinhold
12410b8f702SIngo Weinhold		case B_PACKAGE_INFO_CHECKSUM:
12510b8f702SIngo Weinhold			fPackageInfo.SetChecksum(value.string);
12610b8f702SIngo Weinhold			break;
12710b8f702SIngo Weinhold
12810b8f702SIngo Weinhold		case B_PACKAGE_INFO_INSTALL_PATH:
12910b8f702SIngo Weinhold			fPackageInfo.SetInstallPath(value.string);
13010b8f702SIngo Weinhold			break;
13110b8f702SIngo Weinhold
13256b43ecaSIngo Weinhold		case B_PACKAGE_INFO_BASE_PACKAGE:
13356b43ecaSIngo Weinhold			fPackageInfo.SetBasePackage(value.string);
13456b43ecaSIngo Weinhold			break;
13556b43ecaSIngo Weinhold
1364489c88bSIngo Weinhold		case B_PACKAGE_INFO_GLOBAL_WRITABLE_FILES:
137dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddGlobalWritableFileInfo(
1384489c88bSIngo Weinhold				value.globalWritableFileInfo);
13956b43ecaSIngo Weinhold
14056b43ecaSIngo Weinhold		case B_PACKAGE_INFO_USER_SETTINGS_FILES:
141dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddUserSettingsFileInfo(value.userSettingsFileInfo);
14256b43ecaSIngo Weinhold
14356b43ecaSIngo Weinhold		case B_PACKAGE_INFO_USERS:
144dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddUser(value.user);
14556b43ecaSIngo Weinhold
14656b43ecaSIngo Weinhold		case B_PACKAGE_INFO_GROUPS:
147dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddGroup(value.string);
14856b43ecaSIngo Weinhold
14956b43ecaSIngo Weinhold		case B_PACKAGE_INFO_POST_INSTALL_SCRIPTS:
150dfbf1c8aSAugustin Cavalier			return fPackageInfo.AddPostInstallScript(value.string);
15156b43ecaSIngo Weinhold
15210b8f702SIngo Weinhold		default:
15310b8f702SIngo Weinhold			if (fErrorOutput != NULL) {
15410b8f702SIngo Weinhold				fErrorOutput->PrintError(
15510b8f702SIngo Weinhold					"Invalid package attribute section: unexpected package "
15610b8f702SIngo Weinhold					"attribute id %d encountered\n", value.attributeID);
15710b8f702SIngo Weinhold			}
15831d70c10SAlexander G. M. Smith			return B_NOT_SUPPORTED; // Could be a future attribute we can skip.
15910b8f702SIngo Weinhold	}
16010b8f702SIngo Weinhold
16110b8f702SIngo Weinhold	return B_OK;
16210b8f702SIngo Weinhold}
16310b8f702SIngo Weinhold
16410b8f702SIngo Weinhold
16510b8f702SIngo Weinholdvoid
16610b8f702SIngo WeinholdBPackageInfoContentHandler::HandleErrorOccurred()
16710b8f702SIngo Weinhold{
16810b8f702SIngo Weinhold}
16910b8f702SIngo Weinhold
17010b8f702SIngo Weinhold
17110b8f702SIngo Weinhold}	// namespace BPackageKit
172