BRepositoryInfo: make sure fInitStatus is always set correctly
This commit is contained in:
@@ -66,6 +66,10 @@ public:
|
|||||||
static const char* const kLicenseNameField;
|
static const char* const kLicenseNameField;
|
||||||
static const char* const kLicenseTextField;
|
static const char* const kLicenseTextField;
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t _SetTo(const BMessage* data);
|
||||||
|
status_t _SetTo(const BEntry& entry);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t fInitStatus;
|
status_t fInitStatus;
|
||||||
|
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ BRepositoryInfo::BRepositoryInfo(BMessage* data)
|
|||||||
inherited(data),
|
inherited(data),
|
||||||
fLicenseTexts(5)
|
fLicenseTexts(5)
|
||||||
{
|
{
|
||||||
fInitStatus = SetTo(data);
|
fInitStatus = _SetTo(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BRepositoryInfo::BRepositoryInfo(const BEntry& entry)
|
BRepositoryInfo::BRepositoryInfo(const BEntry& entry)
|
||||||
{
|
{
|
||||||
fInitStatus = SetTo(entry);
|
fInitStatus = _SetTo(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -120,107 +120,14 @@ BRepositoryInfo::InitCheck() const
|
|||||||
status_t
|
status_t
|
||||||
BRepositoryInfo::SetTo(const BMessage* data)
|
BRepositoryInfo::SetTo(const BMessage* data)
|
||||||
{
|
{
|
||||||
if (data == NULL)
|
return fInitStatus = _SetTo(data);
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
status_t result;
|
|
||||||
if ((result = data->FindString(kNameField, &fName)) != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->FindString(kURLField, &fOriginalBaseURL)) != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->FindString(kVendorField, &fVendor)) != B_OK)
|
|
||||||
return result;
|
|
||||||
result = data->FindString(kSummaryField, &fSummary);
|
|
||||||
if (result != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->FindUInt8(kPriorityField, &fPriority)) != B_OK)
|
|
||||||
return result;
|
|
||||||
result = data->FindUInt8(kArchitectureField, (uint8*)&fArchitecture);
|
|
||||||
if (result != B_OK)
|
|
||||||
return result;
|
|
||||||
if (fArchitecture == B_PACKAGE_ARCHITECTURE_ANY)
|
|
||||||
return B_BAD_DATA;
|
|
||||||
|
|
||||||
const char* licenseName;
|
|
||||||
const char* licenseText;
|
|
||||||
for (int i = 0;
|
|
||||||
data->FindString(kLicenseNameField, i, &licenseName) == B_OK
|
|
||||||
&& data->FindString(kLicenseTextField, i, &licenseText) == B_OK;
|
|
||||||
++i) {
|
|
||||||
if (!fLicenseNames.Add(licenseName) || !fLicenseTexts.Add(licenseText))
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BRepositoryInfo::SetTo(const BEntry& entry)
|
BRepositoryInfo::SetTo(const BEntry& entry)
|
||||||
{
|
{
|
||||||
BFile file(&entry, B_READ_ONLY);
|
return fInitStatus = _SetTo(entry);
|
||||||
status_t result = file.InitCheck();
|
|
||||||
if (result != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
off_t size;
|
|
||||||
if ((result = file.GetSize(&size)) != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
BString configString;
|
|
||||||
char* buffer = configString.LockBuffer(size);
|
|
||||||
if (buffer == NULL)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
if ((result = file.Read(buffer, size)) < size) {
|
|
||||||
configString.UnlockBuffer(0);
|
|
||||||
return (result >= 0) ? B_IO_ERROR : result;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[size] = '\0';
|
|
||||||
configString.UnlockBuffer(size);
|
|
||||||
|
|
||||||
void* settingsHandle = parse_driver_settings_string(configString.String());
|
|
||||||
if (settingsHandle == NULL)
|
|
||||||
return B_BAD_DATA;
|
|
||||||
CObjectDeleter<void, status_t> settingsHandleDeleter(settingsHandle,
|
|
||||||
&unload_driver_settings);
|
|
||||||
|
|
||||||
const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL);
|
|
||||||
const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL);
|
|
||||||
const char* vendor
|
|
||||||
= get_driver_parameter(settingsHandle, "vendor", NULL, NULL);
|
|
||||||
const char* summary
|
|
||||||
= get_driver_parameter(settingsHandle, "summary", NULL, NULL);
|
|
||||||
const char* priorityString
|
|
||||||
= get_driver_parameter(settingsHandle, "priority", NULL, NULL);
|
|
||||||
const char* architectureString
|
|
||||||
= get_driver_parameter(settingsHandle, "architecture", NULL, NULL);
|
|
||||||
|
|
||||||
if (name == NULL || *name == '\0' || url == NULL || *url == '\0'
|
|
||||||
|| vendor == NULL || *vendor == '\0'
|
|
||||||
|| summary == NULL || *summary == '\0'
|
|
||||||
|| priorityString == NULL || *priorityString == '\0'
|
|
||||||
|| architectureString == NULL || *architectureString == '\0') {
|
|
||||||
return B_BAD_DATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
BPackageArchitecture architecture;
|
|
||||||
if (BPackageInfo::GetArchitectureByName(architectureString, architecture)
|
|
||||||
!= B_OK || architecture == B_PACKAGE_ARCHITECTURE_ANY) {
|
|
||||||
return B_BAD_DATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
fName = name;
|
|
||||||
fOriginalBaseURL = url;
|
|
||||||
fVendor = vendor;
|
|
||||||
fSummary = summary;
|
|
||||||
fPriority = atoi(priorityString);
|
|
||||||
fArchitecture = architecture;
|
|
||||||
|
|
||||||
fInitStatus = B_OK;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -341,4 +248,109 @@ BRepositoryInfo::ClearLicenses()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryInfo::_SetTo(const BMessage* data)
|
||||||
|
{
|
||||||
|
if (data == NULL)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
status_t result;
|
||||||
|
if ((result = data->FindString(kNameField, &fName)) != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->FindString(kURLField, &fOriginalBaseURL)) != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->FindString(kVendorField, &fVendor)) != B_OK)
|
||||||
|
return result;
|
||||||
|
result = data->FindString(kSummaryField, &fSummary);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->FindUInt8(kPriorityField, &fPriority)) != B_OK)
|
||||||
|
return result;
|
||||||
|
result = data->FindUInt8(kArchitectureField, (uint8*)&fArchitecture);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
if (fArchitecture == B_PACKAGE_ARCHITECTURE_ANY)
|
||||||
|
return B_BAD_DATA;
|
||||||
|
|
||||||
|
const char* licenseName;
|
||||||
|
const char* licenseText;
|
||||||
|
for (int i = 0;
|
||||||
|
data->FindString(kLicenseNameField, i, &licenseName) == B_OK
|
||||||
|
&& data->FindString(kLicenseTextField, i, &licenseText) == B_OK;
|
||||||
|
++i) {
|
||||||
|
if (!fLicenseNames.Add(licenseName) || !fLicenseTexts.Add(licenseText))
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryInfo::_SetTo(const BEntry& entry)
|
||||||
|
{
|
||||||
|
BFile file(&entry, B_READ_ONLY);
|
||||||
|
status_t result = file.InitCheck();
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
off_t size;
|
||||||
|
if ((result = file.GetSize(&size)) != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
BString configString;
|
||||||
|
char* buffer = configString.LockBuffer(size);
|
||||||
|
if (buffer == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
if ((result = file.Read(buffer, size)) < size) {
|
||||||
|
configString.UnlockBuffer(0);
|
||||||
|
return (result >= 0) ? B_IO_ERROR : result;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[size] = '\0';
|
||||||
|
configString.UnlockBuffer(size);
|
||||||
|
|
||||||
|
void* settingsHandle = parse_driver_settings_string(configString.String());
|
||||||
|
if (settingsHandle == NULL)
|
||||||
|
return B_BAD_DATA;
|
||||||
|
CObjectDeleter<void, status_t> settingsHandleDeleter(settingsHandle,
|
||||||
|
&unload_driver_settings);
|
||||||
|
|
||||||
|
const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL);
|
||||||
|
const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL);
|
||||||
|
const char* vendor
|
||||||
|
= get_driver_parameter(settingsHandle, "vendor", NULL, NULL);
|
||||||
|
const char* summary
|
||||||
|
= get_driver_parameter(settingsHandle, "summary", NULL, NULL);
|
||||||
|
const char* priorityString
|
||||||
|
= get_driver_parameter(settingsHandle, "priority", NULL, NULL);
|
||||||
|
const char* architectureString
|
||||||
|
= get_driver_parameter(settingsHandle, "architecture", NULL, NULL);
|
||||||
|
|
||||||
|
if (name == NULL || *name == '\0' || url == NULL || *url == '\0'
|
||||||
|
|| vendor == NULL || *vendor == '\0'
|
||||||
|
|| summary == NULL || *summary == '\0'
|
||||||
|
|| priorityString == NULL || *priorityString == '\0'
|
||||||
|
|| architectureString == NULL || *architectureString == '\0') {
|
||||||
|
return B_BAD_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
BPackageArchitecture architecture;
|
||||||
|
if (BPackageInfo::GetArchitectureByName(architectureString, architecture)
|
||||||
|
!= B_OK || architecture == B_PACKAGE_ARCHITECTURE_ANY) {
|
||||||
|
return B_BAD_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
fName = name;
|
||||||
|
fOriginalBaseURL = url;
|
||||||
|
fVendor = vendor;
|
||||||
|
fSummary = summary;
|
||||||
|
fPriority = atoi(priorityString);
|
||||||
|
fArchitecture = architecture;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPackageKit
|
} // namespace BPackageKit
|
||||||
|
|||||||
Reference in New Issue
Block a user