Ejemplo n.º 1
0
status_t
PackageReaderImpl::ReadAttributeValue(uint8 type, uint8 encoding,
	AttributeValue& _value)
{
	switch (type) {
		case B_HPKG_ATTRIBUTE_TYPE_RAW:
		{
			uint64 size;
			status_t error = ReadUnsignedLEB128(size);
			if (error != B_OK)
				return error;

			if (encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP) {
				uint64 offset;
				error = ReadUnsignedLEB128(offset);
				if (error != B_OK)
					return error;

				if (offset > fHeapSize || size > fHeapSize - offset) {
					ErrorOutput()->PrintError("Error: Invalid %s section: "
						"invalid data reference\n", CurrentSection()->name);
					return B_BAD_DATA;
				}

				_value.SetToData(size, offset);
			} else if (encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE) {
				if (size > B_HPKG_MAX_INLINE_DATA_SIZE) {
					ErrorOutput()->PrintError("Error: Invalid %s section: "
						"inline data too long\n", CurrentSection()->name);
					return B_BAD_DATA;
				}

				const void* buffer;
				error = _GetTOCBuffer(size, buffer);
				if (error != B_OK)
					return error;
				_value.SetToData(size, buffer);
			} else {
				ErrorOutput()->PrintError("Error: Invalid %s section: invalid "
					"raw encoding (%u)\n", CurrentSection()->name, encoding);
				return B_BAD_DATA;
			}

			return B_OK;
		}

		default:
			return inherited::ReadAttributeValue(type, encoding, _value);
	}
}
Ejemplo n.º 2
0
bool IniFile::load(const std::string& Path)
{
	std::ifstream File(Path.c_str());
	if(File)
	{
		free();
		Section *CurrentSection(NULL);
                std::string line, key, value;
		while(std::getline(File, line))
		{
			if(line[0] == '[')
			{
				CurrentSection = new Section(line.substr(1, line.find_first_of("]") - 1));
				insert(std::make_pair(CurrentSection->getName(), CurrentSection));
			} else if(line != "" && line != "\n") {
				key = line.substr(line.find_first_not_of(" "));
				key = line.substr(0, line.find_first_of(" ="));
				if(line.find_first_of("=") + 1>= line.length())
				{
					value = "";
				} else  {
					value = line.substr(line.find_first_of("=") + 1);
					if(value.find_first_not_of(" ") > value.length())
						value = "";
					else
						value = value.substr(value.find_first_not_of(" "));
				}
				//std::cout << key << " = " << value << std::endl;
				CurrentSection->insert(std::make_pair(key, value));
			}
		}
		File.close();
		myPath = Path;
		return true;
	} else { return false; }
}