Add url and sourceURL properties to BPackageInfo

Also extend the parser to accept "url" and "source-url" attributes.
This commit is contained in:
Ingo Weinhold 2011-06-28 17:24:34 +02:00
parent 1338e7b6ae
commit eb7e89518a
3 changed files with 94 additions and 0 deletions

View File

@ -65,6 +65,8 @@ public:
const BObjectList<BString>& CopyrightList() const;
const BObjectList<BString>& LicenseList() const;
const BObjectList<BString>& URLList() const;
const BObjectList<BString>& SourceURLList() const;
const BObjectList<BPackageResolvable>& ProvidesList() const;
const BObjectList<BPackageResolvableExpression>&
@ -97,6 +99,12 @@ public:
void ClearLicenseList();
status_t AddLicense(const BString& license);
void ClearURLList();
status_t AddURL(const BString& url);
void ClearSourceURLList();
status_t AddSourceURL(const BString& url);
void ClearProvidesList();
status_t AddProvides(const BPackageResolvable& provides);
@ -146,6 +154,8 @@ private:
BObjectList<BString> fCopyrightList;
BObjectList<BString> fLicenseList;
BObjectList<BString> fURLList;
BObjectList<BString> fSourceURLList;
BObjectList<BPackageResolvable> fProvidesList;

View File

@ -34,6 +34,8 @@ enum BPackageInfoAttributeID {
B_PACKAGE_INFO_REPLACES, // list of resolvables that this package
// will replace (upon update)
B_PACKAGE_INFO_FLAGS,
B_PACKAGE_INFO_URLS, // list
B_PACKAGE_INFO_SOURCE_URLS, // list
B_PACKAGE_INFO_CHECKSUM, // sha256-checksum
//
B_PACKAGE_INFO_ENUM_COUNT,

View File

@ -773,6 +773,32 @@ BPackageInfo::Parser::_Parse(BPackageInfo* packageInfo)
for (int i = 0; i < count; ++i)
packageInfo->AddLicense(*(licenseList.ItemAt(i)));
seen[B_PACKAGE_INFO_LICENSES] = true;
} else if (t.text.ICompare(names[B_PACKAGE_INFO_URLS]) == 0) {
if (seen[B_PACKAGE_INFO_URLS]) {
BString error = BString(names[B_PACKAGE_INFO_URLS])
<< " already seen!";
throw ParseError(error, t.pos);
}
BObjectList<BString> urlList;
_ParseStringList(&urlList);
int count = urlList.CountItems();
for (int i = 0; i < count; ++i)
packageInfo->AddURL(*(urlList.ItemAt(i)));
seen[B_PACKAGE_INFO_URLS] = true;
} else if (t.text.ICompare(names[B_PACKAGE_INFO_SOURCE_URLS]) == 0) {
if (seen[B_PACKAGE_INFO_SOURCE_URLS]) {
BString error = BString(names[B_PACKAGE_INFO_SOURCE_URLS])
<< " already seen!";
throw ParseError(error, t.pos);
}
BObjectList<BString> urlList;
_ParseStringList(&urlList);
int count = urlList.CountItems();
for (int i = 0; i < count; ++i)
packageInfo->AddSourceURL(*(urlList.ItemAt(i)));
seen[B_PACKAGE_INFO_SOURCE_URLS] = true;
} else if (t.text.ICompare(names[B_PACKAGE_INFO_PROVIDES]) == 0) {
if (seen[B_PACKAGE_INFO_PROVIDES]) {
BString error = BString(names[B_PACKAGE_INFO_PROVIDES])
@ -890,6 +916,8 @@ const char* BPackageInfo::kElementNames[B_PACKAGE_INFO_ENUM_COUNT] = {
"freshens",
"replaces",
"flags",
"urls",
"source-urls",
"checksum", // not being parsed, computed externally
};
@ -908,6 +936,8 @@ BPackageInfo::BPackageInfo()
fArchitecture(B_PACKAGE_ARCHITECTURE_ENUM_COUNT),
fCopyrightList(5, true),
fLicenseList(5, true),
fURLList(5, true),
fSourceURLList(5, true),
fProvidesList(20, true),
fRequiresList(20, true),
fSupplementsList(20, true),
@ -1060,6 +1090,20 @@ BPackageInfo::LicenseList() const
}
const BObjectList<BString>&
BPackageInfo::URLList() const
{
return fURLList;
}
const BObjectList<BString>&
BPackageInfo::SourceURLList() const
{
return fSourceURLList;
}
const BObjectList<BPackageResolvable>&
BPackageInfo::ProvidesList() const
{
@ -1201,6 +1245,42 @@ BPackageInfo::AddLicense(const BString& license)
}
void
BPackageInfo::ClearURLList()
{
fURLList.MakeEmpty();
}
status_t
BPackageInfo::AddURL(const BString& url)
{
BString* newURL = new (std::nothrow) BString(url);
if (newURL == NULL)
return B_NO_MEMORY;
return fURLList.AddItem(newURL) ? B_OK : B_NO_MEMORY;
}
void
BPackageInfo::ClearSourceURLList()
{
fSourceURLList.MakeEmpty();
}
status_t
BPackageInfo::AddSourceURL(const BString& url)
{
BString* newURL = new (std::nothrow) BString(url);
if (newURL == NULL)
return B_NO_MEMORY;
return fSourceURLList.AddItem(newURL) ? B_OK : B_NO_MEMORY;
}
void
BPackageInfo::ClearProvidesList()
{
@ -1328,6 +1408,8 @@ BPackageInfo::Clear()
fVersion.Clear();
fCopyrightList.MakeEmpty();
fLicenseList.MakeEmpty();
fURLList.MakeEmpty();
fSourceURLList.MakeEmpty();
fRequiresList.MakeEmpty();
fProvidesList.MakeEmpty();
fSupplementsList.MakeEmpty();